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 */ |
Cyril Bonté | c4cdeb7 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 84 | STAT_CLI_O_PATS, /* list all pattern reference available */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 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 | e309ab7 | 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" |
Cyril Bonté | c4cdeb7 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 189 | " show acl [id] : report available acls or dump an acl's contents\n" |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 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" |
Cyril Bonté | c4cdeb7 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 194 | " show map [id] : report available maps or dump a map's contents\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 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 | 03cdb7c | 2012-08-27 23:14:58 +0200 | [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) { |
| 252 | s->req->rto = *s->listener->timeout; |
| 253 | s->rep->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 | |
Willy Tarreau | fdfc46e | 2015-10-13 15:06:57 +0200 | [diff] [blame] | 337 | if (kw->parse(args, cur_arg, global.stats_fe, bind_conf, err) != 0) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 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 | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 572 | struct session *s = session_from_task(si->owner); |
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 | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 582 | if (bi_putchk(si->ib, 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 | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 653 | if (bi_putchk(si->ib, 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 | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 661 | struct session *s = session_from_task(si->owner); |
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 | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 1064 | struct session *s = session_from_task(si->owner); |
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 | 0aa5899 | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1112 | appctx->ctx.stats.scope_str = 0; |
| 1113 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1114 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1115 | if (strcmp(args[0], "show") == 0) { |
| 1116 | if (strcmp(args[1], "stat") == 0) { |
| 1117 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1118 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1119 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1120 | appctx->ctx.stats.type = atoi(args[3]); |
| 1121 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1122 | } |
| 1123 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1124 | appctx->st2 = STAT_ST_INIT; |
| 1125 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1126 | } |
| 1127 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1128 | appctx->st2 = STAT_ST_INIT; |
| 1129 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1130 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1131 | else if (strcmp(args[1], "pools") == 0) { |
| 1132 | appctx->st2 = STAT_ST_INIT; |
| 1133 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1134 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1135 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1136 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1137 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1138 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1139 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1140 | return 1; |
| 1141 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1142 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1143 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1144 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1145 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1146 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1147 | appctx->ctx.sess.target = NULL; |
| 1148 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1149 | appctx->ctx.sess.pos = 0; |
| 1150 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1151 | } |
| 1152 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1153 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1154 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1155 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1156 | return 1; |
| 1157 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1158 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1159 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1160 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1161 | appctx->ctx.errors.iid = -1; |
| 1162 | appctx->ctx.errors.px = NULL; |
| 1163 | appctx->st2 = STAT_ST_INIT; |
| 1164 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1165 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1166 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1167 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1168 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1169 | else if (strcmp(args[1], "map") == 0 || |
| 1170 | strcmp(args[1], "acl") == 0) { |
| 1171 | |
| 1172 | /* Set ACL or MAP flags. */ |
| 1173 | if (args[1][0] == 'm') |
| 1174 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1175 | else |
| 1176 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1177 | |
Cyril Bonté | c4cdeb7 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 1178 | /* no parameter: display all map available */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1179 | if (!*args[2]) { |
| 1180 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1181 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1182 | return 1; |
| 1183 | } |
| 1184 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1185 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1186 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1187 | if (!appctx->ctx.map.ref || |
| 1188 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1189 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1190 | 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] | 1191 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1192 | 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] | 1193 | appctx->st0 = STAT_CLI_PRINT; |
| 1194 | return 1; |
| 1195 | } |
| 1196 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1197 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1198 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1199 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1203 | else if (strcmp(args[0], "clear") == 0) { |
| 1204 | if (strcmp(args[1], "counters") == 0) { |
| 1205 | struct proxy *px; |
| 1206 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1207 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1208 | int clrall = 0; |
| 1209 | |
| 1210 | if (strcmp(args[2], "all") == 0) |
| 1211 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1212 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1213 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1214 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1215 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1216 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1217 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1218 | return 1; |
| 1219 | } |
| 1220 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1221 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1222 | if (clrall) { |
| 1223 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1224 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1225 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1226 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1227 | px->be_counters.conn_max = 0; |
| 1228 | px->be_counters.p.http.rps_max = 0; |
| 1229 | px->be_counters.sps_max = 0; |
| 1230 | px->be_counters.cps_max = 0; |
| 1231 | px->be_counters.nbpend_max = 0; |
| 1232 | |
| 1233 | px->fe_counters.conn_max = 0; |
| 1234 | px->fe_counters.p.http.rps_max = 0; |
| 1235 | px->fe_counters.sps_max = 0; |
| 1236 | px->fe_counters.cps_max = 0; |
| 1237 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1238 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1239 | |
| 1240 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1241 | if (clrall) |
| 1242 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1243 | else { |
| 1244 | sv->counters.cur_sess_max = 0; |
| 1245 | sv->counters.nbpend_max = 0; |
| 1246 | sv->counters.sps_max = 0; |
| 1247 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1248 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1249 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1250 | if (li->counters) { |
| 1251 | if (clrall) |
| 1252 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1253 | else |
| 1254 | li->counters->conn_max = 0; |
| 1255 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1256 | } |
| 1257 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1258 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1259 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1260 | return 1; |
| 1261 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1262 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1263 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1264 | /* end of processing */ |
| 1265 | return 1; |
| 1266 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1267 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1268 | /* Set ACL or MAP flags. */ |
| 1269 | if (args[1][0] == 'm') |
| 1270 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1271 | else |
| 1272 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1273 | |
| 1274 | /* no parameter */ |
| 1275 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1276 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1277 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1278 | else |
| 1279 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1280 | appctx->st0 = STAT_CLI_PRINT; |
| 1281 | return 1; |
| 1282 | } |
| 1283 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1284 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1285 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1286 | if (!appctx->ctx.map.ref || |
| 1287 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1288 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1289 | 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] | 1290 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1291 | 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] | 1292 | appctx->st0 = STAT_CLI_PRINT; |
| 1293 | return 1; |
| 1294 | } |
| 1295 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1296 | /* Clear all. */ |
| 1297 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1298 | |
| 1299 | /* return response */ |
Thierry FOURNIER | 73f1d8f | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1300 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1301 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1302 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1303 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1304 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1305 | return 0; |
| 1306 | } |
| 1307 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1308 | else if (strcmp(args[0], "get") == 0) { |
| 1309 | if (strcmp(args[1], "weight") == 0) { |
| 1310 | struct proxy *px; |
| 1311 | struct server *sv; |
| 1312 | |
| 1313 | /* split "backend/server" and make <line> point to server */ |
| 1314 | for (line = args[2]; *line; line++) |
| 1315 | if (*line == '/') { |
| 1316 | *line++ = '\0'; |
| 1317 | break; |
| 1318 | } |
| 1319 | |
| 1320 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1321 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1322 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1323 | return 1; |
| 1324 | } |
| 1325 | |
| 1326 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1327 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1328 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1329 | return 1; |
| 1330 | } |
| 1331 | |
| 1332 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1333 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1334 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1335 | return 1; |
| 1336 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1337 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1338 | /* Set flags. */ |
| 1339 | if (args[1][0] == 'm') |
| 1340 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1341 | else |
| 1342 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1343 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1344 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1345 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1346 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1347 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1348 | else |
| 1349 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1350 | appctx->st0 = STAT_CLI_PRINT; |
| 1351 | return 1; |
| 1352 | } |
| 1353 | |
| 1354 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1355 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1356 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1357 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1358 | 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] | 1359 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1360 | 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] | 1361 | appctx->st0 = STAT_CLI_PRINT; |
| 1362 | return 1; |
| 1363 | } |
| 1364 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1365 | /* copy input string. The string must be allocated because |
| 1366 | * it may be used over multiple iterations. It's released |
| 1367 | * at the end and upon abort anyway. |
| 1368 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1369 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1370 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1371 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1372 | if (!appctx->ctx.map.chunk.str) { |
| 1373 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1374 | appctx->st0 = STAT_CLI_PRINT; |
| 1375 | return 1; |
| 1376 | } |
| 1377 | |
| 1378 | /* prepare response */ |
| 1379 | appctx->st2 = STAT_ST_INIT; |
| 1380 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1381 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1382 | else { /* not "get weight" */ |
| 1383 | return 0; |
| 1384 | } |
| 1385 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1386 | else if (strcmp(args[0], "set") == 0) { |
| 1387 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1388 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1389 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1390 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1391 | sv = expect_server_admin(s, si, args[2]); |
| 1392 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1393 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1394 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1395 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1396 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1397 | appctx->ctx.cli.msg = warning; |
| 1398 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1399 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1400 | return 1; |
| 1401 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1402 | else if (strcmp(args[1], "server") == 0) { |
| 1403 | struct server *sv; |
| 1404 | const char *warning; |
| 1405 | |
| 1406 | sv = expect_server_admin(s, si, args[2]); |
| 1407 | if (!sv) |
| 1408 | return 1; |
| 1409 | |
| 1410 | if (strcmp(args[3], "weight") == 0) { |
| 1411 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1412 | if (warning) { |
| 1413 | appctx->ctx.cli.msg = warning; |
| 1414 | appctx->st0 = STAT_CLI_PRINT; |
| 1415 | } |
| 1416 | } |
| 1417 | else if (strcmp(args[3], "state") == 0) { |
| 1418 | if (strcmp(args[4], "ready") == 0) |
| 1419 | srv_adm_set_ready(sv); |
| 1420 | else if (strcmp(args[4], "drain") == 0) |
| 1421 | srv_adm_set_drain(sv); |
| 1422 | else if (strcmp(args[4], "maint") == 0) |
| 1423 | srv_adm_set_maint(sv); |
| 1424 | else { |
| 1425 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1426 | appctx->st0 = STAT_CLI_PRINT; |
| 1427 | } |
| 1428 | } |
| 1429 | else if (strcmp(args[3], "health") == 0) { |
| 1430 | if (sv->track) { |
| 1431 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1432 | appctx->st0 = STAT_CLI_PRINT; |
| 1433 | } |
| 1434 | else if (strcmp(args[4], "up") == 0) { |
| 1435 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1436 | srv_set_running(sv, "changed from CLI"); |
| 1437 | } |
| 1438 | else if (strcmp(args[4], "stopping") == 0) { |
| 1439 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1440 | srv_set_stopping(sv, "changed from CLI"); |
| 1441 | } |
| 1442 | else if (strcmp(args[4], "down") == 0) { |
| 1443 | sv->check.health = 0; |
| 1444 | srv_set_stopped(sv, "changed from CLI"); |
| 1445 | } |
| 1446 | else { |
| 1447 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1448 | appctx->st0 = STAT_CLI_PRINT; |
| 1449 | } |
| 1450 | } |
| 1451 | else if (strcmp(args[3], "agent") == 0) { |
| 1452 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1453 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1454 | appctx->st0 = STAT_CLI_PRINT; |
| 1455 | } |
| 1456 | else if (strcmp(args[4], "up") == 0) { |
| 1457 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1458 | srv_set_running(sv, "changed from CLI"); |
| 1459 | } |
| 1460 | else if (strcmp(args[4], "down") == 0) { |
| 1461 | sv->agent.health = 0; |
| 1462 | srv_set_stopped(sv, "changed from CLI"); |
| 1463 | } |
| 1464 | else { |
| 1465 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1466 | appctx->st0 = STAT_CLI_PRINT; |
| 1467 | } |
| 1468 | } |
| 1469 | else { |
| 1470 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state' and 'weight'.\n"; |
| 1471 | appctx->st0 = STAT_CLI_PRINT; |
| 1472 | } |
| 1473 | return 1; |
| 1474 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1475 | else if (strcmp(args[1], "timeout") == 0) { |
| 1476 | if (strcmp(args[2], "cli") == 0) { |
| 1477 | unsigned timeout; |
| 1478 | const char *res; |
| 1479 | |
| 1480 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1481 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1482 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1483 | return 1; |
| 1484 | } |
| 1485 | |
| 1486 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1487 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1488 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1489 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1490 | return 1; |
| 1491 | } |
| 1492 | |
| 1493 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1494 | return 1; |
| 1495 | } |
| 1496 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1497 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1498 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1499 | return 1; |
| 1500 | } |
| 1501 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1502 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1503 | if (strcmp(args[2], "frontend") == 0) { |
| 1504 | struct proxy *px; |
| 1505 | struct listener *l; |
| 1506 | int v; |
| 1507 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1508 | px = expect_frontend_admin(s, si, args[3]); |
| 1509 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1510 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1511 | |
| 1512 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1513 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1514 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1515 | return 1; |
| 1516 | } |
| 1517 | |
| 1518 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1519 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1520 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1521 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1522 | return 1; |
| 1523 | } |
| 1524 | |
| 1525 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1526 | * its listeners. The blocked ones will be dequeued. |
| 1527 | */ |
| 1528 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1529 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1530 | l->maxconn = v; |
| 1531 | if (l->state == LI_FULL) |
| 1532 | resume_listener(l); |
| 1533 | } |
| 1534 | |
| 1535 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1536 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1537 | |
| 1538 | return 1; |
| 1539 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1540 | else if (strcmp(args[2], "global") == 0) { |
| 1541 | int v; |
| 1542 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1543 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1544 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1545 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1546 | return 1; |
| 1547 | } |
| 1548 | |
| 1549 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1550 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1551 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1552 | return 1; |
| 1553 | } |
| 1554 | |
| 1555 | v = atoi(args[3]); |
| 1556 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1557 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1558 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1559 | return 1; |
| 1560 | } |
| 1561 | |
| 1562 | /* check for unlimited values */ |
| 1563 | if (v <= 0) |
| 1564 | v = global.hardmaxconn; |
| 1565 | |
| 1566 | global.maxconn = v; |
| 1567 | |
| 1568 | /* Dequeues all of the listeners waiting for a resource */ |
| 1569 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1570 | dequeue_all_listeners(&global_listener_queue); |
| 1571 | |
| 1572 | return 1; |
| 1573 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1574 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1575 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1576 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1577 | return 1; |
| 1578 | } |
| 1579 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1580 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1581 | if (strcmp(args[2], "connections") == 0) { |
| 1582 | if (strcmp(args[3], "global") == 0) { |
| 1583 | int v; |
| 1584 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1585 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1586 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1587 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1588 | return 1; |
| 1589 | } |
| 1590 | |
| 1591 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1592 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1593 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1594 | return 1; |
| 1595 | } |
| 1596 | |
| 1597 | v = atoi(args[4]); |
| 1598 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1599 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1600 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1601 | return 1; |
| 1602 | } |
| 1603 | |
| 1604 | global.cps_lim = v; |
| 1605 | |
| 1606 | /* Dequeues all of the listeners waiting for a resource */ |
| 1607 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1608 | dequeue_all_listeners(&global_listener_queue); |
| 1609 | |
| 1610 | return 1; |
| 1611 | } |
| 1612 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1613 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1614 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1615 | return 1; |
| 1616 | } |
| 1617 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1618 | else if (strcmp(args[2], "sessions") == 0) { |
| 1619 | if (strcmp(args[3], "global") == 0) { |
| 1620 | int v; |
| 1621 | |
| 1622 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1623 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1624 | appctx->st0 = STAT_CLI_PRINT; |
| 1625 | return 1; |
| 1626 | } |
| 1627 | |
| 1628 | if (!*args[4]) { |
| 1629 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1630 | appctx->st0 = STAT_CLI_PRINT; |
| 1631 | return 1; |
| 1632 | } |
| 1633 | |
| 1634 | v = atoi(args[4]); |
| 1635 | if (v < 0) { |
| 1636 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1637 | appctx->st0 = STAT_CLI_PRINT; |
| 1638 | return 1; |
| 1639 | } |
| 1640 | |
| 1641 | global.sps_lim = v; |
| 1642 | |
| 1643 | /* Dequeues all of the listeners waiting for a resource */ |
| 1644 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1645 | dequeue_all_listeners(&global_listener_queue); |
| 1646 | |
| 1647 | return 1; |
| 1648 | } |
| 1649 | else { |
| 1650 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1651 | appctx->st0 = STAT_CLI_PRINT; |
| 1652 | return 1; |
| 1653 | } |
| 1654 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1655 | #ifdef USE_OPENSSL |
| 1656 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1657 | if (strcmp(args[3], "global") == 0) { |
| 1658 | int v; |
| 1659 | |
| 1660 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1661 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1662 | appctx->st0 = STAT_CLI_PRINT; |
| 1663 | return 1; |
| 1664 | } |
| 1665 | |
| 1666 | if (!*args[4]) { |
| 1667 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1668 | appctx->st0 = STAT_CLI_PRINT; |
| 1669 | return 1; |
| 1670 | } |
| 1671 | |
| 1672 | v = atoi(args[4]); |
| 1673 | if (v < 0) { |
| 1674 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1675 | appctx->st0 = STAT_CLI_PRINT; |
| 1676 | return 1; |
| 1677 | } |
| 1678 | |
| 1679 | global.ssl_lim = v; |
| 1680 | |
| 1681 | /* Dequeues all of the listeners waiting for a resource */ |
| 1682 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1683 | dequeue_all_listeners(&global_listener_queue); |
| 1684 | |
| 1685 | return 1; |
| 1686 | } |
| 1687 | else { |
| 1688 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1689 | appctx->st0 = STAT_CLI_PRINT; |
| 1690 | return 1; |
| 1691 | } |
| 1692 | } |
| 1693 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1694 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1695 | if (strcmp(args[3], "global") == 0) { |
| 1696 | int v; |
| 1697 | |
Willy Tarreau | 07ccb48 | 2015-11-26 18:32:39 +0100 | [diff] [blame] | 1698 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1699 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1700 | appctx->st0 = STAT_CLI_PRINT; |
| 1701 | return 1; |
| 1702 | } |
| 1703 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1704 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1705 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1706 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1707 | return 1; |
| 1708 | } |
| 1709 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1710 | v = atoi(args[4]); |
| 1711 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1712 | } |
| 1713 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1714 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1715 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1716 | return 1; |
| 1717 | } |
| 1718 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1719 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1720 | 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] | 1721 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1722 | return 1; |
| 1723 | } |
| 1724 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1725 | else if (strcmp(args[1], "table") == 0) { |
| 1726 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1727 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1728 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1729 | char *err; |
| 1730 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1731 | /* Set flags. */ |
| 1732 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1733 | |
| 1734 | /* Expect three parameters: map name, key and new value. */ |
| 1735 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1736 | 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] | 1737 | appctx->st0 = STAT_CLI_PRINT; |
| 1738 | return 1; |
| 1739 | } |
| 1740 | |
| 1741 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1742 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1743 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1744 | 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] | 1745 | appctx->st0 = STAT_CLI_PRINT; |
| 1746 | return 1; |
| 1747 | } |
| 1748 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1749 | /* If the entry identifier start with a '#', it is considered as |
| 1750 | * pointer id |
| 1751 | */ |
| 1752 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1753 | struct pat_ref_elt *ref; |
| 1754 | long long int conv; |
| 1755 | char *error; |
| 1756 | |
| 1757 | /* Convert argument to integer value. */ |
| 1758 | conv = strtoll(&args[3][1], &error, 16); |
| 1759 | if (*error != '\0') { |
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 | /* Convert and check integer to pointer. */ |
| 1766 | ref = (struct pat_ref_elt *)(long)conv; |
| 1767 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1768 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1769 | appctx->st0 = STAT_CLI_PRINT; |
| 1770 | return 1; |
| 1771 | } |
| 1772 | |
| 1773 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1774 | err = NULL; |
| 1775 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1776 | if (err) |
| 1777 | memprintf(&err, "%s.\n", err); |
| 1778 | appctx->ctx.cli.err = err; |
| 1779 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1780 | return 1; |
| 1781 | } |
| 1782 | } |
| 1783 | else { |
| 1784 | /* Else, use the entry identifier as pattern |
| 1785 | * string, and update the value. |
| 1786 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1787 | err = NULL; |
| 1788 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1789 | if (err) |
| 1790 | memprintf(&err, "%s.\n", err); |
| 1791 | appctx->ctx.cli.err = err; |
| 1792 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1793 | return 1; |
| 1794 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1795 | } |
| 1796 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1797 | /* The set is done, send message. */ |
Thierry FOURNIER | 73f1d8f | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1798 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1799 | return 1; |
| 1800 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1801 | #ifdef USE_OPENSSL |
| 1802 | else if (strcmp(args[1], "ssl") == 0) { |
| 1803 | if (strcmp(args[2], "ocsp-response") == 0) { |
| 1804 | #ifdef SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB |
| 1805 | char *err = NULL; |
| 1806 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 1807 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1808 | if (!*args[3]) { |
| 1809 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 1810 | appctx->st0 = STAT_CLI_PRINT; |
| 1811 | return 1; |
| 1812 | } |
| 1813 | |
| 1814 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 1815 | if (trash.len < 0) { |
| 1816 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 1817 | appctx->st0 = STAT_CLI_PRINT; |
| 1818 | return 1; |
| 1819 | } |
| 1820 | |
| 1821 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 1822 | if (err) { |
| 1823 | memprintf(&err, "%s.\n", err); |
| 1824 | appctx->ctx.cli.err = err; |
| 1825 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 1826 | } |
| 1827 | return 1; |
| 1828 | } |
| 1829 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 1830 | appctx->st0 = STAT_CLI_PRINT; |
| 1831 | return 1; |
| 1832 | #else |
| 1833 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 1834 | appctx->st0 = STAT_CLI_PRINT; |
| 1835 | return 1; |
| 1836 | #endif |
| 1837 | } |
| 1838 | else { |
| 1839 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 1840 | appctx->st0 = STAT_CLI_PRINT; |
| 1841 | return 1; |
| 1842 | } |
| 1843 | } |
| 1844 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1845 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1846 | return 0; |
| 1847 | } |
| 1848 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1849 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1850 | if (strcmp(args[1], "agent") == 0) { |
| 1851 | struct server *sv; |
| 1852 | |
| 1853 | sv = expect_server_admin(s, si, args[2]); |
| 1854 | if (!sv) |
| 1855 | return 1; |
| 1856 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1857 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1858 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1859 | appctx->st0 = STAT_CLI_PRINT; |
| 1860 | return 1; |
| 1861 | } |
| 1862 | |
| 1863 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1864 | return 1; |
| 1865 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1866 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1867 | struct server *sv; |
| 1868 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1869 | sv = expect_server_admin(s, si, args[2]); |
| 1870 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1871 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1872 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1873 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 1874 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 1875 | appctx->st0 = STAT_CLI_PRINT; |
| 1876 | return 1; |
| 1877 | } |
| 1878 | |
| 1879 | sv->check.state |= CHK_ST_ENABLED; |
| 1880 | return 1; |
| 1881 | } |
| 1882 | else if (strcmp(args[1], "server") == 0) { |
| 1883 | struct server *sv; |
| 1884 | |
| 1885 | sv = expect_server_admin(s, si, args[2]); |
| 1886 | if (!sv) |
| 1887 | return 1; |
| 1888 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1889 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1890 | return 1; |
| 1891 | } |
| 1892 | else if (strcmp(args[1], "frontend") == 0) { |
| 1893 | struct proxy *px; |
| 1894 | |
| 1895 | px = expect_frontend_admin(s, si, args[2]); |
| 1896 | if (!px) |
| 1897 | return 1; |
| 1898 | |
| 1899 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1900 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1901 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1902 | return 1; |
| 1903 | } |
| 1904 | |
| 1905 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1906 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1907 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1908 | return 1; |
| 1909 | } |
| 1910 | |
| 1911 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1912 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1913 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1914 | return 1; |
| 1915 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1916 | return 1; |
| 1917 | } |
| 1918 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1919 | 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] | 1920 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1921 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1922 | } |
| 1923 | } |
| 1924 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1925 | if (strcmp(args[1], "agent") == 0) { |
| 1926 | struct server *sv; |
| 1927 | |
| 1928 | sv = expect_server_admin(s, si, args[2]); |
| 1929 | if (!sv) |
| 1930 | return 1; |
| 1931 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1932 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1933 | return 1; |
| 1934 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1935 | else if (strcmp(args[1], "health") == 0) { |
| 1936 | struct server *sv; |
| 1937 | |
| 1938 | sv = expect_server_admin(s, si, args[2]); |
| 1939 | if (!sv) |
| 1940 | return 1; |
| 1941 | |
| 1942 | sv->check.state &= ~CHK_ST_ENABLED; |
| 1943 | return 1; |
| 1944 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1945 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1946 | struct server *sv; |
| 1947 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1948 | sv = expect_server_admin(s, si, args[2]); |
| 1949 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1950 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1951 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1952 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1953 | return 1; |
| 1954 | } |
| 1955 | else if (strcmp(args[1], "frontend") == 0) { |
| 1956 | struct proxy *px; |
| 1957 | |
| 1958 | px = expect_frontend_admin(s, si, args[2]); |
| 1959 | if (!px) |
| 1960 | return 1; |
| 1961 | |
| 1962 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1963 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1964 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1965 | return 1; |
| 1966 | } |
| 1967 | |
| 1968 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1969 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1970 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1971 | return 1; |
| 1972 | } |
| 1973 | |
| 1974 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1975 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1976 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1977 | return 1; |
| 1978 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1979 | return 1; |
| 1980 | } |
| 1981 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1982 | 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] | 1983 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1984 | return 1; |
| 1985 | } |
| 1986 | } |
| 1987 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1988 | if (strcmp(args[1], "frontend") == 0) { |
| 1989 | struct proxy *px; |
| 1990 | |
| 1991 | px = expect_frontend_admin(s, si, args[2]); |
| 1992 | if (!px) |
| 1993 | return 1; |
| 1994 | |
| 1995 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1996 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1997 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1998 | return 1; |
| 1999 | } |
| 2000 | |
| 2001 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2002 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2003 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2004 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2005 | stop_proxy(px); |
| 2006 | return 1; |
| 2007 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2008 | else if (strcmp(args[1], "session") == 0) { |
| 2009 | struct session *sess, *ptr; |
| 2010 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 2011 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2012 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2013 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2014 | return 1; |
| 2015 | } |
| 2016 | |
| 2017 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2018 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2019 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2020 | return 1; |
| 2021 | } |
| 2022 | |
| 2023 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2024 | |
| 2025 | /* first, look for the requested session in the session table */ |
| 2026 | list_for_each_entry(sess, &sessions, list) { |
| 2027 | if (sess == ptr) |
| 2028 | break; |
| 2029 | } |
| 2030 | |
| 2031 | /* do we have the session ? */ |
| 2032 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2033 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2034 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2035 | return 1; |
| 2036 | } |
| 2037 | |
| 2038 | session_shutdown(sess, SN_ERR_KILLED); |
| 2039 | return 1; |
| 2040 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2041 | else if (strcmp(args[1], "sessions") == 0) { |
| 2042 | if (strcmp(args[2], "server") == 0) { |
| 2043 | struct server *sv; |
| 2044 | struct session *sess, *sess_bck; |
| 2045 | |
| 2046 | sv = expect_server_admin(s, si, args[3]); |
| 2047 | if (!sv) |
| 2048 | return 1; |
| 2049 | |
| 2050 | /* kill all the session that are on this server */ |
| 2051 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2052 | if (sess->srv_conn == sv) |
| 2053 | session_shutdown(sess, SN_ERR_KILLED); |
| 2054 | |
| 2055 | return 1; |
| 2056 | } |
| 2057 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2058 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2059 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2060 | return 1; |
| 2061 | } |
| 2062 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2063 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2064 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2065 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2066 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2067 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2068 | } |
| 2069 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2070 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2071 | if (args[1][0] == 'm') |
| 2072 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2073 | else |
| 2074 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2075 | |
| 2076 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2077 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2078 | if (!*args[2] || !*args[3]) { |
| 2079 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2080 | appctx->st0 = STAT_CLI_PRINT; |
| 2081 | return 1; |
| 2082 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2083 | } |
| 2084 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2085 | else { |
| 2086 | if (!*args[2] || !*args[3]) { |
| 2087 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2088 | appctx->st0 = STAT_CLI_PRINT; |
| 2089 | return 1; |
| 2090 | } |
| 2091 | } |
| 2092 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2093 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2094 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2095 | if (!appctx->ctx.map.ref || |
| 2096 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2097 | 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] | 2098 | appctx->st0 = STAT_CLI_PRINT; |
| 2099 | return 1; |
| 2100 | } |
| 2101 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2102 | /* If the entry identifier start with a '#', it is considered as |
| 2103 | * pointer id |
| 2104 | */ |
| 2105 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2106 | struct pat_ref_elt *ref; |
| 2107 | long long int conv; |
| 2108 | char *error; |
| 2109 | |
| 2110 | /* Convert argument to integer value. */ |
| 2111 | conv = strtoll(&args[3][1], &error, 16); |
| 2112 | if (*error != '\0') { |
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 | /* Convert and check integer to pointer. */ |
| 2119 | ref = (struct pat_ref_elt *)(long)conv; |
| 2120 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2121 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2122 | appctx->st0 = STAT_CLI_PRINT; |
| 2123 | return 1; |
| 2124 | } |
| 2125 | |
| 2126 | /* Try to delete the entry. */ |
| 2127 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2128 | /* The entry is not found, send message. */ |
| 2129 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2130 | appctx->st0 = STAT_CLI_PRINT; |
| 2131 | return 1; |
| 2132 | } |
| 2133 | } |
| 2134 | else { |
| 2135 | /* Else, use the entry identifier as pattern |
| 2136 | * string and try to delete the entry. |
| 2137 | */ |
| 2138 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2139 | /* The entry is not found, send message. */ |
| 2140 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2141 | appctx->st0 = STAT_CLI_PRINT; |
| 2142 | return 1; |
| 2143 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2144 | } |
| 2145 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2146 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 73f1d8f | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2147 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2148 | return 1; |
| 2149 | } |
| 2150 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2151 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2152 | appctx->st0 = STAT_CLI_PRINT; |
| 2153 | return 1; |
| 2154 | } |
| 2155 | } |
| 2156 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2157 | if (strcmp(args[1], "map") == 0 || |
| 2158 | strcmp(args[1], "acl") == 0) { |
| 2159 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2160 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2161 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2162 | /* Set flags. */ |
| 2163 | if (args[1][0] == 'm') |
| 2164 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2165 | else |
| 2166 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2167 | |
| 2168 | /* If the keywork is "map", we expect three parameters, if it |
| 2169 | * is "acl", we expect only two parameters |
| 2170 | */ |
| 2171 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2172 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2173 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2174 | appctx->st0 = STAT_CLI_PRINT; |
| 2175 | return 1; |
| 2176 | } |
| 2177 | } |
| 2178 | else { |
| 2179 | if (!*args[2] || !*args[3]) { |
| 2180 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2181 | appctx->st0 = STAT_CLI_PRINT; |
| 2182 | return 1; |
| 2183 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2184 | } |
| 2185 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2186 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2187 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2188 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2189 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2190 | 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] | 2191 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2192 | 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] | 2193 | appctx->st0 = STAT_CLI_PRINT; |
| 2194 | return 1; |
| 2195 | } |
| 2196 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2197 | /* The command "add acl" is prohibited if the reference |
| 2198 | * use samples. |
| 2199 | */ |
| 2200 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2201 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2202 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2203 | "You must use the command 'add map' to add values.\n"; |
| 2204 | appctx->st0 = STAT_CLI_PRINT; |
| 2205 | return 1; |
| 2206 | } |
| 2207 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2208 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2209 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2210 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2211 | 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] | 2212 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2213 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2214 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2215 | if (err) |
| 2216 | memprintf(&err, "%s.\n", err); |
| 2217 | appctx->ctx.cli.err = err; |
| 2218 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2219 | return 1; |
| 2220 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2221 | |
| 2222 | /* The add is done, send message. */ |
Thierry FOURNIER | 73f1d8f | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2223 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2224 | return 1; |
| 2225 | } |
| 2226 | else { /* unknown "del" parameter */ |
| 2227 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2228 | appctx->st0 = STAT_CLI_PRINT; |
| 2229 | return 1; |
| 2230 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2231 | } |
| 2232 | 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] | 2233 | return 0; |
| 2234 | } |
| 2235 | return 1; |
| 2236 | } |
| 2237 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2238 | /* 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] | 2239 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2240 | * state machine handling requests and various responses. We read a request, |
| 2241 | * 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] | 2242 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2243 | * 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] | 2244 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2245 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2246 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2247 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2248 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2249 | struct channel *req = si->ob; |
| 2250 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2251 | int reql; |
| 2252 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2253 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2254 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2255 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2256 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2257 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2258 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2259 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2260 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2261 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2262 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2263 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2264 | /* Let's close for real now. We just close the request |
| 2265 | * side, the conditions below will complete if needed. |
| 2266 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2267 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2268 | break; |
| 2269 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2270 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2271 | /* ensure we have some output room left in the event we |
| 2272 | * would want to return some info right after parsing. |
| 2273 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2274 | if (buffer_almost_full(si->ib->buf)) { |
| 2275 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2276 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2277 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2278 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2279 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2280 | if (reql <= 0) { /* closed or EOL not found */ |
| 2281 | if (reql == 0) |
| 2282 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2283 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2284 | continue; |
| 2285 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2286 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2287 | /* seek for a possible semi-colon. If we find one, we |
| 2288 | * replace it with an LF and skip only this part. |
| 2289 | */ |
| 2290 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2291 | if (trash.str[len] == ';') { |
| 2292 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2293 | reql = len + 1; |
| 2294 | break; |
| 2295 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2296 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2297 | /* now it is time to check that we have a full line, |
| 2298 | * remove the trailing \n and possibly \r, then cut the |
| 2299 | * line. |
| 2300 | */ |
| 2301 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2302 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2303 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2304 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2305 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2306 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2307 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2308 | len--; |
| 2309 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2310 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2311 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2312 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2313 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2314 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2315 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2316 | continue; |
| 2317 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2318 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2319 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2320 | else if (strcmp(trash.str, "help") == 0 || |
| 2321 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2322 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2323 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2324 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2325 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2326 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2327 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2328 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2329 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2330 | /* if prompt is disabled, print help on empty lines, |
| 2331 | * so that the user at least knows how to enable |
| 2332 | * prompt and find help. |
| 2333 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2334 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2335 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2339 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2340 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2341 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2342 | 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] | 2343 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | e309ab7 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 2344 | cli_release_handler(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2345 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2346 | continue; |
| 2347 | } |
| 2348 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2349 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2350 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2351 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2352 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2353 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2354 | case STAT_CLI_PRINT_FREE: |
| 2355 | if (bi_putstr(si->ib, appctx->ctx.cli.err) != -1) { |
| 2356 | free(appctx->ctx.cli.err); |
| 2357 | appctx->st0 = STAT_CLI_PROMPT; |
| 2358 | } |
| 2359 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2360 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2361 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2362 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2363 | break; |
| 2364 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2365 | if (stats_dump_stat_to_buffer(si, NULL)) |
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 | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2368 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2369 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2370 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2371 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2372 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2373 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2374 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2375 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2376 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2377 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2378 | if (stats_table_request(si, appctx->st0)) |
| 2379 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2380 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2381 | case STAT_CLI_O_PATS: |
| 2382 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2383 | appctx->st0 = STAT_CLI_PROMPT; |
| 2384 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2385 | case STAT_CLI_O_PAT: |
| 2386 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2387 | appctx->st0 = STAT_CLI_PROMPT; |
| 2388 | break; |
| 2389 | case STAT_CLI_O_MLOOK: |
| 2390 | if (stats_map_lookup(si)) |
| 2391 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2392 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2393 | case STAT_CLI_O_POOLS: |
| 2394 | if (stats_dump_pools_to_buffer(si)) |
| 2395 | appctx->st0 = STAT_CLI_PROMPT; |
| 2396 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2397 | default: /* abnormal state */ |
Willy Tarreau | e309ab7 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 2398 | cli_release_handler(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2399 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2400 | break; |
| 2401 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2402 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2403 | /* 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] | 2404 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2405 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2406 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2407 | } |
| 2408 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2409 | /* 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] | 2410 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2411 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2412 | |
| 2413 | /* Now we close the output if one of the writers did so, |
| 2414 | * or if we're not in interactive mode and the request |
| 2415 | * buffer is empty. This still allows pipelined requests |
| 2416 | * to be sent in non-interactive mode. |
| 2417 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2418 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2419 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2420 | continue; |
| 2421 | } |
| 2422 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2423 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2424 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2425 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2426 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2427 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2428 | 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] | 2429 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2430 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2431 | /* 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] | 2432 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2433 | * we forward the close to the request side so that it flows upstream to |
| 2434 | * the client. |
| 2435 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2436 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2437 | } |
| 2438 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2439 | 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] | 2440 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2441 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2442 | /* We have no more processing to do, and nothing more to send, and |
| 2443 | * the client side has closed. So we'll forward this state downstream |
| 2444 | * on the response buffer. |
| 2445 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2446 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2447 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2451 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2452 | |
| 2453 | /* we don't want to expire timeouts while we're processing requests */ |
| 2454 | si->ib->rex = TICK_ETERNITY; |
| 2455 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2456 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2457 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2458 | 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] | 2459 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2460 | 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] | 2461 | |
| 2462 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2463 | /* check that we have released everything then unregister */ |
| 2464 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2465 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2466 | } |
| 2467 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2468 | /* This function dumps information onto the stream interface's read buffer. |
| 2469 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2470 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2471 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2472 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2473 | { |
| 2474 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2475 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2476 | #ifdef USE_OPENSSL |
| 2477 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2478 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2479 | int ssl_reuse = 0; |
| 2480 | |
| 2481 | if (ssl_key_rate < ssl_sess_rate) { |
| 2482 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2483 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2484 | } |
| 2485 | #endif |
| 2486 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2487 | chunk_printf(&trash, |
| 2488 | "Name: " PRODUCT_NAME "\n" |
| 2489 | "Version: " HAPROXY_VERSION "\n" |
| 2490 | "Release_date: " HAPROXY_DATE "\n" |
| 2491 | "Nbproc: %d\n" |
| 2492 | "Process_num: %d\n" |
| 2493 | "Pid: %d\n" |
| 2494 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2495 | "Uptime_sec: %d\n" |
| 2496 | "Memmax_MB: %d\n" |
| 2497 | "Ulimit-n: %d\n" |
| 2498 | "Maxsock: %d\n" |
| 2499 | "Maxconn: %d\n" |
| 2500 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2501 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2502 | "CumConns: %d\n" |
Warren Turkal | bc4e62d | 2015-01-27 15:04:16 -0800 | [diff] [blame] | 2503 | "CumReq: %u\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2504 | #ifdef USE_OPENSSL |
| 2505 | "MaxSslConns: %d\n" |
| 2506 | "CurrSslConns: %d\n" |
| 2507 | "CumSslConns: %d\n" |
| 2508 | #endif |
| 2509 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2510 | "PipesUsed: %d\n" |
| 2511 | "PipesFree: %d\n" |
| 2512 | "ConnRate: %d\n" |
| 2513 | "ConnRateLimit: %d\n" |
| 2514 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2515 | "SessRate: %d\n" |
| 2516 | "SessRateLimit: %d\n" |
| 2517 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2518 | #ifdef USE_OPENSSL |
| 2519 | "SslRate: %d\n" |
| 2520 | "SslRateLimit: %d\n" |
| 2521 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2522 | "SslFrontendKeyRate: %d\n" |
| 2523 | "SslFrontendMaxKeyRate: %d\n" |
| 2524 | "SslFrontendSessionReuse_pct: %d\n" |
| 2525 | "SslBackendKeyRate: %d\n" |
| 2526 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2527 | "SslCacheLookups: %u\n" |
| 2528 | "SslCacheMisses: %u\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2529 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2530 | "CompressBpsIn: %u\n" |
| 2531 | "CompressBpsOut: %u\n" |
| 2532 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2533 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2534 | "ZlibMemUsage: %ld\n" |
| 2535 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2536 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2537 | "Tasks: %d\n" |
| 2538 | "Run_queue: %d\n" |
| 2539 | "Idle_pct: %d\n" |
| 2540 | "node: %s\n" |
| 2541 | "description: %s\n" |
| 2542 | "", |
| 2543 | global.nbproc, |
| 2544 | relative_pid, |
| 2545 | pid, |
| 2546 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2547 | up, |
| 2548 | global.rlimit_memmax, |
| 2549 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2550 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2551 | actconn, totalconn, global.req_count, |
| 2552 | #ifdef USE_OPENSSL |
| 2553 | global.maxsslconn, sslconns, totalsslconns, |
| 2554 | #endif |
| 2555 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2556 | 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] | 2557 | 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] | 2558 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2559 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2560 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2561 | ssl_reuse, |
| 2562 | 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] | 2563 | global.shctx_lookups, global.shctx_misses, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2564 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2565 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2566 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2567 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2568 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2569 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2570 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2571 | global.node, global.desc ? global.desc : "" |
| 2572 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2573 | |
| 2574 | if (bi_putchk(si->ib, &trash) == -1) |
| 2575 | return 0; |
| 2576 | |
| 2577 | return 1; |
| 2578 | } |
| 2579 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2580 | /* This function dumps memory usage information onto the stream interface's |
| 2581 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2582 | * completion. No state is used. |
| 2583 | */ |
| 2584 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2585 | { |
| 2586 | dump_pools_to_trash(); |
| 2587 | if (bi_putchk(si->ib, &trash) == -1) |
| 2588 | return 0; |
| 2589 | return 1; |
| 2590 | } |
| 2591 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2592 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2593 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2594 | * 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] | 2595 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2596 | 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] | 2597 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2598 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2599 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2600 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2601 | if (!(px->cap & PR_CAP_FE)) |
| 2602 | return 0; |
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 ((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] | 2605 | return 0; |
| 2606 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2607 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2608 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2609 | /* name, queue */ |
| 2610 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2611 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2612 | if (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] | 2613 | /* Column sub-heading for Enable or Disable server */ |
| 2614 | chunk_appendf(&trash, "<td></td>"); |
| 2615 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2616 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2617 | chunk_appendf(&trash, |
| 2618 | "<td class=ac>" |
| 2619 | "<a name=\"%s/Frontend\"></a>" |
| 2620 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2621 | "<td colspan=3></td>" |
| 2622 | "", |
| 2623 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2624 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2625 | chunk_appendf(&trash, |
| 2626 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2627 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2628 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2629 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2630 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2631 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2632 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2633 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2634 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2635 | if (px->mode == PR_MODE_HTTP) |
| 2636 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2637 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2638 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2639 | |
| 2640 | chunk_appendf(&trash, |
| 2641 | "</table></div></u></td>" |
| 2642 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2643 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2644 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2645 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2646 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2647 | U2H(px->fe_counters.sps_max), |
| 2648 | U2H(px->fe_counters.cps_max), |
| 2649 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2650 | |
| 2651 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2652 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2653 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2654 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2655 | |
| 2656 | chunk_appendf(&trash, |
| 2657 | "</table></div></u></td>" |
| 2658 | /* sessions rate : limit */ |
| 2659 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2660 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2661 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2662 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2663 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2664 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2665 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2666 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2667 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2668 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2669 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2670 | U2H(px->fe_counters.cum_sess), |
| 2671 | U2H(px->fe_counters.cum_conn), |
| 2672 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2673 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2674 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2675 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2676 | chunk_appendf(&trash, |
| 2677 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2678 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2679 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2680 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2681 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2682 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2683 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2684 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2685 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2686 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2687 | U2H(px->fe_counters.p.http.cum_req), |
| 2688 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2689 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2690 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2691 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2692 | (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] | 2693 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2694 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2695 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2696 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2697 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2698 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2699 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2700 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2701 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2702 | /* sessions: lbtot, lastsess */ |
| 2703 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2704 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2705 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2706 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2707 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2708 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2709 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2710 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2711 | "<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] | 2712 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2713 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2714 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2715 | px->fe_counters.comp_in ? |
| 2716 | (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] | 2717 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2718 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2719 | chunk_appendf(&trash, |
| 2720 | /* denied: req, resp */ |
| 2721 | "<td>%s</td><td>%s</td>" |
| 2722 | /* errors : request, connect, response */ |
| 2723 | "<td>%s</td><td></td><td></td>" |
| 2724 | /* warnings: retries, redispatches */ |
| 2725 | "<td></td><td></td>" |
| 2726 | /* server status : reflect frontend status */ |
| 2727 | "<td class=ac>%s</td>" |
| 2728 | /* rest of server: nothing */ |
| 2729 | "<td class=ac colspan=8></td></tr>" |
| 2730 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2731 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2732 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2733 | px->state == PR_STREADY ? "OPEN" : |
| 2734 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2735 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2736 | else { /* CSV mode */ |
| 2737 | chunk_appendf(&trash, |
| 2738 | /* pxid, name, queue cur, queue max, */ |
| 2739 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2740 | /* sessions : current, max, limit, total */ |
| 2741 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2742 | /* bytes : in, out */ |
| 2743 | "%lld,%lld," |
| 2744 | /* denied: req, resp */ |
| 2745 | "%lld,%lld," |
| 2746 | /* errors : request, connect, response */ |
| 2747 | "%lld,,," |
| 2748 | /* warnings: retries, redispatches */ |
| 2749 | ",," |
| 2750 | /* server status : reflect frontend status */ |
| 2751 | "%s," |
| 2752 | /* rest of server: nothing */ |
| 2753 | ",,,,,,,," |
| 2754 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2755 | "%d,%d,0,,,,%d," |
| 2756 | /* rate, rate_lim, rate_max */ |
| 2757 | "%u,%u,%u," |
| 2758 | /* check_status, check_code, check_duration */ |
| 2759 | ",,,", |
| 2760 | px->id, |
| 2761 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2762 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2763 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2764 | px->fe_counters.failed_req, |
| 2765 | px->state == PR_STREADY ? "OPEN" : |
| 2766 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2767 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2768 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2769 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2770 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2771 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2772 | if (px->mode == PR_MODE_HTTP) { |
| 2773 | for (i=1; i<6; i++) |
| 2774 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2775 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2776 | } |
| 2777 | else |
| 2778 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2779 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2780 | /* failed health analyses */ |
| 2781 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2782 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2783 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2784 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2785 | read_freq_ctr(&px->fe_req_per_sec), |
| 2786 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2787 | |
| 2788 | /* errors: cli_aborts, srv_aborts */ |
| 2789 | chunk_appendf(&trash, ",,"); |
| 2790 | |
| 2791 | /* compression: in, out, bypassed */ |
| 2792 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2793 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2794 | |
| 2795 | /* compression: comp_rsp */ |
| 2796 | chunk_appendf(&trash, "%lld,", |
| 2797 | px->fe_counters.p.http.comp_rsp); |
| 2798 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2799 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2800 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2801 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2802 | /* finish with EOL */ |
| 2803 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2804 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2805 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2806 | } |
| 2807 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2808 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2809 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2810 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2811 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2812 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2813 | 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] | 2814 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2815 | struct appctx *appctx = __objt_appctx(si->end); |
| 2816 | |
| 2817 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2818 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2819 | 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] | 2820 | /* Column sub-heading for Enable or Disable server */ |
| 2821 | chunk_appendf(&trash, "<td></td>"); |
| 2822 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2823 | chunk_appendf(&trash, |
| 2824 | /* frontend name, listener name */ |
| 2825 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2826 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2827 | "", |
| 2828 | px->id, l->name, |
| 2829 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2830 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2831 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2832 | if (flags & ST_SHLGNDS) { |
| 2833 | char str[INET6_ADDRSTRLEN]; |
| 2834 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2835 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2836 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2837 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2838 | port = get_host_port(&l->addr); |
| 2839 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2840 | case AF_INET: |
| 2841 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2842 | break; |
| 2843 | case AF_INET6: |
| 2844 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2845 | break; |
| 2846 | case AF_UNIX: |
| 2847 | chunk_appendf(&trash, "unix, "); |
| 2848 | break; |
| 2849 | case -1: |
| 2850 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2851 | break; |
| 2852 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2853 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2854 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2855 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2856 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2857 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2858 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2859 | /* queue */ |
| 2860 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2861 | /* sessions rate: current, max, limit */ |
| 2862 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2863 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2864 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2865 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2866 | /* bytes: in, out */ |
| 2867 | "<td>%s</td><td>%s</td>" |
| 2868 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2869 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2870 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2871 | 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] | 2872 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2873 | chunk_appendf(&trash, |
| 2874 | /* denied: req, resp */ |
| 2875 | "<td>%s</td><td>%s</td>" |
| 2876 | /* errors: request, connect, response */ |
| 2877 | "<td>%s</td><td></td><td></td>" |
| 2878 | /* warnings: retries, redispatches */ |
| 2879 | "<td></td><td></td>" |
| 2880 | /* server status: reflect listener status */ |
| 2881 | "<td class=ac>%s</td>" |
| 2882 | /* rest of server: nothing */ |
| 2883 | "<td class=ac colspan=8></td></tr>" |
| 2884 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2885 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2886 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2887 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2888 | } |
| 2889 | else { /* CSV mode */ |
| 2890 | chunk_appendf(&trash, |
| 2891 | /* pxid, name, queue cur, queue max, */ |
| 2892 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2893 | /* sessions: current, max, limit, total */ |
| 2894 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2895 | /* bytes: in, out */ |
| 2896 | "%lld,%lld," |
| 2897 | /* denied: req, resp */ |
| 2898 | "%lld,%lld," |
| 2899 | /* errors: request, connect, response */ |
| 2900 | "%lld,,," |
| 2901 | /* warnings: retries, redispatches */ |
| 2902 | ",," |
| 2903 | /* server status: reflect listener status */ |
| 2904 | "%s," |
| 2905 | /* rest of server: nothing */ |
| 2906 | ",,,,,,,," |
| 2907 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2908 | "%d,%d,%d,,,,%d," |
| 2909 | /* rate, rate_lim, rate_max */ |
| 2910 | ",,," |
| 2911 | /* check_status, check_code, check_duration */ |
| 2912 | ",,," |
| 2913 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2914 | ",,,,,," |
| 2915 | /* failed health analyses */ |
| 2916 | "," |
| 2917 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2918 | ",,," |
| 2919 | /* errors: cli_aborts, srv_aborts */ |
| 2920 | ",," |
| 2921 | /* compression: in, out, bypassed, comp_rsp */ |
| 2922 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2923 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2924 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2925 | "\n", |
| 2926 | px->id, l->name, |
| 2927 | l->nbconn, l->counters->conn_max, |
| 2928 | l->maxconn, l->counters->cum_conn, |
| 2929 | l->counters->bytes_in, l->counters->bytes_out, |
| 2930 | l->counters->denied_req, l->counters->denied_resp, |
| 2931 | l->counters->failed_req, |
| 2932 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2933 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2934 | } |
| 2935 | return 1; |
| 2936 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2937 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2938 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2939 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2940 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2941 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2942 | * following values : 0=DOWN, 1=DOWN(agent) 2=going up, 3=going down, 4=UP, 5,6=NOLB, |
| 2943 | * 7,8=DRAIN, 9=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2944 | */ |
| 2945 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2946 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2947 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2948 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2949 | char str[INET6_ADDRSTRLEN]; |
| 2950 | struct chunk src; |
| 2951 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2952 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2953 | /* we have "via" which is the tracked server as described in the configuration, |
| 2954 | * and "ref" which is the checked server and the end of the chain. |
| 2955 | */ |
| 2956 | via = sv->track ? sv->track : sv; |
| 2957 | ref = via; |
| 2958 | while (ref->track) |
| 2959 | ref = ref->track; |
| 2960 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2961 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2962 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2963 | "DOWN", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2964 | "DOWN (agent)", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2965 | "DN %d/%d ↑", |
| 2966 | "UP %d/%d ↓", |
| 2967 | "UP", |
| 2968 | "NOLB %d/%d ↓", |
| 2969 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2970 | "DRAIN %d/%d ↓", |
| 2971 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2972 | "<i>no check</i>" |
| 2973 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2974 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 2975 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2976 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2977 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2978 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2979 | "<tr class=\"%s%d\">", |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 2980 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2981 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2982 | 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] | 2983 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2984 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2985 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2986 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2987 | chunk_appendf(&trash, |
| 2988 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2989 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2990 | "", |
| 2991 | px->id, sv->id, |
| 2992 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2993 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2994 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2995 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2996 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2997 | |
| 2998 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2999 | case AF_INET: |
| 3000 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 3001 | break; |
| 3002 | case AF_INET6: |
| 3003 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 3004 | break; |
| 3005 | case AF_UNIX: |
| 3006 | chunk_appendf(&trash, "unix, "); |
| 3007 | break; |
| 3008 | case -1: |
| 3009 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3010 | break; |
| 3011 | default: /* address family not supported */ |
| 3012 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3013 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3014 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3015 | /* id */ |
| 3016 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3017 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3018 | /* cookie */ |
| 3019 | if (sv->cookie) { |
| 3020 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3021 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3022 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3023 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3024 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3025 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3026 | } |
| 3027 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3028 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3029 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3030 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3031 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3032 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3033 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3034 | /* sessions rate : current, max, limit */ |
| 3035 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3036 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3037 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3038 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3039 | 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] | 3040 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3041 | |
| 3042 | chunk_appendf(&trash, |
| 3043 | /* sessions: current, max, limit, total */ |
| 3044 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3045 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3046 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3047 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3048 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3049 | U2H(sv->counters.cum_sess), |
| 3050 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3051 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3052 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3053 | if (px->mode == PR_MODE_HTTP) { |
| 3054 | unsigned long long tot; |
| 3055 | for (tot = i = 0; i < 6; i++) |
| 3056 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3057 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3058 | chunk_appendf(&trash, |
| 3059 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3060 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3061 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3062 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3063 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3064 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3065 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3066 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3067 | U2H(tot), |
| 3068 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3069 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3070 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3071 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3072 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3073 | 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] | 3074 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3075 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3076 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3077 | 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))); |
| 3078 | 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))); |
| 3079 | if (px->mode == PR_MODE_HTTP) |
| 3080 | 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))); |
| 3081 | 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))); |
| 3082 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3083 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3084 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3085 | /* sessions: lbtot, last */ |
| 3086 | "<td>%s</td><td>%s</td>", |
| 3087 | U2H(sv->counters.cum_lbconn), |
| 3088 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3089 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3090 | chunk_appendf(&trash, |
| 3091 | /* bytes : in, out */ |
| 3092 | "<td>%s</td><td>%s</td>" |
| 3093 | /* denied: req, resp */ |
| 3094 | "<td></td><td>%s</td>" |
| 3095 | /* errors : request, connect */ |
| 3096 | "<td></td><td>%s</td>" |
| 3097 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3098 | "<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] | 3099 | /* warnings: retries, redispatches */ |
| 3100 | "<td>%lld</td><td>%lld</td>" |
| 3101 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3102 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3103 | U2H(sv->counters.failed_secu), |
| 3104 | U2H(sv->counters.failed_conns), |
| 3105 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3106 | sv->counters.cli_aborts, |
| 3107 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3108 | sv->counters.retries, sv->counters.redispatches); |
| 3109 | |
| 3110 | /* status, lest check */ |
| 3111 | chunk_appendf(&trash, "<td class=ac>"); |
| 3112 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3113 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3114 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3115 | chunk_appendf(&trash, "MAINT"); |
| 3116 | } |
Simon Horman | 8eccbf7 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3117 | 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] | 3118 | 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] | 3119 | /* DOWN (agent) */ |
| 3120 | 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] | 3121 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3122 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3123 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3124 | chunk_appendf(&trash, |
| 3125 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3126 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3127 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3128 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3129 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3130 | if ((sv->state == SRV_ST_STOPPED) && |
| 3131 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3132 | chunk_appendf(&trash, |
| 3133 | "</td><td class=ac><u> %s%s", |
| 3134 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3135 | get_check_status_info(sv->agent.status)); |
| 3136 | |
| 3137 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3138 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3139 | |
| 3140 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3141 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3142 | |
| 3143 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3144 | get_check_status_description(sv->agent.status)); |
| 3145 | if (*sv->agent.desc) { |
| 3146 | chunk_appendf(&trash, ": "); |
| 3147 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3148 | chunk_htmlencode(&trash, &src); |
| 3149 | } |
| 3150 | chunk_appendf(&trash, "</div></u>"); |
| 3151 | } |
| 3152 | 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] | 3153 | chunk_appendf(&trash, |
| 3154 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3155 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3156 | get_check_status_info(sv->check.status)); |
| 3157 | |
| 3158 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3159 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3160 | |
| 3161 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3162 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3163 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3164 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3165 | get_check_status_description(sv->check.status)); |
| 3166 | if (*sv->check.desc) { |
| 3167 | chunk_appendf(&trash, ": "); |
| 3168 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3169 | chunk_htmlencode(&trash, &src); |
| 3170 | } |
| 3171 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3172 | } |
| 3173 | else |
| 3174 | chunk_appendf(&trash, "</td><td>"); |
| 3175 | |
| 3176 | chunk_appendf(&trash, |
| 3177 | /* weight */ |
| 3178 | "</td><td class=ac>%d</td>" |
| 3179 | /* act, bck */ |
| 3180 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3181 | "", |
| 3182 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3183 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3184 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3185 | |
| 3186 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3187 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3188 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3189 | |
| 3190 | if (ref->observe) |
| 3191 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3192 | |
| 3193 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3194 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3195 | "<td>%lld</td><td>%s</td>" |
| 3196 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3197 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3198 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3199 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3200 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3201 | /* tracking a server */ |
| 3202 | chunk_appendf(&trash, |
| 3203 | "<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] | 3204 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3205 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3206 | else |
| 3207 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3208 | |
| 3209 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3210 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3211 | 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] | 3212 | else |
| 3213 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3214 | } |
| 3215 | else { /* CSV mode */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3216 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3217 | "DOWN,", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3218 | "DOWN (agent),", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3219 | "DOWN %d/%d,", |
| 3220 | "UP %d/%d,", |
| 3221 | "UP,", |
| 3222 | "NOLB %d/%d,", |
| 3223 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3224 | "DRAIN %d/%d,", |
| 3225 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3226 | "no check," |
| 3227 | }; |
| 3228 | |
| 3229 | chunk_appendf(&trash, |
| 3230 | /* pxid, name */ |
| 3231 | "%s,%s," |
| 3232 | /* queue : current, max */ |
| 3233 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3234 | /* sessions : current, max, limit, total */ |
| 3235 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3236 | /* bytes : in, out */ |
| 3237 | "%lld,%lld," |
| 3238 | /* denied: req, resp */ |
| 3239 | ",%lld," |
| 3240 | /* errors : request, connect, response */ |
| 3241 | ",%lld,%lld," |
| 3242 | /* warnings: retries, redispatches */ |
| 3243 | "%lld,%lld," |
| 3244 | "", |
| 3245 | px->id, sv->id, |
| 3246 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3247 | 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] | 3248 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3249 | sv->counters.failed_secu, |
| 3250 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3251 | sv->counters.retries, sv->counters.redispatches); |
| 3252 | |
| 3253 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3254 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3255 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3256 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3257 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3258 | else |
| 3259 | chunk_appendf(&trash, |
| 3260 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3261 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3262 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3263 | |
| 3264 | chunk_appendf(&trash, |
| 3265 | /* weight, active, backup */ |
| 3266 | "%d,%d,%d," |
| 3267 | "", |
| 3268 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3269 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3270 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3271 | |
| 3272 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3273 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3274 | chunk_appendf(&trash, |
| 3275 | "%lld,%lld,%d,%d,", |
| 3276 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3277 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3278 | else |
| 3279 | chunk_appendf(&trash, ",,,,"); |
| 3280 | |
| 3281 | /* queue limit, pid, iid, sid, */ |
| 3282 | chunk_appendf(&trash, |
| 3283 | "%s," |
| 3284 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3285 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3286 | relative_pid, px->uuid, sv->puid); |
| 3287 | |
| 3288 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3289 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3290 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3291 | |
| 3292 | /* sessions: lbtot */ |
| 3293 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3294 | |
| 3295 | /* tracked */ |
| 3296 | if (sv->track) |
| 3297 | chunk_appendf(&trash, "%s/%s,", |
| 3298 | sv->track->proxy->id, sv->track->id); |
| 3299 | else |
| 3300 | chunk_appendf(&trash, ","); |
| 3301 | |
| 3302 | /* type */ |
| 3303 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3304 | |
| 3305 | /* rate */ |
| 3306 | chunk_appendf(&trash, "%u,,%u,", |
| 3307 | read_freq_ctr(&sv->sess_per_sec), |
| 3308 | sv->counters.sps_max); |
| 3309 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3310 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3311 | /* check_status */ |
| 3312 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3313 | |
| 3314 | /* check_code */ |
| 3315 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3316 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3317 | else |
| 3318 | chunk_appendf(&trash, ","); |
| 3319 | |
| 3320 | /* check_duration */ |
| 3321 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3322 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3323 | else |
| 3324 | chunk_appendf(&trash, ","); |
| 3325 | |
| 3326 | } |
| 3327 | else |
| 3328 | chunk_appendf(&trash, ",,,"); |
| 3329 | |
| 3330 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3331 | if (px->mode == PR_MODE_HTTP) { |
| 3332 | for (i=1; i<6; i++) |
| 3333 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3334 | |
| 3335 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3336 | } |
| 3337 | else |
| 3338 | chunk_appendf(&trash, ",,,,,,"); |
| 3339 | |
| 3340 | /* failed health analyses */ |
| 3341 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3342 | |
| 3343 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3344 | chunk_appendf(&trash, ",,,"); |
| 3345 | |
| 3346 | /* errors: cli_aborts, srv_aborts */ |
| 3347 | chunk_appendf(&trash, "%lld,%lld,", |
| 3348 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3349 | |
| 3350 | /* compression: in, out, bypassed, comp_rsp */ |
| 3351 | chunk_appendf(&trash, ",,,,"); |
| 3352 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3353 | /* lastsess */ |
| 3354 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3355 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3356 | /* capture of last check and agent statuses */ |
| 3357 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->check.desc) : ""); |
| 3358 | chunk_appendf(&trash, "%s,", ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->agent.desc) : ""); |
| 3359 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3360 | /* qtime, ctime, rtime, ttime, */ |
| 3361 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3362 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3363 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3364 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3365 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3366 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3367 | /* finish with EOL */ |
| 3368 | chunk_appendf(&trash, "\n"); |
| 3369 | } |
| 3370 | return 1; |
| 3371 | } |
| 3372 | |
| 3373 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3374 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3375 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3376 | */ |
| 3377 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3378 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3379 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3380 | struct chunk src; |
| 3381 | int i; |
| 3382 | |
| 3383 | if (!(px->cap & PR_CAP_BE)) |
| 3384 | return 0; |
| 3385 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3386 | 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] | 3387 | return 0; |
| 3388 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3389 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3390 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3391 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3392 | /* Column sub-heading for Enable or Disable server */ |
| 3393 | chunk_appendf(&trash, "<td></td>"); |
| 3394 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3395 | chunk_appendf(&trash, |
| 3396 | "<td class=ac>" |
| 3397 | /* name */ |
| 3398 | "%s<a name=\"%s/Backend\"></a>" |
| 3399 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3400 | "", |
| 3401 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3402 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3403 | |
| 3404 | if (flags & ST_SHLGNDS) { |
| 3405 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3406 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3407 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3408 | |
| 3409 | /* cookie */ |
| 3410 | if (px->cookie_name) { |
| 3411 | chunk_appendf(&trash, ", cookie: '"); |
| 3412 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3413 | chunk_htmlencode(&trash, &src); |
| 3414 | chunk_appendf(&trash, "'"); |
| 3415 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3416 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3417 | } |
| 3418 | |
| 3419 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3420 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3421 | /* queue : current, max */ |
| 3422 | "<td>%s</td><td>%s</td><td></td>" |
| 3423 | /* sessions rate : current, max, limit */ |
| 3424 | "<td>%s</td><td>%s</td><td></td>" |
| 3425 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3426 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3427 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3428 | 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] | 3429 | |
| 3430 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3431 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3432 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3433 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3434 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3435 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3436 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3437 | U2H(px->be_counters.cum_conn), |
| 3438 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3439 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3440 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3441 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3442 | chunk_appendf(&trash, |
| 3443 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3444 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3445 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3446 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3447 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3448 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3449 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3450 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3451 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3452 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3453 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3454 | U2H(px->be_counters.p.http.cum_req), |
| 3455 | U2H(px->be_counters.p.http.rsp[1]), |
| 3456 | U2H(px->be_counters.p.http.rsp[2]), |
| 3457 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3458 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3459 | (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] | 3460 | U2H(px->be_counters.p.http.rsp[3]), |
| 3461 | U2H(px->be_counters.p.http.rsp[4]), |
| 3462 | U2H(px->be_counters.p.http.rsp[5]), |
| 3463 | U2H(px->be_counters.p.http.rsp[0]), |
| 3464 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3465 | } |
| 3466 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3467 | 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))); |
| 3468 | 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))); |
| 3469 | if (px->mode == PR_MODE_HTTP) |
| 3470 | 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))); |
| 3471 | 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))); |
| 3472 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3473 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3474 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3475 | /* sessions: lbtot, last */ |
| 3476 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3477 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3478 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3479 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3480 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3481 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3482 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3483 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3484 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3485 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3486 | "<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] | 3487 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3488 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3489 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3490 | px->be_counters.comp_in ? |
| 3491 | (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] | 3492 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3493 | |
| 3494 | chunk_appendf(&trash, |
| 3495 | /* denied: req, resp */ |
| 3496 | "<td>%s</td><td>%s</td>" |
| 3497 | /* errors : request, connect */ |
| 3498 | "<td></td><td>%s</td>" |
| 3499 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3500 | "<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] | 3501 | /* warnings: retries, redispatches */ |
| 3502 | "<td>%lld</td><td>%lld</td>" |
| 3503 | /* backend status: reflect backend status (up/down): we display UP |
| 3504 | * if the backend has known working servers or if it has no server at |
| 3505 | * all (eg: for stats). Then we display the total weight, number of |
| 3506 | * active and backups. */ |
| 3507 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3508 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3509 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3510 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3511 | U2H(px->be_counters.failed_conns), |
| 3512 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3513 | px->be_counters.cli_aborts, |
| 3514 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3515 | px->be_counters.retries, px->be_counters.redispatches, |
| 3516 | human_time(now.tv_sec - px->last_change, 1), |
| 3517 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3518 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3519 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3520 | px->srv_act, px->srv_bck); |
| 3521 | |
| 3522 | chunk_appendf(&trash, |
| 3523 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3524 | "<td class=ac> </td><td>%d</td>" |
| 3525 | "<td>%s</td>" |
| 3526 | "<td></td>" |
| 3527 | "</tr>", |
| 3528 | px->down_trans, |
| 3529 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3530 | } |
| 3531 | else { /* CSV mode */ |
| 3532 | chunk_appendf(&trash, |
| 3533 | /* pxid, name */ |
| 3534 | "%s,BACKEND," |
| 3535 | /* queue : current, max */ |
| 3536 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3537 | /* sessions : current, max, limit, total */ |
| 3538 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3539 | /* bytes : in, out */ |
| 3540 | "%lld,%lld," |
| 3541 | /* denied: req, resp */ |
| 3542 | "%lld,%lld," |
| 3543 | /* errors : request, connect, response */ |
| 3544 | ",%lld,%lld," |
| 3545 | /* warnings: retries, redispatches */ |
| 3546 | "%lld,%lld," |
| 3547 | /* backend status: reflect backend status (up/down): we display UP |
| 3548 | * if the backend has known working servers or if it has no server at |
| 3549 | * all (eg: for stats). Then we display the total weight, number of |
| 3550 | * active and backups. */ |
| 3551 | "%s," |
| 3552 | "%d,%d,%d," |
| 3553 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3554 | ",%d,%d,%d,," |
| 3555 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3556 | "%d,%d,0,,%lld,,%d," |
| 3557 | /* rate, rate_lim, rate_max, */ |
| 3558 | "%u,,%u," |
| 3559 | /* check_status, check_code, check_duration */ |
| 3560 | ",,,", |
| 3561 | px->id, |
| 3562 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3563 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3564 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3565 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3566 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3567 | px->be_counters.retries, px->be_counters.redispatches, |
| 3568 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3569 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3570 | px->srv_act, px->srv_bck, |
| 3571 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3572 | px->srv?be_downtime(px):0, |
| 3573 | relative_pid, px->uuid, |
| 3574 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3575 | read_freq_ctr(&px->be_sess_per_sec), |
| 3576 | px->be_counters.sps_max); |
| 3577 | |
| 3578 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3579 | if (px->mode == PR_MODE_HTTP) { |
| 3580 | for (i=1; i<6; i++) |
| 3581 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3582 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3583 | } |
| 3584 | else |
| 3585 | chunk_appendf(&trash, ",,,,,,"); |
| 3586 | |
| 3587 | /* failed health analyses */ |
| 3588 | chunk_appendf(&trash, ","); |
| 3589 | |
| 3590 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3591 | chunk_appendf(&trash, ",,,"); |
| 3592 | |
| 3593 | /* errors: cli_aborts, srv_aborts */ |
| 3594 | chunk_appendf(&trash, "%lld,%lld,", |
| 3595 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3596 | |
| 3597 | /* compression: in, out, bypassed */ |
| 3598 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3599 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3600 | |
| 3601 | /* compression: comp_rsp */ |
| 3602 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3603 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3604 | /* lastsess, last_chk, last_agt, */ |
| 3605 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3606 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3607 | /* qtime, ctime, rtime, ttime, */ |
| 3608 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3609 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 3610 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 3611 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 3612 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 3613 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3614 | /* finish with EOL */ |
| 3615 | chunk_appendf(&trash, "\n"); |
| 3616 | } |
| 3617 | return 1; |
| 3618 | } |
| 3619 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3620 | /* 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] | 3621 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3622 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3623 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3624 | 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] | 3625 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3626 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3627 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3628 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3629 | 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] | 3630 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3631 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3632 | /* 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] | 3633 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3634 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3635 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3636 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3637 | 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] | 3638 | } |
| 3639 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3640 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3641 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3642 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3643 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3644 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3645 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | /* print a new table */ |
| 3649 | chunk_appendf(&trash, |
| 3650 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3651 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3652 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3653 | |
| 3654 | chunk_appendf(&trash, |
| 3655 | "<a name=\"%s\"></a>%s" |
| 3656 | "<a class=px href=\"#%s\">%s</a>", |
| 3657 | px->id, |
| 3658 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3659 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3660 | |
| 3661 | if (uri->flags & ST_SHLGNDS) { |
| 3662 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3663 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3664 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3665 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3666 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3670 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3671 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3672 | "</tr>\n" |
| 3673 | "</table>\n" |
| 3674 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3675 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3676 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3677 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3678 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3679 | 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] | 3680 | /* Column heading for Enable or Disable server */ |
| 3681 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3682 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3683 | |
| 3684 | chunk_appendf(&trash, |
| 3685 | "<th rowspan=2></th>" |
| 3686 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3687 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3688 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3689 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3690 | "<th colspan=9>Server</th>" |
| 3691 | "</tr>\n" |
| 3692 | "<tr class=\"titre\">" |
| 3693 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3694 | "<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] | 3695 | "<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] | 3696 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3697 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3698 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3699 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3700 | "<th>Thrtle</th>\n" |
| 3701 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3702 | } |
| 3703 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3704 | /* 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] | 3705 | * 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] | 3706 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3707 | 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] | 3708 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3709 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3710 | chunk_appendf(&trash, "</table>"); |
| 3711 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3712 | 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] | 3713 | /* close the form used to enable/disable this proxy servers */ |
| 3714 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3715 | "Choose the action to perform on the checked servers : " |
| 3716 | "<select name=action>" |
| 3717 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 3718 | "<option value=\"ready\">Set state to READY</option>" |
| 3719 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | d38f5c0 | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 3720 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 3721 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3722 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3723 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3724 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3725 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3726 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3727 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3728 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3729 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3730 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3731 | "</select>" |
| 3732 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3733 | " <input type=\"submit\" value=\"Apply\">" |
| 3734 | "</form>", |
| 3735 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3739 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3740 | |
| 3741 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3742 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3743 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3744 | * buffer space, or non-zero if everything completed. This function is used |
| 3745 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3746 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3747 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3748 | 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] | 3749 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3750 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3751 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3752 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3753 | 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] | 3754 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3755 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3756 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3757 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3758 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3759 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3760 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3761 | if (uri && uri->scope) { |
| 3762 | /* we have a limited scope, we have to check the proxy name */ |
| 3763 | struct stat_scope *scope; |
| 3764 | int len; |
| 3765 | |
| 3766 | len = strlen(px->id); |
| 3767 | scope = uri->scope; |
| 3768 | |
| 3769 | while (scope) { |
| 3770 | /* match exact proxy name */ |
| 3771 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3772 | break; |
| 3773 | |
| 3774 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3775 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3776 | break; |
| 3777 | scope = scope->next; |
| 3778 | } |
| 3779 | |
| 3780 | /* proxy name not found : don't dump anything */ |
| 3781 | if (scope == NULL) |
| 3782 | return 1; |
| 3783 | } |
| 3784 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3785 | /* if the user has requested a limited output and the proxy |
| 3786 | * name does not match, skip it. |
| 3787 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3788 | if (appctx->ctx.stats.scope_len && |
| 3789 | strnistr(px->id, strlen(px->id), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL) |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3790 | return 1; |
| 3791 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3792 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3793 | (appctx->ctx.stats.iid != -1) && |
| 3794 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3795 | return 1; |
| 3796 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3797 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3798 | /* fall through */ |
| 3799 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3800 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3801 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3802 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3803 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3804 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3805 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3806 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3807 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3808 | /* fall through */ |
| 3809 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3810 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3811 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3812 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3813 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3814 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3815 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3816 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3817 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3818 | /* fall through */ |
| 3819 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3820 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3821 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3822 | 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] | 3823 | if (buffer_almost_full(rep->buf)) { |
| 3824 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3825 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3826 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3827 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3828 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3829 | if (!l->counters) |
| 3830 | continue; |
| 3831 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3832 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3833 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3834 | break; |
| 3835 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3836 | 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] | 3837 | continue; |
| 3838 | } |
| 3839 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3840 | /* print the frontend */ |
| 3841 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3842 | if (bi_putchk(rep, &trash) == -1) |
| 3843 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3844 | } |
| 3845 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3846 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3847 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3848 | /* fall through */ |
| 3849 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3850 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3851 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3852 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3853 | int sv_state; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3854 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3855 | if (buffer_almost_full(rep->buf)) { |
| 3856 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3857 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3858 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3859 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3860 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3861 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3862 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3863 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3864 | break; |
| 3865 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3866 | 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] | 3867 | continue; |
| 3868 | } |
| 3869 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3870 | svs = sv; |
| 3871 | while (svs->track) |
| 3872 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3873 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3874 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 3875 | /* server is UP. The possibilities are : |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3876 | * - UP, draining, going down => state = 7 |
| 3877 | * - UP, going down => state = 3 |
| 3878 | * - UP, draining => state = 8 |
| 3879 | * - UP, checked => state = 4 |
| 3880 | * - UP, not checked nor tracked => state = 9 |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3881 | */ |
| 3882 | |
| 3883 | if ((svs->check.state & CHK_ST_ENABLED) && |
| 3884 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3885 | sv_state = 3; |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3886 | else |
| 3887 | sv_state = 4; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3888 | |
Willy Tarreau | efe2822 | 2014-05-21 17:13:13 +0200 | [diff] [blame] | 3889 | if (server_is_draining(sv)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3890 | sv_state += 4; |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3891 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3892 | if (sv_state == 4 && !(svs->check.state & CHK_ST_ENABLED)) |
| 3893 | sv_state = 9; /* unchecked UP */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3894 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3895 | else if (sv->state == SRV_ST_STOPPING) { |
| 3896 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 3897 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3898 | sv_state = 6; /* NOLB */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3899 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3900 | sv_state = 5; /* NOLB going down */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3901 | } |
| 3902 | else { /* stopped */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3903 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) |
| 3904 | sv_state = 1; /* DOWN (agent) */ |
| 3905 | else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3906 | sv_state = 0; /* DOWN */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3907 | else if ((svs->agent.state & CHK_ST_ENABLED) || (svs->check.state & CHK_ST_ENABLED)) |
| 3908 | sv_state = 2; /* going up */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3909 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3910 | sv_state = 0; /* DOWN, unchecked */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3911 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3912 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3913 | 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] | 3914 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3915 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3916 | continue; |
| 3917 | } |
| 3918 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3919 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3920 | if (bi_putchk(rep, &trash) == -1) |
| 3921 | return 0; |
| 3922 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3923 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3924 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3925 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3926 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3927 | case STAT_PX_ST_BE: |
| 3928 | /* print the backend */ |
| 3929 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3930 | if (bi_putchk(rep, &trash) == -1) |
| 3931 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3932 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3933 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3934 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3935 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3936 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3937 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3938 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3939 | if (bi_putchk(rep, &trash) == -1) |
| 3940 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3941 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3942 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3943 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3944 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3945 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3946 | case STAT_PX_ST_FIN: |
| 3947 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3948 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3949 | default: |
| 3950 | /* unknown state, we should put an abort() here ! */ |
| 3951 | return 1; |
| 3952 | } |
| 3953 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3954 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3955 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3956 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3957 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3958 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3959 | { |
| 3960 | /* WARNING! This must fit in the first buffer !!! */ |
| 3961 | chunk_appendf(&trash, |
| 3962 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3963 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3964 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3965 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3966 | "<style type=\"text/css\"><!--\n" |
| 3967 | "body {" |
| 3968 | " font-family: arial, helvetica, sans-serif;" |
| 3969 | " font-size: 12px;" |
| 3970 | " font-weight: normal;" |
| 3971 | " color: black;" |
| 3972 | " background: white;" |
| 3973 | "}\n" |
| 3974 | "th,td {" |
| 3975 | " font-size: 10px;" |
| 3976 | "}\n" |
| 3977 | "h1 {" |
| 3978 | " font-size: x-large;" |
| 3979 | " margin-bottom: 0.5em;" |
| 3980 | "}\n" |
| 3981 | "h2 {" |
| 3982 | " font-family: helvetica, arial;" |
| 3983 | " font-size: x-large;" |
| 3984 | " font-weight: bold;" |
| 3985 | " font-style: italic;" |
| 3986 | " color: #6020a0;" |
| 3987 | " margin-top: 0em;" |
| 3988 | " margin-bottom: 0em;" |
| 3989 | "}\n" |
| 3990 | "h3 {" |
| 3991 | " font-family: helvetica, arial;" |
| 3992 | " font-size: 16px;" |
| 3993 | " font-weight: bold;" |
| 3994 | " color: #b00040;" |
| 3995 | " background: #e8e8d0;" |
| 3996 | " margin-top: 0em;" |
| 3997 | " margin-bottom: 0em;" |
| 3998 | "}\n" |
| 3999 | "li {" |
| 4000 | " margin-top: 0.25em;" |
| 4001 | " margin-right: 2em;" |
| 4002 | "}\n" |
| 4003 | ".hr {margin-top: 0.25em;" |
| 4004 | " border-color: black;" |
| 4005 | " border-bottom-style: solid;" |
| 4006 | "}\n" |
| 4007 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4008 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4009 | ".frontend {background: #e8e8d0;}\n" |
| 4010 | ".socket {background: #d0d0d0;}\n" |
| 4011 | ".backend {background: #e8e8d0;}\n" |
| 4012 | ".active0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4013 | ".active1 {background: #ff9090;}\n" |
| 4014 | ".active2 {background: #ffd020;}\n" |
| 4015 | ".active3 {background: #ffffa0;}\n" |
| 4016 | ".active4 {background: #c0ffc0;}\n" |
| 4017 | ".active5 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 4018 | ".active6 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 4019 | ".active7 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 4020 | ".active8 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
| 4021 | ".active9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4022 | ".backup0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4023 | ".backup1 {background: #ff9090;}\n" |
| 4024 | ".backup2 {background: #ff80ff;}\n" |
| 4025 | ".backup3 {background: #c060ff;}\n" |
| 4026 | ".backup4 {background: #b0d0ff;}\n" |
| 4027 | ".backup5 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 4028 | ".backup6 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 4029 | ".backup7 {background: #c060ff;}\n" |
| 4030 | ".backup8 {background: #cc9900;}\n" |
| 4031 | ".backup9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4032 | ".maintain {background: #c07820;}\n" |
| 4033 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4034 | "\n" |
| 4035 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4036 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4037 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4038 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4039 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4040 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4041 | "\n" |
| 4042 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4043 | "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" |
| 4044 | "table.tbl td.ac { text-align: center;}\n" |
| 4045 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4046 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4047 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4048 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4049 | "\n" |
| 4050 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4051 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4052 | "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] | 4053 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4054 | "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] | 4055 | "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] | 4056 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4057 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4058 | " display:block;\n" |
| 4059 | " visibility:hidden;\n" |
| 4060 | " z-index:2147483647;\n" |
| 4061 | " position:absolute;\n" |
| 4062 | " padding:2px 4px 3px;\n" |
| 4063 | " background:#f0f060; color:#000000;\n" |
| 4064 | " border:1px solid #7040c0;\n" |
| 4065 | " white-space:nowrap;\n" |
| 4066 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4067 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4068 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4069 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4070 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4071 | "-->\n" |
| 4072 | "</style></head>\n", |
| 4073 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4074 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4075 | ); |
| 4076 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4077 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4078 | /* 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] | 4079 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4080 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4081 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4082 | 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] | 4083 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4084 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4085 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4086 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4087 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4088 | /* WARNING! this has to fit the first packet too. |
| 4089 | * We are around 3.5 kB, add adding entries will |
| 4090 | * become tricky if we want to support 4kB buffers ! |
| 4091 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4092 | chunk_appendf(&trash, |
| 4093 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4094 | PRODUCT_NAME "%s</a></h1>\n" |
| 4095 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4096 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4097 | "<h3>> General process information</h3>\n" |
| 4098 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4099 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4100 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4101 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4102 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4103 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4104 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4105 | "</td><td align=\"center\" nowrap>\n" |
| 4106 | "<table class=\"lgd\"><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4107 | "<td class=\"active4\"> </td><td class=\"noborder\">active UP </td>" |
| 4108 | "<td class=\"backup4\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4109 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4110 | "<td class=\"active3\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4111 | "<td class=\"backup3\"></td><td class=\"noborder\">backup UP, going down </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4112 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4113 | "<td class=\"active2\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4114 | "<td class=\"backup2\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4115 | "</tr><tr>\n" |
| 4116 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4117 | "<td class=\"active9\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4118 | "</tr><tr>\n" |
| 4119 | "<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] | 4120 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4121 | "<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] | 4122 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4123 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4124 | "</td>" |
| 4125 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4126 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4127 | "", |
| 4128 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4129 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4130 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4131 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4132 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4133 | pid, relative_pid, global.nbproc, |
| 4134 | up / 86400, (up % 86400) / 3600, |
| 4135 | (up % 3600) / 60, (up % 60), |
| 4136 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4137 | global.rlimit_memmax ? " MB" : "", |
| 4138 | global.rlimit_nofile, |
| 4139 | global.maxsock, global.maxconn, global.maxpipes, |
| 4140 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4141 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4142 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4143 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4144 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 4145 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4146 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4147 | |
| 4148 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 4149 | "<li><form method=\"GET\" action=\"%s%s%s\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4150 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4151 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4152 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 4153 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4154 | STAT_SCOPE_TXT_MAXLEN); |
| 4155 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4156 | /* 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] | 4157 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4158 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4159 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4160 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4161 | 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] | 4162 | } |
| 4163 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4164 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4165 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4166 | "<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] | 4167 | uri->uri_prefix, |
| 4168 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4169 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4170 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4171 | else |
| 4172 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4173 | "<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] | 4174 | uri->uri_prefix, |
| 4175 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4176 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4177 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4178 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4179 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4180 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
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\">Enable refresh</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" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4185 | "", |
| 4186 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4187 | else |
| 4188 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4189 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4190 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4191 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4192 | ";norefresh", |
| 4193 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4194 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4195 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4196 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4197 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4198 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4199 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4200 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4201 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4202 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4203 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4204 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4205 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4206 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4207 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4208 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4209 | chunk_appendf(&trash, |
| 4210 | "</ul></td>" |
| 4211 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4212 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4213 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4214 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4215 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4216 | "</ul>" |
| 4217 | "</td>" |
| 4218 | "</tr></table>\n" |
| 4219 | "" |
| 4220 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4221 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4222 | if (appctx->ctx.stats.st_code) { |
| 4223 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4224 | case STAT_STATUS_DONE: |
| 4225 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4226 | "<p><div class=active4>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4227 | "<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] | 4228 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4229 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4230 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4231 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4232 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4233 | break; |
| 4234 | case STAT_STATUS_NONE: |
| 4235 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4236 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4237 | "<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] | 4238 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4239 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4240 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4241 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4242 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4243 | break; |
| 4244 | case STAT_STATUS_PART: |
| 4245 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4246 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4247 | "<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] | 4248 | "Action partially processed.<br>" |
| 4249 | "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] | 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_ERRP: |
| 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 | "Action not processed because of invalid parameters." |
| 4260 | "<ul>" |
| 4261 | "<li>The action is maybe unknown.</li>" |
| 4262 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4263 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4264 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4265 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4266 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4267 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4268 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4269 | break; |
| 4270 | case STAT_STATUS_EXCD: |
| 4271 | chunk_appendf(&trash, |
| 4272 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4273 | "<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] | 4274 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4275 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4276 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4277 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4278 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4279 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4280 | break; |
| 4281 | case STAT_STATUS_DENY: |
| 4282 | chunk_appendf(&trash, |
| 4283 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4284 | "<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] | 4285 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4286 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4287 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4288 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4289 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4290 | break; |
| 4291 | default: |
| 4292 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4293 | "<p><div class=active9>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4294 | "<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] | 4295 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4296 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4297 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4298 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4299 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4300 | } |
| 4301 | chunk_appendf(&trash, "<p>\n"); |
| 4302 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4303 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4304 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4305 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4306 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4307 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4308 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4309 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4310 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4311 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4312 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4313 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4314 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4315 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4316 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 4317 | * and the session must be closed, or -1 in case of any error. This function is |
| 4318 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4319 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4320 | 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] | 4321 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4322 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4323 | struct channel *rep = si->ib; |
| 4324 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4325 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4326 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4327 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4328 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4329 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4330 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4331 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4332 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4333 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4334 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4335 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4336 | else |
| 4337 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4338 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4339 | if (bi_putchk(rep, &trash) == -1) |
| 4340 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4341 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4342 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4343 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4344 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4345 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4346 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4347 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4348 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4349 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4350 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4351 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4352 | appctx->ctx.stats.px = proxy; |
| 4353 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4354 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4355 | /* fall through */ |
| 4356 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4357 | case STAT_ST_LIST: |
| 4358 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4359 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4360 | if (buffer_almost_full(rep->buf)) { |
| 4361 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4362 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4363 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4364 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4365 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4366 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4367 | 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] | 4368 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4369 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4370 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4371 | appctx->ctx.stats.px = px->next; |
| 4372 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4373 | } |
| 4374 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4375 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4376 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4377 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4378 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4379 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4380 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4381 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4382 | if (bi_putchk(rep, &trash) == -1) |
| 4383 | return 0; |
| 4384 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4385 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4386 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4387 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4388 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4389 | case STAT_ST_FIN: |
| 4390 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4391 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4392 | default: |
| 4393 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4394 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4395 | return -1; |
| 4396 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4397 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4398 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4399 | /* We reached the stats page through a POST request. The appctx is |
| 4400 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4401 | * Parse the posted data and enable/disable servers if necessary. |
| 4402 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4403 | */ |
| 4404 | static int stats_process_http_post(struct stream_interface *si) |
| 4405 | { |
| 4406 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4407 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4408 | |
| 4409 | struct proxy *px = NULL; |
| 4410 | struct server *sv = NULL; |
| 4411 | |
| 4412 | char key[LINESIZE]; |
| 4413 | int action = ST_ADM_ACTION_NONE; |
| 4414 | int reprocess = 0; |
| 4415 | |
| 4416 | int total_servers = 0; |
| 4417 | int altered_servers = 0; |
| 4418 | |
| 4419 | char *first_param, *cur_param, *next_param, *end_params; |
| 4420 | char *st_cur_param = NULL; |
| 4421 | char *st_next_param = NULL; |
| 4422 | |
| 4423 | struct chunk *temp; |
| 4424 | int reql; |
| 4425 | |
| 4426 | temp = get_trash_chunk(); |
| 4427 | if (temp->size < s->txn.req.body_len) { |
| 4428 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4429 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4430 | goto out; |
| 4431 | } |
| 4432 | |
| 4433 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 4434 | if (reql <= 0) { |
| 4435 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4436 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4437 | return 0; |
| 4438 | } |
| 4439 | |
| 4440 | first_param = temp->str; |
| 4441 | end_params = temp->str + reql; |
| 4442 | cur_param = next_param = end_params; |
| 4443 | *end_params = '\0'; |
| 4444 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4445 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4446 | |
| 4447 | /* |
| 4448 | * Parse the parameters in reverse order to only store the last value. |
| 4449 | * From the html form, the backend and the action are at the end. |
| 4450 | */ |
| 4451 | while (cur_param > first_param) { |
| 4452 | char *value; |
| 4453 | int poffset, plen; |
| 4454 | |
| 4455 | cur_param--; |
| 4456 | |
| 4457 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4458 | reprocess_servers: |
| 4459 | /* Parse the key */ |
| 4460 | poffset = (cur_param != first_param ? 1 : 0); |
| 4461 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4462 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4463 | strncpy(key, cur_param + poffset, plen); |
| 4464 | key[plen - 1] = '\0'; |
| 4465 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4466 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4467 | goto out; |
| 4468 | } |
| 4469 | |
| 4470 | /* Parse the value */ |
| 4471 | value = key; |
| 4472 | while (*value != '\0' && *value != '=') { |
| 4473 | value++; |
| 4474 | } |
| 4475 | if (*value == '=') { |
| 4476 | /* Ok, a value is found, we can mark the end of the key */ |
| 4477 | *value++ = '\0'; |
| 4478 | } |
| 4479 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4480 | break; |
| 4481 | |
| 4482 | /* Now we can check the key to see what to do */ |
| 4483 | if (!px && (strcmp(key, "b") == 0)) { |
| 4484 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4485 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4486 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4487 | goto out; |
| 4488 | } |
| 4489 | } |
| 4490 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4491 | if (strcmp(value, "ready") == 0) { |
| 4492 | action = ST_ADM_ACTION_READY; |
| 4493 | } |
| 4494 | else if (strcmp(value, "drain") == 0) { |
| 4495 | action = ST_ADM_ACTION_DRAIN; |
| 4496 | } |
| 4497 | else if (strcmp(value, "maint") == 0) { |
| 4498 | action = ST_ADM_ACTION_MAINT; |
| 4499 | } |
| 4500 | else if (strcmp(value, "shutdown") == 0) { |
| 4501 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4502 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4503 | else if (strcmp(value, "dhlth") == 0) { |
| 4504 | action = ST_ADM_ACTION_DHLTH; |
| 4505 | } |
| 4506 | else if (strcmp(value, "ehlth") == 0) { |
| 4507 | action = ST_ADM_ACTION_EHLTH; |
| 4508 | } |
| 4509 | else if (strcmp(value, "hrunn") == 0) { |
| 4510 | action = ST_ADM_ACTION_HRUNN; |
| 4511 | } |
| 4512 | else if (strcmp(value, "hnolb") == 0) { |
| 4513 | action = ST_ADM_ACTION_HNOLB; |
| 4514 | } |
| 4515 | else if (strcmp(value, "hdown") == 0) { |
| 4516 | action = ST_ADM_ACTION_HDOWN; |
| 4517 | } |
| 4518 | else if (strcmp(value, "dagent") == 0) { |
| 4519 | action = ST_ADM_ACTION_DAGENT; |
| 4520 | } |
| 4521 | else if (strcmp(value, "eagent") == 0) { |
| 4522 | action = ST_ADM_ACTION_EAGENT; |
| 4523 | } |
| 4524 | else if (strcmp(value, "arunn") == 0) { |
| 4525 | action = ST_ADM_ACTION_ARUNN; |
| 4526 | } |
| 4527 | else if (strcmp(value, "adown") == 0) { |
| 4528 | action = ST_ADM_ACTION_ADOWN; |
| 4529 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4530 | /* else these are the old supported methods */ |
| 4531 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4532 | action = ST_ADM_ACTION_DISABLE; |
| 4533 | } |
| 4534 | else if (strcmp(value, "enable") == 0) { |
| 4535 | action = ST_ADM_ACTION_ENABLE; |
| 4536 | } |
| 4537 | else if (strcmp(value, "stop") == 0) { |
| 4538 | action = ST_ADM_ACTION_STOP; |
| 4539 | } |
| 4540 | else if (strcmp(value, "start") == 0) { |
| 4541 | action = ST_ADM_ACTION_START; |
| 4542 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4543 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4544 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4545 | goto out; |
| 4546 | } |
| 4547 | } |
| 4548 | else if (strcmp(key, "s") == 0) { |
| 4549 | if (!(px && action)) { |
| 4550 | /* |
| 4551 | * Indicates that we'll need to reprocess the parameters |
| 4552 | * as soon as backend and action are known |
| 4553 | */ |
| 4554 | if (!reprocess) { |
| 4555 | st_cur_param = cur_param; |
| 4556 | st_next_param = next_param; |
| 4557 | } |
| 4558 | reprocess = 1; |
| 4559 | } |
| 4560 | else if ((sv = findserver(px, value)) != NULL) { |
| 4561 | switch (action) { |
| 4562 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4563 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4564 | altered_servers++; |
| 4565 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4566 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4567 | } |
| 4568 | break; |
| 4569 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4570 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4571 | altered_servers++; |
| 4572 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4573 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4574 | } |
| 4575 | break; |
| 4576 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4577 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 4578 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4579 | altered_servers++; |
| 4580 | total_servers++; |
| 4581 | } |
| 4582 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4583 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4584 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 4585 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4586 | altered_servers++; |
| 4587 | total_servers++; |
| 4588 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4589 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4590 | case ST_ADM_ACTION_DHLTH: |
| 4591 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4592 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4593 | altered_servers++; |
| 4594 | total_servers++; |
| 4595 | } |
| 4596 | break; |
| 4597 | case ST_ADM_ACTION_EHLTH: |
| 4598 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4599 | sv->check.state |= CHK_ST_ENABLED; |
| 4600 | altered_servers++; |
| 4601 | total_servers++; |
| 4602 | } |
| 4603 | break; |
| 4604 | case ST_ADM_ACTION_HRUNN: |
| 4605 | if (!(sv->track)) { |
| 4606 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4607 | srv_set_running(sv, "changed from Web interface"); |
| 4608 | altered_servers++; |
| 4609 | total_servers++; |
| 4610 | } |
| 4611 | break; |
| 4612 | case ST_ADM_ACTION_HNOLB: |
| 4613 | if (!(sv->track)) { |
| 4614 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4615 | srv_set_stopping(sv, "changed from Web interface"); |
| 4616 | altered_servers++; |
| 4617 | total_servers++; |
| 4618 | } |
| 4619 | break; |
| 4620 | case ST_ADM_ACTION_HDOWN: |
| 4621 | if (!(sv->track)) { |
| 4622 | sv->check.health = 0; |
| 4623 | srv_set_stopped(sv, "changed from Web interface"); |
| 4624 | altered_servers++; |
| 4625 | total_servers++; |
| 4626 | } |
| 4627 | break; |
| 4628 | case ST_ADM_ACTION_DAGENT: |
| 4629 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4630 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4631 | altered_servers++; |
| 4632 | total_servers++; |
| 4633 | } |
| 4634 | break; |
| 4635 | case ST_ADM_ACTION_EAGENT: |
| 4636 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4637 | sv->agent.state |= CHK_ST_ENABLED; |
| 4638 | altered_servers++; |
| 4639 | total_servers++; |
| 4640 | } |
| 4641 | break; |
| 4642 | case ST_ADM_ACTION_ARUNN: |
| 4643 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4644 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 4645 | srv_set_running(sv, "changed from Web interface"); |
| 4646 | altered_servers++; |
| 4647 | total_servers++; |
| 4648 | } |
| 4649 | break; |
| 4650 | case ST_ADM_ACTION_ADOWN: |
| 4651 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4652 | sv->agent.health = 0; |
| 4653 | srv_set_stopped(sv, "changed from Web interface"); |
| 4654 | altered_servers++; |
| 4655 | total_servers++; |
| 4656 | } |
| 4657 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4658 | case ST_ADM_ACTION_READY: |
| 4659 | srv_adm_set_ready(sv); |
| 4660 | altered_servers++; |
| 4661 | total_servers++; |
| 4662 | break; |
| 4663 | case ST_ADM_ACTION_DRAIN: |
| 4664 | srv_adm_set_drain(sv); |
| 4665 | altered_servers++; |
| 4666 | total_servers++; |
| 4667 | break; |
| 4668 | case ST_ADM_ACTION_MAINT: |
| 4669 | srv_adm_set_maint(sv); |
| 4670 | altered_servers++; |
| 4671 | total_servers++; |
| 4672 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4673 | case ST_ADM_ACTION_SHUTDOWN: |
| 4674 | if (px->state != PR_STSTOPPED) { |
| 4675 | struct session *sess, *sess_bck; |
| 4676 | |
| 4677 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4678 | if (sess->srv_conn == sv) |
| 4679 | session_shutdown(sess, SN_ERR_KILLED); |
| 4680 | |
| 4681 | altered_servers++; |
| 4682 | total_servers++; |
| 4683 | } |
| 4684 | break; |
| 4685 | } |
| 4686 | } else { |
| 4687 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4688 | total_servers++; |
| 4689 | } |
| 4690 | } |
| 4691 | if (reprocess && px && action) { |
| 4692 | /* Now, we know the backend and the action chosen by the user. |
| 4693 | * We can safely restart from the first server parameter |
| 4694 | * to reprocess them |
| 4695 | */ |
| 4696 | cur_param = st_cur_param; |
| 4697 | next_param = st_next_param; |
| 4698 | reprocess = 0; |
| 4699 | goto reprocess_servers; |
| 4700 | } |
| 4701 | |
| 4702 | next_param = cur_param; |
| 4703 | } |
| 4704 | } |
| 4705 | |
| 4706 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4707 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4708 | } |
| 4709 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4710 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4711 | } |
| 4712 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4713 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4714 | } |
| 4715 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4716 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4717 | } |
| 4718 | out: |
| 4719 | return 1; |
| 4720 | } |
| 4721 | |
| 4722 | |
| 4723 | static int stats_send_http_headers(struct stream_interface *si) |
| 4724 | { |
| 4725 | struct session *s = session_from_task(si->owner); |
| 4726 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4727 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4728 | |
| 4729 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4730 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4731 | "Cache-Control: no-cache\r\n" |
| 4732 | "Connection: close\r\n" |
| 4733 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4734 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4735 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4736 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4737 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4738 | uri->refresh); |
| 4739 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4740 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4741 | |
| 4742 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4743 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4744 | else |
| 4745 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4746 | |
| 4747 | s->txn.status = 200; |
| 4748 | s->logs.tv_request = now; |
| 4749 | |
| 4750 | if (bi_putchk(si->ib, &trash) == -1) |
| 4751 | return 0; |
| 4752 | |
| 4753 | return 1; |
| 4754 | } |
| 4755 | |
| 4756 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4757 | { |
| 4758 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4759 | struct session *s = session_from_task(si->owner); |
| 4760 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4761 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4762 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4763 | /* 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] | 4764 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4765 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4766 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4767 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4768 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | /* We don't want to land on the posted stats page because a refresh will |
| 4772 | * repost the data. We don't want this to happen on accident so we redirect |
| 4773 | * the browse to the stats page with a GET. |
| 4774 | */ |
| 4775 | chunk_printf(&trash, |
| 4776 | "HTTP/1.1 303 See Other\r\n" |
| 4777 | "Cache-Control: no-cache\r\n" |
| 4778 | "Content-Type: text/plain\r\n" |
| 4779 | "Connection: close\r\n" |
| 4780 | "Location: %s;st=%s%s%s%s\r\n" |
Willy Tarreau | c2f2f80 | 2016-01-26 13:57:29 +0100 | [diff] [blame] | 4781 | "Content-length: 0\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4782 | "\r\n", |
| 4783 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4784 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4785 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4786 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4787 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4788 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4789 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4790 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4791 | scope_txt); |
| 4792 | |
| 4793 | s->txn.status = 303; |
| 4794 | s->logs.tv_request = now; |
| 4795 | |
| 4796 | if (bi_putchk(si->ib, &trash) == -1) |
| 4797 | return 0; |
| 4798 | |
| 4799 | return 1; |
| 4800 | } |
| 4801 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4802 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4803 | * 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] | 4804 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4805 | * automatically unregisters itself once transfer is complete. |
| 4806 | */ |
| 4807 | static void http_stats_io_handler(struct stream_interface *si) |
| 4808 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4809 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4810 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4811 | struct channel *req = si->ob; |
| 4812 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4813 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4814 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4815 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4816 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4817 | /* check that the output is not closed */ |
| 4818 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4819 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4820 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4821 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4822 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4823 | if (stats_send_http_headers(si)) { |
| 4824 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4825 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4826 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4827 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4828 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4829 | } |
| 4830 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4831 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4832 | unsigned int prev_len = si->ib->buf->i; |
| 4833 | unsigned int data_len; |
| 4834 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 4835 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4836 | |
| 4837 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4838 | /* One difficulty we're facing is that we must prevent |
| 4839 | * the input data from being automatically forwarded to |
| 4840 | * the output area. For this, we temporarily disable |
| 4841 | * forwarding on the channel. |
| 4842 | */ |
| 4843 | last_fwd = si->ib->to_forward; |
| 4844 | si->ib->to_forward = 0; |
| 4845 | chunk_printf(&trash, "\r\n000000\r\n"); |
| 4846 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4847 | si->ib->to_forward = last_fwd; |
| 4848 | goto fail; |
| 4849 | } |
| 4850 | } |
| 4851 | |
| 4852 | data_len = si->ib->buf->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4853 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4854 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4855 | |
| 4856 | last_len = si->ib->buf->i; |
| 4857 | |
| 4858 | /* Now we must either adjust or remove the chunk size. This is |
| 4859 | * not easy because the chunk size might wrap at the end of the |
| 4860 | * buffer, so we pretend we have nothing in the buffer, we write |
| 4861 | * the size, then restore the buffer's contents. Note that we can |
| 4862 | * only do that because no forwarding is scheduled on the stats |
| 4863 | * applet. |
| 4864 | */ |
| 4865 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4866 | si->ib->total -= (last_len - prev_len); |
| 4867 | si->ib->buf->i -= (last_len - prev_len); |
| 4868 | |
| 4869 | if (last_len != data_len) { |
| 4870 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
| 4871 | bi_putchk(si->ib, &trash); |
| 4872 | |
| 4873 | si->ib->total += (last_len - data_len); |
| 4874 | si->ib->buf->i += (last_len - data_len); |
| 4875 | } |
| 4876 | /* now re-enable forwarding */ |
| 4877 | channel_forward(si->ib, last_fwd); |
| 4878 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4879 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4880 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4881 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4882 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4883 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4884 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4885 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4886 | } |
| 4887 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4888 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4889 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4890 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4891 | } |
| 4892 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4893 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 4894 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4895 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
| 4896 | if (bi_putchk(si->ib, &trash) == -1) |
| 4897 | goto fail; |
| 4898 | } |
| 4899 | /* eat the whole request */ |
| 4900 | bo_skip(si->ob, si->ob->buf->o); |
| 4901 | res->flags |= CF_READ_NULL; |
| 4902 | si_shutr(si); |
| 4903 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4904 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4905 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4906 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4907 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4908 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4909 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4910 | si_shutr(si); |
| 4911 | res->flags |= CF_READ_NULL; |
| 4912 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4913 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4914 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4915 | fail: |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4916 | /* update all other flags and resync with the other side */ |
| 4917 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4918 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4919 | /* we don't want to expire timeouts while we're processing requests */ |
| 4920 | si->ib->rex = TICK_ETERNITY; |
| 4921 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4922 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4923 | out: |
| 4924 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4925 | /* check that we have released everything then unregister */ |
| 4926 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4927 | } |
| 4928 | } |
| 4929 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4930 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4931 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4932 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4933 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4934 | return "NONE"; |
| 4935 | return conn->ctrl->name; |
| 4936 | } |
| 4937 | |
| 4938 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4939 | { |
| 4940 | static char ptr[17]; |
| 4941 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4942 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4943 | return "NONE"; |
| 4944 | |
| 4945 | if (conn->xprt == &raw_sock) |
| 4946 | return "RAW"; |
| 4947 | |
| 4948 | #ifdef USE_OPENSSL |
| 4949 | if (conn->xprt == &ssl_sock) |
| 4950 | return "SSL"; |
| 4951 | #endif |
| 4952 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4953 | return ptr; |
| 4954 | } |
| 4955 | |
| 4956 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4957 | { |
| 4958 | static char ptr[17]; |
| 4959 | |
| 4960 | if (!conn->data) |
| 4961 | return "NONE"; |
| 4962 | |
| 4963 | if (conn->data == &sess_conn_cb) |
| 4964 | return "SESS"; |
| 4965 | |
| 4966 | if (conn->data == &si_conn_cb) |
| 4967 | return "STRM"; |
| 4968 | |
| 4969 | if (conn->data == &check_conn_cb) |
| 4970 | return "CHCK"; |
| 4971 | |
| 4972 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4973 | return ptr; |
| 4974 | } |
| 4975 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4976 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4977 | * 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] | 4978 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4979 | * 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] | 4980 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4981 | 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] | 4982 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4983 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4984 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4985 | extern const char *monthname[12]; |
| 4986 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4987 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4988 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4989 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4990 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4991 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4992 | 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] | 4993 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4994 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4995 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4996 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4997 | appctx->ctx.sess.uid = 0; |
| 4998 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4999 | return 1; |
| 5000 | } |
| 5001 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5002 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5003 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5004 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5005 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5006 | /* fall through */ |
| 5007 | |
| 5008 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5009 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5010 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5011 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5012 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5013 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5014 | 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] | 5015 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 5016 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5017 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5018 | conn = objt_conn(sess->si[0].end); |
| 5019 | 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] | 5020 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5021 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5022 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5023 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5024 | break; |
| 5025 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5026 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5027 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5028 | default: |
| 5029 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5030 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5031 | break; |
| 5032 | } |
| 5033 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5034 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5035 | " 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] | 5036 | 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] | 5037 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5038 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5039 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5040 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 5041 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 5042 | sess->listener ? sess->listener->luid : 0); |
| 5043 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5044 | if (conn) |
| 5045 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5046 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5047 | 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] | 5048 | case AF_INET: |
| 5049 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5050 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5051 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5052 | break; |
| 5053 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5054 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5055 | break; |
| 5056 | default: |
| 5057 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5058 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5059 | break; |
| 5060 | } |
| 5061 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5062 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5063 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5064 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5065 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5066 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5067 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5068 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5069 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5070 | conn = objt_conn(sess->si[1].end); |
| 5071 | if (conn) |
| 5072 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5073 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5074 | 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] | 5075 | case AF_INET: |
| 5076 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5077 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5078 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5079 | break; |
| 5080 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5081 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5082 | break; |
| 5083 | default: |
| 5084 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5085 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5086 | break; |
| 5087 | } |
| 5088 | |
| 5089 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5090 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5091 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5092 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5093 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5094 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5095 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5096 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5097 | if (conn) |
| 5098 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5099 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5100 | 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] | 5101 | case AF_INET: |
| 5102 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5103 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5104 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5105 | break; |
| 5106 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5107 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5108 | break; |
| 5109 | default: |
| 5110 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5111 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5112 | break; |
| 5113 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5114 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5115 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5116 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5117 | sess->task, |
| 5118 | sess->task->state, |
| 5119 | sess->task->nice, sess->task->calls, |
| 5120 | sess->task->expire ? |
| 5121 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5122 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5123 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5124 | task_in_rq(sess->task) ? ", running" : ""); |
| 5125 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5126 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5127 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5128 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5129 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5130 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5131 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 5132 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 5133 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 5134 | |
| 5135 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5136 | " 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] | 5137 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5138 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5139 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5140 | obj_type_name(sess->si[0].end), |
| 5141 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5142 | sess->si[0].exp ? |
| 5143 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5144 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5145 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5146 | sess->si[0].err_type); |
| 5147 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5148 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5149 | " 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] | 5150 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5151 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5152 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5153 | obj_type_name(sess->si[1].end), |
| 5154 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5155 | sess->si[1].exp ? |
| 5156 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5157 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5158 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5159 | sess->si[1].err_type); |
| 5160 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5161 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5162 | chunk_appendf(&trash, |
| 5163 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5164 | conn, |
| 5165 | get_conn_ctrl_name(conn), |
| 5166 | get_conn_xprt_name(conn), |
| 5167 | get_conn_data_name(conn), |
| 5168 | obj_type_name(conn->target), |
| 5169 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5170 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5171 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5172 | " 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] | 5173 | conn->flags, |
| 5174 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5175 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5176 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5177 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5178 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5179 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5180 | chunk_appendf(&trash, |
| 5181 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5182 | tmpctx, |
| 5183 | tmpctx->st0, |
| 5184 | tmpctx->st1, |
| 5185 | tmpctx->st2, |
| 5186 | tmpctx->applet->name); |
| 5187 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5188 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5189 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5190 | chunk_appendf(&trash, |
| 5191 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5192 | conn, |
| 5193 | get_conn_ctrl_name(conn), |
| 5194 | get_conn_xprt_name(conn), |
| 5195 | get_conn_data_name(conn), |
| 5196 | obj_type_name(conn->target), |
| 5197 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5198 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5199 | chunk_appendf(&trash, |
Willy Tarreau | bccd8b6 | 2016-01-25 15:27:17 +0100 | [diff] [blame] | 5200 | " 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] | 5201 | conn->flags, |
| 5202 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5203 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5204 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5205 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5206 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5207 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5208 | chunk_appendf(&trash, |
| 5209 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5210 | tmpctx, |
| 5211 | tmpctx->st0, |
| 5212 | tmpctx->st1, |
| 5213 | tmpctx->st2, |
| 5214 | tmpctx->applet->name); |
| 5215 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5216 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5217 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5218 | " 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] | 5219 | " an_exp=%s", |
| 5220 | sess->req, |
| 5221 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5222 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5223 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5224 | sess->req->analyse_exp ? |
| 5225 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 5226 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5227 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5228 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5229 | " rex=%s", |
| 5230 | sess->req->rex ? |
| 5231 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 5232 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5233 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5234 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5235 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5236 | " buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5237 | sess->req->wex ? |
| 5238 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 5239 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5240 | sess->req->buf, |
| 5241 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5242 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5243 | sess->txn.req.next, sess->req->buf->i, |
| 5244 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5245 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5246 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5247 | " 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] | 5248 | " an_exp=%s", |
| 5249 | sess->rep, |
| 5250 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5251 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5252 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5253 | sess->rep->analyse_exp ? |
| 5254 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 5255 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5256 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5257 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5258 | " rex=%s", |
| 5259 | sess->rep->rex ? |
| 5260 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 5261 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5262 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5263 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5264 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5265 | " buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5266 | sess->rep->wex ? |
| 5267 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 5268 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5269 | sess->rep->buf, |
| 5270 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5271 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5272 | sess->txn.rsp.next, sess->rep->buf->i, |
| 5273 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5274 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5275 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5276 | return 0; |
| 5277 | |
| 5278 | /* use other states to dump the contents */ |
| 5279 | } |
| 5280 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5281 | appctx->ctx.sess.uid = 0; |
| 5282 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5283 | return 1; |
| 5284 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5285 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5286 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5287 | { |
| 5288 | struct appctx *appctx = __objt_appctx(si->end); |
| 5289 | |
| 5290 | switch (appctx->st2) { |
| 5291 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5292 | /* Display the column headers. If the message cannot be sent, |
| 5293 | * quit the fucntion with returning 0. The function is called |
| 5294 | * later and restart at the state "STAT_ST_INIT". |
| 5295 | */ |
| 5296 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5297 | chunk_appendf(&trash, "# id (file) description\n"); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5298 | if (bi_putchk(si->ib, &trash) == -1) |
| 5299 | return 0; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5300 | |
| 5301 | /* Now, we start the browsing of the references lists. |
| 5302 | * Note that the following call to LIST_ELEM return bad pointer. The only |
Cyril Bonté | c4cdeb7 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 5303 | * available field of this pointer is <list>. It is used with the function |
| 5304 | * pat_list_get_next() for retruning the first available entry |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5305 | */ |
| 5306 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5307 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5308 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5309 | appctx->st2 = STAT_ST_LIST; |
| 5310 | /* fall through */ |
| 5311 | |
| 5312 | case STAT_ST_LIST: |
| 5313 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5314 | chunk_reset(&trash); |
| 5315 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5316 | /* Build messages. If the reference is used by another category than |
| 5317 | * the listed categorie, display the information in the massage. |
| 5318 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5319 | 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] | 5320 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5321 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5322 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5323 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5324 | /* let's try again later from this session. We add ourselves into |
| 5325 | * this session's users so that it can remove us upon termination. |
| 5326 | */ |
| 5327 | return 0; |
| 5328 | } |
| 5329 | |
| 5330 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5331 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5332 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | appctx->st2 = STAT_ST_FIN; |
| 5336 | /* fall through */ |
| 5337 | |
| 5338 | default: |
| 5339 | appctx->st2 = STAT_ST_FIN; |
| 5340 | return 1; |
| 5341 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5342 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5343 | } |
| 5344 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5345 | static int stats_map_lookup(struct stream_interface *si) |
| 5346 | { |
| 5347 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5348 | struct sample sample; |
| 5349 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5350 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5351 | |
| 5352 | switch (appctx->st2) { |
| 5353 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5354 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5355 | 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] | 5356 | 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] | 5357 | appctx->st2 = STAT_ST_LIST; |
| 5358 | /* fall through */ |
| 5359 | |
| 5360 | case STAT_ST_LIST: |
| 5361 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5362 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5363 | /* initialise chunk to build new message */ |
| 5364 | chunk_reset(&trash); |
| 5365 | |
| 5366 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 5367 | sample.type = SMP_T_STR; |
Andreas Seltenreich | a96d28b | 2016-03-03 19:32:25 +0100 | [diff] [blame] | 5368 | sample.flags = SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5369 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 5370 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5371 | if (appctx->ctx.map.expr->pat_head->match && |
| 5372 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5373 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5374 | else |
| 5375 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5376 | |
| 5377 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5378 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5379 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5380 | break; |
| 5381 | if (match_method >= PAT_MATCH_NUM) |
| 5382 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5383 | else |
| 5384 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5385 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5386 | /* case sensitive */ |
| 5387 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5388 | chunk_appendf(&trash, ", case=insensitive"); |
| 5389 | else |
| 5390 | chunk_appendf(&trash, ", case=sensitive"); |
| 5391 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5392 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5393 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5394 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5395 | chunk_appendf(&trash, ", found=no"); |
| 5396 | else |
| 5397 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5398 | } |
| 5399 | |
| 5400 | /* Display match and match info */ |
| 5401 | else { |
| 5402 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5403 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5404 | chunk_appendf(&trash, ", found=yes"); |
| 5405 | else |
| 5406 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5407 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5408 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5409 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5410 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5411 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5412 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5413 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5414 | /* display pattern */ |
| 5415 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5416 | if (pat->ref && pat->ref->pattern) |
| 5417 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5418 | else |
| 5419 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5420 | } |
| 5421 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5422 | if (pat->ref && pat->ref->pattern) |
| 5423 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5424 | else |
| 5425 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5426 | } |
| 5427 | |
| 5428 | /* display return value */ |
| 5429 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5430 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5431 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5432 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5433 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5434 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5435 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5436 | } |
| 5437 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5438 | chunk_appendf(&trash, "\n"); |
| 5439 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5440 | /* display response */ |
| 5441 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5442 | /* let's try again later from this session. We add ourselves into |
| 5443 | * this session's users so that it can remove us upon termination. |
| 5444 | */ |
| 5445 | return 0; |
| 5446 | } |
| 5447 | |
| 5448 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5449 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5450 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | appctx->st2 = STAT_ST_FIN; |
| 5454 | /* fall through */ |
| 5455 | |
| 5456 | default: |
| 5457 | appctx->st2 = STAT_ST_FIN; |
| 5458 | free(appctx->ctx.map.chunk.str); |
| 5459 | return 1; |
| 5460 | } |
| 5461 | } |
| 5462 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5463 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5464 | { |
| 5465 | struct appctx *appctx = __objt_appctx(si->end); |
| 5466 | |
| 5467 | switch (appctx->st2) { |
| 5468 | |
| 5469 | case STAT_ST_INIT: |
| 5470 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5471 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5472 | struct pat_ref_elt *, list); |
| 5473 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5474 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5475 | appctx->st2 = STAT_ST_LIST; |
| 5476 | /* fall through */ |
| 5477 | |
| 5478 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5479 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5480 | chunk_reset(&trash); |
| 5481 | |
| 5482 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5483 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5484 | chunk_appendf(&trash, "%p %s %s\n", |
| 5485 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5486 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5487 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5488 | chunk_appendf(&trash, "%p %s\n", |
| 5489 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5490 | |
| 5491 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5492 | /* let's try again later from this session. We add ourselves into |
| 5493 | * this session's users so that it can remove us upon termination. |
| 5494 | */ |
| 5495 | return 0; |
| 5496 | } |
| 5497 | |
| 5498 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5499 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5500 | struct pat_ref_elt *, list); |
| 5501 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5502 | break; |
| 5503 | } |
| 5504 | |
| 5505 | appctx->st2 = STAT_ST_FIN; |
| 5506 | /* fall through */ |
| 5507 | |
| 5508 | default: |
| 5509 | appctx->st2 = STAT_ST_FIN; |
| 5510 | return 1; |
| 5511 | } |
| 5512 | } |
| 5513 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5514 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5515 | * 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] | 5516 | * to be called again, otherwise non-zero. It is designed to be called |
| 5517 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5518 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5519 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5520 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5521 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5522 | struct connection *conn; |
| 5523 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5524 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5525 | /* If we're forced to shut down, we might have to remove our |
| 5526 | * reference to the last session being dumped. |
| 5527 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5528 | if (appctx->st2 == STAT_ST_LIST) { |
| 5529 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5530 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5531 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5532 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5533 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5534 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5535 | } |
| 5536 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5537 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5538 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5539 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5540 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5541 | /* the function had not been called yet, let's prepare the |
| 5542 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5543 | * pointer to the first in the global list. When a target |
| 5544 | * session is being destroyed, it is responsible for updating |
| 5545 | * this pointer. We know we have reached the end when this |
| 5546 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5547 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5548 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5549 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5550 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5551 | /* fall through */ |
| 5552 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5553 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5554 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5555 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5556 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5557 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5558 | } |
| 5559 | |
| 5560 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5561 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5562 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5563 | struct session *curr_sess; |
| 5564 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5565 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5566 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5567 | if (appctx->ctx.sess.target) { |
| 5568 | 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] | 5569 | goto next_sess; |
| 5570 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5571 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5572 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5573 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5574 | return 0; |
| 5575 | |
| 5576 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5577 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5578 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5579 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5580 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5581 | break; |
| 5582 | } |
| 5583 | else |
| 5584 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5585 | } |
| 5586 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5587 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5588 | "%p: proto=%s", |
| 5589 | curr_sess, |
| 5590 | curr_sess->listener->proto->name); |
| 5591 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5592 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5593 | conn = objt_conn(curr_sess->si[0].end); |
| 5594 | 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] | 5595 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5596 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5597 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5598 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5599 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5600 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5601 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5602 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5603 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5604 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5605 | break; |
| 5606 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5607 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5608 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5609 | curr_sess->listener->luid, |
| 5610 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5611 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5612 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5613 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5614 | break; |
| 5615 | } |
| 5616 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5617 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5618 | " ts=%02x age=%s calls=%d", |
| 5619 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5620 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5621 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5622 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5623 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5624 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5625 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5626 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5627 | curr_sess->req->analysers, |
| 5628 | curr_sess->req->rex ? |
| 5629 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 5630 | TICKS_TO_MS(1000)) : ""); |
| 5631 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5632 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5633 | ",wx=%s", |
| 5634 | curr_sess->req->wex ? |
| 5635 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 5636 | TICKS_TO_MS(1000)) : ""); |
| 5637 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5638 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5639 | ",ax=%s]", |
| 5640 | curr_sess->req->analyse_exp ? |
| 5641 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 5642 | TICKS_TO_MS(1000)) : ""); |
| 5643 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5644 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5645 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5646 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5647 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5648 | curr_sess->rep->analysers, |
| 5649 | curr_sess->rep->rex ? |
| 5650 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5651 | TICKS_TO_MS(1000)) : ""); |
| 5652 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5653 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5654 | ",wx=%s", |
| 5655 | curr_sess->rep->wex ? |
| 5656 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 5657 | TICKS_TO_MS(1000)) : ""); |
| 5658 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5659 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5660 | ",ax=%s]", |
| 5661 | curr_sess->rep->analyse_exp ? |
| 5662 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5663 | TICKS_TO_MS(1000)) : ""); |
| 5664 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5665 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5666 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5667 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5668 | curr_sess->si[0].state, |
| 5669 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5670 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5671 | curr_sess->si[0].exp ? |
| 5672 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5673 | TICKS_TO_MS(1000)) : ""); |
| 5674 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5675 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5676 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5677 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5678 | curr_sess->si[1].state, |
| 5679 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5680 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5681 | curr_sess->si[1].exp ? |
| 5682 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5683 | TICKS_TO_MS(1000)) : ""); |
| 5684 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5685 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5686 | " exp=%s", |
| 5687 | curr_sess->task->expire ? |
| 5688 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5689 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5690 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5691 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5692 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5693 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5694 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5695 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5696 | /* let's try again later from this session. We add ourselves into |
| 5697 | * this session's users so that it can remove us upon termination. |
| 5698 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5699 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5700 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5701 | } |
| 5702 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5703 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5704 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5705 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5706 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5707 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5708 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5709 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5710 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5711 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5712 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5713 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5714 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5715 | return 0; |
| 5716 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5717 | appctx->ctx.sess.target = NULL; |
| 5718 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5719 | return 1; |
| 5720 | } |
| 5721 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5722 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5723 | /* fall through */ |
| 5724 | |
| 5725 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5726 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5727 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5728 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5729 | } |
| 5730 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5731 | /* This is called when the stream interface is closed. For instance, upon an |
| 5732 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5733 | * remove back references to the session currently being dumped. |
| 5734 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5735 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5736 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5737 | struct appctx *appctx = __objt_appctx(si->end); |
| 5738 | |
| 5739 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5740 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5741 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5742 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5743 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5744 | free(appctx->ctx.cli.err); |
| 5745 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5746 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5747 | free(appctx->ctx.map.chunk.str); |
| 5748 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5749 | } |
| 5750 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5751 | /* This function is used to either dump tables states (when action is set |
| 5752 | * 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] | 5753 | * It returns 0 if the output buffer is full and it needs to be called |
| 5754 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5755 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5756 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5757 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5758 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5759 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5760 | struct ebmb_node *eb; |
| 5761 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5762 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5763 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5764 | |
| 5765 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5766 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5767 | * - STAT_ST_INIT : the first call |
| 5768 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5769 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5770 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5771 | * and the entry pointer points to the next entry to be dumped, |
| 5772 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5773 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5774 | * data though. |
| 5775 | */ |
| 5776 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5777 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5778 | /* 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] | 5779 | if (appctx->st2 == STAT_ST_LIST) { |
| 5780 | appctx->ctx.table.entry->ref_cnt--; |
| 5781 | 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] | 5782 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5783 | return 1; |
| 5784 | } |
| 5785 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5786 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5787 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5788 | while (appctx->st2 != STAT_ST_FIN) { |
| 5789 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5790 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5791 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5792 | if (!appctx->ctx.table.proxy) |
| 5793 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5794 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5795 | appctx->ctx.table.entry = NULL; |
| 5796 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5797 | break; |
| 5798 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5799 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5800 | if (!appctx->ctx.table.proxy || |
| 5801 | (appctx->ctx.table.target && |
| 5802 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5803 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5804 | break; |
| 5805 | } |
| 5806 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5807 | if (appctx->ctx.table.proxy->table.size) { |
| 5808 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5809 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5810 | return 0; |
| 5811 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5812 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5813 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5814 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5815 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5816 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5817 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5818 | appctx->ctx.table.entry->ref_cnt++; |
| 5819 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5820 | break; |
| 5821 | } |
| 5822 | } |
| 5823 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5824 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5825 | break; |
| 5826 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5827 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5828 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5829 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5830 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5831 | /* we're filtering on some data contents */ |
| 5832 | void *ptr; |
| 5833 | long long data; |
| 5834 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5835 | dt = appctx->ctx.table.data_type; |
| 5836 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5837 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5838 | dt); |
| 5839 | |
| 5840 | data = 0; |
| 5841 | switch (stktable_data_types[dt].std_type) { |
| 5842 | case STD_T_SINT: |
| 5843 | data = stktable_data_cast(ptr, std_t_sint); |
| 5844 | break; |
| 5845 | case STD_T_UINT: |
| 5846 | data = stktable_data_cast(ptr, std_t_uint); |
| 5847 | break; |
| 5848 | case STD_T_ULL: |
| 5849 | data = stktable_data_cast(ptr, std_t_ull); |
| 5850 | break; |
| 5851 | case STD_T_FRQP: |
| 5852 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5853 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5854 | break; |
| 5855 | } |
| 5856 | |
| 5857 | /* 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] | 5858 | if ((data < appctx->ctx.table.value && |
| 5859 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5860 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5861 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5862 | (data == appctx->ctx.table.value && |
| 5863 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5864 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5865 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5866 | (data > appctx->ctx.table.value && |
| 5867 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5868 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5869 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5870 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5871 | } |
| 5872 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5873 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5874 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5875 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5876 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5877 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5878 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5879 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5880 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5881 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5882 | struct stksess *old = appctx->ctx.table.entry; |
| 5883 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5884 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5885 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5886 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5887 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5888 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5889 | break; |
| 5890 | } |
| 5891 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5892 | |
| 5893 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5894 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5895 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5896 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5897 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5898 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5899 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5900 | break; |
| 5901 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5902 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5903 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5904 | break; |
| 5905 | } |
| 5906 | } |
| 5907 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5908 | } |
| 5909 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5910 | /* 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] | 5911 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5912 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5913 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5914 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5915 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5916 | * after the offset. The new pointer is returned. |
| 5917 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5918 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5919 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5920 | { |
| 5921 | int end; |
| 5922 | unsigned char c; |
| 5923 | |
| 5924 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5925 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5926 | return ptr; |
| 5927 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5928 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5929 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5930 | while (ptr < len && ptr < bsize) { |
| 5931 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5932 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5933 | if (out->len > end - 2) |
| 5934 | break; |
| 5935 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5936 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5937 | if (out->len > end - 3) |
| 5938 | break; |
| 5939 | out->str[out->len++] = '\\'; |
| 5940 | switch (c) { |
| 5941 | case '\t': c = 't'; break; |
| 5942 | case '\n': c = 'n'; break; |
| 5943 | case '\r': c = 'r'; break; |
| 5944 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5945 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5946 | } |
| 5947 | out->str[out->len++] = c; |
| 5948 | } else { |
| 5949 | if (out->len > end - 5) |
| 5950 | break; |
| 5951 | out->str[out->len++] = '\\'; |
| 5952 | out->str[out->len++] = 'x'; |
| 5953 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5954 | out->str[out->len++] = hextab[c & 0xF]; |
| 5955 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5956 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5957 | /* we had a line break, let's return now */ |
| 5958 | out->str[out->len++] = '\n'; |
| 5959 | *line = ptr; |
| 5960 | return ptr; |
| 5961 | } |
| 5962 | } |
| 5963 | /* we have an incomplete line, we return it as-is */ |
| 5964 | out->str[out->len++] = '\n'; |
| 5965 | return ptr; |
| 5966 | } |
| 5967 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5968 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5969 | * 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] | 5970 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5971 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5972 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5973 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5974 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5975 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5976 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5977 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5978 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5979 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5980 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5981 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5982 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5983 | /* the function had not been called yet, let's prepare the |
| 5984 | * buffer for a response. |
| 5985 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5986 | struct tm tm; |
| 5987 | |
| 5988 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5989 | 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] | 5990 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5991 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5992 | error_snapshot_id); |
| 5993 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5994 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5995 | /* Socket buffer full. Let's try again later from the same point */ |
| 5996 | return 0; |
| 5997 | } |
| 5998 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5999 | appctx->ctx.errors.px = proxy; |
| 6000 | appctx->ctx.errors.buf = 0; |
| 6001 | appctx->ctx.errors.bol = 0; |
| 6002 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | /* we have two inner loops here, one for the proxy, the other one for |
| 6006 | * the buffer. |
| 6007 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6008 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6009 | struct error_snapshot *es; |
| 6010 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6011 | if (appctx->ctx.errors.buf == 0) |
| 6012 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6013 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6014 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6015 | |
| 6016 | if (!es->when.tv_sec) |
| 6017 | goto next; |
| 6018 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6019 | if (appctx->ctx.errors.iid >= 0 && |
| 6020 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6021 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6022 | goto next; |
| 6023 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6024 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6025 | /* just print headers now */ |
| 6026 | |
| 6027 | char pn[INET6_ADDRSTRLEN]; |
| 6028 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6029 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6030 | |
| 6031 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6032 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6033 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6034 | 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] | 6035 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6036 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6037 | case AF_INET: |
| 6038 | case AF_INET6: |
| 6039 | port = get_host_port(&es->src); |
| 6040 | break; |
| 6041 | default: |
| 6042 | port = 0; |
| 6043 | } |
| 6044 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6045 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6046 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6047 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6048 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6049 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6050 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6051 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6052 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6053 | break; |
| 6054 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6055 | chunk_appendf(&trash, |
Olivier Doucet | 815d7d5 | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6056 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6057 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6058 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6059 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6060 | break; |
| 6061 | } |
| 6062 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6063 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6064 | ", server %s (#%d), event #%u\n" |
| 6065 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6066 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6067 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6068 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6069 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6070 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6071 | es->ev_id, |
| 6072 | pn, port, es->sid, es->s_flags, |
| 6073 | es->state, es->m_flags, es->t_flags, |
| 6074 | es->m_clen, es->m_blen, |
| 6075 | es->b_flags, es->b_out, es->b_tot, |
| 6076 | es->len, es->b_wrap, es->pos); |
| 6077 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6078 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6079 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6080 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6081 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6082 | appctx->ctx.errors.ptr = 0; |
| 6083 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6084 | } |
| 6085 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6086 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6087 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6088 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6089 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6090 | if (bi_putchk(si->ib, &trash) == -1) |
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 | goto next; |
| 6093 | } |
| 6094 | |
| 6095 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6096 | 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] | 6097 | int newptr; |
| 6098 | int newline; |
| 6099 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6100 | newline = appctx->ctx.errors.bol; |
| 6101 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6102 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6103 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6104 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6105 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6106 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6107 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6108 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6109 | appctx->ctx.errors.ptr = newptr; |
| 6110 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6111 | }; |
| 6112 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6113 | appctx->ctx.errors.bol = 0; |
| 6114 | appctx->ctx.errors.ptr = -1; |
| 6115 | appctx->ctx.errors.buf++; |
| 6116 | if (appctx->ctx.errors.buf > 1) { |
| 6117 | appctx->ctx.errors.buf = 0; |
| 6118 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6119 | } |
| 6120 | } |
| 6121 | |
| 6122 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6123 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6124 | } |
| 6125 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6126 | /* parse the "level" argument on the bind lines */ |
| 6127 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6128 | { |
| 6129 | if (!*args[cur_arg + 1]) { |
| 6130 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6131 | return ERR_ALERT | ERR_FATAL; |
| 6132 | } |
| 6133 | |
| 6134 | if (!strcmp(args[cur_arg+1], "user")) |
| 6135 | conf->level = ACCESS_LVL_USER; |
| 6136 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6137 | conf->level = ACCESS_LVL_OPER; |
| 6138 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6139 | conf->level = ACCESS_LVL_ADMIN; |
| 6140 | else { |
| 6141 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6142 | args[cur_arg], args[cur_arg+1]); |
| 6143 | return ERR_ALERT | ERR_FATAL; |
| 6144 | } |
| 6145 | |
| 6146 | return 0; |
| 6147 | } |
| 6148 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6149 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6150 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6151 | .name = "<STATS>", /* used for logging */ |
| 6152 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6153 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6154 | }; |
| 6155 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6156 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6157 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6158 | .name = "<CLI>", /* used for logging */ |
| 6159 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6160 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6161 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6162 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6163 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6164 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6165 | { 0, NULL, NULL }, |
| 6166 | }}; |
| 6167 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6168 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6169 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6170 | { NULL, NULL, 0 }, |
| 6171 | }}; |
| 6172 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6173 | __attribute__((constructor)) |
| 6174 | static void __dumpstats_module_init(void) |
| 6175 | { |
| 6176 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6177 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6178 | } |
| 6179 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6180 | /* |
| 6181 | * Local variables: |
| 6182 | * c-indent-level: 8 |
| 6183 | * c-basic-offset: 8 |
| 6184 | * End: |
| 6185 | */ |