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 | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 41 | |
| 42 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 43 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 44 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 45 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 46 | #include <proto/dumpstats.h> |
| 47 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 48 | #include <proto/freq_ctr.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 49 | #include <proto/log.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 50 | #include <proto/pattern.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 51 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 52 | #include <proto/listener.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 53 | #include <proto/map.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 54 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 55 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 56 | #include <proto/proxy.h> |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 57 | #include <proto/sample.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 58 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 59 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 60 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 61 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 62 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 63 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 64 | #ifdef USE_OPENSSL |
| 65 | #include <proto/ssl_sock.h> |
| 66 | #endif |
| 67 | |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 68 | /* stats socket states */ |
| 69 | enum { |
| 70 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 71 | STAT_CLI_END, /* final state, let's close */ |
| 72 | STAT_CLI_GETREQ, /* wait for a request */ |
| 73 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 74 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 75 | STAT_CLI_PRINT, /* display message in cli->msg */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 76 | 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] | 77 | STAT_CLI_O_INFO, /* dump info */ |
| 78 | STAT_CLI_O_SESS, /* dump sessions */ |
| 79 | STAT_CLI_O_ERR, /* dump errors */ |
| 80 | STAT_CLI_O_TAB, /* dump tables */ |
| 81 | STAT_CLI_O_CLR, /* clear tables */ |
| 82 | STAT_CLI_O_SET, /* set entries in tables */ |
| 83 | STAT_CLI_O_STAT, /* dump stats */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 84 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 85 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 86 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 87 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 90 | /* Actions available for the stats admin forms */ |
| 91 | enum { |
| 92 | ST_ADM_ACTION_NONE = 0, |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 93 | |
| 94 | /* enable/disable health checks */ |
| 95 | ST_ADM_ACTION_DHLTH, |
| 96 | ST_ADM_ACTION_EHLTH, |
| 97 | |
| 98 | /* force health check status */ |
| 99 | ST_ADM_ACTION_HRUNN, |
| 100 | ST_ADM_ACTION_HNOLB, |
| 101 | ST_ADM_ACTION_HDOWN, |
| 102 | |
| 103 | /* enable/disable agent checks */ |
| 104 | ST_ADM_ACTION_DAGENT, |
| 105 | ST_ADM_ACTION_EAGENT, |
| 106 | |
| 107 | /* force agent check status */ |
| 108 | ST_ADM_ACTION_ARUNN, |
| 109 | ST_ADM_ACTION_ADOWN, |
| 110 | |
| 111 | /* set admin state */ |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 112 | ST_ADM_ACTION_READY, |
| 113 | ST_ADM_ACTION_DRAIN, |
| 114 | ST_ADM_ACTION_MAINT, |
| 115 | ST_ADM_ACTION_SHUTDOWN, |
| 116 | /* these are the ancient actions, still available for compatibility */ |
| 117 | ST_ADM_ACTION_DISABLE, |
| 118 | ST_ADM_ACTION_ENABLE, |
| 119 | ST_ADM_ACTION_STOP, |
| 120 | ST_ADM_ACTION_START, |
| 121 | }; |
| 122 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 123 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 124 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 125 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 126 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 127 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 128 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 129 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 130 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 131 | static int stats_pats_list(struct stream_interface *si); |
| 132 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 133 | static int stats_map_lookup(struct stream_interface *si); |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 134 | static void cli_release_handler(struct stream_interface *si); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 135 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 136 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 137 | * cli_io_handler() |
| 138 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 139 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 140 | * -> stats_dump_info_to_buffer() // "show info" |
| 141 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 142 | * -> stats_dump_csv_header() |
| 143 | * -> stats_dump_proxy_to_buffer() |
| 144 | * -> stats_dump_fe_stats() |
| 145 | * -> stats_dump_li_stats() |
| 146 | * -> stats_dump_sv_stats() |
| 147 | * -> stats_dump_be_stats() |
| 148 | * |
| 149 | * http_stats_io_handler() |
| 150 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 151 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 152 | * -> stats_dump_html_head() // emits the HTML headers |
| 153 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 154 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 155 | * -> stats_dump_html_px_hdr() |
| 156 | * -> stats_dump_fe_stats() |
| 157 | * -> stats_dump_li_stats() |
| 158 | * -> stats_dump_sv_stats() |
| 159 | * -> stats_dump_be_stats() |
| 160 | * -> stats_dump_html_px_end() |
| 161 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 162 | */ |
| 163 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 164 | static struct si_applet cli_applet; |
| 165 | |
| 166 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 167 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 168 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 169 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 170 | " help : this message\n" |
| 171 | " prompt : toggle interactive mode with prompt\n" |
| 172 | " quit : disconnect\n" |
| 173 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 174 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 175 | " show stat : report counters for each proxy and server\n" |
| 176 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 177 | " 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] | 178 | " show table [id]: report table usage stats or dump this table's contents\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 179 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 180 | " set weight : change a server's weight\n" |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 181 | " set server : change a server's state or weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 182 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 183 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 184 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 185 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 186 | " disable : put a server or frontend in maintenance mode\n" |
| 187 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 188 | " 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] | 189 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 190 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 191 | " add acl : add acl entry\n" |
| 192 | " del acl : delete acl entry\n" |
| 193 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 194 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 195 | " get map : reports the keys and values matching a sample for a map\n" |
| 196 | " set map : modify map entry\n" |
| 197 | " add map : add map entry\n" |
| 198 | " del map : delete map entry\n" |
| 199 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 200 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 201 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 202 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 203 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 204 | "Permission denied\n" |
| 205 | ""; |
| 206 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 207 | /* data transmission states for the stats responses */ |
| 208 | enum { |
| 209 | STAT_ST_INIT = 0, |
| 210 | STAT_ST_HEAD, |
| 211 | STAT_ST_INFO, |
| 212 | STAT_ST_LIST, |
| 213 | STAT_ST_END, |
| 214 | STAT_ST_FIN, |
| 215 | }; |
| 216 | |
| 217 | /* data transmission states for the stats responses inside a proxy */ |
| 218 | enum { |
| 219 | STAT_PX_ST_INIT = 0, |
| 220 | STAT_PX_ST_TH, |
| 221 | STAT_PX_ST_FE, |
| 222 | STAT_PX_ST_LI, |
| 223 | STAT_PX_ST_SV, |
| 224 | STAT_PX_ST_BE, |
| 225 | STAT_PX_ST_END, |
| 226 | STAT_PX_ST_FIN, |
| 227 | }; |
| 228 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 229 | extern const char *stat_status_codes[]; |
| 230 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 231 | /* This function is called from the session-level accept() in order to instanciate |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 232 | * a new stats socket. It returns a positive value upon success, 0 if the session |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 233 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 234 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 235 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 236 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 237 | s->target = &cli_applet.obj_type; |
Willy Tarreau | 4171e9e | 2013-12-01 12:32:30 +0100 | [diff] [blame] | 238 | /* no need to initialize the applet, it will start with st0=st1 = 0 */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 239 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 240 | tv_zero(&s->logs.tv_request); |
| 241 | s->logs.t_queue = 0; |
| 242 | s->logs.t_connect = 0; |
| 243 | s->logs.t_data = 0; |
| 244 | s->logs.t_close = 0; |
| 245 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 246 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 247 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 248 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 249 | s->req.flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 250 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 251 | if (s->listener->timeout) { |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 252 | s->req.rto = *s->listener->timeout; |
| 253 | s->res.wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 254 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 255 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 256 | } |
| 257 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 258 | /* allocate a new stats frontend named <name>, and return it |
| 259 | * (or NULL in case of lack of memory). |
| 260 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 261 | 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] | 262 | { |
| 263 | struct proxy *fe; |
| 264 | |
| 265 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 266 | if (!fe) |
| 267 | return NULL; |
| 268 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 269 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 270 | fe->next = proxy; |
| 271 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 272 | fe->last_change = now.tv_sec; |
| 273 | fe->id = strdup("GLOBAL"); |
| 274 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 275 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 276 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 277 | fe->conf.file = strdup(file); |
| 278 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 279 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 280 | |
| 281 | /* the stats frontend is the only one able to assign ID #0 */ |
| 282 | fe->conf.id.key = fe->uuid = 0; |
| 283 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 284 | return fe; |
| 285 | } |
| 286 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 287 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 288 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 289 | * error message into the <err> buffer which will be preallocated. The trailing |
| 290 | * '\n' must not be written. The function must be called with <args> pointing to |
| 291 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 292 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 293 | 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] | 294 | struct proxy *defpx, const char *file, int line, |
| 295 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 296 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 297 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 298 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 299 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 300 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 301 | int cur_arg; |
| 302 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 303 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 304 | 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] | 305 | return -1; |
| 306 | } |
| 307 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 308 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 309 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 310 | 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] | 311 | return -1; |
| 312 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 315 | 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] | 316 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 317 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 318 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 319 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 320 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 321 | return -1; |
| 322 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 323 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 324 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 325 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 326 | static int bind_dumped; |
| 327 | struct bind_kw *kw; |
| 328 | |
| 329 | kw = bind_find_kw(args[cur_arg]); |
| 330 | if (kw) { |
| 331 | if (!kw->parse) { |
| 332 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 333 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 334 | return -1; |
| 335 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 336 | |
| 337 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 338 | if (err && *err) |
| 339 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 340 | else |
| 341 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 342 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 343 | return -1; |
| 344 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 345 | |
| 346 | cur_arg += 1 + kw->skip; |
| 347 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 348 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 349 | |
| 350 | if (!bind_dumped) { |
| 351 | bind_dump_kws(err); |
| 352 | indent_msg(err, 4); |
| 353 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 354 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 355 | |
| 356 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 357 | args[0], args[1], args[cur_arg], |
| 358 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 359 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 360 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 361 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 362 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 363 | l->maxconn = global.stats_fe->maxconn; |
| 364 | l->backlog = global.stats_fe->backlog; |
| 365 | l->timeout = &global.stats_fe->timeout.client; |
| 366 | l->accept = session_accept; |
| 367 | l->handler = process_session; |
| 368 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 369 | l->nice = -64; /* we want to boost priority for local stats */ |
| 370 | global.maxsock += l->maxconn; |
| 371 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 372 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 373 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 374 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 375 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 376 | |
| 377 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 378 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 379 | return -1; |
| 380 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 381 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 382 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 383 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 384 | return -1; |
| 385 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 386 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 387 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 388 | 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] | 389 | return -1; |
| 390 | } |
| 391 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 392 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 393 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 394 | else if (!strcmp(args[1], "maxconn")) { |
| 395 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 396 | |
| 397 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 398 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 399 | return -1; |
| 400 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 401 | |
| 402 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 403 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 404 | 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] | 405 | return -1; |
| 406 | } |
| 407 | } |
| 408 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 409 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 410 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 411 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 412 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 413 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 414 | if (!global.stats_fe) { |
| 415 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 416 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 417 | return -1; |
| 418 | } |
| 419 | } |
| 420 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 421 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 422 | unsigned int low, high; |
| 423 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 424 | if (strcmp(args[cur_arg], "all") == 0) { |
| 425 | set = 0; |
| 426 | break; |
| 427 | } |
| 428 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 429 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 430 | } |
| 431 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 432 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 433 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 434 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 435 | char *dash = strchr(args[cur_arg], '-'); |
| 436 | |
| 437 | low = high = str2uic(args[cur_arg]); |
| 438 | if (dash) |
| 439 | high = str2uic(dash + 1); |
| 440 | |
| 441 | if (high < low) { |
| 442 | unsigned int swap = low; |
| 443 | low = high; |
| 444 | high = swap; |
| 445 | } |
| 446 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 447 | if (low < 1 || high > LONGBITS) { |
| 448 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 449 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 450 | return -1; |
| 451 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 452 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 453 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 454 | } |
| 455 | else { |
| 456 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 457 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 458 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 459 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 460 | } |
| 461 | cur_arg++; |
| 462 | } |
| 463 | global.stats_fe->bind_proc = set; |
| 464 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 465 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 466 | 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] | 467 | return -1; |
| 468 | } |
| 469 | return 0; |
| 470 | } |
| 471 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 472 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 473 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 474 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 475 | * 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] | 476 | */ |
| 477 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 478 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 479 | chunk_appendf(&trash, |
| 480 | "# pxname,svname," |
| 481 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 482 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 483 | "bin,bout," |
| 484 | "dreq,dresp," |
| 485 | "ereq,econ,eresp," |
| 486 | "wretr,wredis," |
| 487 | "status,weight,act,bck," |
| 488 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 489 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 490 | "rate,rate_lim,rate_max," |
| 491 | "check_status,check_code,check_duration," |
| 492 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 493 | "req_rate,req_rate_max,req_tot," |
| 494 | "cli_abrt,srv_abrt," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 495 | "comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 496 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 497 | } |
| 498 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 499 | /* print a string of text buffer to <out>. The format is : |
| 500 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 501 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 502 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 503 | */ |
| 504 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 505 | { |
| 506 | unsigned char c; |
| 507 | int ptr = 0; |
| 508 | |
| 509 | while (buf[ptr] && ptr < bsize) { |
| 510 | c = buf[ptr]; |
| 511 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 512 | if (out->len > out->size - 1) |
| 513 | break; |
| 514 | out->str[out->len++] = c; |
| 515 | } |
| 516 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 517 | if (out->len > out->size - 2) |
| 518 | break; |
| 519 | out->str[out->len++] = '\\'; |
| 520 | switch (c) { |
| 521 | case ' ': c = ' '; break; |
| 522 | case '\t': c = 't'; break; |
| 523 | case '\n': c = 'n'; break; |
| 524 | case '\r': c = 'r'; break; |
| 525 | case '\e': c = 'e'; break; |
| 526 | case '\\': c = '\\'; break; |
| 527 | } |
| 528 | out->str[out->len++] = c; |
| 529 | } |
| 530 | else { |
| 531 | if (out->len > out->size - 4) |
| 532 | break; |
| 533 | out->str[out->len++] = '\\'; |
| 534 | out->str[out->len++] = 'x'; |
| 535 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 536 | out->str[out->len++] = hextab[c & 0xF]; |
| 537 | } |
| 538 | ptr++; |
| 539 | } |
| 540 | |
| 541 | return ptr; |
| 542 | } |
| 543 | |
| 544 | /* print a buffer in hexa. |
| 545 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 546 | */ |
| 547 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 548 | { |
| 549 | unsigned char c; |
| 550 | int ptr = 0; |
| 551 | |
| 552 | while (ptr < bsize) { |
| 553 | c = buf[ptr]; |
| 554 | |
| 555 | if (out->len > out->size - 2) |
| 556 | break; |
| 557 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 558 | out->str[out->len++] = hextab[c & 0xF]; |
| 559 | |
| 560 | ptr++; |
| 561 | } |
| 562 | return ptr; |
| 563 | } |
| 564 | |
| 565 | /* Dump the status of a table to a stream interface's |
| 566 | * read buffer. It returns 0 if the output buffer is full |
| 567 | * and needs to be called again, otherwise non-zero. |
| 568 | */ |
| 569 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 570 | struct proxy *proxy, struct proxy *target) |
| 571 | { |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 572 | struct session *s = si_sess(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 573 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 574 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 575 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 576 | |
| 577 | /* any other information should be dumped here */ |
| 578 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 579 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 580 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 581 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 582 | if (bi_putchk(si_ic(si), msg) == -1) { |
| 583 | si->flags |= SI_FL_WAIT_ROOM; |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 584 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 585 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 586 | |
| 587 | return 1; |
| 588 | } |
| 589 | |
| 590 | /* Dump the a table entry to a stream interface's |
| 591 | * read buffer. It returns 0 if the output buffer is full |
| 592 | * and needs to be called again, otherwise non-zero. |
| 593 | */ |
| 594 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 595 | struct proxy *proxy, struct stksess *entry) |
| 596 | { |
| 597 | int dt; |
| 598 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 599 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 600 | |
| 601 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 602 | char addr[INET_ADDRSTRLEN]; |
| 603 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 604 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 605 | } |
| 606 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 607 | char addr[INET6_ADDRSTRLEN]; |
| 608 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 609 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 610 | } |
| 611 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 612 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 613 | } |
| 614 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 615 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 616 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 617 | } |
| 618 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 619 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 620 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 621 | } |
| 622 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 623 | 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] | 624 | |
| 625 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 626 | void *ptr; |
| 627 | |
| 628 | if (proxy->table.data_ofs[dt] == 0) |
| 629 | continue; |
| 630 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 631 | 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] | 632 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 633 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 634 | |
| 635 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 636 | switch (stktable_data_types[dt].std_type) { |
| 637 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 638 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 639 | break; |
| 640 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 641 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 642 | break; |
| 643 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 644 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 645 | break; |
| 646 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 647 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 648 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 649 | proxy->table.data_arg[dt].u)); |
| 650 | break; |
| 651 | } |
| 652 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 653 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 654 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 655 | if (bi_putchk(si_ic(si), msg) == -1) { |
| 656 | si->flags |= SI_FL_WAIT_ROOM; |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 657 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 658 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 659 | |
| 660 | return 1; |
| 661 | } |
| 662 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 663 | 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] | 664 | { |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 665 | struct session *s = si_sess(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 666 | struct appctx *appctx = __objt_appctx(si->end); |
| 667 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 668 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 669 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 670 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 671 | long long value; |
| 672 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 673 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 674 | void *ptr; |
| 675 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 676 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 677 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 678 | |
| 679 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 680 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 681 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 682 | return; |
| 683 | } |
| 684 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 685 | switch (px->table.type) { |
| 686 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 687 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 688 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 689 | break; |
| 690 | case STKTABLE_TYPE_IPV6: |
| 691 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 692 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 693 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 694 | case STKTABLE_TYPE_INTEGER: |
| 695 | { |
| 696 | char *endptr; |
| 697 | unsigned long val; |
| 698 | errno = 0; |
| 699 | val = strtoul(args[4], &endptr, 10); |
| 700 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 701 | (errno != 0 && val == 0) || endptr == args[4] || |
| 702 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 703 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 704 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 705 | return; |
| 706 | } |
| 707 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 708 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 709 | break; |
| 710 | } |
| 711 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 712 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 713 | static_table_key->key = args[4]; |
| 714 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 715 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 716 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 717 | switch (action) { |
| 718 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 719 | 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] | 720 | break; |
| 721 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 722 | 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] | 723 | break; |
| 724 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 725 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 726 | break; |
| 727 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 728 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 729 | return; |
| 730 | } |
| 731 | |
| 732 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 733 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 734 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 735 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 736 | return; |
| 737 | } |
| 738 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 739 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 740 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 741 | switch (action) { |
| 742 | case STAT_CLI_O_TAB: |
| 743 | if (!ts) |
| 744 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 745 | chunk_reset(&trash); |
| 746 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 747 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 748 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 749 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 750 | |
| 751 | case STAT_CLI_O_CLR: |
| 752 | if (!ts) |
| 753 | return; |
| 754 | if (ts->ref_cnt) { |
| 755 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 756 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 757 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 758 | return; |
| 759 | } |
| 760 | stksess_kill(&px->table, ts); |
| 761 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 762 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 763 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 764 | if (ts) |
| 765 | stktable_touch(&px->table, ts, 1); |
| 766 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 767 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 768 | if (!ts) { |
| 769 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 770 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 771 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 772 | return; |
| 773 | } |
| 774 | stktable_store(&px->table, ts, 1); |
| 775 | } |
| 776 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 777 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 778 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 779 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 780 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 781 | return; |
| 782 | } |
| 783 | |
| 784 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 785 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 786 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 787 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 788 | return; |
| 789 | } |
| 790 | |
| 791 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 792 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 793 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 794 | return; |
| 795 | } |
| 796 | |
| 797 | 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] | 798 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 799 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 800 | return; |
| 801 | } |
| 802 | |
| 803 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 804 | |
| 805 | switch (stktable_data_types[data_type].std_type) { |
| 806 | case STD_T_SINT: |
| 807 | stktable_data_cast(ptr, std_t_sint) = value; |
| 808 | break; |
| 809 | case STD_T_UINT: |
| 810 | stktable_data_cast(ptr, std_t_uint) = value; |
| 811 | break; |
| 812 | case STD_T_ULL: |
| 813 | stktable_data_cast(ptr, std_t_ull) = value; |
| 814 | break; |
| 815 | case STD_T_FRQP: |
| 816 | /* We set both the current and previous values. That way |
| 817 | * the reported frequency is stable during all the period |
| 818 | * then slowly fades out. This allows external tools to |
| 819 | * push measures without having to update them too often. |
| 820 | */ |
| 821 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 822 | frqp->curr_tick = now_ms; |
| 823 | frqp->prev_ctr = 0; |
| 824 | frqp->curr_ctr = value; |
| 825 | break; |
| 826 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 827 | } |
| 828 | break; |
| 829 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 830 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 831 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 832 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 833 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 834 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 835 | } |
| 836 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 837 | 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] | 838 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 839 | struct appctx *appctx = __objt_appctx(si->end); |
| 840 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 841 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 842 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 843 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 844 | return; |
| 845 | } |
| 846 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 847 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 848 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 849 | if (appctx->ctx.table.data_type < 0) { |
| 850 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 851 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 852 | return; |
| 853 | } |
| 854 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 855 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 856 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 857 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 858 | return; |
| 859 | } |
| 860 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 861 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 862 | if (appctx->ctx.table.data_op < 0) { |
| 863 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 864 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 865 | return; |
| 866 | } |
| 867 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 868 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 869 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 870 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 871 | return; |
| 872 | } |
| 873 | } |
| 874 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 875 | 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] | 876 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 877 | struct appctx *appctx = __objt_appctx(si->end); |
| 878 | |
| 879 | appctx->ctx.table.data_type = -1; |
| 880 | appctx->st2 = STAT_ST_INIT; |
| 881 | appctx->ctx.table.target = NULL; |
| 882 | appctx->ctx.table.proxy = NULL; |
| 883 | appctx->ctx.table.entry = NULL; |
| 884 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 885 | |
| 886 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 887 | appctx->ctx.table.target = find_stktable(args[2]); |
| 888 | if (!appctx->ctx.table.target) { |
| 889 | appctx->ctx.cli.msg = "No such table\n"; |
| 890 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 891 | return; |
| 892 | } |
| 893 | } |
| 894 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 895 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 896 | goto err_args; |
| 897 | return; |
| 898 | } |
| 899 | |
| 900 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 901 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 902 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 903 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 904 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 905 | goto err_args; |
| 906 | |
| 907 | return; |
| 908 | |
| 909 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 910 | switch (action) { |
| 911 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 912 | 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] | 913 | break; |
| 914 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 915 | 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] | 916 | break; |
| 917 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 918 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 919 | break; |
| 920 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 921 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 922 | } |
| 923 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 924 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 925 | * adequate error messages and returns NULL. This function also expects the session |
| 926 | * level to be admin. |
| 927 | */ |
| 928 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 929 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 930 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 931 | struct proxy *px; |
| 932 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 933 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 934 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 935 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 936 | return NULL; |
| 937 | } |
| 938 | |
| 939 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 940 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 941 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 942 | return NULL; |
| 943 | } |
| 944 | |
| 945 | px = findproxy(arg, PR_CAP_FE); |
| 946 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 947 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 948 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 949 | return NULL; |
| 950 | } |
| 951 | return px; |
| 952 | } |
| 953 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 954 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 955 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 956 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 957 | * the <arg> is modified to remove the '/'. |
| 958 | */ |
| 959 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 960 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 961 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 962 | struct proxy *px; |
| 963 | struct server *sv; |
| 964 | char *line; |
| 965 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 966 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 967 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 968 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 969 | return NULL; |
| 970 | } |
| 971 | |
| 972 | /* split "backend/server" and make <line> point to server */ |
| 973 | for (line = arg; *line; line++) |
| 974 | if (*line == '/') { |
| 975 | *line++ = '\0'; |
| 976 | break; |
| 977 | } |
| 978 | |
| 979 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 980 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 981 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 982 | return NULL; |
| 983 | } |
| 984 | |
| 985 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 986 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 987 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 988 | return NULL; |
| 989 | } |
| 990 | |
| 991 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 992 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 993 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 994 | return NULL; |
| 995 | } |
| 996 | |
| 997 | return sv; |
| 998 | } |
| 999 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1000 | /* This function is used with map and acl management. It permits to browse |
| 1001 | * each reference. The variable <getnext> must contain the current node, |
| 1002 | * <end> point to the root node and the <flags> permit to filter required |
| 1003 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1004 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1005 | static inline |
| 1006 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1007 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1008 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1009 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1010 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1011 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1012 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1013 | /* Get next list entry. */ |
| 1014 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1015 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1016 | /* If the entry is the last of the list, return NULL. */ |
| 1017 | if (&ref->list == end) |
| 1018 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1019 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1020 | /* If the entry match the flag, return it. */ |
| 1021 | if (ref->flags & flags) |
| 1022 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1026 | static inline |
| 1027 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1028 | { |
| 1029 | int id; |
| 1030 | char *error; |
| 1031 | |
| 1032 | /* If the reference starts by a '#', this is numeric id. */ |
| 1033 | if (reference[0] == '#') { |
| 1034 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1035 | id = strtol(reference + 1, &error, 10); |
| 1036 | if (*error != '\0') |
| 1037 | return NULL; |
| 1038 | |
| 1039 | /* Perform the unique id lookup. */ |
| 1040 | return pat_ref_lookupid(id); |
| 1041 | } |
| 1042 | |
| 1043 | /* Perform the string lookup. */ |
| 1044 | return pat_ref_lookup(reference); |
| 1045 | } |
| 1046 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1047 | /* This function is used with map and acl management. It permits to browse |
| 1048 | * each reference. |
| 1049 | */ |
| 1050 | static inline |
| 1051 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1052 | { |
| 1053 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1054 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1055 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1056 | return NULL; |
| 1057 | return expr; |
| 1058 | } |
| 1059 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1060 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1061 | * 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] | 1062 | * 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] | 1063 | * designating the function which will have to process the request, which can |
| 1064 | * 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] | 1065 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1066 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1067 | { |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 1068 | struct session *s = si_sess(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1069 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1070 | char *args[MAX_STATS_ARGS + 1]; |
| 1071 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1072 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1073 | |
| 1074 | while (isspace((unsigned char)*line)) |
| 1075 | line++; |
| 1076 | |
| 1077 | arg = 0; |
| 1078 | args[arg] = line; |
| 1079 | |
| 1080 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1081 | if (*line == '\\') { |
| 1082 | line++; |
| 1083 | if (*line == '\0') |
| 1084 | break; |
| 1085 | } |
| 1086 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1087 | *line++ = '\0'; |
| 1088 | |
| 1089 | while (isspace((unsigned char)*line)) |
| 1090 | line++; |
| 1091 | |
| 1092 | args[++arg] = line; |
| 1093 | continue; |
| 1094 | } |
| 1095 | |
| 1096 | line++; |
| 1097 | } |
| 1098 | |
| 1099 | while (++arg <= MAX_STATS_ARGS) |
| 1100 | args[arg] = line; |
| 1101 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1102 | /* remove \ */ |
| 1103 | arg = 0; |
| 1104 | while (*args[arg] != '\0') { |
| 1105 | j = 0; |
| 1106 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1107 | if (args[arg][i] == '\\') |
| 1108 | continue; |
| 1109 | args[arg][j] = args[arg][i]; |
| 1110 | j++; |
| 1111 | } |
| 1112 | args[arg][j] = '\0'; |
| 1113 | arg++; |
| 1114 | } |
| 1115 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1116 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1117 | if (strcmp(args[0], "show") == 0) { |
| 1118 | if (strcmp(args[1], "stat") == 0) { |
| 1119 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1120 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1121 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1122 | appctx->ctx.stats.type = atoi(args[3]); |
| 1123 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1124 | } |
| 1125 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1126 | appctx->st2 = STAT_ST_INIT; |
| 1127 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1128 | } |
| 1129 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1130 | appctx->st2 = STAT_ST_INIT; |
| 1131 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1132 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1133 | else if (strcmp(args[1], "pools") == 0) { |
| 1134 | appctx->st2 = STAT_ST_INIT; |
| 1135 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1136 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1137 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1138 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1139 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1140 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1141 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1142 | return 1; |
| 1143 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1144 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1145 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1146 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1147 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1148 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1149 | appctx->ctx.sess.target = NULL; |
| 1150 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1151 | appctx->ctx.sess.pos = 0; |
| 1152 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1153 | } |
| 1154 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1155 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1156 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1157 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1158 | return 1; |
| 1159 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1160 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1161 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1162 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1163 | appctx->ctx.errors.iid = -1; |
| 1164 | appctx->ctx.errors.px = NULL; |
| 1165 | appctx->st2 = STAT_ST_INIT; |
| 1166 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1167 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1168 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1169 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1170 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1171 | else if (strcmp(args[1], "map") == 0 || |
| 1172 | strcmp(args[1], "acl") == 0) { |
| 1173 | |
| 1174 | /* Set ACL or MAP flags. */ |
| 1175 | if (args[1][0] == 'm') |
| 1176 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1177 | else |
| 1178 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1179 | |
| 1180 | /* no parameter: display all map avalaible */ |
| 1181 | if (!*args[2]) { |
| 1182 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1183 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1184 | return 1; |
| 1185 | } |
| 1186 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1187 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1188 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1189 | if (!appctx->ctx.map.ref || |
| 1190 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1191 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1192 | 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] | 1193 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1194 | 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] | 1195 | appctx->st0 = STAT_CLI_PRINT; |
| 1196 | return 1; |
| 1197 | } |
| 1198 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1199 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1200 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1201 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1202 | return 0; |
| 1203 | } |
| 1204 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1205 | else if (strcmp(args[0], "clear") == 0) { |
| 1206 | if (strcmp(args[1], "counters") == 0) { |
| 1207 | struct proxy *px; |
| 1208 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1209 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1210 | int clrall = 0; |
| 1211 | |
| 1212 | if (strcmp(args[2], "all") == 0) |
| 1213 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1214 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1215 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1216 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1217 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1218 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1219 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1220 | return 1; |
| 1221 | } |
| 1222 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1223 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1224 | if (clrall) { |
| 1225 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1226 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1227 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1228 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1229 | px->be_counters.conn_max = 0; |
| 1230 | px->be_counters.p.http.rps_max = 0; |
| 1231 | px->be_counters.sps_max = 0; |
| 1232 | px->be_counters.cps_max = 0; |
| 1233 | px->be_counters.nbpend_max = 0; |
| 1234 | |
| 1235 | px->fe_counters.conn_max = 0; |
| 1236 | px->fe_counters.p.http.rps_max = 0; |
| 1237 | px->fe_counters.sps_max = 0; |
| 1238 | px->fe_counters.cps_max = 0; |
| 1239 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1240 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1241 | |
| 1242 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1243 | if (clrall) |
| 1244 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1245 | else { |
| 1246 | sv->counters.cur_sess_max = 0; |
| 1247 | sv->counters.nbpend_max = 0; |
| 1248 | sv->counters.sps_max = 0; |
| 1249 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1250 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1251 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1252 | if (li->counters) { |
| 1253 | if (clrall) |
| 1254 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1255 | else |
| 1256 | li->counters->conn_max = 0; |
| 1257 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1258 | } |
| 1259 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1260 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1261 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1262 | return 1; |
| 1263 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1264 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1265 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1266 | /* end of processing */ |
| 1267 | return 1; |
| 1268 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1269 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1270 | /* Set ACL or MAP flags. */ |
| 1271 | if (args[1][0] == 'm') |
| 1272 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1273 | else |
| 1274 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1275 | |
| 1276 | /* no parameter */ |
| 1277 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1278 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1279 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1280 | else |
| 1281 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1282 | appctx->st0 = STAT_CLI_PRINT; |
| 1283 | return 1; |
| 1284 | } |
| 1285 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1286 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1287 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1288 | if (!appctx->ctx.map.ref || |
| 1289 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1290 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1291 | 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] | 1292 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1293 | 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] | 1294 | appctx->st0 = STAT_CLI_PRINT; |
| 1295 | return 1; |
| 1296 | } |
| 1297 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1298 | /* Clear all. */ |
| 1299 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1300 | |
| 1301 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1302 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1303 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1304 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1305 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1306 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1307 | return 0; |
| 1308 | } |
| 1309 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1310 | else if (strcmp(args[0], "get") == 0) { |
| 1311 | if (strcmp(args[1], "weight") == 0) { |
| 1312 | struct proxy *px; |
| 1313 | struct server *sv; |
| 1314 | |
| 1315 | /* split "backend/server" and make <line> point to server */ |
| 1316 | for (line = args[2]; *line; line++) |
| 1317 | if (*line == '/') { |
| 1318 | *line++ = '\0'; |
| 1319 | break; |
| 1320 | } |
| 1321 | |
| 1322 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1323 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1324 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1325 | return 1; |
| 1326 | } |
| 1327 | |
| 1328 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1329 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1330 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1331 | return 1; |
| 1332 | } |
| 1333 | |
| 1334 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1335 | 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] | 1336 | if (bi_putstr(si_ic(si), trash.str) == -1) |
| 1337 | si->flags |= SI_FL_WAIT_ROOM; |
| 1338 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1339 | return 1; |
| 1340 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1341 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1342 | /* Set flags. */ |
| 1343 | if (args[1][0] == 'm') |
| 1344 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1345 | else |
| 1346 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1347 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1348 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1349 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1350 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1351 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1352 | else |
| 1353 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1354 | appctx->st0 = STAT_CLI_PRINT; |
| 1355 | return 1; |
| 1356 | } |
| 1357 | |
| 1358 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1359 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1360 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1361 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1362 | 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] | 1363 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1364 | 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] | 1365 | appctx->st0 = STAT_CLI_PRINT; |
| 1366 | return 1; |
| 1367 | } |
| 1368 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1369 | /* copy input string. The string must be allocated because |
| 1370 | * it may be used over multiple iterations. It's released |
| 1371 | * at the end and upon abort anyway. |
| 1372 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1373 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1374 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1375 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1376 | if (!appctx->ctx.map.chunk.str) { |
| 1377 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1378 | appctx->st0 = STAT_CLI_PRINT; |
| 1379 | return 1; |
| 1380 | } |
| 1381 | |
| 1382 | /* prepare response */ |
| 1383 | appctx->st2 = STAT_ST_INIT; |
| 1384 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1385 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1386 | else { /* not "get weight" */ |
| 1387 | return 0; |
| 1388 | } |
| 1389 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1390 | else if (strcmp(args[0], "set") == 0) { |
| 1391 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1392 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1393 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1394 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1395 | sv = expect_server_admin(s, si, args[2]); |
| 1396 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1397 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1398 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1399 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1400 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1401 | appctx->ctx.cli.msg = warning; |
| 1402 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1403 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1404 | return 1; |
| 1405 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1406 | else if (strcmp(args[1], "server") == 0) { |
| 1407 | struct server *sv; |
| 1408 | const char *warning; |
| 1409 | |
| 1410 | sv = expect_server_admin(s, si, args[2]); |
| 1411 | if (!sv) |
| 1412 | return 1; |
| 1413 | |
| 1414 | if (strcmp(args[3], "weight") == 0) { |
| 1415 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1416 | if (warning) { |
| 1417 | appctx->ctx.cli.msg = warning; |
| 1418 | appctx->st0 = STAT_CLI_PRINT; |
| 1419 | } |
| 1420 | } |
| 1421 | else if (strcmp(args[3], "state") == 0) { |
| 1422 | if (strcmp(args[4], "ready") == 0) |
| 1423 | srv_adm_set_ready(sv); |
| 1424 | else if (strcmp(args[4], "drain") == 0) |
| 1425 | srv_adm_set_drain(sv); |
| 1426 | else if (strcmp(args[4], "maint") == 0) |
| 1427 | srv_adm_set_maint(sv); |
| 1428 | else { |
| 1429 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1430 | appctx->st0 = STAT_CLI_PRINT; |
| 1431 | } |
| 1432 | } |
| 1433 | else if (strcmp(args[3], "health") == 0) { |
| 1434 | if (sv->track) { |
| 1435 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1436 | appctx->st0 = STAT_CLI_PRINT; |
| 1437 | } |
| 1438 | else if (strcmp(args[4], "up") == 0) { |
| 1439 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1440 | srv_set_running(sv, "changed from CLI"); |
| 1441 | } |
| 1442 | else if (strcmp(args[4], "stopping") == 0) { |
| 1443 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1444 | srv_set_stopping(sv, "changed from CLI"); |
| 1445 | } |
| 1446 | else if (strcmp(args[4], "down") == 0) { |
| 1447 | sv->check.health = 0; |
| 1448 | srv_set_stopped(sv, "changed from CLI"); |
| 1449 | } |
| 1450 | else { |
| 1451 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1452 | appctx->st0 = STAT_CLI_PRINT; |
| 1453 | } |
| 1454 | } |
| 1455 | else if (strcmp(args[3], "agent") == 0) { |
| 1456 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1457 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1458 | appctx->st0 = STAT_CLI_PRINT; |
| 1459 | } |
| 1460 | else if (strcmp(args[4], "up") == 0) { |
| 1461 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1462 | srv_set_running(sv, "changed from CLI"); |
| 1463 | } |
| 1464 | else if (strcmp(args[4], "down") == 0) { |
| 1465 | sv->agent.health = 0; |
| 1466 | srv_set_stopped(sv, "changed from CLI"); |
| 1467 | } |
| 1468 | else { |
| 1469 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1470 | appctx->st0 = STAT_CLI_PRINT; |
| 1471 | } |
| 1472 | } |
| 1473 | else { |
| 1474 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state' and 'weight'.\n"; |
| 1475 | appctx->st0 = STAT_CLI_PRINT; |
| 1476 | } |
| 1477 | return 1; |
| 1478 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1479 | else if (strcmp(args[1], "timeout") == 0) { |
| 1480 | if (strcmp(args[2], "cli") == 0) { |
| 1481 | unsigned timeout; |
| 1482 | const char *res; |
| 1483 | |
| 1484 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1485 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1486 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1487 | return 1; |
| 1488 | } |
| 1489 | |
| 1490 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1491 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1492 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1493 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1494 | return 1; |
| 1495 | } |
| 1496 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1497 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1498 | return 1; |
| 1499 | } |
| 1500 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1501 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1502 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1503 | return 1; |
| 1504 | } |
| 1505 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1506 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1507 | if (strcmp(args[2], "frontend") == 0) { |
| 1508 | struct proxy *px; |
| 1509 | struct listener *l; |
| 1510 | int v; |
| 1511 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1512 | px = expect_frontend_admin(s, si, args[3]); |
| 1513 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1514 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1515 | |
| 1516 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1517 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1518 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1519 | return 1; |
| 1520 | } |
| 1521 | |
| 1522 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1523 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1524 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1525 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1526 | return 1; |
| 1527 | } |
| 1528 | |
| 1529 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1530 | * its listeners. The blocked ones will be dequeued. |
| 1531 | */ |
| 1532 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1533 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1534 | l->maxconn = v; |
| 1535 | if (l->state == LI_FULL) |
| 1536 | resume_listener(l); |
| 1537 | } |
| 1538 | |
| 1539 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1540 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1541 | |
| 1542 | return 1; |
| 1543 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1544 | else if (strcmp(args[2], "global") == 0) { |
| 1545 | int v; |
| 1546 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1547 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1548 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1549 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1550 | return 1; |
| 1551 | } |
| 1552 | |
| 1553 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1554 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1555 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1556 | return 1; |
| 1557 | } |
| 1558 | |
| 1559 | v = atoi(args[3]); |
| 1560 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1561 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1562 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1563 | return 1; |
| 1564 | } |
| 1565 | |
| 1566 | /* check for unlimited values */ |
| 1567 | if (v <= 0) |
| 1568 | v = global.hardmaxconn; |
| 1569 | |
| 1570 | global.maxconn = v; |
| 1571 | |
| 1572 | /* Dequeues all of the listeners waiting for a resource */ |
| 1573 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1574 | dequeue_all_listeners(&global_listener_queue); |
| 1575 | |
| 1576 | return 1; |
| 1577 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1578 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1579 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1580 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1581 | return 1; |
| 1582 | } |
| 1583 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1584 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1585 | if (strcmp(args[2], "connections") == 0) { |
| 1586 | if (strcmp(args[3], "global") == 0) { |
| 1587 | int v; |
| 1588 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1589 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1590 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1591 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1592 | return 1; |
| 1593 | } |
| 1594 | |
| 1595 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1596 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1597 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1598 | return 1; |
| 1599 | } |
| 1600 | |
| 1601 | v = atoi(args[4]); |
| 1602 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1603 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1604 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1605 | return 1; |
| 1606 | } |
| 1607 | |
| 1608 | global.cps_lim = v; |
| 1609 | |
| 1610 | /* Dequeues all of the listeners waiting for a resource */ |
| 1611 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1612 | dequeue_all_listeners(&global_listener_queue); |
| 1613 | |
| 1614 | return 1; |
| 1615 | } |
| 1616 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1617 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1618 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1619 | return 1; |
| 1620 | } |
| 1621 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1622 | else if (strcmp(args[2], "sessions") == 0) { |
| 1623 | if (strcmp(args[3], "global") == 0) { |
| 1624 | int v; |
| 1625 | |
| 1626 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1627 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1628 | appctx->st0 = STAT_CLI_PRINT; |
| 1629 | return 1; |
| 1630 | } |
| 1631 | |
| 1632 | if (!*args[4]) { |
| 1633 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1634 | appctx->st0 = STAT_CLI_PRINT; |
| 1635 | return 1; |
| 1636 | } |
| 1637 | |
| 1638 | v = atoi(args[4]); |
| 1639 | if (v < 0) { |
| 1640 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1641 | appctx->st0 = STAT_CLI_PRINT; |
| 1642 | return 1; |
| 1643 | } |
| 1644 | |
| 1645 | global.sps_lim = v; |
| 1646 | |
| 1647 | /* Dequeues all of the listeners waiting for a resource */ |
| 1648 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1649 | dequeue_all_listeners(&global_listener_queue); |
| 1650 | |
| 1651 | return 1; |
| 1652 | } |
| 1653 | else { |
| 1654 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1655 | appctx->st0 = STAT_CLI_PRINT; |
| 1656 | return 1; |
| 1657 | } |
| 1658 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1659 | #ifdef USE_OPENSSL |
| 1660 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1661 | if (strcmp(args[3], "global") == 0) { |
| 1662 | int v; |
| 1663 | |
| 1664 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1665 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1666 | appctx->st0 = STAT_CLI_PRINT; |
| 1667 | return 1; |
| 1668 | } |
| 1669 | |
| 1670 | if (!*args[4]) { |
| 1671 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1672 | appctx->st0 = STAT_CLI_PRINT; |
| 1673 | return 1; |
| 1674 | } |
| 1675 | |
| 1676 | v = atoi(args[4]); |
| 1677 | if (v < 0) { |
| 1678 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1679 | appctx->st0 = STAT_CLI_PRINT; |
| 1680 | return 1; |
| 1681 | } |
| 1682 | |
| 1683 | global.ssl_lim = v; |
| 1684 | |
| 1685 | /* Dequeues all of the listeners waiting for a resource */ |
| 1686 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1687 | dequeue_all_listeners(&global_listener_queue); |
| 1688 | |
| 1689 | return 1; |
| 1690 | } |
| 1691 | else { |
| 1692 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1693 | appctx->st0 = STAT_CLI_PRINT; |
| 1694 | return 1; |
| 1695 | } |
| 1696 | } |
| 1697 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1698 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1699 | if (strcmp(args[3], "global") == 0) { |
| 1700 | int v; |
| 1701 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1702 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1703 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1704 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1705 | return 1; |
| 1706 | } |
| 1707 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1708 | v = atoi(args[4]); |
| 1709 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1710 | } |
| 1711 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1712 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1713 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1714 | return 1; |
| 1715 | } |
| 1716 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1717 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1718 | 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] | 1719 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1720 | return 1; |
| 1721 | } |
| 1722 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1723 | else if (strcmp(args[1], "table") == 0) { |
| 1724 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1725 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1726 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1727 | char *err; |
| 1728 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1729 | /* Set flags. */ |
| 1730 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1731 | |
| 1732 | /* Expect three parameters: map name, key and new value. */ |
| 1733 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1734 | 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] | 1735 | appctx->st0 = STAT_CLI_PRINT; |
| 1736 | return 1; |
| 1737 | } |
| 1738 | |
| 1739 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1740 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1741 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1742 | 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] | 1743 | appctx->st0 = STAT_CLI_PRINT; |
| 1744 | return 1; |
| 1745 | } |
| 1746 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1747 | /* If the entry identifier start with a '#', it is considered as |
| 1748 | * pointer id |
| 1749 | */ |
| 1750 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1751 | struct pat_ref_elt *ref; |
| 1752 | long long int conv; |
| 1753 | char *error; |
| 1754 | |
| 1755 | /* Convert argument to integer value. */ |
| 1756 | conv = strtoll(&args[3][1], &error, 16); |
| 1757 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1758 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1759 | appctx->st0 = STAT_CLI_PRINT; |
| 1760 | return 1; |
| 1761 | } |
| 1762 | |
| 1763 | /* Convert and check integer to pointer. */ |
| 1764 | ref = (struct pat_ref_elt *)(long)conv; |
| 1765 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1766 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1767 | appctx->st0 = STAT_CLI_PRINT; |
| 1768 | return 1; |
| 1769 | } |
| 1770 | |
| 1771 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1772 | err = NULL; |
| 1773 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1774 | if (err) |
| 1775 | memprintf(&err, "%s.\n", err); |
| 1776 | appctx->ctx.cli.err = err; |
| 1777 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1778 | return 1; |
| 1779 | } |
| 1780 | } |
| 1781 | else { |
| 1782 | /* Else, use the entry identifier as pattern |
| 1783 | * string, and update the value. |
| 1784 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1785 | err = NULL; |
| 1786 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1787 | if (err) |
| 1788 | memprintf(&err, "%s.\n", err); |
| 1789 | appctx->ctx.cli.err = err; |
| 1790 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1791 | return 1; |
| 1792 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1793 | } |
| 1794 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1795 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1796 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1797 | return 1; |
| 1798 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1799 | #ifdef USE_OPENSSL |
| 1800 | else if (strcmp(args[1], "ssl") == 0) { |
| 1801 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 1802 | #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] | 1803 | char *err = NULL; |
| 1804 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 1805 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1806 | if (!*args[3]) { |
| 1807 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 1808 | appctx->st0 = STAT_CLI_PRINT; |
| 1809 | return 1; |
| 1810 | } |
| 1811 | |
| 1812 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 1813 | if (trash.len < 0) { |
| 1814 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 1815 | appctx->st0 = STAT_CLI_PRINT; |
| 1816 | return 1; |
| 1817 | } |
| 1818 | |
| 1819 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 1820 | if (err) { |
| 1821 | memprintf(&err, "%s.\n", err); |
| 1822 | appctx->ctx.cli.err = err; |
| 1823 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 1824 | } |
| 1825 | return 1; |
| 1826 | } |
| 1827 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 1828 | appctx->st0 = STAT_CLI_PRINT; |
| 1829 | return 1; |
| 1830 | #else |
| 1831 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 1832 | appctx->st0 = STAT_CLI_PRINT; |
| 1833 | return 1; |
| 1834 | #endif |
| 1835 | } |
| 1836 | else { |
| 1837 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 1838 | appctx->st0 = STAT_CLI_PRINT; |
| 1839 | return 1; |
| 1840 | } |
| 1841 | } |
| 1842 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1843 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1844 | return 0; |
| 1845 | } |
| 1846 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1847 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1848 | if (strcmp(args[1], "agent") == 0) { |
| 1849 | struct server *sv; |
| 1850 | |
| 1851 | sv = expect_server_admin(s, si, args[2]); |
| 1852 | if (!sv) |
| 1853 | return 1; |
| 1854 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1855 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1856 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1857 | appctx->st0 = STAT_CLI_PRINT; |
| 1858 | return 1; |
| 1859 | } |
| 1860 | |
| 1861 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1862 | return 1; |
| 1863 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1864 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1865 | struct server *sv; |
| 1866 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1867 | sv = expect_server_admin(s, si, args[2]); |
| 1868 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1869 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1870 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1871 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 1872 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 1873 | appctx->st0 = STAT_CLI_PRINT; |
| 1874 | return 1; |
| 1875 | } |
| 1876 | |
| 1877 | sv->check.state |= CHK_ST_ENABLED; |
| 1878 | return 1; |
| 1879 | } |
| 1880 | else if (strcmp(args[1], "server") == 0) { |
| 1881 | struct server *sv; |
| 1882 | |
| 1883 | sv = expect_server_admin(s, si, args[2]); |
| 1884 | if (!sv) |
| 1885 | return 1; |
| 1886 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1887 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1888 | return 1; |
| 1889 | } |
| 1890 | else if (strcmp(args[1], "frontend") == 0) { |
| 1891 | struct proxy *px; |
| 1892 | |
| 1893 | px = expect_frontend_admin(s, si, args[2]); |
| 1894 | if (!px) |
| 1895 | return 1; |
| 1896 | |
| 1897 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1898 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1899 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1900 | return 1; |
| 1901 | } |
| 1902 | |
| 1903 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1904 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1905 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1906 | return 1; |
| 1907 | } |
| 1908 | |
| 1909 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1910 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1911 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1912 | return 1; |
| 1913 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1914 | return 1; |
| 1915 | } |
| 1916 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1917 | 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] | 1918 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1919 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1920 | } |
| 1921 | } |
| 1922 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1923 | if (strcmp(args[1], "agent") == 0) { |
| 1924 | struct server *sv; |
| 1925 | |
| 1926 | sv = expect_server_admin(s, si, args[2]); |
| 1927 | if (!sv) |
| 1928 | return 1; |
| 1929 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1930 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1931 | return 1; |
| 1932 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1933 | else if (strcmp(args[1], "health") == 0) { |
| 1934 | struct server *sv; |
| 1935 | |
| 1936 | sv = expect_server_admin(s, si, args[2]); |
| 1937 | if (!sv) |
| 1938 | return 1; |
| 1939 | |
| 1940 | sv->check.state &= ~CHK_ST_ENABLED; |
| 1941 | return 1; |
| 1942 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1943 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1944 | struct server *sv; |
| 1945 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1946 | sv = expect_server_admin(s, si, args[2]); |
| 1947 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1948 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1949 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1950 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1951 | return 1; |
| 1952 | } |
| 1953 | else if (strcmp(args[1], "frontend") == 0) { |
| 1954 | struct proxy *px; |
| 1955 | |
| 1956 | px = expect_frontend_admin(s, si, args[2]); |
| 1957 | if (!px) |
| 1958 | return 1; |
| 1959 | |
| 1960 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1961 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1962 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1963 | return 1; |
| 1964 | } |
| 1965 | |
| 1966 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1967 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1968 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1969 | return 1; |
| 1970 | } |
| 1971 | |
| 1972 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1973 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1974 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1975 | return 1; |
| 1976 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1977 | return 1; |
| 1978 | } |
| 1979 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1980 | 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] | 1981 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1982 | return 1; |
| 1983 | } |
| 1984 | } |
| 1985 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1986 | if (strcmp(args[1], "frontend") == 0) { |
| 1987 | struct proxy *px; |
| 1988 | |
| 1989 | px = expect_frontend_admin(s, si, args[2]); |
| 1990 | if (!px) |
| 1991 | return 1; |
| 1992 | |
| 1993 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1994 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1995 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1996 | return 1; |
| 1997 | } |
| 1998 | |
| 1999 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2000 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2001 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2002 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2003 | stop_proxy(px); |
| 2004 | return 1; |
| 2005 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2006 | else if (strcmp(args[1], "session") == 0) { |
| 2007 | struct session *sess, *ptr; |
| 2008 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 2009 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2010 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2011 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2012 | return 1; |
| 2013 | } |
| 2014 | |
| 2015 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2016 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2017 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2018 | return 1; |
| 2019 | } |
| 2020 | |
| 2021 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2022 | |
| 2023 | /* first, look for the requested session in the session table */ |
| 2024 | list_for_each_entry(sess, &sessions, list) { |
| 2025 | if (sess == ptr) |
| 2026 | break; |
| 2027 | } |
| 2028 | |
| 2029 | /* do we have the session ? */ |
| 2030 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2031 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2032 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2033 | return 1; |
| 2034 | } |
| 2035 | |
| 2036 | session_shutdown(sess, SN_ERR_KILLED); |
| 2037 | return 1; |
| 2038 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2039 | else if (strcmp(args[1], "sessions") == 0) { |
| 2040 | if (strcmp(args[2], "server") == 0) { |
| 2041 | struct server *sv; |
| 2042 | struct session *sess, *sess_bck; |
| 2043 | |
| 2044 | sv = expect_server_admin(s, si, args[3]); |
| 2045 | if (!sv) |
| 2046 | return 1; |
| 2047 | |
| 2048 | /* kill all the session that are on this server */ |
| 2049 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2050 | if (sess->srv_conn == sv) |
| 2051 | session_shutdown(sess, SN_ERR_KILLED); |
| 2052 | |
| 2053 | return 1; |
| 2054 | } |
| 2055 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2056 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2057 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2058 | return 1; |
| 2059 | } |
| 2060 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2061 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2062 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2063 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2064 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2065 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2066 | } |
| 2067 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2068 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2069 | if (args[1][0] == 'm') |
| 2070 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2071 | else |
| 2072 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2073 | |
| 2074 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2075 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2076 | if (!*args[2] || !*args[3]) { |
| 2077 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2078 | appctx->st0 = STAT_CLI_PRINT; |
| 2079 | return 1; |
| 2080 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2081 | } |
| 2082 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2083 | else { |
| 2084 | if (!*args[2] || !*args[3]) { |
| 2085 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2086 | appctx->st0 = STAT_CLI_PRINT; |
| 2087 | return 1; |
| 2088 | } |
| 2089 | } |
| 2090 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2091 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2092 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2093 | if (!appctx->ctx.map.ref || |
| 2094 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2095 | 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] | 2096 | appctx->st0 = STAT_CLI_PRINT; |
| 2097 | return 1; |
| 2098 | } |
| 2099 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2100 | /* If the entry identifier start with a '#', it is considered as |
| 2101 | * pointer id |
| 2102 | */ |
| 2103 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2104 | struct pat_ref_elt *ref; |
| 2105 | long long int conv; |
| 2106 | char *error; |
| 2107 | |
| 2108 | /* Convert argument to integer value. */ |
| 2109 | conv = strtoll(&args[3][1], &error, 16); |
| 2110 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2111 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2112 | appctx->st0 = STAT_CLI_PRINT; |
| 2113 | return 1; |
| 2114 | } |
| 2115 | |
| 2116 | /* Convert and check integer to pointer. */ |
| 2117 | ref = (struct pat_ref_elt *)(long)conv; |
| 2118 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2119 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2120 | appctx->st0 = STAT_CLI_PRINT; |
| 2121 | return 1; |
| 2122 | } |
| 2123 | |
| 2124 | /* Try to delete the entry. */ |
| 2125 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2126 | /* The entry is not found, send message. */ |
| 2127 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2128 | appctx->st0 = STAT_CLI_PRINT; |
| 2129 | return 1; |
| 2130 | } |
| 2131 | } |
| 2132 | else { |
| 2133 | /* Else, use the entry identifier as pattern |
| 2134 | * string and try to delete the entry. |
| 2135 | */ |
| 2136 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2137 | /* The entry is not found, send message. */ |
| 2138 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2139 | appctx->st0 = STAT_CLI_PRINT; |
| 2140 | return 1; |
| 2141 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2142 | } |
| 2143 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2144 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2145 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2146 | return 1; |
| 2147 | } |
| 2148 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2149 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2150 | appctx->st0 = STAT_CLI_PRINT; |
| 2151 | return 1; |
| 2152 | } |
| 2153 | } |
| 2154 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2155 | if (strcmp(args[1], "map") == 0 || |
| 2156 | strcmp(args[1], "acl") == 0) { |
| 2157 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2158 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2159 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2160 | /* Set flags. */ |
| 2161 | if (args[1][0] == 'm') |
| 2162 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2163 | else |
| 2164 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2165 | |
| 2166 | /* If the keywork is "map", we expect three parameters, if it |
| 2167 | * is "acl", we expect only two parameters |
| 2168 | */ |
| 2169 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2170 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2171 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2172 | appctx->st0 = STAT_CLI_PRINT; |
| 2173 | return 1; |
| 2174 | } |
| 2175 | } |
| 2176 | else { |
| 2177 | if (!*args[2] || !*args[3]) { |
| 2178 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2179 | appctx->st0 = STAT_CLI_PRINT; |
| 2180 | return 1; |
| 2181 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2182 | } |
| 2183 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2184 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2185 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2186 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2187 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2188 | 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] | 2189 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2190 | 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] | 2191 | appctx->st0 = STAT_CLI_PRINT; |
| 2192 | return 1; |
| 2193 | } |
| 2194 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2195 | /* The command "add acl" is prohibited if the reference |
| 2196 | * use samples. |
| 2197 | */ |
| 2198 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2199 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2200 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2201 | "You must use the command 'add map' to add values.\n"; |
| 2202 | appctx->st0 = STAT_CLI_PRINT; |
| 2203 | return 1; |
| 2204 | } |
| 2205 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2206 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2207 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2208 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2209 | 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] | 2210 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2211 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2212 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2213 | if (err) |
| 2214 | memprintf(&err, "%s.\n", err); |
| 2215 | appctx->ctx.cli.err = err; |
| 2216 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2217 | return 1; |
| 2218 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2219 | |
| 2220 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2221 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2222 | return 1; |
| 2223 | } |
| 2224 | else { /* unknown "del" parameter */ |
| 2225 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2226 | appctx->st0 = STAT_CLI_PRINT; |
| 2227 | return 1; |
| 2228 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2229 | } |
| 2230 | 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] | 2231 | return 0; |
| 2232 | } |
| 2233 | return 1; |
| 2234 | } |
| 2235 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2236 | /* 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] | 2237 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2238 | * state machine handling requests and various responses. We read a request, |
| 2239 | * 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] | 2240 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2241 | * 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] | 2242 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2243 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2244 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2245 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2246 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2247 | struct channel *req = si_oc(si); |
| 2248 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2249 | int reql; |
| 2250 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2251 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2252 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2253 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2254 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2255 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2256 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2257 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2258 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2259 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2260 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2261 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2262 | /* Let's close for real now. We just close the request |
| 2263 | * side, the conditions below will complete if needed. |
| 2264 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2265 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2266 | break; |
| 2267 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2268 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2269 | /* ensure we have some output room left in the event we |
| 2270 | * would want to return some info right after parsing. |
| 2271 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2272 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2273 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2274 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2275 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2276 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2277 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2278 | if (reql <= 0) { /* closed or EOL not found */ |
| 2279 | if (reql == 0) |
| 2280 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2281 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2282 | continue; |
| 2283 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2284 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2285 | /* seek for a possible semi-colon. If we find one, we |
| 2286 | * replace it with an LF and skip only this part. |
| 2287 | */ |
| 2288 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2289 | if (trash.str[len] == ';') { |
| 2290 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2291 | reql = len + 1; |
| 2292 | break; |
| 2293 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2294 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2295 | /* now it is time to check that we have a full line, |
| 2296 | * remove the trailing \n and possibly \r, then cut the |
| 2297 | * line. |
| 2298 | */ |
| 2299 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2300 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2301 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2302 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2303 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2304 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2305 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2306 | len--; |
| 2307 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2308 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2309 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2310 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2311 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2312 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2313 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2314 | continue; |
| 2315 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2316 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2317 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2318 | else if (strcmp(trash.str, "help") == 0 || |
| 2319 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2320 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2321 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2322 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2323 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2324 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2325 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2326 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2327 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2328 | /* if prompt is disabled, print help on empty lines, |
| 2329 | * so that the user at least knows how to enable |
| 2330 | * prompt and find help. |
| 2331 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2332 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2333 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2337 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2338 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2339 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2340 | else { /* output functions: first check if the output buffer is closed then abort */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2341 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 2342 | cli_release_handler(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2343 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2344 | continue; |
| 2345 | } |
| 2346 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2347 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2348 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2349 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2350 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2351 | else |
| 2352 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2353 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2354 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2355 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2356 | free(appctx->ctx.cli.err); |
| 2357 | appctx->st0 = STAT_CLI_PROMPT; |
| 2358 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2359 | else |
| 2360 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2361 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2362 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2363 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2364 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2365 | break; |
| 2366 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2367 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2368 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2369 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2370 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2371 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2372 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2373 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2374 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2375 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2376 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2377 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2378 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2379 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2380 | if (stats_table_request(si, appctx->st0)) |
| 2381 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2382 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2383 | case STAT_CLI_O_PATS: |
| 2384 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2385 | appctx->st0 = STAT_CLI_PROMPT; |
| 2386 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2387 | case STAT_CLI_O_PAT: |
| 2388 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2389 | appctx->st0 = STAT_CLI_PROMPT; |
| 2390 | break; |
| 2391 | case STAT_CLI_O_MLOOK: |
| 2392 | if (stats_map_lookup(si)) |
| 2393 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2394 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2395 | case STAT_CLI_O_POOLS: |
| 2396 | if (stats_dump_pools_to_buffer(si)) |
| 2397 | appctx->st0 = STAT_CLI_PROMPT; |
| 2398 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2399 | default: /* abnormal state */ |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 2400 | cli_release_handler(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2401 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2402 | break; |
| 2403 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2404 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2405 | /* 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] | 2406 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2407 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2408 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2409 | else |
| 2410 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2411 | } |
| 2412 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2413 | /* 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] | 2414 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2415 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2416 | |
| 2417 | /* Now we close the output if one of the writers did so, |
| 2418 | * or if we're not in interactive mode and the request |
| 2419 | * buffer is empty. This still allows pipelined requests |
| 2420 | * to be sent in non-interactive mode. |
| 2421 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2422 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2423 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2424 | continue; |
| 2425 | } |
| 2426 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2427 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2428 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2429 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2430 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2431 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2432 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST) && (appctx->st0 != STAT_CLI_GETREQ)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2433 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2434 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2435 | /* 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] | 2436 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2437 | * we forward the close to the request side so that it flows upstream to |
| 2438 | * the client. |
| 2439 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2440 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2441 | } |
| 2442 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2443 | 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] | 2444 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2445 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2446 | /* We have no more processing to do, and nothing more to send, and |
| 2447 | * the client side has closed. So we'll forward this state downstream |
| 2448 | * on the response buffer. |
| 2449 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2450 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2451 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2455 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2456 | |
| 2457 | /* we don't want to expire timeouts while we're processing requests */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2458 | si_ic(si)->rex = TICK_ETERNITY; |
| 2459 | si_oc(si)->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2460 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2461 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2462 | 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] | 2463 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2464 | si->state, req->flags, res->flags, req->buf->i, req->buf->o, res->buf->i, res->buf->o); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2465 | |
| 2466 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2467 | /* check that we have released everything then unregister */ |
| 2468 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2469 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2470 | } |
| 2471 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2472 | /* This function dumps information onto the stream interface's read buffer. |
| 2473 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2474 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2475 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2476 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2477 | { |
| 2478 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2479 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2480 | #ifdef USE_OPENSSL |
| 2481 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2482 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2483 | int ssl_reuse = 0; |
| 2484 | |
| 2485 | if (ssl_key_rate < ssl_sess_rate) { |
| 2486 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2487 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2488 | } |
| 2489 | #endif |
| 2490 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2491 | chunk_printf(&trash, |
| 2492 | "Name: " PRODUCT_NAME "\n" |
| 2493 | "Version: " HAPROXY_VERSION "\n" |
| 2494 | "Release_date: " HAPROXY_DATE "\n" |
| 2495 | "Nbproc: %d\n" |
| 2496 | "Process_num: %d\n" |
| 2497 | "Pid: %d\n" |
| 2498 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2499 | "Uptime_sec: %d\n" |
| 2500 | "Memmax_MB: %d\n" |
| 2501 | "Ulimit-n: %d\n" |
| 2502 | "Maxsock: %d\n" |
| 2503 | "Maxconn: %d\n" |
| 2504 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2505 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2506 | "CumConns: %d\n" |
Warren Turkal | b197d7f | 2015-01-27 15:04:16 -0800 | [diff] [blame] | 2507 | "CumReq: %u\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2508 | #ifdef USE_OPENSSL |
| 2509 | "MaxSslConns: %d\n" |
| 2510 | "CurrSslConns: %d\n" |
| 2511 | "CumSslConns: %d\n" |
| 2512 | #endif |
| 2513 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2514 | "PipesUsed: %d\n" |
| 2515 | "PipesFree: %d\n" |
| 2516 | "ConnRate: %d\n" |
| 2517 | "ConnRateLimit: %d\n" |
| 2518 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2519 | "SessRate: %d\n" |
| 2520 | "SessRateLimit: %d\n" |
| 2521 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2522 | #ifdef USE_OPENSSL |
| 2523 | "SslRate: %d\n" |
| 2524 | "SslRateLimit: %d\n" |
| 2525 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2526 | "SslFrontendKeyRate: %d\n" |
| 2527 | "SslFrontendMaxKeyRate: %d\n" |
| 2528 | "SslFrontendSessionReuse_pct: %d\n" |
| 2529 | "SslBackendKeyRate: %d\n" |
| 2530 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2531 | "SslCacheLookups: %u\n" |
| 2532 | "SslCacheMisses: %u\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2533 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2534 | "CompressBpsIn: %u\n" |
| 2535 | "CompressBpsOut: %u\n" |
| 2536 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2537 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2538 | "ZlibMemUsage: %ld\n" |
| 2539 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2540 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2541 | "Tasks: %d\n" |
| 2542 | "Run_queue: %d\n" |
| 2543 | "Idle_pct: %d\n" |
| 2544 | "node: %s\n" |
| 2545 | "description: %s\n" |
| 2546 | "", |
| 2547 | global.nbproc, |
| 2548 | relative_pid, |
| 2549 | pid, |
| 2550 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2551 | up, |
| 2552 | global.rlimit_memmax, |
| 2553 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2554 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2555 | actconn, totalconn, global.req_count, |
| 2556 | #ifdef USE_OPENSSL |
| 2557 | global.maxsslconn, sslconns, totalsslconns, |
| 2558 | #endif |
| 2559 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2560 | read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max, |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2561 | read_freq_ctr(&global.sess_per_sec), global.sps_lim, global.sps_max, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2562 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2563 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2564 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2565 | ssl_reuse, |
| 2566 | read_freq_ctr(&global.ssl_be_keys_per_sec), global.ssl_be_keys_max, |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2567 | global.shctx_lookups, global.shctx_misses, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2568 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2569 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2570 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2571 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2572 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2573 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2574 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2575 | global.node, global.desc ? global.desc : "" |
| 2576 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2577 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2578 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 2579 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2580 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2581 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2582 | |
| 2583 | return 1; |
| 2584 | } |
| 2585 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2586 | /* This function dumps memory usage information onto the stream interface's |
| 2587 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2588 | * completion. No state is used. |
| 2589 | */ |
| 2590 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2591 | { |
| 2592 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2593 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 2594 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2595 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2596 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2597 | return 1; |
| 2598 | } |
| 2599 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2600 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2601 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2602 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2603 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2604 | static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2605 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2606 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2607 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2608 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2609 | if (!(px->cap & PR_CAP_FE)) |
| 2610 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2611 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2612 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE))) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2613 | return 0; |
| 2614 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2615 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2616 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2617 | /* name, queue */ |
| 2618 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2619 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2620 | 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] | 2621 | /* Column sub-heading for Enable or Disable server */ |
| 2622 | chunk_appendf(&trash, "<td></td>"); |
| 2623 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2624 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2625 | chunk_appendf(&trash, |
| 2626 | "<td class=ac>" |
| 2627 | "<a name=\"%s/Frontend\"></a>" |
| 2628 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2629 | "<td colspan=3></td>" |
| 2630 | "", |
| 2631 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2632 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2633 | chunk_appendf(&trash, |
| 2634 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2635 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2636 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2637 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2638 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2639 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2640 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2641 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2642 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2643 | if (px->mode == PR_MODE_HTTP) |
| 2644 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2645 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2646 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2647 | |
| 2648 | chunk_appendf(&trash, |
| 2649 | "</table></div></u></td>" |
| 2650 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2651 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2652 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2653 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2654 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2655 | U2H(px->fe_counters.sps_max), |
| 2656 | U2H(px->fe_counters.cps_max), |
| 2657 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2658 | |
| 2659 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2660 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2661 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2662 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2663 | |
| 2664 | chunk_appendf(&trash, |
| 2665 | "</table></div></u></td>" |
| 2666 | /* sessions rate : limit */ |
| 2667 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2668 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2669 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2670 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2671 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2672 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2673 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2674 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2675 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2676 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2677 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2678 | U2H(px->fe_counters.cum_sess), |
| 2679 | U2H(px->fe_counters.cum_conn), |
| 2680 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2681 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2682 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2683 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2684 | chunk_appendf(&trash, |
| 2685 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2686 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2687 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2688 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2689 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2690 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2691 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2692 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2693 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2694 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2695 | U2H(px->fe_counters.p.http.cum_req), |
| 2696 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2697 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2698 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2699 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2700 | (int)(100*px->fe_counters.p.http.comp_rsp/px->fe_counters.p.http.rsp[2]) : 0, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2701 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2702 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2703 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2704 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2705 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2706 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2707 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2708 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2709 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2710 | /* sessions: lbtot, lastsess */ |
| 2711 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2712 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2713 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2714 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2715 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2716 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2717 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2718 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2719 | "<td>%s%s<div class=tips>compression: in=%lld out=%lld bypassed=%lld savings=%d%%</div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2720 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2721 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2722 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2723 | px->fe_counters.comp_in ? |
| 2724 | (int)((px->fe_counters.comp_in - px->fe_counters.comp_out)*100/px->fe_counters.comp_in) : 0, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2725 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2726 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2727 | chunk_appendf(&trash, |
| 2728 | /* denied: req, resp */ |
| 2729 | "<td>%s</td><td>%s</td>" |
| 2730 | /* errors : request, connect, response */ |
| 2731 | "<td>%s</td><td></td><td></td>" |
| 2732 | /* warnings: retries, redispatches */ |
| 2733 | "<td></td><td></td>" |
| 2734 | /* server status : reflect frontend status */ |
| 2735 | "<td class=ac>%s</td>" |
| 2736 | /* rest of server: nothing */ |
| 2737 | "<td class=ac colspan=8></td></tr>" |
| 2738 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2739 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2740 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2741 | px->state == PR_STREADY ? "OPEN" : |
| 2742 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2743 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2744 | else { /* CSV mode */ |
| 2745 | chunk_appendf(&trash, |
| 2746 | /* pxid, name, queue cur, queue max, */ |
| 2747 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2748 | /* sessions : current, max, limit, total */ |
| 2749 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2750 | /* bytes : in, out */ |
| 2751 | "%lld,%lld," |
| 2752 | /* denied: req, resp */ |
| 2753 | "%lld,%lld," |
| 2754 | /* errors : request, connect, response */ |
| 2755 | "%lld,,," |
| 2756 | /* warnings: retries, redispatches */ |
| 2757 | ",," |
| 2758 | /* server status : reflect frontend status */ |
| 2759 | "%s," |
| 2760 | /* rest of server: nothing */ |
| 2761 | ",,,,,,,," |
| 2762 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2763 | "%d,%d,0,,,,%d," |
| 2764 | /* rate, rate_lim, rate_max */ |
| 2765 | "%u,%u,%u," |
| 2766 | /* check_status, check_code, check_duration */ |
| 2767 | ",,,", |
| 2768 | px->id, |
| 2769 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2770 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2771 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2772 | px->fe_counters.failed_req, |
| 2773 | px->state == PR_STREADY ? "OPEN" : |
| 2774 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2775 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2776 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2777 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2778 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2779 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2780 | if (px->mode == PR_MODE_HTTP) { |
| 2781 | for (i=1; i<6; i++) |
| 2782 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2783 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2784 | } |
| 2785 | else |
| 2786 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2787 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2788 | /* failed health analyses */ |
| 2789 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2790 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2791 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2792 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2793 | read_freq_ctr(&px->fe_req_per_sec), |
| 2794 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2795 | |
| 2796 | /* errors: cli_aborts, srv_aborts */ |
| 2797 | chunk_appendf(&trash, ",,"); |
| 2798 | |
| 2799 | /* compression: in, out, bypassed */ |
| 2800 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2801 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2802 | |
| 2803 | /* compression: comp_rsp */ |
| 2804 | chunk_appendf(&trash, "%lld,", |
| 2805 | px->fe_counters.p.http.comp_rsp); |
| 2806 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2807 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2808 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2809 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2810 | /* finish with EOL */ |
| 2811 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2812 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2813 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2814 | } |
| 2815 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2816 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2817 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2818 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2819 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2820 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2821 | static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2822 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2823 | struct appctx *appctx = __objt_appctx(si->end); |
| 2824 | |
| 2825 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2826 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2827 | 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] | 2828 | /* Column sub-heading for Enable or Disable server */ |
| 2829 | chunk_appendf(&trash, "<td></td>"); |
| 2830 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2831 | chunk_appendf(&trash, |
| 2832 | /* frontend name, listener name */ |
| 2833 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2834 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2835 | "", |
| 2836 | px->id, l->name, |
| 2837 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2838 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2839 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2840 | if (flags & ST_SHLGNDS) { |
| 2841 | char str[INET6_ADDRSTRLEN]; |
| 2842 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2843 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2844 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2845 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2846 | port = get_host_port(&l->addr); |
| 2847 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2848 | case AF_INET: |
| 2849 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2850 | break; |
| 2851 | case AF_INET6: |
| 2852 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2853 | break; |
| 2854 | case AF_UNIX: |
| 2855 | chunk_appendf(&trash, "unix, "); |
| 2856 | break; |
| 2857 | case -1: |
| 2858 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2859 | break; |
| 2860 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2861 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2862 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2863 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2864 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2865 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2866 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2867 | /* queue */ |
| 2868 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2869 | /* sessions rate: current, max, limit */ |
| 2870 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2871 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2872 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2873 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2874 | /* bytes: in, out */ |
| 2875 | "<td>%s</td><td>%s</td>" |
| 2876 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2877 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2878 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2879 | U2H(l->counters->cum_conn), U2H(l->counters->bytes_in), U2H(l->counters->bytes_out)); |
Willy Tarreau | 56a560a | 2009-09-22 19:27:35 +0200 | [diff] [blame] | 2880 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2881 | chunk_appendf(&trash, |
| 2882 | /* denied: req, resp */ |
| 2883 | "<td>%s</td><td>%s</td>" |
| 2884 | /* errors: request, connect, response */ |
| 2885 | "<td>%s</td><td></td><td></td>" |
| 2886 | /* warnings: retries, redispatches */ |
| 2887 | "<td></td><td></td>" |
| 2888 | /* server status: reflect listener status */ |
| 2889 | "<td class=ac>%s</td>" |
| 2890 | /* rest of server: nothing */ |
| 2891 | "<td class=ac colspan=8></td></tr>" |
| 2892 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2893 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2894 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2895 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2896 | } |
| 2897 | else { /* CSV mode */ |
| 2898 | chunk_appendf(&trash, |
| 2899 | /* pxid, name, queue cur, queue max, */ |
| 2900 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2901 | /* sessions: current, max, limit, total */ |
| 2902 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2903 | /* bytes: in, out */ |
| 2904 | "%lld,%lld," |
| 2905 | /* denied: req, resp */ |
| 2906 | "%lld,%lld," |
| 2907 | /* errors: request, connect, response */ |
| 2908 | "%lld,,," |
| 2909 | /* warnings: retries, redispatches */ |
| 2910 | ",," |
| 2911 | /* server status: reflect listener status */ |
| 2912 | "%s," |
| 2913 | /* rest of server: nothing */ |
| 2914 | ",,,,,,,," |
| 2915 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2916 | "%d,%d,%d,,,,%d," |
| 2917 | /* rate, rate_lim, rate_max */ |
| 2918 | ",,," |
| 2919 | /* check_status, check_code, check_duration */ |
| 2920 | ",,," |
| 2921 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2922 | ",,,,,," |
| 2923 | /* failed health analyses */ |
| 2924 | "," |
| 2925 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2926 | ",,," |
| 2927 | /* errors: cli_aborts, srv_aborts */ |
| 2928 | ",," |
| 2929 | /* compression: in, out, bypassed, comp_rsp */ |
| 2930 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2931 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2932 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2933 | "\n", |
| 2934 | px->id, l->name, |
| 2935 | l->nbconn, l->counters->conn_max, |
| 2936 | l->maxconn, l->counters->cum_conn, |
| 2937 | l->counters->bytes_in, l->counters->bytes_out, |
| 2938 | l->counters->denied_req, l->counters->denied_resp, |
| 2939 | l->counters->failed_req, |
| 2940 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2941 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2942 | } |
| 2943 | return 1; |
| 2944 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2945 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2946 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2947 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2948 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2949 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2950 | * following values : 0=DOWN, 1=DOWN(agent) 2=going up, 3=going down, 4=UP, 5,6=NOLB, |
| 2951 | * 7,8=DRAIN, 9=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2952 | */ |
| 2953 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2954 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2955 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2956 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2957 | char str[INET6_ADDRSTRLEN]; |
| 2958 | struct chunk src; |
| 2959 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2960 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2961 | /* we have "via" which is the tracked server as described in the configuration, |
| 2962 | * and "ref" which is the checked server and the end of the chain. |
| 2963 | */ |
| 2964 | via = sv->track ? sv->track : sv; |
| 2965 | ref = via; |
| 2966 | while (ref->track) |
| 2967 | ref = ref->track; |
| 2968 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2969 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2970 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2971 | "DOWN", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2972 | "DOWN (agent)", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2973 | "DN %d/%d ↑", |
| 2974 | "UP %d/%d ↓", |
| 2975 | "UP", |
| 2976 | "NOLB %d/%d ↓", |
| 2977 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2978 | "DRAIN %d/%d ↓", |
| 2979 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2980 | "<i>no check</i>" |
| 2981 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2982 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 2983 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2984 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2985 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2986 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2987 | "<tr class=\"%s%d\">", |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 2988 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2989 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2990 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2991 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2992 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2993 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2994 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2995 | chunk_appendf(&trash, |
| 2996 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2997 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2998 | "", |
| 2999 | px->id, sv->id, |
| 3000 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3001 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3002 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3003 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3004 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3005 | |
| 3006 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 3007 | case AF_INET: |
| 3008 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 3009 | break; |
| 3010 | case AF_INET6: |
| 3011 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 3012 | break; |
| 3013 | case AF_UNIX: |
| 3014 | chunk_appendf(&trash, "unix, "); |
| 3015 | break; |
| 3016 | case -1: |
| 3017 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3018 | break; |
| 3019 | default: /* address family not supported */ |
| 3020 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3021 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3022 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3023 | /* id */ |
| 3024 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3025 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3026 | /* cookie */ |
| 3027 | if (sv->cookie) { |
| 3028 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3029 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3030 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3031 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3032 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3033 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3034 | } |
| 3035 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3036 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3037 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3038 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3039 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3040 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3041 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3042 | /* sessions rate : current, max, limit */ |
| 3043 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3044 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3045 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3046 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3047 | U2H(read_freq_ctr(&sv->sess_per_sec)), U2H(sv->counters.sps_max)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3048 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3049 | |
| 3050 | chunk_appendf(&trash, |
| 3051 | /* sessions: current, max, limit, total */ |
| 3052 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3053 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3054 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3055 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3056 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3057 | U2H(sv->counters.cum_sess), |
| 3058 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3059 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3060 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3061 | if (px->mode == PR_MODE_HTTP) { |
| 3062 | unsigned long long tot; |
| 3063 | for (tot = i = 0; i < 6; i++) |
| 3064 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3065 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3066 | chunk_appendf(&trash, |
| 3067 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3068 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3069 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3070 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3071 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3072 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3073 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3074 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3075 | U2H(tot), |
| 3076 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3077 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3078 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3079 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3080 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3081 | U2H(sv->counters.p.http.rsp[0]), tot ? (int)(100*sv->counters.p.http.rsp[0] / tot) : 0); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3082 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3083 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3084 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3085 | chunk_appendf(&trash, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES))); |
| 3086 | chunk_appendf(&trash, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES))); |
| 3087 | if (px->mode == PR_MODE_HTTP) |
| 3088 | chunk_appendf(&trash, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES))); |
| 3089 | chunk_appendf(&trash, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES))); |
| 3090 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3091 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3092 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3093 | /* sessions: lbtot, last */ |
| 3094 | "<td>%s</td><td>%s</td>", |
| 3095 | U2H(sv->counters.cum_lbconn), |
| 3096 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3097 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3098 | chunk_appendf(&trash, |
| 3099 | /* bytes : in, out */ |
| 3100 | "<td>%s</td><td>%s</td>" |
| 3101 | /* denied: req, resp */ |
| 3102 | "<td></td><td>%s</td>" |
| 3103 | /* errors : request, connect */ |
| 3104 | "<td></td><td>%s</td>" |
| 3105 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3106 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3107 | /* warnings: retries, redispatches */ |
| 3108 | "<td>%lld</td><td>%lld</td>" |
| 3109 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3110 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3111 | U2H(sv->counters.failed_secu), |
| 3112 | U2H(sv->counters.failed_conns), |
| 3113 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3114 | sv->counters.cli_aborts, |
| 3115 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3116 | sv->counters.retries, sv->counters.redispatches); |
| 3117 | |
| 3118 | /* status, lest check */ |
| 3119 | chunk_appendf(&trash, "<td class=ac>"); |
| 3120 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3121 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3122 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3123 | chunk_appendf(&trash, "MAINT"); |
| 3124 | } |
Simon Horman | 0766e44 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3125 | else if ((ref->agent.state & CHK_ST_ENABLED) && !(sv->agent.health) && (ref->state == SRV_ST_STOPPED)) { |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3126 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
Willy Tarreau | ac49707 | 2014-05-29 01:04:35 +0200 | [diff] [blame] | 3127 | /* DOWN (agent) */ |
| 3128 | chunk_appendf(&trash, srv_hlt_st[1], "GCC: your -Werror=format-security is bogus, annoying, and hides real bugs, I don't thank you, really!"); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3129 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3130 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3131 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3132 | chunk_appendf(&trash, |
| 3133 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3134 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3135 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3136 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3137 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3138 | if ((sv->state == SRV_ST_STOPPED) && |
| 3139 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3140 | chunk_appendf(&trash, |
| 3141 | "</td><td class=ac><u> %s%s", |
| 3142 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3143 | get_check_status_info(sv->agent.status)); |
| 3144 | |
| 3145 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3146 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3147 | |
| 3148 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3149 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3150 | |
| 3151 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3152 | get_check_status_description(sv->agent.status)); |
| 3153 | if (*sv->agent.desc) { |
| 3154 | chunk_appendf(&trash, ": "); |
| 3155 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3156 | chunk_htmlencode(&trash, &src); |
| 3157 | } |
| 3158 | chunk_appendf(&trash, "</div></u>"); |
| 3159 | } |
| 3160 | else if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3161 | chunk_appendf(&trash, |
| 3162 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3163 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3164 | get_check_status_info(sv->check.status)); |
| 3165 | |
| 3166 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3167 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3168 | |
| 3169 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3170 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3171 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3172 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3173 | get_check_status_description(sv->check.status)); |
| 3174 | if (*sv->check.desc) { |
| 3175 | chunk_appendf(&trash, ": "); |
| 3176 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3177 | chunk_htmlencode(&trash, &src); |
| 3178 | } |
| 3179 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3180 | } |
| 3181 | else |
| 3182 | chunk_appendf(&trash, "</td><td>"); |
| 3183 | |
| 3184 | chunk_appendf(&trash, |
| 3185 | /* weight */ |
| 3186 | "</td><td class=ac>%d</td>" |
| 3187 | /* act, bck */ |
| 3188 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3189 | "", |
| 3190 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3191 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3192 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3193 | |
| 3194 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3195 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3196 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3197 | |
| 3198 | if (ref->observe) |
| 3199 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3200 | |
| 3201 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3202 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3203 | "<td>%lld</td><td>%s</td>" |
| 3204 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3205 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3206 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3207 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3208 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3209 | /* tracking a server */ |
| 3210 | chunk_appendf(&trash, |
| 3211 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s</a></td>", |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3212 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3213 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3214 | else |
| 3215 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3216 | |
| 3217 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3218 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3219 | chunk_appendf(&trash, "<td class=ac>%d %%</td></tr>\n", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3220 | else |
| 3221 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3222 | } |
| 3223 | else { /* CSV mode */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3224 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3225 | "DOWN,", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3226 | "DOWN (agent),", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3227 | "DOWN %d/%d,", |
| 3228 | "UP %d/%d,", |
| 3229 | "UP,", |
| 3230 | "NOLB %d/%d,", |
| 3231 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3232 | "DRAIN %d/%d,", |
| 3233 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3234 | "no check," |
| 3235 | }; |
| 3236 | |
| 3237 | chunk_appendf(&trash, |
| 3238 | /* pxid, name */ |
| 3239 | "%s,%s," |
| 3240 | /* queue : current, max */ |
| 3241 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3242 | /* sessions : current, max, limit, total */ |
| 3243 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3244 | /* bytes : in, out */ |
| 3245 | "%lld,%lld," |
| 3246 | /* denied: req, resp */ |
| 3247 | ",%lld," |
| 3248 | /* errors : request, connect, response */ |
| 3249 | ",%lld,%lld," |
| 3250 | /* warnings: retries, redispatches */ |
| 3251 | "%lld,%lld," |
| 3252 | "", |
| 3253 | px->id, sv->id, |
| 3254 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3255 | sv->cur_sess, sv->counters.cur_sess_max, LIM2A(sv->maxconn, ""), sv->counters.cum_sess, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3256 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3257 | sv->counters.failed_secu, |
| 3258 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3259 | sv->counters.retries, sv->counters.redispatches); |
| 3260 | |
| 3261 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3262 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3263 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3264 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3265 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3266 | else |
| 3267 | chunk_appendf(&trash, |
| 3268 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3269 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3270 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3271 | |
| 3272 | chunk_appendf(&trash, |
| 3273 | /* weight, active, backup */ |
| 3274 | "%d,%d,%d," |
| 3275 | "", |
| 3276 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3277 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3278 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3279 | |
| 3280 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3281 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3282 | chunk_appendf(&trash, |
| 3283 | "%lld,%lld,%d,%d,", |
| 3284 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3285 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3286 | else |
| 3287 | chunk_appendf(&trash, ",,,,"); |
| 3288 | |
| 3289 | /* queue limit, pid, iid, sid, */ |
| 3290 | chunk_appendf(&trash, |
| 3291 | "%s," |
| 3292 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3293 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3294 | relative_pid, px->uuid, sv->puid); |
| 3295 | |
| 3296 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3297 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3298 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3299 | |
| 3300 | /* sessions: lbtot */ |
| 3301 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3302 | |
| 3303 | /* tracked */ |
| 3304 | if (sv->track) |
| 3305 | chunk_appendf(&trash, "%s/%s,", |
| 3306 | sv->track->proxy->id, sv->track->id); |
| 3307 | else |
| 3308 | chunk_appendf(&trash, ","); |
| 3309 | |
| 3310 | /* type */ |
| 3311 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3312 | |
| 3313 | /* rate */ |
| 3314 | chunk_appendf(&trash, "%u,,%u,", |
| 3315 | read_freq_ctr(&sv->sess_per_sec), |
| 3316 | sv->counters.sps_max); |
| 3317 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3318 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3319 | /* check_status */ |
| 3320 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3321 | |
| 3322 | /* check_code */ |
| 3323 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3324 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3325 | else |
| 3326 | chunk_appendf(&trash, ","); |
| 3327 | |
| 3328 | /* check_duration */ |
| 3329 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3330 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3331 | else |
| 3332 | chunk_appendf(&trash, ","); |
| 3333 | |
| 3334 | } |
| 3335 | else |
| 3336 | chunk_appendf(&trash, ",,,"); |
| 3337 | |
| 3338 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3339 | if (px->mode == PR_MODE_HTTP) { |
| 3340 | for (i=1; i<6; i++) |
| 3341 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3342 | |
| 3343 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3344 | } |
| 3345 | else |
| 3346 | chunk_appendf(&trash, ",,,,,,"); |
| 3347 | |
| 3348 | /* failed health analyses */ |
| 3349 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3350 | |
| 3351 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3352 | chunk_appendf(&trash, ",,,"); |
| 3353 | |
| 3354 | /* errors: cli_aborts, srv_aborts */ |
| 3355 | chunk_appendf(&trash, "%lld,%lld,", |
| 3356 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3357 | |
| 3358 | /* compression: in, out, bypassed, comp_rsp */ |
| 3359 | chunk_appendf(&trash, ",,,,"); |
| 3360 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3361 | /* lastsess */ |
| 3362 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3363 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3364 | /* capture of last check and agent statuses */ |
| 3365 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->check.desc) : ""); |
| 3366 | chunk_appendf(&trash, "%s,", ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->agent.desc) : ""); |
| 3367 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3368 | /* qtime, ctime, rtime, ttime, */ |
| 3369 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3370 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3371 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3372 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3373 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3374 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3375 | /* finish with EOL */ |
| 3376 | chunk_appendf(&trash, "\n"); |
| 3377 | } |
| 3378 | return 1; |
| 3379 | } |
| 3380 | |
| 3381 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3382 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3383 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3384 | */ |
| 3385 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3386 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3387 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3388 | struct chunk src; |
| 3389 | int i; |
| 3390 | |
| 3391 | if (!(px->cap & PR_CAP_BE)) |
| 3392 | return 0; |
| 3393 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3394 | 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] | 3395 | return 0; |
| 3396 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3397 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3398 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3399 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3400 | /* Column sub-heading for Enable or Disable server */ |
| 3401 | chunk_appendf(&trash, "<td></td>"); |
| 3402 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3403 | chunk_appendf(&trash, |
| 3404 | "<td class=ac>" |
| 3405 | /* name */ |
| 3406 | "%s<a name=\"%s/Backend\"></a>" |
| 3407 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3408 | "", |
| 3409 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3410 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3411 | |
| 3412 | if (flags & ST_SHLGNDS) { |
| 3413 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3414 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3415 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3416 | |
| 3417 | /* cookie */ |
| 3418 | if (px->cookie_name) { |
| 3419 | chunk_appendf(&trash, ", cookie: '"); |
| 3420 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3421 | chunk_htmlencode(&trash, &src); |
| 3422 | chunk_appendf(&trash, "'"); |
| 3423 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3424 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3428 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3429 | /* queue : current, max */ |
| 3430 | "<td>%s</td><td>%s</td><td></td>" |
| 3431 | /* sessions rate : current, max, limit */ |
| 3432 | "<td>%s</td><td>%s</td><td></td>" |
| 3433 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3434 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3435 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3436 | U2H(read_freq_ctr(&px->be_sess_per_sec)), U2H(px->be_counters.sps_max)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3437 | |
| 3438 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3439 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3440 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3441 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3442 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3443 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3444 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3445 | U2H(px->be_counters.cum_conn), |
| 3446 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3447 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3448 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3449 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3450 | chunk_appendf(&trash, |
| 3451 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3452 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3453 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3454 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3455 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3456 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3457 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3458 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3459 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3460 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3461 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3462 | U2H(px->be_counters.p.http.cum_req), |
| 3463 | U2H(px->be_counters.p.http.rsp[1]), |
| 3464 | U2H(px->be_counters.p.http.rsp[2]), |
| 3465 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3466 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3467 | (int)(100*px->be_counters.p.http.comp_rsp/px->be_counters.p.http.rsp[2]) : 0, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3468 | U2H(px->be_counters.p.http.rsp[3]), |
| 3469 | U2H(px->be_counters.p.http.rsp[4]), |
| 3470 | U2H(px->be_counters.p.http.rsp[5]), |
| 3471 | U2H(px->be_counters.p.http.rsp[0]), |
| 3472 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3473 | } |
| 3474 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3475 | chunk_appendf(&trash, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES))); |
| 3476 | chunk_appendf(&trash, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES))); |
| 3477 | if (px->mode == PR_MODE_HTTP) |
| 3478 | chunk_appendf(&trash, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES))); |
| 3479 | chunk_appendf(&trash, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES))); |
| 3480 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3481 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3482 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3483 | /* sessions: lbtot, last */ |
| 3484 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3485 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3486 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3487 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3488 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3489 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3490 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3491 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3492 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3493 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3494 | "<td>%s%s<div class=tips>compression: in=%lld out=%lld bypassed=%lld savings=%d%%</div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3495 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3496 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3497 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3498 | px->be_counters.comp_in ? |
| 3499 | (int)((px->be_counters.comp_in - px->be_counters.comp_out)*100/px->be_counters.comp_in) : 0, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3500 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3501 | |
| 3502 | chunk_appendf(&trash, |
| 3503 | /* denied: req, resp */ |
| 3504 | "<td>%s</td><td>%s</td>" |
| 3505 | /* errors : request, connect */ |
| 3506 | "<td></td><td>%s</td>" |
| 3507 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3508 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3509 | /* warnings: retries, redispatches */ |
| 3510 | "<td>%lld</td><td>%lld</td>" |
| 3511 | /* backend status: reflect backend status (up/down): we display UP |
| 3512 | * if the backend has known working servers or if it has no server at |
| 3513 | * all (eg: for stats). Then we display the total weight, number of |
| 3514 | * active and backups. */ |
| 3515 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3516 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3517 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3518 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3519 | U2H(px->be_counters.failed_conns), |
| 3520 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3521 | px->be_counters.cli_aborts, |
| 3522 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3523 | px->be_counters.retries, px->be_counters.redispatches, |
| 3524 | human_time(now.tv_sec - px->last_change, 1), |
| 3525 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3526 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3527 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3528 | px->srv_act, px->srv_bck); |
| 3529 | |
| 3530 | chunk_appendf(&trash, |
| 3531 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3532 | "<td class=ac> </td><td>%d</td>" |
| 3533 | "<td>%s</td>" |
| 3534 | "<td></td>" |
| 3535 | "</tr>", |
| 3536 | px->down_trans, |
| 3537 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3538 | } |
| 3539 | else { /* CSV mode */ |
| 3540 | chunk_appendf(&trash, |
| 3541 | /* pxid, name */ |
| 3542 | "%s,BACKEND," |
| 3543 | /* queue : current, max */ |
| 3544 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3545 | /* sessions : current, max, limit, total */ |
| 3546 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3547 | /* bytes : in, out */ |
| 3548 | "%lld,%lld," |
| 3549 | /* denied: req, resp */ |
| 3550 | "%lld,%lld," |
| 3551 | /* errors : request, connect, response */ |
| 3552 | ",%lld,%lld," |
| 3553 | /* warnings: retries, redispatches */ |
| 3554 | "%lld,%lld," |
| 3555 | /* backend status: reflect backend status (up/down): we display UP |
| 3556 | * if the backend has known working servers or if it has no server at |
| 3557 | * all (eg: for stats). Then we display the total weight, number of |
| 3558 | * active and backups. */ |
| 3559 | "%s," |
| 3560 | "%d,%d,%d," |
| 3561 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3562 | ",%d,%d,%d,," |
| 3563 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3564 | "%d,%d,0,,%lld,,%d," |
| 3565 | /* rate, rate_lim, rate_max, */ |
| 3566 | "%u,,%u," |
| 3567 | /* check_status, check_code, check_duration */ |
| 3568 | ",,,", |
| 3569 | px->id, |
| 3570 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3571 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3572 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3573 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3574 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3575 | px->be_counters.retries, px->be_counters.redispatches, |
| 3576 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3577 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3578 | px->srv_act, px->srv_bck, |
| 3579 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3580 | px->srv?be_downtime(px):0, |
| 3581 | relative_pid, px->uuid, |
| 3582 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3583 | read_freq_ctr(&px->be_sess_per_sec), |
| 3584 | px->be_counters.sps_max); |
| 3585 | |
| 3586 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3587 | if (px->mode == PR_MODE_HTTP) { |
| 3588 | for (i=1; i<6; i++) |
| 3589 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3590 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3591 | } |
| 3592 | else |
| 3593 | chunk_appendf(&trash, ",,,,,,"); |
| 3594 | |
| 3595 | /* failed health analyses */ |
| 3596 | chunk_appendf(&trash, ","); |
| 3597 | |
| 3598 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3599 | chunk_appendf(&trash, ",,,"); |
| 3600 | |
| 3601 | /* errors: cli_aborts, srv_aborts */ |
| 3602 | chunk_appendf(&trash, "%lld,%lld,", |
| 3603 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3604 | |
| 3605 | /* compression: in, out, bypassed */ |
| 3606 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3607 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3608 | |
| 3609 | /* compression: comp_rsp */ |
| 3610 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3611 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3612 | /* lastsess, last_chk, last_agt, */ |
| 3613 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3614 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3615 | /* qtime, ctime, rtime, ttime, */ |
| 3616 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3617 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 3618 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 3619 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 3620 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 3621 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3622 | /* finish with EOL */ |
| 3623 | chunk_appendf(&trash, "\n"); |
| 3624 | } |
| 3625 | return 1; |
| 3626 | } |
| 3627 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3628 | /* 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] | 3629 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3630 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3631 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3632 | 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] | 3633 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3634 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3635 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3636 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3637 | 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] | 3638 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3639 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3640 | /* 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] | 3641 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3642 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3643 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3644 | 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] | 3645 | 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] | 3646 | } |
| 3647 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3648 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 3649 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | /* print a new table */ |
| 3653 | chunk_appendf(&trash, |
| 3654 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3655 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3656 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3657 | |
| 3658 | chunk_appendf(&trash, |
| 3659 | "<a name=\"%s\"></a>%s" |
| 3660 | "<a class=px href=\"#%s\">%s</a>", |
| 3661 | px->id, |
| 3662 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3663 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3664 | |
| 3665 | if (uri->flags & ST_SHLGNDS) { |
| 3666 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3667 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3668 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3669 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3670 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3674 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3675 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3676 | "</tr>\n" |
| 3677 | "</table>\n" |
| 3678 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3679 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3680 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3681 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3682 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3683 | 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] | 3684 | /* Column heading for Enable or Disable server */ |
| 3685 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3686 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3687 | |
| 3688 | chunk_appendf(&trash, |
| 3689 | "<th rowspan=2></th>" |
| 3690 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3691 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3692 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3693 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3694 | "<th colspan=9>Server</th>" |
| 3695 | "</tr>\n" |
| 3696 | "<tr class=\"titre\">" |
| 3697 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3698 | "<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] | 3699 | "<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] | 3700 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3701 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3702 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3703 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3704 | "<th>Thrtle</th>\n" |
| 3705 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3706 | } |
| 3707 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3708 | /* 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] | 3709 | * 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] | 3710 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3711 | 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] | 3712 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3713 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3714 | chunk_appendf(&trash, "</table>"); |
| 3715 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3716 | 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] | 3717 | /* close the form used to enable/disable this proxy servers */ |
| 3718 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3719 | "Choose the action to perform on the checked servers : " |
| 3720 | "<select name=action>" |
| 3721 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 3722 | "<option value=\"ready\">Set state to READY</option>" |
| 3723 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 3724 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 3725 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3726 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3727 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3728 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3729 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3730 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3731 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3732 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3733 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3734 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3735 | "</select>" |
| 3736 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3737 | " <input type=\"submit\" value=\"Apply\">" |
| 3738 | "</form>", |
| 3739 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3743 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3744 | |
| 3745 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3746 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3747 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3748 | * buffer space, or non-zero if everything completed. This function is used |
| 3749 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3750 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3751 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3752 | 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] | 3753 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3754 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 3755 | struct session *s = si_sess(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 3756 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3757 | 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] | 3758 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3759 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3760 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3761 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3762 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3763 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3764 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3765 | if (uri && uri->scope) { |
| 3766 | /* we have a limited scope, we have to check the proxy name */ |
| 3767 | struct stat_scope *scope; |
| 3768 | int len; |
| 3769 | |
| 3770 | len = strlen(px->id); |
| 3771 | scope = uri->scope; |
| 3772 | |
| 3773 | while (scope) { |
| 3774 | /* match exact proxy name */ |
| 3775 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3776 | break; |
| 3777 | |
| 3778 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3779 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3780 | break; |
| 3781 | scope = scope->next; |
| 3782 | } |
| 3783 | |
| 3784 | /* proxy name not found : don't dump anything */ |
| 3785 | if (scope == NULL) |
| 3786 | return 1; |
| 3787 | } |
| 3788 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3789 | /* if the user has requested a limited output and the proxy |
| 3790 | * name does not match, skip it. |
| 3791 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3792 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3793 | 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] | 3794 | return 1; |
| 3795 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3796 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3797 | (appctx->ctx.stats.iid != -1) && |
| 3798 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3799 | return 1; |
| 3800 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3801 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3802 | /* fall through */ |
| 3803 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3804 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3805 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3806 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3807 | if (bi_putchk(rep, &trash) == -1) { |
| 3808 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3809 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3810 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3811 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3812 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3813 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3814 | /* fall through */ |
| 3815 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3816 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3817 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3818 | if (stats_dump_fe_stats(si, px)) { |
| 3819 | if (bi_putchk(rep, &trash) == -1) { |
| 3820 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3821 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3822 | } |
| 3823 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3824 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3825 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3826 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3827 | /* fall through */ |
| 3828 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3829 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3830 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3831 | 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] | 3832 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3833 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3834 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3835 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3836 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3837 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3838 | if (!l->counters) |
| 3839 | continue; |
| 3840 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3841 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3842 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3843 | break; |
| 3844 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3845 | 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] | 3846 | continue; |
| 3847 | } |
| 3848 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3849 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3850 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) { |
| 3851 | if (bi_putchk(rep, &trash) == -1) { |
| 3852 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3853 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3854 | } |
| 3855 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3856 | } |
| 3857 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3858 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3859 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3860 | /* fall through */ |
| 3861 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3862 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3863 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3864 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3865 | int sv_state; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3866 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3867 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3868 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3869 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3870 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3871 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3872 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3873 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3874 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3875 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3876 | break; |
| 3877 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3878 | 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] | 3879 | continue; |
| 3880 | } |
| 3881 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3882 | svs = sv; |
| 3883 | while (svs->track) |
| 3884 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3885 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3886 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 3887 | /* server is UP. The possibilities are : |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3888 | * - UP, draining, going down => state = 7 |
| 3889 | * - UP, going down => state = 3 |
| 3890 | * - UP, draining => state = 8 |
| 3891 | * - UP, checked => state = 4 |
| 3892 | * - UP, not checked nor tracked => state = 9 |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3893 | */ |
| 3894 | |
| 3895 | if ((svs->check.state & CHK_ST_ENABLED) && |
| 3896 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3897 | sv_state = 3; |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3898 | else |
| 3899 | sv_state = 4; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3900 | |
Willy Tarreau | efe2822 | 2014-05-21 17:13:13 +0200 | [diff] [blame] | 3901 | if (server_is_draining(sv)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3902 | sv_state += 4; |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3903 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3904 | if (sv_state == 4 && !(svs->check.state & CHK_ST_ENABLED)) |
| 3905 | sv_state = 9; /* unchecked UP */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3906 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3907 | else if (sv->state == SRV_ST_STOPPING) { |
| 3908 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 3909 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3910 | sv_state = 6; /* NOLB */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3911 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3912 | sv_state = 5; /* NOLB going down */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3913 | } |
| 3914 | else { /* stopped */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3915 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) |
| 3916 | sv_state = 1; /* DOWN (agent) */ |
| 3917 | else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3918 | sv_state = 0; /* DOWN */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3919 | else if ((svs->agent.state & CHK_ST_ENABLED) || (svs->check.state & CHK_ST_ENABLED)) |
| 3920 | sv_state = 2; /* going up */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3921 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3922 | sv_state = 0; /* DOWN, unchecked */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3923 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3924 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3925 | if (((sv_state <= 1) || (sv->admin & SRV_ADMF_MAINT)) && (appctx->ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3926 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3927 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3928 | continue; |
| 3929 | } |
| 3930 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3931 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) { |
| 3932 | if (bi_putchk(rep, &trash) == -1) { |
| 3933 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3934 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3935 | } |
| 3936 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3937 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3938 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3939 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3940 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3941 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3942 | case STAT_PX_ST_BE: |
| 3943 | /* print the backend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3944 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) { |
| 3945 | if (bi_putchk(rep, &trash) == -1) { |
| 3946 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3947 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3948 | } |
| 3949 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3950 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3951 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3952 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3953 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3954 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3955 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3956 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3957 | if (bi_putchk(rep, &trash) == -1) { |
| 3958 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3959 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3960 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3961 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3962 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3963 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3964 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3965 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3966 | case STAT_PX_ST_FIN: |
| 3967 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3968 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3969 | default: |
| 3970 | /* unknown state, we should put an abort() here ! */ |
| 3971 | return 1; |
| 3972 | } |
| 3973 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3974 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3975 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3976 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3977 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3978 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3979 | { |
| 3980 | /* WARNING! This must fit in the first buffer !!! */ |
| 3981 | chunk_appendf(&trash, |
| 3982 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3983 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3984 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3985 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3986 | "<style type=\"text/css\"><!--\n" |
| 3987 | "body {" |
| 3988 | " font-family: arial, helvetica, sans-serif;" |
| 3989 | " font-size: 12px;" |
| 3990 | " font-weight: normal;" |
| 3991 | " color: black;" |
| 3992 | " background: white;" |
| 3993 | "}\n" |
| 3994 | "th,td {" |
| 3995 | " font-size: 10px;" |
| 3996 | "}\n" |
| 3997 | "h1 {" |
| 3998 | " font-size: x-large;" |
| 3999 | " margin-bottom: 0.5em;" |
| 4000 | "}\n" |
| 4001 | "h2 {" |
| 4002 | " font-family: helvetica, arial;" |
| 4003 | " font-size: x-large;" |
| 4004 | " font-weight: bold;" |
| 4005 | " font-style: italic;" |
| 4006 | " color: #6020a0;" |
| 4007 | " margin-top: 0em;" |
| 4008 | " margin-bottom: 0em;" |
| 4009 | "}\n" |
| 4010 | "h3 {" |
| 4011 | " font-family: helvetica, arial;" |
| 4012 | " font-size: 16px;" |
| 4013 | " font-weight: bold;" |
| 4014 | " color: #b00040;" |
| 4015 | " background: #e8e8d0;" |
| 4016 | " margin-top: 0em;" |
| 4017 | " margin-bottom: 0em;" |
| 4018 | "}\n" |
| 4019 | "li {" |
| 4020 | " margin-top: 0.25em;" |
| 4021 | " margin-right: 2em;" |
| 4022 | "}\n" |
| 4023 | ".hr {margin-top: 0.25em;" |
| 4024 | " border-color: black;" |
| 4025 | " border-bottom-style: solid;" |
| 4026 | "}\n" |
| 4027 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4028 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4029 | ".frontend {background: #e8e8d0;}\n" |
| 4030 | ".socket {background: #d0d0d0;}\n" |
| 4031 | ".backend {background: #e8e8d0;}\n" |
| 4032 | ".active0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4033 | ".active1 {background: #ff9090;}\n" |
| 4034 | ".active2 {background: #ffd020;}\n" |
| 4035 | ".active3 {background: #ffffa0;}\n" |
| 4036 | ".active4 {background: #c0ffc0;}\n" |
| 4037 | ".active5 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 4038 | ".active6 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 4039 | ".active7 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 4040 | ".active8 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
| 4041 | ".active9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4042 | ".backup0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4043 | ".backup1 {background: #ff9090;}\n" |
| 4044 | ".backup2 {background: #ff80ff;}\n" |
| 4045 | ".backup3 {background: #c060ff;}\n" |
| 4046 | ".backup4 {background: #b0d0ff;}\n" |
| 4047 | ".backup5 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 4048 | ".backup6 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 4049 | ".backup7 {background: #c060ff;}\n" |
| 4050 | ".backup8 {background: #cc9900;}\n" |
| 4051 | ".backup9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4052 | ".maintain {background: #c07820;}\n" |
| 4053 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4054 | "\n" |
| 4055 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4056 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4057 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4058 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4059 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4060 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4061 | "\n" |
| 4062 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4063 | "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" |
| 4064 | "table.tbl td.ac { text-align: center;}\n" |
| 4065 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4066 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4067 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4068 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4069 | "\n" |
| 4070 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4071 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4072 | "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] | 4073 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4074 | "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] | 4075 | "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] | 4076 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4077 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4078 | " display:block;\n" |
| 4079 | " visibility:hidden;\n" |
| 4080 | " z-index:2147483647;\n" |
| 4081 | " position:absolute;\n" |
| 4082 | " padding:2px 4px 3px;\n" |
| 4083 | " background:#f0f060; color:#000000;\n" |
| 4084 | " border:1px solid #7040c0;\n" |
| 4085 | " white-space:nowrap;\n" |
| 4086 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4087 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4088 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4089 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4090 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4091 | "-->\n" |
| 4092 | "</style></head>\n", |
| 4093 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4094 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4095 | ); |
| 4096 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4097 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4098 | /* 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] | 4099 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4100 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4101 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4102 | 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] | 4103 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4104 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4105 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4106 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4107 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4108 | /* WARNING! this has to fit the first packet too. |
| 4109 | * We are around 3.5 kB, add adding entries will |
| 4110 | * become tricky if we want to support 4kB buffers ! |
| 4111 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4112 | chunk_appendf(&trash, |
| 4113 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4114 | PRODUCT_NAME "%s</a></h1>\n" |
| 4115 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4116 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4117 | "<h3>> General process information</h3>\n" |
| 4118 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4119 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4120 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4121 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4122 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4123 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4124 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4125 | "</td><td align=\"center\" nowrap>\n" |
| 4126 | "<table class=\"lgd\"><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4127 | "<td class=\"active4\"> </td><td class=\"noborder\">active UP </td>" |
| 4128 | "<td class=\"backup4\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4129 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4130 | "<td class=\"active3\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4131 | "<td class=\"backup3\"></td><td class=\"noborder\">backup UP, going down </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4132 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4133 | "<td class=\"active2\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4134 | "<td class=\"backup2\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4135 | "</tr><tr>\n" |
| 4136 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4137 | "<td class=\"active9\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4138 | "</tr><tr>\n" |
| 4139 | "<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] | 4140 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4141 | "<td class=\"active8\"></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] | 4142 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4143 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4144 | "</td>" |
| 4145 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4146 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4147 | "", |
| 4148 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4149 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4150 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4151 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4152 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4153 | pid, relative_pid, global.nbproc, |
| 4154 | up / 86400, (up % 86400) / 3600, |
| 4155 | (up % 3600) / 60, (up % 60), |
| 4156 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4157 | global.rlimit_memmax ? " MB" : "", |
| 4158 | global.rlimit_nofile, |
| 4159 | global.maxsock, global.maxconn, global.maxpipes, |
| 4160 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4161 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4162 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4163 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4164 | /* 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] | 4165 | 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] | 4166 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4167 | |
| 4168 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4169 | "<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] | 4170 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4171 | STAT_SCOPE_TXT_MAXLEN); |
| 4172 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4173 | /* 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] | 4174 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4175 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4176 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4177 | 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] | 4178 | 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] | 4179 | } |
| 4180 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4181 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4182 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4183 | "<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] | 4184 | uri->uri_prefix, |
| 4185 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4186 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4187 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4188 | else |
| 4189 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4190 | "<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] | 4191 | uri->uri_prefix, |
| 4192 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4193 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4194 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4195 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4196 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4197 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4198 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4199 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4200 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4201 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4202 | "", |
| 4203 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4204 | else |
| 4205 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4206 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4207 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4208 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4209 | ";norefresh", |
| 4210 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4211 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4212 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4213 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4214 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4215 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4216 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4217 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4218 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4219 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4220 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4221 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4222 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4223 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4224 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4225 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4226 | chunk_appendf(&trash, |
| 4227 | "</ul></td>" |
| 4228 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4229 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4230 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4231 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4232 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4233 | "</ul>" |
| 4234 | "</td>" |
| 4235 | "</tr></table>\n" |
| 4236 | "" |
| 4237 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4238 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4239 | if (appctx->ctx.stats.st_code) { |
| 4240 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4241 | case STAT_STATUS_DONE: |
| 4242 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4243 | "<p><div class=active4>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4244 | "<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] | 4245 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4246 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4247 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4248 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4249 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4250 | break; |
| 4251 | case STAT_STATUS_NONE: |
| 4252 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4253 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4254 | "<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] | 4255 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4256 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4257 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4258 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4259 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4260 | break; |
| 4261 | case STAT_STATUS_PART: |
| 4262 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4263 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4264 | "<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] | 4265 | "Action partially processed.<br>" |
| 4266 | "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] | 4267 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4268 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4269 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4270 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4271 | break; |
| 4272 | case STAT_STATUS_ERRP: |
| 4273 | chunk_appendf(&trash, |
| 4274 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4275 | "<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] | 4276 | "Action not processed because of invalid parameters." |
| 4277 | "<ul>" |
| 4278 | "<li>The action is maybe unknown.</li>" |
| 4279 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4280 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4281 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4282 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4283 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4284 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4285 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4286 | break; |
| 4287 | case STAT_STATUS_EXCD: |
| 4288 | chunk_appendf(&trash, |
| 4289 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4290 | "<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] | 4291 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4292 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4293 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4294 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4295 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4296 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4297 | break; |
| 4298 | case STAT_STATUS_DENY: |
| 4299 | chunk_appendf(&trash, |
| 4300 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4301 | "<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] | 4302 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4303 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4304 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4305 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4306 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4307 | break; |
| 4308 | default: |
| 4309 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4310 | "<p><div class=active9>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4311 | "<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] | 4312 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4313 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4314 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4315 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4316 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4317 | } |
| 4318 | chunk_appendf(&trash, "<p>\n"); |
| 4319 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4320 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4321 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4322 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4323 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4324 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4325 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4326 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4327 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4328 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4329 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4330 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4331 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4332 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4333 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 4334 | * and the session must be closed, or -1 in case of any error. This function is |
| 4335 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4336 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4337 | 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] | 4338 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4339 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4340 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4341 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4342 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4343 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4344 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4345 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4346 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4347 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4348 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4349 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4350 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4351 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4352 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4353 | else |
| 4354 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4355 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4356 | if (bi_putchk(rep, &trash) == -1) { |
| 4357 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4358 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4359 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4360 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4361 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4362 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4363 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4364 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4365 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4366 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4367 | if (bi_putchk(rep, &trash) == -1) { |
| 4368 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4369 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4370 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4371 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4372 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4373 | appctx->ctx.stats.px = proxy; |
| 4374 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4375 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4376 | /* fall through */ |
| 4377 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4378 | case STAT_ST_LIST: |
| 4379 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4380 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4381 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4382 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4383 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4384 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4385 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4386 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4387 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4388 | 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] | 4389 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4390 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4391 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4392 | appctx->ctx.stats.px = px->next; |
| 4393 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4394 | } |
| 4395 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4396 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4397 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4398 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4399 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4400 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4401 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4402 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4403 | if (bi_putchk(rep, &trash) == -1) { |
| 4404 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4405 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4406 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4407 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4408 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4409 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4410 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4411 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4412 | case STAT_ST_FIN: |
| 4413 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4414 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4415 | default: |
| 4416 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4417 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4418 | return -1; |
| 4419 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4420 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4421 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4422 | /* We reached the stats page through a POST request. The appctx is |
| 4423 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4424 | * Parse the posted data and enable/disable servers if necessary. |
| 4425 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4426 | */ |
| 4427 | static int stats_process_http_post(struct stream_interface *si) |
| 4428 | { |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 4429 | struct session *s = si_sess(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4430 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4431 | |
| 4432 | struct proxy *px = NULL; |
| 4433 | struct server *sv = NULL; |
| 4434 | |
| 4435 | char key[LINESIZE]; |
| 4436 | int action = ST_ADM_ACTION_NONE; |
| 4437 | int reprocess = 0; |
| 4438 | |
| 4439 | int total_servers = 0; |
| 4440 | int altered_servers = 0; |
| 4441 | |
| 4442 | char *first_param, *cur_param, *next_param, *end_params; |
| 4443 | char *st_cur_param = NULL; |
| 4444 | char *st_next_param = NULL; |
| 4445 | |
| 4446 | struct chunk *temp; |
| 4447 | int reql; |
| 4448 | |
| 4449 | temp = get_trash_chunk(); |
| 4450 | if (temp->size < s->txn.req.body_len) { |
| 4451 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4452 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4453 | goto out; |
| 4454 | } |
| 4455 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4456 | 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] | 4457 | if (reql <= 0) { |
| 4458 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4459 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4460 | return 0; |
| 4461 | } |
| 4462 | |
| 4463 | first_param = temp->str; |
| 4464 | end_params = temp->str + reql; |
| 4465 | cur_param = next_param = end_params; |
| 4466 | *end_params = '\0'; |
| 4467 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4468 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4469 | |
| 4470 | /* |
| 4471 | * Parse the parameters in reverse order to only store the last value. |
| 4472 | * From the html form, the backend and the action are at the end. |
| 4473 | */ |
| 4474 | while (cur_param > first_param) { |
| 4475 | char *value; |
| 4476 | int poffset, plen; |
| 4477 | |
| 4478 | cur_param--; |
| 4479 | |
| 4480 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4481 | reprocess_servers: |
| 4482 | /* Parse the key */ |
| 4483 | poffset = (cur_param != first_param ? 1 : 0); |
| 4484 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4485 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4486 | strncpy(key, cur_param + poffset, plen); |
| 4487 | key[plen - 1] = '\0'; |
| 4488 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4489 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4490 | goto out; |
| 4491 | } |
| 4492 | |
| 4493 | /* Parse the value */ |
| 4494 | value = key; |
| 4495 | while (*value != '\0' && *value != '=') { |
| 4496 | value++; |
| 4497 | } |
| 4498 | if (*value == '=') { |
| 4499 | /* Ok, a value is found, we can mark the end of the key */ |
| 4500 | *value++ = '\0'; |
| 4501 | } |
| 4502 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4503 | break; |
| 4504 | |
| 4505 | /* Now we can check the key to see what to do */ |
| 4506 | if (!px && (strcmp(key, "b") == 0)) { |
| 4507 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4508 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4509 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4510 | goto out; |
| 4511 | } |
| 4512 | } |
| 4513 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4514 | if (strcmp(value, "ready") == 0) { |
| 4515 | action = ST_ADM_ACTION_READY; |
| 4516 | } |
| 4517 | else if (strcmp(value, "drain") == 0) { |
| 4518 | action = ST_ADM_ACTION_DRAIN; |
| 4519 | } |
| 4520 | else if (strcmp(value, "maint") == 0) { |
| 4521 | action = ST_ADM_ACTION_MAINT; |
| 4522 | } |
| 4523 | else if (strcmp(value, "shutdown") == 0) { |
| 4524 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4525 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4526 | else if (strcmp(value, "dhlth") == 0) { |
| 4527 | action = ST_ADM_ACTION_DHLTH; |
| 4528 | } |
| 4529 | else if (strcmp(value, "ehlth") == 0) { |
| 4530 | action = ST_ADM_ACTION_EHLTH; |
| 4531 | } |
| 4532 | else if (strcmp(value, "hrunn") == 0) { |
| 4533 | action = ST_ADM_ACTION_HRUNN; |
| 4534 | } |
| 4535 | else if (strcmp(value, "hnolb") == 0) { |
| 4536 | action = ST_ADM_ACTION_HNOLB; |
| 4537 | } |
| 4538 | else if (strcmp(value, "hdown") == 0) { |
| 4539 | action = ST_ADM_ACTION_HDOWN; |
| 4540 | } |
| 4541 | else if (strcmp(value, "dagent") == 0) { |
| 4542 | action = ST_ADM_ACTION_DAGENT; |
| 4543 | } |
| 4544 | else if (strcmp(value, "eagent") == 0) { |
| 4545 | action = ST_ADM_ACTION_EAGENT; |
| 4546 | } |
| 4547 | else if (strcmp(value, "arunn") == 0) { |
| 4548 | action = ST_ADM_ACTION_ARUNN; |
| 4549 | } |
| 4550 | else if (strcmp(value, "adown") == 0) { |
| 4551 | action = ST_ADM_ACTION_ADOWN; |
| 4552 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4553 | /* else these are the old supported methods */ |
| 4554 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4555 | action = ST_ADM_ACTION_DISABLE; |
| 4556 | } |
| 4557 | else if (strcmp(value, "enable") == 0) { |
| 4558 | action = ST_ADM_ACTION_ENABLE; |
| 4559 | } |
| 4560 | else if (strcmp(value, "stop") == 0) { |
| 4561 | action = ST_ADM_ACTION_STOP; |
| 4562 | } |
| 4563 | else if (strcmp(value, "start") == 0) { |
| 4564 | action = ST_ADM_ACTION_START; |
| 4565 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4566 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4567 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4568 | goto out; |
| 4569 | } |
| 4570 | } |
| 4571 | else if (strcmp(key, "s") == 0) { |
| 4572 | if (!(px && action)) { |
| 4573 | /* |
| 4574 | * Indicates that we'll need to reprocess the parameters |
| 4575 | * as soon as backend and action are known |
| 4576 | */ |
| 4577 | if (!reprocess) { |
| 4578 | st_cur_param = cur_param; |
| 4579 | st_next_param = next_param; |
| 4580 | } |
| 4581 | reprocess = 1; |
| 4582 | } |
| 4583 | else if ((sv = findserver(px, value)) != NULL) { |
| 4584 | switch (action) { |
| 4585 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4586 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4587 | altered_servers++; |
| 4588 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4589 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4590 | } |
| 4591 | break; |
| 4592 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4593 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4594 | altered_servers++; |
| 4595 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4596 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4597 | } |
| 4598 | break; |
| 4599 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4600 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 4601 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4602 | altered_servers++; |
| 4603 | total_servers++; |
| 4604 | } |
| 4605 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4606 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4607 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 4608 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4609 | altered_servers++; |
| 4610 | total_servers++; |
| 4611 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4612 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4613 | case ST_ADM_ACTION_DHLTH: |
| 4614 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4615 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4616 | altered_servers++; |
| 4617 | total_servers++; |
| 4618 | } |
| 4619 | break; |
| 4620 | case ST_ADM_ACTION_EHLTH: |
| 4621 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4622 | sv->check.state |= CHK_ST_ENABLED; |
| 4623 | altered_servers++; |
| 4624 | total_servers++; |
| 4625 | } |
| 4626 | break; |
| 4627 | case ST_ADM_ACTION_HRUNN: |
| 4628 | if (!(sv->track)) { |
| 4629 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4630 | srv_set_running(sv, "changed from Web interface"); |
| 4631 | altered_servers++; |
| 4632 | total_servers++; |
| 4633 | } |
| 4634 | break; |
| 4635 | case ST_ADM_ACTION_HNOLB: |
| 4636 | if (!(sv->track)) { |
| 4637 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4638 | srv_set_stopping(sv, "changed from Web interface"); |
| 4639 | altered_servers++; |
| 4640 | total_servers++; |
| 4641 | } |
| 4642 | break; |
| 4643 | case ST_ADM_ACTION_HDOWN: |
| 4644 | if (!(sv->track)) { |
| 4645 | sv->check.health = 0; |
| 4646 | srv_set_stopped(sv, "changed from Web interface"); |
| 4647 | altered_servers++; |
| 4648 | total_servers++; |
| 4649 | } |
| 4650 | break; |
| 4651 | case ST_ADM_ACTION_DAGENT: |
| 4652 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4653 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4654 | altered_servers++; |
| 4655 | total_servers++; |
| 4656 | } |
| 4657 | break; |
| 4658 | case ST_ADM_ACTION_EAGENT: |
| 4659 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4660 | sv->agent.state |= CHK_ST_ENABLED; |
| 4661 | altered_servers++; |
| 4662 | total_servers++; |
| 4663 | } |
| 4664 | break; |
| 4665 | case ST_ADM_ACTION_ARUNN: |
| 4666 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4667 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 4668 | srv_set_running(sv, "changed from Web interface"); |
| 4669 | altered_servers++; |
| 4670 | total_servers++; |
| 4671 | } |
| 4672 | break; |
| 4673 | case ST_ADM_ACTION_ADOWN: |
| 4674 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4675 | sv->agent.health = 0; |
| 4676 | srv_set_stopped(sv, "changed from Web interface"); |
| 4677 | altered_servers++; |
| 4678 | total_servers++; |
| 4679 | } |
| 4680 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4681 | case ST_ADM_ACTION_READY: |
| 4682 | srv_adm_set_ready(sv); |
| 4683 | altered_servers++; |
| 4684 | total_servers++; |
| 4685 | break; |
| 4686 | case ST_ADM_ACTION_DRAIN: |
| 4687 | srv_adm_set_drain(sv); |
| 4688 | altered_servers++; |
| 4689 | total_servers++; |
| 4690 | break; |
| 4691 | case ST_ADM_ACTION_MAINT: |
| 4692 | srv_adm_set_maint(sv); |
| 4693 | altered_servers++; |
| 4694 | total_servers++; |
| 4695 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4696 | case ST_ADM_ACTION_SHUTDOWN: |
| 4697 | if (px->state != PR_STSTOPPED) { |
| 4698 | struct session *sess, *sess_bck; |
| 4699 | |
| 4700 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4701 | if (sess->srv_conn == sv) |
| 4702 | session_shutdown(sess, SN_ERR_KILLED); |
| 4703 | |
| 4704 | altered_servers++; |
| 4705 | total_servers++; |
| 4706 | } |
| 4707 | break; |
| 4708 | } |
| 4709 | } else { |
| 4710 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4711 | total_servers++; |
| 4712 | } |
| 4713 | } |
| 4714 | if (reprocess && px && action) { |
| 4715 | /* Now, we know the backend and the action chosen by the user. |
| 4716 | * We can safely restart from the first server parameter |
| 4717 | * to reprocess them |
| 4718 | */ |
| 4719 | cur_param = st_cur_param; |
| 4720 | next_param = st_next_param; |
| 4721 | reprocess = 0; |
| 4722 | goto reprocess_servers; |
| 4723 | } |
| 4724 | |
| 4725 | next_param = cur_param; |
| 4726 | } |
| 4727 | } |
| 4728 | |
| 4729 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4730 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4731 | } |
| 4732 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4733 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4734 | } |
| 4735 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4736 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4737 | } |
| 4738 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4739 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4740 | } |
| 4741 | out: |
| 4742 | return 1; |
| 4743 | } |
| 4744 | |
| 4745 | |
| 4746 | static int stats_send_http_headers(struct stream_interface *si) |
| 4747 | { |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 4748 | struct session *s = si_sess(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4749 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4750 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4751 | |
| 4752 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4753 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4754 | "Cache-Control: no-cache\r\n" |
| 4755 | "Connection: close\r\n" |
| 4756 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4757 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4758 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4759 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4760 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4761 | uri->refresh); |
| 4762 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4763 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4764 | |
| 4765 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4766 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4767 | else |
| 4768 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4769 | |
| 4770 | s->txn.status = 200; |
| 4771 | s->logs.tv_request = now; |
| 4772 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4773 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 4774 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4775 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4776 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4777 | |
| 4778 | return 1; |
| 4779 | } |
| 4780 | |
| 4781 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4782 | { |
| 4783 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 4784 | struct session *s = si_sess(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4785 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4786 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4787 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4788 | /* 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] | 4789 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4790 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4791 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4792 | 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] | 4793 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | /* We don't want to land on the posted stats page because a refresh will |
| 4797 | * repost the data. We don't want this to happen on accident so we redirect |
| 4798 | * the browse to the stats page with a GET. |
| 4799 | */ |
| 4800 | chunk_printf(&trash, |
| 4801 | "HTTP/1.1 303 See Other\r\n" |
| 4802 | "Cache-Control: no-cache\r\n" |
| 4803 | "Content-Type: text/plain\r\n" |
| 4804 | "Connection: close\r\n" |
| 4805 | "Location: %s;st=%s%s%s%s\r\n" |
| 4806 | "\r\n", |
| 4807 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4808 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4809 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4810 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4811 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4812 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4813 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4814 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4815 | scope_txt); |
| 4816 | |
| 4817 | s->txn.status = 303; |
| 4818 | s->logs.tv_request = now; |
| 4819 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4820 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 4821 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4822 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4823 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4824 | |
| 4825 | return 1; |
| 4826 | } |
| 4827 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4828 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4829 | * 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] | 4830 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4831 | * automatically unregisters itself once transfer is complete. |
| 4832 | */ |
| 4833 | static void http_stats_io_handler(struct stream_interface *si) |
| 4834 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4835 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 4836 | struct session *s = si_sess(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4837 | struct channel *req = si_oc(si); |
| 4838 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4839 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4840 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4841 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4842 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4843 | /* check that the output is not closed */ |
| 4844 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4845 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4846 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4847 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4848 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4849 | if (stats_send_http_headers(si)) { |
| 4850 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4851 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4852 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4853 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4854 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4855 | } |
| 4856 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4857 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4858 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4859 | unsigned int data_len; |
| 4860 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 4861 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4862 | |
| 4863 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4864 | /* One difficulty we're facing is that we must prevent |
| 4865 | * the input data from being automatically forwarded to |
| 4866 | * the output area. For this, we temporarily disable |
| 4867 | * forwarding on the channel. |
| 4868 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4869 | last_fwd = si_ic(si)->to_forward; |
| 4870 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4871 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4872 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4873 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4874 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4875 | goto fail; |
| 4876 | } |
| 4877 | } |
| 4878 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4879 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4880 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4881 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4882 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4883 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4884 | |
| 4885 | /* Now we must either adjust or remove the chunk size. This is |
| 4886 | * not easy because the chunk size might wrap at the end of the |
| 4887 | * buffer, so we pretend we have nothing in the buffer, we write |
| 4888 | * the size, then restore the buffer's contents. Note that we can |
| 4889 | * only do that because no forwarding is scheduled on the stats |
| 4890 | * applet. |
| 4891 | */ |
| 4892 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4893 | si_ic(si)->total -= (last_len - prev_len); |
| 4894 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4895 | |
| 4896 | if (last_len != data_len) { |
| 4897 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4898 | if (bi_putchk(si_ic(si), &trash) == -1) |
| 4899 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4900 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4901 | si_ic(si)->total += (last_len - data_len); |
| 4902 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4903 | } |
| 4904 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4905 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4906 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4907 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4908 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4909 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4910 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4911 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4912 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4913 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4914 | } |
| 4915 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4916 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4917 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4918 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4919 | } |
| 4920 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4921 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 4922 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4923 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4924 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 4925 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4926 | goto fail; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4927 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4928 | } |
| 4929 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4930 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4931 | res->flags |= CF_READ_NULL; |
| 4932 | si_shutr(si); |
| 4933 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4934 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4935 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4936 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4937 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4938 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4939 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4940 | si_shutr(si); |
| 4941 | res->flags |= CF_READ_NULL; |
| 4942 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4943 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4944 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4945 | fail: |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4946 | /* update all other flags and resync with the other side */ |
| 4947 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4948 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4949 | /* we don't want to expire timeouts while we're processing requests */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4950 | si_ic(si)->rex = TICK_ETERNITY; |
| 4951 | si_oc(si)->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4952 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4953 | out: |
| 4954 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4955 | /* check that we have released everything then unregister */ |
| 4956 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4957 | } |
| 4958 | } |
| 4959 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4960 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4961 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4962 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4963 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4964 | return "NONE"; |
| 4965 | return conn->ctrl->name; |
| 4966 | } |
| 4967 | |
| 4968 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4969 | { |
| 4970 | static char ptr[17]; |
| 4971 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4972 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4973 | return "NONE"; |
| 4974 | |
| 4975 | if (conn->xprt == &raw_sock) |
| 4976 | return "RAW"; |
| 4977 | |
| 4978 | #ifdef USE_OPENSSL |
| 4979 | if (conn->xprt == &ssl_sock) |
| 4980 | return "SSL"; |
| 4981 | #endif |
| 4982 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4983 | return ptr; |
| 4984 | } |
| 4985 | |
| 4986 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4987 | { |
| 4988 | static char ptr[17]; |
| 4989 | |
| 4990 | if (!conn->data) |
| 4991 | return "NONE"; |
| 4992 | |
| 4993 | if (conn->data == &sess_conn_cb) |
| 4994 | return "SESS"; |
| 4995 | |
| 4996 | if (conn->data == &si_conn_cb) |
| 4997 | return "STRM"; |
| 4998 | |
| 4999 | if (conn->data == &check_conn_cb) |
| 5000 | return "CHCK"; |
| 5001 | |
| 5002 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5003 | return ptr; |
| 5004 | } |
| 5005 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5006 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5007 | * read buffer. The session has to be set in sess->target. It returns |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 5008 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5009 | * 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] | 5010 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5011 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5012 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5013 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5014 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5015 | extern const char *monthname[12]; |
| 5016 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5017 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5018 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5019 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5020 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5021 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5022 | if (appctx->ctx.sess.section > 0 && appctx->ctx.sess.uid != sess->uniq_id) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5023 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5024 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5025 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5026 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5027 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5028 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5029 | appctx->ctx.sess.uid = 0; |
| 5030 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5031 | return 1; |
| 5032 | } |
| 5033 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5034 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5035 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5036 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5037 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5038 | /* fall through */ |
| 5039 | |
| 5040 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5041 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5042 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5043 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5044 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5045 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5046 | 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] | 5047 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 5048 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5049 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5050 | conn = objt_conn(sess->si[0].end); |
| 5051 | 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] | 5052 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5053 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5054 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5055 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5056 | break; |
| 5057 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5058 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5059 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5060 | default: |
| 5061 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5062 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5063 | break; |
| 5064 | } |
| 5065 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5066 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5067 | " 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] | 5068 | 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] | 5069 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5070 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5071 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5072 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 5073 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 5074 | sess->listener ? sess->listener->luid : 0); |
| 5075 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5076 | if (conn) |
| 5077 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5078 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5079 | 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] | 5080 | case AF_INET: |
| 5081 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5082 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5083 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5084 | break; |
| 5085 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5086 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5087 | break; |
| 5088 | default: |
| 5089 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5090 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5091 | break; |
| 5092 | } |
| 5093 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5094 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5095 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5096 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5097 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5098 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5099 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5100 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5101 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5102 | conn = objt_conn(sess->si[1].end); |
| 5103 | if (conn) |
| 5104 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5105 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5106 | 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] | 5107 | case AF_INET: |
| 5108 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5109 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5110 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5111 | break; |
| 5112 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5113 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5114 | break; |
| 5115 | default: |
| 5116 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5117 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5118 | break; |
| 5119 | } |
| 5120 | |
| 5121 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5122 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5123 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5124 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5125 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5126 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5127 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5128 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5129 | if (conn) |
| 5130 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5131 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5132 | 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] | 5133 | case AF_INET: |
| 5134 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5135 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5136 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5137 | break; |
| 5138 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5139 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5140 | break; |
| 5141 | default: |
| 5142 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5143 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5144 | break; |
| 5145 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5146 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5147 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5148 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5149 | sess->task, |
| 5150 | sess->task->state, |
| 5151 | sess->task->nice, sess->task->calls, |
| 5152 | sess->task->expire ? |
| 5153 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5154 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5155 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5156 | task_in_rq(sess->task) ? ", running" : ""); |
| 5157 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5158 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5159 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5160 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5161 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5162 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5163 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s waiting=%d\n", |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5164 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5165 | 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] | 5166 | |
| 5167 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5168 | " 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] | 5169 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5170 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5171 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5172 | obj_type_name(sess->si[0].end), |
| 5173 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5174 | sess->si[0].exp ? |
| 5175 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5176 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5177 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5178 | sess->si[0].err_type); |
| 5179 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5180 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5181 | " 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] | 5182 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5183 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5184 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5185 | obj_type_name(sess->si[1].end), |
| 5186 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5187 | sess->si[1].exp ? |
| 5188 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5189 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5190 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5191 | sess->si[1].err_type); |
| 5192 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5193 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5194 | chunk_appendf(&trash, |
| 5195 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5196 | conn, |
| 5197 | get_conn_ctrl_name(conn), |
| 5198 | get_conn_xprt_name(conn), |
| 5199 | get_conn_data_name(conn), |
| 5200 | obj_type_name(conn->target), |
| 5201 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5202 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5203 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5204 | " 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] | 5205 | conn->flags, |
| 5206 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5207 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5208 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5209 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5210 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5211 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5212 | chunk_appendf(&trash, |
| 5213 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5214 | tmpctx, |
| 5215 | tmpctx->st0, |
| 5216 | tmpctx->st1, |
| 5217 | tmpctx->st2, |
| 5218 | tmpctx->applet->name); |
| 5219 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5220 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5221 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5222 | chunk_appendf(&trash, |
| 5223 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5224 | conn, |
| 5225 | get_conn_ctrl_name(conn), |
| 5226 | get_conn_xprt_name(conn), |
| 5227 | get_conn_data_name(conn), |
| 5228 | obj_type_name(conn->target), |
| 5229 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5230 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5231 | chunk_appendf(&trash, |
| 5232 | " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5233 | conn->flags, |
| 5234 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5235 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5236 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5237 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5238 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5239 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5240 | chunk_appendf(&trash, |
| 5241 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5242 | tmpctx, |
| 5243 | tmpctx->st0, |
| 5244 | tmpctx->st1, |
| 5245 | tmpctx->st2, |
| 5246 | tmpctx->applet->name); |
| 5247 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5248 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5249 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5250 | " 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] | 5251 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5252 | &sess->req, |
| 5253 | sess->req.flags, sess->req.analysers, |
| 5254 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5255 | sess->req.to_forward, sess->req.total, |
| 5256 | sess->req.analyse_exp ? |
| 5257 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5258 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5259 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5260 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5261 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5262 | sess->req.rex ? |
| 5263 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5264 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5265 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5266 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5267 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5268 | " 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] | 5269 | sess->req.wex ? |
| 5270 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5271 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5272 | sess->req.buf, |
| 5273 | sess->req.buf->data, sess->req.buf->o, |
| 5274 | (int)(sess->req.buf->p - sess->req.buf->data), |
| 5275 | sess->txn.req.next, sess->req.buf->i, |
| 5276 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5277 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5278 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5279 | " 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] | 5280 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5281 | &sess->res, |
| 5282 | sess->res.flags, sess->res.analysers, |
| 5283 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5284 | sess->res.to_forward, sess->res.total, |
| 5285 | sess->res.analyse_exp ? |
| 5286 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5287 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5288 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5289 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5290 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5291 | sess->res.rex ? |
| 5292 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5293 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5294 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5295 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5296 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5297 | " 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] | 5298 | sess->res.wex ? |
| 5299 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5300 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5301 | sess->res.buf, |
| 5302 | sess->res.buf->data, sess->res.buf->o, |
| 5303 | (int)(sess->res.buf->p - sess->res.buf->data), |
| 5304 | sess->txn.rsp.next, sess->res.buf->i, |
| 5305 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5306 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5307 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5308 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5309 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5310 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5311 | |
| 5312 | /* use other states to dump the contents */ |
| 5313 | } |
| 5314 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5315 | appctx->ctx.sess.uid = 0; |
| 5316 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5317 | return 1; |
| 5318 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5319 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5320 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5321 | { |
| 5322 | struct appctx *appctx = __objt_appctx(si->end); |
| 5323 | |
| 5324 | switch (appctx->st2) { |
| 5325 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5326 | /* Display the column headers. If the message cannot be sent, |
| 5327 | * quit the fucntion with returning 0. The function is called |
| 5328 | * later and restart at the state "STAT_ST_INIT". |
| 5329 | */ |
| 5330 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5331 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5332 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5333 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5334 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5335 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5336 | |
| 5337 | /* Now, we start the browsing of the references lists. |
| 5338 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5339 | * avalaible field of this pointer is <list>. It is used with the function |
| 5340 | * pat_list_get_next() for retruning the first avalaible entry |
| 5341 | */ |
| 5342 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5343 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5344 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5345 | appctx->st2 = STAT_ST_LIST; |
| 5346 | /* fall through */ |
| 5347 | |
| 5348 | case STAT_ST_LIST: |
| 5349 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5350 | chunk_reset(&trash); |
| 5351 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5352 | /* Build messages. If the reference is used by another category than |
| 5353 | * the listed categorie, display the information in the massage. |
| 5354 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5355 | 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] | 5356 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5357 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5358 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5359 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5360 | /* let's try again later from this session. We add ourselves into |
| 5361 | * this session's users so that it can remove us upon termination. |
| 5362 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5363 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5364 | return 0; |
| 5365 | } |
| 5366 | |
| 5367 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5368 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5369 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | appctx->st2 = STAT_ST_FIN; |
| 5373 | /* fall through */ |
| 5374 | |
| 5375 | default: |
| 5376 | appctx->st2 = STAT_ST_FIN; |
| 5377 | return 1; |
| 5378 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5379 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5380 | } |
| 5381 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5382 | static int stats_map_lookup(struct stream_interface *si) |
| 5383 | { |
| 5384 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5385 | struct sample sample; |
| 5386 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5387 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5388 | |
| 5389 | switch (appctx->st2) { |
| 5390 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5391 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5392 | 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] | 5393 | 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] | 5394 | appctx->st2 = STAT_ST_LIST; |
| 5395 | /* fall through */ |
| 5396 | |
| 5397 | case STAT_ST_LIST: |
| 5398 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5399 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5400 | /* initialise chunk to build new message */ |
| 5401 | chunk_reset(&trash); |
| 5402 | |
| 5403 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 5404 | sample.type = SMP_T_STR; |
| 5405 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5406 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 5407 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5408 | if (appctx->ctx.map.expr->pat_head->match && |
| 5409 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5410 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5411 | else |
| 5412 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5413 | |
| 5414 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5415 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5416 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5417 | break; |
| 5418 | if (match_method >= PAT_MATCH_NUM) |
| 5419 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5420 | else |
| 5421 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5422 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5423 | /* case sensitive */ |
| 5424 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5425 | chunk_appendf(&trash, ", case=insensitive"); |
| 5426 | else |
| 5427 | chunk_appendf(&trash, ", case=sensitive"); |
| 5428 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5429 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5430 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5431 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5432 | chunk_appendf(&trash, ", found=no"); |
| 5433 | else |
| 5434 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | /* Display match and match info */ |
| 5438 | else { |
| 5439 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5440 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5441 | chunk_appendf(&trash, ", found=yes"); |
| 5442 | else |
| 5443 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5444 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5445 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5446 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5447 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5448 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5449 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5450 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5451 | /* display pattern */ |
| 5452 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5453 | if (pat->ref && pat->ref->pattern) |
| 5454 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5455 | else |
| 5456 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5457 | } |
| 5458 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5459 | if (pat->ref && pat->ref->pattern) |
| 5460 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5461 | else |
| 5462 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5463 | } |
| 5464 | |
| 5465 | /* display return value */ |
| 5466 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5467 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5468 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5469 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5470 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5471 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5472 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5473 | } |
| 5474 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5475 | chunk_appendf(&trash, "\n"); |
| 5476 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5477 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5478 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5479 | /* let's try again later from this session. We add ourselves into |
| 5480 | * this session's users so that it can remove us upon termination. |
| 5481 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5482 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5483 | return 0; |
| 5484 | } |
| 5485 | |
| 5486 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5487 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5488 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5489 | } |
| 5490 | |
| 5491 | appctx->st2 = STAT_ST_FIN; |
| 5492 | /* fall through */ |
| 5493 | |
| 5494 | default: |
| 5495 | appctx->st2 = STAT_ST_FIN; |
| 5496 | free(appctx->ctx.map.chunk.str); |
| 5497 | return 1; |
| 5498 | } |
| 5499 | } |
| 5500 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5501 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5502 | { |
| 5503 | struct appctx *appctx = __objt_appctx(si->end); |
| 5504 | |
| 5505 | switch (appctx->st2) { |
| 5506 | |
| 5507 | case STAT_ST_INIT: |
| 5508 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5509 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5510 | struct pat_ref_elt *, list); |
| 5511 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5512 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5513 | appctx->st2 = STAT_ST_LIST; |
| 5514 | /* fall through */ |
| 5515 | |
| 5516 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5517 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5518 | chunk_reset(&trash); |
| 5519 | |
| 5520 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5521 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5522 | chunk_appendf(&trash, "%p %s %s\n", |
| 5523 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5524 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5525 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5526 | chunk_appendf(&trash, "%p %s\n", |
| 5527 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5528 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5529 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5530 | /* let's try again later from this session. We add ourselves into |
| 5531 | * this session's users so that it can remove us upon termination. |
| 5532 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5533 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5534 | return 0; |
| 5535 | } |
| 5536 | |
| 5537 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5538 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5539 | struct pat_ref_elt *, list); |
| 5540 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5541 | break; |
| 5542 | } |
| 5543 | |
| 5544 | appctx->st2 = STAT_ST_FIN; |
| 5545 | /* fall through */ |
| 5546 | |
| 5547 | default: |
| 5548 | appctx->st2 = STAT_ST_FIN; |
| 5549 | return 1; |
| 5550 | } |
| 5551 | } |
| 5552 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5553 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5554 | * 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] | 5555 | * to be called again, otherwise non-zero. It is designed to be called |
| 5556 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5557 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5558 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5559 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5560 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5561 | struct connection *conn; |
| 5562 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5563 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5564 | /* If we're forced to shut down, we might have to remove our |
| 5565 | * reference to the last session being dumped. |
| 5566 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5567 | if (appctx->st2 == STAT_ST_LIST) { |
| 5568 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5569 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5570 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5571 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5572 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5573 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5574 | } |
| 5575 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5576 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5577 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5578 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5579 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5580 | /* the function had not been called yet, let's prepare the |
| 5581 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5582 | * pointer to the first in the global list. When a target |
| 5583 | * session is being destroyed, it is responsible for updating |
| 5584 | * this pointer. We know we have reached the end when this |
| 5585 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5586 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5587 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5588 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5589 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5590 | /* fall through */ |
| 5591 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5592 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5593 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5594 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5595 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5596 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5597 | } |
| 5598 | |
| 5599 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5600 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5601 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5602 | struct session *curr_sess; |
| 5603 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5604 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5605 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5606 | if (appctx->ctx.sess.target) { |
| 5607 | 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] | 5608 | goto next_sess; |
| 5609 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5610 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5611 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5612 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5613 | return 0; |
| 5614 | |
| 5615 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5616 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5617 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5618 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5619 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5620 | break; |
| 5621 | } |
| 5622 | else |
| 5623 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5624 | } |
| 5625 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5626 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5627 | "%p: proto=%s", |
| 5628 | curr_sess, |
| 5629 | curr_sess->listener->proto->name); |
| 5630 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5631 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5632 | conn = objt_conn(curr_sess->si[0].end); |
| 5633 | 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] | 5634 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5635 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5636 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5637 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5638 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5639 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5640 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5641 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5642 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5643 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5644 | break; |
| 5645 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5646 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5647 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5648 | curr_sess->listener->luid, |
| 5649 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5650 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5651 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5652 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5653 | break; |
| 5654 | } |
| 5655 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5656 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5657 | " ts=%02x age=%s calls=%d", |
| 5658 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5659 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5660 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5661 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5662 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5663 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5664 | curr_sess->req.flags, |
| 5665 | curr_sess->req.buf->i, |
| 5666 | curr_sess->req.analysers, |
| 5667 | curr_sess->req.rex ? |
| 5668 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5669 | TICKS_TO_MS(1000)) : ""); |
| 5670 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5671 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5672 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5673 | curr_sess->req.wex ? |
| 5674 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5675 | TICKS_TO_MS(1000)) : ""); |
| 5676 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5677 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5678 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5679 | curr_sess->req.analyse_exp ? |
| 5680 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5681 | TICKS_TO_MS(1000)) : ""); |
| 5682 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5683 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5684 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5685 | curr_sess->res.flags, |
| 5686 | curr_sess->res.buf->i, |
| 5687 | curr_sess->res.analysers, |
| 5688 | curr_sess->res.rex ? |
| 5689 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5690 | TICKS_TO_MS(1000)) : ""); |
| 5691 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5692 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5693 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5694 | curr_sess->res.wex ? |
| 5695 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5696 | TICKS_TO_MS(1000)) : ""); |
| 5697 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5698 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5699 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5700 | curr_sess->res.analyse_exp ? |
| 5701 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5702 | TICKS_TO_MS(1000)) : ""); |
| 5703 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5704 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5705 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5706 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5707 | curr_sess->si[0].state, |
| 5708 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5709 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5710 | curr_sess->si[0].exp ? |
| 5711 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5712 | TICKS_TO_MS(1000)) : ""); |
| 5713 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5714 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5715 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5716 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5717 | curr_sess->si[1].state, |
| 5718 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5719 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5720 | curr_sess->si[1].exp ? |
| 5721 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5722 | TICKS_TO_MS(1000)) : ""); |
| 5723 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5724 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5725 | " exp=%s", |
| 5726 | curr_sess->task->expire ? |
| 5727 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5728 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5729 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5730 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5731 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5732 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5733 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5734 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5735 | /* let's try again later from this session. We add ourselves into |
| 5736 | * this session's users so that it can remove us upon termination. |
| 5737 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5738 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5739 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5740 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5741 | } |
| 5742 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5743 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5744 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5745 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5746 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5747 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5748 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5749 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5750 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5751 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5752 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5753 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5754 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5755 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5756 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5757 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5758 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5759 | appctx->ctx.sess.target = NULL; |
| 5760 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5761 | return 1; |
| 5762 | } |
| 5763 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5764 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5765 | /* fall through */ |
| 5766 | |
| 5767 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5768 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5769 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5770 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5771 | } |
| 5772 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5773 | /* This is called when the stream interface is closed. For instance, upon an |
| 5774 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5775 | * remove back references to the session currently being dumped. |
| 5776 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5777 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5778 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5779 | struct appctx *appctx = __objt_appctx(si->end); |
| 5780 | |
| 5781 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5782 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5783 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5784 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5785 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5786 | free(appctx->ctx.cli.err); |
| 5787 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5788 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5789 | free(appctx->ctx.map.chunk.str); |
| 5790 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5791 | } |
| 5792 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5793 | /* This function is used to either dump tables states (when action is set |
| 5794 | * 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] | 5795 | * It returns 0 if the output buffer is full and it needs to be called |
| 5796 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5797 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5798 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5799 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5800 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 5801 | struct session *s = si_sess(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5802 | struct ebmb_node *eb; |
| 5803 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5804 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5805 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5806 | |
| 5807 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5808 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5809 | * - STAT_ST_INIT : the first call |
| 5810 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5811 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5812 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5813 | * and the entry pointer points to the next entry to be dumped, |
| 5814 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5815 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5816 | * data though. |
| 5817 | */ |
| 5818 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5819 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5820 | /* 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] | 5821 | if (appctx->st2 == STAT_ST_LIST) { |
| 5822 | appctx->ctx.table.entry->ref_cnt--; |
| 5823 | 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] | 5824 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5825 | return 1; |
| 5826 | } |
| 5827 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5828 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5829 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5830 | while (appctx->st2 != STAT_ST_FIN) { |
| 5831 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5832 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5833 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5834 | if (!appctx->ctx.table.proxy) |
| 5835 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5836 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5837 | appctx->ctx.table.entry = NULL; |
| 5838 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5839 | break; |
| 5840 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5841 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5842 | if (!appctx->ctx.table.proxy || |
| 5843 | (appctx->ctx.table.target && |
| 5844 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5845 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5846 | break; |
| 5847 | } |
| 5848 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5849 | if (appctx->ctx.table.proxy->table.size) { |
| 5850 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5851 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5852 | return 0; |
| 5853 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5854 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5855 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5856 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5857 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5858 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5859 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5860 | appctx->ctx.table.entry->ref_cnt++; |
| 5861 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5862 | break; |
| 5863 | } |
| 5864 | } |
| 5865 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5866 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5867 | break; |
| 5868 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5869 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5870 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5871 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5872 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5873 | /* we're filtering on some data contents */ |
| 5874 | void *ptr; |
| 5875 | long long data; |
| 5876 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5877 | dt = appctx->ctx.table.data_type; |
| 5878 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5879 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5880 | dt); |
| 5881 | |
| 5882 | data = 0; |
| 5883 | switch (stktable_data_types[dt].std_type) { |
| 5884 | case STD_T_SINT: |
| 5885 | data = stktable_data_cast(ptr, std_t_sint); |
| 5886 | break; |
| 5887 | case STD_T_UINT: |
| 5888 | data = stktable_data_cast(ptr, std_t_uint); |
| 5889 | break; |
| 5890 | case STD_T_ULL: |
| 5891 | data = stktable_data_cast(ptr, std_t_ull); |
| 5892 | break; |
| 5893 | case STD_T_FRQP: |
| 5894 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5895 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5896 | break; |
| 5897 | } |
| 5898 | |
| 5899 | /* 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] | 5900 | if ((data < appctx->ctx.table.value && |
| 5901 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5902 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5903 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5904 | (data == appctx->ctx.table.value && |
| 5905 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5906 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5907 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5908 | (data > appctx->ctx.table.value && |
| 5909 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5910 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5911 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5912 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5913 | } |
| 5914 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5915 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5916 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5917 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5918 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5919 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5920 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5921 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5922 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5923 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5924 | struct stksess *old = appctx->ctx.table.entry; |
| 5925 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5926 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5927 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5928 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5929 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5930 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5931 | break; |
| 5932 | } |
| 5933 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5934 | |
| 5935 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5936 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5937 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5938 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5939 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5940 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5941 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5942 | break; |
| 5943 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5944 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5945 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5946 | break; |
| 5947 | } |
| 5948 | } |
| 5949 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5950 | } |
| 5951 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5952 | /* 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] | 5953 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5954 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5955 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5956 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5957 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5958 | * after the offset. The new pointer is returned. |
| 5959 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5960 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5961 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5962 | { |
| 5963 | int end; |
| 5964 | unsigned char c; |
| 5965 | |
| 5966 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5967 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5968 | return ptr; |
| 5969 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5970 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5971 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5972 | while (ptr < len && ptr < bsize) { |
| 5973 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5974 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5975 | if (out->len > end - 2) |
| 5976 | break; |
| 5977 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5978 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5979 | if (out->len > end - 3) |
| 5980 | break; |
| 5981 | out->str[out->len++] = '\\'; |
| 5982 | switch (c) { |
| 5983 | case '\t': c = 't'; break; |
| 5984 | case '\n': c = 'n'; break; |
| 5985 | case '\r': c = 'r'; break; |
| 5986 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5987 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5988 | } |
| 5989 | out->str[out->len++] = c; |
| 5990 | } else { |
| 5991 | if (out->len > end - 5) |
| 5992 | break; |
| 5993 | out->str[out->len++] = '\\'; |
| 5994 | out->str[out->len++] = 'x'; |
| 5995 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5996 | out->str[out->len++] = hextab[c & 0xF]; |
| 5997 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5998 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5999 | /* we had a line break, let's return now */ |
| 6000 | out->str[out->len++] = '\n'; |
| 6001 | *line = ptr; |
| 6002 | return ptr; |
| 6003 | } |
| 6004 | } |
| 6005 | /* we have an incomplete line, we return it as-is */ |
| 6006 | out->str[out->len++] = '\n'; |
| 6007 | return ptr; |
| 6008 | } |
| 6009 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6010 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6011 | * 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] | 6012 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6013 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6014 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6015 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6016 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6017 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6018 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6019 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6020 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6021 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6022 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6023 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6024 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6025 | /* the function had not been called yet, let's prepare the |
| 6026 | * buffer for a response. |
| 6027 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6028 | struct tm tm; |
| 6029 | |
| 6030 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6031 | 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] | 6032 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6033 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6034 | error_snapshot_id); |
| 6035 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6036 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6037 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6038 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6039 | return 0; |
| 6040 | } |
| 6041 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6042 | appctx->ctx.errors.px = proxy; |
| 6043 | appctx->ctx.errors.buf = 0; |
| 6044 | appctx->ctx.errors.bol = 0; |
| 6045 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6046 | } |
| 6047 | |
| 6048 | /* we have two inner loops here, one for the proxy, the other one for |
| 6049 | * the buffer. |
| 6050 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6051 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6052 | struct error_snapshot *es; |
| 6053 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6054 | if (appctx->ctx.errors.buf == 0) |
| 6055 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6056 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6057 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6058 | |
| 6059 | if (!es->when.tv_sec) |
| 6060 | goto next; |
| 6061 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6062 | if (appctx->ctx.errors.iid >= 0 && |
| 6063 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6064 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6065 | goto next; |
| 6066 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6067 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6068 | /* just print headers now */ |
| 6069 | |
| 6070 | char pn[INET6_ADDRSTRLEN]; |
| 6071 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6072 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6073 | |
| 6074 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6075 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6076 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6077 | 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] | 6078 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6079 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6080 | case AF_INET: |
| 6081 | case AF_INET6: |
| 6082 | port = get_host_port(&es->src); |
| 6083 | break; |
| 6084 | default: |
| 6085 | port = 0; |
| 6086 | } |
| 6087 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6088 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6089 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6090 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6091 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6092 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6093 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6094 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6095 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6096 | break; |
| 6097 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6098 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6099 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6100 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6101 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6102 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6103 | break; |
| 6104 | } |
| 6105 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6106 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6107 | ", server %s (#%d), event #%u\n" |
| 6108 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6109 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6110 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6111 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6112 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6113 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6114 | es->ev_id, |
| 6115 | pn, port, es->sid, es->s_flags, |
| 6116 | es->state, es->m_flags, es->t_flags, |
| 6117 | es->m_clen, es->m_blen, |
| 6118 | es->b_flags, es->b_out, es->b_tot, |
| 6119 | es->len, es->b_wrap, es->pos); |
| 6120 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6121 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6122 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6123 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6124 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6125 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6126 | appctx->ctx.errors.ptr = 0; |
| 6127 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6128 | } |
| 6129 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6130 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6131 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6132 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6133 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6134 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6135 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6136 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6137 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6138 | goto next; |
| 6139 | } |
| 6140 | |
| 6141 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6142 | 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] | 6143 | int newptr; |
| 6144 | int newline; |
| 6145 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6146 | newline = appctx->ctx.errors.bol; |
| 6147 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6148 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6149 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6150 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6151 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6152 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6153 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6154 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6155 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6156 | appctx->ctx.errors.ptr = newptr; |
| 6157 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6158 | }; |
| 6159 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6160 | appctx->ctx.errors.bol = 0; |
| 6161 | appctx->ctx.errors.ptr = -1; |
| 6162 | appctx->ctx.errors.buf++; |
| 6163 | if (appctx->ctx.errors.buf > 1) { |
| 6164 | appctx->ctx.errors.buf = 0; |
| 6165 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6166 | } |
| 6167 | } |
| 6168 | |
| 6169 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6170 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6171 | } |
| 6172 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6173 | /* parse the "level" argument on the bind lines */ |
| 6174 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6175 | { |
| 6176 | if (!*args[cur_arg + 1]) { |
| 6177 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6178 | return ERR_ALERT | ERR_FATAL; |
| 6179 | } |
| 6180 | |
| 6181 | if (!strcmp(args[cur_arg+1], "user")) |
| 6182 | conf->level = ACCESS_LVL_USER; |
| 6183 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6184 | conf->level = ACCESS_LVL_OPER; |
| 6185 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6186 | conf->level = ACCESS_LVL_ADMIN; |
| 6187 | else { |
| 6188 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6189 | args[cur_arg], args[cur_arg+1]); |
| 6190 | return ERR_ALERT | ERR_FATAL; |
| 6191 | } |
| 6192 | |
| 6193 | return 0; |
| 6194 | } |
| 6195 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6196 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6197 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6198 | .name = "<STATS>", /* used for logging */ |
| 6199 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6200 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6201 | }; |
| 6202 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6203 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6204 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6205 | .name = "<CLI>", /* used for logging */ |
| 6206 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6207 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6208 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6209 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6210 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6211 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6212 | { 0, NULL, NULL }, |
| 6213 | }}; |
| 6214 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6215 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6216 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6217 | { NULL, NULL, 0 }, |
| 6218 | }}; |
| 6219 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6220 | __attribute__((constructor)) |
| 6221 | static void __dumpstats_module_init(void) |
| 6222 | { |
| 6223 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6224 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6225 | } |
| 6226 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6227 | /* |
| 6228 | * Local variables: |
| 6229 | * c-indent-level: 8 |
| 6230 | * c-basic-offset: 8 |
| 6231 | * End: |
| 6232 | */ |