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 | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 582 | if (bi_putchk(si_ic(si), msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 583 | return 0; |
| 584 | |
| 585 | return 1; |
| 586 | } |
| 587 | |
| 588 | /* Dump the a table entry to a stream interface's |
| 589 | * read buffer. It returns 0 if the output buffer is full |
| 590 | * and needs to be called again, otherwise non-zero. |
| 591 | */ |
| 592 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 593 | struct proxy *proxy, struct stksess *entry) |
| 594 | { |
| 595 | int dt; |
| 596 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 597 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 598 | |
| 599 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 600 | char addr[INET_ADDRSTRLEN]; |
| 601 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 602 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 603 | } |
| 604 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 605 | char addr[INET6_ADDRSTRLEN]; |
| 606 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 607 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 608 | } |
| 609 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 610 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 611 | } |
| 612 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 613 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 614 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 615 | } |
| 616 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 617 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 618 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 619 | } |
| 620 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 621 | 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] | 622 | |
| 623 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 624 | void *ptr; |
| 625 | |
| 626 | if (proxy->table.data_ofs[dt] == 0) |
| 627 | continue; |
| 628 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 629 | 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] | 630 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 631 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 632 | |
| 633 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 634 | switch (stktable_data_types[dt].std_type) { |
| 635 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 636 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 637 | break; |
| 638 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 639 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 640 | break; |
| 641 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 642 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 643 | break; |
| 644 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 645 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 646 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 647 | proxy->table.data_arg[dt].u)); |
| 648 | break; |
| 649 | } |
| 650 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 651 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 652 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 653 | if (bi_putchk(si_ic(si), msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 654 | return 0; |
| 655 | |
| 656 | return 1; |
| 657 | } |
| 658 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 659 | 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] | 660 | { |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 661 | struct session *s = si_sess(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 662 | struct appctx *appctx = __objt_appctx(si->end); |
| 663 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 664 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 665 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 666 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 667 | long long value; |
| 668 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 669 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 670 | void *ptr; |
| 671 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 672 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 673 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 674 | |
| 675 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 676 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 677 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 678 | return; |
| 679 | } |
| 680 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 681 | switch (px->table.type) { |
| 682 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 683 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 684 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 685 | break; |
| 686 | case STKTABLE_TYPE_IPV6: |
| 687 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 688 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 689 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 690 | case STKTABLE_TYPE_INTEGER: |
| 691 | { |
| 692 | char *endptr; |
| 693 | unsigned long val; |
| 694 | errno = 0; |
| 695 | val = strtoul(args[4], &endptr, 10); |
| 696 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 697 | (errno != 0 && val == 0) || endptr == args[4] || |
| 698 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 699 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 700 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 701 | return; |
| 702 | } |
| 703 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 704 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 705 | break; |
| 706 | } |
| 707 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 708 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 709 | static_table_key->key = args[4]; |
| 710 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 711 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 712 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 713 | switch (action) { |
| 714 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 715 | 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] | 716 | break; |
| 717 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 718 | 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] | 719 | break; |
| 720 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 721 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 722 | break; |
| 723 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 724 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 725 | return; |
| 726 | } |
| 727 | |
| 728 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 729 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 730 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 731 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 732 | return; |
| 733 | } |
| 734 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 735 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 736 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 737 | switch (action) { |
| 738 | case STAT_CLI_O_TAB: |
| 739 | if (!ts) |
| 740 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 741 | chunk_reset(&trash); |
| 742 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 743 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 744 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 745 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 746 | |
| 747 | case STAT_CLI_O_CLR: |
| 748 | if (!ts) |
| 749 | return; |
| 750 | if (ts->ref_cnt) { |
| 751 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 752 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 753 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 754 | return; |
| 755 | } |
| 756 | stksess_kill(&px->table, ts); |
| 757 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 758 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 759 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 760 | if (ts) |
| 761 | stktable_touch(&px->table, ts, 1); |
| 762 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 763 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 764 | if (!ts) { |
| 765 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 766 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 767 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 768 | return; |
| 769 | } |
| 770 | stktable_store(&px->table, ts, 1); |
| 771 | } |
| 772 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 773 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 774 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 775 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 776 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 777 | return; |
| 778 | } |
| 779 | |
| 780 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 781 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 782 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 783 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 784 | return; |
| 785 | } |
| 786 | |
| 787 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 788 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 789 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 790 | return; |
| 791 | } |
| 792 | |
| 793 | 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] | 794 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 795 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 796 | return; |
| 797 | } |
| 798 | |
| 799 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 800 | |
| 801 | switch (stktable_data_types[data_type].std_type) { |
| 802 | case STD_T_SINT: |
| 803 | stktable_data_cast(ptr, std_t_sint) = value; |
| 804 | break; |
| 805 | case STD_T_UINT: |
| 806 | stktable_data_cast(ptr, std_t_uint) = value; |
| 807 | break; |
| 808 | case STD_T_ULL: |
| 809 | stktable_data_cast(ptr, std_t_ull) = value; |
| 810 | break; |
| 811 | case STD_T_FRQP: |
| 812 | /* We set both the current and previous values. That way |
| 813 | * the reported frequency is stable during all the period |
| 814 | * then slowly fades out. This allows external tools to |
| 815 | * push measures without having to update them too often. |
| 816 | */ |
| 817 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 818 | frqp->curr_tick = now_ms; |
| 819 | frqp->prev_ctr = 0; |
| 820 | frqp->curr_ctr = value; |
| 821 | break; |
| 822 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 823 | } |
| 824 | break; |
| 825 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 826 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 827 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 828 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 829 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 830 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 831 | } |
| 832 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 833 | 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] | 834 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 835 | struct appctx *appctx = __objt_appctx(si->end); |
| 836 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 837 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 838 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 839 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 840 | return; |
| 841 | } |
| 842 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 843 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 844 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 845 | if (appctx->ctx.table.data_type < 0) { |
| 846 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 847 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 848 | return; |
| 849 | } |
| 850 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 851 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 852 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 853 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 854 | return; |
| 855 | } |
| 856 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 857 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 858 | if (appctx->ctx.table.data_op < 0) { |
| 859 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 860 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 861 | return; |
| 862 | } |
| 863 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 864 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 865 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 866 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 867 | return; |
| 868 | } |
| 869 | } |
| 870 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 871 | 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] | 872 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 873 | struct appctx *appctx = __objt_appctx(si->end); |
| 874 | |
| 875 | appctx->ctx.table.data_type = -1; |
| 876 | appctx->st2 = STAT_ST_INIT; |
| 877 | appctx->ctx.table.target = NULL; |
| 878 | appctx->ctx.table.proxy = NULL; |
| 879 | appctx->ctx.table.entry = NULL; |
| 880 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 881 | |
| 882 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 883 | appctx->ctx.table.target = find_stktable(args[2]); |
| 884 | if (!appctx->ctx.table.target) { |
| 885 | appctx->ctx.cli.msg = "No such table\n"; |
| 886 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 887 | return; |
| 888 | } |
| 889 | } |
| 890 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 891 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 892 | goto err_args; |
| 893 | return; |
| 894 | } |
| 895 | |
| 896 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 897 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 898 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 899 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 900 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 901 | goto err_args; |
| 902 | |
| 903 | return; |
| 904 | |
| 905 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 906 | switch (action) { |
| 907 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 908 | 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] | 909 | break; |
| 910 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 911 | 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] | 912 | break; |
| 913 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 914 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 915 | break; |
| 916 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 917 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 918 | } |
| 919 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 920 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 921 | * adequate error messages and returns NULL. This function also expects the session |
| 922 | * level to be admin. |
| 923 | */ |
| 924 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 925 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 926 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 927 | struct proxy *px; |
| 928 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 929 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 930 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 931 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 932 | return NULL; |
| 933 | } |
| 934 | |
| 935 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 936 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 937 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 938 | return NULL; |
| 939 | } |
| 940 | |
| 941 | px = findproxy(arg, PR_CAP_FE); |
| 942 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 943 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 944 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 945 | return NULL; |
| 946 | } |
| 947 | return px; |
| 948 | } |
| 949 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 950 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 951 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 952 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 953 | * the <arg> is modified to remove the '/'. |
| 954 | */ |
| 955 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 956 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 957 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 958 | struct proxy *px; |
| 959 | struct server *sv; |
| 960 | char *line; |
| 961 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 962 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 963 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 964 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 965 | return NULL; |
| 966 | } |
| 967 | |
| 968 | /* split "backend/server" and make <line> point to server */ |
| 969 | for (line = arg; *line; line++) |
| 970 | if (*line == '/') { |
| 971 | *line++ = '\0'; |
| 972 | break; |
| 973 | } |
| 974 | |
| 975 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 976 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 977 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 978 | return NULL; |
| 979 | } |
| 980 | |
| 981 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 982 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 983 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 984 | return NULL; |
| 985 | } |
| 986 | |
| 987 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 988 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 989 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 990 | return NULL; |
| 991 | } |
| 992 | |
| 993 | return sv; |
| 994 | } |
| 995 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 996 | /* This function is used with map and acl management. It permits to browse |
| 997 | * each reference. The variable <getnext> must contain the current node, |
| 998 | * <end> point to the root node and the <flags> permit to filter required |
| 999 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1000 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1001 | static inline |
| 1002 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1003 | unsigned int flags) |
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 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1006 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1007 | while (1) { |
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 | /* Get next list entry. */ |
| 1010 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1011 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1012 | /* If the entry is the last of the list, return NULL. */ |
| 1013 | if (&ref->list == end) |
| 1014 | return NULL; |
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 match the flag, return it. */ |
| 1017 | if (ref->flags & flags) |
| 1018 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1022 | static inline |
| 1023 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1024 | { |
| 1025 | int id; |
| 1026 | char *error; |
| 1027 | |
| 1028 | /* If the reference starts by a '#', this is numeric id. */ |
| 1029 | if (reference[0] == '#') { |
| 1030 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1031 | id = strtol(reference + 1, &error, 10); |
| 1032 | if (*error != '\0') |
| 1033 | return NULL; |
| 1034 | |
| 1035 | /* Perform the unique id lookup. */ |
| 1036 | return pat_ref_lookupid(id); |
| 1037 | } |
| 1038 | |
| 1039 | /* Perform the string lookup. */ |
| 1040 | return pat_ref_lookup(reference); |
| 1041 | } |
| 1042 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1043 | /* This function is used with map and acl management. It permits to browse |
| 1044 | * each reference. |
| 1045 | */ |
| 1046 | static inline |
| 1047 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1048 | { |
| 1049 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1050 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1051 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1052 | return NULL; |
| 1053 | return expr; |
| 1054 | } |
| 1055 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1056 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1057 | * 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] | 1058 | * 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] | 1059 | * designating the function which will have to process the request, which can |
| 1060 | * 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] | 1061 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1062 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1063 | { |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 1064 | struct session *s = si_sess(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1065 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1066 | char *args[MAX_STATS_ARGS + 1]; |
| 1067 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1068 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1069 | |
| 1070 | while (isspace((unsigned char)*line)) |
| 1071 | line++; |
| 1072 | |
| 1073 | arg = 0; |
| 1074 | args[arg] = line; |
| 1075 | |
| 1076 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1077 | if (*line == '\\') { |
| 1078 | line++; |
| 1079 | if (*line == '\0') |
| 1080 | break; |
| 1081 | } |
| 1082 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1083 | *line++ = '\0'; |
| 1084 | |
| 1085 | while (isspace((unsigned char)*line)) |
| 1086 | line++; |
| 1087 | |
| 1088 | args[++arg] = line; |
| 1089 | continue; |
| 1090 | } |
| 1091 | |
| 1092 | line++; |
| 1093 | } |
| 1094 | |
| 1095 | while (++arg <= MAX_STATS_ARGS) |
| 1096 | args[arg] = line; |
| 1097 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1098 | /* remove \ */ |
| 1099 | arg = 0; |
| 1100 | while (*args[arg] != '\0') { |
| 1101 | j = 0; |
| 1102 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1103 | if (args[arg][i] == '\\') |
| 1104 | continue; |
| 1105 | args[arg][j] = args[arg][i]; |
| 1106 | j++; |
| 1107 | } |
| 1108 | args[arg][j] = '\0'; |
| 1109 | arg++; |
| 1110 | } |
| 1111 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1112 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1113 | if (strcmp(args[0], "show") == 0) { |
| 1114 | if (strcmp(args[1], "stat") == 0) { |
| 1115 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1116 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1117 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1118 | appctx->ctx.stats.type = atoi(args[3]); |
| 1119 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1120 | } |
| 1121 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1122 | appctx->st2 = STAT_ST_INIT; |
| 1123 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1124 | } |
| 1125 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1126 | appctx->st2 = STAT_ST_INIT; |
| 1127 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1128 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1129 | else if (strcmp(args[1], "pools") == 0) { |
| 1130 | appctx->st2 = STAT_ST_INIT; |
| 1131 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1132 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1133 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1134 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1135 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1136 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1137 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1138 | return 1; |
| 1139 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1140 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1141 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1142 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1143 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1144 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1145 | appctx->ctx.sess.target = NULL; |
| 1146 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1147 | appctx->ctx.sess.pos = 0; |
| 1148 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1149 | } |
| 1150 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1151 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1152 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1153 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1154 | return 1; |
| 1155 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1156 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1157 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1158 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1159 | appctx->ctx.errors.iid = -1; |
| 1160 | appctx->ctx.errors.px = NULL; |
| 1161 | appctx->st2 = STAT_ST_INIT; |
| 1162 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1163 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1164 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1165 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1166 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1167 | else if (strcmp(args[1], "map") == 0 || |
| 1168 | strcmp(args[1], "acl") == 0) { |
| 1169 | |
| 1170 | /* Set ACL or MAP flags. */ |
| 1171 | if (args[1][0] == 'm') |
| 1172 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1173 | else |
| 1174 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1175 | |
| 1176 | /* no parameter: display all map avalaible */ |
| 1177 | if (!*args[2]) { |
| 1178 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1179 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1180 | return 1; |
| 1181 | } |
| 1182 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1183 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1184 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1185 | if (!appctx->ctx.map.ref || |
| 1186 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1187 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1188 | 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] | 1189 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1190 | 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] | 1191 | appctx->st0 = STAT_CLI_PRINT; |
| 1192 | return 1; |
| 1193 | } |
| 1194 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1195 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1196 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1197 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1198 | return 0; |
| 1199 | } |
| 1200 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1201 | else if (strcmp(args[0], "clear") == 0) { |
| 1202 | if (strcmp(args[1], "counters") == 0) { |
| 1203 | struct proxy *px; |
| 1204 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1205 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1206 | int clrall = 0; |
| 1207 | |
| 1208 | if (strcmp(args[2], "all") == 0) |
| 1209 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1210 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1211 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1212 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1213 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1214 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1215 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1216 | return 1; |
| 1217 | } |
| 1218 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1219 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1220 | if (clrall) { |
| 1221 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1222 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1223 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1224 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1225 | px->be_counters.conn_max = 0; |
| 1226 | px->be_counters.p.http.rps_max = 0; |
| 1227 | px->be_counters.sps_max = 0; |
| 1228 | px->be_counters.cps_max = 0; |
| 1229 | px->be_counters.nbpend_max = 0; |
| 1230 | |
| 1231 | px->fe_counters.conn_max = 0; |
| 1232 | px->fe_counters.p.http.rps_max = 0; |
| 1233 | px->fe_counters.sps_max = 0; |
| 1234 | px->fe_counters.cps_max = 0; |
| 1235 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1236 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1237 | |
| 1238 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1239 | if (clrall) |
| 1240 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1241 | else { |
| 1242 | sv->counters.cur_sess_max = 0; |
| 1243 | sv->counters.nbpend_max = 0; |
| 1244 | sv->counters.sps_max = 0; |
| 1245 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1246 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1247 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1248 | if (li->counters) { |
| 1249 | if (clrall) |
| 1250 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1251 | else |
| 1252 | li->counters->conn_max = 0; |
| 1253 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1254 | } |
| 1255 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1256 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1257 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1258 | return 1; |
| 1259 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1260 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1261 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1262 | /* end of processing */ |
| 1263 | return 1; |
| 1264 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1265 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1266 | /* Set ACL or MAP flags. */ |
| 1267 | if (args[1][0] == 'm') |
| 1268 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1269 | else |
| 1270 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1271 | |
| 1272 | /* no parameter */ |
| 1273 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1274 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1275 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1276 | else |
| 1277 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1278 | appctx->st0 = STAT_CLI_PRINT; |
| 1279 | return 1; |
| 1280 | } |
| 1281 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1282 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1283 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1284 | if (!appctx->ctx.map.ref || |
| 1285 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1286 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1287 | 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] | 1288 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1289 | 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] | 1290 | appctx->st0 = STAT_CLI_PRINT; |
| 1291 | return 1; |
| 1292 | } |
| 1293 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1294 | /* Clear all. */ |
| 1295 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1296 | |
| 1297 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1298 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1299 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1300 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1301 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1302 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1303 | return 0; |
| 1304 | } |
| 1305 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1306 | else if (strcmp(args[0], "get") == 0) { |
| 1307 | if (strcmp(args[1], "weight") == 0) { |
| 1308 | struct proxy *px; |
| 1309 | struct server *sv; |
| 1310 | |
| 1311 | /* split "backend/server" and make <line> point to server */ |
| 1312 | for (line = args[2]; *line; line++) |
| 1313 | if (*line == '/') { |
| 1314 | *line++ = '\0'; |
| 1315 | break; |
| 1316 | } |
| 1317 | |
| 1318 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1319 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1320 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1321 | return 1; |
| 1322 | } |
| 1323 | |
| 1324 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1325 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1326 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1327 | return 1; |
| 1328 | } |
| 1329 | |
| 1330 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1331 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 1332 | bi_putstr(si_ic(si), trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1333 | return 1; |
| 1334 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1335 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1336 | /* Set flags. */ |
| 1337 | if (args[1][0] == 'm') |
| 1338 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1339 | else |
| 1340 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1341 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1342 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1343 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1344 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1345 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1346 | else |
| 1347 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1348 | appctx->st0 = STAT_CLI_PRINT; |
| 1349 | return 1; |
| 1350 | } |
| 1351 | |
| 1352 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1353 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1354 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1355 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1356 | 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] | 1357 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1358 | 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] | 1359 | appctx->st0 = STAT_CLI_PRINT; |
| 1360 | return 1; |
| 1361 | } |
| 1362 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1363 | /* copy input string. The string must be allocated because |
| 1364 | * it may be used over multiple iterations. It's released |
| 1365 | * at the end and upon abort anyway. |
| 1366 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1367 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1368 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1369 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1370 | if (!appctx->ctx.map.chunk.str) { |
| 1371 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1372 | appctx->st0 = STAT_CLI_PRINT; |
| 1373 | return 1; |
| 1374 | } |
| 1375 | |
| 1376 | /* prepare response */ |
| 1377 | appctx->st2 = STAT_ST_INIT; |
| 1378 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1379 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1380 | else { /* not "get weight" */ |
| 1381 | return 0; |
| 1382 | } |
| 1383 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1384 | else if (strcmp(args[0], "set") == 0) { |
| 1385 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1386 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1387 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1388 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1389 | sv = expect_server_admin(s, si, args[2]); |
| 1390 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1391 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1392 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1393 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1394 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1395 | appctx->ctx.cli.msg = warning; |
| 1396 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1397 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1398 | return 1; |
| 1399 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1400 | else if (strcmp(args[1], "server") == 0) { |
| 1401 | struct server *sv; |
| 1402 | const char *warning; |
| 1403 | |
| 1404 | sv = expect_server_admin(s, si, args[2]); |
| 1405 | if (!sv) |
| 1406 | return 1; |
| 1407 | |
| 1408 | if (strcmp(args[3], "weight") == 0) { |
| 1409 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1410 | if (warning) { |
| 1411 | appctx->ctx.cli.msg = warning; |
| 1412 | appctx->st0 = STAT_CLI_PRINT; |
| 1413 | } |
| 1414 | } |
| 1415 | else if (strcmp(args[3], "state") == 0) { |
| 1416 | if (strcmp(args[4], "ready") == 0) |
| 1417 | srv_adm_set_ready(sv); |
| 1418 | else if (strcmp(args[4], "drain") == 0) |
| 1419 | srv_adm_set_drain(sv); |
| 1420 | else if (strcmp(args[4], "maint") == 0) |
| 1421 | srv_adm_set_maint(sv); |
| 1422 | else { |
| 1423 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1424 | appctx->st0 = STAT_CLI_PRINT; |
| 1425 | } |
| 1426 | } |
| 1427 | else if (strcmp(args[3], "health") == 0) { |
| 1428 | if (sv->track) { |
| 1429 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1430 | appctx->st0 = STAT_CLI_PRINT; |
| 1431 | } |
| 1432 | else if (strcmp(args[4], "up") == 0) { |
| 1433 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1434 | srv_set_running(sv, "changed from CLI"); |
| 1435 | } |
| 1436 | else if (strcmp(args[4], "stopping") == 0) { |
| 1437 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1438 | srv_set_stopping(sv, "changed from CLI"); |
| 1439 | } |
| 1440 | else if (strcmp(args[4], "down") == 0) { |
| 1441 | sv->check.health = 0; |
| 1442 | srv_set_stopped(sv, "changed from CLI"); |
| 1443 | } |
| 1444 | else { |
| 1445 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1446 | appctx->st0 = STAT_CLI_PRINT; |
| 1447 | } |
| 1448 | } |
| 1449 | else if (strcmp(args[3], "agent") == 0) { |
| 1450 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1451 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1452 | appctx->st0 = STAT_CLI_PRINT; |
| 1453 | } |
| 1454 | else if (strcmp(args[4], "up") == 0) { |
| 1455 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1456 | srv_set_running(sv, "changed from CLI"); |
| 1457 | } |
| 1458 | else if (strcmp(args[4], "down") == 0) { |
| 1459 | sv->agent.health = 0; |
| 1460 | srv_set_stopped(sv, "changed from CLI"); |
| 1461 | } |
| 1462 | else { |
| 1463 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1464 | appctx->st0 = STAT_CLI_PRINT; |
| 1465 | } |
| 1466 | } |
| 1467 | else { |
| 1468 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state' and 'weight'.\n"; |
| 1469 | appctx->st0 = STAT_CLI_PRINT; |
| 1470 | } |
| 1471 | return 1; |
| 1472 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1473 | else if (strcmp(args[1], "timeout") == 0) { |
| 1474 | if (strcmp(args[2], "cli") == 0) { |
| 1475 | unsigned timeout; |
| 1476 | const char *res; |
| 1477 | |
| 1478 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1479 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1480 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1481 | return 1; |
| 1482 | } |
| 1483 | |
| 1484 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1485 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1486 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1487 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1488 | return 1; |
| 1489 | } |
| 1490 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1491 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1492 | return 1; |
| 1493 | } |
| 1494 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1495 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1496 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1497 | return 1; |
| 1498 | } |
| 1499 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1500 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1501 | if (strcmp(args[2], "frontend") == 0) { |
| 1502 | struct proxy *px; |
| 1503 | struct listener *l; |
| 1504 | int v; |
| 1505 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1506 | px = expect_frontend_admin(s, si, args[3]); |
| 1507 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1508 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1509 | |
| 1510 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1511 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1512 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1513 | return 1; |
| 1514 | } |
| 1515 | |
| 1516 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1517 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1518 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1519 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1520 | return 1; |
| 1521 | } |
| 1522 | |
| 1523 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1524 | * its listeners. The blocked ones will be dequeued. |
| 1525 | */ |
| 1526 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1527 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1528 | l->maxconn = v; |
| 1529 | if (l->state == LI_FULL) |
| 1530 | resume_listener(l); |
| 1531 | } |
| 1532 | |
| 1533 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1534 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1535 | |
| 1536 | return 1; |
| 1537 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1538 | else if (strcmp(args[2], "global") == 0) { |
| 1539 | int v; |
| 1540 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1541 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1542 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1543 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1544 | return 1; |
| 1545 | } |
| 1546 | |
| 1547 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1548 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1549 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1550 | return 1; |
| 1551 | } |
| 1552 | |
| 1553 | v = atoi(args[3]); |
| 1554 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1555 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1556 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1557 | return 1; |
| 1558 | } |
| 1559 | |
| 1560 | /* check for unlimited values */ |
| 1561 | if (v <= 0) |
| 1562 | v = global.hardmaxconn; |
| 1563 | |
| 1564 | global.maxconn = v; |
| 1565 | |
| 1566 | /* Dequeues all of the listeners waiting for a resource */ |
| 1567 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1568 | dequeue_all_listeners(&global_listener_queue); |
| 1569 | |
| 1570 | return 1; |
| 1571 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1572 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1573 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1574 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1575 | return 1; |
| 1576 | } |
| 1577 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1578 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1579 | if (strcmp(args[2], "connections") == 0) { |
| 1580 | if (strcmp(args[3], "global") == 0) { |
| 1581 | int v; |
| 1582 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1583 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1584 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1585 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1586 | return 1; |
| 1587 | } |
| 1588 | |
| 1589 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1590 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1591 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1592 | return 1; |
| 1593 | } |
| 1594 | |
| 1595 | v = atoi(args[4]); |
| 1596 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1597 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1598 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1599 | return 1; |
| 1600 | } |
| 1601 | |
| 1602 | global.cps_lim = v; |
| 1603 | |
| 1604 | /* Dequeues all of the listeners waiting for a resource */ |
| 1605 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1606 | dequeue_all_listeners(&global_listener_queue); |
| 1607 | |
| 1608 | return 1; |
| 1609 | } |
| 1610 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1611 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1612 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1613 | return 1; |
| 1614 | } |
| 1615 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1616 | else if (strcmp(args[2], "sessions") == 0) { |
| 1617 | if (strcmp(args[3], "global") == 0) { |
| 1618 | int v; |
| 1619 | |
| 1620 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1621 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1622 | appctx->st0 = STAT_CLI_PRINT; |
| 1623 | return 1; |
| 1624 | } |
| 1625 | |
| 1626 | if (!*args[4]) { |
| 1627 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1628 | appctx->st0 = STAT_CLI_PRINT; |
| 1629 | return 1; |
| 1630 | } |
| 1631 | |
| 1632 | v = atoi(args[4]); |
| 1633 | if (v < 0) { |
| 1634 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1635 | appctx->st0 = STAT_CLI_PRINT; |
| 1636 | return 1; |
| 1637 | } |
| 1638 | |
| 1639 | global.sps_lim = v; |
| 1640 | |
| 1641 | /* Dequeues all of the listeners waiting for a resource */ |
| 1642 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1643 | dequeue_all_listeners(&global_listener_queue); |
| 1644 | |
| 1645 | return 1; |
| 1646 | } |
| 1647 | else { |
| 1648 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1649 | appctx->st0 = STAT_CLI_PRINT; |
| 1650 | return 1; |
| 1651 | } |
| 1652 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1653 | #ifdef USE_OPENSSL |
| 1654 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1655 | if (strcmp(args[3], "global") == 0) { |
| 1656 | int v; |
| 1657 | |
| 1658 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1659 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1660 | appctx->st0 = STAT_CLI_PRINT; |
| 1661 | return 1; |
| 1662 | } |
| 1663 | |
| 1664 | if (!*args[4]) { |
| 1665 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1666 | appctx->st0 = STAT_CLI_PRINT; |
| 1667 | return 1; |
| 1668 | } |
| 1669 | |
| 1670 | v = atoi(args[4]); |
| 1671 | if (v < 0) { |
| 1672 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1673 | appctx->st0 = STAT_CLI_PRINT; |
| 1674 | return 1; |
| 1675 | } |
| 1676 | |
| 1677 | global.ssl_lim = v; |
| 1678 | |
| 1679 | /* Dequeues all of the listeners waiting for a resource */ |
| 1680 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1681 | dequeue_all_listeners(&global_listener_queue); |
| 1682 | |
| 1683 | return 1; |
| 1684 | } |
| 1685 | else { |
| 1686 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1687 | appctx->st0 = STAT_CLI_PRINT; |
| 1688 | return 1; |
| 1689 | } |
| 1690 | } |
| 1691 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1692 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1693 | if (strcmp(args[3], "global") == 0) { |
| 1694 | int v; |
| 1695 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1696 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1697 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1698 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1699 | return 1; |
| 1700 | } |
| 1701 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1702 | v = atoi(args[4]); |
| 1703 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1704 | } |
| 1705 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1706 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1707 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1708 | return 1; |
| 1709 | } |
| 1710 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1711 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1712 | 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] | 1713 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1714 | return 1; |
| 1715 | } |
| 1716 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1717 | else if (strcmp(args[1], "table") == 0) { |
| 1718 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1719 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1720 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1721 | char *err; |
| 1722 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1723 | /* Set flags. */ |
| 1724 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1725 | |
| 1726 | /* Expect three parameters: map name, key and new value. */ |
| 1727 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1728 | 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] | 1729 | appctx->st0 = STAT_CLI_PRINT; |
| 1730 | return 1; |
| 1731 | } |
| 1732 | |
| 1733 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1734 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1735 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1736 | 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] | 1737 | appctx->st0 = STAT_CLI_PRINT; |
| 1738 | return 1; |
| 1739 | } |
| 1740 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1741 | /* If the entry identifier start with a '#', it is considered as |
| 1742 | * pointer id |
| 1743 | */ |
| 1744 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1745 | struct pat_ref_elt *ref; |
| 1746 | long long int conv; |
| 1747 | char *error; |
| 1748 | |
| 1749 | /* Convert argument to integer value. */ |
| 1750 | conv = strtoll(&args[3][1], &error, 16); |
| 1751 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1752 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1753 | appctx->st0 = STAT_CLI_PRINT; |
| 1754 | return 1; |
| 1755 | } |
| 1756 | |
| 1757 | /* Convert and check integer to pointer. */ |
| 1758 | ref = (struct pat_ref_elt *)(long)conv; |
| 1759 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1760 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1761 | appctx->st0 = STAT_CLI_PRINT; |
| 1762 | return 1; |
| 1763 | } |
| 1764 | |
| 1765 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1766 | err = NULL; |
| 1767 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1768 | if (err) |
| 1769 | memprintf(&err, "%s.\n", err); |
| 1770 | appctx->ctx.cli.err = err; |
| 1771 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1772 | return 1; |
| 1773 | } |
| 1774 | } |
| 1775 | else { |
| 1776 | /* Else, use the entry identifier as pattern |
| 1777 | * string, and update the value. |
| 1778 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1779 | err = NULL; |
| 1780 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1781 | if (err) |
| 1782 | memprintf(&err, "%s.\n", err); |
| 1783 | appctx->ctx.cli.err = err; |
| 1784 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1785 | return 1; |
| 1786 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1787 | } |
| 1788 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1789 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1790 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1791 | return 1; |
| 1792 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1793 | #ifdef USE_OPENSSL |
| 1794 | else if (strcmp(args[1], "ssl") == 0) { |
| 1795 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 1796 | #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] | 1797 | char *err = NULL; |
| 1798 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 1799 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1800 | if (!*args[3]) { |
| 1801 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 1802 | appctx->st0 = STAT_CLI_PRINT; |
| 1803 | return 1; |
| 1804 | } |
| 1805 | |
| 1806 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 1807 | if (trash.len < 0) { |
| 1808 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 1809 | appctx->st0 = STAT_CLI_PRINT; |
| 1810 | return 1; |
| 1811 | } |
| 1812 | |
| 1813 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 1814 | if (err) { |
| 1815 | memprintf(&err, "%s.\n", err); |
| 1816 | appctx->ctx.cli.err = err; |
| 1817 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 1818 | } |
| 1819 | return 1; |
| 1820 | } |
| 1821 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 1822 | appctx->st0 = STAT_CLI_PRINT; |
| 1823 | return 1; |
| 1824 | #else |
| 1825 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 1826 | appctx->st0 = STAT_CLI_PRINT; |
| 1827 | return 1; |
| 1828 | #endif |
| 1829 | } |
| 1830 | else { |
| 1831 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 1832 | appctx->st0 = STAT_CLI_PRINT; |
| 1833 | return 1; |
| 1834 | } |
| 1835 | } |
| 1836 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1837 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1838 | return 0; |
| 1839 | } |
| 1840 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1841 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1842 | if (strcmp(args[1], "agent") == 0) { |
| 1843 | struct server *sv; |
| 1844 | |
| 1845 | sv = expect_server_admin(s, si, args[2]); |
| 1846 | if (!sv) |
| 1847 | return 1; |
| 1848 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1849 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1850 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1851 | appctx->st0 = STAT_CLI_PRINT; |
| 1852 | return 1; |
| 1853 | } |
| 1854 | |
| 1855 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1856 | return 1; |
| 1857 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1858 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1859 | struct server *sv; |
| 1860 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1861 | sv = expect_server_admin(s, si, args[2]); |
| 1862 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1863 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1864 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1865 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 1866 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 1867 | appctx->st0 = STAT_CLI_PRINT; |
| 1868 | return 1; |
| 1869 | } |
| 1870 | |
| 1871 | sv->check.state |= CHK_ST_ENABLED; |
| 1872 | return 1; |
| 1873 | } |
| 1874 | else if (strcmp(args[1], "server") == 0) { |
| 1875 | struct server *sv; |
| 1876 | |
| 1877 | sv = expect_server_admin(s, si, args[2]); |
| 1878 | if (!sv) |
| 1879 | return 1; |
| 1880 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1881 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1882 | return 1; |
| 1883 | } |
| 1884 | else if (strcmp(args[1], "frontend") == 0) { |
| 1885 | struct proxy *px; |
| 1886 | |
| 1887 | px = expect_frontend_admin(s, si, args[2]); |
| 1888 | if (!px) |
| 1889 | return 1; |
| 1890 | |
| 1891 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1892 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1893 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1894 | return 1; |
| 1895 | } |
| 1896 | |
| 1897 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1898 | appctx->ctx.cli.msg = "Frontend is already enabled.\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 (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1904 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1905 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1906 | return 1; |
| 1907 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1908 | return 1; |
| 1909 | } |
| 1910 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1911 | 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] | 1912 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1913 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1914 | } |
| 1915 | } |
| 1916 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1917 | if (strcmp(args[1], "agent") == 0) { |
| 1918 | struct server *sv; |
| 1919 | |
| 1920 | sv = expect_server_admin(s, si, args[2]); |
| 1921 | if (!sv) |
| 1922 | return 1; |
| 1923 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1924 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1925 | return 1; |
| 1926 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1927 | else if (strcmp(args[1], "health") == 0) { |
| 1928 | struct server *sv; |
| 1929 | |
| 1930 | sv = expect_server_admin(s, si, args[2]); |
| 1931 | if (!sv) |
| 1932 | return 1; |
| 1933 | |
| 1934 | sv->check.state &= ~CHK_ST_ENABLED; |
| 1935 | return 1; |
| 1936 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1937 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1938 | struct server *sv; |
| 1939 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1940 | sv = expect_server_admin(s, si, args[2]); |
| 1941 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1942 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1943 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1944 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1945 | return 1; |
| 1946 | } |
| 1947 | else if (strcmp(args[1], "frontend") == 0) { |
| 1948 | struct proxy *px; |
| 1949 | |
| 1950 | px = expect_frontend_admin(s, si, args[2]); |
| 1951 | if (!px) |
| 1952 | return 1; |
| 1953 | |
| 1954 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1955 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1956 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1957 | return 1; |
| 1958 | } |
| 1959 | |
| 1960 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1961 | appctx->ctx.cli.msg = "Frontend is already disabled.\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 (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1967 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1968 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1969 | return 1; |
| 1970 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1971 | return 1; |
| 1972 | } |
| 1973 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1974 | 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] | 1975 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1976 | return 1; |
| 1977 | } |
| 1978 | } |
| 1979 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1980 | if (strcmp(args[1], "frontend") == 0) { |
| 1981 | struct proxy *px; |
| 1982 | |
| 1983 | px = expect_frontend_admin(s, si, args[2]); |
| 1984 | if (!px) |
| 1985 | return 1; |
| 1986 | |
| 1987 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1988 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1989 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1990 | return 1; |
| 1991 | } |
| 1992 | |
| 1993 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1994 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1995 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1996 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1997 | stop_proxy(px); |
| 1998 | return 1; |
| 1999 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2000 | else if (strcmp(args[1], "session") == 0) { |
| 2001 | struct session *sess, *ptr; |
| 2002 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 2003 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2004 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2005 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2006 | return 1; |
| 2007 | } |
| 2008 | |
| 2009 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2010 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2011 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2012 | return 1; |
| 2013 | } |
| 2014 | |
| 2015 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2016 | |
| 2017 | /* first, look for the requested session in the session table */ |
| 2018 | list_for_each_entry(sess, &sessions, list) { |
| 2019 | if (sess == ptr) |
| 2020 | break; |
| 2021 | } |
| 2022 | |
| 2023 | /* do we have the session ? */ |
| 2024 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2025 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2026 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2027 | return 1; |
| 2028 | } |
| 2029 | |
| 2030 | session_shutdown(sess, SN_ERR_KILLED); |
| 2031 | return 1; |
| 2032 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2033 | else if (strcmp(args[1], "sessions") == 0) { |
| 2034 | if (strcmp(args[2], "server") == 0) { |
| 2035 | struct server *sv; |
| 2036 | struct session *sess, *sess_bck; |
| 2037 | |
| 2038 | sv = expect_server_admin(s, si, args[3]); |
| 2039 | if (!sv) |
| 2040 | return 1; |
| 2041 | |
| 2042 | /* kill all the session that are on this server */ |
| 2043 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2044 | if (sess->srv_conn == sv) |
| 2045 | session_shutdown(sess, SN_ERR_KILLED); |
| 2046 | |
| 2047 | return 1; |
| 2048 | } |
| 2049 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2050 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2051 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2052 | return 1; |
| 2053 | } |
| 2054 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2055 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2056 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2057 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2058 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2059 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2060 | } |
| 2061 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2062 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2063 | if (args[1][0] == 'm') |
| 2064 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2065 | else |
| 2066 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2067 | |
| 2068 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2069 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2070 | if (!*args[2] || !*args[3]) { |
| 2071 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2072 | appctx->st0 = STAT_CLI_PRINT; |
| 2073 | return 1; |
| 2074 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2075 | } |
| 2076 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2077 | else { |
| 2078 | if (!*args[2] || !*args[3]) { |
| 2079 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2080 | appctx->st0 = STAT_CLI_PRINT; |
| 2081 | return 1; |
| 2082 | } |
| 2083 | } |
| 2084 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2085 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2086 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2087 | if (!appctx->ctx.map.ref || |
| 2088 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2089 | 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] | 2090 | appctx->st0 = STAT_CLI_PRINT; |
| 2091 | return 1; |
| 2092 | } |
| 2093 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2094 | /* If the entry identifier start with a '#', it is considered as |
| 2095 | * pointer id |
| 2096 | */ |
| 2097 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2098 | struct pat_ref_elt *ref; |
| 2099 | long long int conv; |
| 2100 | char *error; |
| 2101 | |
| 2102 | /* Convert argument to integer value. */ |
| 2103 | conv = strtoll(&args[3][1], &error, 16); |
| 2104 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2105 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2106 | appctx->st0 = STAT_CLI_PRINT; |
| 2107 | return 1; |
| 2108 | } |
| 2109 | |
| 2110 | /* Convert and check integer to pointer. */ |
| 2111 | ref = (struct pat_ref_elt *)(long)conv; |
| 2112 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2113 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2114 | appctx->st0 = STAT_CLI_PRINT; |
| 2115 | return 1; |
| 2116 | } |
| 2117 | |
| 2118 | /* Try to delete the entry. */ |
| 2119 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2120 | /* The entry is not found, send message. */ |
| 2121 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2122 | appctx->st0 = STAT_CLI_PRINT; |
| 2123 | return 1; |
| 2124 | } |
| 2125 | } |
| 2126 | else { |
| 2127 | /* Else, use the entry identifier as pattern |
| 2128 | * string and try to delete the entry. |
| 2129 | */ |
| 2130 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2131 | /* The entry is not found, send message. */ |
| 2132 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2133 | appctx->st0 = STAT_CLI_PRINT; |
| 2134 | return 1; |
| 2135 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2136 | } |
| 2137 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2138 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2139 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2140 | return 1; |
| 2141 | } |
| 2142 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2143 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2144 | appctx->st0 = STAT_CLI_PRINT; |
| 2145 | return 1; |
| 2146 | } |
| 2147 | } |
| 2148 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2149 | if (strcmp(args[1], "map") == 0 || |
| 2150 | strcmp(args[1], "acl") == 0) { |
| 2151 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2152 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2153 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2154 | /* Set flags. */ |
| 2155 | if (args[1][0] == 'm') |
| 2156 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2157 | else |
| 2158 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2159 | |
| 2160 | /* If the keywork is "map", we expect three parameters, if it |
| 2161 | * is "acl", we expect only two parameters |
| 2162 | */ |
| 2163 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2164 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2165 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2166 | appctx->st0 = STAT_CLI_PRINT; |
| 2167 | return 1; |
| 2168 | } |
| 2169 | } |
| 2170 | else { |
| 2171 | if (!*args[2] || !*args[3]) { |
| 2172 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2173 | appctx->st0 = STAT_CLI_PRINT; |
| 2174 | return 1; |
| 2175 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2176 | } |
| 2177 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2178 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2179 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2180 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2181 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2182 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2183 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2184 | 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] | 2185 | appctx->st0 = STAT_CLI_PRINT; |
| 2186 | return 1; |
| 2187 | } |
| 2188 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2189 | /* The command "add acl" is prohibited if the reference |
| 2190 | * use samples. |
| 2191 | */ |
| 2192 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2193 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2194 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2195 | "You must use the command 'add map' to add values.\n"; |
| 2196 | appctx->st0 = STAT_CLI_PRINT; |
| 2197 | return 1; |
| 2198 | } |
| 2199 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2200 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2201 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2202 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2203 | 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] | 2204 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2205 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2206 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2207 | if (err) |
| 2208 | memprintf(&err, "%s.\n", err); |
| 2209 | appctx->ctx.cli.err = err; |
| 2210 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2211 | return 1; |
| 2212 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2213 | |
| 2214 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2215 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2216 | return 1; |
| 2217 | } |
| 2218 | else { /* unknown "del" parameter */ |
| 2219 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2220 | appctx->st0 = STAT_CLI_PRINT; |
| 2221 | return 1; |
| 2222 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2223 | } |
| 2224 | 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] | 2225 | return 0; |
| 2226 | } |
| 2227 | return 1; |
| 2228 | } |
| 2229 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2230 | /* 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] | 2231 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2232 | * state machine handling requests and various responses. We read a request, |
| 2233 | * 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] | 2234 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2235 | * 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] | 2236 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2237 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2238 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2239 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2240 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2241 | struct channel *req = si_oc(si); |
| 2242 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2243 | int reql; |
| 2244 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2245 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2246 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2247 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2248 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2249 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2250 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2251 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2252 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2253 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2254 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2255 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2256 | /* Let's close for real now. We just close the request |
| 2257 | * side, the conditions below will complete if needed. |
| 2258 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2259 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2260 | break; |
| 2261 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2262 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2263 | /* ensure we have some output room left in the event we |
| 2264 | * would want to return some info right after parsing. |
| 2265 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2266 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2267 | si_ic(si)->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2268 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2269 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2270 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2271 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2272 | if (reql <= 0) { /* closed or EOL not found */ |
| 2273 | if (reql == 0) |
| 2274 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2275 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2276 | continue; |
| 2277 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2278 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2279 | /* seek for a possible semi-colon. If we find one, we |
| 2280 | * replace it with an LF and skip only this part. |
| 2281 | */ |
| 2282 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2283 | if (trash.str[len] == ';') { |
| 2284 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2285 | reql = len + 1; |
| 2286 | break; |
| 2287 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2288 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2289 | /* now it is time to check that we have a full line, |
| 2290 | * remove the trailing \n and possibly \r, then cut the |
| 2291 | * line. |
| 2292 | */ |
| 2293 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2294 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2295 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2296 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2297 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2298 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2299 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2300 | len--; |
| 2301 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2302 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2303 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2304 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2305 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2306 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2307 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2308 | continue; |
| 2309 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2310 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2311 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2312 | else if (strcmp(trash.str, "help") == 0 || |
| 2313 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2314 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2315 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2316 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2317 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2318 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2319 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2320 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2321 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2322 | /* if prompt is disabled, print help on empty lines, |
| 2323 | * so that the user at least knows how to enable |
| 2324 | * prompt and find help. |
| 2325 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2326 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2327 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2331 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2332 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2333 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2334 | 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] | 2335 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 2336 | cli_release_handler(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2337 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2338 | continue; |
| 2339 | } |
| 2340 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2341 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2342 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2343 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2344 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2345 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2346 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2347 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2348 | free(appctx->ctx.cli.err); |
| 2349 | appctx->st0 = STAT_CLI_PROMPT; |
| 2350 | } |
| 2351 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2352 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2353 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2354 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2355 | break; |
| 2356 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2357 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2358 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2359 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2360 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2361 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2362 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2363 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2364 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2365 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2366 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2367 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2368 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2369 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2370 | if (stats_table_request(si, appctx->st0)) |
| 2371 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2372 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2373 | case STAT_CLI_O_PATS: |
| 2374 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2375 | appctx->st0 = STAT_CLI_PROMPT; |
| 2376 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2377 | case STAT_CLI_O_PAT: |
| 2378 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2379 | appctx->st0 = STAT_CLI_PROMPT; |
| 2380 | break; |
| 2381 | case STAT_CLI_O_MLOOK: |
| 2382 | if (stats_map_lookup(si)) |
| 2383 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2384 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2385 | case STAT_CLI_O_POOLS: |
| 2386 | if (stats_dump_pools_to_buffer(si)) |
| 2387 | appctx->st0 = STAT_CLI_PROMPT; |
| 2388 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2389 | default: /* abnormal state */ |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 2390 | cli_release_handler(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2391 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2392 | break; |
| 2393 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2394 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2395 | /* 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] | 2396 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2397 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2398 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2399 | } |
| 2400 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2401 | /* 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] | 2402 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2403 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2404 | |
| 2405 | /* Now we close the output if one of the writers did so, |
| 2406 | * or if we're not in interactive mode and the request |
| 2407 | * buffer is empty. This still allows pipelined requests |
| 2408 | * to be sent in non-interactive mode. |
| 2409 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2410 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2411 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2412 | continue; |
| 2413 | } |
| 2414 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2415 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2416 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2417 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2418 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2419 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2420 | 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] | 2421 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2422 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2423 | /* 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] | 2424 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2425 | * we forward the close to the request side so that it flows upstream to |
| 2426 | * the client. |
| 2427 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2428 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2429 | } |
| 2430 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2431 | 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] | 2432 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2433 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2434 | /* We have no more processing to do, and nothing more to send, and |
| 2435 | * the client side has closed. So we'll forward this state downstream |
| 2436 | * on the response buffer. |
| 2437 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2438 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2439 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2443 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2444 | |
| 2445 | /* we don't want to expire timeouts while we're processing requests */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2446 | si_ic(si)->rex = TICK_ETERNITY; |
| 2447 | si_oc(si)->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2448 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2449 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2450 | 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] | 2451 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2452 | 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] | 2453 | |
| 2454 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2455 | /* check that we have released everything then unregister */ |
| 2456 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2457 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2458 | } |
| 2459 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2460 | /* This function dumps information onto the stream interface's read buffer. |
| 2461 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2462 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2463 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2464 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2465 | { |
| 2466 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2467 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2468 | #ifdef USE_OPENSSL |
| 2469 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2470 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2471 | int ssl_reuse = 0; |
| 2472 | |
| 2473 | if (ssl_key_rate < ssl_sess_rate) { |
| 2474 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2475 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2476 | } |
| 2477 | #endif |
| 2478 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2479 | chunk_printf(&trash, |
| 2480 | "Name: " PRODUCT_NAME "\n" |
| 2481 | "Version: " HAPROXY_VERSION "\n" |
| 2482 | "Release_date: " HAPROXY_DATE "\n" |
| 2483 | "Nbproc: %d\n" |
| 2484 | "Process_num: %d\n" |
| 2485 | "Pid: %d\n" |
| 2486 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2487 | "Uptime_sec: %d\n" |
| 2488 | "Memmax_MB: %d\n" |
| 2489 | "Ulimit-n: %d\n" |
| 2490 | "Maxsock: %d\n" |
| 2491 | "Maxconn: %d\n" |
| 2492 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2493 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2494 | "CumConns: %d\n" |
Warren Turkal | b197d7f | 2015-01-27 15:04:16 -0800 | [diff] [blame] | 2495 | "CumReq: %u\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2496 | #ifdef USE_OPENSSL |
| 2497 | "MaxSslConns: %d\n" |
| 2498 | "CurrSslConns: %d\n" |
| 2499 | "CumSslConns: %d\n" |
| 2500 | #endif |
| 2501 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2502 | "PipesUsed: %d\n" |
| 2503 | "PipesFree: %d\n" |
| 2504 | "ConnRate: %d\n" |
| 2505 | "ConnRateLimit: %d\n" |
| 2506 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2507 | "SessRate: %d\n" |
| 2508 | "SessRateLimit: %d\n" |
| 2509 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2510 | #ifdef USE_OPENSSL |
| 2511 | "SslRate: %d\n" |
| 2512 | "SslRateLimit: %d\n" |
| 2513 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2514 | "SslFrontendKeyRate: %d\n" |
| 2515 | "SslFrontendMaxKeyRate: %d\n" |
| 2516 | "SslFrontendSessionReuse_pct: %d\n" |
| 2517 | "SslBackendKeyRate: %d\n" |
| 2518 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2519 | "SslCacheLookups: %u\n" |
| 2520 | "SslCacheMisses: %u\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2521 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2522 | "CompressBpsIn: %u\n" |
| 2523 | "CompressBpsOut: %u\n" |
| 2524 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2525 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2526 | "ZlibMemUsage: %ld\n" |
| 2527 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2528 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2529 | "Tasks: %d\n" |
| 2530 | "Run_queue: %d\n" |
| 2531 | "Idle_pct: %d\n" |
| 2532 | "node: %s\n" |
| 2533 | "description: %s\n" |
| 2534 | "", |
| 2535 | global.nbproc, |
| 2536 | relative_pid, |
| 2537 | pid, |
| 2538 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2539 | up, |
| 2540 | global.rlimit_memmax, |
| 2541 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2542 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2543 | actconn, totalconn, global.req_count, |
| 2544 | #ifdef USE_OPENSSL |
| 2545 | global.maxsslconn, sslconns, totalsslconns, |
| 2546 | #endif |
| 2547 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2548 | 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] | 2549 | 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] | 2550 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2551 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2552 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2553 | ssl_reuse, |
| 2554 | 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] | 2555 | global.shctx_lookups, global.shctx_misses, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2556 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2557 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2558 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2559 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2560 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2561 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2562 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2563 | global.node, global.desc ? global.desc : "" |
| 2564 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2565 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2566 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2567 | return 0; |
| 2568 | |
| 2569 | return 1; |
| 2570 | } |
| 2571 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2572 | /* This function dumps memory usage information onto the stream interface's |
| 2573 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2574 | * completion. No state is used. |
| 2575 | */ |
| 2576 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2577 | { |
| 2578 | dump_pools_to_trash(); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2579 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2580 | return 0; |
| 2581 | return 1; |
| 2582 | } |
| 2583 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2584 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2585 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2586 | * 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] | 2587 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2588 | 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] | 2589 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2590 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2591 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2592 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2593 | if (!(px->cap & PR_CAP_FE)) |
| 2594 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2595 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2596 | 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] | 2597 | return 0; |
| 2598 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2599 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2600 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2601 | /* name, queue */ |
| 2602 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2603 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2604 | 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] | 2605 | /* Column sub-heading for Enable or Disable server */ |
| 2606 | chunk_appendf(&trash, "<td></td>"); |
| 2607 | } |
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 | chunk_appendf(&trash, |
| 2610 | "<td class=ac>" |
| 2611 | "<a name=\"%s/Frontend\"></a>" |
| 2612 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2613 | "<td colspan=3></td>" |
| 2614 | "", |
| 2615 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2616 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2617 | chunk_appendf(&trash, |
| 2618 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2619 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2620 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2621 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2622 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2623 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2624 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2625 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2626 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2627 | if (px->mode == PR_MODE_HTTP) |
| 2628 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2629 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2630 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2631 | |
| 2632 | chunk_appendf(&trash, |
| 2633 | "</table></div></u></td>" |
| 2634 | /* sessions rate : max */ |
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>Max connection rate:</th><td>%s/s</td></tr>" |
| 2637 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2638 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2639 | U2H(px->fe_counters.sps_max), |
| 2640 | U2H(px->fe_counters.cps_max), |
| 2641 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2642 | |
| 2643 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2644 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2645 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2646 | U2H(px->fe_counters.p.http.rps_max)); |
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 : limit */ |
| 2651 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2652 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2653 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2654 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2655 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2656 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2657 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2658 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2659 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2660 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2661 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2662 | U2H(px->fe_counters.cum_sess), |
| 2663 | U2H(px->fe_counters.cum_conn), |
| 2664 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2665 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2666 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2667 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2668 | chunk_appendf(&trash, |
| 2669 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2670 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2671 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2672 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2673 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2674 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2675 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2676 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2677 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2678 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2679 | U2H(px->fe_counters.p.http.cum_req), |
| 2680 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2681 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2682 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2683 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2684 | (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] | 2685 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2686 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2687 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2688 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2689 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2690 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2691 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2692 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2693 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2694 | /* sessions: lbtot, lastsess */ |
| 2695 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2696 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2697 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2698 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2699 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2700 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2701 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2702 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2703 | "<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] | 2704 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2705 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2706 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2707 | px->fe_counters.comp_in ? |
| 2708 | (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] | 2709 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2710 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2711 | chunk_appendf(&trash, |
| 2712 | /* denied: req, resp */ |
| 2713 | "<td>%s</td><td>%s</td>" |
| 2714 | /* errors : request, connect, response */ |
| 2715 | "<td>%s</td><td></td><td></td>" |
| 2716 | /* warnings: retries, redispatches */ |
| 2717 | "<td></td><td></td>" |
| 2718 | /* server status : reflect frontend status */ |
| 2719 | "<td class=ac>%s</td>" |
| 2720 | /* rest of server: nothing */ |
| 2721 | "<td class=ac colspan=8></td></tr>" |
| 2722 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2723 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2724 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2725 | px->state == PR_STREADY ? "OPEN" : |
| 2726 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2727 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2728 | else { /* CSV mode */ |
| 2729 | chunk_appendf(&trash, |
| 2730 | /* pxid, name, queue cur, queue max, */ |
| 2731 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2732 | /* sessions : current, max, limit, total */ |
| 2733 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2734 | /* bytes : in, out */ |
| 2735 | "%lld,%lld," |
| 2736 | /* denied: req, resp */ |
| 2737 | "%lld,%lld," |
| 2738 | /* errors : request, connect, response */ |
| 2739 | "%lld,,," |
| 2740 | /* warnings: retries, redispatches */ |
| 2741 | ",," |
| 2742 | /* server status : reflect frontend status */ |
| 2743 | "%s," |
| 2744 | /* rest of server: nothing */ |
| 2745 | ",,,,,,,," |
| 2746 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2747 | "%d,%d,0,,,,%d," |
| 2748 | /* rate, rate_lim, rate_max */ |
| 2749 | "%u,%u,%u," |
| 2750 | /* check_status, check_code, check_duration */ |
| 2751 | ",,,", |
| 2752 | px->id, |
| 2753 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2754 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2755 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2756 | px->fe_counters.failed_req, |
| 2757 | px->state == PR_STREADY ? "OPEN" : |
| 2758 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2759 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2760 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2761 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2762 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2763 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2764 | if (px->mode == PR_MODE_HTTP) { |
| 2765 | for (i=1; i<6; i++) |
| 2766 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2767 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2768 | } |
| 2769 | else |
| 2770 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2771 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2772 | /* failed health analyses */ |
| 2773 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2774 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2775 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2776 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2777 | read_freq_ctr(&px->fe_req_per_sec), |
| 2778 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2779 | |
| 2780 | /* errors: cli_aborts, srv_aborts */ |
| 2781 | chunk_appendf(&trash, ",,"); |
| 2782 | |
| 2783 | /* compression: in, out, bypassed */ |
| 2784 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2785 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2786 | |
| 2787 | /* compression: comp_rsp */ |
| 2788 | chunk_appendf(&trash, "%lld,", |
| 2789 | px->fe_counters.p.http.comp_rsp); |
| 2790 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2791 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2792 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2793 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2794 | /* finish with EOL */ |
| 2795 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2796 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2797 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2798 | } |
| 2799 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2800 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2801 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2802 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2803 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2804 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2805 | 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] | 2806 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2807 | struct appctx *appctx = __objt_appctx(si->end); |
| 2808 | |
| 2809 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2810 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2811 | 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] | 2812 | /* Column sub-heading for Enable or Disable server */ |
| 2813 | chunk_appendf(&trash, "<td></td>"); |
| 2814 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2815 | chunk_appendf(&trash, |
| 2816 | /* frontend name, listener name */ |
| 2817 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2818 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2819 | "", |
| 2820 | px->id, l->name, |
| 2821 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2822 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2823 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2824 | if (flags & ST_SHLGNDS) { |
| 2825 | char str[INET6_ADDRSTRLEN]; |
| 2826 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2827 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2828 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2829 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2830 | port = get_host_port(&l->addr); |
| 2831 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2832 | case AF_INET: |
| 2833 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2834 | break; |
| 2835 | case AF_INET6: |
| 2836 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2837 | break; |
| 2838 | case AF_UNIX: |
| 2839 | chunk_appendf(&trash, "unix, "); |
| 2840 | break; |
| 2841 | case -1: |
| 2842 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2843 | break; |
| 2844 | } |
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 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2847 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2848 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2849 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2850 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2851 | /* queue */ |
| 2852 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2853 | /* sessions rate: current, max, limit */ |
| 2854 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2855 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2856 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2857 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2858 | /* bytes: in, out */ |
| 2859 | "<td>%s</td><td>%s</td>" |
| 2860 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2861 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2862 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2863 | 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] | 2864 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2865 | chunk_appendf(&trash, |
| 2866 | /* denied: req, resp */ |
| 2867 | "<td>%s</td><td>%s</td>" |
| 2868 | /* errors: request, connect, response */ |
| 2869 | "<td>%s</td><td></td><td></td>" |
| 2870 | /* warnings: retries, redispatches */ |
| 2871 | "<td></td><td></td>" |
| 2872 | /* server status: reflect listener status */ |
| 2873 | "<td class=ac>%s</td>" |
| 2874 | /* rest of server: nothing */ |
| 2875 | "<td class=ac colspan=8></td></tr>" |
| 2876 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2877 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2878 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2879 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2880 | } |
| 2881 | else { /* CSV mode */ |
| 2882 | chunk_appendf(&trash, |
| 2883 | /* pxid, name, queue cur, queue max, */ |
| 2884 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2885 | /* sessions: current, max, limit, total */ |
| 2886 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2887 | /* bytes: in, out */ |
| 2888 | "%lld,%lld," |
| 2889 | /* denied: req, resp */ |
| 2890 | "%lld,%lld," |
| 2891 | /* errors: request, connect, response */ |
| 2892 | "%lld,,," |
| 2893 | /* warnings: retries, redispatches */ |
| 2894 | ",," |
| 2895 | /* server status: reflect listener status */ |
| 2896 | "%s," |
| 2897 | /* rest of server: nothing */ |
| 2898 | ",,,,,,,," |
| 2899 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2900 | "%d,%d,%d,,,,%d," |
| 2901 | /* rate, rate_lim, rate_max */ |
| 2902 | ",,," |
| 2903 | /* check_status, check_code, check_duration */ |
| 2904 | ",,," |
| 2905 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2906 | ",,,,,," |
| 2907 | /* failed health analyses */ |
| 2908 | "," |
| 2909 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2910 | ",,," |
| 2911 | /* errors: cli_aborts, srv_aborts */ |
| 2912 | ",," |
| 2913 | /* compression: in, out, bypassed, comp_rsp */ |
| 2914 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2915 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2916 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2917 | "\n", |
| 2918 | px->id, l->name, |
| 2919 | l->nbconn, l->counters->conn_max, |
| 2920 | l->maxconn, l->counters->cum_conn, |
| 2921 | l->counters->bytes_in, l->counters->bytes_out, |
| 2922 | l->counters->denied_req, l->counters->denied_resp, |
| 2923 | l->counters->failed_req, |
| 2924 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2925 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2926 | } |
| 2927 | return 1; |
| 2928 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2929 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2930 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2931 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2932 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2933 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2934 | * following values : 0=DOWN, 1=DOWN(agent) 2=going up, 3=going down, 4=UP, 5,6=NOLB, |
| 2935 | * 7,8=DRAIN, 9=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2936 | */ |
| 2937 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2938 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2939 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2940 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2941 | char str[INET6_ADDRSTRLEN]; |
| 2942 | struct chunk src; |
| 2943 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2944 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2945 | /* we have "via" which is the tracked server as described in the configuration, |
| 2946 | * and "ref" which is the checked server and the end of the chain. |
| 2947 | */ |
| 2948 | via = sv->track ? sv->track : sv; |
| 2949 | ref = via; |
| 2950 | while (ref->track) |
| 2951 | ref = ref->track; |
| 2952 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2953 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2954 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2955 | "DOWN", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2956 | "DOWN (agent)", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2957 | "DN %d/%d ↑", |
| 2958 | "UP %d/%d ↓", |
| 2959 | "UP", |
| 2960 | "NOLB %d/%d ↓", |
| 2961 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2962 | "DRAIN %d/%d ↓", |
| 2963 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2964 | "<i>no check</i>" |
| 2965 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2966 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 2967 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2968 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2969 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2970 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2971 | "<tr class=\"%s%d\">", |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 2972 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2973 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2974 | 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] | 2975 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2976 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2977 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2978 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2979 | chunk_appendf(&trash, |
| 2980 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2981 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2982 | "", |
| 2983 | px->id, sv->id, |
| 2984 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2985 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2986 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2987 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2988 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2989 | |
| 2990 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2991 | case AF_INET: |
| 2992 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2993 | break; |
| 2994 | case AF_INET6: |
| 2995 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2996 | break; |
| 2997 | case AF_UNIX: |
| 2998 | chunk_appendf(&trash, "unix, "); |
| 2999 | break; |
| 3000 | case -1: |
| 3001 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3002 | break; |
| 3003 | default: /* address family not supported */ |
| 3004 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3005 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3006 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3007 | /* id */ |
| 3008 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3009 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3010 | /* cookie */ |
| 3011 | if (sv->cookie) { |
| 3012 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3013 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3014 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3015 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3016 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3017 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3018 | } |
| 3019 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3020 | chunk_appendf(&trash, "</div>"); |
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 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3024 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3025 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3026 | /* sessions rate : current, max, limit */ |
| 3027 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3028 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3029 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3030 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3031 | 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] | 3032 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3033 | |
| 3034 | chunk_appendf(&trash, |
| 3035 | /* sessions: current, max, limit, total */ |
| 3036 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3037 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3038 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3039 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3040 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3041 | U2H(sv->counters.cum_sess), |
| 3042 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3043 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3044 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3045 | if (px->mode == PR_MODE_HTTP) { |
| 3046 | unsigned long long tot; |
| 3047 | for (tot = i = 0; i < 6; i++) |
| 3048 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3049 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3050 | chunk_appendf(&trash, |
| 3051 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3052 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3053 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3054 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3055 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3056 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3057 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3058 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3059 | U2H(tot), |
| 3060 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3061 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3062 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3063 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3064 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3065 | 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] | 3066 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3067 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3068 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3069 | 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))); |
| 3070 | 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))); |
| 3071 | if (px->mode == PR_MODE_HTTP) |
| 3072 | 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))); |
| 3073 | 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))); |
| 3074 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3075 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3076 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3077 | /* sessions: lbtot, last */ |
| 3078 | "<td>%s</td><td>%s</td>", |
| 3079 | U2H(sv->counters.cum_lbconn), |
| 3080 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3081 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3082 | chunk_appendf(&trash, |
| 3083 | /* bytes : in, out */ |
| 3084 | "<td>%s</td><td>%s</td>" |
| 3085 | /* denied: req, resp */ |
| 3086 | "<td></td><td>%s</td>" |
| 3087 | /* errors : request, connect */ |
| 3088 | "<td></td><td>%s</td>" |
| 3089 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3090 | "<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] | 3091 | /* warnings: retries, redispatches */ |
| 3092 | "<td>%lld</td><td>%lld</td>" |
| 3093 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3094 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3095 | U2H(sv->counters.failed_secu), |
| 3096 | U2H(sv->counters.failed_conns), |
| 3097 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3098 | sv->counters.cli_aborts, |
| 3099 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3100 | sv->counters.retries, sv->counters.redispatches); |
| 3101 | |
| 3102 | /* status, lest check */ |
| 3103 | chunk_appendf(&trash, "<td class=ac>"); |
| 3104 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3105 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3106 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3107 | chunk_appendf(&trash, "MAINT"); |
| 3108 | } |
Simon Horman | 0766e44 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3109 | 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] | 3110 | 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] | 3111 | /* DOWN (agent) */ |
| 3112 | 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] | 3113 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3114 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3115 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3116 | chunk_appendf(&trash, |
| 3117 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3118 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3119 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3120 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3121 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3122 | if ((sv->state == SRV_ST_STOPPED) && |
| 3123 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3124 | chunk_appendf(&trash, |
| 3125 | "</td><td class=ac><u> %s%s", |
| 3126 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3127 | get_check_status_info(sv->agent.status)); |
| 3128 | |
| 3129 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3130 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3131 | |
| 3132 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3133 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3134 | |
| 3135 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3136 | get_check_status_description(sv->agent.status)); |
| 3137 | if (*sv->agent.desc) { |
| 3138 | chunk_appendf(&trash, ": "); |
| 3139 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3140 | chunk_htmlencode(&trash, &src); |
| 3141 | } |
| 3142 | chunk_appendf(&trash, "</div></u>"); |
| 3143 | } |
| 3144 | 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] | 3145 | chunk_appendf(&trash, |
| 3146 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3147 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3148 | get_check_status_info(sv->check.status)); |
| 3149 | |
| 3150 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3151 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3152 | |
| 3153 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3154 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3155 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3156 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3157 | get_check_status_description(sv->check.status)); |
| 3158 | if (*sv->check.desc) { |
| 3159 | chunk_appendf(&trash, ": "); |
| 3160 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3161 | chunk_htmlencode(&trash, &src); |
| 3162 | } |
| 3163 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3164 | } |
| 3165 | else |
| 3166 | chunk_appendf(&trash, "</td><td>"); |
| 3167 | |
| 3168 | chunk_appendf(&trash, |
| 3169 | /* weight */ |
| 3170 | "</td><td class=ac>%d</td>" |
| 3171 | /* act, bck */ |
| 3172 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3173 | "", |
| 3174 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3175 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3176 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3177 | |
| 3178 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3179 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3180 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3181 | |
| 3182 | if (ref->observe) |
| 3183 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3184 | |
| 3185 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3186 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3187 | "<td>%lld</td><td>%s</td>" |
| 3188 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3189 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3190 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3191 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3192 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3193 | /* tracking a server */ |
| 3194 | chunk_appendf(&trash, |
| 3195 | "<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] | 3196 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3197 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3198 | else |
| 3199 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3200 | |
| 3201 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3202 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3203 | 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] | 3204 | else |
| 3205 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3206 | } |
| 3207 | else { /* CSV mode */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3208 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3209 | "DOWN,", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3210 | "DOWN (agent),", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3211 | "DOWN %d/%d,", |
| 3212 | "UP %d/%d,", |
| 3213 | "UP,", |
| 3214 | "NOLB %d/%d,", |
| 3215 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3216 | "DRAIN %d/%d,", |
| 3217 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3218 | "no check," |
| 3219 | }; |
| 3220 | |
| 3221 | chunk_appendf(&trash, |
| 3222 | /* pxid, name */ |
| 3223 | "%s,%s," |
| 3224 | /* queue : current, max */ |
| 3225 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3226 | /* sessions : current, max, limit, total */ |
| 3227 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3228 | /* bytes : in, out */ |
| 3229 | "%lld,%lld," |
| 3230 | /* denied: req, resp */ |
| 3231 | ",%lld," |
| 3232 | /* errors : request, connect, response */ |
| 3233 | ",%lld,%lld," |
| 3234 | /* warnings: retries, redispatches */ |
| 3235 | "%lld,%lld," |
| 3236 | "", |
| 3237 | px->id, sv->id, |
| 3238 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3239 | 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] | 3240 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3241 | sv->counters.failed_secu, |
| 3242 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3243 | sv->counters.retries, sv->counters.redispatches); |
| 3244 | |
| 3245 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3246 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3247 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3248 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3249 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3250 | else |
| 3251 | chunk_appendf(&trash, |
| 3252 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3253 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3254 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3255 | |
| 3256 | chunk_appendf(&trash, |
| 3257 | /* weight, active, backup */ |
| 3258 | "%d,%d,%d," |
| 3259 | "", |
| 3260 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3261 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3262 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3263 | |
| 3264 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3265 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3266 | chunk_appendf(&trash, |
| 3267 | "%lld,%lld,%d,%d,", |
| 3268 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3269 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3270 | else |
| 3271 | chunk_appendf(&trash, ",,,,"); |
| 3272 | |
| 3273 | /* queue limit, pid, iid, sid, */ |
| 3274 | chunk_appendf(&trash, |
| 3275 | "%s," |
| 3276 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3277 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3278 | relative_pid, px->uuid, sv->puid); |
| 3279 | |
| 3280 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3281 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3282 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3283 | |
| 3284 | /* sessions: lbtot */ |
| 3285 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3286 | |
| 3287 | /* tracked */ |
| 3288 | if (sv->track) |
| 3289 | chunk_appendf(&trash, "%s/%s,", |
| 3290 | sv->track->proxy->id, sv->track->id); |
| 3291 | else |
| 3292 | chunk_appendf(&trash, ","); |
| 3293 | |
| 3294 | /* type */ |
| 3295 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3296 | |
| 3297 | /* rate */ |
| 3298 | chunk_appendf(&trash, "%u,,%u,", |
| 3299 | read_freq_ctr(&sv->sess_per_sec), |
| 3300 | sv->counters.sps_max); |
| 3301 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3302 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3303 | /* check_status */ |
| 3304 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3305 | |
| 3306 | /* check_code */ |
| 3307 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3308 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3309 | else |
| 3310 | chunk_appendf(&trash, ","); |
| 3311 | |
| 3312 | /* check_duration */ |
| 3313 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3314 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3315 | else |
| 3316 | chunk_appendf(&trash, ","); |
| 3317 | |
| 3318 | } |
| 3319 | else |
| 3320 | chunk_appendf(&trash, ",,,"); |
| 3321 | |
| 3322 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3323 | if (px->mode == PR_MODE_HTTP) { |
| 3324 | for (i=1; i<6; i++) |
| 3325 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3326 | |
| 3327 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3328 | } |
| 3329 | else |
| 3330 | chunk_appendf(&trash, ",,,,,,"); |
| 3331 | |
| 3332 | /* failed health analyses */ |
| 3333 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3334 | |
| 3335 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3336 | chunk_appendf(&trash, ",,,"); |
| 3337 | |
| 3338 | /* errors: cli_aborts, srv_aborts */ |
| 3339 | chunk_appendf(&trash, "%lld,%lld,", |
| 3340 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3341 | |
| 3342 | /* compression: in, out, bypassed, comp_rsp */ |
| 3343 | chunk_appendf(&trash, ",,,,"); |
| 3344 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3345 | /* lastsess */ |
| 3346 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3347 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3348 | /* capture of last check and agent statuses */ |
| 3349 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->check.desc) : ""); |
| 3350 | chunk_appendf(&trash, "%s,", ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->agent.desc) : ""); |
| 3351 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3352 | /* qtime, ctime, rtime, ttime, */ |
| 3353 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3354 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3355 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3356 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3357 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3358 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3359 | /* finish with EOL */ |
| 3360 | chunk_appendf(&trash, "\n"); |
| 3361 | } |
| 3362 | return 1; |
| 3363 | } |
| 3364 | |
| 3365 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3366 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3367 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3368 | */ |
| 3369 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3370 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3371 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3372 | struct chunk src; |
| 3373 | int i; |
| 3374 | |
| 3375 | if (!(px->cap & PR_CAP_BE)) |
| 3376 | return 0; |
| 3377 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3378 | 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] | 3379 | return 0; |
| 3380 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3381 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3382 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3383 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3384 | /* Column sub-heading for Enable or Disable server */ |
| 3385 | chunk_appendf(&trash, "<td></td>"); |
| 3386 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3387 | chunk_appendf(&trash, |
| 3388 | "<td class=ac>" |
| 3389 | /* name */ |
| 3390 | "%s<a name=\"%s/Backend\"></a>" |
| 3391 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3392 | "", |
| 3393 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3394 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3395 | |
| 3396 | if (flags & ST_SHLGNDS) { |
| 3397 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3398 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3399 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3400 | |
| 3401 | /* cookie */ |
| 3402 | if (px->cookie_name) { |
| 3403 | chunk_appendf(&trash, ", cookie: '"); |
| 3404 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3405 | chunk_htmlencode(&trash, &src); |
| 3406 | chunk_appendf(&trash, "'"); |
| 3407 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3408 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3412 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3413 | /* queue : current, max */ |
| 3414 | "<td>%s</td><td>%s</td><td></td>" |
| 3415 | /* sessions rate : current, max, limit */ |
| 3416 | "<td>%s</td><td>%s</td><td></td>" |
| 3417 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3418 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3419 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3420 | 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] | 3421 | |
| 3422 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3423 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3424 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3425 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3426 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3427 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3428 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3429 | U2H(px->be_counters.cum_conn), |
| 3430 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3431 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3432 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3433 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3434 | chunk_appendf(&trash, |
| 3435 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3436 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3437 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3438 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3439 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3440 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3441 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3442 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3443 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3444 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3445 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3446 | U2H(px->be_counters.p.http.cum_req), |
| 3447 | U2H(px->be_counters.p.http.rsp[1]), |
| 3448 | U2H(px->be_counters.p.http.rsp[2]), |
| 3449 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3450 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3451 | (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] | 3452 | U2H(px->be_counters.p.http.rsp[3]), |
| 3453 | U2H(px->be_counters.p.http.rsp[4]), |
| 3454 | U2H(px->be_counters.p.http.rsp[5]), |
| 3455 | U2H(px->be_counters.p.http.rsp[0]), |
| 3456 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3457 | } |
| 3458 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3459 | 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))); |
| 3460 | 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))); |
| 3461 | if (px->mode == PR_MODE_HTTP) |
| 3462 | 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))); |
| 3463 | 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))); |
| 3464 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3465 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3466 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3467 | /* sessions: lbtot, last */ |
| 3468 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3469 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3470 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3471 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3472 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3473 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3474 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3475 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3476 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3477 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3478 | "<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] | 3479 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3480 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3481 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3482 | px->be_counters.comp_in ? |
| 3483 | (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] | 3484 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3485 | |
| 3486 | chunk_appendf(&trash, |
| 3487 | /* denied: req, resp */ |
| 3488 | "<td>%s</td><td>%s</td>" |
| 3489 | /* errors : request, connect */ |
| 3490 | "<td></td><td>%s</td>" |
| 3491 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3492 | "<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] | 3493 | /* warnings: retries, redispatches */ |
| 3494 | "<td>%lld</td><td>%lld</td>" |
| 3495 | /* backend status: reflect backend status (up/down): we display UP |
| 3496 | * if the backend has known working servers or if it has no server at |
| 3497 | * all (eg: for stats). Then we display the total weight, number of |
| 3498 | * active and backups. */ |
| 3499 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3500 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3501 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3502 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3503 | U2H(px->be_counters.failed_conns), |
| 3504 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3505 | px->be_counters.cli_aborts, |
| 3506 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3507 | px->be_counters.retries, px->be_counters.redispatches, |
| 3508 | human_time(now.tv_sec - px->last_change, 1), |
| 3509 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3510 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3511 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3512 | px->srv_act, px->srv_bck); |
| 3513 | |
| 3514 | chunk_appendf(&trash, |
| 3515 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3516 | "<td class=ac> </td><td>%d</td>" |
| 3517 | "<td>%s</td>" |
| 3518 | "<td></td>" |
| 3519 | "</tr>", |
| 3520 | px->down_trans, |
| 3521 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3522 | } |
| 3523 | else { /* CSV mode */ |
| 3524 | chunk_appendf(&trash, |
| 3525 | /* pxid, name */ |
| 3526 | "%s,BACKEND," |
| 3527 | /* queue : current, max */ |
| 3528 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3529 | /* sessions : current, max, limit, total */ |
| 3530 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3531 | /* bytes : in, out */ |
| 3532 | "%lld,%lld," |
| 3533 | /* denied: req, resp */ |
| 3534 | "%lld,%lld," |
| 3535 | /* errors : request, connect, response */ |
| 3536 | ",%lld,%lld," |
| 3537 | /* warnings: retries, redispatches */ |
| 3538 | "%lld,%lld," |
| 3539 | /* backend status: reflect backend status (up/down): we display UP |
| 3540 | * if the backend has known working servers or if it has no server at |
| 3541 | * all (eg: for stats). Then we display the total weight, number of |
| 3542 | * active and backups. */ |
| 3543 | "%s," |
| 3544 | "%d,%d,%d," |
| 3545 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3546 | ",%d,%d,%d,," |
| 3547 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3548 | "%d,%d,0,,%lld,,%d," |
| 3549 | /* rate, rate_lim, rate_max, */ |
| 3550 | "%u,,%u," |
| 3551 | /* check_status, check_code, check_duration */ |
| 3552 | ",,,", |
| 3553 | px->id, |
| 3554 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3555 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3556 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3557 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3558 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3559 | px->be_counters.retries, px->be_counters.redispatches, |
| 3560 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3561 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3562 | px->srv_act, px->srv_bck, |
| 3563 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3564 | px->srv?be_downtime(px):0, |
| 3565 | relative_pid, px->uuid, |
| 3566 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3567 | read_freq_ctr(&px->be_sess_per_sec), |
| 3568 | px->be_counters.sps_max); |
| 3569 | |
| 3570 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3571 | if (px->mode == PR_MODE_HTTP) { |
| 3572 | for (i=1; i<6; i++) |
| 3573 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3574 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3575 | } |
| 3576 | else |
| 3577 | chunk_appendf(&trash, ",,,,,,"); |
| 3578 | |
| 3579 | /* failed health analyses */ |
| 3580 | chunk_appendf(&trash, ","); |
| 3581 | |
| 3582 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3583 | chunk_appendf(&trash, ",,,"); |
| 3584 | |
| 3585 | /* errors: cli_aborts, srv_aborts */ |
| 3586 | chunk_appendf(&trash, "%lld,%lld,", |
| 3587 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3588 | |
| 3589 | /* compression: in, out, bypassed */ |
| 3590 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3591 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3592 | |
| 3593 | /* compression: comp_rsp */ |
| 3594 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3595 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3596 | /* lastsess, last_chk, last_agt, */ |
| 3597 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3598 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3599 | /* qtime, ctime, rtime, ttime, */ |
| 3600 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3601 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 3602 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 3603 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 3604 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 3605 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3606 | /* finish with EOL */ |
| 3607 | chunk_appendf(&trash, "\n"); |
| 3608 | } |
| 3609 | return 1; |
| 3610 | } |
| 3611 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3612 | /* 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] | 3613 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3614 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3615 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3616 | 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] | 3617 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3618 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3619 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3620 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3621 | 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] | 3622 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3623 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3624 | /* 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] | 3625 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3626 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3627 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3628 | 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] | 3629 | 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] | 3630 | } |
| 3631 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3632 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 3633 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3634 | } |
| 3635 | |
| 3636 | /* print a new table */ |
| 3637 | chunk_appendf(&trash, |
| 3638 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3639 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3640 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3641 | |
| 3642 | chunk_appendf(&trash, |
| 3643 | "<a name=\"%s\"></a>%s" |
| 3644 | "<a class=px href=\"#%s\">%s</a>", |
| 3645 | px->id, |
| 3646 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3647 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3648 | |
| 3649 | if (uri->flags & ST_SHLGNDS) { |
| 3650 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3651 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3652 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3653 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3654 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3658 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3659 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3660 | "</tr>\n" |
| 3661 | "</table>\n" |
| 3662 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3663 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3664 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3665 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3666 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3667 | 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] | 3668 | /* Column heading for Enable or Disable server */ |
| 3669 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3670 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3671 | |
| 3672 | chunk_appendf(&trash, |
| 3673 | "<th rowspan=2></th>" |
| 3674 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3675 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3676 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3677 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3678 | "<th colspan=9>Server</th>" |
| 3679 | "</tr>\n" |
| 3680 | "<tr class=\"titre\">" |
| 3681 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3682 | "<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] | 3683 | "<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] | 3684 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3685 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3686 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3687 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3688 | "<th>Thrtle</th>\n" |
| 3689 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3690 | } |
| 3691 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3692 | /* 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] | 3693 | * 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] | 3694 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3695 | 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] | 3696 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3697 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3698 | chunk_appendf(&trash, "</table>"); |
| 3699 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3700 | 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] | 3701 | /* close the form used to enable/disable this proxy servers */ |
| 3702 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3703 | "Choose the action to perform on the checked servers : " |
| 3704 | "<select name=action>" |
| 3705 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 3706 | "<option value=\"ready\">Set state to READY</option>" |
| 3707 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 3708 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 3709 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3710 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3711 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3712 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3713 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3714 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3715 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3716 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3717 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3718 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3719 | "</select>" |
| 3720 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3721 | " <input type=\"submit\" value=\"Apply\">" |
| 3722 | "</form>", |
| 3723 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3727 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3728 | |
| 3729 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3730 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3731 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3732 | * buffer space, or non-zero if everything completed. This function is used |
| 3733 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3734 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3735 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3736 | 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] | 3737 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3738 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 3739 | struct session *s = si_sess(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 3740 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3741 | 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] | 3742 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3743 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3744 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3745 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3746 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3747 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3748 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3749 | if (uri && uri->scope) { |
| 3750 | /* we have a limited scope, we have to check the proxy name */ |
| 3751 | struct stat_scope *scope; |
| 3752 | int len; |
| 3753 | |
| 3754 | len = strlen(px->id); |
| 3755 | scope = uri->scope; |
| 3756 | |
| 3757 | while (scope) { |
| 3758 | /* match exact proxy name */ |
| 3759 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3760 | break; |
| 3761 | |
| 3762 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3763 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3764 | break; |
| 3765 | scope = scope->next; |
| 3766 | } |
| 3767 | |
| 3768 | /* proxy name not found : don't dump anything */ |
| 3769 | if (scope == NULL) |
| 3770 | return 1; |
| 3771 | } |
| 3772 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3773 | /* if the user has requested a limited output and the proxy |
| 3774 | * name does not match, skip it. |
| 3775 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3776 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3777 | 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] | 3778 | return 1; |
| 3779 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3780 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3781 | (appctx->ctx.stats.iid != -1) && |
| 3782 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3783 | return 1; |
| 3784 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3785 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3786 | /* fall through */ |
| 3787 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3788 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3789 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3790 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3791 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3792 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3793 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3794 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3795 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3796 | /* fall through */ |
| 3797 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3798 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3799 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3800 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3801 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3802 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3803 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3804 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3805 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3806 | /* fall through */ |
| 3807 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3808 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3809 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3810 | 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] | 3811 | if (buffer_almost_full(rep->buf)) { |
| 3812 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3813 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3814 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3815 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3816 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3817 | if (!l->counters) |
| 3818 | continue; |
| 3819 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3820 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3821 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3822 | break; |
| 3823 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3824 | 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] | 3825 | continue; |
| 3826 | } |
| 3827 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3828 | /* print the frontend */ |
| 3829 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3830 | if (bi_putchk(rep, &trash) == -1) |
| 3831 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3832 | } |
| 3833 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3834 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3835 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3836 | /* fall through */ |
| 3837 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3838 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3839 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3840 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3841 | int sv_state; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3842 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3843 | if (buffer_almost_full(rep->buf)) { |
| 3844 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3845 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3846 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3847 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3848 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3849 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3850 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3851 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3852 | break; |
| 3853 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3854 | 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] | 3855 | continue; |
| 3856 | } |
| 3857 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3858 | svs = sv; |
| 3859 | while (svs->track) |
| 3860 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3861 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3862 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 3863 | /* server is UP. The possibilities are : |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3864 | * - UP, draining, going down => state = 7 |
| 3865 | * - UP, going down => state = 3 |
| 3866 | * - UP, draining => state = 8 |
| 3867 | * - UP, checked => state = 4 |
| 3868 | * - UP, not checked nor tracked => state = 9 |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3869 | */ |
| 3870 | |
| 3871 | if ((svs->check.state & CHK_ST_ENABLED) && |
| 3872 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3873 | sv_state = 3; |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3874 | else |
| 3875 | sv_state = 4; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3876 | |
Willy Tarreau | efe2822 | 2014-05-21 17:13:13 +0200 | [diff] [blame] | 3877 | if (server_is_draining(sv)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3878 | sv_state += 4; |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3879 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3880 | if (sv_state == 4 && !(svs->check.state & CHK_ST_ENABLED)) |
| 3881 | sv_state = 9; /* unchecked UP */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3882 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3883 | else if (sv->state == SRV_ST_STOPPING) { |
| 3884 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 3885 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3886 | sv_state = 6; /* NOLB */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3887 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3888 | sv_state = 5; /* NOLB going down */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3889 | } |
| 3890 | else { /* stopped */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3891 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) |
| 3892 | sv_state = 1; /* DOWN (agent) */ |
| 3893 | else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3894 | sv_state = 0; /* DOWN */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3895 | else if ((svs->agent.state & CHK_ST_ENABLED) || (svs->check.state & CHK_ST_ENABLED)) |
| 3896 | sv_state = 2; /* going up */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3897 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3898 | sv_state = 0; /* DOWN, unchecked */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3899 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3900 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3901 | 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] | 3902 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3903 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3904 | continue; |
| 3905 | } |
| 3906 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3907 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3908 | if (bi_putchk(rep, &trash) == -1) |
| 3909 | return 0; |
| 3910 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3911 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3912 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3913 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3914 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3915 | case STAT_PX_ST_BE: |
| 3916 | /* print the backend */ |
| 3917 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3918 | if (bi_putchk(rep, &trash) == -1) |
| 3919 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3920 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3921 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3922 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3923 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3924 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3925 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3926 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3927 | if (bi_putchk(rep, &trash) == -1) |
| 3928 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3929 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3930 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3931 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3932 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3933 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3934 | case STAT_PX_ST_FIN: |
| 3935 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3936 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3937 | default: |
| 3938 | /* unknown state, we should put an abort() here ! */ |
| 3939 | return 1; |
| 3940 | } |
| 3941 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3942 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3943 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3944 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3945 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3946 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3947 | { |
| 3948 | /* WARNING! This must fit in the first buffer !!! */ |
| 3949 | chunk_appendf(&trash, |
| 3950 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3951 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3952 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3953 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3954 | "<style type=\"text/css\"><!--\n" |
| 3955 | "body {" |
| 3956 | " font-family: arial, helvetica, sans-serif;" |
| 3957 | " font-size: 12px;" |
| 3958 | " font-weight: normal;" |
| 3959 | " color: black;" |
| 3960 | " background: white;" |
| 3961 | "}\n" |
| 3962 | "th,td {" |
| 3963 | " font-size: 10px;" |
| 3964 | "}\n" |
| 3965 | "h1 {" |
| 3966 | " font-size: x-large;" |
| 3967 | " margin-bottom: 0.5em;" |
| 3968 | "}\n" |
| 3969 | "h2 {" |
| 3970 | " font-family: helvetica, arial;" |
| 3971 | " font-size: x-large;" |
| 3972 | " font-weight: bold;" |
| 3973 | " font-style: italic;" |
| 3974 | " color: #6020a0;" |
| 3975 | " margin-top: 0em;" |
| 3976 | " margin-bottom: 0em;" |
| 3977 | "}\n" |
| 3978 | "h3 {" |
| 3979 | " font-family: helvetica, arial;" |
| 3980 | " font-size: 16px;" |
| 3981 | " font-weight: bold;" |
| 3982 | " color: #b00040;" |
| 3983 | " background: #e8e8d0;" |
| 3984 | " margin-top: 0em;" |
| 3985 | " margin-bottom: 0em;" |
| 3986 | "}\n" |
| 3987 | "li {" |
| 3988 | " margin-top: 0.25em;" |
| 3989 | " margin-right: 2em;" |
| 3990 | "}\n" |
| 3991 | ".hr {margin-top: 0.25em;" |
| 3992 | " border-color: black;" |
| 3993 | " border-bottom-style: solid;" |
| 3994 | "}\n" |
| 3995 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3996 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3997 | ".frontend {background: #e8e8d0;}\n" |
| 3998 | ".socket {background: #d0d0d0;}\n" |
| 3999 | ".backend {background: #e8e8d0;}\n" |
| 4000 | ".active0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4001 | ".active1 {background: #ff9090;}\n" |
| 4002 | ".active2 {background: #ffd020;}\n" |
| 4003 | ".active3 {background: #ffffa0;}\n" |
| 4004 | ".active4 {background: #c0ffc0;}\n" |
| 4005 | ".active5 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 4006 | ".active6 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 4007 | ".active7 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 4008 | ".active8 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
| 4009 | ".active9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4010 | ".backup0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4011 | ".backup1 {background: #ff9090;}\n" |
| 4012 | ".backup2 {background: #ff80ff;}\n" |
| 4013 | ".backup3 {background: #c060ff;}\n" |
| 4014 | ".backup4 {background: #b0d0ff;}\n" |
| 4015 | ".backup5 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 4016 | ".backup6 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 4017 | ".backup7 {background: #c060ff;}\n" |
| 4018 | ".backup8 {background: #cc9900;}\n" |
| 4019 | ".backup9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4020 | ".maintain {background: #c07820;}\n" |
| 4021 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4022 | "\n" |
| 4023 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4024 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4025 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4026 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4027 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4028 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4029 | "\n" |
| 4030 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4031 | "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" |
| 4032 | "table.tbl td.ac { text-align: center;}\n" |
| 4033 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4034 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4035 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4036 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4037 | "\n" |
| 4038 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4039 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4040 | "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] | 4041 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4042 | "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] | 4043 | "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] | 4044 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4045 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4046 | " display:block;\n" |
| 4047 | " visibility:hidden;\n" |
| 4048 | " z-index:2147483647;\n" |
| 4049 | " position:absolute;\n" |
| 4050 | " padding:2px 4px 3px;\n" |
| 4051 | " background:#f0f060; color:#000000;\n" |
| 4052 | " border:1px solid #7040c0;\n" |
| 4053 | " white-space:nowrap;\n" |
| 4054 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4055 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4056 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4057 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4058 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4059 | "-->\n" |
| 4060 | "</style></head>\n", |
| 4061 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4062 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4063 | ); |
| 4064 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4065 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4066 | /* 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] | 4067 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4068 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4069 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4070 | 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] | 4071 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4072 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4073 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4074 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4075 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4076 | /* WARNING! this has to fit the first packet too. |
| 4077 | * We are around 3.5 kB, add adding entries will |
| 4078 | * become tricky if we want to support 4kB buffers ! |
| 4079 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4080 | chunk_appendf(&trash, |
| 4081 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4082 | PRODUCT_NAME "%s</a></h1>\n" |
| 4083 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4084 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4085 | "<h3>> General process information</h3>\n" |
| 4086 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4087 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4088 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4089 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4090 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4091 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4092 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4093 | "</td><td align=\"center\" nowrap>\n" |
| 4094 | "<table class=\"lgd\"><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4095 | "<td class=\"active4\"> </td><td class=\"noborder\">active UP </td>" |
| 4096 | "<td class=\"backup4\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4097 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4098 | "<td class=\"active3\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4099 | "<td class=\"backup3\"></td><td class=\"noborder\">backup UP, going down </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4100 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4101 | "<td class=\"active2\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4102 | "<td class=\"backup2\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4103 | "</tr><tr>\n" |
| 4104 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4105 | "<td class=\"active9\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4106 | "</tr><tr>\n" |
| 4107 | "<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] | 4108 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4109 | "<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] | 4110 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4111 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4112 | "</td>" |
| 4113 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4114 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4115 | "", |
| 4116 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4117 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4118 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4119 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4120 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4121 | pid, relative_pid, global.nbproc, |
| 4122 | up / 86400, (up % 86400) / 3600, |
| 4123 | (up % 3600) / 60, (up % 60), |
| 4124 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4125 | global.rlimit_memmax ? " MB" : "", |
| 4126 | global.rlimit_nofile, |
| 4127 | global.maxsock, global.maxconn, global.maxpipes, |
| 4128 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4129 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4130 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4131 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4132 | /* 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] | 4133 | 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] | 4134 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4135 | |
| 4136 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4137 | "<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] | 4138 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4139 | STAT_SCOPE_TXT_MAXLEN); |
| 4140 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4141 | /* 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] | 4142 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4143 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4144 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4145 | 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] | 4146 | 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] | 4147 | } |
| 4148 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4149 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4150 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4151 | "<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] | 4152 | uri->uri_prefix, |
| 4153 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4154 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4155 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4156 | else |
| 4157 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4158 | "<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] | 4159 | uri->uri_prefix, |
| 4160 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4161 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4162 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4163 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4164 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4165 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4166 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4167 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4168 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4169 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4170 | "", |
| 4171 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4172 | else |
| 4173 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4174 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4175 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4176 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4177 | ";norefresh", |
| 4178 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4179 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4180 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4181 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4182 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4183 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4184 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4185 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4186 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4187 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4188 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4189 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4190 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4191 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4192 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4193 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4194 | chunk_appendf(&trash, |
| 4195 | "</ul></td>" |
| 4196 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4197 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4198 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4199 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4200 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4201 | "</ul>" |
| 4202 | "</td>" |
| 4203 | "</tr></table>\n" |
| 4204 | "" |
| 4205 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4206 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4207 | if (appctx->ctx.stats.st_code) { |
| 4208 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4209 | case STAT_STATUS_DONE: |
| 4210 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4211 | "<p><div class=active4>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4212 | "<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] | 4213 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4214 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4215 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4216 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4217 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4218 | break; |
| 4219 | case STAT_STATUS_NONE: |
| 4220 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4221 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4222 | "<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] | 4223 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4224 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4225 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4226 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4227 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4228 | break; |
| 4229 | case STAT_STATUS_PART: |
| 4230 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4231 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4232 | "<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] | 4233 | "Action partially processed.<br>" |
| 4234 | "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] | 4235 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4236 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4237 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4238 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4239 | break; |
| 4240 | case STAT_STATUS_ERRP: |
| 4241 | chunk_appendf(&trash, |
| 4242 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4243 | "<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] | 4244 | "Action not processed because of invalid parameters." |
| 4245 | "<ul>" |
| 4246 | "<li>The action is maybe unknown.</li>" |
| 4247 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4248 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4249 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4250 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4251 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4252 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4253 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4254 | break; |
| 4255 | case STAT_STATUS_EXCD: |
| 4256 | chunk_appendf(&trash, |
| 4257 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4258 | "<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] | 4259 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4260 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4261 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4262 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4263 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4264 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4265 | break; |
| 4266 | case STAT_STATUS_DENY: |
| 4267 | chunk_appendf(&trash, |
| 4268 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4269 | "<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] | 4270 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4271 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4272 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4273 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4274 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4275 | break; |
| 4276 | default: |
| 4277 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4278 | "<p><div class=active9>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4279 | "<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] | 4280 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4281 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4282 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4283 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4284 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4285 | } |
| 4286 | chunk_appendf(&trash, "<p>\n"); |
| 4287 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4288 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4289 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4290 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4291 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4292 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4293 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4294 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4295 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4296 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4297 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4298 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4299 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4300 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4301 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 4302 | * and the session must be closed, or -1 in case of any error. This function is |
| 4303 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4304 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4305 | 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] | 4306 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4307 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4308 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4309 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4310 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4311 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4312 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4313 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4314 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4315 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4316 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4317 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4318 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4319 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4320 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4321 | else |
| 4322 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4323 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4324 | if (bi_putchk(rep, &trash) == -1) |
| 4325 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4326 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4327 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4328 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4329 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4330 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4331 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4332 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4333 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4334 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4335 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4336 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4337 | appctx->ctx.stats.px = proxy; |
| 4338 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4339 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4340 | /* fall through */ |
| 4341 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4342 | case STAT_ST_LIST: |
| 4343 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4344 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4345 | if (buffer_almost_full(rep->buf)) { |
| 4346 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4347 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4348 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4349 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4350 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4351 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4352 | 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] | 4353 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4354 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4355 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4356 | appctx->ctx.stats.px = px->next; |
| 4357 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4358 | } |
| 4359 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4360 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4361 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4362 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4363 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4364 | case STAT_ST_END: |
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_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4367 | if (bi_putchk(rep, &trash) == -1) |
| 4368 | return 0; |
| 4369 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4370 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4371 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4372 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4373 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4374 | case STAT_ST_FIN: |
| 4375 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4376 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4377 | default: |
| 4378 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4379 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4380 | return -1; |
| 4381 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4382 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4383 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4384 | /* We reached the stats page through a POST request. The appctx is |
| 4385 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4386 | * Parse the posted data and enable/disable servers if necessary. |
| 4387 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4388 | */ |
| 4389 | static int stats_process_http_post(struct stream_interface *si) |
| 4390 | { |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 4391 | struct session *s = si_sess(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4392 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4393 | |
| 4394 | struct proxy *px = NULL; |
| 4395 | struct server *sv = NULL; |
| 4396 | |
| 4397 | char key[LINESIZE]; |
| 4398 | int action = ST_ADM_ACTION_NONE; |
| 4399 | int reprocess = 0; |
| 4400 | |
| 4401 | int total_servers = 0; |
| 4402 | int altered_servers = 0; |
| 4403 | |
| 4404 | char *first_param, *cur_param, *next_param, *end_params; |
| 4405 | char *st_cur_param = NULL; |
| 4406 | char *st_next_param = NULL; |
| 4407 | |
| 4408 | struct chunk *temp; |
| 4409 | int reql; |
| 4410 | |
| 4411 | temp = get_trash_chunk(); |
| 4412 | if (temp->size < s->txn.req.body_len) { |
| 4413 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4414 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4415 | goto out; |
| 4416 | } |
| 4417 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4418 | 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] | 4419 | if (reql <= 0) { |
| 4420 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4421 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4422 | return 0; |
| 4423 | } |
| 4424 | |
| 4425 | first_param = temp->str; |
| 4426 | end_params = temp->str + reql; |
| 4427 | cur_param = next_param = end_params; |
| 4428 | *end_params = '\0'; |
| 4429 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4430 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4431 | |
| 4432 | /* |
| 4433 | * Parse the parameters in reverse order to only store the last value. |
| 4434 | * From the html form, the backend and the action are at the end. |
| 4435 | */ |
| 4436 | while (cur_param > first_param) { |
| 4437 | char *value; |
| 4438 | int poffset, plen; |
| 4439 | |
| 4440 | cur_param--; |
| 4441 | |
| 4442 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4443 | reprocess_servers: |
| 4444 | /* Parse the key */ |
| 4445 | poffset = (cur_param != first_param ? 1 : 0); |
| 4446 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4447 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4448 | strncpy(key, cur_param + poffset, plen); |
| 4449 | key[plen - 1] = '\0'; |
| 4450 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4451 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4452 | goto out; |
| 4453 | } |
| 4454 | |
| 4455 | /* Parse the value */ |
| 4456 | value = key; |
| 4457 | while (*value != '\0' && *value != '=') { |
| 4458 | value++; |
| 4459 | } |
| 4460 | if (*value == '=') { |
| 4461 | /* Ok, a value is found, we can mark the end of the key */ |
| 4462 | *value++ = '\0'; |
| 4463 | } |
| 4464 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4465 | break; |
| 4466 | |
| 4467 | /* Now we can check the key to see what to do */ |
| 4468 | if (!px && (strcmp(key, "b") == 0)) { |
| 4469 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4470 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4471 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4472 | goto out; |
| 4473 | } |
| 4474 | } |
| 4475 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4476 | if (strcmp(value, "ready") == 0) { |
| 4477 | action = ST_ADM_ACTION_READY; |
| 4478 | } |
| 4479 | else if (strcmp(value, "drain") == 0) { |
| 4480 | action = ST_ADM_ACTION_DRAIN; |
| 4481 | } |
| 4482 | else if (strcmp(value, "maint") == 0) { |
| 4483 | action = ST_ADM_ACTION_MAINT; |
| 4484 | } |
| 4485 | else if (strcmp(value, "shutdown") == 0) { |
| 4486 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4487 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4488 | else if (strcmp(value, "dhlth") == 0) { |
| 4489 | action = ST_ADM_ACTION_DHLTH; |
| 4490 | } |
| 4491 | else if (strcmp(value, "ehlth") == 0) { |
| 4492 | action = ST_ADM_ACTION_EHLTH; |
| 4493 | } |
| 4494 | else if (strcmp(value, "hrunn") == 0) { |
| 4495 | action = ST_ADM_ACTION_HRUNN; |
| 4496 | } |
| 4497 | else if (strcmp(value, "hnolb") == 0) { |
| 4498 | action = ST_ADM_ACTION_HNOLB; |
| 4499 | } |
| 4500 | else if (strcmp(value, "hdown") == 0) { |
| 4501 | action = ST_ADM_ACTION_HDOWN; |
| 4502 | } |
| 4503 | else if (strcmp(value, "dagent") == 0) { |
| 4504 | action = ST_ADM_ACTION_DAGENT; |
| 4505 | } |
| 4506 | else if (strcmp(value, "eagent") == 0) { |
| 4507 | action = ST_ADM_ACTION_EAGENT; |
| 4508 | } |
| 4509 | else if (strcmp(value, "arunn") == 0) { |
| 4510 | action = ST_ADM_ACTION_ARUNN; |
| 4511 | } |
| 4512 | else if (strcmp(value, "adown") == 0) { |
| 4513 | action = ST_ADM_ACTION_ADOWN; |
| 4514 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4515 | /* else these are the old supported methods */ |
| 4516 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4517 | action = ST_ADM_ACTION_DISABLE; |
| 4518 | } |
| 4519 | else if (strcmp(value, "enable") == 0) { |
| 4520 | action = ST_ADM_ACTION_ENABLE; |
| 4521 | } |
| 4522 | else if (strcmp(value, "stop") == 0) { |
| 4523 | action = ST_ADM_ACTION_STOP; |
| 4524 | } |
| 4525 | else if (strcmp(value, "start") == 0) { |
| 4526 | action = ST_ADM_ACTION_START; |
| 4527 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4528 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4529 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4530 | goto out; |
| 4531 | } |
| 4532 | } |
| 4533 | else if (strcmp(key, "s") == 0) { |
| 4534 | if (!(px && action)) { |
| 4535 | /* |
| 4536 | * Indicates that we'll need to reprocess the parameters |
| 4537 | * as soon as backend and action are known |
| 4538 | */ |
| 4539 | if (!reprocess) { |
| 4540 | st_cur_param = cur_param; |
| 4541 | st_next_param = next_param; |
| 4542 | } |
| 4543 | reprocess = 1; |
| 4544 | } |
| 4545 | else if ((sv = findserver(px, value)) != NULL) { |
| 4546 | switch (action) { |
| 4547 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4548 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4549 | altered_servers++; |
| 4550 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4551 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4552 | } |
| 4553 | break; |
| 4554 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4555 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4556 | altered_servers++; |
| 4557 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4558 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4559 | } |
| 4560 | break; |
| 4561 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4562 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 4563 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4564 | altered_servers++; |
| 4565 | total_servers++; |
| 4566 | } |
| 4567 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4568 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4569 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 4570 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4571 | altered_servers++; |
| 4572 | total_servers++; |
| 4573 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4574 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4575 | case ST_ADM_ACTION_DHLTH: |
| 4576 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4577 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4578 | altered_servers++; |
| 4579 | total_servers++; |
| 4580 | } |
| 4581 | break; |
| 4582 | case ST_ADM_ACTION_EHLTH: |
| 4583 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4584 | sv->check.state |= CHK_ST_ENABLED; |
| 4585 | altered_servers++; |
| 4586 | total_servers++; |
| 4587 | } |
| 4588 | break; |
| 4589 | case ST_ADM_ACTION_HRUNN: |
| 4590 | if (!(sv->track)) { |
| 4591 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4592 | srv_set_running(sv, "changed from Web interface"); |
| 4593 | altered_servers++; |
| 4594 | total_servers++; |
| 4595 | } |
| 4596 | break; |
| 4597 | case ST_ADM_ACTION_HNOLB: |
| 4598 | if (!(sv->track)) { |
| 4599 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4600 | srv_set_stopping(sv, "changed from Web interface"); |
| 4601 | altered_servers++; |
| 4602 | total_servers++; |
| 4603 | } |
| 4604 | break; |
| 4605 | case ST_ADM_ACTION_HDOWN: |
| 4606 | if (!(sv->track)) { |
| 4607 | sv->check.health = 0; |
| 4608 | srv_set_stopped(sv, "changed from Web interface"); |
| 4609 | altered_servers++; |
| 4610 | total_servers++; |
| 4611 | } |
| 4612 | break; |
| 4613 | case ST_ADM_ACTION_DAGENT: |
| 4614 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4615 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4616 | altered_servers++; |
| 4617 | total_servers++; |
| 4618 | } |
| 4619 | break; |
| 4620 | case ST_ADM_ACTION_EAGENT: |
| 4621 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4622 | sv->agent.state |= CHK_ST_ENABLED; |
| 4623 | altered_servers++; |
| 4624 | total_servers++; |
| 4625 | } |
| 4626 | break; |
| 4627 | case ST_ADM_ACTION_ARUNN: |
| 4628 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4629 | sv->agent.health = sv->agent.rise + sv->agent.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_ADOWN: |
| 4636 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4637 | sv->agent.health = 0; |
| 4638 | srv_set_stopped(sv, "changed from Web interface"); |
| 4639 | altered_servers++; |
| 4640 | total_servers++; |
| 4641 | } |
| 4642 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4643 | case ST_ADM_ACTION_READY: |
| 4644 | srv_adm_set_ready(sv); |
| 4645 | altered_servers++; |
| 4646 | total_servers++; |
| 4647 | break; |
| 4648 | case ST_ADM_ACTION_DRAIN: |
| 4649 | srv_adm_set_drain(sv); |
| 4650 | altered_servers++; |
| 4651 | total_servers++; |
| 4652 | break; |
| 4653 | case ST_ADM_ACTION_MAINT: |
| 4654 | srv_adm_set_maint(sv); |
| 4655 | altered_servers++; |
| 4656 | total_servers++; |
| 4657 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4658 | case ST_ADM_ACTION_SHUTDOWN: |
| 4659 | if (px->state != PR_STSTOPPED) { |
| 4660 | struct session *sess, *sess_bck; |
| 4661 | |
| 4662 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4663 | if (sess->srv_conn == sv) |
| 4664 | session_shutdown(sess, SN_ERR_KILLED); |
| 4665 | |
| 4666 | altered_servers++; |
| 4667 | total_servers++; |
| 4668 | } |
| 4669 | break; |
| 4670 | } |
| 4671 | } else { |
| 4672 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4673 | total_servers++; |
| 4674 | } |
| 4675 | } |
| 4676 | if (reprocess && px && action) { |
| 4677 | /* Now, we know the backend and the action chosen by the user. |
| 4678 | * We can safely restart from the first server parameter |
| 4679 | * to reprocess them |
| 4680 | */ |
| 4681 | cur_param = st_cur_param; |
| 4682 | next_param = st_next_param; |
| 4683 | reprocess = 0; |
| 4684 | goto reprocess_servers; |
| 4685 | } |
| 4686 | |
| 4687 | next_param = cur_param; |
| 4688 | } |
| 4689 | } |
| 4690 | |
| 4691 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4692 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4693 | } |
| 4694 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4695 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4696 | } |
| 4697 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4698 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4699 | } |
| 4700 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4701 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4702 | } |
| 4703 | out: |
| 4704 | return 1; |
| 4705 | } |
| 4706 | |
| 4707 | |
| 4708 | static int stats_send_http_headers(struct stream_interface *si) |
| 4709 | { |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 4710 | struct session *s = si_sess(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4711 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4712 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4713 | |
| 4714 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4715 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4716 | "Cache-Control: no-cache\r\n" |
| 4717 | "Connection: close\r\n" |
| 4718 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4719 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4720 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4721 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4722 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4723 | uri->refresh); |
| 4724 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4725 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4726 | |
| 4727 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4728 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4729 | else |
| 4730 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4731 | |
| 4732 | s->txn.status = 200; |
| 4733 | s->logs.tv_request = now; |
| 4734 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4735 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4736 | return 0; |
| 4737 | |
| 4738 | return 1; |
| 4739 | } |
| 4740 | |
| 4741 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4742 | { |
| 4743 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 4744 | struct session *s = si_sess(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4745 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4746 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4747 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4748 | /* 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] | 4749 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4750 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4751 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4752 | 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] | 4753 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4754 | } |
| 4755 | |
| 4756 | /* We don't want to land on the posted stats page because a refresh will |
| 4757 | * repost the data. We don't want this to happen on accident so we redirect |
| 4758 | * the browse to the stats page with a GET. |
| 4759 | */ |
| 4760 | chunk_printf(&trash, |
| 4761 | "HTTP/1.1 303 See Other\r\n" |
| 4762 | "Cache-Control: no-cache\r\n" |
| 4763 | "Content-Type: text/plain\r\n" |
| 4764 | "Connection: close\r\n" |
| 4765 | "Location: %s;st=%s%s%s%s\r\n" |
| 4766 | "\r\n", |
| 4767 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4768 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4769 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4770 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4771 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4772 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4773 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4774 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4775 | scope_txt); |
| 4776 | |
| 4777 | s->txn.status = 303; |
| 4778 | s->logs.tv_request = now; |
| 4779 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4780 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4781 | return 0; |
| 4782 | |
| 4783 | return 1; |
| 4784 | } |
| 4785 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4786 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4787 | * 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] | 4788 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4789 | * automatically unregisters itself once transfer is complete. |
| 4790 | */ |
| 4791 | static void http_stats_io_handler(struct stream_interface *si) |
| 4792 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4793 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 4794 | struct session *s = si_sess(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4795 | struct channel *req = si_oc(si); |
| 4796 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4797 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4798 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4799 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4800 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4801 | /* check that the output is not closed */ |
| 4802 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4803 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4804 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4805 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4806 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4807 | if (stats_send_http_headers(si)) { |
| 4808 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4809 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4810 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4811 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4812 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4813 | } |
| 4814 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4815 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4816 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4817 | unsigned int data_len; |
| 4818 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 4819 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4820 | |
| 4821 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4822 | /* One difficulty we're facing is that we must prevent |
| 4823 | * the input data from being automatically forwarded to |
| 4824 | * the output area. For this, we temporarily disable |
| 4825 | * forwarding on the channel. |
| 4826 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4827 | last_fwd = si_ic(si)->to_forward; |
| 4828 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4829 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4830 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 4831 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4832 | goto fail; |
| 4833 | } |
| 4834 | } |
| 4835 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4836 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4837 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4838 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4839 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4840 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4841 | |
| 4842 | /* Now we must either adjust or remove the chunk size. This is |
| 4843 | * not easy because the chunk size might wrap at the end of the |
| 4844 | * buffer, so we pretend we have nothing in the buffer, we write |
| 4845 | * the size, then restore the buffer's contents. Note that we can |
| 4846 | * only do that because no forwarding is scheduled on the stats |
| 4847 | * applet. |
| 4848 | */ |
| 4849 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4850 | si_ic(si)->total -= (last_len - prev_len); |
| 4851 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4852 | |
| 4853 | if (last_len != data_len) { |
| 4854 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4855 | bi_putchk(si_ic(si), &trash); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4856 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4857 | si_ic(si)->total += (last_len - data_len); |
| 4858 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4859 | } |
| 4860 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4861 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4862 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4863 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4864 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4865 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4866 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4867 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4868 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4869 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4870 | } |
| 4871 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4872 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4873 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4874 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4875 | } |
| 4876 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4877 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 4878 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4879 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4880 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4881 | goto fail; |
| 4882 | } |
| 4883 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4884 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4885 | res->flags |= CF_READ_NULL; |
| 4886 | si_shutr(si); |
| 4887 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4888 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4889 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4890 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4891 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4892 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4893 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4894 | si_shutr(si); |
| 4895 | res->flags |= CF_READ_NULL; |
| 4896 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4897 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4898 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4899 | fail: |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4900 | /* update all other flags and resync with the other side */ |
| 4901 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4902 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4903 | /* we don't want to expire timeouts while we're processing requests */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4904 | si_ic(si)->rex = TICK_ETERNITY; |
| 4905 | si_oc(si)->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4906 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4907 | out: |
| 4908 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4909 | /* check that we have released everything then unregister */ |
| 4910 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4911 | } |
| 4912 | } |
| 4913 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4914 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4915 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4916 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4917 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4918 | return "NONE"; |
| 4919 | return conn->ctrl->name; |
| 4920 | } |
| 4921 | |
| 4922 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4923 | { |
| 4924 | static char ptr[17]; |
| 4925 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4926 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4927 | return "NONE"; |
| 4928 | |
| 4929 | if (conn->xprt == &raw_sock) |
| 4930 | return "RAW"; |
| 4931 | |
| 4932 | #ifdef USE_OPENSSL |
| 4933 | if (conn->xprt == &ssl_sock) |
| 4934 | return "SSL"; |
| 4935 | #endif |
| 4936 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4937 | return ptr; |
| 4938 | } |
| 4939 | |
| 4940 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4941 | { |
| 4942 | static char ptr[17]; |
| 4943 | |
| 4944 | if (!conn->data) |
| 4945 | return "NONE"; |
| 4946 | |
| 4947 | if (conn->data == &sess_conn_cb) |
| 4948 | return "SESS"; |
| 4949 | |
| 4950 | if (conn->data == &si_conn_cb) |
| 4951 | return "STRM"; |
| 4952 | |
| 4953 | if (conn->data == &check_conn_cb) |
| 4954 | return "CHCK"; |
| 4955 | |
| 4956 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4957 | return ptr; |
| 4958 | } |
| 4959 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4960 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4961 | * 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] | 4962 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4963 | * 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] | 4964 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4965 | 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] | 4966 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4967 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4968 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4969 | extern const char *monthname[12]; |
| 4970 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4971 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4972 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4973 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4974 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4975 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4976 | 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] | 4977 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4978 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4979 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4980 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4981 | appctx->ctx.sess.uid = 0; |
| 4982 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4983 | return 1; |
| 4984 | } |
| 4985 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4986 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4987 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4988 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4989 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4990 | /* fall through */ |
| 4991 | |
| 4992 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4993 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4994 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4995 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4996 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4997 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4998 | 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] | 4999 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 5000 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5001 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5002 | conn = objt_conn(sess->si[0].end); |
| 5003 | 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] | 5004 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5005 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5006 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5007 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5008 | break; |
| 5009 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5010 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5011 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5012 | default: |
| 5013 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5014 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5015 | break; |
| 5016 | } |
| 5017 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5018 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5019 | " 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] | 5020 | 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] | 5021 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5022 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5023 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5024 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 5025 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 5026 | sess->listener ? sess->listener->luid : 0); |
| 5027 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5028 | if (conn) |
| 5029 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5030 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5031 | 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] | 5032 | case AF_INET: |
| 5033 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5034 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5035 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5036 | break; |
| 5037 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5038 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5039 | break; |
| 5040 | default: |
| 5041 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5042 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5043 | break; |
| 5044 | } |
| 5045 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5046 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5047 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5048 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5049 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5050 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5051 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5052 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5053 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5054 | conn = objt_conn(sess->si[1].end); |
| 5055 | if (conn) |
| 5056 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5057 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5058 | 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] | 5059 | case AF_INET: |
| 5060 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5061 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5062 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5063 | break; |
| 5064 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5065 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5066 | break; |
| 5067 | default: |
| 5068 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5069 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5070 | break; |
| 5071 | } |
| 5072 | |
| 5073 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5074 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5075 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5076 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5077 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5078 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5079 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5080 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5081 | if (conn) |
| 5082 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5083 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5084 | 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] | 5085 | case AF_INET: |
| 5086 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5087 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5088 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5089 | break; |
| 5090 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5091 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5092 | break; |
| 5093 | default: |
| 5094 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5095 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5096 | break; |
| 5097 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5098 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5099 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5100 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5101 | sess->task, |
| 5102 | sess->task->state, |
| 5103 | sess->task->nice, sess->task->calls, |
| 5104 | sess->task->expire ? |
| 5105 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5106 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5107 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5108 | task_in_rq(sess->task) ? ", running" : ""); |
| 5109 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5110 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5111 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5112 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5113 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5114 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5115 | " 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] | 5116 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5117 | 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] | 5118 | |
| 5119 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5120 | " 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] | 5121 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5122 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5123 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5124 | obj_type_name(sess->si[0].end), |
| 5125 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5126 | sess->si[0].exp ? |
| 5127 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5128 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5129 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5130 | sess->si[0].err_type); |
| 5131 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5132 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5133 | " 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] | 5134 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5135 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5136 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5137 | obj_type_name(sess->si[1].end), |
| 5138 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5139 | sess->si[1].exp ? |
| 5140 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5141 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5142 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5143 | sess->si[1].err_type); |
| 5144 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5145 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5146 | chunk_appendf(&trash, |
| 5147 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5148 | conn, |
| 5149 | get_conn_ctrl_name(conn), |
| 5150 | get_conn_xprt_name(conn), |
| 5151 | get_conn_data_name(conn), |
| 5152 | obj_type_name(conn->target), |
| 5153 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5154 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5155 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5156 | " 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] | 5157 | conn->flags, |
| 5158 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5159 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5160 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5161 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5162 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5163 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5164 | chunk_appendf(&trash, |
| 5165 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5166 | tmpctx, |
| 5167 | tmpctx->st0, |
| 5168 | tmpctx->st1, |
| 5169 | tmpctx->st2, |
| 5170 | tmpctx->applet->name); |
| 5171 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5172 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5173 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5174 | chunk_appendf(&trash, |
| 5175 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5176 | conn, |
| 5177 | get_conn_ctrl_name(conn), |
| 5178 | get_conn_xprt_name(conn), |
| 5179 | get_conn_data_name(conn), |
| 5180 | obj_type_name(conn->target), |
| 5181 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5182 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5183 | chunk_appendf(&trash, |
| 5184 | " 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] | 5185 | conn->flags, |
| 5186 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5187 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5188 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5189 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5190 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5191 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5192 | chunk_appendf(&trash, |
| 5193 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5194 | tmpctx, |
| 5195 | tmpctx->st0, |
| 5196 | tmpctx->st1, |
| 5197 | tmpctx->st2, |
| 5198 | tmpctx->applet->name); |
| 5199 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5200 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5201 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5202 | " 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] | 5203 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5204 | &sess->req, |
| 5205 | sess->req.flags, sess->req.analysers, |
| 5206 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5207 | sess->req.to_forward, sess->req.total, |
| 5208 | sess->req.analyse_exp ? |
| 5209 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5210 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5211 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5212 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5213 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5214 | sess->req.rex ? |
| 5215 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5216 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5217 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5218 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5219 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5220 | " 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] | 5221 | sess->req.wex ? |
| 5222 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5223 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5224 | sess->req.buf, |
| 5225 | sess->req.buf->data, sess->req.buf->o, |
| 5226 | (int)(sess->req.buf->p - sess->req.buf->data), |
| 5227 | sess->txn.req.next, sess->req.buf->i, |
| 5228 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5229 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5230 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5231 | " 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] | 5232 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5233 | &sess->res, |
| 5234 | sess->res.flags, sess->res.analysers, |
| 5235 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5236 | sess->res.to_forward, sess->res.total, |
| 5237 | sess->res.analyse_exp ? |
| 5238 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5239 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5240 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5241 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5242 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5243 | sess->res.rex ? |
| 5244 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5245 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5246 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5247 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5248 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5249 | " 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] | 5250 | sess->res.wex ? |
| 5251 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5252 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5253 | sess->res.buf, |
| 5254 | sess->res.buf->data, sess->res.buf->o, |
| 5255 | (int)(sess->res.buf->p - sess->res.buf->data), |
| 5256 | sess->txn.rsp.next, sess->res.buf->i, |
| 5257 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5258 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5259 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5260 | return 0; |
| 5261 | |
| 5262 | /* use other states to dump the contents */ |
| 5263 | } |
| 5264 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5265 | appctx->ctx.sess.uid = 0; |
| 5266 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5267 | return 1; |
| 5268 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5269 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5270 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5271 | { |
| 5272 | struct appctx *appctx = __objt_appctx(si->end); |
| 5273 | |
| 5274 | switch (appctx->st2) { |
| 5275 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5276 | /* Display the column headers. If the message cannot be sent, |
| 5277 | * quit the fucntion with returning 0. The function is called |
| 5278 | * later and restart at the state "STAT_ST_INIT". |
| 5279 | */ |
| 5280 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5281 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5282 | if (bi_putchk(si_ic(si), &trash) == -1) |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5283 | return 0; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5284 | |
| 5285 | /* Now, we start the browsing of the references lists. |
| 5286 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5287 | * avalaible field of this pointer is <list>. It is used with the function |
| 5288 | * pat_list_get_next() for retruning the first avalaible entry |
| 5289 | */ |
| 5290 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5291 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5292 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5293 | appctx->st2 = STAT_ST_LIST; |
| 5294 | /* fall through */ |
| 5295 | |
| 5296 | case STAT_ST_LIST: |
| 5297 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5298 | chunk_reset(&trash); |
| 5299 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5300 | /* Build messages. If the reference is used by another category than |
| 5301 | * the listed categorie, display the information in the massage. |
| 5302 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5303 | 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] | 5304 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5305 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5306 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5307 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5308 | /* let's try again later from this session. We add ourselves into |
| 5309 | * this session's users so that it can remove us upon termination. |
| 5310 | */ |
| 5311 | return 0; |
| 5312 | } |
| 5313 | |
| 5314 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5315 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5316 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | appctx->st2 = STAT_ST_FIN; |
| 5320 | /* fall through */ |
| 5321 | |
| 5322 | default: |
| 5323 | appctx->st2 = STAT_ST_FIN; |
| 5324 | return 1; |
| 5325 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5326 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5327 | } |
| 5328 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5329 | static int stats_map_lookup(struct stream_interface *si) |
| 5330 | { |
| 5331 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5332 | struct sample sample; |
| 5333 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5334 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5335 | |
| 5336 | switch (appctx->st2) { |
| 5337 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5338 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5339 | 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] | 5340 | 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] | 5341 | appctx->st2 = STAT_ST_LIST; |
| 5342 | /* fall through */ |
| 5343 | |
| 5344 | case STAT_ST_LIST: |
| 5345 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5346 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5347 | /* initialise chunk to build new message */ |
| 5348 | chunk_reset(&trash); |
| 5349 | |
| 5350 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 5351 | sample.type = SMP_T_STR; |
| 5352 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5353 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 5354 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5355 | if (appctx->ctx.map.expr->pat_head->match && |
| 5356 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5357 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5358 | else |
| 5359 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5360 | |
| 5361 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5362 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5363 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5364 | break; |
| 5365 | if (match_method >= PAT_MATCH_NUM) |
| 5366 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5367 | else |
| 5368 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5369 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5370 | /* case sensitive */ |
| 5371 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5372 | chunk_appendf(&trash, ", case=insensitive"); |
| 5373 | else |
| 5374 | chunk_appendf(&trash, ", case=sensitive"); |
| 5375 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5376 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5377 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5378 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5379 | chunk_appendf(&trash, ", found=no"); |
| 5380 | else |
| 5381 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | /* Display match and match info */ |
| 5385 | else { |
| 5386 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5387 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5388 | chunk_appendf(&trash, ", found=yes"); |
| 5389 | else |
| 5390 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5391 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5392 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5393 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5394 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5395 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5396 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5397 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5398 | /* display pattern */ |
| 5399 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5400 | if (pat->ref && pat->ref->pattern) |
| 5401 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5402 | else |
| 5403 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5404 | } |
| 5405 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5406 | if (pat->ref && pat->ref->pattern) |
| 5407 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5408 | else |
| 5409 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5410 | } |
| 5411 | |
| 5412 | /* display return value */ |
| 5413 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5414 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5415 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5416 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5417 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5418 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5419 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5420 | } |
| 5421 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5422 | chunk_appendf(&trash, "\n"); |
| 5423 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5424 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5425 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5426 | /* let's try again later from this session. We add ourselves into |
| 5427 | * this session's users so that it can remove us upon termination. |
| 5428 | */ |
| 5429 | return 0; |
| 5430 | } |
| 5431 | |
| 5432 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5433 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5434 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | appctx->st2 = STAT_ST_FIN; |
| 5438 | /* fall through */ |
| 5439 | |
| 5440 | default: |
| 5441 | appctx->st2 = STAT_ST_FIN; |
| 5442 | free(appctx->ctx.map.chunk.str); |
| 5443 | return 1; |
| 5444 | } |
| 5445 | } |
| 5446 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5447 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5448 | { |
| 5449 | struct appctx *appctx = __objt_appctx(si->end); |
| 5450 | |
| 5451 | switch (appctx->st2) { |
| 5452 | |
| 5453 | case STAT_ST_INIT: |
| 5454 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5455 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5456 | struct pat_ref_elt *, list); |
| 5457 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5458 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5459 | appctx->st2 = STAT_ST_LIST; |
| 5460 | /* fall through */ |
| 5461 | |
| 5462 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5463 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5464 | chunk_reset(&trash); |
| 5465 | |
| 5466 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5467 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5468 | chunk_appendf(&trash, "%p %s %s\n", |
| 5469 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5470 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5471 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5472 | chunk_appendf(&trash, "%p %s\n", |
| 5473 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5474 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5475 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5476 | /* let's try again later from this session. We add ourselves into |
| 5477 | * this session's users so that it can remove us upon termination. |
| 5478 | */ |
| 5479 | return 0; |
| 5480 | } |
| 5481 | |
| 5482 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5483 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5484 | struct pat_ref_elt *, list); |
| 5485 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5486 | break; |
| 5487 | } |
| 5488 | |
| 5489 | appctx->st2 = STAT_ST_FIN; |
| 5490 | /* fall through */ |
| 5491 | |
| 5492 | default: |
| 5493 | appctx->st2 = STAT_ST_FIN; |
| 5494 | return 1; |
| 5495 | } |
| 5496 | } |
| 5497 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5498 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5499 | * 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] | 5500 | * to be called again, otherwise non-zero. It is designed to be called |
| 5501 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5502 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5503 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5504 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5505 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5506 | struct connection *conn; |
| 5507 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5508 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5509 | /* If we're forced to shut down, we might have to remove our |
| 5510 | * reference to the last session being dumped. |
| 5511 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5512 | if (appctx->st2 == STAT_ST_LIST) { |
| 5513 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5514 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5515 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5516 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5517 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5518 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5519 | } |
| 5520 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5521 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5522 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5523 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5524 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5525 | /* the function had not been called yet, let's prepare the |
| 5526 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5527 | * pointer to the first in the global list. When a target |
| 5528 | * session is being destroyed, it is responsible for updating |
| 5529 | * this pointer. We know we have reached the end when this |
| 5530 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5531 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5532 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5533 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5534 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5535 | /* fall through */ |
| 5536 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5537 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5538 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5539 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5540 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5541 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5545 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5546 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5547 | struct session *curr_sess; |
| 5548 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5549 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5550 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5551 | if (appctx->ctx.sess.target) { |
| 5552 | 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] | 5553 | goto next_sess; |
| 5554 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5555 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5556 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5557 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5558 | return 0; |
| 5559 | |
| 5560 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5561 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5562 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5563 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5564 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5565 | break; |
| 5566 | } |
| 5567 | else |
| 5568 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5569 | } |
| 5570 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5571 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5572 | "%p: proto=%s", |
| 5573 | curr_sess, |
| 5574 | curr_sess->listener->proto->name); |
| 5575 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5576 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5577 | conn = objt_conn(curr_sess->si[0].end); |
| 5578 | 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] | 5579 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5580 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5581 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5582 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5583 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5584 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5585 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5586 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5587 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5588 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5589 | break; |
| 5590 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5591 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5592 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5593 | curr_sess->listener->luid, |
| 5594 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5595 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5596 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5597 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5598 | break; |
| 5599 | } |
| 5600 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5601 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5602 | " ts=%02x age=%s calls=%d", |
| 5603 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5604 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5605 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5606 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5607 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5608 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5609 | curr_sess->req.flags, |
| 5610 | curr_sess->req.buf->i, |
| 5611 | curr_sess->req.analysers, |
| 5612 | curr_sess->req.rex ? |
| 5613 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5614 | TICKS_TO_MS(1000)) : ""); |
| 5615 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5616 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5617 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5618 | curr_sess->req.wex ? |
| 5619 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5620 | TICKS_TO_MS(1000)) : ""); |
| 5621 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5622 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5623 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5624 | curr_sess->req.analyse_exp ? |
| 5625 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5626 | TICKS_TO_MS(1000)) : ""); |
| 5627 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5628 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5629 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5630 | curr_sess->res.flags, |
| 5631 | curr_sess->res.buf->i, |
| 5632 | curr_sess->res.analysers, |
| 5633 | curr_sess->res.rex ? |
| 5634 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5635 | TICKS_TO_MS(1000)) : ""); |
| 5636 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5637 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5638 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5639 | curr_sess->res.wex ? |
| 5640 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5641 | TICKS_TO_MS(1000)) : ""); |
| 5642 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5643 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5644 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5645 | curr_sess->res.analyse_exp ? |
| 5646 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5647 | TICKS_TO_MS(1000)) : ""); |
| 5648 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5649 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5650 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5651 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5652 | curr_sess->si[0].state, |
| 5653 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5654 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5655 | curr_sess->si[0].exp ? |
| 5656 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5657 | TICKS_TO_MS(1000)) : ""); |
| 5658 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5659 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5660 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5661 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5662 | curr_sess->si[1].state, |
| 5663 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5664 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5665 | curr_sess->si[1].exp ? |
| 5666 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5667 | TICKS_TO_MS(1000)) : ""); |
| 5668 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5669 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5670 | " exp=%s", |
| 5671 | curr_sess->task->expire ? |
| 5672 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5673 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5674 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5675 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5676 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5677 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5678 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5679 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5680 | /* let's try again later from this session. We add ourselves into |
| 5681 | * this session's users so that it can remove us upon termination. |
| 5682 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5683 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5684 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5685 | } |
| 5686 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5687 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5688 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5689 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5690 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5691 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5692 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5693 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5694 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5695 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5696 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5697 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5698 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5699 | return 0; |
| 5700 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5701 | appctx->ctx.sess.target = NULL; |
| 5702 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5703 | return 1; |
| 5704 | } |
| 5705 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5706 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5707 | /* fall through */ |
| 5708 | |
| 5709 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5710 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5711 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5712 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5713 | } |
| 5714 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5715 | /* This is called when the stream interface is closed. For instance, upon an |
| 5716 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5717 | * remove back references to the session currently being dumped. |
| 5718 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5719 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5720 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5721 | struct appctx *appctx = __objt_appctx(si->end); |
| 5722 | |
| 5723 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5724 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5725 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5726 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5727 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5728 | free(appctx->ctx.cli.err); |
| 5729 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5730 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5731 | free(appctx->ctx.map.chunk.str); |
| 5732 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5733 | } |
| 5734 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5735 | /* This function is used to either dump tables states (when action is set |
| 5736 | * 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] | 5737 | * It returns 0 if the output buffer is full and it needs to be called |
| 5738 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5739 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5740 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5741 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5742 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3c23a85 | 2014-12-28 12:19:57 +0100 | [diff] [blame] | 5743 | struct session *s = si_sess(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5744 | struct ebmb_node *eb; |
| 5745 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5746 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5747 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5748 | |
| 5749 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5750 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5751 | * - STAT_ST_INIT : the first call |
| 5752 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5753 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5754 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5755 | * and the entry pointer points to the next entry to be dumped, |
| 5756 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5757 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5758 | * data though. |
| 5759 | */ |
| 5760 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5761 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5762 | /* 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] | 5763 | if (appctx->st2 == STAT_ST_LIST) { |
| 5764 | appctx->ctx.table.entry->ref_cnt--; |
| 5765 | 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] | 5766 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5767 | return 1; |
| 5768 | } |
| 5769 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5770 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5771 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5772 | while (appctx->st2 != STAT_ST_FIN) { |
| 5773 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5774 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5775 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5776 | if (!appctx->ctx.table.proxy) |
| 5777 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5778 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5779 | appctx->ctx.table.entry = NULL; |
| 5780 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5781 | break; |
| 5782 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5783 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5784 | if (!appctx->ctx.table.proxy || |
| 5785 | (appctx->ctx.table.target && |
| 5786 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5787 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5788 | break; |
| 5789 | } |
| 5790 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5791 | if (appctx->ctx.table.proxy->table.size) { |
| 5792 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5793 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5794 | return 0; |
| 5795 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5796 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5797 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5798 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5799 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5800 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5801 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5802 | appctx->ctx.table.entry->ref_cnt++; |
| 5803 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5804 | break; |
| 5805 | } |
| 5806 | } |
| 5807 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5808 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5809 | break; |
| 5810 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5811 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5812 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5813 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5814 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5815 | /* we're filtering on some data contents */ |
| 5816 | void *ptr; |
| 5817 | long long data; |
| 5818 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5819 | dt = appctx->ctx.table.data_type; |
| 5820 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5821 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5822 | dt); |
| 5823 | |
| 5824 | data = 0; |
| 5825 | switch (stktable_data_types[dt].std_type) { |
| 5826 | case STD_T_SINT: |
| 5827 | data = stktable_data_cast(ptr, std_t_sint); |
| 5828 | break; |
| 5829 | case STD_T_UINT: |
| 5830 | data = stktable_data_cast(ptr, std_t_uint); |
| 5831 | break; |
| 5832 | case STD_T_ULL: |
| 5833 | data = stktable_data_cast(ptr, std_t_ull); |
| 5834 | break; |
| 5835 | case STD_T_FRQP: |
| 5836 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5837 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5838 | break; |
| 5839 | } |
| 5840 | |
| 5841 | /* 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] | 5842 | if ((data < appctx->ctx.table.value && |
| 5843 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5844 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5845 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5846 | (data == appctx->ctx.table.value && |
| 5847 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5848 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5849 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5850 | (data > appctx->ctx.table.value && |
| 5851 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5852 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5853 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5854 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5855 | } |
| 5856 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5857 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5858 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5859 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5860 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5861 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5862 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5863 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5864 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5865 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5866 | struct stksess *old = appctx->ctx.table.entry; |
| 5867 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5868 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5869 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5870 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5871 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5872 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5873 | break; |
| 5874 | } |
| 5875 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5876 | |
| 5877 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5878 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5879 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5880 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5881 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5882 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5883 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5884 | break; |
| 5885 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5886 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5887 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5888 | break; |
| 5889 | } |
| 5890 | } |
| 5891 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5892 | } |
| 5893 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5894 | /* 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] | 5895 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5896 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5897 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5898 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5899 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5900 | * after the offset. The new pointer is returned. |
| 5901 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5902 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5903 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5904 | { |
| 5905 | int end; |
| 5906 | unsigned char c; |
| 5907 | |
| 5908 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5909 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5910 | return ptr; |
| 5911 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5912 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5913 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5914 | while (ptr < len && ptr < bsize) { |
| 5915 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5916 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5917 | if (out->len > end - 2) |
| 5918 | break; |
| 5919 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5920 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5921 | if (out->len > end - 3) |
| 5922 | break; |
| 5923 | out->str[out->len++] = '\\'; |
| 5924 | switch (c) { |
| 5925 | case '\t': c = 't'; break; |
| 5926 | case '\n': c = 'n'; break; |
| 5927 | case '\r': c = 'r'; break; |
| 5928 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5929 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5930 | } |
| 5931 | out->str[out->len++] = c; |
| 5932 | } else { |
| 5933 | if (out->len > end - 5) |
| 5934 | break; |
| 5935 | out->str[out->len++] = '\\'; |
| 5936 | out->str[out->len++] = 'x'; |
| 5937 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5938 | out->str[out->len++] = hextab[c & 0xF]; |
| 5939 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5940 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5941 | /* we had a line break, let's return now */ |
| 5942 | out->str[out->len++] = '\n'; |
| 5943 | *line = ptr; |
| 5944 | return ptr; |
| 5945 | } |
| 5946 | } |
| 5947 | /* we have an incomplete line, we return it as-is */ |
| 5948 | out->str[out->len++] = '\n'; |
| 5949 | return ptr; |
| 5950 | } |
| 5951 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5952 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5953 | * 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] | 5954 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5955 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5956 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5957 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5958 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5959 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5960 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5961 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5962 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5963 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5964 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5965 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5966 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5967 | /* the function had not been called yet, let's prepare the |
| 5968 | * buffer for a response. |
| 5969 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5970 | struct tm tm; |
| 5971 | |
| 5972 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5973 | 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] | 5974 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5975 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5976 | error_snapshot_id); |
| 5977 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5978 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5979 | /* Socket buffer full. Let's try again later from the same point */ |
| 5980 | return 0; |
| 5981 | } |
| 5982 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5983 | appctx->ctx.errors.px = proxy; |
| 5984 | appctx->ctx.errors.buf = 0; |
| 5985 | appctx->ctx.errors.bol = 0; |
| 5986 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5987 | } |
| 5988 | |
| 5989 | /* we have two inner loops here, one for the proxy, the other one for |
| 5990 | * the buffer. |
| 5991 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5992 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5993 | struct error_snapshot *es; |
| 5994 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5995 | if (appctx->ctx.errors.buf == 0) |
| 5996 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5997 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5998 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5999 | |
| 6000 | if (!es->when.tv_sec) |
| 6001 | goto next; |
| 6002 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6003 | if (appctx->ctx.errors.iid >= 0 && |
| 6004 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6005 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6006 | goto next; |
| 6007 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6008 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6009 | /* just print headers now */ |
| 6010 | |
| 6011 | char pn[INET6_ADDRSTRLEN]; |
| 6012 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6013 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6014 | |
| 6015 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6016 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6017 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6018 | 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] | 6019 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6020 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6021 | case AF_INET: |
| 6022 | case AF_INET6: |
| 6023 | port = get_host_port(&es->src); |
| 6024 | break; |
| 6025 | default: |
| 6026 | port = 0; |
| 6027 | } |
| 6028 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6029 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6030 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6031 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6032 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6033 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6034 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6035 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6036 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6037 | break; |
| 6038 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6039 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6040 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6041 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6042 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6043 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6044 | break; |
| 6045 | } |
| 6046 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6047 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6048 | ", server %s (#%d), event #%u\n" |
| 6049 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6050 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6051 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6052 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6053 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6054 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6055 | es->ev_id, |
| 6056 | pn, port, es->sid, es->s_flags, |
| 6057 | es->state, es->m_flags, es->t_flags, |
| 6058 | es->m_clen, es->m_blen, |
| 6059 | es->b_flags, es->b_out, es->b_tot, |
| 6060 | es->len, es->b_wrap, es->pos); |
| 6061 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6062 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6063 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6064 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6065 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6066 | appctx->ctx.errors.ptr = 0; |
| 6067 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6068 | } |
| 6069 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6070 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6071 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6072 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6073 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6074 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6075 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6076 | goto next; |
| 6077 | } |
| 6078 | |
| 6079 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6080 | 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] | 6081 | int newptr; |
| 6082 | int newline; |
| 6083 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6084 | newline = appctx->ctx.errors.bol; |
| 6085 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6086 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6087 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6088 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6089 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6090 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6091 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6092 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6093 | appctx->ctx.errors.ptr = newptr; |
| 6094 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6095 | }; |
| 6096 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6097 | appctx->ctx.errors.bol = 0; |
| 6098 | appctx->ctx.errors.ptr = -1; |
| 6099 | appctx->ctx.errors.buf++; |
| 6100 | if (appctx->ctx.errors.buf > 1) { |
| 6101 | appctx->ctx.errors.buf = 0; |
| 6102 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6107 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6108 | } |
| 6109 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6110 | /* parse the "level" argument on the bind lines */ |
| 6111 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6112 | { |
| 6113 | if (!*args[cur_arg + 1]) { |
| 6114 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6115 | return ERR_ALERT | ERR_FATAL; |
| 6116 | } |
| 6117 | |
| 6118 | if (!strcmp(args[cur_arg+1], "user")) |
| 6119 | conf->level = ACCESS_LVL_USER; |
| 6120 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6121 | conf->level = ACCESS_LVL_OPER; |
| 6122 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6123 | conf->level = ACCESS_LVL_ADMIN; |
| 6124 | else { |
| 6125 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6126 | args[cur_arg], args[cur_arg+1]); |
| 6127 | return ERR_ALERT | ERR_FATAL; |
| 6128 | } |
| 6129 | |
| 6130 | return 0; |
| 6131 | } |
| 6132 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6133 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6134 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6135 | .name = "<STATS>", /* used for logging */ |
| 6136 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6137 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6138 | }; |
| 6139 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6140 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6141 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6142 | .name = "<CLI>", /* used for logging */ |
| 6143 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6144 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6145 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6146 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6147 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6148 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6149 | { 0, NULL, NULL }, |
| 6150 | }}; |
| 6151 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6152 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6153 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6154 | { NULL, NULL, 0 }, |
| 6155 | }}; |
| 6156 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6157 | __attribute__((constructor)) |
| 6158 | static void __dumpstats_module_init(void) |
| 6159 | { |
| 6160 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6161 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6162 | } |
| 6163 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6164 | /* |
| 6165 | * Local variables: |
| 6166 | * c-indent-level: 8 |
| 6167 | * c-basic-offset: 8 |
| 6168 | * End: |
| 6169 | */ |