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, |
Willy Tarreau | 7f61884 | 2016-01-08 11:40:03 +0100 | [diff] [blame] | 325 | ST_F_AGENT_STATUS, |
| 326 | ST_F_AGENT_CODE, |
| 327 | ST_F_AGENT_DURATION, |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 328 | ST_F_CHECK_DESC, |
| 329 | ST_F_AGENT_DESC, |
Willy Tarreau | 3141f59 | 2016-01-08 14:25:28 +0100 | [diff] [blame] | 330 | ST_F_CHECK_RISE, |
| 331 | ST_F_CHECK_FALL, |
| 332 | ST_F_CHECK_HEALTH, |
| 333 | ST_F_AGENT_RISE, |
| 334 | ST_F_AGENT_FALL, |
| 335 | ST_F_AGENT_HEALTH, |
Willy Tarreau | 3a4ec3a | 2016-01-08 15:35:43 +0100 | [diff] [blame] | 336 | ST_F_ADDR, |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 337 | ST_F_COOKIE, |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 338 | ST_F_MODE, |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 339 | ST_F_ALGO, |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 340 | ST_F_CONN_RATE, |
| 341 | ST_F_CONN_RATE_MAX, |
| 342 | ST_F_CONN_TOT, |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 343 | ST_F_INTERCEPTED, |
Willy Tarreau | 8e20514 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 344 | |
| 345 | /* must always be the last one */ |
| 346 | ST_F_TOTAL_FIELDS |
| 347 | }; |
| 348 | |
| 349 | /* These are the field names for each ST_F_* field position. Please pay attention |
| 350 | * to always use the exact same name except that the strings must be lower case |
| 351 | * while the enum entries must be upper case. |
| 352 | */ |
| 353 | const char *stat_field_names[ST_F_TOTAL_FIELDS] = { |
| 354 | [ST_F_PXNAME] = "pxname", |
| 355 | [ST_F_SVNAME] = "svname", |
| 356 | [ST_F_QCUR] = "qcur", |
| 357 | [ST_F_QMAX] = "qmax", |
| 358 | [ST_F_SCUR] = "scur", |
| 359 | [ST_F_SMAX] = "smax", |
| 360 | [ST_F_SLIM] = "slim", |
| 361 | [ST_F_STOT] = "stot", |
| 362 | [ST_F_BIN] = "bin", |
| 363 | [ST_F_BOUT] = "bout", |
| 364 | [ST_F_DREQ] = "dreq", |
| 365 | [ST_F_DRESP] = "dresp", |
| 366 | [ST_F_EREQ] = "ereq", |
| 367 | [ST_F_ECON] = "econ", |
| 368 | [ST_F_ERESP] = "eresp", |
| 369 | [ST_F_WRETR] = "wretr", |
| 370 | [ST_F_WREDIS] = "wredis", |
| 371 | [ST_F_STATUS] = "status", |
| 372 | [ST_F_WEIGHT] = "weight", |
| 373 | [ST_F_ACT] = "act", |
| 374 | [ST_F_BCK] = "bck", |
| 375 | [ST_F_CHKFAIL] = "chkfail", |
| 376 | [ST_F_CHKDOWN] = "chkdown", |
| 377 | [ST_F_LASTCHG] = "lastchg", |
| 378 | [ST_F_DOWNTIME] = "downtime", |
| 379 | [ST_F_QLIMIT] = "qlimit", |
| 380 | [ST_F_PID] = "pid", |
| 381 | [ST_F_IID] = "iid", |
| 382 | [ST_F_SID] = "sid", |
| 383 | [ST_F_THROTTLE] = "throttle", |
| 384 | [ST_F_LBTOT] = "lbtot", |
| 385 | [ST_F_TRACKED] = "tracked", |
| 386 | [ST_F_TYPE] = "type", |
| 387 | [ST_F_RATE] = "rate", |
| 388 | [ST_F_RATE_LIM] = "rate_lim", |
| 389 | [ST_F_RATE_MAX] = "rate_max", |
| 390 | [ST_F_CHECK_STATUS] = "check_status", |
| 391 | [ST_F_CHECK_CODE] = "check_code", |
| 392 | [ST_F_CHECK_DURATION] = "check_duration", |
| 393 | [ST_F_HRSP_1XX] = "hrsp_1xx", |
| 394 | [ST_F_HRSP_2XX] = "hrsp_2xx", |
| 395 | [ST_F_HRSP_3XX] = "hrsp_3xx", |
| 396 | [ST_F_HRSP_4XX] = "hrsp_4xx", |
| 397 | [ST_F_HRSP_5XX] = "hrsp_5xx", |
| 398 | [ST_F_HRSP_OTHER] = "hrsp_other", |
| 399 | [ST_F_HANAFAIL] = "hanafail", |
| 400 | [ST_F_REQ_RATE] = "req_rate", |
| 401 | [ST_F_REQ_RATE_MAX] = "req_rate_max", |
| 402 | [ST_F_REQ_TOT] = "req_tot", |
| 403 | [ST_F_CLI_ABRT] = "cli_abrt", |
| 404 | [ST_F_SRV_ABRT] = "srv_abrt", |
| 405 | [ST_F_COMP_IN] = "comp_in", |
| 406 | [ST_F_COMP_OUT] = "comp_out", |
| 407 | [ST_F_COMP_BYP] = "comp_byp", |
| 408 | [ST_F_COMP_RSP] = "comp_rsp", |
| 409 | [ST_F_LASTSESS] = "lastsess", |
| 410 | [ST_F_LAST_CHK] = "last_chk", |
| 411 | [ST_F_LAST_AGT] = "last_agt", |
| 412 | [ST_F_QTIME] = "qtime", |
| 413 | [ST_F_CTIME] = "ctime", |
| 414 | [ST_F_RTIME] = "rtime", |
| 415 | [ST_F_TTIME] = "ttime", |
Willy Tarreau | 7f61884 | 2016-01-08 11:40:03 +0100 | [diff] [blame] | 416 | [ST_F_AGENT_STATUS] = "agent_status", |
| 417 | [ST_F_AGENT_CODE] = "agent_code", |
| 418 | [ST_F_AGENT_DURATION] = "agent_duration", |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 419 | [ST_F_CHECK_DESC] = "check_desc", |
| 420 | [ST_F_AGENT_DESC] = "agent_desc", |
Willy Tarreau | 3141f59 | 2016-01-08 14:25:28 +0100 | [diff] [blame] | 421 | [ST_F_CHECK_RISE] = "check_rise", |
| 422 | [ST_F_CHECK_FALL] = "check_fall", |
| 423 | [ST_F_CHECK_HEALTH] = "check_health", |
| 424 | [ST_F_AGENT_RISE] = "agent_rise", |
| 425 | [ST_F_AGENT_FALL] = "agent_fall", |
| 426 | [ST_F_AGENT_HEALTH] = "agent_health", |
Willy Tarreau | 3a4ec3a | 2016-01-08 15:35:43 +0100 | [diff] [blame] | 427 | [ST_F_ADDR] = "addr", |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 428 | [ST_F_COOKIE] = "cookie", |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 429 | [ST_F_MODE] = "mode", |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 430 | [ST_F_ALGO] = "algo", |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 431 | [ST_F_CONN_RATE] = "conn_rate", |
| 432 | [ST_F_CONN_RATE_MAX] = "conn_rate_max", |
| 433 | [ST_F_CONN_TOT] = "conn_tot", |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 434 | [ST_F_INTERCEPTED] = "intercepted", |
Willy Tarreau | 8e20514 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 435 | }; |
| 436 | |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 437 | /* one line of stats */ |
| 438 | static struct field stats[ST_F_TOTAL_FIELDS]; |
| 439 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 440 | static int stats_dump_backend_to_buffer(struct stream_interface *si); |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 441 | static int stats_dump_env_to_buffer(struct stream_interface *si); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 442 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 443 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 444 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 445 | 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] | 446 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 447 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 448 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 449 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 450 | 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] | 451 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 452 | static int stats_pats_list(struct stream_interface *si); |
| 453 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 454 | static int stats_map_lookup(struct stream_interface *si); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 455 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 456 | static int stats_tlskeys_list(struct stream_interface *si); |
| 457 | #endif |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 458 | static void cli_release_handler(struct appctx *appctx); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 459 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 460 | static void dump_servers_state(struct proxy *backend, struct chunk *buf); |
| 461 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 462 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 463 | * cli_io_handler() |
| 464 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 465 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 466 | * -> stats_dump_info_to_buffer() // "show info" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 467 | * -> stats_dump_backend_to_buffer() // "show backend" |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 468 | * -> stats_dump_servers_state_to_buffer() // "show servers state [<backend name>]" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 469 | * -> stats_dump_stat_to_buffer() // "show stat" |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 470 | * -> stats_dump_resolvers_to_buffer() // "show stat resolver <id>" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 471 | * -> stats_dump_csv_header() |
| 472 | * -> stats_dump_proxy_to_buffer() |
| 473 | * -> stats_dump_fe_stats() |
| 474 | * -> stats_dump_li_stats() |
| 475 | * -> stats_dump_sv_stats() |
| 476 | * -> stats_dump_be_stats() |
| 477 | * |
| 478 | * http_stats_io_handler() |
| 479 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 480 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 481 | * -> stats_dump_html_head() // emits the HTML headers |
| 482 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 483 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 484 | * -> stats_dump_html_px_hdr() |
| 485 | * -> stats_dump_fe_stats() |
| 486 | * -> stats_dump_li_stats() |
| 487 | * -> stats_dump_sv_stats() |
| 488 | * -> stats_dump_be_stats() |
| 489 | * -> stats_dump_html_px_end() |
| 490 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 491 | */ |
| 492 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 493 | static struct applet cli_applet; |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 494 | |
| 495 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 496 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 497 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 498 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 499 | " help : this message\n" |
| 500 | " prompt : toggle interactive mode with prompt\n" |
| 501 | " quit : disconnect\n" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 502 | " show backend : list backends in the current running config\n" |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 503 | " show env [var] : dump environment variables known to the process\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 504 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 505 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 506 | " show stat : report counters for each proxy and server\n" |
| 507 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 508 | " 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] | 509 | " 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] | 510 | " show servers state [id]: dump volatile server information (for backend <id>)\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 511 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 512 | " set weight : change a server's weight\n" |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 513 | " set server : change a server's state, weight or address\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 514 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 515 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 516 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 517 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 518 | " disable : put a server or frontend in maintenance mode\n" |
| 519 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 520 | " 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] | 521 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 522 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 523 | " add acl : add acl entry\n" |
| 524 | " del acl : delete acl entry\n" |
| 525 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 526 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 527 | " get map : reports the keys and values matching a sample for a map\n" |
| 528 | " set map : modify map entry\n" |
| 529 | " add map : add map entry\n" |
| 530 | " del map : delete map entry\n" |
| 531 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 532 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 533 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 534 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 535 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 536 | "Permission denied\n" |
| 537 | ""; |
| 538 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 539 | /* data transmission states for the stats responses */ |
| 540 | enum { |
| 541 | STAT_ST_INIT = 0, |
| 542 | STAT_ST_HEAD, |
| 543 | STAT_ST_INFO, |
| 544 | STAT_ST_LIST, |
| 545 | STAT_ST_END, |
| 546 | STAT_ST_FIN, |
| 547 | }; |
| 548 | |
| 549 | /* data transmission states for the stats responses inside a proxy */ |
| 550 | enum { |
| 551 | STAT_PX_ST_INIT = 0, |
| 552 | STAT_PX_ST_TH, |
| 553 | STAT_PX_ST_FE, |
| 554 | STAT_PX_ST_LI, |
| 555 | STAT_PX_ST_SV, |
| 556 | STAT_PX_ST_BE, |
| 557 | STAT_PX_ST_END, |
| 558 | STAT_PX_ST_FIN, |
| 559 | }; |
| 560 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 561 | extern const char *stat_status_codes[]; |
| 562 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 563 | /* allocate a new stats frontend named <name>, and return it |
| 564 | * (or NULL in case of lack of memory). |
| 565 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 566 | 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] | 567 | { |
| 568 | struct proxy *fe; |
| 569 | |
| 570 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 571 | if (!fe) |
| 572 | return NULL; |
| 573 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 574 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 575 | fe->next = proxy; |
| 576 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 577 | fe->last_change = now.tv_sec; |
| 578 | fe->id = strdup("GLOBAL"); |
| 579 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 580 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 581 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 582 | fe->conf.file = strdup(file); |
| 583 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 584 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 585 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 586 | |
| 587 | /* the stats frontend is the only one able to assign ID #0 */ |
| 588 | fe->conf.id.key = fe->uuid = 0; |
| 589 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 590 | return fe; |
| 591 | } |
| 592 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 593 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 594 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 595 | * error message into the <err> buffer which will be preallocated. The trailing |
| 596 | * '\n' must not be written. The function must be called with <args> pointing to |
| 597 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 598 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 599 | 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] | 600 | struct proxy *defpx, const char *file, int line, |
| 601 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 602 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 603 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 604 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 605 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 606 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 607 | int cur_arg; |
| 608 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 609 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 610 | 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] | 611 | return -1; |
| 612 | } |
| 613 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 614 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 615 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 616 | 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] | 617 | return -1; |
| 618 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 619 | } |
| 620 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 621 | 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] | 622 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 623 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 624 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 625 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 626 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 627 | return -1; |
| 628 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 629 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 630 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 631 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 632 | static int bind_dumped; |
| 633 | struct bind_kw *kw; |
| 634 | |
| 635 | kw = bind_find_kw(args[cur_arg]); |
| 636 | if (kw) { |
| 637 | if (!kw->parse) { |
| 638 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 639 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 640 | return -1; |
| 641 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 642 | |
Willy Tarreau | 061b5de | 2015-10-13 15:06:57 +0200 | [diff] [blame] | 643 | 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] | 644 | if (err && *err) |
| 645 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 646 | else |
| 647 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 648 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 649 | return -1; |
| 650 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 651 | |
| 652 | cur_arg += 1 + kw->skip; |
| 653 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 654 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 655 | |
| 656 | if (!bind_dumped) { |
| 657 | bind_dump_kws(err); |
| 658 | indent_msg(err, 4); |
| 659 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 660 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 661 | |
| 662 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 663 | args[0], args[1], args[cur_arg], |
| 664 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 665 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 666 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 667 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 668 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 669 | l->maxconn = global.stats_fe->maxconn; |
| 670 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 671 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 672 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 673 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 674 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 675 | l->nice = -64; /* we want to boost priority for local stats */ |
| 676 | global.maxsock += l->maxconn; |
| 677 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 678 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 679 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 680 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 681 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 682 | |
| 683 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 684 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 685 | return -1; |
| 686 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 687 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 688 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 689 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 690 | return -1; |
| 691 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 692 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 693 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 694 | 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] | 695 | return -1; |
| 696 | } |
| 697 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 698 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 699 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 700 | else if (!strcmp(args[1], "maxconn")) { |
| 701 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 702 | |
| 703 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 704 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 705 | return -1; |
| 706 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 707 | |
| 708 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 709 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 710 | 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] | 711 | return -1; |
| 712 | } |
| 713 | } |
| 714 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 715 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 716 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 717 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 718 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 719 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 720 | if (!global.stats_fe) { |
| 721 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 722 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 723 | return -1; |
| 724 | } |
| 725 | } |
| 726 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 727 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 728 | unsigned int low, high; |
| 729 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 730 | if (strcmp(args[cur_arg], "all") == 0) { |
| 731 | set = 0; |
| 732 | break; |
| 733 | } |
| 734 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 735 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 736 | } |
| 737 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 738 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 739 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 740 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 741 | char *dash = strchr(args[cur_arg], '-'); |
| 742 | |
| 743 | low = high = str2uic(args[cur_arg]); |
| 744 | if (dash) |
| 745 | high = str2uic(dash + 1); |
| 746 | |
| 747 | if (high < low) { |
| 748 | unsigned int swap = low; |
| 749 | low = high; |
| 750 | high = swap; |
| 751 | } |
| 752 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 753 | if (low < 1 || high > LONGBITS) { |
| 754 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 755 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 756 | return -1; |
| 757 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 758 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 759 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 760 | } |
| 761 | else { |
| 762 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 763 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 764 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 765 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 766 | } |
| 767 | cur_arg++; |
| 768 | } |
| 769 | global.stats_fe->bind_proc = set; |
| 770 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 771 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 772 | 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] | 773 | return -1; |
| 774 | } |
| 775 | return 0; |
| 776 | } |
| 777 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 778 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 779 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 780 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 781 | * 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] | 782 | */ |
| 783 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 784 | { |
Willy Tarreau | f614229 | 2016-01-04 17:24:29 +0100 | [diff] [blame] | 785 | int field; |
| 786 | |
| 787 | chunk_appendf(&trash, "# "); |
| 788 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) |
| 789 | chunk_appendf(&trash, "%s,", stat_field_names[field]); |
| 790 | |
| 791 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 792 | } |
| 793 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 794 | /* print a string of text buffer to <out>. The format is : |
| 795 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 796 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 797 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 798 | */ |
| 799 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 800 | { |
| 801 | unsigned char c; |
| 802 | int ptr = 0; |
| 803 | |
| 804 | while (buf[ptr] && ptr < bsize) { |
| 805 | c = buf[ptr]; |
| 806 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 807 | if (out->len > out->size - 1) |
| 808 | break; |
| 809 | out->str[out->len++] = c; |
| 810 | } |
| 811 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 812 | if (out->len > out->size - 2) |
| 813 | break; |
| 814 | out->str[out->len++] = '\\'; |
| 815 | switch (c) { |
| 816 | case ' ': c = ' '; break; |
| 817 | case '\t': c = 't'; break; |
| 818 | case '\n': c = 'n'; break; |
| 819 | case '\r': c = 'r'; break; |
| 820 | case '\e': c = 'e'; break; |
| 821 | case '\\': c = '\\'; break; |
| 822 | } |
| 823 | out->str[out->len++] = c; |
| 824 | } |
| 825 | else { |
| 826 | if (out->len > out->size - 4) |
| 827 | break; |
| 828 | out->str[out->len++] = '\\'; |
| 829 | out->str[out->len++] = 'x'; |
| 830 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 831 | out->str[out->len++] = hextab[c & 0xF]; |
| 832 | } |
| 833 | ptr++; |
| 834 | } |
| 835 | |
| 836 | return ptr; |
| 837 | } |
| 838 | |
| 839 | /* print a buffer in hexa. |
| 840 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 841 | */ |
| 842 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 843 | { |
| 844 | unsigned char c; |
| 845 | int ptr = 0; |
| 846 | |
| 847 | while (ptr < bsize) { |
| 848 | c = buf[ptr]; |
| 849 | |
| 850 | if (out->len > out->size - 2) |
| 851 | break; |
| 852 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 853 | out->str[out->len++] = hextab[c & 0xF]; |
| 854 | |
| 855 | ptr++; |
| 856 | } |
| 857 | return ptr; |
| 858 | } |
| 859 | |
| 860 | /* Dump the status of a table to a stream interface's |
| 861 | * read buffer. It returns 0 if the output buffer is full |
| 862 | * and needs to be called again, otherwise non-zero. |
| 863 | */ |
| 864 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 865 | struct proxy *proxy, struct proxy *target) |
| 866 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 867 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 868 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 869 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 870 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 871 | |
| 872 | /* any other information should be dumped here */ |
| 873 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 874 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 875 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 876 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 877 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 878 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 879 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 880 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 881 | |
| 882 | return 1; |
| 883 | } |
| 884 | |
| 885 | /* Dump the a table entry to a stream interface's |
| 886 | * read buffer. It returns 0 if the output buffer is full |
| 887 | * and needs to be called again, otherwise non-zero. |
| 888 | */ |
| 889 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 890 | struct proxy *proxy, struct stksess *entry) |
| 891 | { |
| 892 | int dt; |
| 893 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 894 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 895 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 896 | if (proxy->table.type == SMP_T_IPV4) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 897 | char addr[INET_ADDRSTRLEN]; |
| 898 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 899 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 900 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 901 | else if (proxy->table.type == SMP_T_IPV6) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 902 | char addr[INET6_ADDRSTRLEN]; |
| 903 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 904 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 905 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 906 | else if (proxy->table.type == SMP_T_SINT) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 907 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 908 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 909 | else if (proxy->table.type == SMP_T_STR) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 910 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 911 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 912 | } |
| 913 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 914 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 915 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 916 | } |
| 917 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 918 | 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] | 919 | |
| 920 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 921 | void *ptr; |
| 922 | |
| 923 | if (proxy->table.data_ofs[dt] == 0) |
| 924 | continue; |
| 925 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 926 | 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] | 927 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 928 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 929 | |
| 930 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 931 | switch (stktable_data_types[dt].std_type) { |
| 932 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 933 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 934 | break; |
| 935 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 936 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 937 | break; |
| 938 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 939 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 940 | break; |
| 941 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 942 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 943 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 944 | proxy->table.data_arg[dt].u)); |
| 945 | break; |
| 946 | } |
| 947 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 948 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 949 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 950 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 951 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 952 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 953 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 954 | |
| 955 | return 1; |
| 956 | } |
| 957 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 958 | 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] | 959 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 960 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 961 | struct appctx *appctx = __objt_appctx(si->end); |
| 962 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 963 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 964 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 965 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 966 | long long value; |
| 967 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 968 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 969 | void *ptr; |
| 970 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 971 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 972 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 973 | |
| 974 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 975 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 976 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 977 | return; |
| 978 | } |
| 979 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 980 | switch (px->table.type) { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 981 | case SMP_T_IPV4: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 982 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 983 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 984 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 985 | case SMP_T_IPV6: |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 986 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 987 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 988 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 989 | case SMP_T_SINT: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 990 | { |
| 991 | char *endptr; |
| 992 | unsigned long val; |
| 993 | errno = 0; |
| 994 | val = strtoul(args[4], &endptr, 10); |
| 995 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 996 | (errno != 0 && val == 0) || endptr == args[4] || |
| 997 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 998 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 999 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 1000 | return; |
| 1001 | } |
| 1002 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 1003 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 1004 | break; |
| 1005 | } |
| 1006 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 1007 | case SMP_T_STR: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 1008 | static_table_key->key = args[4]; |
| 1009 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 1010 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 1011 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1012 | switch (action) { |
| 1013 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1014 | 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] | 1015 | break; |
| 1016 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1017 | 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] | 1018 | break; |
| 1019 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1020 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1021 | break; |
| 1022 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1023 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1024 | return; |
| 1025 | } |
| 1026 | |
| 1027 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1028 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1029 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1030 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1031 | return; |
| 1032 | } |
| 1033 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 1034 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 1035 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1036 | switch (action) { |
| 1037 | case STAT_CLI_O_TAB: |
| 1038 | if (!ts) |
| 1039 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1040 | chunk_reset(&trash); |
| 1041 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 1042 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1043 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1044 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1045 | |
| 1046 | case STAT_CLI_O_CLR: |
| 1047 | if (!ts) |
| 1048 | return; |
| 1049 | if (ts->ref_cnt) { |
| 1050 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1051 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 1052 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1053 | return; |
| 1054 | } |
| 1055 | stksess_kill(&px->table, ts); |
| 1056 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 1057 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1058 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1059 | if (ts) |
| 1060 | stktable_touch(&px->table, ts, 1); |
| 1061 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 1062 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1063 | if (!ts) { |
| 1064 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1065 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 1066 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1067 | return; |
| 1068 | } |
| 1069 | stktable_store(&px->table, ts, 1); |
| 1070 | } |
| 1071 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1072 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 1073 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1074 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 1075 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1076 | return; |
| 1077 | } |
| 1078 | |
| 1079 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 1080 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1081 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 1082 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1083 | return; |
| 1084 | } |
| 1085 | |
| 1086 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1087 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 1088 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1089 | return; |
| 1090 | } |
| 1091 | |
| 1092 | 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] | 1093 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 1094 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1095 | return; |
| 1096 | } |
| 1097 | |
| 1098 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 1099 | |
| 1100 | switch (stktable_data_types[data_type].std_type) { |
| 1101 | case STD_T_SINT: |
| 1102 | stktable_data_cast(ptr, std_t_sint) = value; |
| 1103 | break; |
| 1104 | case STD_T_UINT: |
| 1105 | stktable_data_cast(ptr, std_t_uint) = value; |
| 1106 | break; |
| 1107 | case STD_T_ULL: |
| 1108 | stktable_data_cast(ptr, std_t_ull) = value; |
| 1109 | break; |
| 1110 | case STD_T_FRQP: |
| 1111 | /* We set both the current and previous values. That way |
| 1112 | * the reported frequency is stable during all the period |
| 1113 | * then slowly fades out. This allows external tools to |
| 1114 | * push measures without having to update them too often. |
| 1115 | */ |
| 1116 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 1117 | frqp->curr_tick = now_ms; |
| 1118 | frqp->prev_ctr = 0; |
| 1119 | frqp->curr_ctr = value; |
| 1120 | break; |
| 1121 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1122 | } |
| 1123 | break; |
| 1124 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1125 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1126 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 1127 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1128 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1129 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1130 | } |
| 1131 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1132 | 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] | 1133 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1134 | struct appctx *appctx = __objt_appctx(si->end); |
| 1135 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 1136 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1137 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 1138 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1139 | return; |
| 1140 | } |
| 1141 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1142 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1143 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 1144 | if (appctx->ctx.table.data_type < 0) { |
| 1145 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 1146 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1147 | return; |
| 1148 | } |
| 1149 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1150 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 1151 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 1152 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1153 | return; |
| 1154 | } |
| 1155 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1156 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 1157 | if (appctx->ctx.table.data_op < 0) { |
| 1158 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 1159 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1160 | return; |
| 1161 | } |
| 1162 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1163 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 1164 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 1165 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1166 | return; |
| 1167 | } |
| 1168 | } |
| 1169 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1170 | 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] | 1171 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1172 | struct appctx *appctx = __objt_appctx(si->end); |
| 1173 | |
| 1174 | appctx->ctx.table.data_type = -1; |
| 1175 | appctx->st2 = STAT_ST_INIT; |
| 1176 | appctx->ctx.table.target = NULL; |
| 1177 | appctx->ctx.table.proxy = NULL; |
| 1178 | appctx->ctx.table.entry = NULL; |
| 1179 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1180 | |
| 1181 | if (*args[2]) { |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 1182 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1183 | if (!appctx->ctx.table.target) { |
| 1184 | appctx->ctx.cli.msg = "No such table\n"; |
| 1185 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1186 | return; |
| 1187 | } |
| 1188 | } |
| 1189 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1190 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1191 | goto err_args; |
| 1192 | return; |
| 1193 | } |
| 1194 | |
| 1195 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1196 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1197 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1198 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1199 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1200 | goto err_args; |
| 1201 | |
| 1202 | return; |
| 1203 | |
| 1204 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1205 | switch (action) { |
| 1206 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1207 | 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] | 1208 | break; |
| 1209 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1210 | 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] | 1211 | break; |
| 1212 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1213 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1214 | break; |
| 1215 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1216 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1217 | } |
| 1218 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1219 | /* 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] | 1220 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1221 | * level to be admin. |
| 1222 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1223 | 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] | 1224 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1225 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1226 | struct proxy *px; |
| 1227 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1228 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1229 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1230 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1231 | return NULL; |
| 1232 | } |
| 1233 | |
| 1234 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1235 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 1236 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1237 | return NULL; |
| 1238 | } |
| 1239 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 1240 | px = proxy_fe_by_name(arg); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1241 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1242 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 1243 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1244 | return NULL; |
| 1245 | } |
| 1246 | return px; |
| 1247 | } |
| 1248 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1249 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 1250 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1251 | * 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] | 1252 | * the <arg> is modified to remove the '/'. |
| 1253 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1254 | 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] | 1255 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1256 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1257 | struct proxy *px; |
| 1258 | struct server *sv; |
| 1259 | char *line; |
| 1260 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1261 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1262 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1263 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1264 | return NULL; |
| 1265 | } |
| 1266 | |
| 1267 | /* split "backend/server" and make <line> point to server */ |
| 1268 | for (line = arg; *line; line++) |
| 1269 | if (*line == '/') { |
| 1270 | *line++ = '\0'; |
| 1271 | break; |
| 1272 | } |
| 1273 | |
| 1274 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1275 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1276 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1277 | return NULL; |
| 1278 | } |
| 1279 | |
| 1280 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1281 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1282 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1283 | return NULL; |
| 1284 | } |
| 1285 | |
| 1286 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1287 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 1288 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1289 | return NULL; |
| 1290 | } |
| 1291 | |
| 1292 | return sv; |
| 1293 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1294 | |
| 1295 | /* This function is used with TLS ticket keys management. It permits to browse |
| 1296 | * each reference. The variable <getnext> must contain the current node, |
| 1297 | * <end> point to the root node. |
| 1298 | */ |
| 1299 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1300 | static inline |
| 1301 | struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end) |
| 1302 | { |
| 1303 | struct tls_keys_ref *ref = getnext; |
| 1304 | |
| 1305 | while (1) { |
| 1306 | |
| 1307 | /* Get next list entry. */ |
| 1308 | ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list); |
| 1309 | |
| 1310 | /* If the entry is the last of the list, return NULL. */ |
| 1311 | if (&ref->list == end) |
| 1312 | return NULL; |
| 1313 | |
| 1314 | return ref; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | static inline |
| 1319 | struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference) |
| 1320 | { |
| 1321 | int id; |
| 1322 | char *error; |
| 1323 | |
| 1324 | /* If the reference starts by a '#', this is numeric id. */ |
| 1325 | if (reference[0] == '#') { |
| 1326 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1327 | id = strtol(reference + 1, &error, 10); |
| 1328 | if (*error != '\0') |
| 1329 | return NULL; |
| 1330 | |
| 1331 | /* Perform the unique id lookup. */ |
| 1332 | return tlskeys_ref_lookupid(id); |
| 1333 | } |
| 1334 | |
| 1335 | /* Perform the string lookup. */ |
| 1336 | return tlskeys_ref_lookup(reference); |
| 1337 | } |
| 1338 | #endif |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1339 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1340 | /* This function is used with map and acl management. It permits to browse |
| 1341 | * each reference. The variable <getnext> must contain the current node, |
| 1342 | * <end> point to the root node and the <flags> permit to filter required |
| 1343 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1344 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1345 | static inline |
| 1346 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1347 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1348 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1349 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1350 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1351 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1352 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1353 | /* Get next list entry. */ |
| 1354 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1355 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1356 | /* If the entry is the last of the list, return NULL. */ |
| 1357 | if (&ref->list == end) |
| 1358 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1359 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1360 | /* If the entry match the flag, return it. */ |
| 1361 | if (ref->flags & flags) |
| 1362 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1363 | } |
| 1364 | } |
| 1365 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1366 | static inline |
| 1367 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1368 | { |
| 1369 | int id; |
| 1370 | char *error; |
| 1371 | |
| 1372 | /* If the reference starts by a '#', this is numeric id. */ |
| 1373 | if (reference[0] == '#') { |
| 1374 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1375 | id = strtol(reference + 1, &error, 10); |
| 1376 | if (*error != '\0') |
| 1377 | return NULL; |
| 1378 | |
| 1379 | /* Perform the unique id lookup. */ |
| 1380 | return pat_ref_lookupid(id); |
| 1381 | } |
| 1382 | |
| 1383 | /* Perform the string lookup. */ |
| 1384 | return pat_ref_lookup(reference); |
| 1385 | } |
| 1386 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1387 | /* This function is used with map and acl management. It permits to browse |
| 1388 | * each reference. |
| 1389 | */ |
| 1390 | static inline |
| 1391 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1392 | { |
| 1393 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1394 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1395 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1396 | return NULL; |
| 1397 | return expr; |
| 1398 | } |
| 1399 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1400 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1401 | * 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] | 1402 | * 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] | 1403 | * designating the function which will have to process the request, which can |
| 1404 | * 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] | 1405 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1406 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1407 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1408 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1409 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1410 | char *args[MAX_STATS_ARGS + 1]; |
| 1411 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1412 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1413 | |
| 1414 | while (isspace((unsigned char)*line)) |
| 1415 | line++; |
| 1416 | |
| 1417 | arg = 0; |
| 1418 | args[arg] = line; |
| 1419 | |
| 1420 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1421 | if (*line == '\\') { |
| 1422 | line++; |
| 1423 | if (*line == '\0') |
| 1424 | break; |
| 1425 | } |
| 1426 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1427 | *line++ = '\0'; |
| 1428 | |
| 1429 | while (isspace((unsigned char)*line)) |
| 1430 | line++; |
| 1431 | |
| 1432 | args[++arg] = line; |
| 1433 | continue; |
| 1434 | } |
| 1435 | |
| 1436 | line++; |
| 1437 | } |
| 1438 | |
| 1439 | while (++arg <= MAX_STATS_ARGS) |
| 1440 | args[arg] = line; |
| 1441 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1442 | /* remove \ */ |
| 1443 | arg = 0; |
| 1444 | while (*args[arg] != '\0') { |
| 1445 | j = 0; |
| 1446 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1447 | if (args[arg][i] == '\\') |
| 1448 | continue; |
| 1449 | args[arg][j] = args[arg][i]; |
| 1450 | j++; |
| 1451 | } |
| 1452 | args[arg][j] = '\0'; |
| 1453 | arg++; |
| 1454 | } |
| 1455 | |
Willy Tarreau | 6bcb95d | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1456 | appctx->ctx.stats.scope_str = 0; |
| 1457 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1458 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1459 | if (strcmp(args[0], "show") == 0) { |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 1460 | if (strcmp(args[1], "backend") == 0) { |
| 1461 | appctx->st2 = STAT_ST_INIT; |
| 1462 | appctx->st0 = STAT_CLI_O_BACKEND; |
| 1463 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 1464 | else if (strcmp(args[1], "env") == 0) { |
| 1465 | extern char **environ; |
| 1466 | |
| 1467 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
| 1468 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1469 | appctx->st0 = STAT_CLI_PRINT; |
| 1470 | return 1; |
| 1471 | } |
| 1472 | appctx->ctx.env.var = environ; |
| 1473 | appctx->st2 = STAT_ST_INIT; |
| 1474 | appctx->st0 = STAT_CLI_O_ENV; // stats_dump_env_to_buffer |
| 1475 | |
| 1476 | if (*args[2]) { |
| 1477 | int len = strlen(args[2]); |
| 1478 | |
| 1479 | for (; *appctx->ctx.env.var; appctx->ctx.env.var++) { |
| 1480 | if (strncmp(*appctx->ctx.env.var, args[2], len) == 0 && |
| 1481 | (*appctx->ctx.env.var)[len] == '=') |
| 1482 | break; |
| 1483 | } |
| 1484 | if (!*appctx->ctx.env.var) { |
| 1485 | appctx->ctx.cli.msg = "Variable not found\n"; |
| 1486 | appctx->st0 = STAT_CLI_PRINT; |
| 1487 | return 1; |
| 1488 | } |
| 1489 | appctx->st2 = STAT_ST_END; |
| 1490 | } |
| 1491 | } |
| 1492 | else if (strcmp(args[1], "stat") == 0) { |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1493 | if (strcmp(args[2], "resolvers") == 0) { |
| 1494 | struct dns_resolvers *presolvers; |
| 1495 | |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1496 | if (*args[3]) { |
| 1497 | appctx->ctx.resolvers.ptr = NULL; |
| 1498 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 1499 | if (strcmp(presolvers->id, args[3]) == 0) { |
| 1500 | appctx->ctx.resolvers.ptr = presolvers; |
| 1501 | break; |
| 1502 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1503 | } |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1504 | if (appctx->ctx.resolvers.ptr == NULL) { |
| 1505 | appctx->ctx.cli.msg = "Can't find that resolvers section\n"; |
| 1506 | appctx->st0 = STAT_CLI_PRINT; |
| 1507 | return 1; |
| 1508 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | appctx->st2 = STAT_ST_INIT; |
| 1512 | appctx->st0 = STAT_CLI_O_RESOLVERS; |
| 1513 | return 1; |
| 1514 | } |
| 1515 | else if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1516 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1517 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1518 | appctx->ctx.stats.type = atoi(args[3]); |
| 1519 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 1520 | if (strcmp(args[5], "typed") == 0) |
| 1521 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1522 | } |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 1523 | else if (strcmp(args[2], "typed") == 0) |
| 1524 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1525 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1526 | appctx->st2 = STAT_ST_INIT; |
| 1527 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1528 | } |
| 1529 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 1530 | if (strcmp(args[2], "typed") == 0) |
| 1531 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1532 | appctx->st2 = STAT_ST_INIT; |
| 1533 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1534 | } |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1535 | else if (strcmp(args[1], "servers") == 0 && strcmp(args[2], "state") == 0) { |
| 1536 | appctx->ctx.server_state.backend = NULL; |
| 1537 | |
| 1538 | /* check if a backend name has been provided */ |
| 1539 | if (*args[3]) { |
| 1540 | /* read server state from local file */ |
| 1541 | appctx->ctx.server_state.backend = proxy_be_by_name(args[3]); |
| 1542 | |
| 1543 | if (appctx->ctx.server_state.backend == NULL) { |
| 1544 | appctx->ctx.cli.msg = "Can't find backend.\n"; |
| 1545 | appctx->st0 = STAT_CLI_PRINT; |
| 1546 | return 1; |
| 1547 | } |
| 1548 | } |
| 1549 | appctx->st2 = STAT_ST_INIT; |
| 1550 | appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer |
| 1551 | return 1; |
| 1552 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1553 | else if (strcmp(args[1], "pools") == 0) { |
| 1554 | appctx->st2 = STAT_ST_INIT; |
| 1555 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1556 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1557 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1558 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1559 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1560 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1561 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1562 | return 1; |
| 1563 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1564 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1565 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1566 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1567 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1568 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1569 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1570 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1571 | appctx->ctx.sess.pos = 0; |
| 1572 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1573 | } |
| 1574 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1575 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1576 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1577 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1578 | return 1; |
| 1579 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1580 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1581 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1582 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1583 | appctx->ctx.errors.iid = -1; |
| 1584 | appctx->ctx.errors.px = NULL; |
| 1585 | appctx->st2 = STAT_ST_INIT; |
| 1586 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1587 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1588 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1589 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1590 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1591 | else if (strcmp(args[1], "tls-keys") == 0) { |
| 1592 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1593 | appctx->st2 = STAT_ST_INIT; |
| 1594 | appctx->st0 = STAT_CLI_O_TLSK; |
| 1595 | #else |
| 1596 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1597 | "that doesn't support specifying TLS ticket keys\n"; |
| 1598 | appctx->st0 = STAT_CLI_PRINT; |
| 1599 | #endif |
| 1600 | return 1; |
| 1601 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1602 | else if (strcmp(args[1], "map") == 0 || |
| 1603 | strcmp(args[1], "acl") == 0) { |
| 1604 | |
| 1605 | /* Set ACL or MAP flags. */ |
| 1606 | if (args[1][0] == 'm') |
| 1607 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1608 | else |
| 1609 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1610 | |
| 1611 | /* no parameter: display all map avalaible */ |
| 1612 | if (!*args[2]) { |
| 1613 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1614 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1615 | return 1; |
| 1616 | } |
| 1617 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1618 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1619 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1620 | if (!appctx->ctx.map.ref || |
| 1621 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1622 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1623 | 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] | 1624 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1625 | 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] | 1626 | appctx->st0 = STAT_CLI_PRINT; |
| 1627 | return 1; |
| 1628 | } |
| 1629 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1630 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1631 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1632 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1633 | return 0; |
| 1634 | } |
| 1635 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1636 | else if (strcmp(args[0], "clear") == 0) { |
| 1637 | if (strcmp(args[1], "counters") == 0) { |
| 1638 | struct proxy *px; |
| 1639 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1640 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1641 | int clrall = 0; |
| 1642 | |
| 1643 | if (strcmp(args[2], "all") == 0) |
| 1644 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1645 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1646 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1647 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1648 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1649 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1650 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1651 | return 1; |
| 1652 | } |
| 1653 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1654 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1655 | if (clrall) { |
| 1656 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1657 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1658 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1659 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1660 | px->be_counters.conn_max = 0; |
| 1661 | px->be_counters.p.http.rps_max = 0; |
| 1662 | px->be_counters.sps_max = 0; |
| 1663 | px->be_counters.cps_max = 0; |
| 1664 | px->be_counters.nbpend_max = 0; |
| 1665 | |
| 1666 | px->fe_counters.conn_max = 0; |
| 1667 | px->fe_counters.p.http.rps_max = 0; |
| 1668 | px->fe_counters.sps_max = 0; |
| 1669 | px->fe_counters.cps_max = 0; |
| 1670 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1671 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1672 | |
| 1673 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1674 | if (clrall) |
| 1675 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1676 | else { |
| 1677 | sv->counters.cur_sess_max = 0; |
| 1678 | sv->counters.nbpend_max = 0; |
| 1679 | sv->counters.sps_max = 0; |
| 1680 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1681 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1682 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1683 | if (li->counters) { |
| 1684 | if (clrall) |
| 1685 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1686 | else |
| 1687 | li->counters->conn_max = 0; |
| 1688 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1689 | } |
| 1690 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1691 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1692 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1693 | return 1; |
| 1694 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1695 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1696 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1697 | /* end of processing */ |
| 1698 | return 1; |
| 1699 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1700 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1701 | /* Set ACL or MAP flags. */ |
| 1702 | if (args[1][0] == 'm') |
| 1703 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1704 | else |
| 1705 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1706 | |
| 1707 | /* no parameter */ |
| 1708 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1709 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1710 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1711 | else |
| 1712 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1713 | appctx->st0 = STAT_CLI_PRINT; |
| 1714 | return 1; |
| 1715 | } |
| 1716 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1717 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1718 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1719 | if (!appctx->ctx.map.ref || |
| 1720 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1721 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1722 | 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] | 1723 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1724 | 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] | 1725 | appctx->st0 = STAT_CLI_PRINT; |
| 1726 | return 1; |
| 1727 | } |
| 1728 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1729 | /* Clear all. */ |
| 1730 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1731 | |
| 1732 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1733 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1734 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1735 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1736 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1737 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1738 | return 0; |
| 1739 | } |
| 1740 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1741 | else if (strcmp(args[0], "get") == 0) { |
| 1742 | if (strcmp(args[1], "weight") == 0) { |
| 1743 | struct proxy *px; |
| 1744 | struct server *sv; |
| 1745 | |
| 1746 | /* split "backend/server" and make <line> point to server */ |
| 1747 | for (line = args[2]; *line; line++) |
| 1748 | if (*line == '/') { |
| 1749 | *line++ = '\0'; |
| 1750 | break; |
| 1751 | } |
| 1752 | |
| 1753 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1754 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1755 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1756 | return 1; |
| 1757 | } |
| 1758 | |
| 1759 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1760 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1761 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1762 | return 1; |
| 1763 | } |
| 1764 | |
| 1765 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1766 | 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] | 1767 | if (bi_putstr(si_ic(si), trash.str) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 1768 | si_applet_cant_put(si); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1769 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1770 | return 1; |
| 1771 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1772 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1773 | /* Set flags. */ |
| 1774 | if (args[1][0] == 'm') |
| 1775 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1776 | else |
| 1777 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1778 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1779 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1780 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1781 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1782 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1783 | else |
| 1784 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1785 | appctx->st0 = STAT_CLI_PRINT; |
| 1786 | return 1; |
| 1787 | } |
| 1788 | |
| 1789 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1790 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1791 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1792 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1793 | 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] | 1794 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1795 | 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] | 1796 | appctx->st0 = STAT_CLI_PRINT; |
| 1797 | return 1; |
| 1798 | } |
| 1799 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1800 | /* copy input string. The string must be allocated because |
| 1801 | * it may be used over multiple iterations. It's released |
| 1802 | * at the end and upon abort anyway. |
| 1803 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1804 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1805 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1806 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1807 | if (!appctx->ctx.map.chunk.str) { |
| 1808 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1809 | appctx->st0 = STAT_CLI_PRINT; |
| 1810 | return 1; |
| 1811 | } |
| 1812 | |
| 1813 | /* prepare response */ |
| 1814 | appctx->st2 = STAT_ST_INIT; |
| 1815 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1816 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1817 | else { /* not "get weight" */ |
| 1818 | return 0; |
| 1819 | } |
| 1820 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1821 | else if (strcmp(args[0], "set") == 0) { |
| 1822 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1823 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1824 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1825 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1826 | sv = expect_server_admin(s, si, args[2]); |
| 1827 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1828 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1829 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1830 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1831 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1832 | appctx->ctx.cli.msg = warning; |
| 1833 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1834 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1835 | return 1; |
| 1836 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1837 | else if (strcmp(args[1], "server") == 0) { |
| 1838 | struct server *sv; |
| 1839 | const char *warning; |
| 1840 | |
| 1841 | sv = expect_server_admin(s, si, args[2]); |
| 1842 | if (!sv) |
| 1843 | return 1; |
| 1844 | |
| 1845 | if (strcmp(args[3], "weight") == 0) { |
| 1846 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1847 | if (warning) { |
| 1848 | appctx->ctx.cli.msg = warning; |
| 1849 | appctx->st0 = STAT_CLI_PRINT; |
| 1850 | } |
| 1851 | } |
| 1852 | else if (strcmp(args[3], "state") == 0) { |
| 1853 | if (strcmp(args[4], "ready") == 0) |
| 1854 | srv_adm_set_ready(sv); |
| 1855 | else if (strcmp(args[4], "drain") == 0) |
| 1856 | srv_adm_set_drain(sv); |
| 1857 | else if (strcmp(args[4], "maint") == 0) |
| 1858 | srv_adm_set_maint(sv); |
| 1859 | else { |
| 1860 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1861 | appctx->st0 = STAT_CLI_PRINT; |
| 1862 | } |
| 1863 | } |
| 1864 | else if (strcmp(args[3], "health") == 0) { |
| 1865 | if (sv->track) { |
| 1866 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1867 | appctx->st0 = STAT_CLI_PRINT; |
| 1868 | } |
| 1869 | else if (strcmp(args[4], "up") == 0) { |
| 1870 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1871 | srv_set_running(sv, "changed from CLI"); |
| 1872 | } |
| 1873 | else if (strcmp(args[4], "stopping") == 0) { |
| 1874 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1875 | srv_set_stopping(sv, "changed from CLI"); |
| 1876 | } |
| 1877 | else if (strcmp(args[4], "down") == 0) { |
| 1878 | sv->check.health = 0; |
| 1879 | srv_set_stopped(sv, "changed from CLI"); |
| 1880 | } |
| 1881 | else { |
| 1882 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1883 | appctx->st0 = STAT_CLI_PRINT; |
| 1884 | } |
| 1885 | } |
| 1886 | else if (strcmp(args[3], "agent") == 0) { |
| 1887 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1888 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1889 | appctx->st0 = STAT_CLI_PRINT; |
| 1890 | } |
| 1891 | else if (strcmp(args[4], "up") == 0) { |
| 1892 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1893 | srv_set_running(sv, "changed from CLI"); |
| 1894 | } |
| 1895 | else if (strcmp(args[4], "down") == 0) { |
| 1896 | sv->agent.health = 0; |
| 1897 | srv_set_stopped(sv, "changed from CLI"); |
| 1898 | } |
| 1899 | else { |
| 1900 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1901 | appctx->st0 = STAT_CLI_PRINT; |
| 1902 | } |
| 1903 | } |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1904 | else if (strcmp(args[3], "addr") == 0) { |
Thierry Fournier | 09a9178 | 2016-02-24 08:25:39 +0100 | [diff] [blame] | 1905 | warning = server_parse_addr_change_request(sv, args[4], "stats command"); |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1906 | if (warning) { |
| 1907 | appctx->ctx.cli.msg = warning; |
| 1908 | appctx->st0 = STAT_CLI_PRINT; |
| 1909 | } |
| 1910 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1911 | else { |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1912 | 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] | 1913 | appctx->st0 = STAT_CLI_PRINT; |
| 1914 | } |
| 1915 | return 1; |
| 1916 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1917 | else if (strcmp(args[1], "timeout") == 0) { |
| 1918 | if (strcmp(args[2], "cli") == 0) { |
| 1919 | unsigned timeout; |
| 1920 | const char *res; |
| 1921 | |
| 1922 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1923 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1924 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1925 | return 1; |
| 1926 | } |
| 1927 | |
| 1928 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1929 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1930 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1931 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1932 | return 1; |
| 1933 | } |
| 1934 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1935 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1936 | return 1; |
| 1937 | } |
| 1938 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1939 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1940 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1941 | return 1; |
| 1942 | } |
| 1943 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1944 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1945 | if (strcmp(args[2], "frontend") == 0) { |
| 1946 | struct proxy *px; |
| 1947 | struct listener *l; |
| 1948 | int v; |
| 1949 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1950 | px = expect_frontend_admin(s, si, args[3]); |
| 1951 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1952 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1953 | |
| 1954 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1955 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1956 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1957 | return 1; |
| 1958 | } |
| 1959 | |
| 1960 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1961 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1962 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1963 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1964 | return 1; |
| 1965 | } |
| 1966 | |
| 1967 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1968 | * its listeners. The blocked ones will be dequeued. |
| 1969 | */ |
| 1970 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1971 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1972 | l->maxconn = v; |
| 1973 | if (l->state == LI_FULL) |
| 1974 | resume_listener(l); |
| 1975 | } |
| 1976 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1977 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1978 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1979 | |
| 1980 | return 1; |
| 1981 | } |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1982 | else if (strcmp(args[2], "server") == 0) { |
| 1983 | struct server *sv; |
| 1984 | int v; |
| 1985 | |
| 1986 | sv = expect_server_admin(s, si, args[3]); |
| 1987 | if (!sv) |
| 1988 | return 1; |
| 1989 | |
| 1990 | if (!*args[4]) { |
| 1991 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1992 | appctx->st0 = STAT_CLI_PRINT; |
| 1993 | return 1; |
| 1994 | } |
| 1995 | |
| 1996 | v = atoi(args[4]); |
| 1997 | if (v < 0) { |
| 1998 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1999 | appctx->st0 = STAT_CLI_PRINT; |
| 2000 | return 1; |
| 2001 | } |
| 2002 | |
| 2003 | if (sv->maxconn == sv->minconn) { // static maxconn |
| 2004 | sv->maxconn = sv->minconn = v; |
| 2005 | } else { // dynamic maxconn |
| 2006 | sv->maxconn = v; |
| 2007 | } |
| 2008 | |
| 2009 | if (may_dequeue_tasks(sv, sv->proxy)) |
| 2010 | process_srv_queue(sv); |
| 2011 | |
| 2012 | return 1; |
| 2013 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 2014 | else if (strcmp(args[2], "global") == 0) { |
| 2015 | int v; |
| 2016 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2017 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2018 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2019 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 2020 | return 1; |
| 2021 | } |
| 2022 | |
| 2023 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2024 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2025 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 2026 | return 1; |
| 2027 | } |
| 2028 | |
| 2029 | v = atoi(args[3]); |
| 2030 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2031 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2032 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 2033 | return 1; |
| 2034 | } |
| 2035 | |
| 2036 | /* check for unlimited values */ |
| 2037 | if (v <= 0) |
| 2038 | v = global.hardmaxconn; |
| 2039 | |
| 2040 | global.maxconn = v; |
| 2041 | |
| 2042 | /* Dequeues all of the listeners waiting for a resource */ |
| 2043 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2044 | dequeue_all_listeners(&global_listener_queue); |
| 2045 | |
| 2046 | return 1; |
| 2047 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 2048 | else { |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 2049 | 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] | 2050 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 2051 | return 1; |
| 2052 | } |
| 2053 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2054 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 2055 | if (strcmp(args[2], "connections") == 0) { |
| 2056 | if (strcmp(args[3], "global") == 0) { |
| 2057 | int v; |
| 2058 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2059 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2060 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2061 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2062 | return 1; |
| 2063 | } |
| 2064 | |
| 2065 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2066 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2067 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2068 | return 1; |
| 2069 | } |
| 2070 | |
| 2071 | v = atoi(args[4]); |
| 2072 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2073 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2074 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2075 | return 1; |
| 2076 | } |
| 2077 | |
| 2078 | global.cps_lim = v; |
| 2079 | |
| 2080 | /* Dequeues all of the listeners waiting for a resource */ |
| 2081 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2082 | dequeue_all_listeners(&global_listener_queue); |
| 2083 | |
| 2084 | return 1; |
| 2085 | } |
| 2086 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2087 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 2088 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2089 | return 1; |
| 2090 | } |
| 2091 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2092 | else if (strcmp(args[2], "sessions") == 0) { |
| 2093 | if (strcmp(args[3], "global") == 0) { |
| 2094 | int v; |
| 2095 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2096 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2097 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2098 | appctx->st0 = STAT_CLI_PRINT; |
| 2099 | return 1; |
| 2100 | } |
| 2101 | |
| 2102 | if (!*args[4]) { |
| 2103 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2104 | appctx->st0 = STAT_CLI_PRINT; |
| 2105 | return 1; |
| 2106 | } |
| 2107 | |
| 2108 | v = atoi(args[4]); |
| 2109 | if (v < 0) { |
| 2110 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2111 | appctx->st0 = STAT_CLI_PRINT; |
| 2112 | return 1; |
| 2113 | } |
| 2114 | |
| 2115 | global.sps_lim = v; |
| 2116 | |
| 2117 | /* Dequeues all of the listeners waiting for a resource */ |
| 2118 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2119 | dequeue_all_listeners(&global_listener_queue); |
| 2120 | |
| 2121 | return 1; |
| 2122 | } |
| 2123 | else { |
| 2124 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 2125 | appctx->st0 = STAT_CLI_PRINT; |
| 2126 | return 1; |
| 2127 | } |
| 2128 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2129 | #ifdef USE_OPENSSL |
| 2130 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 2131 | if (strcmp(args[3], "global") == 0) { |
| 2132 | int v; |
| 2133 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2134 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2135 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2136 | appctx->st0 = STAT_CLI_PRINT; |
| 2137 | return 1; |
| 2138 | } |
| 2139 | |
| 2140 | if (!*args[4]) { |
| 2141 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2142 | appctx->st0 = STAT_CLI_PRINT; |
| 2143 | return 1; |
| 2144 | } |
| 2145 | |
| 2146 | v = atoi(args[4]); |
| 2147 | if (v < 0) { |
| 2148 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2149 | appctx->st0 = STAT_CLI_PRINT; |
| 2150 | return 1; |
| 2151 | } |
| 2152 | |
| 2153 | global.ssl_lim = v; |
| 2154 | |
| 2155 | /* Dequeues all of the listeners waiting for a resource */ |
| 2156 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2157 | dequeue_all_listeners(&global_listener_queue); |
| 2158 | |
| 2159 | return 1; |
| 2160 | } |
| 2161 | else { |
| 2162 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 2163 | appctx->st0 = STAT_CLI_PRINT; |
| 2164 | return 1; |
| 2165 | } |
| 2166 | } |
| 2167 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2168 | else if (strcmp(args[2], "http-compression") == 0) { |
| 2169 | if (strcmp(args[3], "global") == 0) { |
| 2170 | int v; |
| 2171 | |
Willy Tarreau | a1c2b2c | 2015-11-26 18:32:39 +0100 | [diff] [blame] | 2172 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 2173 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2174 | appctx->st0 = STAT_CLI_PRINT; |
| 2175 | return 1; |
| 2176 | } |
| 2177 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2178 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2179 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 2180 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2181 | return 1; |
| 2182 | } |
| 2183 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2184 | v = atoi(args[4]); |
| 2185 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 2186 | } |
| 2187 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2188 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 2189 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2190 | return 1; |
| 2191 | } |
| 2192 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2193 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2194 | 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] | 2195 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2196 | return 1; |
| 2197 | } |
| 2198 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 2199 | else if (strcmp(args[1], "table") == 0) { |
| 2200 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 2201 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2202 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2203 | char *err; |
| 2204 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2205 | /* Set flags. */ |
| 2206 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2207 | |
| 2208 | /* Expect three parameters: map name, key and new value. */ |
| 2209 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 2210 | 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] | 2211 | appctx->st0 = STAT_CLI_PRINT; |
| 2212 | return 1; |
| 2213 | } |
| 2214 | |
| 2215 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2216 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2217 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2218 | 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] | 2219 | appctx->st0 = STAT_CLI_PRINT; |
| 2220 | return 1; |
| 2221 | } |
| 2222 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2223 | /* If the entry identifier start with a '#', it is considered as |
| 2224 | * pointer id |
| 2225 | */ |
| 2226 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2227 | struct pat_ref_elt *ref; |
| 2228 | long long int conv; |
| 2229 | char *error; |
| 2230 | |
| 2231 | /* Convert argument to integer value. */ |
| 2232 | conv = strtoll(&args[3][1], &error, 16); |
| 2233 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2234 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2235 | appctx->st0 = STAT_CLI_PRINT; |
| 2236 | return 1; |
| 2237 | } |
| 2238 | |
| 2239 | /* Convert and check integer to pointer. */ |
| 2240 | ref = (struct pat_ref_elt *)(long)conv; |
| 2241 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2242 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2243 | appctx->st0 = STAT_CLI_PRINT; |
| 2244 | return 1; |
| 2245 | } |
| 2246 | |
| 2247 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2248 | err = NULL; |
| 2249 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 2250 | if (err) |
| 2251 | memprintf(&err, "%s.\n", err); |
| 2252 | appctx->ctx.cli.err = err; |
| 2253 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2254 | return 1; |
| 2255 | } |
| 2256 | } |
| 2257 | else { |
| 2258 | /* Else, use the entry identifier as pattern |
| 2259 | * string, and update the value. |
| 2260 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2261 | err = NULL; |
| 2262 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 2263 | if (err) |
| 2264 | memprintf(&err, "%s.\n", err); |
| 2265 | appctx->ctx.cli.err = err; |
| 2266 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2267 | return 1; |
| 2268 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2269 | } |
| 2270 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2271 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2272 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2273 | return 1; |
| 2274 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2275 | #ifdef USE_OPENSSL |
| 2276 | else if (strcmp(args[1], "ssl") == 0) { |
| 2277 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 2278 | #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] | 2279 | char *err = NULL; |
| 2280 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 2281 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2282 | if (!*args[3]) { |
| 2283 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 2284 | appctx->st0 = STAT_CLI_PRINT; |
| 2285 | return 1; |
| 2286 | } |
| 2287 | |
| 2288 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 2289 | if (trash.len < 0) { |
| 2290 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 2291 | appctx->st0 = STAT_CLI_PRINT; |
| 2292 | return 1; |
| 2293 | } |
| 2294 | |
| 2295 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 2296 | if (err) { |
| 2297 | memprintf(&err, "%s.\n", err); |
| 2298 | appctx->ctx.cli.err = err; |
| 2299 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 2300 | } |
| 2301 | return 1; |
| 2302 | } |
| 2303 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 2304 | appctx->st0 = STAT_CLI_PRINT; |
| 2305 | return 1; |
| 2306 | #else |
| 2307 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 2308 | appctx->st0 = STAT_CLI_PRINT; |
| 2309 | return 1; |
| 2310 | #endif |
| 2311 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2312 | else if (strcmp(args[2], "tls-key") == 0) { |
| 2313 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2314 | /* Expect two parameters: the filename and the new new TLS key in encoding */ |
| 2315 | if (!*args[3] || !*args[4]) { |
| 2316 | appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n"; |
| 2317 | appctx->st0 = STAT_CLI_PRINT; |
| 2318 | return 1; |
| 2319 | } |
| 2320 | |
| 2321 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]); |
| 2322 | if(!appctx->ctx.tlskeys.ref) { |
| 2323 | appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n"; |
| 2324 | appctx->st0 = STAT_CLI_PRINT; |
| 2325 | return 1; |
| 2326 | } |
| 2327 | |
| 2328 | trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size); |
| 2329 | if (trash.len != sizeof(struct tls_sess_key)) { |
| 2330 | appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n"; |
| 2331 | appctx->st0 = STAT_CLI_PRINT; |
| 2332 | return 1; |
| 2333 | } |
| 2334 | |
Pradeep Jindal | cc79b00 | 2015-08-20 18:25:17 +0530 | [diff] [blame] | 2335 | memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len); |
| 2336 | 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] | 2337 | |
| 2338 | appctx->ctx.cli.msg = "TLS ticket key updated!"; |
| 2339 | appctx->st0 = STAT_CLI_PRINT; |
| 2340 | return 1; |
| 2341 | #else |
| 2342 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 2343 | "that doesn't support specifying TLS ticket keys\n"; |
| 2344 | appctx->st0 = STAT_CLI_PRINT; |
| 2345 | return 1; |
| 2346 | #endif |
| 2347 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2348 | else { |
| 2349 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 2350 | appctx->st0 = STAT_CLI_PRINT; |
| 2351 | return 1; |
| 2352 | } |
| 2353 | } |
| 2354 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 2355 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 2356 | return 0; |
| 2357 | } |
| 2358 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2359 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2360 | if (strcmp(args[1], "agent") == 0) { |
| 2361 | struct server *sv; |
| 2362 | |
| 2363 | sv = expect_server_admin(s, si, args[2]); |
| 2364 | if (!sv) |
| 2365 | return 1; |
| 2366 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2367 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 2368 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 2369 | appctx->st0 = STAT_CLI_PRINT; |
| 2370 | return 1; |
| 2371 | } |
| 2372 | |
| 2373 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2374 | return 1; |
| 2375 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2376 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2377 | struct server *sv; |
| 2378 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2379 | sv = expect_server_admin(s, si, args[2]); |
| 2380 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2381 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2382 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2383 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 2384 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 2385 | appctx->st0 = STAT_CLI_PRINT; |
| 2386 | return 1; |
| 2387 | } |
| 2388 | |
| 2389 | sv->check.state |= CHK_ST_ENABLED; |
| 2390 | return 1; |
| 2391 | } |
| 2392 | else if (strcmp(args[1], "server") == 0) { |
| 2393 | struct server *sv; |
| 2394 | |
| 2395 | sv = expect_server_admin(s, si, args[2]); |
| 2396 | if (!sv) |
| 2397 | return 1; |
| 2398 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2399 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2400 | return 1; |
| 2401 | } |
| 2402 | else if (strcmp(args[1], "frontend") == 0) { |
| 2403 | struct proxy *px; |
| 2404 | |
| 2405 | px = expect_frontend_admin(s, si, args[2]); |
| 2406 | if (!px) |
| 2407 | return 1; |
| 2408 | |
| 2409 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2410 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 2411 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2412 | return 1; |
| 2413 | } |
| 2414 | |
| 2415 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2416 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 2417 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2418 | return 1; |
| 2419 | } |
| 2420 | |
| 2421 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2422 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 2423 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2424 | return 1; |
| 2425 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2426 | return 1; |
| 2427 | } |
| 2428 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2429 | 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] | 2430 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2431 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2432 | } |
| 2433 | } |
| 2434 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2435 | if (strcmp(args[1], "agent") == 0) { |
| 2436 | struct server *sv; |
| 2437 | |
| 2438 | sv = expect_server_admin(s, si, args[2]); |
| 2439 | if (!sv) |
| 2440 | return 1; |
| 2441 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2442 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2443 | return 1; |
| 2444 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2445 | else if (strcmp(args[1], "health") == 0) { |
| 2446 | struct server *sv; |
| 2447 | |
| 2448 | sv = expect_server_admin(s, si, args[2]); |
| 2449 | if (!sv) |
| 2450 | return 1; |
| 2451 | |
| 2452 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2453 | return 1; |
| 2454 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2455 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2456 | struct server *sv; |
| 2457 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2458 | sv = expect_server_admin(s, si, args[2]); |
| 2459 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2460 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2461 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2462 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2463 | return 1; |
| 2464 | } |
| 2465 | else if (strcmp(args[1], "frontend") == 0) { |
| 2466 | struct proxy *px; |
| 2467 | |
| 2468 | px = expect_frontend_admin(s, si, args[2]); |
| 2469 | if (!px) |
| 2470 | return 1; |
| 2471 | |
| 2472 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2473 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 2474 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2475 | return 1; |
| 2476 | } |
| 2477 | |
| 2478 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2479 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 2480 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2481 | return 1; |
| 2482 | } |
| 2483 | |
| 2484 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2485 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 2486 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2487 | return 1; |
| 2488 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2489 | return 1; |
| 2490 | } |
| 2491 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2492 | 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] | 2493 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2494 | return 1; |
| 2495 | } |
| 2496 | } |
| 2497 | else if (strcmp(args[0], "shutdown") == 0) { |
| 2498 | if (strcmp(args[1], "frontend") == 0) { |
| 2499 | struct proxy *px; |
| 2500 | |
| 2501 | px = expect_frontend_admin(s, si, args[2]); |
| 2502 | if (!px) |
| 2503 | return 1; |
| 2504 | |
| 2505 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2506 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 2507 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2508 | return 1; |
| 2509 | } |
| 2510 | |
| 2511 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2512 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2513 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2514 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2515 | stop_proxy(px); |
| 2516 | return 1; |
| 2517 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2518 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2519 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2520 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2521 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2522 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2523 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2524 | return 1; |
| 2525 | } |
| 2526 | |
| 2527 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2528 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2529 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2530 | return 1; |
| 2531 | } |
| 2532 | |
| 2533 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2534 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2535 | /* first, look for the requested stream in the stream table */ |
| 2536 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2537 | if (sess == ptr) |
| 2538 | break; |
| 2539 | } |
| 2540 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2541 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2542 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2543 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2544 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2545 | return 1; |
| 2546 | } |
| 2547 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2548 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2549 | return 1; |
| 2550 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2551 | else if (strcmp(args[1], "sessions") == 0) { |
| 2552 | if (strcmp(args[2], "server") == 0) { |
| 2553 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2554 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2555 | |
| 2556 | sv = expect_server_admin(s, si, args[3]); |
| 2557 | if (!sv) |
| 2558 | return 1; |
| 2559 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2560 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2561 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2562 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2563 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2564 | |
| 2565 | return 1; |
| 2566 | } |
| 2567 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2568 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2569 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2570 | return 1; |
| 2571 | } |
| 2572 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2573 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2574 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2575 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2576 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2577 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2578 | } |
| 2579 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2580 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2581 | if (args[1][0] == 'm') |
| 2582 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2583 | else |
| 2584 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2585 | |
| 2586 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2587 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2588 | if (!*args[2] || !*args[3]) { |
| 2589 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2590 | appctx->st0 = STAT_CLI_PRINT; |
| 2591 | return 1; |
| 2592 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2593 | } |
| 2594 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2595 | else { |
| 2596 | if (!*args[2] || !*args[3]) { |
| 2597 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2598 | appctx->st0 = STAT_CLI_PRINT; |
| 2599 | return 1; |
| 2600 | } |
| 2601 | } |
| 2602 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2603 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2604 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2605 | if (!appctx->ctx.map.ref || |
| 2606 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2607 | 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] | 2608 | appctx->st0 = STAT_CLI_PRINT; |
| 2609 | return 1; |
| 2610 | } |
| 2611 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2612 | /* If the entry identifier start with a '#', it is considered as |
| 2613 | * pointer id |
| 2614 | */ |
| 2615 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2616 | struct pat_ref_elt *ref; |
| 2617 | long long int conv; |
| 2618 | char *error; |
| 2619 | |
| 2620 | /* Convert argument to integer value. */ |
| 2621 | conv = strtoll(&args[3][1], &error, 16); |
| 2622 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2623 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2624 | appctx->st0 = STAT_CLI_PRINT; |
| 2625 | return 1; |
| 2626 | } |
| 2627 | |
| 2628 | /* Convert and check integer to pointer. */ |
| 2629 | ref = (struct pat_ref_elt *)(long)conv; |
| 2630 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2631 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2632 | appctx->st0 = STAT_CLI_PRINT; |
| 2633 | return 1; |
| 2634 | } |
| 2635 | |
| 2636 | /* Try to delete the entry. */ |
| 2637 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2638 | /* The entry is not found, send message. */ |
| 2639 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2640 | appctx->st0 = STAT_CLI_PRINT; |
| 2641 | return 1; |
| 2642 | } |
| 2643 | } |
| 2644 | else { |
| 2645 | /* Else, use the entry identifier as pattern |
| 2646 | * string and try to delete the entry. |
| 2647 | */ |
| 2648 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2649 | /* The entry is not found, send message. */ |
| 2650 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2651 | appctx->st0 = STAT_CLI_PRINT; |
| 2652 | return 1; |
| 2653 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2654 | } |
| 2655 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2656 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2657 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2658 | return 1; |
| 2659 | } |
| 2660 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2661 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2662 | appctx->st0 = STAT_CLI_PRINT; |
| 2663 | return 1; |
| 2664 | } |
| 2665 | } |
| 2666 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2667 | if (strcmp(args[1], "map") == 0 || |
| 2668 | strcmp(args[1], "acl") == 0) { |
| 2669 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2670 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2671 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2672 | /* Set flags. */ |
| 2673 | if (args[1][0] == 'm') |
| 2674 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2675 | else |
| 2676 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2677 | |
| 2678 | /* If the keywork is "map", we expect three parameters, if it |
| 2679 | * is "acl", we expect only two parameters |
| 2680 | */ |
| 2681 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2682 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2683 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2684 | appctx->st0 = STAT_CLI_PRINT; |
| 2685 | return 1; |
| 2686 | } |
| 2687 | } |
| 2688 | else { |
| 2689 | if (!*args[2] || !*args[3]) { |
| 2690 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2691 | appctx->st0 = STAT_CLI_PRINT; |
| 2692 | return 1; |
| 2693 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2694 | } |
| 2695 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2696 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2697 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2698 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2699 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2700 | 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] | 2701 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2702 | 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] | 2703 | appctx->st0 = STAT_CLI_PRINT; |
| 2704 | return 1; |
| 2705 | } |
| 2706 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2707 | /* The command "add acl" is prohibited if the reference |
| 2708 | * use samples. |
| 2709 | */ |
| 2710 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2711 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2712 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2713 | "You must use the command 'add map' to add values.\n"; |
| 2714 | appctx->st0 = STAT_CLI_PRINT; |
| 2715 | return 1; |
| 2716 | } |
| 2717 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2718 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2719 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2720 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2721 | 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] | 2722 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2723 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2724 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2725 | if (err) |
| 2726 | memprintf(&err, "%s.\n", err); |
| 2727 | appctx->ctx.cli.err = err; |
| 2728 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2729 | return 1; |
| 2730 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2731 | |
| 2732 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2733 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2734 | return 1; |
| 2735 | } |
| 2736 | else { /* unknown "del" parameter */ |
| 2737 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2738 | appctx->st0 = STAT_CLI_PRINT; |
| 2739 | return 1; |
| 2740 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2741 | } |
| 2742 | 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] | 2743 | return 0; |
| 2744 | } |
| 2745 | return 1; |
| 2746 | } |
| 2747 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2748 | /* 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] | 2749 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2750 | * state machine handling requests and various responses. We read a request, |
| 2751 | * 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] | 2752 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2753 | * 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] | 2754 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2755 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2756 | static void cli_io_handler(struct appctx *appctx) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2757 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2758 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2759 | struct channel *req = si_oc(si); |
| 2760 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2761 | int reql; |
| 2762 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2763 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2764 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2765 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2766 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2767 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2768 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2769 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2770 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2771 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2772 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2773 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2774 | /* Let's close for real now. We just close the request |
| 2775 | * side, the conditions below will complete if needed. |
| 2776 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2777 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2778 | break; |
| 2779 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2780 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2781 | /* ensure we have some output room left in the event we |
| 2782 | * would want to return some info right after parsing. |
| 2783 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2784 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2785 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2786 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2787 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2788 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2789 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2790 | if (reql <= 0) { /* closed or EOL not found */ |
| 2791 | if (reql == 0) |
| 2792 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2793 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2794 | continue; |
| 2795 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2796 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2797 | /* seek for a possible semi-colon. If we find one, we |
| 2798 | * replace it with an LF and skip only this part. |
| 2799 | */ |
| 2800 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2801 | if (trash.str[len] == ';') { |
| 2802 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2803 | reql = len + 1; |
| 2804 | break; |
| 2805 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2806 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2807 | /* now it is time to check that we have a full line, |
| 2808 | * remove the trailing \n and possibly \r, then cut the |
| 2809 | * line. |
| 2810 | */ |
| 2811 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2812 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2813 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2814 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2815 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2816 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2817 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2818 | len--; |
| 2819 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2820 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2821 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2822 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2823 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2824 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2825 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2826 | continue; |
| 2827 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2828 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2829 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2830 | else if (strcmp(trash.str, "help") == 0 || |
| 2831 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2832 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2833 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2834 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2835 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2836 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2837 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2838 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2839 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2840 | /* if prompt is disabled, print help on empty lines, |
| 2841 | * so that the user at least knows how to enable |
| 2842 | * prompt and find help. |
| 2843 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2844 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2845 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2849 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2850 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2851 | } |
Willy Tarreau | 68c00c7 | 2015-09-25 19:21:19 +0200 | [diff] [blame] | 2852 | else { /* output functions */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2853 | switch (appctx->st0) { |
Andrew Hayworth | e32d186 | 2015-10-02 15:08:10 +0000 | [diff] [blame] | 2854 | case STAT_CLI_PROMPT: |
| 2855 | break; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2856 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2857 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2858 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2859 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2860 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2861 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2862 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2863 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2864 | free(appctx->ctx.cli.err); |
| 2865 | appctx->st0 = STAT_CLI_PROMPT; |
| 2866 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2867 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2868 | si_applet_cant_put(si); |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2869 | break; |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 2870 | case STAT_CLI_O_BACKEND: |
| 2871 | if (stats_dump_backend_to_buffer(si)) |
| 2872 | appctx->st0 = STAT_CLI_PROMPT; |
| 2873 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2874 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2875 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2876 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2877 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2878 | case STAT_CLI_O_SERVERS_STATE: |
| 2879 | if (stats_dump_servers_state_to_buffer(si)) |
| 2880 | appctx->st0 = STAT_CLI_PROMPT; |
| 2881 | break; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2882 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2883 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2884 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2885 | break; |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 2886 | case STAT_CLI_O_RESOLVERS: |
| 2887 | if (stats_dump_resolvers_to_buffer(si)) |
| 2888 | appctx->st0 = STAT_CLI_PROMPT; |
| 2889 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2890 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2891 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2892 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2893 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2894 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2895 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2896 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2897 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2898 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2899 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2900 | if (stats_table_request(si, appctx->st0)) |
| 2901 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2902 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2903 | case STAT_CLI_O_PATS: |
| 2904 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2905 | appctx->st0 = STAT_CLI_PROMPT; |
| 2906 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2907 | case STAT_CLI_O_PAT: |
| 2908 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2909 | appctx->st0 = STAT_CLI_PROMPT; |
| 2910 | break; |
| 2911 | case STAT_CLI_O_MLOOK: |
| 2912 | if (stats_map_lookup(si)) |
| 2913 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2914 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2915 | case STAT_CLI_O_POOLS: |
| 2916 | if (stats_dump_pools_to_buffer(si)) |
| 2917 | appctx->st0 = STAT_CLI_PROMPT; |
| 2918 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2919 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2920 | case STAT_CLI_O_TLSK: |
| 2921 | if (stats_tlskeys_list(si)) |
| 2922 | appctx->st0 = STAT_CLI_PROMPT; |
| 2923 | break; |
| 2924 | #endif |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 2925 | case STAT_CLI_O_ENV: /* environment dump */ |
| 2926 | if (stats_dump_env_to_buffer(si)) |
| 2927 | appctx->st0 = STAT_CLI_PROMPT; |
| 2928 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2929 | default: /* abnormal state */ |
Willy Tarreau | 5cfa3bc | 2015-09-25 20:08:51 +0200 | [diff] [blame] | 2930 | si->flags |= SI_FL_ERR; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2931 | break; |
| 2932 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2933 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2934 | /* 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] | 2935 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2936 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2937 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2938 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2939 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2940 | } |
| 2941 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2942 | /* 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] | 2943 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2944 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2945 | |
| 2946 | /* Now we close the output if one of the writers did so, |
| 2947 | * or if we're not in interactive mode and the request |
| 2948 | * buffer is empty. This still allows pipelined requests |
| 2949 | * to be sent in non-interactive mode. |
| 2950 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2951 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2952 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2953 | continue; |
| 2954 | } |
| 2955 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2956 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2957 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2958 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2959 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2960 | |
Willy Tarreau | c9e930a | 2015-09-25 20:06:08 +0200 | [diff] [blame] | 2961 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2962 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2963 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2964 | /* 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] | 2965 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2966 | * we forward the close to the request side so that it flows upstream to |
| 2967 | * the client. |
| 2968 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2969 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2970 | } |
| 2971 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2972 | 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] | 2973 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2974 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2975 | /* We have no more processing to do, and nothing more to send, and |
| 2976 | * the client side has closed. So we'll forward this state downstream |
| 2977 | * on the response buffer. |
| 2978 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2979 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2980 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2981 | } |
| 2982 | |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 2983 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2984 | 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] | 2985 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2986 | 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] | 2987 | } |
| 2988 | |
Willy Tarreau | 638d40a | 2016-02-24 23:11:01 +0100 | [diff] [blame] | 2989 | /* Emits a stats field without any surrounding element and properly encoded to |
| 2990 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 2991 | */ |
Willy Tarreau | b47785f | 2016-02-24 23:28:31 +0100 | [diff] [blame] | 2992 | int stats_emit_raw_data_field(struct chunk *out, const struct field *f) |
Willy Tarreau | 638d40a | 2016-02-24 23:11:01 +0100 | [diff] [blame] | 2993 | { |
| 2994 | switch (field_format(f, 0)) { |
| 2995 | case FF_EMPTY: return 1; |
| 2996 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 2997 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 2998 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 2999 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
| 3000 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 3001 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 3002 | } |
| 3003 | } |
| 3004 | |
Willy Tarreau | b47785f | 2016-02-24 23:28:31 +0100 | [diff] [blame] | 3005 | /* Emits a stats field prefixed with its type. No CSV encoding is prepared, the |
| 3006 | * output is supposed to be used on its own line. Returns non-zero on success, 0 |
| 3007 | * if the buffer is full. |
| 3008 | */ |
| 3009 | int stats_emit_typed_data_field(struct chunk *out, const struct field *f) |
| 3010 | { |
| 3011 | switch (field_format(f, 0)) { |
| 3012 | case FF_EMPTY: return 1; |
| 3013 | case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32); |
| 3014 | case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32); |
| 3015 | case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64); |
| 3016 | case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64); |
| 3017 | case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0)); |
| 3018 | default: return chunk_appendf(out, "%08x:?", f->type); |
| 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | /* Emits an encoding of the field type on 3 characters followed by a delimiter. |
| 3023 | * Returns non-zero on success, 0 if the buffer is full. |
| 3024 | */ |
| 3025 | int stats_emit_field_tags(struct chunk *out, const struct field *f, char delim) |
| 3026 | { |
| 3027 | char origin, nature, scope; |
| 3028 | |
| 3029 | switch (field_origin(f, 0)) { |
| 3030 | case FO_METRIC: origin = 'M'; break; |
| 3031 | case FO_STATUS: origin = 'S'; break; |
| 3032 | case FO_KEY: origin = 'K'; break; |
| 3033 | case FO_CONFIG: origin = 'C'; break; |
| 3034 | case FO_PRODUCT: origin = 'P'; break; |
| 3035 | default: origin = '?'; break; |
| 3036 | } |
| 3037 | |
| 3038 | switch (field_nature(f, 0)) { |
| 3039 | case FN_GAUGE: nature = 'G'; break; |
| 3040 | case FN_LIMIT: nature = 'L'; break; |
| 3041 | case FN_MIN: nature = 'm'; break; |
| 3042 | case FN_MAX: nature = 'M'; break; |
| 3043 | case FN_RATE: nature = 'R'; break; |
| 3044 | case FN_COUNTER: nature = 'C'; break; |
| 3045 | case FN_DURATION: nature = 'D'; break; |
| 3046 | case FN_AGE: nature = 'A'; break; |
| 3047 | case FN_TIME: nature = 'T'; break; |
| 3048 | case FN_NAME: nature = 'N'; break; |
| 3049 | case FN_OUTPUT: nature = 'O'; break; |
| 3050 | case FN_AVG: nature = 'a'; break; |
| 3051 | default: nature = '?'; break; |
| 3052 | } |
| 3053 | |
| 3054 | switch (field_scope(f, 0)) { |
| 3055 | case FS_PROCESS: scope = 'P'; break; |
| 3056 | case FS_SERVICE: scope = 'S'; break; |
| 3057 | case FS_SYSTEM: scope = 's'; break; |
| 3058 | case FS_CLUSTER: scope = 'C'; break; |
| 3059 | default: scope = '?'; break; |
| 3060 | } |
| 3061 | |
| 3062 | return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim); |
| 3063 | } |
| 3064 | |
Willy Tarreau | bf95cba | 2016-01-11 18:27:29 +0100 | [diff] [blame] | 3065 | /* Dump all fields from <info> into <out> using the "show info" format (name: value) */ |
| 3066 | static int stats_dump_info_fields(struct chunk *out, const struct field *info) |
| 3067 | { |
| 3068 | int field; |
| 3069 | |
| 3070 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 3071 | if (!field_format(info, field)) |
| 3072 | continue; |
| 3073 | |
| 3074 | if (!chunk_appendf(out, "%s: ", info_field_names[field])) |
| 3075 | return 0; |
| 3076 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 3077 | return 0; |
| 3078 | if (!chunk_strcat(out, "\n")) |
| 3079 | return 0; |
| 3080 | } |
| 3081 | return 1; |
| 3082 | } |
| 3083 | |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 3084 | /* Dump all fields from <info> into <out> using the "show info typed" format */ |
| 3085 | static int stats_dump_typed_info_fields(struct chunk *out, const struct field *info) |
| 3086 | { |
| 3087 | int field; |
| 3088 | |
| 3089 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 3090 | if (!field_format(info, field)) |
| 3091 | continue; |
| 3092 | |
| 3093 | if (!chunk_appendf(out, "%d.%s.%u:", field, info_field_names[field], info[INF_PROCESS_NUM].u.u32)) |
| 3094 | return 0; |
| 3095 | if (!stats_emit_field_tags(out, &info[field], ':')) |
| 3096 | return 0; |
| 3097 | if (!stats_emit_typed_data_field(out, &info[field])) |
| 3098 | return 0; |
| 3099 | if (!chunk_strcat(out, "\n")) |
| 3100 | return 0; |
| 3101 | } |
| 3102 | return 1; |
| 3103 | } |
| 3104 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3105 | /* This function dumps information onto the stream interface's read buffer. |
| 3106 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 3107 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3108 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3109 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3110 | { |
| 3111 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 3112 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 3113 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3114 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 3115 | #ifdef USE_OPENSSL |
| 3116 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 3117 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 3118 | int ssl_reuse = 0; |
| 3119 | |
| 3120 | if (ssl_key_rate < ssl_sess_rate) { |
| 3121 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 3122 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 3123 | } |
| 3124 | #endif |
| 3125 | |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 3126 | chunk_reset(out); |
| 3127 | memset(&info, 0, sizeof(info)); |
| 3128 | |
| 3129 | info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME); |
| 3130 | info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_VERSION); |
| 3131 | info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_DATE); |
| 3132 | |
| 3133 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc); |
| 3134 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid); |
| 3135 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 3136 | |
| 3137 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
| 3138 | chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); |
| 3139 | |
| 3140 | info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up); |
| 3141 | info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); |
| 3142 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
| 3143 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
| 3144 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 3145 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 3146 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 3147 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 3148 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 3149 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 3150 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 3151 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 3152 | #ifdef USE_OPENSSL |
| 3153 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
| 3154 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns); |
| 3155 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns); |
| 3156 | #endif |
| 3157 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 3158 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 3159 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
| 3160 | info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec)); |
| 3161 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 3162 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
| 3163 | info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec)); |
| 3164 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 3165 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 3166 | |
| 3167 | #ifdef USE_OPENSSL |
| 3168 | info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate); |
| 3169 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 3170 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
| 3171 | info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate); |
| 3172 | info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max); |
| 3173 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse); |
| 3174 | info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec)); |
| 3175 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 3176 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 3177 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 3178 | #endif |
| 3179 | info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in)); |
| 3180 | info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out)); |
| 3181 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 3182 | #ifdef USE_ZLIB |
| 3183 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 3184 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 3185 | #endif |
| 3186 | info[INF_TASKS] = mkf_u32(0, nb_tasks_cur); |
| 3187 | info[INF_RUN_QUEUE] = mkf_u32(0, run_queue_cur); |
| 3188 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, idle_pct); |
| 3189 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 3190 | if (global.desc) |
| 3191 | info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc); |
| 3192 | |
Willy Tarreau | 1b4ba1e | 2016-01-11 18:29:04 +0100 | [diff] [blame] | 3193 | chunk_reset(&trash); |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 3194 | |
| 3195 | if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
| 3196 | stats_dump_typed_info_fields(&trash, info); |
| 3197 | else |
| 3198 | stats_dump_info_fields(&trash, info); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3199 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3200 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3201 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3202 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3203 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3204 | |
| 3205 | return 1; |
| 3206 | } |
| 3207 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3208 | /* dumps server state information into <buf> for all the servers found in <backend> |
| 3209 | * These information are all the parameters which may change during HAProxy runtime. |
| 3210 | * By default, we only export to the last known server state file format. |
| 3211 | * These information can be used at next startup to recover same level of server state. |
| 3212 | */ |
| 3213 | static void dump_servers_state(struct proxy *backend, struct chunk *buf) |
| 3214 | { |
| 3215 | struct server *srv; |
| 3216 | char srv_addr[INET6_ADDRSTRLEN + 1]; |
| 3217 | time_t srv_time_since_last_change; |
| 3218 | int bk_f_forced_id, srv_f_forced_id; |
| 3219 | |
| 3220 | /* we don't want to report any state if the backend is not enabled on this process */ |
| 3221 | if (backend->bind_proc && !(backend->bind_proc & (1UL << (relative_pid - 1)))) |
| 3222 | return; |
| 3223 | |
| 3224 | srv = backend->srv; |
| 3225 | |
| 3226 | while (srv) { |
| 3227 | srv_addr[0] = '\0'; |
| 3228 | srv_time_since_last_change = 0; |
| 3229 | bk_f_forced_id = 0; |
| 3230 | srv_f_forced_id = 0; |
| 3231 | |
| 3232 | switch (srv->addr.ss_family) { |
| 3233 | case AF_INET: |
| 3234 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr, |
| 3235 | srv_addr, INET_ADDRSTRLEN + 1); |
| 3236 | break; |
| 3237 | case AF_INET6: |
| 3238 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr, |
| 3239 | srv_addr, INET6_ADDRSTRLEN + 1); |
| 3240 | break; |
| 3241 | } |
| 3242 | srv_time_since_last_change = now.tv_sec - srv->last_change; |
| 3243 | bk_f_forced_id = backend->options & PR_O_FORCED_ID ? 1 : 0; |
| 3244 | srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0; |
| 3245 | |
| 3246 | chunk_appendf(buf, |
| 3247 | "%d %s " |
| 3248 | "%d %s %s " |
| 3249 | "%d %d %d %d %ld " |
| 3250 | "%d %d %d %d %d " |
| 3251 | "%d %d" |
| 3252 | "\n", |
| 3253 | backend->uuid, backend->id, |
| 3254 | srv->puid, srv->id, srv_addr, |
David Carlier | 081b336 | 2015-11-18 06:10:22 +0000 | [diff] [blame] | 3255 | 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] | 3256 | srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state, |
| 3257 | bk_f_forced_id, srv_f_forced_id); |
| 3258 | |
| 3259 | srv = srv->next; |
| 3260 | } |
| 3261 | } |
| 3262 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3263 | /* Parses backend list and simply report backend names */ |
| 3264 | static int stats_dump_backend_to_buffer(struct stream_interface *si) |
| 3265 | { |
| 3266 | extern struct proxy *proxy; |
| 3267 | struct proxy *curproxy; |
| 3268 | |
| 3269 | chunk_reset(&trash); |
| 3270 | chunk_printf(&trash, "# name\n"); |
| 3271 | |
| 3272 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 3273 | /* looking for backends only */ |
| 3274 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3275 | continue; |
| 3276 | |
| 3277 | /* we don't want to list a backend which is bound to this process */ |
| 3278 | if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1)))) |
| 3279 | continue; |
| 3280 | |
| 3281 | chunk_appendf(&trash, "%s\n", curproxy->id); |
| 3282 | } |
| 3283 | |
| 3284 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3285 | si_applet_cant_put(si); |
| 3286 | return 0; |
| 3287 | } |
| 3288 | |
| 3289 | return 1; |
| 3290 | } |
| 3291 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3292 | /* Parses backend list or simply use backend name provided by the user to return |
| 3293 | * states of servers to stdout. |
| 3294 | */ |
| 3295 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si) |
| 3296 | { |
| 3297 | struct appctx *appctx = __objt_appctx(si->end); |
| 3298 | extern struct proxy *proxy; |
| 3299 | struct proxy *curproxy; |
| 3300 | |
| 3301 | chunk_reset(&trash); |
| 3302 | |
| 3303 | chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); |
| 3304 | |
| 3305 | if (appctx->ctx.server_state.backend) { |
| 3306 | dump_servers_state(appctx->ctx.server_state.backend, &trash); |
| 3307 | } |
| 3308 | else { |
| 3309 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 3310 | /* servers are only in backends */ |
| 3311 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3312 | continue; |
| 3313 | |
| 3314 | dump_servers_state(curproxy, &trash); |
| 3315 | } |
| 3316 | } |
| 3317 | |
| 3318 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3319 | si_applet_cant_put(si); |
| 3320 | return 0; |
| 3321 | } |
| 3322 | |
| 3323 | return 1; |
| 3324 | } |
| 3325 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3326 | /* This function dumps memory usage information onto the stream interface's |
| 3327 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 3328 | * completion. No state is used. |
| 3329 | */ |
| 3330 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 3331 | { |
| 3332 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3333 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3334 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3335 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3336 | } |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 3337 | return 1; |
| 3338 | } |
| 3339 | |
| 3340 | /* Dump all fields from <stats> into <out> using CSV format */ |
| 3341 | static int stats_dump_fields_csv(struct chunk *out, const struct field *stats) |
| 3342 | { |
| 3343 | int field; |
| 3344 | |
| 3345 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3346 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 3347 | return 0; |
| 3348 | if (!chunk_strcat(out, ",")) |
| 3349 | return 0; |
| 3350 | } |
| 3351 | chunk_strcat(&trash, "\n"); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3352 | return 1; |
| 3353 | } |
| 3354 | |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 3355 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
| 3356 | static int stats_dump_fields_typed(struct chunk *out, const struct field *stats) |
| 3357 | { |
| 3358 | int field; |
| 3359 | |
| 3360 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3361 | if (!stats[field].type) |
| 3362 | continue; |
| 3363 | |
| 3364 | chunk_appendf(out, "%c.%u.%u.%d.%s.%u:", |
| 3365 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' : |
| 3366 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' : |
| 3367 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' : |
| 3368 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' : |
| 3369 | '?', |
| 3370 | stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, |
| 3371 | field, stat_field_names[field], stats[ST_F_PID].u.u32); |
| 3372 | |
| 3373 | if (!stats_emit_field_tags(out, &stats[field], ':')) |
| 3374 | return 0; |
| 3375 | if (!stats_emit_typed_data_field(out, &stats[field])) |
| 3376 | return 0; |
| 3377 | if (!chunk_strcat(out, "\n")) |
| 3378 | return 0; |
| 3379 | } |
| 3380 | return 1; |
| 3381 | } |
| 3382 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3383 | /* Dump all fields from <stats> into <out> using the HTML format. A column is |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3384 | * reserved for the checkbox is ST_SHOWADMIN is set in <flags>. Some extra info |
| 3385 | * are provided if ST_SHLGNDS is present in <flags>. |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3386 | */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3387 | static int stats_dump_fields_html(struct chunk *out, const struct field *stats, unsigned int flags) |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3388 | { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3389 | struct chunk src; |
| 3390 | |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3391 | if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3392 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3393 | /* name, queue */ |
| 3394 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3395 | |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3396 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3397 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3398 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3399 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3400 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3401 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3402 | "<td class=ac>" |
| 3403 | "<a name=\"%s/Frontend\"></a>" |
| 3404 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 3405 | "<td colspan=3></td>" |
| 3406 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3407 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3408 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3409 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3410 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3411 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3412 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 3413 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 3414 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3415 | U2H(stats[ST_F_RATE].u.u32), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3416 | U2H(stats[ST_F_CONN_RATE].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3417 | U2H(stats[ST_F_RATE].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3418 | |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3419 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3420 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3421 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3422 | U2H(stats[ST_F_REQ_RATE].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3423 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3424 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3425 | "</table></div></u></td>" |
| 3426 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3427 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3428 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 3429 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 3430 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3431 | U2H(stats[ST_F_RATE_MAX].u.u32), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3432 | U2H(stats[ST_F_CONN_RATE_MAX].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3433 | U2H(stats[ST_F_RATE_MAX].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3434 | |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3435 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3436 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3437 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3438 | U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3439 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3440 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3441 | "</table></div></u></td>" |
| 3442 | /* sessions rate : limit */ |
| 3443 | "<td>%s</td>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3444 | LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3445 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3446 | chunk_appendf(out, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3447 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3448 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3449 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3450 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 3451 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3452 | "", |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3453 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3454 | U2H(stats[ST_F_STOT].u.u64), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3455 | U2H(stats[ST_F_CONN_TOT].u.u64), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3456 | U2H(stats[ST_F_STOT].u.u64)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3457 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3458 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3459 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3460 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3461 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3462 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3463 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3464 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3465 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3466 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3467 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3468 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3469 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3470 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3471 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 3472 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 3473 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 3474 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 3475 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 3476 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 3477 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 3478 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 3479 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 3480 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 3481 | U2H(stats[ST_F_INTERCEPTED].u.u64)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3482 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3483 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3484 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3485 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3486 | /* sessions: lbtot, lastsess */ |
| 3487 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3488 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3489 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3490 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3491 | U2H(stats[ST_F_BIN].u.u64)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3492 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3493 | chunk_appendf(out, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3494 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3495 | "<td>%s%s<div class=tips><table class=det>" |
| 3496 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3497 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3498 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3499 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3500 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3501 | "</table></div>%s</td>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3502 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 3503 | U2H(stats[ST_F_BOUT].u.u64), |
| 3504 | U2H(stats[ST_F_BOUT].u.u64), |
| 3505 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 3506 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 3507 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 3508 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 3509 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 3510 | stats[ST_F_BOUT].u.u64 ? (int)((stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64) * 100 / stats[ST_F_BOUT].u.u64) : 0, |
| 3511 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3512 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3513 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3514 | /* denied: req, resp */ |
| 3515 | "<td>%s</td><td>%s</td>" |
| 3516 | /* errors : request, connect, response */ |
| 3517 | "<td>%s</td><td></td><td></td>" |
| 3518 | /* warnings: retries, redispatches */ |
| 3519 | "<td></td><td></td>" |
| 3520 | /* server status : reflect frontend status */ |
| 3521 | "<td class=ac>%s</td>" |
| 3522 | /* rest of server: nothing */ |
| 3523 | "<td class=ac colspan=8></td></tr>" |
| 3524 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3525 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3526 | U2H(stats[ST_F_EREQ].u.u64), |
| 3527 | field_str(stats, ST_F_STATUS)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3528 | } |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3529 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3530 | chunk_appendf(out, "<tr class=socket>"); |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3531 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3532 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3533 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3534 | } |
| 3535 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3536 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3537 | /* frontend name, listener name */ |
| 3538 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 3539 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 3540 | "", |
| 3541 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 3542 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3543 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 3544 | |
| 3545 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3546 | chunk_appendf(out, "<div class=tips>"); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3547 | |
| 3548 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3549 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3550 | else if (*field_str(stats, ST_F_ADDR) == '[') |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3551 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3552 | else if (*field_str(stats, ST_F_ADDR)) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3553 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3554 | |
| 3555 | /* id */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3556 | chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3557 | } |
| 3558 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3559 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3560 | /* queue */ |
| 3561 | "%s</td><td colspan=3></td>" |
| 3562 | /* sessions rate: current, max, limit */ |
| 3563 | "<td colspan=3> </td>" |
| 3564 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
| 3565 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3566 | "<td>%s</td><td> </td><td> </td>" |
| 3567 | /* bytes: in, out */ |
| 3568 | "<td>%s</td><td>%s</td>" |
| 3569 | "", |
| 3570 | (flags & ST_SHLGNDS)?"</u>":"", |
| 3571 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 3572 | U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); |
| 3573 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3574 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3575 | /* denied: req, resp */ |
| 3576 | "<td>%s</td><td>%s</td>" |
| 3577 | /* errors: request, connect, response */ |
| 3578 | "<td>%s</td><td></td><td></td>" |
| 3579 | /* warnings: retries, redispatches */ |
| 3580 | "<td></td><td></td>" |
| 3581 | /* server status: reflect listener status */ |
| 3582 | "<td class=ac>%s</td>" |
| 3583 | /* rest of server: nothing */ |
| 3584 | "<td class=ac colspan=8></td></tr>" |
| 3585 | "", |
| 3586 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3587 | U2H(stats[ST_F_EREQ].u.u64), |
| 3588 | field_str(stats, ST_F_STATUS)); |
| 3589 | } |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3590 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) { |
| 3591 | const char *style; |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3592 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3593 | /* determine the style to use depending on the server's state, |
| 3594 | * its health and weight. There isn't a 1-to-1 mapping between |
| 3595 | * state and styles for the cases where the server is (still) |
| 3596 | * up. The reason is that we don't want to report nolb and |
| 3597 | * drain with the same color. |
| 3598 | */ |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3599 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3600 | if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 || |
| 3601 | strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) { |
| 3602 | style = "down"; |
| 3603 | } |
| 3604 | else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) { |
| 3605 | style = "going_up"; |
| 3606 | } |
| 3607 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) { |
| 3608 | style = "going_down"; |
| 3609 | } |
| 3610 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) { |
| 3611 | style = "nolb"; |
| 3612 | } |
| 3613 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
| 3614 | style = "no_check"; |
| 3615 | } |
| 3616 | else if (!stats[ST_F_CHKFAIL].type || |
| 3617 | stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) { |
| 3618 | /* no check or max health = UP */ |
| 3619 | if (stats[ST_F_WEIGHT].u.u32) |
| 3620 | style = "up"; |
| 3621 | else |
| 3622 | style = "draining"; |
| 3623 | } |
| 3624 | else { |
| 3625 | style = "going_down"; |
| 3626 | } |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3627 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3628 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3629 | chunk_appendf(out, "<tr class=\"maintain\">"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3630 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3631 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3632 | "<tr class=\"%s_%s\">", |
| 3633 | (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3634 | |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3635 | |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3636 | if (flags & ST_SHOWADMIN) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3637 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3638 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3639 | field_str(stats, ST_F_SVNAME)); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3640 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3641 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3642 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3643 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3644 | "", |
| 3645 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 3646 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3647 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3648 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3649 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3650 | chunk_appendf(out, "<div class=tips>"); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3651 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3652 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3653 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3654 | else if (*field_str(stats, ST_F_ADDR) == '[') |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3655 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3656 | else if (*field_str(stats, ST_F_ADDR)) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3657 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3658 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3659 | /* id */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3660 | chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3661 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3662 | /* cookie */ |
| 3663 | if (stats[ST_F_COOKIE].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3664 | chunk_appendf(out, ", cookie: '"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3665 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3666 | chunk_htmlencode(out, &src); |
| 3667 | chunk_appendf(out, "'"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3668 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3669 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3670 | chunk_appendf(out, "</div>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3671 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3672 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3673 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3674 | /* queue : current, max, limit */ |
| 3675 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
| 3676 | /* sessions rate : current, max, limit */ |
| 3677 | "<td>%s</td><td>%s</td><td></td>" |
| 3678 | "", |
| 3679 | (flags & ST_SHLGNDS) ? "</u>" : "", |
| 3680 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), |
| 3681 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
Willy Tarreau | 4607fad | 2016-01-06 15:41:29 +0100 | [diff] [blame] | 3682 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3683 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3684 | /* sessions: current, max, limit, total */ |
| 3685 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3686 | "<td><u>%s<div class=tips><table class=det>" |
| 3687 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3688 | "", |
| 3689 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
| 3690 | U2H(stats[ST_F_STOT].u.u64), |
| 3691 | U2H(stats[ST_F_STOT].u.u64)); |
Willy Tarreau | 4607fad | 2016-01-06 15:41:29 +0100 | [diff] [blame] | 3692 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3693 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3694 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3695 | unsigned long long tot; |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3696 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3697 | tot = stats[ST_F_HRSP_OTHER].u.u64; |
| 3698 | tot += stats[ST_F_HRSP_1XX].u.u64; |
| 3699 | tot += stats[ST_F_HRSP_2XX].u.u64; |
| 3700 | tot += stats[ST_F_HRSP_3XX].u.u64; |
| 3701 | tot += stats[ST_F_HRSP_4XX].u.u64; |
| 3702 | tot += stats[ST_F_HRSP_5XX].u.u64; |
| 3703 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3704 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3705 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3706 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3707 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3708 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3709 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3710 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3711 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3712 | "", |
| 3713 | U2H(tot), |
| 3714 | U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0, |
| 3715 | U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0, |
| 3716 | U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0, |
| 3717 | U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0, |
| 3718 | U2H(stats[ST_F_HRSP_5XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / tot) : 0, |
| 3719 | U2H(stats[ST_F_HRSP_OTHER].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / tot) : 0); |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3720 | } |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3721 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3722 | chunk_appendf(out, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3723 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 3724 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32)); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3725 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3726 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 3727 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32)); |
Willy Tarreau | 56a560a | 2009-09-22 19:27:35 +0200 | [diff] [blame] | 3728 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3729 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3730 | "</table></div></u></td>" |
| 3731 | /* sessions: lbtot, last */ |
| 3732 | "<td>%s</td><td>%s</td>", |
| 3733 | U2H(stats[ST_F_LBTOT].u.u64), |
| 3734 | human_time(stats[ST_F_LASTSESS].u.s32, 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3735 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3736 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3737 | /* bytes : in, out */ |
| 3738 | "<td>%s</td><td>%s</td>" |
| 3739 | /* denied: req, resp */ |
| 3740 | "<td></td><td>%s</td>" |
| 3741 | /* errors : request, connect */ |
| 3742 | "<td></td><td>%s</td>" |
| 3743 | /* errors : response */ |
| 3744 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 3745 | /* warnings: retries, redispatches */ |
| 3746 | "<td>%lld</td><td>%lld</td>" |
| 3747 | "", |
| 3748 | U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64), |
| 3749 | U2H(stats[ST_F_DRESP].u.u64), |
| 3750 | U2H(stats[ST_F_ECON].u.u64), |
| 3751 | U2H(stats[ST_F_ERESP].u.u64), |
| 3752 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 3753 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 3754 | (long long)stats[ST_F_WRETR].u.u64, |
| 3755 | (long long)stats[ST_F_WREDIS].u.u64); |
| 3756 | |
| 3757 | /* status, last change */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3758 | chunk_appendf(out, "<td class=ac>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3759 | |
| 3760 | /* FIXME!!!! |
| 3761 | * LASTCHG should contain the last change for *this* server and must be computed |
| 3762 | * properly above, as was done below, ie: this server if maint, otherwise ref server |
| 3763 | * if tracking. Note that ref is either local or remote depending on tracking. |
| 3764 | */ |
| 3765 | |
| 3766 | |
| 3767 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3768 | chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3769 | } |
| 3770 | else if (memcmp(field_str(stats, ST_F_STATUS), "no check", 5) == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3771 | chunk_strcat(out, "<i>no check</i>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3772 | } |
| 3773 | else { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3774 | chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3775 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { |
| 3776 | if (stats[ST_F_CHECK_HEALTH].u.u32) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3777 | chunk_strcat(out, " ↑"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3778 | } |
| 3779 | else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3780 | chunk_strcat(out, " ↓"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && |
| 3784 | stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3785 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3786 | "</td><td class=ac><u> %s", |
| 3787 | field_str(stats, ST_F_AGENT_STATUS)); |
| 3788 | |
| 3789 | if (stats[ST_F_AGENT_CODE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3790 | chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3791 | |
| 3792 | if (stats[ST_F_AGENT_DURATION].type && stats[ST_F_AGENT_DURATION].u.u64 >= 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3793 | chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3794 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3795 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3796 | |
| 3797 | if (*field_str(stats, ST_F_LAST_AGT)) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3798 | chunk_appendf(out, ": "); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3799 | chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3800 | chunk_htmlencode(out, &src); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3801 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3802 | chunk_appendf(out, "</div></u>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3803 | } |
| 3804 | else if (stats[ST_F_CHECK_STATUS].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3805 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3806 | "</td><td class=ac><u> %s", |
| 3807 | field_str(stats, ST_F_CHECK_STATUS)); |
| 3808 | |
| 3809 | if (stats[ST_F_CHECK_CODE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3810 | chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3811 | |
| 3812 | if (stats[ST_F_CHECK_DURATION].type && stats[ST_F_CHECK_DURATION].u.u64 >= 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3813 | chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3814 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3815 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3816 | |
| 3817 | if (*field_str(stats, ST_F_LAST_CHK)) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3818 | chunk_appendf(out, ": "); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3819 | chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3820 | chunk_htmlencode(out, &src); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3821 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3822 | chunk_appendf(out, "</div></u>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3823 | } |
| 3824 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3825 | chunk_appendf(out, "</td><td>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3826 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3827 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3828 | /* weight */ |
| 3829 | "</td><td class=ac>%d</td>" |
| 3830 | /* act, bck */ |
| 3831 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3832 | "", |
| 3833 | stats[ST_F_WEIGHT].u.u32, |
| 3834 | stats[ST_F_BCK].u.u32 ? "-" : "Y", |
| 3835 | stats[ST_F_BCK].u.u32 ? "Y" : "-"); |
| 3836 | |
| 3837 | /* check failures: unique, fatal, down time */ |
| 3838 | if (stats[ST_F_CHKFAIL].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3839 | chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3840 | |
| 3841 | if (stats[ST_F_HANAFAIL].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3842 | chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3843 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3844 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3845 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
| 3846 | "<td>%lld</td><td>%s</td>" |
| 3847 | "", |
| 3848 | stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "", |
| 3849 | (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1)); |
| 3850 | } |
| 3851 | else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { |
| 3852 | /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3853 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3854 | "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>", |
| 3855 | field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); |
| 3856 | } |
| 3857 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3858 | chunk_appendf(out, "<td colspan=3></td>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3859 | |
| 3860 | /* throttle */ |
| 3861 | if (stats[ST_F_THROTTLE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3862 | chunk_appendf(out, "<td class=ac>%d %%</td></tr>\n", stats[ST_F_THROTTLE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3863 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3864 | chunk_appendf(out, "<td class=ac>-</td></tr>\n"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3865 | } |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3866 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3867 | chunk_appendf(out, "<tr class=\"backend\">"); |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3868 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3869 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3870 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3871 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3872 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3873 | "<td class=ac>" |
| 3874 | /* name */ |
| 3875 | "%s<a name=\"%s/Backend\"></a>" |
| 3876 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3877 | "", |
| 3878 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3879 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 3880 | |
| 3881 | if (flags & ST_SHLGNDS) { |
| 3882 | /* balancing */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3883 | chunk_appendf(out, "<div class=tips>balancing: %s", |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 3884 | field_str(stats, ST_F_ALGO)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3885 | |
| 3886 | /* cookie */ |
| 3887 | if (stats[ST_F_COOKIE].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3888 | chunk_appendf(out, ", cookie: '"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3889 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3890 | chunk_htmlencode(out, &src); |
| 3891 | chunk_appendf(out, "'"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3892 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3893 | chunk_appendf(out, "</div>"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3894 | } |
| 3895 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3896 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3897 | "%s</td>" |
| 3898 | /* queue : current, max */ |
| 3899 | "<td>%s</td><td>%s</td><td></td>" |
| 3900 | /* sessions rate : current, max, limit */ |
| 3901 | "<td>%s</td><td>%s</td><td></td>" |
| 3902 | "", |
| 3903 | (flags & ST_SHLGNDS)?"</u>":"", |
| 3904 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), |
| 3905 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 3906 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3907 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3908 | /* sessions: current, max, limit, total */ |
| 3909 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3910 | "<td><u>%s<div class=tips><table class=det>" |
| 3911 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3912 | "", |
| 3913 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 3914 | U2H(stats[ST_F_STOT].u.u64), |
| 3915 | U2H(stats[ST_F_STOT].u.u64)); |
| 3916 | |
| 3917 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3918 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3919 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3920 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3921 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3922 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3923 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3924 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3925 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3926 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3927 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3928 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3929 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
| 3930 | "", |
| 3931 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 3932 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 3933 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 3934 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 3935 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 3936 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 3937 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 3938 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 3939 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 3940 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 3941 | U2H(stats[ST_F_INTERCEPTED].u.u64)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3942 | } |
| 3943 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3944 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 3945 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3946 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3947 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 3948 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3949 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3950 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3951 | "</table></div></u></td>" |
| 3952 | /* sessions: lbtot, last */ |
| 3953 | "<td>%s</td><td>%s</td>" |
| 3954 | /* bytes: in */ |
| 3955 | "<td>%s</td>" |
| 3956 | "", |
| 3957 | U2H(stats[ST_F_LBTOT].u.u64), |
| 3958 | human_time(stats[ST_F_LASTSESS].u.s32, 1), |
| 3959 | U2H(stats[ST_F_BIN].u.u64)); |
| 3960 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3961 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3962 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 3963 | "<td>%s%s<div class=tips><table class=det>" |
| 3964 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3965 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3966 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3967 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3968 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3969 | "</table></div>%s</td>", |
| 3970 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 3971 | U2H(stats[ST_F_BOUT].u.u64), |
| 3972 | U2H(stats[ST_F_BOUT].u.u64), |
| 3973 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 3974 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 3975 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 3976 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 3977 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_BYP].u.u64), |
| 3978 | stats[ST_F_BOUT].u.u64 ? (int)((stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64) * 100 / stats[ST_F_BOUT].u.u64) : 0, |
| 3979 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 3980 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3981 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3982 | /* denied: req, resp */ |
| 3983 | "<td>%s</td><td>%s</td>" |
| 3984 | /* errors : request, connect */ |
| 3985 | "<td></td><td>%s</td>" |
| 3986 | /* errors : response */ |
| 3987 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 3988 | /* warnings: retries, redispatches */ |
| 3989 | "<td>%lld</td><td>%lld</td>" |
| 3990 | /* backend status: reflect backend status (up/down): we display UP |
| 3991 | * if the backend has known working servers or if it has no server at |
| 3992 | * all (eg: for stats). Then we display the total weight, number of |
| 3993 | * active and backups. */ |
| 3994 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3995 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3996 | "", |
| 3997 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3998 | U2H(stats[ST_F_ECON].u.u64), |
| 3999 | U2H(stats[ST_F_ERESP].u.u64), |
| 4000 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 4001 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 4002 | (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64, |
| 4003 | human_time(stats[ST_F_LASTCHG].u.u32, 1), |
| 4004 | strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>", |
| 4005 | stats[ST_F_WEIGHT].u.u32, |
| 4006 | stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); |
| 4007 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 4008 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 4009 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 4010 | "<td class=ac> </td><td>%d</td>" |
| 4011 | "<td>%s</td>" |
| 4012 | "<td></td>" |
| 4013 | "</tr>", |
| 4014 | stats[ST_F_CHKDOWN].u.u32, |
| 4015 | stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : " "); |
| 4016 | } |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4017 | return 1; |
| 4018 | } |
| 4019 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4020 | static int stats_dump_one_line(const struct field *stats, unsigned int flags, struct proxy *px, struct appctx *appctx) |
| 4021 | { |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 4022 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) |
| 4023 | flags |= ST_SHOWADMIN; |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4024 | |
| 4025 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 4026 | return stats_dump_fields_html(&trash, stats, flags); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 4027 | else if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
| 4028 | return stats_dump_fields_typed(&trash, stats); |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4029 | else |
| 4030 | return stats_dump_fields_csv(&trash, stats); |
| 4031 | } |
| 4032 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4033 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 4034 | * the state from stream interface <si>. The caller is responsible for clearing |
| 4035 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4036 | */ |
| 4037 | static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) |
| 4038 | { |
| 4039 | struct appctx *appctx = __objt_appctx(si->end); |
| 4040 | |
| 4041 | if (!(px->cap & PR_CAP_FE)) |
| 4042 | return 0; |
| 4043 | |
| 4044 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE))) |
| 4045 | return 0; |
| 4046 | |
| 4047 | memset(&stats, 0, sizeof(stats)); |
| 4048 | |
| 4049 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4050 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND"); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 4051 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4052 | stats[ST_F_SCUR] = mkf_u32(0, px->feconn); |
| 4053 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 4054 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 4055 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 4056 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 4057 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 4058 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 4059 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 4060 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 4061 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP"); |
| 4062 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4063 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4064 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 4065 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 4066 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 4067 | stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 4068 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
| 4069 | |
| 4070 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4071 | if (px->mode == PR_MODE_HTTP) { |
| 4072 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
| 4073 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
| 4074 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
| 4075 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
| 4076 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
| 4077 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]); |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 4078 | stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 4082 | stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 4083 | stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 4084 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req); |
| 4085 | |
| 4086 | /* compression: in, out, bypassed, responses */ |
| 4087 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in); |
| 4088 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out); |
| 4089 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp); |
| 4090 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 4091 | |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 4092 | /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */ |
| 4093 | stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); |
| 4094 | stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 4095 | stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 4096 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4097 | return stats_dump_one_line(stats, 0, px, appctx); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 4101 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 4102 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 4103 | * otherwise. |
| 4104 | */ |
| 4105 | static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags) |
| 4106 | { |
| 4107 | struct appctx *appctx = __objt_appctx(si->end); |
| 4108 | struct chunk *out = get_trash_chunk(); |
| 4109 | |
Thierry Fournier | ac9d467 | 2016-03-25 08:43:46 +0100 | [diff] [blame] | 4110 | if (!l->counters) |
| 4111 | return 0; |
| 4112 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4113 | chunk_reset(out); |
| 4114 | memset(&stats, 0, sizeof(stats)); |
| 4115 | |
| 4116 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4117 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 4118 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4119 | stats[ST_F_SCUR] = mkf_u32(0, l->nbconn); |
| 4120 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max); |
| 4121 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn); |
| 4122 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn); |
| 4123 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in); |
| 4124 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out); |
| 4125 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req); |
| 4126 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp); |
| 4127 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req); |
| 4128 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 4129 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4130 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4131 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid); |
| 4132 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO); |
| 4133 | |
| 4134 | if (flags & ST_SHLGNDS) { |
| 4135 | char str[INET6_ADDRSTRLEN]; |
| 4136 | int port; |
| 4137 | |
| 4138 | port = get_host_port(&l->addr); |
| 4139 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 4140 | case AF_INET: |
| 4141 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4142 | chunk_appendf(out, "%s:%d", str, port); |
| 4143 | break; |
| 4144 | case AF_INET6: |
| 4145 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4146 | chunk_appendf(out, "[%s]:%d", str, port); |
| 4147 | break; |
| 4148 | case AF_UNIX: |
| 4149 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 4150 | break; |
| 4151 | case -1: |
| 4152 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4153 | chunk_strcat(out, strerror(errno)); |
| 4154 | break; |
| 4155 | default: /* address family not supported */ |
| 4156 | break; |
| 4157 | } |
| 4158 | } |
| 4159 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4160 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | enum srv_stats_state { |
| 4164 | SRV_STATS_STATE_DOWN = 0, |
| 4165 | SRV_STATS_STATE_DOWN_AGENT, |
| 4166 | SRV_STATS_STATE_GOING_UP, |
| 4167 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 4168 | SRV_STATS_STATE_UP, |
| 4169 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4170 | SRV_STATS_STATE_NOLB, |
| 4171 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 4172 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4173 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4174 | SRV_STATS_STATE_NO_CHECK, |
| 4175 | |
| 4176 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 4177 | }; |
| 4178 | |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4179 | static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 4180 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 4181 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 4182 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d", |
| 4183 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d", |
| 4184 | [SRV_STATS_STATE_UP] = "UP", |
| 4185 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d", |
| 4186 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 4187 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d", |
| 4188 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
| 4189 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
| 4190 | [SRV_STATS_STATE_NO_CHECK] = "no check" |
| 4191 | }; |
| 4192 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4193 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 4194 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 4195 | * 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] | 4196 | * if it emits anything, zero otherwise. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4197 | */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4198 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4199 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4200 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4201 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4202 | char str[INET6_ADDRSTRLEN]; |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4203 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4204 | enum srv_stats_state state; |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4205 | char *fld_status; |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4206 | /* we have "via" which is the tracked server as described in the configuration, |
| 4207 | * and "ref" which is the checked server and the end of the chain. |
| 4208 | */ |
| 4209 | via = sv->track ? sv->track : sv; |
| 4210 | ref = via; |
| 4211 | while (ref->track) |
| 4212 | ref = ref->track; |
| 4213 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4214 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 4215 | if ((ref->check.state & CHK_ST_ENABLED) && |
| 4216 | (ref->check.health < ref->check.rise + ref->check.fall - 1)) { |
| 4217 | state = SRV_STATS_STATE_UP_GOING_DOWN; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4218 | } else { |
| 4219 | state = SRV_STATS_STATE_UP; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4220 | } |
| 4221 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4222 | if (sv->admin & SRV_ADMF_DRAIN) { |
| 4223 | if (ref->agent.state & CHK_ST_ENABLED) |
| 4224 | state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4225 | else if (state == SRV_STATS_STATE_UP_GOING_DOWN) |
| 4226 | state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
| 4227 | else |
| 4228 | state = SRV_STATS_STATE_DRAIN; |
| 4229 | } |
| 4230 | |
| 4231 | if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) { |
| 4232 | state = SRV_STATS_STATE_NO_CHECK; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4233 | } |
| 4234 | } |
| 4235 | else if (sv->state == SRV_ST_STOPPING) { |
| 4236 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 4237 | (ref->check.health == ref->check.rise + ref->check.fall - 1)) { |
| 4238 | state = SRV_STATS_STATE_NOLB; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4239 | } else { |
| 4240 | state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4241 | } |
| 4242 | } |
| 4243 | else { /* stopped */ |
| 4244 | if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) { |
| 4245 | state = SRV_STATS_STATE_DOWN_AGENT; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4246 | } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) { |
| 4247 | state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4248 | } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) { |
| 4249 | state = SRV_STATS_STATE_GOING_UP; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4250 | } else { |
| 4251 | state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4252 | } |
| 4253 | } |
| 4254 | |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4255 | chunk_reset(out); |
| 4256 | memset(&stats, 0, sizeof(stats)); |
| 4257 | |
| 4258 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4259 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 4260 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4261 | stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend); |
| 4262 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 4263 | stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess); |
| 4264 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 4265 | |
| 4266 | if (sv->maxconn) |
| 4267 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 4268 | |
| 4269 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 4270 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 4271 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
| 4272 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.failed_secu); |
| 4273 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 4274 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 4275 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 4276 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
| 4277 | |
| 4278 | /* status */ |
| 4279 | fld_status = chunk_newstr(out); |
| 4280 | if (sv->admin & SRV_ADMF_IMAINT) |
| 4281 | chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id); |
| 4282 | else if (sv->admin & SRV_ADMF_MAINT) |
| 4283 | chunk_appendf(out, "MAINT"); |
| 4284 | else |
| 4285 | chunk_appendf(out, |
| 4286 | srv_hlt_st[state], |
| 4287 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 4288 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
| 4289 | |
| 4290 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4291 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change); |
| 4292 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 4293 | stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1); |
| 4294 | stats[ST_F_BCK] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4295 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4296 | /* check failures: unique, fatal; last change, total downtime */ |
| 4297 | if (sv->check.state & CHK_ST_ENABLED) { |
| 4298 | stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 4299 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 4300 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 4301 | } |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4302 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4303 | if (sv->maxqueue) |
| 4304 | stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4305 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4306 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4307 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4308 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4309 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4310 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
| 4311 | stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4312 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4313 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4314 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4315 | if (sv->track) { |
| 4316 | char *fld_track = chunk_newstr(out); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4317 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4318 | chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id); |
| 4319 | stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track); |
| 4320 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4321 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4322 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); |
| 4323 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); |
| 4324 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, sv->counters.sps_max); |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4325 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4326 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 4327 | const char *fld_chksts; |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4328 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4329 | fld_chksts = chunk_newstr(out); |
| 4330 | chunk_strcat(out, "* "); // for check in progress |
| 4331 | chunk_strcat(out, get_check_status_info(sv->check.status)); |
| 4332 | if (!(sv->check.state & CHK_ST_INPROGRESS)) |
| 4333 | fld_chksts += 2; // skip "* " |
| 4334 | stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4335 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4336 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 4337 | stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4338 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4339 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 4340 | stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4341 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4342 | stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status)); |
| 4343 | stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc); |
| 4344 | stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise); |
| 4345 | stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall); |
| 4346 | stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health); |
| 4347 | } |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4348 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4349 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 4350 | const char *fld_chksts; |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 4351 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4352 | fld_chksts = chunk_newstr(out); |
| 4353 | chunk_strcat(out, "* "); // for check in progress |
| 4354 | chunk_strcat(out, get_check_status_info(sv->agent.status)); |
| 4355 | if (!(sv->agent.state & CHK_ST_INPROGRESS)) |
| 4356 | fld_chksts += 2; // skip "* " |
| 4357 | stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4358 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4359 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 4360 | stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4361 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4362 | if (sv->agent.status >= HCHK_STATUS_CHECKED) |
| 4363 | stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4364 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4365 | stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status)); |
| 4366 | stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc); |
| 4367 | stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise); |
| 4368 | stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall); |
| 4369 | stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); |
| 4370 | } |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 4371 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4372 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4373 | if (px->mode == PR_MODE_HTTP) { |
| 4374 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 4375 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 4376 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 4377 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 4378 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 4379 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 4380 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4381 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4382 | if (ref->observe) |
| 4383 | stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana); |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4384 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4385 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 4386 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 4387 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4388 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4389 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES)); |
| 4390 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES)); |
| 4391 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES)); |
| 4392 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4393 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4394 | if (flags & ST_SHLGNDS) { |
| 4395 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 4396 | case AF_INET: |
| 4397 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4398 | chunk_appendf(out, "%s:%d", str, get_host_port(&sv->addr)); |
| 4399 | break; |
| 4400 | case AF_INET6: |
| 4401 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4402 | chunk_appendf(out, "[%s]:%d", str, get_host_port(&sv->addr)); |
| 4403 | break; |
| 4404 | case AF_UNIX: |
| 4405 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 4406 | break; |
| 4407 | case -1: |
| 4408 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4409 | chunk_strcat(out, strerror(errno)); |
| 4410 | break; |
| 4411 | default: /* address family not supported */ |
| 4412 | break; |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 4413 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4414 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4415 | if (sv->cookie) |
| 4416 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); |
| 4417 | } |
| 4418 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4419 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 4423 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 4424 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4425 | */ |
| 4426 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 4427 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4428 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4429 | |
| 4430 | if (!(px->cap & PR_CAP_BE)) |
| 4431 | return 0; |
| 4432 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4433 | 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] | 4434 | return 0; |
| 4435 | |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4436 | memset(&stats, 0, sizeof(stats)); |
| 4437 | |
| 4438 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4439 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND"); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 4440 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4441 | stats[ST_F_QCUR] = mkf_u32(0, px->nbpend); |
| 4442 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
| 4443 | stats[ST_F_SCUR] = mkf_u32(FO_CONFIG|FN_LIMIT, px->beconn); |
| 4444 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 4445 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 4446 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn); |
| 4447 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 4448 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 4449 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 4450 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 4451 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 4452 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 4453 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 4454 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
| 4455 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); |
| 4456 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 4457 | stats[ST_F_ACT] = mkf_u32(0, px->srv_act); |
| 4458 | stats[ST_F_BCK] = mkf_u32(0, px->srv_bck); |
| 4459 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans); |
| 4460 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - px->last_change); |
Willy Tarreau | 7344f47 | 2016-01-11 12:04:02 +0100 | [diff] [blame] | 4461 | if (px->srv) |
| 4462 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 4463 | |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4464 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4465 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4466 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 4467 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 4468 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); |
| 4469 | stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); |
| 4470 | stats[ST_F_RATE_MAX] = mkf_u32(0, px->be_counters.sps_max); |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 4471 | |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 4472 | if (flags & ST_SHLGNDS) { |
| 4473 | if (px->cookie_name) |
| 4474 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name); |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 4475 | stats[ST_F_ALGO] = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 4476 | } |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4477 | |
| 4478 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4479 | if (px->mode == PR_MODE_HTTP) { |
| 4480 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 4481 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 4482 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 4483 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 4484 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 4485 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 4486 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]); |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 4487 | stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->be_counters.intercepted_req); |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 4491 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 4492 | |
| 4493 | /* compression: in, out, bypassed, responses */ |
| 4494 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in); |
| 4495 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out); |
| 4496 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp); |
| 4497 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 4498 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px)); |
| 4499 | |
| 4500 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES)); |
| 4501 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES)); |
| 4502 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES)); |
| 4503 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 4504 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4505 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4506 | } |
| 4507 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4508 | /* 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] | 4509 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4510 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4511 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4512 | 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] | 4513 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4514 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4515 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4516 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4517 | 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] | 4518 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4519 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4520 | /* 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] | 4521 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4522 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4523 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4524 | 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] | 4525 | 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] | 4526 | } |
| 4527 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4528 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4529 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | /* print a new table */ |
| 4533 | chunk_appendf(&trash, |
| 4534 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4535 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4536 | "<th class=\"pxname\" width=\"10%%\">"); |
| 4537 | |
| 4538 | chunk_appendf(&trash, |
| 4539 | "<a name=\"%s\"></a>%s" |
| 4540 | "<a class=px href=\"#%s\">%s</a>", |
| 4541 | px->id, |
| 4542 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 4543 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4544 | |
| 4545 | if (uri->flags & ST_SHLGNDS) { |
| 4546 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4547 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4548 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 4549 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4550 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4551 | } |
| 4552 | |
| 4553 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4554 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4555 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 4556 | "</tr>\n" |
| 4557 | "</table>\n" |
| 4558 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4559 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4560 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 4561 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 4562 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4563 | 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] | 4564 | /* Column heading for Enable or Disable server */ |
| 4565 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4566 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4567 | |
| 4568 | chunk_appendf(&trash, |
| 4569 | "<th rowspan=2></th>" |
| 4570 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4571 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4572 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 4573 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 4574 | "<th colspan=9>Server</th>" |
| 4575 | "</tr>\n" |
| 4576 | "<tr class=\"titre\">" |
| 4577 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 4578 | "<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] | 4579 | "<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] | 4580 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 4581 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 4582 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 4583 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 4584 | "<th>Thrtle</th>\n" |
| 4585 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4586 | } |
| 4587 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4588 | /* 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] | 4589 | * 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] | 4590 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4591 | 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] | 4592 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4593 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4594 | chunk_appendf(&trash, "</table>"); |
| 4595 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4596 | 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] | 4597 | /* close the form used to enable/disable this proxy servers */ |
| 4598 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4599 | "Choose the action to perform on the checked servers : " |
| 4600 | "<select name=action>" |
| 4601 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4602 | "<option value=\"ready\">Set state to READY</option>" |
| 4603 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 4604 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4605 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 4606 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 4607 | "<option value=\"hrunn\">Health: force UP</option>" |
| 4608 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 4609 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 4610 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 4611 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 4612 | "<option value=\"arunn\">Agent: force UP</option>" |
| 4613 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4614 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 4615 | "</select>" |
| 4616 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 4617 | " <input type=\"submit\" value=\"Apply\">" |
| 4618 | "</form>", |
| 4619 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4623 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4624 | |
| 4625 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4626 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 4627 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 4628 | * buffer space, or non-zero if everything completed. This function is used |
| 4629 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 4630 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4631 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4632 | 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] | 4633 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4634 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4635 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4636 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 4637 | 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] | 4638 | struct listener *l; |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4639 | unsigned int flags; |
| 4640 | |
| 4641 | if (uri) |
| 4642 | flags = uri->flags; |
| 4643 | else if (strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) |
| 4644 | flags = ST_SHLGNDS | ST_SHNODE | ST_SHDESC; |
| 4645 | else |
| 4646 | flags = ST_SHNODE | ST_SHDESC; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4647 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4648 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4649 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4650 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4651 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4652 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4653 | if (uri && uri->scope) { |
| 4654 | /* we have a limited scope, we have to check the proxy name */ |
| 4655 | struct stat_scope *scope; |
| 4656 | int len; |
| 4657 | |
| 4658 | len = strlen(px->id); |
| 4659 | scope = uri->scope; |
| 4660 | |
| 4661 | while (scope) { |
| 4662 | /* match exact proxy name */ |
| 4663 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 4664 | break; |
| 4665 | |
| 4666 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 4667 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4668 | break; |
| 4669 | scope = scope->next; |
| 4670 | } |
| 4671 | |
| 4672 | /* proxy name not found : don't dump anything */ |
| 4673 | if (scope == NULL) |
| 4674 | return 1; |
| 4675 | } |
| 4676 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4677 | /* if the user has requested a limited output and the proxy |
| 4678 | * name does not match, skip it. |
| 4679 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4680 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4681 | 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] | 4682 | return 1; |
| 4683 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4684 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 4685 | (appctx->ctx.stats.iid != -1) && |
| 4686 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4687 | return 1; |
| 4688 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4689 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4690 | /* fall through */ |
| 4691 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4692 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4693 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4694 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4695 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4696 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4697 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4698 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4699 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4700 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4701 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4702 | /* fall through */ |
| 4703 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4704 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4705 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4706 | if (stats_dump_fe_stats(si, px)) { |
| 4707 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4708 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4709 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4710 | } |
| 4711 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4712 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4713 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 4714 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4715 | /* fall through */ |
| 4716 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4717 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4718 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4719 | 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] | 4720 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4721 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4722 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4723 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4724 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4725 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4726 | if (!l->counters) |
| 4727 | continue; |
| 4728 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4729 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4730 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4731 | break; |
| 4732 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4733 | 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] | 4734 | continue; |
| 4735 | } |
| 4736 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4737 | /* print the frontend */ |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4738 | if (stats_dump_li_stats(si, px, l, flags)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4739 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4740 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4741 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4742 | } |
| 4743 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4744 | } |
| 4745 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4746 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 4747 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4748 | /* fall through */ |
| 4749 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4750 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4751 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4752 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4753 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4754 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4755 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4756 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4757 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4758 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4759 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4760 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4761 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4762 | break; |
| 4763 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4764 | 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] | 4765 | continue; |
| 4766 | } |
| 4767 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4768 | svs = sv; |
| 4769 | while (svs->track) |
| 4770 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4771 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4772 | /* do not report servers which are DOWN and not changing state */ |
| 4773 | if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) && |
| 4774 | ((sv->admin & SRV_ADMF_MAINT) || /* server is in maintenance */ |
| 4775 | (sv->state == SRV_ST_STOPPED && /* server is down */ |
| 4776 | (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) || |
| 4777 | ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) || |
| 4778 | ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4779 | continue; |
| 4780 | } |
| 4781 | |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4782 | if (stats_dump_sv_stats(si, px, flags, sv)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4783 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4784 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4785 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4786 | } |
| 4787 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4788 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4789 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4790 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4791 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4792 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4793 | case STAT_PX_ST_BE: |
| 4794 | /* print the backend */ |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4795 | if (stats_dump_be_stats(si, px, flags)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4796 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4797 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4798 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4799 | } |
| 4800 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4801 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4802 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4803 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4804 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4805 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4806 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4807 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4808 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4809 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4810 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4811 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4812 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4813 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4814 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4815 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4816 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4817 | case STAT_PX_ST_FIN: |
| 4818 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4819 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4820 | default: |
| 4821 | /* unknown state, we should put an abort() here ! */ |
| 4822 | return 1; |
| 4823 | } |
| 4824 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4825 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4826 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4827 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4828 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4829 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4830 | { |
| 4831 | /* WARNING! This must fit in the first buffer !!! */ |
| 4832 | chunk_appendf(&trash, |
| 4833 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4834 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4835 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4836 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4837 | "<style type=\"text/css\"><!--\n" |
| 4838 | "body {" |
| 4839 | " font-family: arial, helvetica, sans-serif;" |
| 4840 | " font-size: 12px;" |
| 4841 | " font-weight: normal;" |
| 4842 | " color: black;" |
| 4843 | " background: white;" |
| 4844 | "}\n" |
| 4845 | "th,td {" |
| 4846 | " font-size: 10px;" |
| 4847 | "}\n" |
| 4848 | "h1 {" |
| 4849 | " font-size: x-large;" |
| 4850 | " margin-bottom: 0.5em;" |
| 4851 | "}\n" |
| 4852 | "h2 {" |
| 4853 | " font-family: helvetica, arial;" |
| 4854 | " font-size: x-large;" |
| 4855 | " font-weight: bold;" |
| 4856 | " font-style: italic;" |
| 4857 | " color: #6020a0;" |
| 4858 | " margin-top: 0em;" |
| 4859 | " margin-bottom: 0em;" |
| 4860 | "}\n" |
| 4861 | "h3 {" |
| 4862 | " font-family: helvetica, arial;" |
| 4863 | " font-size: 16px;" |
| 4864 | " font-weight: bold;" |
| 4865 | " color: #b00040;" |
| 4866 | " background: #e8e8d0;" |
| 4867 | " margin-top: 0em;" |
| 4868 | " margin-bottom: 0em;" |
| 4869 | "}\n" |
| 4870 | "li {" |
| 4871 | " margin-top: 0.25em;" |
| 4872 | " margin-right: 2em;" |
| 4873 | "}\n" |
| 4874 | ".hr {margin-top: 0.25em;" |
| 4875 | " border-color: black;" |
| 4876 | " border-bottom-style: solid;" |
| 4877 | "}\n" |
| 4878 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4879 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4880 | ".frontend {background: #e8e8d0;}\n" |
| 4881 | ".socket {background: #d0d0d0;}\n" |
| 4882 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4883 | ".active_down {background: #ff9090;}\n" |
| 4884 | ".active_going_up {background: #ffd020;}\n" |
| 4885 | ".active_going_down {background: #ffffa0;}\n" |
| 4886 | ".active_up {background: #c0ffc0;}\n" |
| 4887 | ".active_nolb {background: #20a0ff;}\n" |
| 4888 | ".active_draining {background: #20a0FF;}\n" |
| 4889 | ".active_no_check {background: #e0e0e0;}\n" |
| 4890 | ".backup_down {background: #ff9090;}\n" |
| 4891 | ".backup_going_up {background: #ff80ff;}\n" |
| 4892 | ".backup_going_down {background: #c060ff;}\n" |
| 4893 | ".backup_up {background: #b0d0ff;}\n" |
| 4894 | ".backup_nolb {background: #90b0e0;}\n" |
| 4895 | ".backup_draining {background: #cc9900;}\n" |
| 4896 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4897 | ".maintain {background: #c07820;}\n" |
| 4898 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4899 | "\n" |
| 4900 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4901 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4902 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4903 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4904 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4905 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4906 | "\n" |
| 4907 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4908 | "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" |
| 4909 | "table.tbl td.ac { text-align: center;}\n" |
| 4910 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4911 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4912 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4913 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4914 | "\n" |
| 4915 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4916 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4917 | "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] | 4918 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4919 | "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] | 4920 | "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] | 4921 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4922 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4923 | " display:block;\n" |
| 4924 | " visibility:hidden;\n" |
| 4925 | " z-index:2147483647;\n" |
| 4926 | " position:absolute;\n" |
| 4927 | " padding:2px 4px 3px;\n" |
| 4928 | " background:#f0f060; color:#000000;\n" |
| 4929 | " border:1px solid #7040c0;\n" |
| 4930 | " white-space:nowrap;\n" |
| 4931 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4932 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4933 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4934 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4935 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4936 | "-->\n" |
| 4937 | "</style></head>\n", |
| 4938 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4939 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4940 | ); |
| 4941 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4942 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4943 | /* 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] | 4944 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4945 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4946 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4947 | 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] | 4948 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4949 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4950 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4951 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4952 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4953 | /* WARNING! this has to fit the first packet too. |
| 4954 | * We are around 3.5 kB, add adding entries will |
| 4955 | * become tricky if we want to support 4kB buffers ! |
| 4956 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4957 | chunk_appendf(&trash, |
| 4958 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4959 | PRODUCT_NAME "%s</a></h1>\n" |
| 4960 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4961 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4962 | "<h3>> General process information</h3>\n" |
| 4963 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4964 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4965 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4966 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4967 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4968 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4969 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4970 | "</td><td align=\"center\" nowrap>\n" |
| 4971 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4972 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4973 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4974 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4975 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4976 | "<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] | 4977 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4978 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4979 | "<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] | 4980 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4981 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4982 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4983 | "</tr><tr>\n" |
| 4984 | "<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] | 4985 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4986 | "<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] | 4987 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4988 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4989 | "</td>" |
| 4990 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4991 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4992 | "", |
| 4993 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4994 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4995 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4996 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4997 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4998 | pid, relative_pid, global.nbproc, |
| 4999 | up / 86400, (up % 86400) / 3600, |
| 5000 | (up % 3600) / 60, (up % 60), |
| 5001 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 5002 | global.rlimit_memmax ? " MB" : "", |
| 5003 | global.rlimit_nofile, |
| 5004 | global.maxsock, global.maxconn, global.maxpipes, |
| 5005 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 5006 | run_queue_cur, nb_tasks_cur, idle_pct |
| 5007 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5008 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5009 | /* 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] | 5010 | 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] | 5011 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5012 | |
| 5013 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 5014 | "<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] | 5015 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5016 | STAT_SCOPE_TXT_MAXLEN); |
| 5017 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5018 | /* 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] | 5019 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5020 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5021 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5022 | 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] | 5023 | 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] | 5024 | } |
| 5025 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5026 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5027 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5028 | "<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] | 5029 | uri->uri_prefix, |
| 5030 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5031 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5032 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5033 | else |
| 5034 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5035 | "<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] | 5036 | uri->uri_prefix, |
| 5037 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5038 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5039 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5040 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5041 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5042 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5043 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5044 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5045 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5046 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5047 | "", |
| 5048 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5049 | else |
| 5050 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5051 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5052 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5053 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5054 | ";norefresh", |
| 5055 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5056 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 5057 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5058 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5059 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5060 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5061 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5062 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5063 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 5064 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5065 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5066 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5067 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5068 | (uri->refresh > 0) ? ";norefresh" : "", |
| 5069 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 5070 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5071 | chunk_appendf(&trash, |
| 5072 | "</ul></td>" |
| 5073 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 5074 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 5075 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 5076 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 5077 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 5078 | "</ul>" |
| 5079 | "</td>" |
| 5080 | "</tr></table>\n" |
| 5081 | "" |
| 5082 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 5083 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5084 | if (appctx->ctx.stats.st_code) { |
| 5085 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5086 | case STAT_STATUS_DONE: |
| 5087 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5088 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5089 | "<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] | 5090 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5091 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5092 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5093 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5094 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5095 | break; |
| 5096 | case STAT_STATUS_NONE: |
| 5097 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5098 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5099 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5100 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5101 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5102 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5103 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5104 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5105 | break; |
| 5106 | case STAT_STATUS_PART: |
| 5107 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5108 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5109 | "<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] | 5110 | "Action partially processed.<br>" |
| 5111 | "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] | 5112 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5113 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5114 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5115 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5116 | break; |
| 5117 | case STAT_STATUS_ERRP: |
| 5118 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5119 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5120 | "<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] | 5121 | "Action not processed because of invalid parameters." |
| 5122 | "<ul>" |
| 5123 | "<li>The action is maybe unknown.</li>" |
| 5124 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 5125 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 5126 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5127 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5128 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5129 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5130 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5131 | break; |
| 5132 | case STAT_STATUS_EXCD: |
| 5133 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5134 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5135 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5136 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 5137 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5138 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5139 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5140 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5141 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5142 | break; |
| 5143 | case STAT_STATUS_DENY: |
| 5144 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5145 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5146 | "<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] | 5147 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5148 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5149 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5150 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5151 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5152 | break; |
| 5153 | default: |
| 5154 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5155 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5156 | "<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] | 5157 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5158 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5159 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5160 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5161 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5162 | } |
| 5163 | chunk_appendf(&trash, "<p>\n"); |
| 5164 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5165 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5166 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5167 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 5168 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5169 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5170 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5171 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5172 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5173 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5174 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5175 | /* This function dumps statistics onto the stream interface's read buffer in |
| 5176 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5177 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 5178 | * 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] | 5179 | * 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] | 5180 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5181 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5182 | 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] | 5183 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5184 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5185 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5186 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5187 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5188 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5189 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5190 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5191 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5192 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5193 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 5194 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5195 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5196 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5197 | stats_dump_html_head(uri); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 5198 | else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED)) |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 5199 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 5200 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5201 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5202 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5203 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5204 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5205 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5206 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5207 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5208 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5209 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5210 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5211 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5212 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5213 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5214 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5215 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5216 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5217 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5218 | appctx->ctx.stats.px = proxy; |
| 5219 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 5220 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5221 | /* fall through */ |
| 5222 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5223 | case STAT_ST_LIST: |
| 5224 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5225 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5226 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5227 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5228 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5229 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5230 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5231 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5232 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 5233 | 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] | 5234 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5235 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5236 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5237 | appctx->ctx.stats.px = px->next; |
| 5238 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5239 | } |
| 5240 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5241 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5242 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5243 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5244 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5245 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5246 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5247 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5248 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5249 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5250 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5251 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5252 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5253 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5254 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5255 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 5256 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5257 | case STAT_ST_FIN: |
| 5258 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5259 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5260 | default: |
| 5261 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5262 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5263 | return -1; |
| 5264 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5265 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5266 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5267 | /* We reached the stats page through a POST request. The appctx is |
| 5268 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5269 | * Parse the posted data and enable/disable servers if necessary. |
| 5270 | * Returns 1 if request was parsed or zero if it needs more data. |
| 5271 | */ |
| 5272 | static int stats_process_http_post(struct stream_interface *si) |
| 5273 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5274 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5275 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5276 | |
| 5277 | struct proxy *px = NULL; |
| 5278 | struct server *sv = NULL; |
| 5279 | |
| 5280 | char key[LINESIZE]; |
| 5281 | int action = ST_ADM_ACTION_NONE; |
| 5282 | int reprocess = 0; |
| 5283 | |
| 5284 | int total_servers = 0; |
| 5285 | int altered_servers = 0; |
| 5286 | |
| 5287 | char *first_param, *cur_param, *next_param, *end_params; |
| 5288 | char *st_cur_param = NULL; |
| 5289 | char *st_next_param = NULL; |
| 5290 | |
| 5291 | struct chunk *temp; |
| 5292 | int reql; |
| 5293 | |
| 5294 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5295 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5296 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5297 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5298 | goto out; |
| 5299 | } |
| 5300 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5301 | 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] | 5302 | if (reql <= 0) { |
| 5303 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5304 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5305 | return 0; |
| 5306 | } |
| 5307 | |
| 5308 | first_param = temp->str; |
| 5309 | end_params = temp->str + reql; |
| 5310 | cur_param = next_param = end_params; |
| 5311 | *end_params = '\0'; |
| 5312 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5313 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5314 | |
| 5315 | /* |
| 5316 | * Parse the parameters in reverse order to only store the last value. |
| 5317 | * From the html form, the backend and the action are at the end. |
| 5318 | */ |
| 5319 | while (cur_param > first_param) { |
| 5320 | char *value; |
| 5321 | int poffset, plen; |
| 5322 | |
| 5323 | cur_param--; |
| 5324 | |
| 5325 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 5326 | reprocess_servers: |
| 5327 | /* Parse the key */ |
| 5328 | poffset = (cur_param != first_param ? 1 : 0); |
| 5329 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 5330 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 5331 | strncpy(key, cur_param + poffset, plen); |
| 5332 | key[plen - 1] = '\0'; |
| 5333 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5334 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5335 | goto out; |
| 5336 | } |
| 5337 | |
| 5338 | /* Parse the value */ |
| 5339 | value = key; |
| 5340 | while (*value != '\0' && *value != '=') { |
| 5341 | value++; |
| 5342 | } |
| 5343 | if (*value == '=') { |
| 5344 | /* Ok, a value is found, we can mark the end of the key */ |
| 5345 | *value++ = '\0'; |
| 5346 | } |
| 5347 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 5348 | break; |
| 5349 | |
| 5350 | /* Now we can check the key to see what to do */ |
| 5351 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 5352 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5353 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5354 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5355 | goto out; |
| 5356 | } |
| 5357 | } |
| 5358 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5359 | if (strcmp(value, "ready") == 0) { |
| 5360 | action = ST_ADM_ACTION_READY; |
| 5361 | } |
| 5362 | else if (strcmp(value, "drain") == 0) { |
| 5363 | action = ST_ADM_ACTION_DRAIN; |
| 5364 | } |
| 5365 | else if (strcmp(value, "maint") == 0) { |
| 5366 | action = ST_ADM_ACTION_MAINT; |
| 5367 | } |
| 5368 | else if (strcmp(value, "shutdown") == 0) { |
| 5369 | action = ST_ADM_ACTION_SHUTDOWN; |
| 5370 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5371 | else if (strcmp(value, "dhlth") == 0) { |
| 5372 | action = ST_ADM_ACTION_DHLTH; |
| 5373 | } |
| 5374 | else if (strcmp(value, "ehlth") == 0) { |
| 5375 | action = ST_ADM_ACTION_EHLTH; |
| 5376 | } |
| 5377 | else if (strcmp(value, "hrunn") == 0) { |
| 5378 | action = ST_ADM_ACTION_HRUNN; |
| 5379 | } |
| 5380 | else if (strcmp(value, "hnolb") == 0) { |
| 5381 | action = ST_ADM_ACTION_HNOLB; |
| 5382 | } |
| 5383 | else if (strcmp(value, "hdown") == 0) { |
| 5384 | action = ST_ADM_ACTION_HDOWN; |
| 5385 | } |
| 5386 | else if (strcmp(value, "dagent") == 0) { |
| 5387 | action = ST_ADM_ACTION_DAGENT; |
| 5388 | } |
| 5389 | else if (strcmp(value, "eagent") == 0) { |
| 5390 | action = ST_ADM_ACTION_EAGENT; |
| 5391 | } |
| 5392 | else if (strcmp(value, "arunn") == 0) { |
| 5393 | action = ST_ADM_ACTION_ARUNN; |
| 5394 | } |
| 5395 | else if (strcmp(value, "adown") == 0) { |
| 5396 | action = ST_ADM_ACTION_ADOWN; |
| 5397 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5398 | /* else these are the old supported methods */ |
| 5399 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5400 | action = ST_ADM_ACTION_DISABLE; |
| 5401 | } |
| 5402 | else if (strcmp(value, "enable") == 0) { |
| 5403 | action = ST_ADM_ACTION_ENABLE; |
| 5404 | } |
| 5405 | else if (strcmp(value, "stop") == 0) { |
| 5406 | action = ST_ADM_ACTION_STOP; |
| 5407 | } |
| 5408 | else if (strcmp(value, "start") == 0) { |
| 5409 | action = ST_ADM_ACTION_START; |
| 5410 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5411 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5412 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5413 | goto out; |
| 5414 | } |
| 5415 | } |
| 5416 | else if (strcmp(key, "s") == 0) { |
| 5417 | if (!(px && action)) { |
| 5418 | /* |
| 5419 | * Indicates that we'll need to reprocess the parameters |
| 5420 | * as soon as backend and action are known |
| 5421 | */ |
| 5422 | if (!reprocess) { |
| 5423 | st_cur_param = cur_param; |
| 5424 | st_next_param = next_param; |
| 5425 | } |
| 5426 | reprocess = 1; |
| 5427 | } |
| 5428 | else if ((sv = findserver(px, value)) != NULL) { |
| 5429 | switch (action) { |
| 5430 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5431 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5432 | altered_servers++; |
| 5433 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5434 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5435 | } |
| 5436 | break; |
| 5437 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5438 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5439 | altered_servers++; |
| 5440 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5441 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5442 | } |
| 5443 | break; |
| 5444 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5445 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 5446 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5447 | altered_servers++; |
| 5448 | total_servers++; |
| 5449 | } |
| 5450 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5451 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5452 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 5453 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5454 | altered_servers++; |
| 5455 | total_servers++; |
| 5456 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5457 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5458 | case ST_ADM_ACTION_DHLTH: |
| 5459 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5460 | sv->check.state &= ~CHK_ST_ENABLED; |
| 5461 | altered_servers++; |
| 5462 | total_servers++; |
| 5463 | } |
| 5464 | break; |
| 5465 | case ST_ADM_ACTION_EHLTH: |
| 5466 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5467 | sv->check.state |= CHK_ST_ENABLED; |
| 5468 | altered_servers++; |
| 5469 | total_servers++; |
| 5470 | } |
| 5471 | break; |
| 5472 | case ST_ADM_ACTION_HRUNN: |
| 5473 | if (!(sv->track)) { |
| 5474 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5475 | srv_set_running(sv, "changed from Web interface"); |
| 5476 | altered_servers++; |
| 5477 | total_servers++; |
| 5478 | } |
| 5479 | break; |
| 5480 | case ST_ADM_ACTION_HNOLB: |
| 5481 | if (!(sv->track)) { |
| 5482 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5483 | srv_set_stopping(sv, "changed from Web interface"); |
| 5484 | altered_servers++; |
| 5485 | total_servers++; |
| 5486 | } |
| 5487 | break; |
| 5488 | case ST_ADM_ACTION_HDOWN: |
| 5489 | if (!(sv->track)) { |
| 5490 | sv->check.health = 0; |
| 5491 | srv_set_stopped(sv, "changed from Web interface"); |
| 5492 | altered_servers++; |
| 5493 | total_servers++; |
| 5494 | } |
| 5495 | break; |
| 5496 | case ST_ADM_ACTION_DAGENT: |
| 5497 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5498 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 5499 | altered_servers++; |
| 5500 | total_servers++; |
| 5501 | } |
| 5502 | break; |
| 5503 | case ST_ADM_ACTION_EAGENT: |
| 5504 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5505 | sv->agent.state |= CHK_ST_ENABLED; |
| 5506 | altered_servers++; |
| 5507 | total_servers++; |
| 5508 | } |
| 5509 | break; |
| 5510 | case ST_ADM_ACTION_ARUNN: |
| 5511 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5512 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 5513 | srv_set_running(sv, "changed from Web interface"); |
| 5514 | altered_servers++; |
| 5515 | total_servers++; |
| 5516 | } |
| 5517 | break; |
| 5518 | case ST_ADM_ACTION_ADOWN: |
| 5519 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5520 | sv->agent.health = 0; |
| 5521 | srv_set_stopped(sv, "changed from Web interface"); |
| 5522 | altered_servers++; |
| 5523 | total_servers++; |
| 5524 | } |
| 5525 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5526 | case ST_ADM_ACTION_READY: |
| 5527 | srv_adm_set_ready(sv); |
| 5528 | altered_servers++; |
| 5529 | total_servers++; |
| 5530 | break; |
| 5531 | case ST_ADM_ACTION_DRAIN: |
| 5532 | srv_adm_set_drain(sv); |
| 5533 | altered_servers++; |
| 5534 | total_servers++; |
| 5535 | break; |
| 5536 | case ST_ADM_ACTION_MAINT: |
| 5537 | srv_adm_set_maint(sv); |
| 5538 | altered_servers++; |
| 5539 | total_servers++; |
| 5540 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5541 | case ST_ADM_ACTION_SHUTDOWN: |
| 5542 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5543 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5544 | |
| 5545 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 5546 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 5547 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5548 | |
| 5549 | altered_servers++; |
| 5550 | total_servers++; |
| 5551 | } |
| 5552 | break; |
| 5553 | } |
| 5554 | } else { |
| 5555 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 5556 | total_servers++; |
| 5557 | } |
| 5558 | } |
| 5559 | if (reprocess && px && action) { |
| 5560 | /* Now, we know the backend and the action chosen by the user. |
| 5561 | * We can safely restart from the first server parameter |
| 5562 | * to reprocess them |
| 5563 | */ |
| 5564 | cur_param = st_cur_param; |
| 5565 | next_param = st_next_param; |
| 5566 | reprocess = 0; |
| 5567 | goto reprocess_servers; |
| 5568 | } |
| 5569 | |
| 5570 | next_param = cur_param; |
| 5571 | } |
| 5572 | } |
| 5573 | |
| 5574 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5575 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5576 | } |
| 5577 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5578 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5579 | } |
| 5580 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5581 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5582 | } |
| 5583 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5584 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5585 | } |
| 5586 | out: |
| 5587 | return 1; |
| 5588 | } |
| 5589 | |
| 5590 | |
| 5591 | static int stats_send_http_headers(struct stream_interface *si) |
| 5592 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5593 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5594 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5595 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5596 | |
| 5597 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 5598 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5599 | "Cache-Control: no-cache\r\n" |
| 5600 | "Connection: close\r\n" |
| 5601 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5602 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5603 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5604 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5605 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 5606 | uri->refresh); |
| 5607 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5608 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 5609 | |
| 5610 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 5611 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 5612 | else |
| 5613 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5614 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5615 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5616 | s->logs.tv_request = now; |
| 5617 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5618 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5619 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5620 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5621 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5622 | |
| 5623 | return 1; |
| 5624 | } |
| 5625 | |
| 5626 | static int stats_send_http_redirect(struct stream_interface *si) |
| 5627 | { |
| 5628 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5629 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5630 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5631 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5632 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5633 | /* 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] | 5634 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5635 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5636 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5637 | 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] | 5638 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | /* We don't want to land on the posted stats page because a refresh will |
| 5642 | * repost the data. We don't want this to happen on accident so we redirect |
| 5643 | * the browse to the stats page with a GET. |
| 5644 | */ |
| 5645 | chunk_printf(&trash, |
| 5646 | "HTTP/1.1 303 See Other\r\n" |
| 5647 | "Cache-Control: no-cache\r\n" |
| 5648 | "Content-Type: text/plain\r\n" |
| 5649 | "Connection: close\r\n" |
| 5650 | "Location: %s;st=%s%s%s%s\r\n" |
Willy Tarreau | fdfcc9d | 2016-01-26 13:57:29 +0100 | [diff] [blame] | 5651 | "Content-length: 0\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5652 | "\r\n", |
| 5653 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5654 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 5655 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 5656 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 5657 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5658 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5659 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5660 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5661 | scope_txt); |
| 5662 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5663 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5664 | s->logs.tv_request = now; |
| 5665 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5666 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5667 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5668 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5669 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5670 | |
| 5671 | return 1; |
| 5672 | } |
| 5673 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5674 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 5675 | * 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] | 5676 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5677 | * automatically unregisters itself once transfer is complete. |
| 5678 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5679 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5680 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5681 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5682 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5683 | struct channel *req = si_oc(si); |
| 5684 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5685 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5686 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 5687 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5688 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5689 | /* check that the output is not closed */ |
| 5690 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5691 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5692 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5693 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5694 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5695 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5696 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5697 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5698 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5699 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5700 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5701 | } |
| 5702 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5703 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5704 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5705 | unsigned int data_len; |
| 5706 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 5707 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5708 | |
| 5709 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5710 | /* One difficulty we're facing is that we must prevent |
| 5711 | * the input data from being automatically forwarded to |
| 5712 | * the output area. For this, we temporarily disable |
| 5713 | * forwarding on the channel. |
| 5714 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5715 | last_fwd = si_ic(si)->to_forward; |
| 5716 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5717 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5718 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5719 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5720 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5721 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5722 | } |
| 5723 | } |
| 5724 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5725 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5726 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5727 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5728 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5729 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5730 | |
| 5731 | /* Now we must either adjust or remove the chunk size. This is |
| 5732 | * not easy because the chunk size might wrap at the end of the |
| 5733 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5734 | * the size, then restore the buffer's contents. Note that we can |
| 5735 | * only do that because no forwarding is scheduled on the stats |
| 5736 | * applet. |
| 5737 | */ |
| 5738 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5739 | si_ic(si)->total -= (last_len - prev_len); |
| 5740 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5741 | |
| 5742 | if (last_len != data_len) { |
| 5743 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5744 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5745 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5746 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5747 | si_ic(si)->total += (last_len - data_len); |
| 5748 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5749 | } |
| 5750 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5751 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5752 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5753 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5754 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5755 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5756 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5757 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5758 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5759 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5760 | } |
| 5761 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5762 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5763 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5764 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5765 | } |
| 5766 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5767 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5768 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5769 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5770 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5771 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5772 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5773 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5774 | } |
| 5775 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5776 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5777 | res->flags |= CF_READ_NULL; |
| 5778 | si_shutr(si); |
| 5779 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5780 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5781 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5782 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5783 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5784 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5785 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5786 | si_shutr(si); |
| 5787 | res->flags |= CF_READ_NULL; |
| 5788 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5789 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5790 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5791 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5792 | } |
| 5793 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5794 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5795 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5796 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5797 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5798 | return "NONE"; |
| 5799 | return conn->ctrl->name; |
| 5800 | } |
| 5801 | |
| 5802 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5803 | { |
| 5804 | static char ptr[17]; |
| 5805 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5806 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5807 | return "NONE"; |
| 5808 | |
| 5809 | if (conn->xprt == &raw_sock) |
| 5810 | return "RAW"; |
| 5811 | |
| 5812 | #ifdef USE_OPENSSL |
| 5813 | if (conn->xprt == &ssl_sock) |
| 5814 | return "SSL"; |
| 5815 | #endif |
| 5816 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5817 | return ptr; |
| 5818 | } |
| 5819 | |
| 5820 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5821 | { |
| 5822 | static char ptr[17]; |
| 5823 | |
| 5824 | if (!conn->data) |
| 5825 | return "NONE"; |
| 5826 | |
| 5827 | if (conn->data == &sess_conn_cb) |
| 5828 | return "SESS"; |
| 5829 | |
| 5830 | if (conn->data == &si_conn_cb) |
| 5831 | return "STRM"; |
| 5832 | |
| 5833 | if (conn->data == &check_conn_cb) |
| 5834 | return "CHCK"; |
| 5835 | |
| 5836 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5837 | return ptr; |
| 5838 | } |
| 5839 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5840 | /* This function dumps a complete stream state onto the stream interface's |
| 5841 | * 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] | 5842 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5843 | * 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] | 5844 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5845 | 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] | 5846 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5847 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5848 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5849 | extern const char *monthname[12]; |
| 5850 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5851 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5852 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5853 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5854 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5855 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5856 | 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] | 5857 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5858 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5859 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5860 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5861 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5862 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5863 | appctx->ctx.sess.uid = 0; |
| 5864 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5865 | return 1; |
| 5866 | } |
| 5867 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5868 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5869 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5870 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5871 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5872 | /* fall through */ |
| 5873 | |
| 5874 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5875 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5876 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5877 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5878 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5879 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5880 | 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] | 5881 | sess->uniq_id, |
Willy Tarreau | 666f504 | 2015-06-17 19:49:52 +0200 | [diff] [blame] | 5882 | strm_li(sess) ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5883 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5884 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5885 | 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] | 5886 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5887 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5888 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5889 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5890 | break; |
| 5891 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5892 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5893 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5894 | default: |
| 5895 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5896 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5897 | break; |
| 5898 | } |
| 5899 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5900 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5901 | " 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] | 5902 | 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] | 5903 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5904 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5905 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5906 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5907 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5908 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5909 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5910 | if (conn) |
| 5911 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5912 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5913 | 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] | 5914 | case AF_INET: |
| 5915 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5916 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5917 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5918 | break; |
| 5919 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5920 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5921 | break; |
| 5922 | default: |
| 5923 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5924 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5925 | break; |
| 5926 | } |
| 5927 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5928 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5929 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5930 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5931 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5932 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5933 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5934 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5935 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5936 | conn = objt_conn(sess->si[1].end); |
| 5937 | if (conn) |
| 5938 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5939 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5940 | 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] | 5941 | case AF_INET: |
| 5942 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5943 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5944 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5945 | break; |
| 5946 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5947 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5948 | break; |
| 5949 | default: |
| 5950 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5951 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5952 | break; |
| 5953 | } |
| 5954 | |
| 5955 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5956 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5957 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5958 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5959 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5960 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5961 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5962 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5963 | if (conn) |
| 5964 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5965 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5966 | 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] | 5967 | case AF_INET: |
| 5968 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5969 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5970 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5971 | break; |
| 5972 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5973 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5974 | break; |
| 5975 | default: |
| 5976 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5977 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5978 | break; |
| 5979 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5980 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5981 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5982 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5983 | sess->task, |
| 5984 | sess->task->state, |
| 5985 | sess->task->nice, sess->task->calls, |
| 5986 | sess->task->expire ? |
| 5987 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5988 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5989 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5990 | task_in_rq(sess->task) ? ", running" : ""); |
| 5991 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5992 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5993 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5994 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5995 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5996 | if (sess->txn) |
| 5997 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5998 | " 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] | 5999 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 6000 | 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] | 6001 | |
| 6002 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 6003 | " 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] | 6004 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 6005 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6006 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6007 | obj_type_name(sess->si[0].end), |
| 6008 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6009 | sess->si[0].exp ? |
| 6010 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 6011 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 6012 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 6013 | sess->si[0].err_type); |
| 6014 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6015 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 6016 | " 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] | 6017 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 6018 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6019 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6020 | obj_type_name(sess->si[1].end), |
| 6021 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6022 | sess->si[1].exp ? |
| 6023 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 6024 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 6025 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 6026 | sess->si[1].err_type); |
| 6027 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6028 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6029 | chunk_appendf(&trash, |
| 6030 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6031 | conn, |
| 6032 | get_conn_ctrl_name(conn), |
| 6033 | get_conn_xprt_name(conn), |
| 6034 | get_conn_data_name(conn), |
| 6035 | obj_type_name(conn->target), |
| 6036 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6037 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6038 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 6039 | " 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] | 6040 | conn->flags, |
| 6041 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 6042 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 6043 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6044 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6045 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6046 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 6047 | chunk_appendf(&trash, |
| 6048 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 6049 | tmpctx, |
| 6050 | tmpctx->st0, |
| 6051 | tmpctx->st1, |
| 6052 | tmpctx->st2, |
| 6053 | tmpctx->applet->name); |
| 6054 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 6055 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6056 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6057 | chunk_appendf(&trash, |
| 6058 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6059 | conn, |
| 6060 | get_conn_ctrl_name(conn), |
| 6061 | get_conn_xprt_name(conn), |
| 6062 | get_conn_data_name(conn), |
| 6063 | obj_type_name(conn->target), |
| 6064 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6065 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6066 | chunk_appendf(&trash, |
Willy Tarreau | ceeafb5 | 2016-01-25 15:27:17 +0100 | [diff] [blame] | 6067 | " 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] | 6068 | conn->flags, |
| 6069 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 6070 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 6071 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6072 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6073 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6074 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 6075 | chunk_appendf(&trash, |
| 6076 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 6077 | tmpctx, |
| 6078 | tmpctx->st0, |
| 6079 | tmpctx->st1, |
| 6080 | tmpctx->st2, |
| 6081 | tmpctx->applet->name); |
| 6082 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6083 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6084 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6085 | " 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] | 6086 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6087 | &sess->req, |
| 6088 | sess->req.flags, sess->req.analysers, |
| 6089 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 6090 | sess->req.to_forward, sess->req.total, |
| 6091 | sess->req.analyse_exp ? |
| 6092 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6093 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6094 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6095 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6096 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6097 | sess->req.rex ? |
| 6098 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6099 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6100 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6101 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6102 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6103 | " 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] | 6104 | sess->req.wex ? |
| 6105 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6106 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6107 | sess->req.buf, |
| 6108 | sess->req.buf->data, sess->req.buf->o, |
| 6109 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6110 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6111 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6112 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6113 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6114 | " 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] | 6115 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6116 | &sess->res, |
| 6117 | sess->res.flags, sess->res.analysers, |
| 6118 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 6119 | sess->res.to_forward, sess->res.total, |
| 6120 | sess->res.analyse_exp ? |
| 6121 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6122 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6123 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6124 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6125 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6126 | sess->res.rex ? |
| 6127 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6128 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6129 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6130 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6131 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6132 | " 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] | 6133 | sess->res.wex ? |
| 6134 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6135 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6136 | sess->res.buf, |
| 6137 | sess->res.buf->data, sess->res.buf->o, |
| 6138 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6139 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6140 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6141 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6142 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6143 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6144 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6145 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6146 | |
| 6147 | /* use other states to dump the contents */ |
| 6148 | } |
| 6149 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6150 | appctx->ctx.sess.uid = 0; |
| 6151 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6152 | return 1; |
| 6153 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6154 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6155 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 6156 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 6157 | struct appctx *appctx = __objt_appctx(si->end); |
| 6158 | |
| 6159 | switch (appctx->st2) { |
| 6160 | case STAT_ST_INIT: |
| 6161 | /* Display the column headers. If the message cannot be sent, |
| 6162 | * quit the fucntion with returning 0. The function is called |
| 6163 | * later and restart at the state "STAT_ST_INIT". |
| 6164 | */ |
| 6165 | chunk_reset(&trash); |
| 6166 | chunk_appendf(&trash, "# id (file)\n"); |
| 6167 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6168 | si_applet_cant_put(si); |
| 6169 | return 0; |
| 6170 | } |
| 6171 | |
| 6172 | /* Now, we start the browsing of the references lists. |
| 6173 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 6174 | * avalaible field of this pointer is <list>. It is used with the function |
| 6175 | * tlskeys_list_get_next() for retruning the first avalaible entry |
| 6176 | */ |
| 6177 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 6178 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 6179 | |
| 6180 | appctx->st2 = STAT_ST_LIST; |
| 6181 | /* fall through */ |
| 6182 | |
| 6183 | case STAT_ST_LIST: |
| 6184 | while (appctx->ctx.tlskeys.ref) { |
| 6185 | chunk_reset(&trash); |
| 6186 | |
| 6187 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 6188 | appctx->ctx.tlskeys.ref->filename); |
| 6189 | |
| 6190 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6191 | /* let's try again later from this stream. We add ourselves into |
| 6192 | * this stream's users so that it can remove us upon termination. |
| 6193 | */ |
| 6194 | si_applet_cant_put(si); |
| 6195 | return 0; |
| 6196 | } |
| 6197 | |
| 6198 | /* get next list entry and check the end of the list */ |
| 6199 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 6200 | } |
| 6201 | |
| 6202 | appctx->st2 = STAT_ST_FIN; |
| 6203 | /* fall through */ |
| 6204 | |
| 6205 | default: |
| 6206 | appctx->st2 = STAT_ST_FIN; |
| 6207 | return 1; |
| 6208 | } |
| 6209 | return 0; |
| 6210 | } |
| 6211 | #endif |
| 6212 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6213 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6214 | { |
| 6215 | struct appctx *appctx = __objt_appctx(si->end); |
| 6216 | |
| 6217 | switch (appctx->st2) { |
| 6218 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6219 | /* Display the column headers. If the message cannot be sent, |
| 6220 | * quit the fucntion with returning 0. The function is called |
| 6221 | * later and restart at the state "STAT_ST_INIT". |
| 6222 | */ |
| 6223 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 6224 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6225 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6226 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6227 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6228 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6229 | |
| 6230 | /* Now, we start the browsing of the references lists. |
| 6231 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 6232 | * avalaible field of this pointer is <list>. It is used with the function |
| 6233 | * pat_list_get_next() for retruning the first avalaible entry |
| 6234 | */ |
| 6235 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 6236 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6237 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6238 | appctx->st2 = STAT_ST_LIST; |
| 6239 | /* fall through */ |
| 6240 | |
| 6241 | case STAT_ST_LIST: |
| 6242 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6243 | chunk_reset(&trash); |
| 6244 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6245 | /* Build messages. If the reference is used by another category than |
| 6246 | * the listed categorie, display the information in the massage. |
| 6247 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 6248 | 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] | 6249 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 6250 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6251 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6252 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6253 | /* let's try again later from this stream. We add ourselves into |
| 6254 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6255 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6256 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6257 | return 0; |
| 6258 | } |
| 6259 | |
| 6260 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6261 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6262 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | appctx->st2 = STAT_ST_FIN; |
| 6266 | /* fall through */ |
| 6267 | |
| 6268 | default: |
| 6269 | appctx->st2 = STAT_ST_FIN; |
| 6270 | return 1; |
| 6271 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6272 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6273 | } |
| 6274 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6275 | static int stats_map_lookup(struct stream_interface *si) |
| 6276 | { |
| 6277 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6278 | struct sample sample; |
| 6279 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6280 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6281 | |
| 6282 | switch (appctx->st2) { |
| 6283 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6284 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 6285 | 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] | 6286 | 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] | 6287 | appctx->st2 = STAT_ST_LIST; |
| 6288 | /* fall through */ |
| 6289 | |
| 6290 | case STAT_ST_LIST: |
| 6291 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6292 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6293 | /* initialise chunk to build new message */ |
| 6294 | chunk_reset(&trash); |
| 6295 | |
| 6296 | /* execute pattern matching */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 6297 | sample.data.type = SMP_T_STR; |
Andreas Seltenreich | 9727cf4 | 2016-03-03 19:32:25 +0100 | [diff] [blame] | 6298 | sample.flags = SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 6299 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 6300 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 6301 | if (appctx->ctx.map.expr->pat_head->match && |
| 6302 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6303 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 6304 | else |
| 6305 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6306 | |
| 6307 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6308 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 6309 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 6310 | break; |
| 6311 | if (match_method >= PAT_MATCH_NUM) |
| 6312 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 6313 | else |
| 6314 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6315 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6316 | /* case sensitive */ |
| 6317 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 6318 | chunk_appendf(&trash, ", case=insensitive"); |
| 6319 | else |
| 6320 | chunk_appendf(&trash, ", case=sensitive"); |
| 6321 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6322 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6323 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6324 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6325 | chunk_appendf(&trash, ", found=no"); |
| 6326 | else |
| 6327 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6328 | } |
| 6329 | |
| 6330 | /* Display match and match info */ |
| 6331 | else { |
| 6332 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6333 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6334 | chunk_appendf(&trash, ", found=yes"); |
| 6335 | else |
| 6336 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6337 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6338 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6339 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6340 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6341 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6342 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6343 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6344 | /* display pattern */ |
| 6345 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 6346 | if (pat->ref && pat->ref->pattern) |
| 6347 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 6348 | else |
| 6349 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6350 | } |
| 6351 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6352 | if (pat->ref && pat->ref->pattern) |
| 6353 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 6354 | else |
| 6355 | chunk_appendf(&trash, ", pattern=unknown"); |
| 6356 | } |
| 6357 | |
| 6358 | /* display return value */ |
| 6359 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 6360 | if (pat->data && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 03d0e45 | 2015-07-23 18:33:41 +0200 | [diff] [blame] | 6361 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
Thierry FOURNIER | 7d4335c | 2015-08-19 09:05:25 +0200 | [diff] [blame] | 6362 | smp_to_type[pat->data->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6363 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6364 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6365 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6366 | } |
| 6367 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6368 | chunk_appendf(&trash, "\n"); |
| 6369 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6370 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6371 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6372 | /* let's try again later from this stream. We add ourselves into |
| 6373 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6374 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6375 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6376 | return 0; |
| 6377 | } |
| 6378 | |
| 6379 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6380 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 6381 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6382 | } |
| 6383 | |
| 6384 | appctx->st2 = STAT_ST_FIN; |
| 6385 | /* fall through */ |
| 6386 | |
| 6387 | default: |
| 6388 | appctx->st2 = STAT_ST_FIN; |
| 6389 | free(appctx->ctx.map.chunk.str); |
| 6390 | return 1; |
| 6391 | } |
| 6392 | } |
| 6393 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6394 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6395 | { |
| 6396 | struct appctx *appctx = __objt_appctx(si->end); |
| 6397 | |
| 6398 | switch (appctx->st2) { |
| 6399 | |
| 6400 | case STAT_ST_INIT: |
| 6401 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6402 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 6403 | struct pat_ref_elt *, list); |
| 6404 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 6405 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6406 | appctx->st2 = STAT_ST_LIST; |
| 6407 | /* fall through */ |
| 6408 | |
| 6409 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6410 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6411 | chunk_reset(&trash); |
| 6412 | |
| 6413 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6414 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6415 | chunk_appendf(&trash, "%p %s %s\n", |
| 6416 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 6417 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6418 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6419 | chunk_appendf(&trash, "%p %s\n", |
| 6420 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6421 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6422 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6423 | /* let's try again later from this stream. We add ourselves into |
| 6424 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6425 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6426 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6427 | return 0; |
| 6428 | } |
| 6429 | |
| 6430 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6431 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 6432 | struct pat_ref_elt *, list); |
| 6433 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6434 | break; |
| 6435 | } |
| 6436 | |
| 6437 | appctx->st2 = STAT_ST_FIN; |
| 6438 | /* fall through */ |
| 6439 | |
| 6440 | default: |
| 6441 | appctx->st2 = STAT_ST_FIN; |
| 6442 | return 1; |
| 6443 | } |
| 6444 | } |
| 6445 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6446 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6447 | * 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] | 6448 | * to be called again, otherwise non-zero. It is designed to be called |
| 6449 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6450 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6451 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6452 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6453 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6454 | struct connection *conn; |
| 6455 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6456 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6457 | /* 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] | 6458 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6459 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6460 | if (appctx->st2 == STAT_ST_LIST) { |
| 6461 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6462 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6463 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6464 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6465 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6466 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6467 | } |
| 6468 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6469 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6470 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6471 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6472 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6473 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6474 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6475 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6476 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6477 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6478 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6479 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6480 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6481 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6482 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6483 | /* fall through */ |
| 6484 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6485 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6486 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6487 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6488 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6489 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6493 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 6494 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6495 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6496 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6497 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6498 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6499 | if (appctx->ctx.sess.target) { |
| 6500 | 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] | 6501 | goto next_sess; |
| 6502 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6503 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6504 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6505 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6506 | return 0; |
| 6507 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6508 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6509 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6510 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 6511 | if (appctx->ctx.sess.target != (void *)-1) { |
| 6512 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6513 | break; |
| 6514 | } |
| 6515 | else |
| 6516 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6517 | } |
| 6518 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6519 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6520 | "%p: proto=%s", |
| 6521 | curr_sess, |
Willy Tarreau | f1e0212 | 2015-09-23 12:16:43 +0200 | [diff] [blame] | 6522 | strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6523 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6524 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6525 | 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] | 6526 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6527 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6528 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6529 | " src=%s:%d fe=%s be=%s srv=%s", |
| 6530 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6531 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6532 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6533 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6534 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6535 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6536 | break; |
| 6537 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6538 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6539 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6540 | strm_li(curr_sess)->luid, |
| 6541 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6542 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6543 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6544 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6545 | break; |
| 6546 | } |
| 6547 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6548 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 6549 | " ts=%02x age=%s calls=%d", |
| 6550 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 6551 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 6552 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6553 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6554 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6555 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6556 | curr_sess->req.flags, |
| 6557 | curr_sess->req.buf->i, |
| 6558 | curr_sess->req.analysers, |
| 6559 | curr_sess->req.rex ? |
| 6560 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6561 | TICKS_TO_MS(1000)) : ""); |
| 6562 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6563 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6564 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6565 | curr_sess->req.wex ? |
| 6566 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6567 | TICKS_TO_MS(1000)) : ""); |
| 6568 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6569 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6570 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6571 | curr_sess->req.analyse_exp ? |
| 6572 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6573 | TICKS_TO_MS(1000)) : ""); |
| 6574 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6575 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6576 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6577 | curr_sess->res.flags, |
| 6578 | curr_sess->res.buf->i, |
| 6579 | curr_sess->res.analysers, |
| 6580 | curr_sess->res.rex ? |
| 6581 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6582 | TICKS_TO_MS(1000)) : ""); |
| 6583 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6584 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6585 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6586 | curr_sess->res.wex ? |
| 6587 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6588 | TICKS_TO_MS(1000)) : ""); |
| 6589 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6590 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6591 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6592 | curr_sess->res.analyse_exp ? |
| 6593 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6594 | TICKS_TO_MS(1000)) : ""); |
| 6595 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6596 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6597 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6598 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 6599 | curr_sess->si[0].state, |
| 6600 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6601 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6602 | curr_sess->si[0].exp ? |
| 6603 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 6604 | TICKS_TO_MS(1000)) : ""); |
| 6605 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6606 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6607 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6608 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 6609 | curr_sess->si[1].state, |
| 6610 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6611 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6612 | curr_sess->si[1].exp ? |
| 6613 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 6614 | TICKS_TO_MS(1000)) : ""); |
| 6615 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6616 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6617 | " exp=%s", |
| 6618 | curr_sess->task->expire ? |
| 6619 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 6620 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 6621 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6622 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6623 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6624 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6625 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6626 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6627 | /* let's try again later from this stream. We add ourselves into |
| 6628 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6629 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6630 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6631 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6632 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6633 | } |
| 6634 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6635 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6636 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6637 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6638 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6639 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6640 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6641 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6642 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6643 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6644 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6645 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6646 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6647 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6648 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6649 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6650 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6651 | appctx->ctx.sess.target = NULL; |
| 6652 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6653 | return 1; |
| 6654 | } |
| 6655 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6656 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6657 | /* fall through */ |
| 6658 | |
| 6659 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6660 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6661 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6662 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 6663 | } |
| 6664 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6665 | /* This is called when the stream interface is closed. For instance, upon an |
| 6666 | * 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] | 6667 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6668 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 6669 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6670 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6671 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 6672 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 6673 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6674 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6675 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 6676 | free(appctx->ctx.cli.err); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6677 | appctx->ctx.cli.err = NULL; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6678 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6679 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 6680 | free(appctx->ctx.map.chunk.str); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6681 | appctx->ctx.map.chunk.str = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6682 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6683 | } |
| 6684 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6685 | /* This function is used to either dump tables states (when action is set |
| 6686 | * 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] | 6687 | * It returns 0 if the output buffer is full and it needs to be called |
| 6688 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6689 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6690 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6691 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6692 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6693 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6694 | struct ebmb_node *eb; |
| 6695 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6696 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6697 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6698 | |
| 6699 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6700 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6701 | * - STAT_ST_INIT : the first call |
| 6702 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6703 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6704 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6705 | * and the entry pointer points to the next entry to be dumped, |
| 6706 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6707 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6708 | * data though. |
| 6709 | */ |
| 6710 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6711 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6712 | /* 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] | 6713 | if (appctx->st2 == STAT_ST_LIST) { |
| 6714 | appctx->ctx.table.entry->ref_cnt--; |
| 6715 | 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] | 6716 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6717 | return 1; |
| 6718 | } |
| 6719 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6720 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6721 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6722 | while (appctx->st2 != STAT_ST_FIN) { |
| 6723 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6724 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6725 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 6726 | if (!appctx->ctx.table.proxy) |
| 6727 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6728 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6729 | appctx->ctx.table.entry = NULL; |
| 6730 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6731 | break; |
| 6732 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6733 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6734 | if (!appctx->ctx.table.proxy || |
| 6735 | (appctx->ctx.table.target && |
| 6736 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6737 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6738 | break; |
| 6739 | } |
| 6740 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6741 | if (appctx->ctx.table.proxy->table.size) { |
| 6742 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6743 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6744 | return 0; |
| 6745 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6746 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6747 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6748 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6749 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6750 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6751 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6752 | appctx->ctx.table.entry->ref_cnt++; |
| 6753 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6754 | break; |
| 6755 | } |
| 6756 | } |
| 6757 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6758 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6759 | break; |
| 6760 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6761 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6762 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6763 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6764 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6765 | /* we're filtering on some data contents */ |
| 6766 | void *ptr; |
| 6767 | long long data; |
| 6768 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6769 | dt = appctx->ctx.table.data_type; |
| 6770 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6771 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6772 | dt); |
| 6773 | |
| 6774 | data = 0; |
| 6775 | switch (stktable_data_types[dt].std_type) { |
| 6776 | case STD_T_SINT: |
| 6777 | data = stktable_data_cast(ptr, std_t_sint); |
| 6778 | break; |
| 6779 | case STD_T_UINT: |
| 6780 | data = stktable_data_cast(ptr, std_t_uint); |
| 6781 | break; |
| 6782 | case STD_T_ULL: |
| 6783 | data = stktable_data_cast(ptr, std_t_ull); |
| 6784 | break; |
| 6785 | case STD_T_FRQP: |
| 6786 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6787 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6788 | break; |
| 6789 | } |
| 6790 | |
| 6791 | /* 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] | 6792 | if ((data < appctx->ctx.table.value && |
| 6793 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6794 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6795 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6796 | (data == appctx->ctx.table.value && |
| 6797 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6798 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6799 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6800 | (data > appctx->ctx.table.value && |
| 6801 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6802 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6803 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6804 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6805 | } |
| 6806 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6807 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6808 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6809 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6810 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6811 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6812 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6813 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6814 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6815 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6816 | struct stksess *old = appctx->ctx.table.entry; |
| 6817 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6818 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6819 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6820 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6821 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6822 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6823 | break; |
| 6824 | } |
| 6825 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6826 | |
| 6827 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6828 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6829 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6830 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6831 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6832 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6833 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6834 | break; |
| 6835 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6836 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6837 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6838 | break; |
| 6839 | } |
| 6840 | } |
| 6841 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6842 | } |
| 6843 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6844 | /* 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] | 6845 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6846 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6847 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6848 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6849 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6850 | * after the offset. The new pointer is returned. |
| 6851 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6852 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6853 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6854 | { |
| 6855 | int end; |
| 6856 | unsigned char c; |
| 6857 | |
| 6858 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6859 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6860 | return ptr; |
| 6861 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6862 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6863 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6864 | while (ptr < len && ptr < bsize) { |
| 6865 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6866 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6867 | if (out->len > end - 2) |
| 6868 | break; |
| 6869 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6870 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6871 | if (out->len > end - 3) |
| 6872 | break; |
| 6873 | out->str[out->len++] = '\\'; |
| 6874 | switch (c) { |
| 6875 | case '\t': c = 't'; break; |
| 6876 | case '\n': c = 'n'; break; |
| 6877 | case '\r': c = 'r'; break; |
| 6878 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6879 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6880 | } |
| 6881 | out->str[out->len++] = c; |
| 6882 | } else { |
| 6883 | if (out->len > end - 5) |
| 6884 | break; |
| 6885 | out->str[out->len++] = '\\'; |
| 6886 | out->str[out->len++] = 'x'; |
| 6887 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6888 | out->str[out->len++] = hextab[c & 0xF]; |
| 6889 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6890 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6891 | /* we had a line break, let's return now */ |
| 6892 | out->str[out->len++] = '\n'; |
| 6893 | *line = ptr; |
| 6894 | return ptr; |
| 6895 | } |
| 6896 | } |
| 6897 | /* we have an incomplete line, we return it as-is */ |
| 6898 | out->str[out->len++] = '\n'; |
| 6899 | return ptr; |
| 6900 | } |
| 6901 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6902 | /* This function dumps counters from all resolvers section and associated name servers. |
| 6903 | * It returns 0 if the output buffer is full and it needs |
| 6904 | * to be called again, otherwise non-zero. |
| 6905 | */ |
| 6906 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si) |
| 6907 | { |
| 6908 | struct appctx *appctx = __objt_appctx(si->end); |
| 6909 | struct dns_resolvers *presolvers; |
| 6910 | struct dns_nameserver *pnameserver; |
| 6911 | |
| 6912 | chunk_reset(&trash); |
| 6913 | |
| 6914 | switch (appctx->st2) { |
| 6915 | case STAT_ST_INIT: |
| 6916 | appctx->st2 = STAT_ST_LIST; /* let's start producing data */ |
| 6917 | /* fall through */ |
| 6918 | |
| 6919 | case STAT_ST_LIST: |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 6920 | if (LIST_ISEMPTY(&dns_resolvers)) { |
| 6921 | chunk_appendf(&trash, "No resolvers found\n"); |
| 6922 | } |
| 6923 | else { |
| 6924 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 6925 | if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers) |
| 6926 | continue; |
| 6927 | |
| 6928 | chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id); |
| 6929 | list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) { |
| 6930 | chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id); |
| 6931 | chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent); |
| 6932 | chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid); |
| 6933 | chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update); |
| 6934 | chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname); |
| 6935 | chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error); |
| 6936 | chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err); |
| 6937 | chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx); |
| 6938 | chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout); |
| 6939 | chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused); |
| 6940 | chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other); |
| 6941 | chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid); |
| 6942 | chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big); |
| 6943 | chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated); |
| 6944 | chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated); |
| 6945 | } |
| 6946 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6947 | } |
| 6948 | |
| 6949 | /* display response */ |
| 6950 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6951 | /* let's try again later from this session. We add ourselves into |
| 6952 | * this session's users so that it can remove us upon termination. |
| 6953 | */ |
| 6954 | si->flags |= SI_FL_WAIT_ROOM; |
| 6955 | return 0; |
| 6956 | } |
| 6957 | |
| 6958 | appctx->st2 = STAT_ST_FIN; |
| 6959 | /* fall through */ |
| 6960 | |
| 6961 | default: |
| 6962 | appctx->st2 = STAT_ST_FIN; |
| 6963 | return 1; |
| 6964 | } |
| 6965 | } |
| 6966 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6967 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6968 | * 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] | 6969 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6970 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6971 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6972 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6973 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6974 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6975 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6976 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6977 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6978 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6979 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6980 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6981 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6982 | /* the function had not been called yet, let's prepare the |
| 6983 | * buffer for a response. |
| 6984 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6985 | struct tm tm; |
| 6986 | |
| 6987 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6988 | 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] | 6989 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6990 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6991 | error_snapshot_id); |
| 6992 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6993 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6994 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6995 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6996 | return 0; |
| 6997 | } |
| 6998 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6999 | appctx->ctx.errors.px = proxy; |
| 7000 | appctx->ctx.errors.buf = 0; |
| 7001 | appctx->ctx.errors.bol = 0; |
| 7002 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7003 | } |
| 7004 | |
| 7005 | /* we have two inner loops here, one for the proxy, the other one for |
| 7006 | * the buffer. |
| 7007 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7008 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7009 | struct error_snapshot *es; |
| 7010 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7011 | if (appctx->ctx.errors.buf == 0) |
| 7012 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7013 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7014 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7015 | |
| 7016 | if (!es->when.tv_sec) |
| 7017 | goto next; |
| 7018 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7019 | if (appctx->ctx.errors.iid >= 0 && |
| 7020 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 7021 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7022 | goto next; |
| 7023 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7024 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7025 | /* just print headers now */ |
| 7026 | |
| 7027 | char pn[INET6_ADDRSTRLEN]; |
| 7028 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7029 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7030 | |
| 7031 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7032 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7033 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 7034 | 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] | 7035 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7036 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 7037 | case AF_INET: |
| 7038 | case AF_INET6: |
| 7039 | port = get_host_port(&es->src); |
| 7040 | break; |
| 7041 | default: |
| 7042 | port = 0; |
| 7043 | } |
| 7044 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7045 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7046 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7047 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7048 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7049 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7050 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7051 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 7052 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7053 | break; |
| 7054 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7055 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 7056 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7057 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7058 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7059 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7060 | break; |
| 7061 | } |
| 7062 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7063 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7064 | ", server %s (#%d), event #%u\n" |
| 7065 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 7066 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 7067 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 7068 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 7069 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 7070 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 7071 | es->ev_id, |
| 7072 | pn, port, es->sid, es->s_flags, |
| 7073 | es->state, es->m_flags, es->t_flags, |
| 7074 | es->m_clen, es->m_blen, |
| 7075 | es->b_flags, es->b_out, es->b_tot, |
| 7076 | es->len, es->b_wrap, es->pos); |
| 7077 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7078 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7079 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7080 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7081 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7082 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7083 | appctx->ctx.errors.ptr = 0; |
| 7084 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7085 | } |
| 7086 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7087 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7088 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7089 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7090 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 7091 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7092 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7093 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 7094 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7095 | goto next; |
| 7096 | } |
| 7097 | |
| 7098 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7099 | 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] | 7100 | int newptr; |
| 7101 | int newline; |
| 7102 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7103 | newline = appctx->ctx.errors.bol; |
| 7104 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 7105 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7106 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7107 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7108 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7109 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7110 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7111 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7112 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7113 | appctx->ctx.errors.ptr = newptr; |
| 7114 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7115 | }; |
| 7116 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7117 | appctx->ctx.errors.bol = 0; |
| 7118 | appctx->ctx.errors.ptr = -1; |
| 7119 | appctx->ctx.errors.buf++; |
| 7120 | if (appctx->ctx.errors.buf > 1) { |
| 7121 | appctx->ctx.errors.buf = 0; |
| 7122 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7123 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 7124 | } |
| 7125 | |
| 7126 | /* dump complete */ |
| 7127 | return 1; |
| 7128 | } |
| 7129 | |
| 7130 | /* This function dumps all environmnent variables to the buffer. It returns 0 |
| 7131 | * if the output buffer is full and it needs to be called again, otherwise |
| 7132 | * non-zero. Dumps only one entry if st2 == STAT_ST_END. |
| 7133 | */ |
| 7134 | static int stats_dump_env_to_buffer(struct stream_interface *si) |
| 7135 | { |
| 7136 | struct appctx *appctx = __objt_appctx(si->end); |
| 7137 | |
| 7138 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 7139 | return 1; |
| 7140 | |
| 7141 | chunk_reset(&trash); |
| 7142 | |
| 7143 | /* we have two inner loops here, one for the proxy, the other one for |
| 7144 | * the buffer. |
| 7145 | */ |
| 7146 | while (*appctx->ctx.env.var) { |
| 7147 | chunk_printf(&trash, "%s\n", *appctx->ctx.env.var); |
| 7148 | |
| 7149 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 7150 | si_applet_cant_put(si); |
| 7151 | return 0; |
| 7152 | } |
| 7153 | if (appctx->st2 == STAT_ST_END) |
| 7154 | break; |
| 7155 | appctx->ctx.env.var++; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7156 | } |
| 7157 | |
| 7158 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7159 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7160 | } |
| 7161 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7162 | /* parse the "level" argument on the bind lines */ |
| 7163 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 7164 | { |
| 7165 | if (!*args[cur_arg + 1]) { |
| 7166 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 7167 | return ERR_ALERT | ERR_FATAL; |
| 7168 | } |
| 7169 | |
| 7170 | if (!strcmp(args[cur_arg+1], "user")) |
| 7171 | conf->level = ACCESS_LVL_USER; |
| 7172 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 7173 | conf->level = ACCESS_LVL_OPER; |
| 7174 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 7175 | conf->level = ACCESS_LVL_ADMIN; |
| 7176 | else { |
| 7177 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 7178 | args[cur_arg], args[cur_arg+1]); |
| 7179 | return ERR_ALERT | ERR_FATAL; |
| 7180 | } |
| 7181 | |
| 7182 | return 0; |
| 7183 | } |
| 7184 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7185 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7186 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7187 | .name = "<STATS>", /* used for logging */ |
| 7188 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 7189 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7190 | }; |
| 7191 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7192 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7193 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7194 | .name = "<CLI>", /* used for logging */ |
| 7195 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 7196 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7197 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 7198 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 7199 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7200 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 7201 | { 0, NULL, NULL }, |
| 7202 | }}; |
| 7203 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7204 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 7205 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 7206 | { NULL, NULL, 0 }, |
| 7207 | }}; |
| 7208 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7209 | __attribute__((constructor)) |
| 7210 | static void __dumpstats_module_init(void) |
| 7211 | { |
| 7212 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7213 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7214 | } |
| 7215 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 7216 | /* |
| 7217 | * Local variables: |
| 7218 | * c-indent-level: 8 |
| 7219 | * c-basic-offset: 8 |
| 7220 | * End: |
| 7221 | */ |