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> |
| 38 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | |
| 41 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 42 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 43 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 44 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 45 | #include <proto/dumpstats.h> |
| 46 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 47 | #include <proto/freq_ctr.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 48 | #include <proto/log.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 49 | #include <proto/pattern.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 50 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 51 | #include <proto/listener.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 52 | #include <proto/map.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 53 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 54 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 55 | #include <proto/proxy.h> |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 56 | #include <proto/sample.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 57 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 58 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 59 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 60 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 61 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 62 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 63 | #ifdef USE_OPENSSL |
| 64 | #include <proto/ssl_sock.h> |
| 65 | #endif |
| 66 | |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 67 | /* stats socket states */ |
| 68 | enum { |
| 69 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 70 | STAT_CLI_END, /* final state, let's close */ |
| 71 | STAT_CLI_GETREQ, /* wait for a request */ |
| 72 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 73 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 74 | STAT_CLI_PRINT, /* display message in cli->msg */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 75 | 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] | 76 | STAT_CLI_O_INFO, /* dump info */ |
| 77 | STAT_CLI_O_SESS, /* dump sessions */ |
| 78 | STAT_CLI_O_ERR, /* dump errors */ |
| 79 | STAT_CLI_O_TAB, /* dump tables */ |
| 80 | STAT_CLI_O_CLR, /* clear tables */ |
| 81 | STAT_CLI_O_SET, /* set entries in tables */ |
| 82 | STAT_CLI_O_STAT, /* dump stats */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 83 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 84 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 85 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 86 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 89 | /* Actions available for the stats admin forms */ |
| 90 | enum { |
| 91 | ST_ADM_ACTION_NONE = 0, |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 92 | |
| 93 | /* enable/disable health checks */ |
| 94 | ST_ADM_ACTION_DHLTH, |
| 95 | ST_ADM_ACTION_EHLTH, |
| 96 | |
| 97 | /* force health check status */ |
| 98 | ST_ADM_ACTION_HRUNN, |
| 99 | ST_ADM_ACTION_HNOLB, |
| 100 | ST_ADM_ACTION_HDOWN, |
| 101 | |
| 102 | /* enable/disable agent checks */ |
| 103 | ST_ADM_ACTION_DAGENT, |
| 104 | ST_ADM_ACTION_EAGENT, |
| 105 | |
| 106 | /* force agent check status */ |
| 107 | ST_ADM_ACTION_ARUNN, |
| 108 | ST_ADM_ACTION_ADOWN, |
| 109 | |
| 110 | /* set admin state */ |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 111 | ST_ADM_ACTION_READY, |
| 112 | ST_ADM_ACTION_DRAIN, |
| 113 | ST_ADM_ACTION_MAINT, |
| 114 | ST_ADM_ACTION_SHUTDOWN, |
| 115 | /* these are the ancient actions, still available for compatibility */ |
| 116 | ST_ADM_ACTION_DISABLE, |
| 117 | ST_ADM_ACTION_ENABLE, |
| 118 | ST_ADM_ACTION_STOP, |
| 119 | ST_ADM_ACTION_START, |
| 120 | }; |
| 121 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 122 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 123 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 124 | 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] | 125 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 126 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 127 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 128 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 129 | 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] | 130 | static int stats_pats_list(struct stream_interface *si); |
| 131 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 132 | static int stats_map_lookup(struct stream_interface *si); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 133 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 134 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 135 | * cli_io_handler() |
| 136 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 137 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 138 | * -> stats_dump_info_to_buffer() // "show info" |
| 139 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 140 | * -> stats_dump_csv_header() |
| 141 | * -> stats_dump_proxy_to_buffer() |
| 142 | * -> stats_dump_fe_stats() |
| 143 | * -> stats_dump_li_stats() |
| 144 | * -> stats_dump_sv_stats() |
| 145 | * -> stats_dump_be_stats() |
| 146 | * |
| 147 | * http_stats_io_handler() |
| 148 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 149 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 150 | * -> stats_dump_html_head() // emits the HTML headers |
| 151 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 152 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 153 | * -> stats_dump_html_px_hdr() |
| 154 | * -> stats_dump_fe_stats() |
| 155 | * -> stats_dump_li_stats() |
| 156 | * -> stats_dump_sv_stats() |
| 157 | * -> stats_dump_be_stats() |
| 158 | * -> stats_dump_html_px_end() |
| 159 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 160 | */ |
| 161 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 162 | static struct si_applet cli_applet; |
| 163 | |
| 164 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 165 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 166 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 167 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 168 | " help : this message\n" |
| 169 | " prompt : toggle interactive mode with prompt\n" |
| 170 | " quit : disconnect\n" |
| 171 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 172 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 173 | " show stat : report counters for each proxy and server\n" |
| 174 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 175 | " 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] | 176 | " 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] | 177 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 178 | " set weight : change a server's weight\n" |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 179 | " set server : change a server's state or weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 180 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 181 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 182 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 183 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 184 | " disable : put a server or frontend in maintenance mode\n" |
| 185 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 186 | " shutdown : kill a session or a frontend (eg:to release listening ports)\n" |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 187 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 188 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 189 | " add acl : add acl entry\n" |
| 190 | " del acl : delete acl entry\n" |
| 191 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 192 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 193 | " get map : reports the keys and values matching a sample for a map\n" |
| 194 | " set map : modify map entry\n" |
| 195 | " add map : add map entry\n" |
| 196 | " del map : delete map entry\n" |
| 197 | " clear map <id> : clear the content of this map\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 198 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 199 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 200 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 201 | "Permission denied\n" |
| 202 | ""; |
| 203 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 204 | /* data transmission states for the stats responses */ |
| 205 | enum { |
| 206 | STAT_ST_INIT = 0, |
| 207 | STAT_ST_HEAD, |
| 208 | STAT_ST_INFO, |
| 209 | STAT_ST_LIST, |
| 210 | STAT_ST_END, |
| 211 | STAT_ST_FIN, |
| 212 | }; |
| 213 | |
| 214 | /* data transmission states for the stats responses inside a proxy */ |
| 215 | enum { |
| 216 | STAT_PX_ST_INIT = 0, |
| 217 | STAT_PX_ST_TH, |
| 218 | STAT_PX_ST_FE, |
| 219 | STAT_PX_ST_LI, |
| 220 | STAT_PX_ST_SV, |
| 221 | STAT_PX_ST_BE, |
| 222 | STAT_PX_ST_END, |
| 223 | STAT_PX_ST_FIN, |
| 224 | }; |
| 225 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 226 | extern const char *stat_status_codes[]; |
| 227 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 228 | /* 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] | 229 | * 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] | 230 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 231 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 232 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 233 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 234 | s->target = &cli_applet.obj_type; |
Willy Tarreau | 4171e9e | 2013-12-01 12:32:30 +0100 | [diff] [blame] | 235 | /* 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] | 236 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 237 | tv_zero(&s->logs.tv_request); |
| 238 | s->logs.t_queue = 0; |
| 239 | s->logs.t_connect = 0; |
| 240 | s->logs.t_data = 0; |
| 241 | s->logs.t_close = 0; |
| 242 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 243 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 244 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 245 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 246 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 247 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 248 | if (s->listener->timeout) { |
| 249 | s->req->rto = *s->listener->timeout; |
| 250 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 251 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 252 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 255 | /* allocate a new stats frontend named <name>, and return it |
| 256 | * (or NULL in case of lack of memory). |
| 257 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 258 | 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] | 259 | { |
| 260 | struct proxy *fe; |
| 261 | |
| 262 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 263 | if (!fe) |
| 264 | return NULL; |
| 265 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 266 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 267 | fe->next = proxy; |
| 268 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 269 | fe->last_change = now.tv_sec; |
| 270 | fe->id = strdup("GLOBAL"); |
| 271 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 272 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 273 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 274 | fe->conf.file = strdup(file); |
| 275 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 276 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 277 | |
| 278 | /* the stats frontend is the only one able to assign ID #0 */ |
| 279 | fe->conf.id.key = fe->uuid = 0; |
| 280 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 281 | return fe; |
| 282 | } |
| 283 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 284 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 285 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 286 | * error message into the <err> buffer which will be preallocated. The trailing |
| 287 | * '\n' must not be written. The function must be called with <args> pointing to |
| 288 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 289 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 290 | 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] | 291 | struct proxy *defpx, const char *file, int line, |
| 292 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 293 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 294 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 295 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 296 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 297 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 298 | int cur_arg; |
| 299 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 300 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 301 | 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] | 302 | return -1; |
| 303 | } |
| 304 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 305 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 306 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 307 | 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] | 308 | return -1; |
| 309 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 312 | 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] | 313 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 314 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 315 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 316 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 317 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 318 | return -1; |
| 319 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 320 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 321 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 322 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 323 | static int bind_dumped; |
| 324 | struct bind_kw *kw; |
| 325 | |
| 326 | kw = bind_find_kw(args[cur_arg]); |
| 327 | if (kw) { |
| 328 | if (!kw->parse) { |
| 329 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 330 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 331 | return -1; |
| 332 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 333 | |
| 334 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 335 | if (err && *err) |
| 336 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 337 | else |
| 338 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 339 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 340 | return -1; |
| 341 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 342 | |
| 343 | cur_arg += 1 + kw->skip; |
| 344 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 345 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 346 | |
| 347 | if (!bind_dumped) { |
| 348 | bind_dump_kws(err); |
| 349 | indent_msg(err, 4); |
| 350 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 351 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 352 | |
| 353 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 354 | args[0], args[1], args[cur_arg], |
| 355 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 356 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 357 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 358 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 359 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 360 | l->maxconn = global.stats_fe->maxconn; |
| 361 | l->backlog = global.stats_fe->backlog; |
| 362 | l->timeout = &global.stats_fe->timeout.client; |
| 363 | l->accept = session_accept; |
| 364 | l->handler = process_session; |
| 365 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 366 | l->nice = -64; /* we want to boost priority for local stats */ |
| 367 | global.maxsock += l->maxconn; |
| 368 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 369 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 370 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 371 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 372 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 373 | |
| 374 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 375 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 376 | return -1; |
| 377 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 378 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 379 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 380 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 381 | return -1; |
| 382 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 383 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 384 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 385 | 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] | 386 | return -1; |
| 387 | } |
| 388 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 389 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 390 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 391 | else if (!strcmp(args[1], "maxconn")) { |
| 392 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 393 | |
| 394 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 395 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 396 | return -1; |
| 397 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 398 | |
| 399 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 400 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 401 | 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] | 402 | return -1; |
| 403 | } |
| 404 | } |
| 405 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 406 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 407 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 408 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 409 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 410 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 411 | if (!global.stats_fe) { |
| 412 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 413 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 414 | return -1; |
| 415 | } |
| 416 | } |
| 417 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 418 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 419 | unsigned int low, high; |
| 420 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 421 | if (strcmp(args[cur_arg], "all") == 0) { |
| 422 | set = 0; |
| 423 | break; |
| 424 | } |
| 425 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 426 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 427 | } |
| 428 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 429 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 430 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 431 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 432 | char *dash = strchr(args[cur_arg], '-'); |
| 433 | |
| 434 | low = high = str2uic(args[cur_arg]); |
| 435 | if (dash) |
| 436 | high = str2uic(dash + 1); |
| 437 | |
| 438 | if (high < low) { |
| 439 | unsigned int swap = low; |
| 440 | low = high; |
| 441 | high = swap; |
| 442 | } |
| 443 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 444 | if (low < 1 || high > LONGBITS) { |
| 445 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 446 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 447 | return -1; |
| 448 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 449 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 450 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 451 | } |
| 452 | else { |
| 453 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 454 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 455 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 456 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 457 | } |
| 458 | cur_arg++; |
| 459 | } |
| 460 | global.stats_fe->bind_proc = set; |
| 461 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 462 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 463 | 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] | 464 | return -1; |
| 465 | } |
| 466 | return 0; |
| 467 | } |
| 468 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 469 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 470 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 471 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 472 | * 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] | 473 | */ |
| 474 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 475 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 476 | chunk_appendf(&trash, |
| 477 | "# pxname,svname," |
| 478 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 479 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 480 | "bin,bout," |
| 481 | "dreq,dresp," |
| 482 | "ereq,econ,eresp," |
| 483 | "wretr,wredis," |
| 484 | "status,weight,act,bck," |
| 485 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 486 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 487 | "rate,rate_lim,rate_max," |
| 488 | "check_status,check_code,check_duration," |
| 489 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 490 | "req_rate,req_rate_max,req_tot," |
| 491 | "cli_abrt,srv_abrt," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 492 | "comp_in,comp_out,comp_byp,comp_rsp,lastsess," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 493 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 494 | } |
| 495 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 496 | /* print a string of text buffer to <out>. The format is : |
| 497 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 498 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 499 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 500 | */ |
| 501 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 502 | { |
| 503 | unsigned char c; |
| 504 | int ptr = 0; |
| 505 | |
| 506 | while (buf[ptr] && ptr < bsize) { |
| 507 | c = buf[ptr]; |
| 508 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 509 | if (out->len > out->size - 1) |
| 510 | break; |
| 511 | out->str[out->len++] = c; |
| 512 | } |
| 513 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 514 | if (out->len > out->size - 2) |
| 515 | break; |
| 516 | out->str[out->len++] = '\\'; |
| 517 | switch (c) { |
| 518 | case ' ': c = ' '; break; |
| 519 | case '\t': c = 't'; break; |
| 520 | case '\n': c = 'n'; break; |
| 521 | case '\r': c = 'r'; break; |
| 522 | case '\e': c = 'e'; break; |
| 523 | case '\\': c = '\\'; break; |
| 524 | } |
| 525 | out->str[out->len++] = c; |
| 526 | } |
| 527 | else { |
| 528 | if (out->len > out->size - 4) |
| 529 | break; |
| 530 | out->str[out->len++] = '\\'; |
| 531 | out->str[out->len++] = 'x'; |
| 532 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 533 | out->str[out->len++] = hextab[c & 0xF]; |
| 534 | } |
| 535 | ptr++; |
| 536 | } |
| 537 | |
| 538 | return ptr; |
| 539 | } |
| 540 | |
| 541 | /* print a buffer in hexa. |
| 542 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 543 | */ |
| 544 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 545 | { |
| 546 | unsigned char c; |
| 547 | int ptr = 0; |
| 548 | |
| 549 | while (ptr < bsize) { |
| 550 | c = buf[ptr]; |
| 551 | |
| 552 | if (out->len > out->size - 2) |
| 553 | break; |
| 554 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 555 | out->str[out->len++] = hextab[c & 0xF]; |
| 556 | |
| 557 | ptr++; |
| 558 | } |
| 559 | return ptr; |
| 560 | } |
| 561 | |
| 562 | /* Dump the status of a table to a stream interface's |
| 563 | * read buffer. It returns 0 if the output buffer is full |
| 564 | * and needs to be called again, otherwise non-zero. |
| 565 | */ |
| 566 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 567 | struct proxy *proxy, struct proxy *target) |
| 568 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 569 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 570 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 571 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 572 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 573 | |
| 574 | /* any other information should be dumped here */ |
| 575 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 576 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 577 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 578 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 579 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 580 | return 0; |
| 581 | |
| 582 | return 1; |
| 583 | } |
| 584 | |
| 585 | /* Dump the a table entry to a stream interface's |
| 586 | * read buffer. It returns 0 if the output buffer is full |
| 587 | * and needs to be called again, otherwise non-zero. |
| 588 | */ |
| 589 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 590 | struct proxy *proxy, struct stksess *entry) |
| 591 | { |
| 592 | int dt; |
| 593 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 594 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 595 | |
| 596 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 597 | char addr[INET_ADDRSTRLEN]; |
| 598 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 599 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 600 | } |
| 601 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 602 | char addr[INET6_ADDRSTRLEN]; |
| 603 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 604 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 605 | } |
| 606 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 607 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 608 | } |
| 609 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 610 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 611 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 612 | } |
| 613 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 614 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 615 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 616 | } |
| 617 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 618 | 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] | 619 | |
| 620 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 621 | void *ptr; |
| 622 | |
| 623 | if (proxy->table.data_ofs[dt] == 0) |
| 624 | continue; |
| 625 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 626 | 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] | 627 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 628 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 629 | |
| 630 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 631 | switch (stktable_data_types[dt].std_type) { |
| 632 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 633 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 634 | break; |
| 635 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 636 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 637 | break; |
| 638 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 639 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 640 | break; |
| 641 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 642 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 643 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 644 | proxy->table.data_arg[dt].u)); |
| 645 | break; |
| 646 | } |
| 647 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 648 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 649 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 650 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 651 | return 0; |
| 652 | |
| 653 | return 1; |
| 654 | } |
| 655 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 656 | 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] | 657 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 658 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 659 | struct appctx *appctx = __objt_appctx(si->end); |
| 660 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 661 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 662 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 663 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 664 | long long value; |
| 665 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 666 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 667 | void *ptr; |
| 668 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 669 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 670 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 671 | |
| 672 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 673 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 674 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 675 | return; |
| 676 | } |
| 677 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 678 | switch (px->table.type) { |
| 679 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 680 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 681 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 682 | break; |
| 683 | case STKTABLE_TYPE_IPV6: |
| 684 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 685 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 686 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 687 | case STKTABLE_TYPE_INTEGER: |
| 688 | { |
| 689 | char *endptr; |
| 690 | unsigned long val; |
| 691 | errno = 0; |
| 692 | val = strtoul(args[4], &endptr, 10); |
| 693 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 694 | (errno != 0 && val == 0) || endptr == args[4] || |
| 695 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 696 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 697 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 698 | return; |
| 699 | } |
| 700 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 701 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 702 | break; |
| 703 | } |
| 704 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 705 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 706 | static_table_key->key = args[4]; |
| 707 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 708 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 709 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 710 | switch (action) { |
| 711 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 712 | 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] | 713 | break; |
| 714 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 715 | 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] | 716 | break; |
| 717 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 718 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 719 | break; |
| 720 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 721 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 722 | return; |
| 723 | } |
| 724 | |
| 725 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 726 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 727 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 728 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 729 | return; |
| 730 | } |
| 731 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 732 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 733 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 734 | switch (action) { |
| 735 | case STAT_CLI_O_TAB: |
| 736 | if (!ts) |
| 737 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 738 | chunk_reset(&trash); |
| 739 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 740 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 741 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 742 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 743 | |
| 744 | case STAT_CLI_O_CLR: |
| 745 | if (!ts) |
| 746 | return; |
| 747 | if (ts->ref_cnt) { |
| 748 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 749 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 750 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 751 | return; |
| 752 | } |
| 753 | stksess_kill(&px->table, ts); |
| 754 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 755 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 756 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 757 | if (ts) |
| 758 | stktable_touch(&px->table, ts, 1); |
| 759 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 760 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 761 | if (!ts) { |
| 762 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 763 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 764 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 765 | return; |
| 766 | } |
| 767 | stktable_store(&px->table, ts, 1); |
| 768 | } |
| 769 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 770 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 771 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 772 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 773 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 774 | return; |
| 775 | } |
| 776 | |
| 777 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 778 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 779 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 780 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 781 | return; |
| 782 | } |
| 783 | |
| 784 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 785 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 786 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 787 | return; |
| 788 | } |
| 789 | |
| 790 | 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] | 791 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 792 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 793 | return; |
| 794 | } |
| 795 | |
| 796 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 797 | |
| 798 | switch (stktable_data_types[data_type].std_type) { |
| 799 | case STD_T_SINT: |
| 800 | stktable_data_cast(ptr, std_t_sint) = value; |
| 801 | break; |
| 802 | case STD_T_UINT: |
| 803 | stktable_data_cast(ptr, std_t_uint) = value; |
| 804 | break; |
| 805 | case STD_T_ULL: |
| 806 | stktable_data_cast(ptr, std_t_ull) = value; |
| 807 | break; |
| 808 | case STD_T_FRQP: |
| 809 | /* We set both the current and previous values. That way |
| 810 | * the reported frequency is stable during all the period |
| 811 | * then slowly fades out. This allows external tools to |
| 812 | * push measures without having to update them too often. |
| 813 | */ |
| 814 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 815 | frqp->curr_tick = now_ms; |
| 816 | frqp->prev_ctr = 0; |
| 817 | frqp->curr_ctr = value; |
| 818 | break; |
| 819 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 820 | } |
| 821 | break; |
| 822 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 823 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 824 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 825 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 826 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 827 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 828 | } |
| 829 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 830 | 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] | 831 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 832 | struct appctx *appctx = __objt_appctx(si->end); |
| 833 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 834 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 835 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 836 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 837 | return; |
| 838 | } |
| 839 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 840 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 841 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 842 | if (appctx->ctx.table.data_type < 0) { |
| 843 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 844 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 845 | return; |
| 846 | } |
| 847 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 848 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 849 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 850 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 851 | return; |
| 852 | } |
| 853 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 854 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 855 | if (appctx->ctx.table.data_op < 0) { |
| 856 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 857 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 858 | return; |
| 859 | } |
| 860 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 861 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 862 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 863 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 864 | return; |
| 865 | } |
| 866 | } |
| 867 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 868 | 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] | 869 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 870 | struct appctx *appctx = __objt_appctx(si->end); |
| 871 | |
| 872 | appctx->ctx.table.data_type = -1; |
| 873 | appctx->st2 = STAT_ST_INIT; |
| 874 | appctx->ctx.table.target = NULL; |
| 875 | appctx->ctx.table.proxy = NULL; |
| 876 | appctx->ctx.table.entry = NULL; |
| 877 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 878 | |
| 879 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 880 | appctx->ctx.table.target = find_stktable(args[2]); |
| 881 | if (!appctx->ctx.table.target) { |
| 882 | appctx->ctx.cli.msg = "No such table\n"; |
| 883 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 884 | return; |
| 885 | } |
| 886 | } |
| 887 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 888 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 889 | goto err_args; |
| 890 | return; |
| 891 | } |
| 892 | |
| 893 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 894 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 895 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 896 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 897 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 898 | goto err_args; |
| 899 | |
| 900 | return; |
| 901 | |
| 902 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 903 | switch (action) { |
| 904 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 905 | 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] | 906 | break; |
| 907 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 908 | 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] | 909 | break; |
| 910 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 911 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 912 | break; |
| 913 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 914 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 915 | } |
| 916 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 917 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 918 | * adequate error messages and returns NULL. This function also expects the session |
| 919 | * level to be admin. |
| 920 | */ |
| 921 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 922 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 923 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 924 | struct proxy *px; |
| 925 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 926 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 927 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 928 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 929 | return NULL; |
| 930 | } |
| 931 | |
| 932 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 933 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 934 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 935 | return NULL; |
| 936 | } |
| 937 | |
| 938 | px = findproxy(arg, PR_CAP_FE); |
| 939 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 940 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 941 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 942 | return NULL; |
| 943 | } |
| 944 | return px; |
| 945 | } |
| 946 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 947 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 948 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 949 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 950 | * the <arg> is modified to remove the '/'. |
| 951 | */ |
| 952 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 953 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 954 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 955 | struct proxy *px; |
| 956 | struct server *sv; |
| 957 | char *line; |
| 958 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 959 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 960 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 961 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 962 | return NULL; |
| 963 | } |
| 964 | |
| 965 | /* split "backend/server" and make <line> point to server */ |
| 966 | for (line = arg; *line; line++) |
| 967 | if (*line == '/') { |
| 968 | *line++ = '\0'; |
| 969 | break; |
| 970 | } |
| 971 | |
| 972 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 973 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 974 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 975 | return NULL; |
| 976 | } |
| 977 | |
| 978 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 979 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 980 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 981 | return NULL; |
| 982 | } |
| 983 | |
| 984 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 985 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 986 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 987 | return NULL; |
| 988 | } |
| 989 | |
| 990 | return sv; |
| 991 | } |
| 992 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 993 | /* This function is used with map and acl management. It permits to browse |
| 994 | * each reference. The variable <getnext> must contain the current node, |
| 995 | * <end> point to the root node and the <flags> permit to filter required |
| 996 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 997 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 998 | static inline |
| 999 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1000 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1001 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1002 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1003 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1004 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1005 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1006 | /* Get next list entry. */ |
| 1007 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
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 | /* If the entry is the last of the list, return NULL. */ |
| 1010 | if (&ref->list == end) |
| 1011 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1012 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1013 | /* If the entry match the flag, return it. */ |
| 1014 | if (ref->flags & flags) |
| 1015 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1019 | static inline |
| 1020 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1021 | { |
| 1022 | int id; |
| 1023 | char *error; |
| 1024 | |
| 1025 | /* If the reference starts by a '#', this is numeric id. */ |
| 1026 | if (reference[0] == '#') { |
| 1027 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1028 | id = strtol(reference + 1, &error, 10); |
| 1029 | if (*error != '\0') |
| 1030 | return NULL; |
| 1031 | |
| 1032 | /* Perform the unique id lookup. */ |
| 1033 | return pat_ref_lookupid(id); |
| 1034 | } |
| 1035 | |
| 1036 | /* Perform the string lookup. */ |
| 1037 | return pat_ref_lookup(reference); |
| 1038 | } |
| 1039 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1040 | /* This function is used with map and acl management. It permits to browse |
| 1041 | * each reference. |
| 1042 | */ |
| 1043 | static inline |
| 1044 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1045 | { |
| 1046 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1047 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1048 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1049 | return NULL; |
| 1050 | return expr; |
| 1051 | } |
| 1052 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1053 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1054 | * 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] | 1055 | * 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] | 1056 | * designating the function which will have to process the request, which can |
| 1057 | * 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] | 1058 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1059 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1060 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 1061 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1062 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1063 | char *args[MAX_STATS_ARGS + 1]; |
| 1064 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1065 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1066 | |
| 1067 | while (isspace((unsigned char)*line)) |
| 1068 | line++; |
| 1069 | |
| 1070 | arg = 0; |
| 1071 | args[arg] = line; |
| 1072 | |
| 1073 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1074 | if (*line == '\\') { |
| 1075 | line++; |
| 1076 | if (*line == '\0') |
| 1077 | break; |
| 1078 | } |
| 1079 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1080 | *line++ = '\0'; |
| 1081 | |
| 1082 | while (isspace((unsigned char)*line)) |
| 1083 | line++; |
| 1084 | |
| 1085 | args[++arg] = line; |
| 1086 | continue; |
| 1087 | } |
| 1088 | |
| 1089 | line++; |
| 1090 | } |
| 1091 | |
| 1092 | while (++arg <= MAX_STATS_ARGS) |
| 1093 | args[arg] = line; |
| 1094 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1095 | /* remove \ */ |
| 1096 | arg = 0; |
| 1097 | while (*args[arg] != '\0') { |
| 1098 | j = 0; |
| 1099 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1100 | if (args[arg][i] == '\\') |
| 1101 | continue; |
| 1102 | args[arg][j] = args[arg][i]; |
| 1103 | j++; |
| 1104 | } |
| 1105 | args[arg][j] = '\0'; |
| 1106 | arg++; |
| 1107 | } |
| 1108 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1109 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1110 | if (strcmp(args[0], "show") == 0) { |
| 1111 | if (strcmp(args[1], "stat") == 0) { |
| 1112 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1113 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1114 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1115 | appctx->ctx.stats.type = atoi(args[3]); |
| 1116 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1117 | } |
| 1118 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1119 | appctx->st2 = STAT_ST_INIT; |
| 1120 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1121 | } |
| 1122 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1123 | appctx->st2 = STAT_ST_INIT; |
| 1124 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1125 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1126 | else if (strcmp(args[1], "pools") == 0) { |
| 1127 | appctx->st2 = STAT_ST_INIT; |
| 1128 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1129 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1130 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1131 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1132 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1133 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1134 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1135 | return 1; |
| 1136 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1137 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1138 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1139 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1140 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1141 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1142 | appctx->ctx.sess.target = NULL; |
| 1143 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1144 | appctx->ctx.sess.pos = 0; |
| 1145 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1146 | } |
| 1147 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1148 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1149 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1150 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1151 | return 1; |
| 1152 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1153 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1154 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1155 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1156 | appctx->ctx.errors.iid = -1; |
| 1157 | appctx->ctx.errors.px = NULL; |
| 1158 | appctx->st2 = STAT_ST_INIT; |
| 1159 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1160 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1161 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1162 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1163 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1164 | else if (strcmp(args[1], "map") == 0 || |
| 1165 | strcmp(args[1], "acl") == 0) { |
| 1166 | |
| 1167 | /* Set ACL or MAP flags. */ |
| 1168 | if (args[1][0] == 'm') |
| 1169 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1170 | else |
| 1171 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1172 | |
| 1173 | /* no parameter: display all map avalaible */ |
| 1174 | if (!*args[2]) { |
| 1175 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1176 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1177 | return 1; |
| 1178 | } |
| 1179 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1180 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1181 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1182 | if (!appctx->ctx.map.ref || |
| 1183 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1184 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1185 | 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] | 1186 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1187 | 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] | 1188 | appctx->st0 = STAT_CLI_PRINT; |
| 1189 | return 1; |
| 1190 | } |
| 1191 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1192 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1193 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1194 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1195 | return 0; |
| 1196 | } |
| 1197 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1198 | else if (strcmp(args[0], "clear") == 0) { |
| 1199 | if (strcmp(args[1], "counters") == 0) { |
| 1200 | struct proxy *px; |
| 1201 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1202 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1203 | int clrall = 0; |
| 1204 | |
| 1205 | if (strcmp(args[2], "all") == 0) |
| 1206 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1207 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1208 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1209 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1210 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1211 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1212 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1213 | return 1; |
| 1214 | } |
| 1215 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1216 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1217 | if (clrall) { |
| 1218 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1219 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1220 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1221 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1222 | px->be_counters.conn_max = 0; |
| 1223 | px->be_counters.p.http.rps_max = 0; |
| 1224 | px->be_counters.sps_max = 0; |
| 1225 | px->be_counters.cps_max = 0; |
| 1226 | px->be_counters.nbpend_max = 0; |
| 1227 | |
| 1228 | px->fe_counters.conn_max = 0; |
| 1229 | px->fe_counters.p.http.rps_max = 0; |
| 1230 | px->fe_counters.sps_max = 0; |
| 1231 | px->fe_counters.cps_max = 0; |
| 1232 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1233 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1234 | |
| 1235 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1236 | if (clrall) |
| 1237 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1238 | else { |
| 1239 | sv->counters.cur_sess_max = 0; |
| 1240 | sv->counters.nbpend_max = 0; |
| 1241 | sv->counters.sps_max = 0; |
| 1242 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1243 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1244 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1245 | if (li->counters) { |
| 1246 | if (clrall) |
| 1247 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1248 | else |
| 1249 | li->counters->conn_max = 0; |
| 1250 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1251 | } |
| 1252 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1253 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1254 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1255 | return 1; |
| 1256 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1257 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1258 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1259 | /* end of processing */ |
| 1260 | return 1; |
| 1261 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1262 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1263 | /* Set ACL or MAP flags. */ |
| 1264 | if (args[1][0] == 'm') |
| 1265 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1266 | else |
| 1267 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1268 | |
| 1269 | /* no parameter */ |
| 1270 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1271 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1272 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1273 | else |
| 1274 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1275 | appctx->st0 = STAT_CLI_PRINT; |
| 1276 | return 1; |
| 1277 | } |
| 1278 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1279 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1280 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1281 | if (!appctx->ctx.map.ref || |
| 1282 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1283 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1284 | 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] | 1285 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1286 | 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] | 1287 | appctx->st0 = STAT_CLI_PRINT; |
| 1288 | return 1; |
| 1289 | } |
| 1290 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1291 | /* Clear all. */ |
| 1292 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1293 | |
| 1294 | /* return response */ |
| 1295 | appctx->ctx.cli.msg = "Done.\n"; |
| 1296 | appctx->st0 = STAT_CLI_PRINT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1297 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1298 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1299 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1300 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1301 | return 0; |
| 1302 | } |
| 1303 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1304 | else if (strcmp(args[0], "get") == 0) { |
| 1305 | if (strcmp(args[1], "weight") == 0) { |
| 1306 | struct proxy *px; |
| 1307 | struct server *sv; |
| 1308 | |
| 1309 | /* split "backend/server" and make <line> point to server */ |
| 1310 | for (line = args[2]; *line; line++) |
| 1311 | if (*line == '/') { |
| 1312 | *line++ = '\0'; |
| 1313 | break; |
| 1314 | } |
| 1315 | |
| 1316 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1317 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1318 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1319 | return 1; |
| 1320 | } |
| 1321 | |
| 1322 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1323 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1324 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1325 | return 1; |
| 1326 | } |
| 1327 | |
| 1328 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1329 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1330 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1331 | return 1; |
| 1332 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1333 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1334 | /* Set flags. */ |
| 1335 | if (args[1][0] == 'm') |
| 1336 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1337 | else |
| 1338 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1339 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1340 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1341 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1342 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1343 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1344 | else |
| 1345 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1346 | appctx->st0 = STAT_CLI_PRINT; |
| 1347 | return 1; |
| 1348 | } |
| 1349 | |
| 1350 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1351 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1352 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1353 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1354 | 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] | 1355 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1356 | 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] | 1357 | appctx->st0 = STAT_CLI_PRINT; |
| 1358 | return 1; |
| 1359 | } |
| 1360 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1361 | /* copy input string. The string must be allocated because |
| 1362 | * it may be used over multiple iterations. It's released |
| 1363 | * at the end and upon abort anyway. |
| 1364 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1365 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1366 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1367 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1368 | if (!appctx->ctx.map.chunk.str) { |
| 1369 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1370 | appctx->st0 = STAT_CLI_PRINT; |
| 1371 | return 1; |
| 1372 | } |
| 1373 | |
| 1374 | /* prepare response */ |
| 1375 | appctx->st2 = STAT_ST_INIT; |
| 1376 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1377 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1378 | else { /* not "get weight" */ |
| 1379 | return 0; |
| 1380 | } |
| 1381 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1382 | else if (strcmp(args[0], "set") == 0) { |
| 1383 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1384 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1385 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1386 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1387 | sv = expect_server_admin(s, si, args[2]); |
| 1388 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1389 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1390 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1391 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1392 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1393 | appctx->ctx.cli.msg = warning; |
| 1394 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1395 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1396 | return 1; |
| 1397 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1398 | else if (strcmp(args[1], "server") == 0) { |
| 1399 | struct server *sv; |
| 1400 | const char *warning; |
| 1401 | |
| 1402 | sv = expect_server_admin(s, si, args[2]); |
| 1403 | if (!sv) |
| 1404 | return 1; |
| 1405 | |
| 1406 | if (strcmp(args[3], "weight") == 0) { |
| 1407 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1408 | if (warning) { |
| 1409 | appctx->ctx.cli.msg = warning; |
| 1410 | appctx->st0 = STAT_CLI_PRINT; |
| 1411 | } |
| 1412 | } |
| 1413 | else if (strcmp(args[3], "state") == 0) { |
| 1414 | if (strcmp(args[4], "ready") == 0) |
| 1415 | srv_adm_set_ready(sv); |
| 1416 | else if (strcmp(args[4], "drain") == 0) |
| 1417 | srv_adm_set_drain(sv); |
| 1418 | else if (strcmp(args[4], "maint") == 0) |
| 1419 | srv_adm_set_maint(sv); |
| 1420 | else { |
| 1421 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1422 | appctx->st0 = STAT_CLI_PRINT; |
| 1423 | } |
| 1424 | } |
| 1425 | else if (strcmp(args[3], "health") == 0) { |
| 1426 | if (sv->track) { |
| 1427 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1428 | appctx->st0 = STAT_CLI_PRINT; |
| 1429 | } |
| 1430 | else if (strcmp(args[4], "up") == 0) { |
| 1431 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1432 | srv_set_running(sv, "changed from CLI"); |
| 1433 | } |
| 1434 | else if (strcmp(args[4], "stopping") == 0) { |
| 1435 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1436 | srv_set_stopping(sv, "changed from CLI"); |
| 1437 | } |
| 1438 | else if (strcmp(args[4], "down") == 0) { |
| 1439 | sv->check.health = 0; |
| 1440 | srv_set_stopped(sv, "changed from CLI"); |
| 1441 | } |
| 1442 | else { |
| 1443 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1444 | appctx->st0 = STAT_CLI_PRINT; |
| 1445 | } |
| 1446 | } |
| 1447 | else if (strcmp(args[3], "agent") == 0) { |
| 1448 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1449 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1450 | appctx->st0 = STAT_CLI_PRINT; |
| 1451 | } |
| 1452 | else if (strcmp(args[4], "up") == 0) { |
| 1453 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1454 | srv_set_running(sv, "changed from CLI"); |
| 1455 | } |
| 1456 | else if (strcmp(args[4], "down") == 0) { |
| 1457 | sv->agent.health = 0; |
| 1458 | srv_set_stopped(sv, "changed from CLI"); |
| 1459 | } |
| 1460 | else { |
| 1461 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1462 | appctx->st0 = STAT_CLI_PRINT; |
| 1463 | } |
| 1464 | } |
| 1465 | else { |
| 1466 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state' and 'weight'.\n"; |
| 1467 | appctx->st0 = STAT_CLI_PRINT; |
| 1468 | } |
| 1469 | return 1; |
| 1470 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1471 | else if (strcmp(args[1], "timeout") == 0) { |
| 1472 | if (strcmp(args[2], "cli") == 0) { |
| 1473 | unsigned timeout; |
| 1474 | const char *res; |
| 1475 | |
| 1476 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1477 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1478 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1479 | return 1; |
| 1480 | } |
| 1481 | |
| 1482 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1483 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1484 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1485 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1486 | return 1; |
| 1487 | } |
| 1488 | |
| 1489 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1490 | return 1; |
| 1491 | } |
| 1492 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1493 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1494 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1495 | return 1; |
| 1496 | } |
| 1497 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1498 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1499 | if (strcmp(args[2], "frontend") == 0) { |
| 1500 | struct proxy *px; |
| 1501 | struct listener *l; |
| 1502 | int v; |
| 1503 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1504 | px = expect_frontend_admin(s, si, args[3]); |
| 1505 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1506 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1507 | |
| 1508 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1509 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1510 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1511 | return 1; |
| 1512 | } |
| 1513 | |
| 1514 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1515 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1516 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1517 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1518 | return 1; |
| 1519 | } |
| 1520 | |
| 1521 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1522 | * its listeners. The blocked ones will be dequeued. |
| 1523 | */ |
| 1524 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1525 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1526 | l->maxconn = v; |
| 1527 | if (l->state == LI_FULL) |
| 1528 | resume_listener(l); |
| 1529 | } |
| 1530 | |
| 1531 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1532 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1533 | |
| 1534 | return 1; |
| 1535 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1536 | else if (strcmp(args[2], "global") == 0) { |
| 1537 | int v; |
| 1538 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1539 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1540 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1541 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1542 | return 1; |
| 1543 | } |
| 1544 | |
| 1545 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1546 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1547 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1548 | return 1; |
| 1549 | } |
| 1550 | |
| 1551 | v = atoi(args[3]); |
| 1552 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1553 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1554 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1555 | return 1; |
| 1556 | } |
| 1557 | |
| 1558 | /* check for unlimited values */ |
| 1559 | if (v <= 0) |
| 1560 | v = global.hardmaxconn; |
| 1561 | |
| 1562 | global.maxconn = v; |
| 1563 | |
| 1564 | /* Dequeues all of the listeners waiting for a resource */ |
| 1565 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1566 | dequeue_all_listeners(&global_listener_queue); |
| 1567 | |
| 1568 | return 1; |
| 1569 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1570 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1571 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1572 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1573 | return 1; |
| 1574 | } |
| 1575 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1576 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1577 | if (strcmp(args[2], "connections") == 0) { |
| 1578 | if (strcmp(args[3], "global") == 0) { |
| 1579 | int v; |
| 1580 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1581 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1582 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1583 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1584 | return 1; |
| 1585 | } |
| 1586 | |
| 1587 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1588 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1589 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1590 | return 1; |
| 1591 | } |
| 1592 | |
| 1593 | v = atoi(args[4]); |
| 1594 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1595 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1596 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1597 | return 1; |
| 1598 | } |
| 1599 | |
| 1600 | global.cps_lim = v; |
| 1601 | |
| 1602 | /* Dequeues all of the listeners waiting for a resource */ |
| 1603 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1604 | dequeue_all_listeners(&global_listener_queue); |
| 1605 | |
| 1606 | return 1; |
| 1607 | } |
| 1608 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1609 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1610 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1611 | return 1; |
| 1612 | } |
| 1613 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1614 | else if (strcmp(args[2], "sessions") == 0) { |
| 1615 | if (strcmp(args[3], "global") == 0) { |
| 1616 | int v; |
| 1617 | |
| 1618 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1619 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1620 | appctx->st0 = STAT_CLI_PRINT; |
| 1621 | return 1; |
| 1622 | } |
| 1623 | |
| 1624 | if (!*args[4]) { |
| 1625 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1626 | appctx->st0 = STAT_CLI_PRINT; |
| 1627 | return 1; |
| 1628 | } |
| 1629 | |
| 1630 | v = atoi(args[4]); |
| 1631 | if (v < 0) { |
| 1632 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1633 | appctx->st0 = STAT_CLI_PRINT; |
| 1634 | return 1; |
| 1635 | } |
| 1636 | |
| 1637 | global.sps_lim = v; |
| 1638 | |
| 1639 | /* Dequeues all of the listeners waiting for a resource */ |
| 1640 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1641 | dequeue_all_listeners(&global_listener_queue); |
| 1642 | |
| 1643 | return 1; |
| 1644 | } |
| 1645 | else { |
| 1646 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1647 | appctx->st0 = STAT_CLI_PRINT; |
| 1648 | return 1; |
| 1649 | } |
| 1650 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1651 | #ifdef USE_OPENSSL |
| 1652 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1653 | if (strcmp(args[3], "global") == 0) { |
| 1654 | int v; |
| 1655 | |
| 1656 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1657 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1658 | appctx->st0 = STAT_CLI_PRINT; |
| 1659 | return 1; |
| 1660 | } |
| 1661 | |
| 1662 | if (!*args[4]) { |
| 1663 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1664 | appctx->st0 = STAT_CLI_PRINT; |
| 1665 | return 1; |
| 1666 | } |
| 1667 | |
| 1668 | v = atoi(args[4]); |
| 1669 | if (v < 0) { |
| 1670 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1671 | appctx->st0 = STAT_CLI_PRINT; |
| 1672 | return 1; |
| 1673 | } |
| 1674 | |
| 1675 | global.ssl_lim = v; |
| 1676 | |
| 1677 | /* Dequeues all of the listeners waiting for a resource */ |
| 1678 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1679 | dequeue_all_listeners(&global_listener_queue); |
| 1680 | |
| 1681 | return 1; |
| 1682 | } |
| 1683 | else { |
| 1684 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1685 | appctx->st0 = STAT_CLI_PRINT; |
| 1686 | return 1; |
| 1687 | } |
| 1688 | } |
| 1689 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1690 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1691 | if (strcmp(args[3], "global") == 0) { |
| 1692 | int v; |
| 1693 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1694 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1695 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1696 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1697 | return 1; |
| 1698 | } |
| 1699 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1700 | v = atoi(args[4]); |
| 1701 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1702 | } |
| 1703 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1704 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1705 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1706 | return 1; |
| 1707 | } |
| 1708 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1709 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1710 | 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] | 1711 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1712 | return 1; |
| 1713 | } |
| 1714 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1715 | else if (strcmp(args[1], "table") == 0) { |
| 1716 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1717 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1718 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1719 | char *err; |
| 1720 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1721 | /* Set flags. */ |
| 1722 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1723 | |
| 1724 | /* Expect three parameters: map name, key and new value. */ |
| 1725 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1726 | 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] | 1727 | appctx->st0 = STAT_CLI_PRINT; |
| 1728 | return 1; |
| 1729 | } |
| 1730 | |
| 1731 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1732 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1733 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1734 | 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] | 1735 | appctx->st0 = STAT_CLI_PRINT; |
| 1736 | return 1; |
| 1737 | } |
| 1738 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1739 | /* If the entry identifier start with a '#', it is considered as |
| 1740 | * pointer id |
| 1741 | */ |
| 1742 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1743 | struct pat_ref_elt *ref; |
| 1744 | long long int conv; |
| 1745 | char *error; |
| 1746 | |
| 1747 | /* Convert argument to integer value. */ |
| 1748 | conv = strtoll(&args[3][1], &error, 16); |
| 1749 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1750 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1751 | appctx->st0 = STAT_CLI_PRINT; |
| 1752 | return 1; |
| 1753 | } |
| 1754 | |
| 1755 | /* Convert and check integer to pointer. */ |
| 1756 | ref = (struct pat_ref_elt *)(long)conv; |
| 1757 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1758 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1759 | appctx->st0 = STAT_CLI_PRINT; |
| 1760 | return 1; |
| 1761 | } |
| 1762 | |
| 1763 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1764 | err = NULL; |
| 1765 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1766 | if (err) |
| 1767 | memprintf(&err, "%s.\n", err); |
| 1768 | appctx->ctx.cli.err = err; |
| 1769 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1770 | return 1; |
| 1771 | } |
| 1772 | } |
| 1773 | else { |
| 1774 | /* Else, use the entry identifier as pattern |
| 1775 | * string, and update the value. |
| 1776 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1777 | err = NULL; |
| 1778 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1779 | if (err) |
| 1780 | memprintf(&err, "%s.\n", err); |
| 1781 | appctx->ctx.cli.err = err; |
| 1782 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1783 | return 1; |
| 1784 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1785 | } |
| 1786 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1787 | /* The set is done, send message. */ |
| 1788 | appctx->ctx.cli.msg = "Done.\n"; |
| 1789 | appctx->st0 = STAT_CLI_PRINT; |
| 1790 | return 1; |
| 1791 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1792 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1793 | return 0; |
| 1794 | } |
| 1795 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1796 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1797 | if (strcmp(args[1], "agent") == 0) { |
| 1798 | struct server *sv; |
| 1799 | |
| 1800 | sv = expect_server_admin(s, si, args[2]); |
| 1801 | if (!sv) |
| 1802 | return 1; |
| 1803 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1804 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1805 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1806 | appctx->st0 = STAT_CLI_PRINT; |
| 1807 | return 1; |
| 1808 | } |
| 1809 | |
| 1810 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1811 | return 1; |
| 1812 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1813 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1814 | struct server *sv; |
| 1815 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1816 | sv = expect_server_admin(s, si, args[2]); |
| 1817 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1818 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1819 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1820 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 1821 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 1822 | appctx->st0 = STAT_CLI_PRINT; |
| 1823 | return 1; |
| 1824 | } |
| 1825 | |
| 1826 | sv->check.state |= CHK_ST_ENABLED; |
| 1827 | return 1; |
| 1828 | } |
| 1829 | else if (strcmp(args[1], "server") == 0) { |
| 1830 | struct server *sv; |
| 1831 | |
| 1832 | sv = expect_server_admin(s, si, args[2]); |
| 1833 | if (!sv) |
| 1834 | return 1; |
| 1835 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1836 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1837 | return 1; |
| 1838 | } |
| 1839 | else if (strcmp(args[1], "frontend") == 0) { |
| 1840 | struct proxy *px; |
| 1841 | |
| 1842 | px = expect_frontend_admin(s, si, args[2]); |
| 1843 | if (!px) |
| 1844 | return 1; |
| 1845 | |
| 1846 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1847 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1848 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1849 | return 1; |
| 1850 | } |
| 1851 | |
| 1852 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1853 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1854 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1855 | return 1; |
| 1856 | } |
| 1857 | |
| 1858 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1859 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1860 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1861 | return 1; |
| 1862 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1863 | return 1; |
| 1864 | } |
| 1865 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1866 | 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] | 1867 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1868 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1869 | } |
| 1870 | } |
| 1871 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1872 | if (strcmp(args[1], "agent") == 0) { |
| 1873 | struct server *sv; |
| 1874 | |
| 1875 | sv = expect_server_admin(s, si, args[2]); |
| 1876 | if (!sv) |
| 1877 | return 1; |
| 1878 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1879 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1880 | return 1; |
| 1881 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1882 | else if (strcmp(args[1], "health") == 0) { |
| 1883 | struct server *sv; |
| 1884 | |
| 1885 | sv = expect_server_admin(s, si, args[2]); |
| 1886 | if (!sv) |
| 1887 | return 1; |
| 1888 | |
| 1889 | sv->check.state &= ~CHK_ST_ENABLED; |
| 1890 | return 1; |
| 1891 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1892 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1893 | struct server *sv; |
| 1894 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1895 | sv = expect_server_admin(s, si, args[2]); |
| 1896 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1897 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1898 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1899 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1900 | return 1; |
| 1901 | } |
| 1902 | else if (strcmp(args[1], "frontend") == 0) { |
| 1903 | struct proxy *px; |
| 1904 | |
| 1905 | px = expect_frontend_admin(s, si, args[2]); |
| 1906 | if (!px) |
| 1907 | return 1; |
| 1908 | |
| 1909 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1910 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1911 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1912 | return 1; |
| 1913 | } |
| 1914 | |
| 1915 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1916 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1917 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1918 | return 1; |
| 1919 | } |
| 1920 | |
| 1921 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1922 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1923 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1924 | return 1; |
| 1925 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1926 | return 1; |
| 1927 | } |
| 1928 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1929 | 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] | 1930 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1931 | return 1; |
| 1932 | } |
| 1933 | } |
| 1934 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1935 | if (strcmp(args[1], "frontend") == 0) { |
| 1936 | struct proxy *px; |
| 1937 | |
| 1938 | px = expect_frontend_admin(s, si, args[2]); |
| 1939 | if (!px) |
| 1940 | return 1; |
| 1941 | |
| 1942 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1943 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1944 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1945 | return 1; |
| 1946 | } |
| 1947 | |
| 1948 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1949 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1950 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1951 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1952 | stop_proxy(px); |
| 1953 | return 1; |
| 1954 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1955 | else if (strcmp(args[1], "session") == 0) { |
| 1956 | struct session *sess, *ptr; |
| 1957 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1958 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1959 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1960 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1961 | return 1; |
| 1962 | } |
| 1963 | |
| 1964 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1965 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1966 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1967 | return 1; |
| 1968 | } |
| 1969 | |
| 1970 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1971 | |
| 1972 | /* first, look for the requested session in the session table */ |
| 1973 | list_for_each_entry(sess, &sessions, list) { |
| 1974 | if (sess == ptr) |
| 1975 | break; |
| 1976 | } |
| 1977 | |
| 1978 | /* do we have the session ? */ |
| 1979 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1980 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1981 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1982 | return 1; |
| 1983 | } |
| 1984 | |
| 1985 | session_shutdown(sess, SN_ERR_KILLED); |
| 1986 | return 1; |
| 1987 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1988 | else if (strcmp(args[1], "sessions") == 0) { |
| 1989 | if (strcmp(args[2], "server") == 0) { |
| 1990 | struct server *sv; |
| 1991 | struct session *sess, *sess_bck; |
| 1992 | |
| 1993 | sv = expect_server_admin(s, si, args[3]); |
| 1994 | if (!sv) |
| 1995 | return 1; |
| 1996 | |
| 1997 | /* kill all the session that are on this server */ |
| 1998 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1999 | if (sess->srv_conn == sv) |
| 2000 | session_shutdown(sess, SN_ERR_KILLED); |
| 2001 | |
| 2002 | return 1; |
| 2003 | } |
| 2004 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2005 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2006 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2007 | return 1; |
| 2008 | } |
| 2009 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2010 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2011 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2012 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2013 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2014 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2015 | } |
| 2016 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2017 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2018 | if (args[1][0] == 'm') |
| 2019 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2020 | else |
| 2021 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2022 | |
| 2023 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2024 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2025 | if (!*args[2] || !*args[3]) { |
| 2026 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2027 | appctx->st0 = STAT_CLI_PRINT; |
| 2028 | return 1; |
| 2029 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2030 | } |
| 2031 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2032 | else { |
| 2033 | if (!*args[2] || !*args[3]) { |
| 2034 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2035 | appctx->st0 = STAT_CLI_PRINT; |
| 2036 | return 1; |
| 2037 | } |
| 2038 | } |
| 2039 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2040 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2041 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2042 | if (!appctx->ctx.map.ref || |
| 2043 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2044 | 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] | 2045 | appctx->st0 = STAT_CLI_PRINT; |
| 2046 | return 1; |
| 2047 | } |
| 2048 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2049 | /* If the entry identifier start with a '#', it is considered as |
| 2050 | * pointer id |
| 2051 | */ |
| 2052 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2053 | struct pat_ref_elt *ref; |
| 2054 | long long int conv; |
| 2055 | char *error; |
| 2056 | |
| 2057 | /* Convert argument to integer value. */ |
| 2058 | conv = strtoll(&args[3][1], &error, 16); |
| 2059 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2060 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2061 | appctx->st0 = STAT_CLI_PRINT; |
| 2062 | return 1; |
| 2063 | } |
| 2064 | |
| 2065 | /* Convert and check integer to pointer. */ |
| 2066 | ref = (struct pat_ref_elt *)(long)conv; |
| 2067 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2068 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2069 | appctx->st0 = STAT_CLI_PRINT; |
| 2070 | return 1; |
| 2071 | } |
| 2072 | |
| 2073 | /* Try to delete the entry. */ |
| 2074 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2075 | /* The entry is not found, send message. */ |
| 2076 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2077 | appctx->st0 = STAT_CLI_PRINT; |
| 2078 | return 1; |
| 2079 | } |
| 2080 | } |
| 2081 | else { |
| 2082 | /* Else, use the entry identifier as pattern |
| 2083 | * string and try to delete the entry. |
| 2084 | */ |
| 2085 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2086 | /* The entry is not found, send message. */ |
| 2087 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2088 | appctx->st0 = STAT_CLI_PRINT; |
| 2089 | return 1; |
| 2090 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2091 | } |
| 2092 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2093 | /* The deletion is done, send message. */ |
| 2094 | appctx->ctx.cli.msg = "Done.\n"; |
| 2095 | appctx->st0 = STAT_CLI_PRINT; |
| 2096 | return 1; |
| 2097 | } |
| 2098 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2099 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2100 | appctx->st0 = STAT_CLI_PRINT; |
| 2101 | return 1; |
| 2102 | } |
| 2103 | } |
| 2104 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2105 | if (strcmp(args[1], "map") == 0 || |
| 2106 | strcmp(args[1], "acl") == 0) { |
| 2107 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2108 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2109 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2110 | /* Set flags. */ |
| 2111 | if (args[1][0] == 'm') |
| 2112 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2113 | else |
| 2114 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2115 | |
| 2116 | /* If the keywork is "map", we expect three parameters, if it |
| 2117 | * is "acl", we expect only two parameters |
| 2118 | */ |
| 2119 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2120 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2121 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2122 | appctx->st0 = STAT_CLI_PRINT; |
| 2123 | return 1; |
| 2124 | } |
| 2125 | } |
| 2126 | else { |
| 2127 | if (!*args[2] || !*args[3]) { |
| 2128 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2129 | appctx->st0 = STAT_CLI_PRINT; |
| 2130 | return 1; |
| 2131 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2132 | } |
| 2133 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2134 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2135 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2136 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2137 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2138 | 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] | 2139 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2140 | 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] | 2141 | appctx->st0 = STAT_CLI_PRINT; |
| 2142 | return 1; |
| 2143 | } |
| 2144 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2145 | /* The command "add acl" is prohibited if the reference |
| 2146 | * use samples. |
| 2147 | */ |
| 2148 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2149 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2150 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2151 | "You must use the command 'add map' to add values.\n"; |
| 2152 | appctx->st0 = STAT_CLI_PRINT; |
| 2153 | return 1; |
| 2154 | } |
| 2155 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2156 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2157 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2158 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2159 | 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] | 2160 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2161 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2162 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2163 | if (err) |
| 2164 | memprintf(&err, "%s.\n", err); |
| 2165 | appctx->ctx.cli.err = err; |
| 2166 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2167 | return 1; |
| 2168 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2169 | |
| 2170 | /* The add is done, send message. */ |
| 2171 | appctx->ctx.cli.msg = "Done.\n"; |
| 2172 | appctx->st0 = STAT_CLI_PRINT; |
| 2173 | return 1; |
| 2174 | } |
| 2175 | else { /* unknown "del" parameter */ |
| 2176 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2177 | appctx->st0 = STAT_CLI_PRINT; |
| 2178 | return 1; |
| 2179 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2180 | } |
| 2181 | 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] | 2182 | return 0; |
| 2183 | } |
| 2184 | return 1; |
| 2185 | } |
| 2186 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2187 | /* 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] | 2188 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2189 | * state machine handling requests and various responses. We read a request, |
| 2190 | * 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] | 2191 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2192 | * 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] | 2193 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2194 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2195 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2196 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2197 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2198 | struct channel *req = si->ob; |
| 2199 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2200 | int reql; |
| 2201 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2202 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2203 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2204 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2205 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2206 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2207 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2208 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2209 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2210 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2211 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2212 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2213 | /* Let's close for real now. We just close the request |
| 2214 | * side, the conditions below will complete if needed. |
| 2215 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2216 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2217 | break; |
| 2218 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2219 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2220 | /* ensure we have some output room left in the event we |
| 2221 | * would want to return some info right after parsing. |
| 2222 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2223 | if (buffer_almost_full(si->ib->buf)) { |
| 2224 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2225 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2226 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2227 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2228 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2229 | if (reql <= 0) { /* closed or EOL not found */ |
| 2230 | if (reql == 0) |
| 2231 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2232 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2233 | continue; |
| 2234 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2235 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2236 | /* seek for a possible semi-colon. If we find one, we |
| 2237 | * replace it with an LF and skip only this part. |
| 2238 | */ |
| 2239 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2240 | if (trash.str[len] == ';') { |
| 2241 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2242 | reql = len + 1; |
| 2243 | break; |
| 2244 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2245 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2246 | /* now it is time to check that we have a full line, |
| 2247 | * remove the trailing \n and possibly \r, then cut the |
| 2248 | * line. |
| 2249 | */ |
| 2250 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2251 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2252 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2253 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2254 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2255 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2256 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2257 | len--; |
| 2258 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2259 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2260 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2261 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2262 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2263 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2264 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2265 | continue; |
| 2266 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2267 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2268 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2269 | else if (strcmp(trash.str, "help") == 0 || |
| 2270 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2271 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2272 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2273 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2274 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2275 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2276 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2277 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2278 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2279 | /* if prompt is disabled, print help on empty lines, |
| 2280 | * so that the user at least knows how to enable |
| 2281 | * prompt and find help. |
| 2282 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2283 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2284 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2288 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2289 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2290 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2291 | 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] | 2292 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2293 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2294 | continue; |
| 2295 | } |
| 2296 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2297 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2298 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2299 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2300 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2301 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2302 | case STAT_CLI_PRINT_FREE: |
| 2303 | if (bi_putstr(si->ib, appctx->ctx.cli.err) != -1) { |
| 2304 | free(appctx->ctx.cli.err); |
| 2305 | appctx->st0 = STAT_CLI_PROMPT; |
| 2306 | } |
| 2307 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2308 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2309 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2310 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2311 | break; |
| 2312 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2313 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2314 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2315 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2316 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2317 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2318 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2319 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2320 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2321 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2322 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2323 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2324 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2325 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2326 | if (stats_table_request(si, appctx->st0)) |
| 2327 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2328 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2329 | case STAT_CLI_O_PATS: |
| 2330 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2331 | appctx->st0 = STAT_CLI_PROMPT; |
| 2332 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2333 | case STAT_CLI_O_PAT: |
| 2334 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2335 | appctx->st0 = STAT_CLI_PROMPT; |
| 2336 | break; |
| 2337 | case STAT_CLI_O_MLOOK: |
| 2338 | if (stats_map_lookup(si)) |
| 2339 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2340 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2341 | case STAT_CLI_O_POOLS: |
| 2342 | if (stats_dump_pools_to_buffer(si)) |
| 2343 | appctx->st0 = STAT_CLI_PROMPT; |
| 2344 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2345 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2346 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2347 | break; |
| 2348 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2349 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2350 | /* 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] | 2351 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2352 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2353 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2354 | } |
| 2355 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2356 | /* 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] | 2357 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2358 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2359 | |
| 2360 | /* Now we close the output if one of the writers did so, |
| 2361 | * or if we're not in interactive mode and the request |
| 2362 | * buffer is empty. This still allows pipelined requests |
| 2363 | * to be sent in non-interactive mode. |
| 2364 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2365 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2366 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2367 | continue; |
| 2368 | } |
| 2369 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2370 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2371 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2372 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2373 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2374 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2375 | 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] | 2376 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2377 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2378 | /* 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] | 2379 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2380 | * we forward the close to the request side so that it flows upstream to |
| 2381 | * the client. |
| 2382 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2383 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2384 | } |
| 2385 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2386 | 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] | 2387 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2388 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2389 | /* We have no more processing to do, and nothing more to send, and |
| 2390 | * the client side has closed. So we'll forward this state downstream |
| 2391 | * on the response buffer. |
| 2392 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2393 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2394 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2398 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2399 | |
| 2400 | /* we don't want to expire timeouts while we're processing requests */ |
| 2401 | si->ib->rex = TICK_ETERNITY; |
| 2402 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2403 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2404 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2405 | 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] | 2406 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2407 | 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] | 2408 | |
| 2409 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2410 | /* check that we have released everything then unregister */ |
| 2411 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2412 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2413 | } |
| 2414 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2415 | /* This function dumps information onto the stream interface's read buffer. |
| 2416 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2417 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2418 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2419 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2420 | { |
| 2421 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2422 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame^] | 2423 | #ifdef USE_OPENSSL |
| 2424 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2425 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2426 | int ssl_reuse = 0; |
| 2427 | |
| 2428 | if (ssl_key_rate < ssl_sess_rate) { |
| 2429 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2430 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2431 | } |
| 2432 | #endif |
| 2433 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2434 | chunk_printf(&trash, |
| 2435 | "Name: " PRODUCT_NAME "\n" |
| 2436 | "Version: " HAPROXY_VERSION "\n" |
| 2437 | "Release_date: " HAPROXY_DATE "\n" |
| 2438 | "Nbproc: %d\n" |
| 2439 | "Process_num: %d\n" |
| 2440 | "Pid: %d\n" |
| 2441 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2442 | "Uptime_sec: %d\n" |
| 2443 | "Memmax_MB: %d\n" |
| 2444 | "Ulimit-n: %d\n" |
| 2445 | "Maxsock: %d\n" |
| 2446 | "Maxconn: %d\n" |
| 2447 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2448 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2449 | "CumConns: %d\n" |
| 2450 | "CumReq: %d\n" |
| 2451 | #ifdef USE_OPENSSL |
| 2452 | "MaxSslConns: %d\n" |
| 2453 | "CurrSslConns: %d\n" |
| 2454 | "CumSslConns: %d\n" |
| 2455 | #endif |
| 2456 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2457 | "PipesUsed: %d\n" |
| 2458 | "PipesFree: %d\n" |
| 2459 | "ConnRate: %d\n" |
| 2460 | "ConnRateLimit: %d\n" |
| 2461 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2462 | "SessRate: %d\n" |
| 2463 | "SessRateLimit: %d\n" |
| 2464 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2465 | #ifdef USE_OPENSSL |
| 2466 | "SslRate: %d\n" |
| 2467 | "SslRateLimit: %d\n" |
| 2468 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame^] | 2469 | "SslFrontendKeyRate: %d\n" |
| 2470 | "SslFrontendMaxKeyRate: %d\n" |
| 2471 | "SslFrontendSessionReuse_pct: %d\n" |
| 2472 | "SslBackendKeyRate: %d\n" |
| 2473 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2474 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2475 | "CompressBpsIn: %u\n" |
| 2476 | "CompressBpsOut: %u\n" |
| 2477 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2478 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2479 | "ZlibMemUsage: %ld\n" |
| 2480 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2481 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2482 | "Tasks: %d\n" |
| 2483 | "Run_queue: %d\n" |
| 2484 | "Idle_pct: %d\n" |
| 2485 | "node: %s\n" |
| 2486 | "description: %s\n" |
| 2487 | "", |
| 2488 | global.nbproc, |
| 2489 | relative_pid, |
| 2490 | pid, |
| 2491 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2492 | up, |
| 2493 | global.rlimit_memmax, |
| 2494 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2495 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2496 | actconn, totalconn, global.req_count, |
| 2497 | #ifdef USE_OPENSSL |
| 2498 | global.maxsslconn, sslconns, totalsslconns, |
| 2499 | #endif |
| 2500 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2501 | 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] | 2502 | 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] | 2503 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame^] | 2504 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2505 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2506 | ssl_reuse, |
| 2507 | read_freq_ctr(&global.ssl_be_keys_per_sec), global.ssl_be_keys_max, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2508 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2509 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2510 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2511 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2512 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2513 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2514 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2515 | global.node, global.desc ? global.desc : "" |
| 2516 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2517 | |
| 2518 | if (bi_putchk(si->ib, &trash) == -1) |
| 2519 | return 0; |
| 2520 | |
| 2521 | return 1; |
| 2522 | } |
| 2523 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2524 | /* This function dumps memory usage information onto the stream interface's |
| 2525 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2526 | * completion. No state is used. |
| 2527 | */ |
| 2528 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2529 | { |
| 2530 | dump_pools_to_trash(); |
| 2531 | if (bi_putchk(si->ib, &trash) == -1) |
| 2532 | return 0; |
| 2533 | return 1; |
| 2534 | } |
| 2535 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2536 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2537 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2538 | * 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] | 2539 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2540 | 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] | 2541 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2542 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2543 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2544 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2545 | if (!(px->cap & PR_CAP_FE)) |
| 2546 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2547 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2548 | 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] | 2549 | return 0; |
| 2550 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2551 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2552 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2553 | /* name, queue */ |
| 2554 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2555 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2556 | 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] | 2557 | /* Column sub-heading for Enable or Disable server */ |
| 2558 | chunk_appendf(&trash, "<td></td>"); |
| 2559 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2560 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2561 | chunk_appendf(&trash, |
| 2562 | "<td class=ac>" |
| 2563 | "<a name=\"%s/Frontend\"></a>" |
| 2564 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2565 | "<td colspan=3></td>" |
| 2566 | "", |
| 2567 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2568 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2569 | chunk_appendf(&trash, |
| 2570 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2571 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2572 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2573 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2574 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2575 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2576 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2577 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2578 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2579 | if (px->mode == PR_MODE_HTTP) |
| 2580 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2581 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2582 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2583 | |
| 2584 | chunk_appendf(&trash, |
| 2585 | "</table></div></u></td>" |
| 2586 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2587 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2588 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2589 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2590 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2591 | U2H(px->fe_counters.sps_max), |
| 2592 | U2H(px->fe_counters.cps_max), |
| 2593 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2594 | |
| 2595 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2596 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2597 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2598 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2599 | |
| 2600 | chunk_appendf(&trash, |
| 2601 | "</table></div></u></td>" |
| 2602 | /* sessions rate : limit */ |
| 2603 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2604 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2605 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2606 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2607 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2608 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2609 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2610 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2611 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2612 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2613 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2614 | U2H(px->fe_counters.cum_sess), |
| 2615 | U2H(px->fe_counters.cum_conn), |
| 2616 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2617 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2618 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2619 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2620 | chunk_appendf(&trash, |
| 2621 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2622 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2623 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2624 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2625 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2626 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2627 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2628 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2629 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2630 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2631 | U2H(px->fe_counters.p.http.cum_req), |
| 2632 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2633 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2634 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2635 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2636 | (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] | 2637 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2638 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2639 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2640 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2641 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2642 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2643 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2644 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2645 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2646 | /* sessions: lbtot, lastsess */ |
| 2647 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2648 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2649 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2650 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2651 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2652 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2653 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2654 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2655 | "<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] | 2656 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2657 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2658 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2659 | px->fe_counters.comp_in ? |
| 2660 | (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] | 2661 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2662 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2663 | chunk_appendf(&trash, |
| 2664 | /* denied: req, resp */ |
| 2665 | "<td>%s</td><td>%s</td>" |
| 2666 | /* errors : request, connect, response */ |
| 2667 | "<td>%s</td><td></td><td></td>" |
| 2668 | /* warnings: retries, redispatches */ |
| 2669 | "<td></td><td></td>" |
| 2670 | /* server status : reflect frontend status */ |
| 2671 | "<td class=ac>%s</td>" |
| 2672 | /* rest of server: nothing */ |
| 2673 | "<td class=ac colspan=8></td></tr>" |
| 2674 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2675 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2676 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2677 | px->state == PR_STREADY ? "OPEN" : |
| 2678 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2679 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2680 | else { /* CSV mode */ |
| 2681 | chunk_appendf(&trash, |
| 2682 | /* pxid, name, queue cur, queue max, */ |
| 2683 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2684 | /* sessions : current, max, limit, total */ |
| 2685 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2686 | /* bytes : in, out */ |
| 2687 | "%lld,%lld," |
| 2688 | /* denied: req, resp */ |
| 2689 | "%lld,%lld," |
| 2690 | /* errors : request, connect, response */ |
| 2691 | "%lld,,," |
| 2692 | /* warnings: retries, redispatches */ |
| 2693 | ",," |
| 2694 | /* server status : reflect frontend status */ |
| 2695 | "%s," |
| 2696 | /* rest of server: nothing */ |
| 2697 | ",,,,,,,," |
| 2698 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2699 | "%d,%d,0,,,,%d," |
| 2700 | /* rate, rate_lim, rate_max */ |
| 2701 | "%u,%u,%u," |
| 2702 | /* check_status, check_code, check_duration */ |
| 2703 | ",,,", |
| 2704 | px->id, |
| 2705 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2706 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2707 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2708 | px->fe_counters.failed_req, |
| 2709 | px->state == PR_STREADY ? "OPEN" : |
| 2710 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2711 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2712 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2713 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2714 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2715 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2716 | if (px->mode == PR_MODE_HTTP) { |
| 2717 | for (i=1; i<6; i++) |
| 2718 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2719 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2720 | } |
| 2721 | else |
| 2722 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2723 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2724 | /* failed health analyses */ |
| 2725 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2726 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2727 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2728 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2729 | read_freq_ctr(&px->fe_req_per_sec), |
| 2730 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2731 | |
| 2732 | /* errors: cli_aborts, srv_aborts */ |
| 2733 | chunk_appendf(&trash, ",,"); |
| 2734 | |
| 2735 | /* compression: in, out, bypassed */ |
| 2736 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2737 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2738 | |
| 2739 | /* compression: comp_rsp */ |
| 2740 | chunk_appendf(&trash, "%lld,", |
| 2741 | px->fe_counters.p.http.comp_rsp); |
| 2742 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2743 | /* lastsess */ |
| 2744 | chunk_appendf(&trash, ","); |
| 2745 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2746 | /* finish with EOL */ |
| 2747 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2748 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2749 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2750 | } |
| 2751 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2752 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2753 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2754 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2755 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2756 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2757 | 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] | 2758 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2759 | struct appctx *appctx = __objt_appctx(si->end); |
| 2760 | |
| 2761 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2762 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2763 | 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] | 2764 | /* Column sub-heading for Enable or Disable server */ |
| 2765 | chunk_appendf(&trash, "<td></td>"); |
| 2766 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2767 | chunk_appendf(&trash, |
| 2768 | /* frontend name, listener name */ |
| 2769 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2770 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2771 | "", |
| 2772 | px->id, l->name, |
| 2773 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2774 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2775 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2776 | if (flags & ST_SHLGNDS) { |
| 2777 | char str[INET6_ADDRSTRLEN]; |
| 2778 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2779 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2780 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2781 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2782 | port = get_host_port(&l->addr); |
| 2783 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2784 | case AF_INET: |
| 2785 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2786 | break; |
| 2787 | case AF_INET6: |
| 2788 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2789 | break; |
| 2790 | case AF_UNIX: |
| 2791 | chunk_appendf(&trash, "unix, "); |
| 2792 | break; |
| 2793 | case -1: |
| 2794 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2795 | break; |
| 2796 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2797 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2798 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2799 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2800 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2801 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2802 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2803 | /* queue */ |
| 2804 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2805 | /* sessions rate: current, max, limit */ |
| 2806 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2807 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2808 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2809 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2810 | /* bytes: in, out */ |
| 2811 | "<td>%s</td><td>%s</td>" |
| 2812 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2813 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2814 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2815 | 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] | 2816 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2817 | chunk_appendf(&trash, |
| 2818 | /* denied: req, resp */ |
| 2819 | "<td>%s</td><td>%s</td>" |
| 2820 | /* errors: request, connect, response */ |
| 2821 | "<td>%s</td><td></td><td></td>" |
| 2822 | /* warnings: retries, redispatches */ |
| 2823 | "<td></td><td></td>" |
| 2824 | /* server status: reflect listener status */ |
| 2825 | "<td class=ac>%s</td>" |
| 2826 | /* rest of server: nothing */ |
| 2827 | "<td class=ac colspan=8></td></tr>" |
| 2828 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2829 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2830 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2831 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2832 | } |
| 2833 | else { /* CSV mode */ |
| 2834 | chunk_appendf(&trash, |
| 2835 | /* pxid, name, queue cur, queue max, */ |
| 2836 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2837 | /* sessions: current, max, limit, total */ |
| 2838 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2839 | /* bytes: in, out */ |
| 2840 | "%lld,%lld," |
| 2841 | /* denied: req, resp */ |
| 2842 | "%lld,%lld," |
| 2843 | /* errors: request, connect, response */ |
| 2844 | "%lld,,," |
| 2845 | /* warnings: retries, redispatches */ |
| 2846 | ",," |
| 2847 | /* server status: reflect listener status */ |
| 2848 | "%s," |
| 2849 | /* rest of server: nothing */ |
| 2850 | ",,,,,,,," |
| 2851 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2852 | "%d,%d,%d,,,,%d," |
| 2853 | /* rate, rate_lim, rate_max */ |
| 2854 | ",,," |
| 2855 | /* check_status, check_code, check_duration */ |
| 2856 | ",,," |
| 2857 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2858 | ",,,,,," |
| 2859 | /* failed health analyses */ |
| 2860 | "," |
| 2861 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2862 | ",,," |
| 2863 | /* errors: cli_aborts, srv_aborts */ |
| 2864 | ",," |
| 2865 | /* compression: in, out, bypassed, comp_rsp */ |
| 2866 | ",,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2867 | /* lastsess */ |
| 2868 | "," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2869 | "\n", |
| 2870 | px->id, l->name, |
| 2871 | l->nbconn, l->counters->conn_max, |
| 2872 | l->maxconn, l->counters->cum_conn, |
| 2873 | l->counters->bytes_in, l->counters->bytes_out, |
| 2874 | l->counters->denied_req, l->counters->denied_resp, |
| 2875 | l->counters->failed_req, |
| 2876 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2877 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2878 | } |
| 2879 | return 1; |
| 2880 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2881 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2882 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2883 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2884 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2885 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2886 | * following values : 0=DOWN, 1=DOWN(agent) 2=going up, 3=going down, 4=UP, 5,6=NOLB, |
| 2887 | * 7,8=DRAIN, 9=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2888 | */ |
| 2889 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2890 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2891 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2892 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2893 | char str[INET6_ADDRSTRLEN]; |
| 2894 | struct chunk src; |
| 2895 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2896 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2897 | /* we have "via" which is the tracked server as described in the configuration, |
| 2898 | * and "ref" which is the checked server and the end of the chain. |
| 2899 | */ |
| 2900 | via = sv->track ? sv->track : sv; |
| 2901 | ref = via; |
| 2902 | while (ref->track) |
| 2903 | ref = ref->track; |
| 2904 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2905 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2906 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2907 | "DOWN", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2908 | "DOWN (agent)", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2909 | "DN %d/%d ↑", |
| 2910 | "UP %d/%d ↓", |
| 2911 | "UP", |
| 2912 | "NOLB %d/%d ↓", |
| 2913 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2914 | "DRAIN %d/%d ↓", |
| 2915 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2916 | "<i>no check</i>" |
| 2917 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2918 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 2919 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2920 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2921 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2922 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2923 | "<tr class=\"%s%d\">", |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 2924 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2925 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2926 | 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] | 2927 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2928 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2929 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2930 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2931 | chunk_appendf(&trash, |
| 2932 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2933 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2934 | "", |
| 2935 | px->id, sv->id, |
| 2936 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2937 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2938 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2939 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2940 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2941 | |
| 2942 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2943 | case AF_INET: |
| 2944 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2945 | break; |
| 2946 | case AF_INET6: |
| 2947 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2948 | break; |
| 2949 | case AF_UNIX: |
| 2950 | chunk_appendf(&trash, "unix, "); |
| 2951 | break; |
| 2952 | case -1: |
| 2953 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2954 | break; |
| 2955 | default: /* address family not supported */ |
| 2956 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2957 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2958 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2959 | /* id */ |
| 2960 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2961 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2962 | /* cookie */ |
| 2963 | if (sv->cookie) { |
| 2964 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2965 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2966 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2967 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2968 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2969 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2970 | } |
| 2971 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2972 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2973 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2974 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2975 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2976 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2977 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2978 | /* sessions rate : current, max, limit */ |
| 2979 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2980 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2981 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2982 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2983 | 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] | 2984 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2985 | |
| 2986 | chunk_appendf(&trash, |
| 2987 | /* sessions: current, max, limit, total */ |
| 2988 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2989 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2990 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2991 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2992 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2993 | U2H(sv->counters.cum_sess), |
| 2994 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2995 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2996 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2997 | if (px->mode == PR_MODE_HTTP) { |
| 2998 | unsigned long long tot; |
| 2999 | for (tot = i = 0; i < 6; i++) |
| 3000 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3001 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3002 | chunk_appendf(&trash, |
| 3003 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3004 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3005 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3006 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3007 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3008 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3009 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3010 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3011 | U2H(tot), |
| 3012 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3013 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3014 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3015 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3016 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3017 | 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] | 3018 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3019 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3020 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3021 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3022 | /* sessions: lbtot, last */ |
| 3023 | "<td>%s</td><td>%s</td>", |
| 3024 | U2H(sv->counters.cum_lbconn), |
| 3025 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3026 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3027 | chunk_appendf(&trash, |
| 3028 | /* bytes : in, out */ |
| 3029 | "<td>%s</td><td>%s</td>" |
| 3030 | /* denied: req, resp */ |
| 3031 | "<td></td><td>%s</td>" |
| 3032 | /* errors : request, connect */ |
| 3033 | "<td></td><td>%s</td>" |
| 3034 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3035 | "<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] | 3036 | /* warnings: retries, redispatches */ |
| 3037 | "<td>%lld</td><td>%lld</td>" |
| 3038 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3039 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3040 | U2H(sv->counters.failed_secu), |
| 3041 | U2H(sv->counters.failed_conns), |
| 3042 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3043 | sv->counters.cli_aborts, |
| 3044 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3045 | sv->counters.retries, sv->counters.redispatches); |
| 3046 | |
| 3047 | /* status, lest check */ |
| 3048 | chunk_appendf(&trash, "<td class=ac>"); |
| 3049 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3050 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3051 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3052 | chunk_appendf(&trash, "MAINT"); |
| 3053 | } |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3054 | else if ((ref->agent.state & CHK_ST_ENABLED) && (ref->state == SRV_ST_STOPPED)) { |
| 3055 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3056 | chunk_appendf(&trash, srv_hlt_st[1]); /* DOWN (agent) */ |
| 3057 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3058 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3059 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3060 | chunk_appendf(&trash, |
| 3061 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3062 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3063 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3064 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3065 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3066 | if ((sv->state == SRV_ST_STOPPED) && |
| 3067 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3068 | chunk_appendf(&trash, |
| 3069 | "</td><td class=ac><u> %s%s", |
| 3070 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3071 | get_check_status_info(sv->agent.status)); |
| 3072 | |
| 3073 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3074 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3075 | |
| 3076 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3077 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3078 | |
| 3079 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3080 | get_check_status_description(sv->agent.status)); |
| 3081 | if (*sv->agent.desc) { |
| 3082 | chunk_appendf(&trash, ": "); |
| 3083 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3084 | chunk_htmlencode(&trash, &src); |
| 3085 | } |
| 3086 | chunk_appendf(&trash, "</div></u>"); |
| 3087 | } |
| 3088 | 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] | 3089 | chunk_appendf(&trash, |
| 3090 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3091 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3092 | get_check_status_info(sv->check.status)); |
| 3093 | |
| 3094 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3095 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3096 | |
| 3097 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3098 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3099 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3100 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3101 | get_check_status_description(sv->check.status)); |
| 3102 | if (*sv->check.desc) { |
| 3103 | chunk_appendf(&trash, ": "); |
| 3104 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3105 | chunk_htmlencode(&trash, &src); |
| 3106 | } |
| 3107 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3108 | } |
| 3109 | else |
| 3110 | chunk_appendf(&trash, "</td><td>"); |
| 3111 | |
| 3112 | chunk_appendf(&trash, |
| 3113 | /* weight */ |
| 3114 | "</td><td class=ac>%d</td>" |
| 3115 | /* act, bck */ |
| 3116 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3117 | "", |
| 3118 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3119 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3120 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3121 | |
| 3122 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3123 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3124 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3125 | |
| 3126 | if (ref->observe) |
| 3127 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3128 | |
| 3129 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3130 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3131 | "<td>%lld</td><td>%s</td>" |
| 3132 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3133 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3134 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3135 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3136 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3137 | /* tracking a server */ |
| 3138 | chunk_appendf(&trash, |
| 3139 | "<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] | 3140 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3141 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3142 | else |
| 3143 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3144 | |
| 3145 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3146 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3147 | 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] | 3148 | else |
| 3149 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3150 | } |
| 3151 | else { /* CSV mode */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3152 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3153 | "DOWN,", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3154 | "DOWN (agent),", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3155 | "DOWN %d/%d,", |
| 3156 | "UP %d/%d,", |
| 3157 | "UP,", |
| 3158 | "NOLB %d/%d,", |
| 3159 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3160 | "DRAIN %d/%d,", |
| 3161 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3162 | "no check," |
| 3163 | }; |
| 3164 | |
| 3165 | chunk_appendf(&trash, |
| 3166 | /* pxid, name */ |
| 3167 | "%s,%s," |
| 3168 | /* queue : current, max */ |
| 3169 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3170 | /* sessions : current, max, limit, total */ |
| 3171 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3172 | /* bytes : in, out */ |
| 3173 | "%lld,%lld," |
| 3174 | /* denied: req, resp */ |
| 3175 | ",%lld," |
| 3176 | /* errors : request, connect, response */ |
| 3177 | ",%lld,%lld," |
| 3178 | /* warnings: retries, redispatches */ |
| 3179 | "%lld,%lld," |
| 3180 | "", |
| 3181 | px->id, sv->id, |
| 3182 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3183 | 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] | 3184 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3185 | sv->counters.failed_secu, |
| 3186 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3187 | sv->counters.retries, sv->counters.redispatches); |
| 3188 | |
| 3189 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3190 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3191 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3192 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3193 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3194 | else |
| 3195 | chunk_appendf(&trash, |
| 3196 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3197 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3198 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3199 | |
| 3200 | chunk_appendf(&trash, |
| 3201 | /* weight, active, backup */ |
| 3202 | "%d,%d,%d," |
| 3203 | "", |
| 3204 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3205 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3206 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3207 | |
| 3208 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3209 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3210 | chunk_appendf(&trash, |
| 3211 | "%lld,%lld,%d,%d,", |
| 3212 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3213 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3214 | else |
| 3215 | chunk_appendf(&trash, ",,,,"); |
| 3216 | |
| 3217 | /* queue limit, pid, iid, sid, */ |
| 3218 | chunk_appendf(&trash, |
| 3219 | "%s," |
| 3220 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3221 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3222 | relative_pid, px->uuid, sv->puid); |
| 3223 | |
| 3224 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3225 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3226 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3227 | |
| 3228 | /* sessions: lbtot */ |
| 3229 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3230 | |
| 3231 | /* tracked */ |
| 3232 | if (sv->track) |
| 3233 | chunk_appendf(&trash, "%s/%s,", |
| 3234 | sv->track->proxy->id, sv->track->id); |
| 3235 | else |
| 3236 | chunk_appendf(&trash, ","); |
| 3237 | |
| 3238 | /* type */ |
| 3239 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3240 | |
| 3241 | /* rate */ |
| 3242 | chunk_appendf(&trash, "%u,,%u,", |
| 3243 | read_freq_ctr(&sv->sess_per_sec), |
| 3244 | sv->counters.sps_max); |
| 3245 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3246 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3247 | /* check_status */ |
| 3248 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3249 | |
| 3250 | /* check_code */ |
| 3251 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3252 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3253 | else |
| 3254 | chunk_appendf(&trash, ","); |
| 3255 | |
| 3256 | /* check_duration */ |
| 3257 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3258 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3259 | else |
| 3260 | chunk_appendf(&trash, ","); |
| 3261 | |
| 3262 | } |
| 3263 | else |
| 3264 | chunk_appendf(&trash, ",,,"); |
| 3265 | |
| 3266 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3267 | if (px->mode == PR_MODE_HTTP) { |
| 3268 | for (i=1; i<6; i++) |
| 3269 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3270 | |
| 3271 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3272 | } |
| 3273 | else |
| 3274 | chunk_appendf(&trash, ",,,,,,"); |
| 3275 | |
| 3276 | /* failed health analyses */ |
| 3277 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3278 | |
| 3279 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3280 | chunk_appendf(&trash, ",,,"); |
| 3281 | |
| 3282 | /* errors: cli_aborts, srv_aborts */ |
| 3283 | chunk_appendf(&trash, "%lld,%lld,", |
| 3284 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3285 | |
| 3286 | /* compression: in, out, bypassed, comp_rsp */ |
| 3287 | chunk_appendf(&trash, ",,,,"); |
| 3288 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3289 | /* lastsess */ |
| 3290 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3291 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3292 | /* finish with EOL */ |
| 3293 | chunk_appendf(&trash, "\n"); |
| 3294 | } |
| 3295 | return 1; |
| 3296 | } |
| 3297 | |
| 3298 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3299 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3300 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3301 | */ |
| 3302 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3303 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3304 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3305 | struct chunk src; |
| 3306 | int i; |
| 3307 | |
| 3308 | if (!(px->cap & PR_CAP_BE)) |
| 3309 | return 0; |
| 3310 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3311 | 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] | 3312 | return 0; |
| 3313 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3314 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3315 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3316 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3317 | /* Column sub-heading for Enable or Disable server */ |
| 3318 | chunk_appendf(&trash, "<td></td>"); |
| 3319 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3320 | chunk_appendf(&trash, |
| 3321 | "<td class=ac>" |
| 3322 | /* name */ |
| 3323 | "%s<a name=\"%s/Backend\"></a>" |
| 3324 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3325 | "", |
| 3326 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3327 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3328 | |
| 3329 | if (flags & ST_SHLGNDS) { |
| 3330 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3331 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3332 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3333 | |
| 3334 | /* cookie */ |
| 3335 | if (px->cookie_name) { |
| 3336 | chunk_appendf(&trash, ", cookie: '"); |
| 3337 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3338 | chunk_htmlencode(&trash, &src); |
| 3339 | chunk_appendf(&trash, "'"); |
| 3340 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3341 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3345 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3346 | /* queue : current, max */ |
| 3347 | "<td>%s</td><td>%s</td><td></td>" |
| 3348 | /* sessions rate : current, max, limit */ |
| 3349 | "<td>%s</td><td>%s</td><td></td>" |
| 3350 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3351 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3352 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3353 | 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] | 3354 | |
| 3355 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3356 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3357 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3358 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3359 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3360 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3361 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3362 | U2H(px->be_counters.cum_conn), |
| 3363 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3364 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3365 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3366 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3367 | chunk_appendf(&trash, |
| 3368 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3369 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3370 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3371 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3372 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3373 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3374 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3375 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3376 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3377 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3378 | U2H(px->be_counters.p.http.cum_req), |
| 3379 | U2H(px->be_counters.p.http.rsp[1]), |
| 3380 | U2H(px->be_counters.p.http.rsp[2]), |
| 3381 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3382 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3383 | (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] | 3384 | U2H(px->be_counters.p.http.rsp[3]), |
| 3385 | U2H(px->be_counters.p.http.rsp[4]), |
| 3386 | U2H(px->be_counters.p.http.rsp[5]), |
| 3387 | U2H(px->be_counters.p.http.rsp[0]), |
| 3388 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3389 | } |
| 3390 | |
| 3391 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3392 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3393 | /* sessions: lbtot, last */ |
| 3394 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3395 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3396 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3397 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3398 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3399 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3400 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3401 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3402 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3403 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3404 | "<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] | 3405 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3406 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3407 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3408 | px->be_counters.comp_in ? |
| 3409 | (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] | 3410 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3411 | |
| 3412 | chunk_appendf(&trash, |
| 3413 | /* denied: req, resp */ |
| 3414 | "<td>%s</td><td>%s</td>" |
| 3415 | /* errors : request, connect */ |
| 3416 | "<td></td><td>%s</td>" |
| 3417 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3418 | "<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] | 3419 | /* warnings: retries, redispatches */ |
| 3420 | "<td>%lld</td><td>%lld</td>" |
| 3421 | /* backend status: reflect backend status (up/down): we display UP |
| 3422 | * if the backend has known working servers or if it has no server at |
| 3423 | * all (eg: for stats). Then we display the total weight, number of |
| 3424 | * active and backups. */ |
| 3425 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3426 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3427 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3428 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3429 | U2H(px->be_counters.failed_conns), |
| 3430 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3431 | px->be_counters.cli_aborts, |
| 3432 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3433 | px->be_counters.retries, px->be_counters.redispatches, |
| 3434 | human_time(now.tv_sec - px->last_change, 1), |
| 3435 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3436 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3437 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3438 | px->srv_act, px->srv_bck); |
| 3439 | |
| 3440 | chunk_appendf(&trash, |
| 3441 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3442 | "<td class=ac> </td><td>%d</td>" |
| 3443 | "<td>%s</td>" |
| 3444 | "<td></td>" |
| 3445 | "</tr>", |
| 3446 | px->down_trans, |
| 3447 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3448 | } |
| 3449 | else { /* CSV mode */ |
| 3450 | chunk_appendf(&trash, |
| 3451 | /* pxid, name */ |
| 3452 | "%s,BACKEND," |
| 3453 | /* queue : current, max */ |
| 3454 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3455 | /* sessions : current, max, limit, total */ |
| 3456 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3457 | /* bytes : in, out */ |
| 3458 | "%lld,%lld," |
| 3459 | /* denied: req, resp */ |
| 3460 | "%lld,%lld," |
| 3461 | /* errors : request, connect, response */ |
| 3462 | ",%lld,%lld," |
| 3463 | /* warnings: retries, redispatches */ |
| 3464 | "%lld,%lld," |
| 3465 | /* backend status: reflect backend status (up/down): we display UP |
| 3466 | * if the backend has known working servers or if it has no server at |
| 3467 | * all (eg: for stats). Then we display the total weight, number of |
| 3468 | * active and backups. */ |
| 3469 | "%s," |
| 3470 | "%d,%d,%d," |
| 3471 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3472 | ",%d,%d,%d,," |
| 3473 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3474 | "%d,%d,0,,%lld,,%d," |
| 3475 | /* rate, rate_lim, rate_max, */ |
| 3476 | "%u,,%u," |
| 3477 | /* check_status, check_code, check_duration */ |
| 3478 | ",,,", |
| 3479 | px->id, |
| 3480 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3481 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3482 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3483 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3484 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3485 | px->be_counters.retries, px->be_counters.redispatches, |
| 3486 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3487 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3488 | px->srv_act, px->srv_bck, |
| 3489 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3490 | px->srv?be_downtime(px):0, |
| 3491 | relative_pid, px->uuid, |
| 3492 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3493 | read_freq_ctr(&px->be_sess_per_sec), |
| 3494 | px->be_counters.sps_max); |
| 3495 | |
| 3496 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3497 | if (px->mode == PR_MODE_HTTP) { |
| 3498 | for (i=1; i<6; i++) |
| 3499 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3500 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3501 | } |
| 3502 | else |
| 3503 | chunk_appendf(&trash, ",,,,,,"); |
| 3504 | |
| 3505 | /* failed health analyses */ |
| 3506 | chunk_appendf(&trash, ","); |
| 3507 | |
| 3508 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3509 | chunk_appendf(&trash, ",,,"); |
| 3510 | |
| 3511 | /* errors: cli_aborts, srv_aborts */ |
| 3512 | chunk_appendf(&trash, "%lld,%lld,", |
| 3513 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3514 | |
| 3515 | /* compression: in, out, bypassed */ |
| 3516 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3517 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3518 | |
| 3519 | /* compression: comp_rsp */ |
| 3520 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3521 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3522 | /* lastsess */ |
| 3523 | chunk_appendf(&trash, "%d,", be_lastsession(px)); |
| 3524 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3525 | /* finish with EOL */ |
| 3526 | chunk_appendf(&trash, "\n"); |
| 3527 | } |
| 3528 | return 1; |
| 3529 | } |
| 3530 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3531 | /* 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] | 3532 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3533 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3534 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3535 | 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] | 3536 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3537 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3538 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3539 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3540 | 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] | 3541 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3542 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3543 | /* 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] | 3544 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3545 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3546 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3547 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3548 | 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] | 3549 | } |
| 3550 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3551 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3552 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3553 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3554 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3555 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3556 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | /* print a new table */ |
| 3560 | chunk_appendf(&trash, |
| 3561 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3562 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3563 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3564 | |
| 3565 | chunk_appendf(&trash, |
| 3566 | "<a name=\"%s\"></a>%s" |
| 3567 | "<a class=px href=\"#%s\">%s</a>", |
| 3568 | px->id, |
| 3569 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3570 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3571 | |
| 3572 | if (uri->flags & ST_SHLGNDS) { |
| 3573 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3574 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3575 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3576 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3577 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3581 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3582 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3583 | "</tr>\n" |
| 3584 | "</table>\n" |
| 3585 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3586 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3587 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3588 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3589 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3590 | 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] | 3591 | /* Column heading for Enable or Disable server */ |
| 3592 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3593 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3594 | |
| 3595 | chunk_appendf(&trash, |
| 3596 | "<th rowspan=2></th>" |
| 3597 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3598 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3599 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3600 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3601 | "<th colspan=9>Server</th>" |
| 3602 | "</tr>\n" |
| 3603 | "<tr class=\"titre\">" |
| 3604 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3605 | "<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] | 3606 | "<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] | 3607 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3608 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3609 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3610 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3611 | "<th>Thrtle</th>\n" |
| 3612 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3613 | } |
| 3614 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3615 | /* 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] | 3616 | * 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] | 3617 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3618 | 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] | 3619 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3620 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3621 | chunk_appendf(&trash, "</table>"); |
| 3622 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3623 | 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] | 3624 | /* close the form used to enable/disable this proxy servers */ |
| 3625 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3626 | "Choose the action to perform on the checked servers : " |
| 3627 | "<select name=action>" |
| 3628 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 3629 | "<option value=\"ready\">Set state to READY</option>" |
| 3630 | "<option value=\"drain\">Set state to DRAIN</option>" |
| 3631 | "<option value=\"maint\">set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 3632 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3633 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3634 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3635 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3636 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3637 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3638 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3639 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3640 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3641 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3642 | "</select>" |
| 3643 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3644 | " <input type=\"submit\" value=\"Apply\">" |
| 3645 | "</form>", |
| 3646 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3650 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3651 | |
| 3652 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3653 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3654 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3655 | * buffer space, or non-zero if everything completed. This function is used |
| 3656 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3657 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3658 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3659 | 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] | 3660 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3661 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3662 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3663 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3664 | 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] | 3665 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3666 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3667 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3668 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3669 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3670 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3671 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3672 | if (uri && uri->scope) { |
| 3673 | /* we have a limited scope, we have to check the proxy name */ |
| 3674 | struct stat_scope *scope; |
| 3675 | int len; |
| 3676 | |
| 3677 | len = strlen(px->id); |
| 3678 | scope = uri->scope; |
| 3679 | |
| 3680 | while (scope) { |
| 3681 | /* match exact proxy name */ |
| 3682 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3683 | break; |
| 3684 | |
| 3685 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3686 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3687 | break; |
| 3688 | scope = scope->next; |
| 3689 | } |
| 3690 | |
| 3691 | /* proxy name not found : don't dump anything */ |
| 3692 | if (scope == NULL) |
| 3693 | return 1; |
| 3694 | } |
| 3695 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3696 | /* if the user has requested a limited output and the proxy |
| 3697 | * name does not match, skip it. |
| 3698 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3699 | if (appctx->ctx.stats.scope_len && |
| 3700 | 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] | 3701 | return 1; |
| 3702 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3703 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3704 | (appctx->ctx.stats.iid != -1) && |
| 3705 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3706 | return 1; |
| 3707 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3708 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3709 | /* fall through */ |
| 3710 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3711 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3712 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3713 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3714 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3715 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3716 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3717 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3718 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3719 | /* fall through */ |
| 3720 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3721 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3722 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3723 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3724 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3725 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3726 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3727 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3728 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3729 | /* fall through */ |
| 3730 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3731 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3732 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3733 | 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] | 3734 | if (buffer_almost_full(rep->buf)) { |
| 3735 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3736 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3737 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3738 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3739 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3740 | if (!l->counters) |
| 3741 | continue; |
| 3742 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3743 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3744 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3745 | break; |
| 3746 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3747 | 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] | 3748 | continue; |
| 3749 | } |
| 3750 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3751 | /* print the frontend */ |
| 3752 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3753 | if (bi_putchk(rep, &trash) == -1) |
| 3754 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3755 | } |
| 3756 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3757 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3758 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3759 | /* fall through */ |
| 3760 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3761 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3762 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3763 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3764 | int sv_state; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3765 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3766 | if (buffer_almost_full(rep->buf)) { |
| 3767 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3768 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3769 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3770 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3771 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3772 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3773 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3774 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3775 | break; |
| 3776 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3777 | 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] | 3778 | continue; |
| 3779 | } |
| 3780 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3781 | svs = sv; |
| 3782 | while (svs->track) |
| 3783 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3784 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3785 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 3786 | /* server is UP. The possibilities are : |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3787 | * - UP, draining, going down => state = 7 |
| 3788 | * - UP, going down => state = 3 |
| 3789 | * - UP, draining => state = 8 |
| 3790 | * - UP, checked => state = 4 |
| 3791 | * - UP, not checked nor tracked => state = 9 |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3792 | */ |
| 3793 | |
| 3794 | if ((svs->check.state & CHK_ST_ENABLED) && |
| 3795 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3796 | sv_state = 3; |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3797 | else |
| 3798 | sv_state = 4; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3799 | |
Willy Tarreau | efe2822 | 2014-05-21 17:13:13 +0200 | [diff] [blame] | 3800 | if (server_is_draining(sv)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3801 | sv_state += 4; |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3802 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3803 | if (sv_state == 4 && !(svs->check.state & CHK_ST_ENABLED)) |
| 3804 | sv_state = 9; /* unchecked UP */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3805 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3806 | else if (sv->state == SRV_ST_STOPPING) { |
| 3807 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 3808 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3809 | sv_state = 6; /* NOLB */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3810 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3811 | sv_state = 5; /* NOLB going down */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3812 | } |
| 3813 | else { /* stopped */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3814 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) |
| 3815 | sv_state = 1; /* DOWN (agent) */ |
| 3816 | else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3817 | sv_state = 0; /* DOWN */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3818 | else if ((svs->agent.state & CHK_ST_ENABLED) || (svs->check.state & CHK_ST_ENABLED)) |
| 3819 | sv_state = 2; /* going up */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3820 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3821 | sv_state = 0; /* DOWN, unchecked */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3822 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3823 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3824 | 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] | 3825 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3826 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3827 | continue; |
| 3828 | } |
| 3829 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3830 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3831 | if (bi_putchk(rep, &trash) == -1) |
| 3832 | return 0; |
| 3833 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3834 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3835 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3836 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3837 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3838 | case STAT_PX_ST_BE: |
| 3839 | /* print the backend */ |
| 3840 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3841 | if (bi_putchk(rep, &trash) == -1) |
| 3842 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3843 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3844 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3845 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3846 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3847 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3848 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3849 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3850 | if (bi_putchk(rep, &trash) == -1) |
| 3851 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3852 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3853 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3854 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3855 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3856 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3857 | case STAT_PX_ST_FIN: |
| 3858 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3859 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3860 | default: |
| 3861 | /* unknown state, we should put an abort() here ! */ |
| 3862 | return 1; |
| 3863 | } |
| 3864 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3865 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3866 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3867 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3868 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3869 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3870 | { |
| 3871 | /* WARNING! This must fit in the first buffer !!! */ |
| 3872 | chunk_appendf(&trash, |
| 3873 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3874 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3875 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3876 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3877 | "<style type=\"text/css\"><!--\n" |
| 3878 | "body {" |
| 3879 | " font-family: arial, helvetica, sans-serif;" |
| 3880 | " font-size: 12px;" |
| 3881 | " font-weight: normal;" |
| 3882 | " color: black;" |
| 3883 | " background: white;" |
| 3884 | "}\n" |
| 3885 | "th,td {" |
| 3886 | " font-size: 10px;" |
| 3887 | "}\n" |
| 3888 | "h1 {" |
| 3889 | " font-size: x-large;" |
| 3890 | " margin-bottom: 0.5em;" |
| 3891 | "}\n" |
| 3892 | "h2 {" |
| 3893 | " font-family: helvetica, arial;" |
| 3894 | " font-size: x-large;" |
| 3895 | " font-weight: bold;" |
| 3896 | " font-style: italic;" |
| 3897 | " color: #6020a0;" |
| 3898 | " margin-top: 0em;" |
| 3899 | " margin-bottom: 0em;" |
| 3900 | "}\n" |
| 3901 | "h3 {" |
| 3902 | " font-family: helvetica, arial;" |
| 3903 | " font-size: 16px;" |
| 3904 | " font-weight: bold;" |
| 3905 | " color: #b00040;" |
| 3906 | " background: #e8e8d0;" |
| 3907 | " margin-top: 0em;" |
| 3908 | " margin-bottom: 0em;" |
| 3909 | "}\n" |
| 3910 | "li {" |
| 3911 | " margin-top: 0.25em;" |
| 3912 | " margin-right: 2em;" |
| 3913 | "}\n" |
| 3914 | ".hr {margin-top: 0.25em;" |
| 3915 | " border-color: black;" |
| 3916 | " border-bottom-style: solid;" |
| 3917 | "}\n" |
| 3918 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3919 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3920 | ".frontend {background: #e8e8d0;}\n" |
| 3921 | ".socket {background: #d0d0d0;}\n" |
| 3922 | ".backend {background: #e8e8d0;}\n" |
| 3923 | ".active0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3924 | ".active1 {background: #ff9090;}\n" |
| 3925 | ".active2 {background: #ffd020;}\n" |
| 3926 | ".active3 {background: #ffffa0;}\n" |
| 3927 | ".active4 {background: #c0ffc0;}\n" |
| 3928 | ".active5 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 3929 | ".active6 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3930 | ".active7 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3931 | ".active8 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
| 3932 | ".active9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3933 | ".backup0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3934 | ".backup1 {background: #ff9090;}\n" |
| 3935 | ".backup2 {background: #ff80ff;}\n" |
| 3936 | ".backup3 {background: #c060ff;}\n" |
| 3937 | ".backup4 {background: #b0d0ff;}\n" |
| 3938 | ".backup5 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3939 | ".backup6 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 3940 | ".backup7 {background: #c060ff;}\n" |
| 3941 | ".backup8 {background: #cc9900;}\n" |
| 3942 | ".backup9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3943 | ".maintain {background: #c07820;}\n" |
| 3944 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3945 | "\n" |
| 3946 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3947 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3948 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3949 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3950 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3951 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3952 | "\n" |
| 3953 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3954 | "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" |
| 3955 | "table.tbl td.ac { text-align: center;}\n" |
| 3956 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3957 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3958 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3959 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3960 | "\n" |
| 3961 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3962 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3963 | "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] | 3964 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3965 | "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] | 3966 | "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] | 3967 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3968 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3969 | " display:block;\n" |
| 3970 | " visibility:hidden;\n" |
| 3971 | " z-index:2147483647;\n" |
| 3972 | " position:absolute;\n" |
| 3973 | " padding:2px 4px 3px;\n" |
| 3974 | " background:#f0f060; color:#000000;\n" |
| 3975 | " border:1px solid #7040c0;\n" |
| 3976 | " white-space:nowrap;\n" |
| 3977 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3978 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3979 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3980 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3981 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3982 | "-->\n" |
| 3983 | "</style></head>\n", |
| 3984 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3985 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3986 | ); |
| 3987 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3988 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3989 | /* 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] | 3990 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3991 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3992 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3993 | 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] | 3994 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3995 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3996 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3997 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3998 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3999 | /* WARNING! this has to fit the first packet too. |
| 4000 | * We are around 3.5 kB, add adding entries will |
| 4001 | * become tricky if we want to support 4kB buffers ! |
| 4002 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4003 | chunk_appendf(&trash, |
| 4004 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4005 | PRODUCT_NAME "%s</a></h1>\n" |
| 4006 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4007 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4008 | "<h3>> General process information</h3>\n" |
| 4009 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4010 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4011 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4012 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4013 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4014 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4015 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4016 | "</td><td align=\"center\" nowrap>\n" |
| 4017 | "<table class=\"lgd\"><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4018 | "<td class=\"active4\"> </td><td class=\"noborder\">active UP </td>" |
| 4019 | "<td class=\"backup4\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4020 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4021 | "<td class=\"active3\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4022 | "<td class=\"backup3\"></td><td class=\"noborder\">backup UP, going down </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4023 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4024 | "<td class=\"active2\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4025 | "<td class=\"backup2\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4026 | "</tr><tr>\n" |
| 4027 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4028 | "<td class=\"active9\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4029 | "</tr><tr>\n" |
| 4030 | "<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] | 4031 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4032 | "<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] | 4033 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4034 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4035 | "</td>" |
| 4036 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4037 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4038 | "", |
| 4039 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4040 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4041 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4042 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4043 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4044 | pid, relative_pid, global.nbproc, |
| 4045 | up / 86400, (up % 86400) / 3600, |
| 4046 | (up % 3600) / 60, (up % 60), |
| 4047 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4048 | global.rlimit_memmax ? " MB" : "", |
| 4049 | global.rlimit_nofile, |
| 4050 | global.maxsock, global.maxconn, global.maxpipes, |
| 4051 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4052 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4053 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4054 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4055 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 4056 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4057 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4058 | |
| 4059 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 4060 | "<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] | 4061 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4062 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4063 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 4064 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4065 | STAT_SCOPE_TXT_MAXLEN); |
| 4066 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4067 | /* 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] | 4068 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4069 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4070 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4071 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4072 | 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] | 4073 | } |
| 4074 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4075 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4076 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4077 | "<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] | 4078 | uri->uri_prefix, |
| 4079 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4080 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4081 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4082 | else |
| 4083 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4084 | "<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] | 4085 | uri->uri_prefix, |
| 4086 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4087 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4088 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4089 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4090 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4091 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4092 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4093 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4094 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4095 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4096 | "", |
| 4097 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4098 | else |
| 4099 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4100 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4101 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4102 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4103 | ";norefresh", |
| 4104 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4105 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4106 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4107 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4108 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4109 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4110 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4111 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4112 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4113 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4114 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4115 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4116 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4117 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4118 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4119 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4120 | chunk_appendf(&trash, |
| 4121 | "</ul></td>" |
| 4122 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4123 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4124 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4125 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4126 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4127 | "</ul>" |
| 4128 | "</td>" |
| 4129 | "</tr></table>\n" |
| 4130 | "" |
| 4131 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4132 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4133 | if (appctx->ctx.stats.st_code) { |
| 4134 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4135 | case STAT_STATUS_DONE: |
| 4136 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4137 | "<p><div class=active4>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4138 | "<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] | 4139 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4140 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4141 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4142 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4143 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4144 | break; |
| 4145 | case STAT_STATUS_NONE: |
| 4146 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4147 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4148 | "<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] | 4149 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4150 | "</div>\n", 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" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4153 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4154 | break; |
| 4155 | case STAT_STATUS_PART: |
| 4156 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4157 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4158 | "<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] | 4159 | "Action partially processed.<br>" |
| 4160 | "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] | 4161 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4162 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4163 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4164 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4165 | break; |
| 4166 | case STAT_STATUS_ERRP: |
| 4167 | chunk_appendf(&trash, |
| 4168 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4169 | "<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] | 4170 | "Action not processed because of invalid parameters." |
| 4171 | "<ul>" |
| 4172 | "<li>The action is maybe unknown.</li>" |
| 4173 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4174 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4175 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4176 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4177 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4178 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4179 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4180 | break; |
| 4181 | case STAT_STATUS_EXCD: |
| 4182 | chunk_appendf(&trash, |
| 4183 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4184 | "<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] | 4185 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4186 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4187 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4188 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4189 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4190 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4191 | break; |
| 4192 | case STAT_STATUS_DENY: |
| 4193 | chunk_appendf(&trash, |
| 4194 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4195 | "<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] | 4196 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4197 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4198 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4199 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4200 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4201 | break; |
| 4202 | default: |
| 4203 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4204 | "<p><div class=active9>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4205 | "<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] | 4206 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4207 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4208 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4209 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4210 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4211 | } |
| 4212 | chunk_appendf(&trash, "<p>\n"); |
| 4213 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4214 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4215 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4216 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4217 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4218 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4219 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4220 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4221 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4222 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4223 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4224 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4225 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4226 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4227 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 4228 | * and the session must be closed, or -1 in case of any error. This function is |
| 4229 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4230 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4231 | 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] | 4232 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4233 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4234 | struct channel *rep = si->ib; |
| 4235 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4236 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4237 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4238 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4239 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4240 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4241 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4242 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4243 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4244 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4245 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4246 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4247 | else |
| 4248 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4249 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4250 | if (bi_putchk(rep, &trash) == -1) |
| 4251 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4252 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4253 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4254 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4255 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4256 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4257 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4258 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4259 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4260 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4261 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4262 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4263 | appctx->ctx.stats.px = proxy; |
| 4264 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4265 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4266 | /* fall through */ |
| 4267 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4268 | case STAT_ST_LIST: |
| 4269 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4270 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4271 | if (buffer_almost_full(rep->buf)) { |
| 4272 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4273 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4274 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4275 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4276 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4277 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4278 | 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] | 4279 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4280 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4281 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4282 | appctx->ctx.stats.px = px->next; |
| 4283 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4284 | } |
| 4285 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4286 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4287 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4288 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4289 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4290 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4291 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4292 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4293 | if (bi_putchk(rep, &trash) == -1) |
| 4294 | return 0; |
| 4295 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4296 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4297 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4298 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4299 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4300 | case STAT_ST_FIN: |
| 4301 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4302 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4303 | default: |
| 4304 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4305 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4306 | return -1; |
| 4307 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4308 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4309 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4310 | /* We reached the stats page through a POST request. The appctx is |
| 4311 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4312 | * Parse the posted data and enable/disable servers if necessary. |
| 4313 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4314 | */ |
| 4315 | static int stats_process_http_post(struct stream_interface *si) |
| 4316 | { |
| 4317 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4318 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4319 | |
| 4320 | struct proxy *px = NULL; |
| 4321 | struct server *sv = NULL; |
| 4322 | |
| 4323 | char key[LINESIZE]; |
| 4324 | int action = ST_ADM_ACTION_NONE; |
| 4325 | int reprocess = 0; |
| 4326 | |
| 4327 | int total_servers = 0; |
| 4328 | int altered_servers = 0; |
| 4329 | |
| 4330 | char *first_param, *cur_param, *next_param, *end_params; |
| 4331 | char *st_cur_param = NULL; |
| 4332 | char *st_next_param = NULL; |
| 4333 | |
| 4334 | struct chunk *temp; |
| 4335 | int reql; |
| 4336 | |
| 4337 | temp = get_trash_chunk(); |
| 4338 | if (temp->size < s->txn.req.body_len) { |
| 4339 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4340 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4341 | goto out; |
| 4342 | } |
| 4343 | |
| 4344 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 4345 | if (reql <= 0) { |
| 4346 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4347 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4348 | return 0; |
| 4349 | } |
| 4350 | |
| 4351 | first_param = temp->str; |
| 4352 | end_params = temp->str + reql; |
| 4353 | cur_param = next_param = end_params; |
| 4354 | *end_params = '\0'; |
| 4355 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4356 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4357 | |
| 4358 | /* |
| 4359 | * Parse the parameters in reverse order to only store the last value. |
| 4360 | * From the html form, the backend and the action are at the end. |
| 4361 | */ |
| 4362 | while (cur_param > first_param) { |
| 4363 | char *value; |
| 4364 | int poffset, plen; |
| 4365 | |
| 4366 | cur_param--; |
| 4367 | |
| 4368 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4369 | reprocess_servers: |
| 4370 | /* Parse the key */ |
| 4371 | poffset = (cur_param != first_param ? 1 : 0); |
| 4372 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4373 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4374 | strncpy(key, cur_param + poffset, plen); |
| 4375 | key[plen - 1] = '\0'; |
| 4376 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4377 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4378 | goto out; |
| 4379 | } |
| 4380 | |
| 4381 | /* Parse the value */ |
| 4382 | value = key; |
| 4383 | while (*value != '\0' && *value != '=') { |
| 4384 | value++; |
| 4385 | } |
| 4386 | if (*value == '=') { |
| 4387 | /* Ok, a value is found, we can mark the end of the key */ |
| 4388 | *value++ = '\0'; |
| 4389 | } |
| 4390 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4391 | break; |
| 4392 | |
| 4393 | /* Now we can check the key to see what to do */ |
| 4394 | if (!px && (strcmp(key, "b") == 0)) { |
| 4395 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4396 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4397 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4398 | goto out; |
| 4399 | } |
| 4400 | } |
| 4401 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4402 | if (strcmp(value, "ready") == 0) { |
| 4403 | action = ST_ADM_ACTION_READY; |
| 4404 | } |
| 4405 | else if (strcmp(value, "drain") == 0) { |
| 4406 | action = ST_ADM_ACTION_DRAIN; |
| 4407 | } |
| 4408 | else if (strcmp(value, "maint") == 0) { |
| 4409 | action = ST_ADM_ACTION_MAINT; |
| 4410 | } |
| 4411 | else if (strcmp(value, "shutdown") == 0) { |
| 4412 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4413 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4414 | else if (strcmp(value, "dhlth") == 0) { |
| 4415 | action = ST_ADM_ACTION_DHLTH; |
| 4416 | } |
| 4417 | else if (strcmp(value, "ehlth") == 0) { |
| 4418 | action = ST_ADM_ACTION_EHLTH; |
| 4419 | } |
| 4420 | else if (strcmp(value, "hrunn") == 0) { |
| 4421 | action = ST_ADM_ACTION_HRUNN; |
| 4422 | } |
| 4423 | else if (strcmp(value, "hnolb") == 0) { |
| 4424 | action = ST_ADM_ACTION_HNOLB; |
| 4425 | } |
| 4426 | else if (strcmp(value, "hdown") == 0) { |
| 4427 | action = ST_ADM_ACTION_HDOWN; |
| 4428 | } |
| 4429 | else if (strcmp(value, "dagent") == 0) { |
| 4430 | action = ST_ADM_ACTION_DAGENT; |
| 4431 | } |
| 4432 | else if (strcmp(value, "eagent") == 0) { |
| 4433 | action = ST_ADM_ACTION_EAGENT; |
| 4434 | } |
| 4435 | else if (strcmp(value, "arunn") == 0) { |
| 4436 | action = ST_ADM_ACTION_ARUNN; |
| 4437 | } |
| 4438 | else if (strcmp(value, "adown") == 0) { |
| 4439 | action = ST_ADM_ACTION_ADOWN; |
| 4440 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4441 | /* else these are the old supported methods */ |
| 4442 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4443 | action = ST_ADM_ACTION_DISABLE; |
| 4444 | } |
| 4445 | else if (strcmp(value, "enable") == 0) { |
| 4446 | action = ST_ADM_ACTION_ENABLE; |
| 4447 | } |
| 4448 | else if (strcmp(value, "stop") == 0) { |
| 4449 | action = ST_ADM_ACTION_STOP; |
| 4450 | } |
| 4451 | else if (strcmp(value, "start") == 0) { |
| 4452 | action = ST_ADM_ACTION_START; |
| 4453 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4454 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4455 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4456 | goto out; |
| 4457 | } |
| 4458 | } |
| 4459 | else if (strcmp(key, "s") == 0) { |
| 4460 | if (!(px && action)) { |
| 4461 | /* |
| 4462 | * Indicates that we'll need to reprocess the parameters |
| 4463 | * as soon as backend and action are known |
| 4464 | */ |
| 4465 | if (!reprocess) { |
| 4466 | st_cur_param = cur_param; |
| 4467 | st_next_param = next_param; |
| 4468 | } |
| 4469 | reprocess = 1; |
| 4470 | } |
| 4471 | else if ((sv = findserver(px, value)) != NULL) { |
| 4472 | switch (action) { |
| 4473 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4474 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4475 | altered_servers++; |
| 4476 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4477 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4478 | } |
| 4479 | break; |
| 4480 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4481 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4482 | altered_servers++; |
| 4483 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4484 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4485 | } |
| 4486 | break; |
| 4487 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4488 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 4489 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4490 | altered_servers++; |
| 4491 | total_servers++; |
| 4492 | } |
| 4493 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4494 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4495 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 4496 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4497 | altered_servers++; |
| 4498 | total_servers++; |
| 4499 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4500 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4501 | case ST_ADM_ACTION_DHLTH: |
| 4502 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4503 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4504 | altered_servers++; |
| 4505 | total_servers++; |
| 4506 | } |
| 4507 | break; |
| 4508 | case ST_ADM_ACTION_EHLTH: |
| 4509 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4510 | sv->check.state |= CHK_ST_ENABLED; |
| 4511 | altered_servers++; |
| 4512 | total_servers++; |
| 4513 | } |
| 4514 | break; |
| 4515 | case ST_ADM_ACTION_HRUNN: |
| 4516 | if (!(sv->track)) { |
| 4517 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4518 | srv_set_running(sv, "changed from Web interface"); |
| 4519 | altered_servers++; |
| 4520 | total_servers++; |
| 4521 | } |
| 4522 | break; |
| 4523 | case ST_ADM_ACTION_HNOLB: |
| 4524 | if (!(sv->track)) { |
| 4525 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4526 | srv_set_stopping(sv, "changed from Web interface"); |
| 4527 | altered_servers++; |
| 4528 | total_servers++; |
| 4529 | } |
| 4530 | break; |
| 4531 | case ST_ADM_ACTION_HDOWN: |
| 4532 | if (!(sv->track)) { |
| 4533 | sv->check.health = 0; |
| 4534 | srv_set_stopped(sv, "changed from Web interface"); |
| 4535 | altered_servers++; |
| 4536 | total_servers++; |
| 4537 | } |
| 4538 | break; |
| 4539 | case ST_ADM_ACTION_DAGENT: |
| 4540 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4541 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4542 | altered_servers++; |
| 4543 | total_servers++; |
| 4544 | } |
| 4545 | break; |
| 4546 | case ST_ADM_ACTION_EAGENT: |
| 4547 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4548 | sv->agent.state |= CHK_ST_ENABLED; |
| 4549 | altered_servers++; |
| 4550 | total_servers++; |
| 4551 | } |
| 4552 | break; |
| 4553 | case ST_ADM_ACTION_ARUNN: |
| 4554 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4555 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 4556 | srv_set_running(sv, "changed from Web interface"); |
| 4557 | altered_servers++; |
| 4558 | total_servers++; |
| 4559 | } |
| 4560 | break; |
| 4561 | case ST_ADM_ACTION_ADOWN: |
| 4562 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4563 | sv->agent.health = 0; |
| 4564 | srv_set_stopped(sv, "changed from Web interface"); |
| 4565 | altered_servers++; |
| 4566 | total_servers++; |
| 4567 | } |
| 4568 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4569 | case ST_ADM_ACTION_READY: |
| 4570 | srv_adm_set_ready(sv); |
| 4571 | altered_servers++; |
| 4572 | total_servers++; |
| 4573 | break; |
| 4574 | case ST_ADM_ACTION_DRAIN: |
| 4575 | srv_adm_set_drain(sv); |
| 4576 | altered_servers++; |
| 4577 | total_servers++; |
| 4578 | break; |
| 4579 | case ST_ADM_ACTION_MAINT: |
| 4580 | srv_adm_set_maint(sv); |
| 4581 | altered_servers++; |
| 4582 | total_servers++; |
| 4583 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4584 | case ST_ADM_ACTION_SHUTDOWN: |
| 4585 | if (px->state != PR_STSTOPPED) { |
| 4586 | struct session *sess, *sess_bck; |
| 4587 | |
| 4588 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4589 | if (sess->srv_conn == sv) |
| 4590 | session_shutdown(sess, SN_ERR_KILLED); |
| 4591 | |
| 4592 | altered_servers++; |
| 4593 | total_servers++; |
| 4594 | } |
| 4595 | break; |
| 4596 | } |
| 4597 | } else { |
| 4598 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4599 | total_servers++; |
| 4600 | } |
| 4601 | } |
| 4602 | if (reprocess && px && action) { |
| 4603 | /* Now, we know the backend and the action chosen by the user. |
| 4604 | * We can safely restart from the first server parameter |
| 4605 | * to reprocess them |
| 4606 | */ |
| 4607 | cur_param = st_cur_param; |
| 4608 | next_param = st_next_param; |
| 4609 | reprocess = 0; |
| 4610 | goto reprocess_servers; |
| 4611 | } |
| 4612 | |
| 4613 | next_param = cur_param; |
| 4614 | } |
| 4615 | } |
| 4616 | |
| 4617 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4618 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4619 | } |
| 4620 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4621 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4622 | } |
| 4623 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4624 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4625 | } |
| 4626 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4627 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4628 | } |
| 4629 | out: |
| 4630 | return 1; |
| 4631 | } |
| 4632 | |
| 4633 | |
| 4634 | static int stats_send_http_headers(struct stream_interface *si) |
| 4635 | { |
| 4636 | struct session *s = session_from_task(si->owner); |
| 4637 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4638 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4639 | |
| 4640 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4641 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4642 | "Cache-Control: no-cache\r\n" |
| 4643 | "Connection: close\r\n" |
| 4644 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4645 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4646 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4647 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4648 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4649 | uri->refresh); |
| 4650 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4651 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4652 | |
| 4653 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4654 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4655 | else |
| 4656 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4657 | |
| 4658 | s->txn.status = 200; |
| 4659 | s->logs.tv_request = now; |
| 4660 | |
| 4661 | if (bi_putchk(si->ib, &trash) == -1) |
| 4662 | return 0; |
| 4663 | |
| 4664 | return 1; |
| 4665 | } |
| 4666 | |
| 4667 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4668 | { |
| 4669 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4670 | struct session *s = session_from_task(si->owner); |
| 4671 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4672 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4673 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4674 | /* 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] | 4675 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4676 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4677 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4678 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4679 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4680 | } |
| 4681 | |
| 4682 | /* We don't want to land on the posted stats page because a refresh will |
| 4683 | * repost the data. We don't want this to happen on accident so we redirect |
| 4684 | * the browse to the stats page with a GET. |
| 4685 | */ |
| 4686 | chunk_printf(&trash, |
| 4687 | "HTTP/1.1 303 See Other\r\n" |
| 4688 | "Cache-Control: no-cache\r\n" |
| 4689 | "Content-Type: text/plain\r\n" |
| 4690 | "Connection: close\r\n" |
| 4691 | "Location: %s;st=%s%s%s%s\r\n" |
| 4692 | "\r\n", |
| 4693 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4694 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4695 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4696 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4697 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4698 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4699 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4700 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4701 | scope_txt); |
| 4702 | |
| 4703 | s->txn.status = 303; |
| 4704 | s->logs.tv_request = now; |
| 4705 | |
| 4706 | if (bi_putchk(si->ib, &trash) == -1) |
| 4707 | return 0; |
| 4708 | |
| 4709 | return 1; |
| 4710 | } |
| 4711 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4712 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4713 | * 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] | 4714 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4715 | * automatically unregisters itself once transfer is complete. |
| 4716 | */ |
| 4717 | static void http_stats_io_handler(struct stream_interface *si) |
| 4718 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4719 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4720 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4721 | struct channel *req = si->ob; |
| 4722 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4723 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4724 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4725 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4726 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4727 | /* check that the output is not closed */ |
| 4728 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4729 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4730 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4731 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4732 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4733 | if (stats_send_http_headers(si)) { |
| 4734 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4735 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4736 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4737 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4738 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4739 | } |
| 4740 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4741 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4742 | unsigned int prev_len = si->ib->buf->i; |
| 4743 | unsigned int data_len; |
| 4744 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 4745 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4746 | |
| 4747 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4748 | /* One difficulty we're facing is that we must prevent |
| 4749 | * the input data from being automatically forwarded to |
| 4750 | * the output area. For this, we temporarily disable |
| 4751 | * forwarding on the channel. |
| 4752 | */ |
| 4753 | last_fwd = si->ib->to_forward; |
| 4754 | si->ib->to_forward = 0; |
| 4755 | chunk_printf(&trash, "\r\n000000\r\n"); |
| 4756 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4757 | si->ib->to_forward = last_fwd; |
| 4758 | goto fail; |
| 4759 | } |
| 4760 | } |
| 4761 | |
| 4762 | data_len = si->ib->buf->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4763 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4764 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4765 | |
| 4766 | last_len = si->ib->buf->i; |
| 4767 | |
| 4768 | /* Now we must either adjust or remove the chunk size. This is |
| 4769 | * not easy because the chunk size might wrap at the end of the |
| 4770 | * buffer, so we pretend we have nothing in the buffer, we write |
| 4771 | * the size, then restore the buffer's contents. Note that we can |
| 4772 | * only do that because no forwarding is scheduled on the stats |
| 4773 | * applet. |
| 4774 | */ |
| 4775 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4776 | si->ib->total -= (last_len - prev_len); |
| 4777 | si->ib->buf->i -= (last_len - prev_len); |
| 4778 | |
| 4779 | if (last_len != data_len) { |
| 4780 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
| 4781 | bi_putchk(si->ib, &trash); |
| 4782 | |
| 4783 | si->ib->total += (last_len - data_len); |
| 4784 | si->ib->buf->i += (last_len - data_len); |
| 4785 | } |
| 4786 | /* now re-enable forwarding */ |
| 4787 | channel_forward(si->ib, last_fwd); |
| 4788 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4789 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4790 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4791 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4792 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4793 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4794 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4795 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4796 | } |
| 4797 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4798 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4799 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4800 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4801 | } |
| 4802 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4803 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 4804 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4805 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
| 4806 | if (bi_putchk(si->ib, &trash) == -1) |
| 4807 | goto fail; |
| 4808 | } |
| 4809 | /* eat the whole request */ |
| 4810 | bo_skip(si->ob, si->ob->buf->o); |
| 4811 | res->flags |= CF_READ_NULL; |
| 4812 | si_shutr(si); |
| 4813 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4814 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4815 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4816 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4817 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4818 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4819 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4820 | si_shutr(si); |
| 4821 | res->flags |= CF_READ_NULL; |
| 4822 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4823 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4824 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4825 | fail: |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4826 | /* update all other flags and resync with the other side */ |
| 4827 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4828 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4829 | /* we don't want to expire timeouts while we're processing requests */ |
| 4830 | si->ib->rex = TICK_ETERNITY; |
| 4831 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4832 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4833 | out: |
| 4834 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4835 | /* check that we have released everything then unregister */ |
| 4836 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4837 | } |
| 4838 | } |
| 4839 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4840 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4841 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4842 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4843 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4844 | return "NONE"; |
| 4845 | return conn->ctrl->name; |
| 4846 | } |
| 4847 | |
| 4848 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4849 | { |
| 4850 | static char ptr[17]; |
| 4851 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4852 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4853 | return "NONE"; |
| 4854 | |
| 4855 | if (conn->xprt == &raw_sock) |
| 4856 | return "RAW"; |
| 4857 | |
| 4858 | #ifdef USE_OPENSSL |
| 4859 | if (conn->xprt == &ssl_sock) |
| 4860 | return "SSL"; |
| 4861 | #endif |
| 4862 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4863 | return ptr; |
| 4864 | } |
| 4865 | |
| 4866 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4867 | { |
| 4868 | static char ptr[17]; |
| 4869 | |
| 4870 | if (!conn->data) |
| 4871 | return "NONE"; |
| 4872 | |
| 4873 | if (conn->data == &sess_conn_cb) |
| 4874 | return "SESS"; |
| 4875 | |
| 4876 | if (conn->data == &si_conn_cb) |
| 4877 | return "STRM"; |
| 4878 | |
| 4879 | if (conn->data == &check_conn_cb) |
| 4880 | return "CHCK"; |
| 4881 | |
| 4882 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4883 | return ptr; |
| 4884 | } |
| 4885 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4886 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4887 | * 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] | 4888 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4889 | * 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] | 4890 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4891 | 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] | 4892 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4893 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4894 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4895 | extern const char *monthname[12]; |
| 4896 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4897 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4898 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4899 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4900 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4901 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4902 | 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] | 4903 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4904 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4905 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4906 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4907 | appctx->ctx.sess.uid = 0; |
| 4908 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4909 | return 1; |
| 4910 | } |
| 4911 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4912 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4913 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4914 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4915 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4916 | /* fall through */ |
| 4917 | |
| 4918 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4919 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4920 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4921 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4922 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4923 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4924 | 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] | 4925 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 4926 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4927 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4928 | conn = objt_conn(sess->si[0].end); |
| 4929 | 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] | 4930 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4931 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4932 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4933 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4934 | break; |
| 4935 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4936 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4937 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4938 | default: |
| 4939 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4940 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4941 | break; |
| 4942 | } |
| 4943 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4944 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4945 | " 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] | 4946 | 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] | 4947 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4948 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4949 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4950 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 4951 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 4952 | sess->listener ? sess->listener->luid : 0); |
| 4953 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4954 | if (conn) |
| 4955 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4956 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4957 | 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] | 4958 | case AF_INET: |
| 4959 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4960 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4961 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4962 | break; |
| 4963 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4964 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4965 | break; |
| 4966 | default: |
| 4967 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4968 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4969 | break; |
| 4970 | } |
| 4971 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4972 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4973 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4974 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4975 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4976 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 4977 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4978 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4979 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4980 | conn = objt_conn(sess->si[1].end); |
| 4981 | if (conn) |
| 4982 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4983 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4984 | 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] | 4985 | case AF_INET: |
| 4986 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4987 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4988 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4989 | break; |
| 4990 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4991 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4992 | break; |
| 4993 | default: |
| 4994 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4995 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4996 | break; |
| 4997 | } |
| 4998 | |
| 4999 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5000 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5001 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5002 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5003 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5004 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5005 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5006 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5007 | if (conn) |
| 5008 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5009 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5010 | 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] | 5011 | case AF_INET: |
| 5012 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5013 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5014 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5015 | break; |
| 5016 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5017 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5018 | break; |
| 5019 | default: |
| 5020 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5021 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5022 | break; |
| 5023 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5024 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5025 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5026 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5027 | sess->task, |
| 5028 | sess->task->state, |
| 5029 | sess->task->nice, sess->task->calls, |
| 5030 | sess->task->expire ? |
| 5031 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5032 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5033 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5034 | task_in_rq(sess->task) ? ", running" : ""); |
| 5035 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5036 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5037 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5038 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5039 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5040 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5041 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 5042 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 5043 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 5044 | |
| 5045 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5046 | " 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] | 5047 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5048 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5049 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5050 | obj_type_name(sess->si[0].end), |
| 5051 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5052 | sess->si[0].exp ? |
| 5053 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5054 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5055 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5056 | sess->si[0].err_type); |
| 5057 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5058 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5059 | " 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] | 5060 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5061 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5062 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5063 | obj_type_name(sess->si[1].end), |
| 5064 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5065 | sess->si[1].exp ? |
| 5066 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5067 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5068 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5069 | sess->si[1].err_type); |
| 5070 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5071 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5072 | chunk_appendf(&trash, |
| 5073 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5074 | conn, |
| 5075 | get_conn_ctrl_name(conn), |
| 5076 | get_conn_xprt_name(conn), |
| 5077 | get_conn_data_name(conn), |
| 5078 | obj_type_name(conn->target), |
| 5079 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5080 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5081 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5082 | " 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] | 5083 | conn->flags, |
| 5084 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5085 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5086 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5087 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5088 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5089 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5090 | chunk_appendf(&trash, |
| 5091 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5092 | tmpctx, |
| 5093 | tmpctx->st0, |
| 5094 | tmpctx->st1, |
| 5095 | tmpctx->st2, |
| 5096 | tmpctx->applet->name); |
| 5097 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5098 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5099 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5100 | chunk_appendf(&trash, |
| 5101 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5102 | conn, |
| 5103 | get_conn_ctrl_name(conn), |
| 5104 | get_conn_xprt_name(conn), |
| 5105 | get_conn_data_name(conn), |
| 5106 | obj_type_name(conn->target), |
| 5107 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5108 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5109 | chunk_appendf(&trash, |
| 5110 | " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5111 | conn->flags, |
| 5112 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5113 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5114 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5115 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5116 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5117 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5118 | chunk_appendf(&trash, |
| 5119 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5120 | tmpctx, |
| 5121 | tmpctx->st0, |
| 5122 | tmpctx->st1, |
| 5123 | tmpctx->st2, |
| 5124 | tmpctx->applet->name); |
| 5125 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5126 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5127 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5128 | " 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] | 5129 | " an_exp=%s", |
| 5130 | sess->req, |
| 5131 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5132 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5133 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5134 | sess->req->analyse_exp ? |
| 5135 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 5136 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5137 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5138 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5139 | " rex=%s", |
| 5140 | sess->req->rex ? |
| 5141 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 5142 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5143 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5144 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5145 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5146 | " 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] | 5147 | sess->req->wex ? |
| 5148 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 5149 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5150 | sess->req->buf, |
| 5151 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5152 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5153 | sess->txn.req.next, sess->req->buf->i, |
| 5154 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5155 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5156 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5157 | " 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] | 5158 | " an_exp=%s", |
| 5159 | sess->rep, |
| 5160 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5161 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5162 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5163 | sess->rep->analyse_exp ? |
| 5164 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 5165 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5166 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5167 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5168 | " rex=%s", |
| 5169 | sess->rep->rex ? |
| 5170 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 5171 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5172 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5173 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5174 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5175 | " 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] | 5176 | sess->rep->wex ? |
| 5177 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 5178 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5179 | sess->rep->buf, |
| 5180 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5181 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5182 | sess->txn.rsp.next, sess->rep->buf->i, |
| 5183 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5184 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5185 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5186 | return 0; |
| 5187 | |
| 5188 | /* use other states to dump the contents */ |
| 5189 | } |
| 5190 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5191 | appctx->ctx.sess.uid = 0; |
| 5192 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5193 | return 1; |
| 5194 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5195 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5196 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5197 | { |
| 5198 | struct appctx *appctx = __objt_appctx(si->end); |
| 5199 | |
| 5200 | switch (appctx->st2) { |
| 5201 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5202 | /* Display the column headers. If the message cannot be sent, |
| 5203 | * quit the fucntion with returning 0. The function is called |
| 5204 | * later and restart at the state "STAT_ST_INIT". |
| 5205 | */ |
| 5206 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5207 | chunk_appendf(&trash, "# id (file) description\n"); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5208 | if (bi_putchk(si->ib, &trash) == -1) |
| 5209 | return 0; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5210 | |
| 5211 | /* Now, we start the browsing of the references lists. |
| 5212 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5213 | * avalaible field of this pointer is <list>. It is used with the function |
| 5214 | * pat_list_get_next() for retruning the first avalaible entry |
| 5215 | */ |
| 5216 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5217 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5218 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5219 | appctx->st2 = STAT_ST_LIST; |
| 5220 | /* fall through */ |
| 5221 | |
| 5222 | case STAT_ST_LIST: |
| 5223 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5224 | chunk_reset(&trash); |
| 5225 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5226 | /* Build messages. If the reference is used by another category than |
| 5227 | * the listed categorie, display the information in the massage. |
| 5228 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5229 | 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] | 5230 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5231 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5232 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5233 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5234 | /* let's try again later from this session. We add ourselves into |
| 5235 | * this session's users so that it can remove us upon termination. |
| 5236 | */ |
| 5237 | return 0; |
| 5238 | } |
| 5239 | |
| 5240 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5241 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5242 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | appctx->st2 = STAT_ST_FIN; |
| 5246 | /* fall through */ |
| 5247 | |
| 5248 | default: |
| 5249 | appctx->st2 = STAT_ST_FIN; |
| 5250 | return 1; |
| 5251 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5252 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5253 | } |
| 5254 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5255 | static int stats_map_lookup(struct stream_interface *si) |
| 5256 | { |
| 5257 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5258 | struct sample sample; |
| 5259 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5260 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5261 | |
| 5262 | switch (appctx->st2) { |
| 5263 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5264 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5265 | 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] | 5266 | 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] | 5267 | appctx->st2 = STAT_ST_LIST; |
| 5268 | /* fall through */ |
| 5269 | |
| 5270 | case STAT_ST_LIST: |
| 5271 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5272 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5273 | /* initialise chunk to build new message */ |
| 5274 | chunk_reset(&trash); |
| 5275 | |
| 5276 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 5277 | sample.type = SMP_T_STR; |
| 5278 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5279 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 5280 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5281 | if (appctx->ctx.map.expr->pat_head->match && |
| 5282 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5283 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5284 | else |
| 5285 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5286 | |
| 5287 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5288 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5289 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5290 | break; |
| 5291 | if (match_method >= PAT_MATCH_NUM) |
| 5292 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5293 | else |
| 5294 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5295 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5296 | /* case sensitive */ |
| 5297 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5298 | chunk_appendf(&trash, ", case=insensitive"); |
| 5299 | else |
| 5300 | chunk_appendf(&trash, ", case=sensitive"); |
| 5301 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5302 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5303 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5304 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5305 | chunk_appendf(&trash, ", found=no"); |
| 5306 | else |
| 5307 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | /* Display match and match info */ |
| 5311 | else { |
| 5312 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5313 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5314 | chunk_appendf(&trash, ", found=yes"); |
| 5315 | else |
| 5316 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5317 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5318 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5319 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5320 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5321 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5322 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5323 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5324 | /* display pattern */ |
| 5325 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5326 | if (pat->ref && pat->ref->pattern) |
| 5327 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5328 | else |
| 5329 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5330 | } |
| 5331 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5332 | if (pat->ref && pat->ref->pattern) |
| 5333 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5334 | else |
| 5335 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5336 | } |
| 5337 | |
| 5338 | /* display return value */ |
| 5339 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5340 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5341 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5342 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5343 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5344 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5345 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5346 | } |
| 5347 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5348 | chunk_appendf(&trash, "\n"); |
| 5349 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5350 | /* display response */ |
| 5351 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5352 | /* let's try again later from this session. We add ourselves into |
| 5353 | * this session's users so that it can remove us upon termination. |
| 5354 | */ |
| 5355 | return 0; |
| 5356 | } |
| 5357 | |
| 5358 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5359 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5360 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | appctx->st2 = STAT_ST_FIN; |
| 5364 | /* fall through */ |
| 5365 | |
| 5366 | default: |
| 5367 | appctx->st2 = STAT_ST_FIN; |
| 5368 | free(appctx->ctx.map.chunk.str); |
| 5369 | return 1; |
| 5370 | } |
| 5371 | } |
| 5372 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5373 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5374 | { |
| 5375 | struct appctx *appctx = __objt_appctx(si->end); |
| 5376 | |
| 5377 | switch (appctx->st2) { |
| 5378 | |
| 5379 | case STAT_ST_INIT: |
| 5380 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5381 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5382 | struct pat_ref_elt *, list); |
| 5383 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5384 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5385 | appctx->st2 = STAT_ST_LIST; |
| 5386 | /* fall through */ |
| 5387 | |
| 5388 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5389 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5390 | chunk_reset(&trash); |
| 5391 | |
| 5392 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5393 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5394 | chunk_appendf(&trash, "%p %s %s\n", |
| 5395 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5396 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5397 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5398 | chunk_appendf(&trash, "%p %s\n", |
| 5399 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5400 | |
| 5401 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5402 | /* let's try again later from this session. We add ourselves into |
| 5403 | * this session's users so that it can remove us upon termination. |
| 5404 | */ |
| 5405 | return 0; |
| 5406 | } |
| 5407 | |
| 5408 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5409 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5410 | struct pat_ref_elt *, list); |
| 5411 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5412 | break; |
| 5413 | } |
| 5414 | |
| 5415 | appctx->st2 = STAT_ST_FIN; |
| 5416 | /* fall through */ |
| 5417 | |
| 5418 | default: |
| 5419 | appctx->st2 = STAT_ST_FIN; |
| 5420 | return 1; |
| 5421 | } |
| 5422 | } |
| 5423 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5424 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5425 | * 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] | 5426 | * to be called again, otherwise non-zero. It is designed to be called |
| 5427 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5428 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5429 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5430 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5431 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5432 | struct connection *conn; |
| 5433 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5434 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5435 | /* If we're forced to shut down, we might have to remove our |
| 5436 | * reference to the last session being dumped. |
| 5437 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5438 | if (appctx->st2 == STAT_ST_LIST) { |
| 5439 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5440 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5441 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5442 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5443 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5444 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5445 | } |
| 5446 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5447 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5448 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5449 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5450 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5451 | /* the function had not been called yet, let's prepare the |
| 5452 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5453 | * pointer to the first in the global list. When a target |
| 5454 | * session is being destroyed, it is responsible for updating |
| 5455 | * this pointer. We know we have reached the end when this |
| 5456 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5457 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5458 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5459 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5460 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5461 | /* fall through */ |
| 5462 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5463 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5464 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5465 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5466 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5467 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5471 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5472 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5473 | struct session *curr_sess; |
| 5474 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5475 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5476 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5477 | if (appctx->ctx.sess.target) { |
| 5478 | 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] | 5479 | goto next_sess; |
| 5480 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5481 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5482 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5483 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5484 | return 0; |
| 5485 | |
| 5486 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5487 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5488 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5489 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5490 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5491 | break; |
| 5492 | } |
| 5493 | else |
| 5494 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5495 | } |
| 5496 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5497 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5498 | "%p: proto=%s", |
| 5499 | curr_sess, |
| 5500 | curr_sess->listener->proto->name); |
| 5501 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5502 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5503 | conn = objt_conn(curr_sess->si[0].end); |
| 5504 | 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] | 5505 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5506 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5507 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5508 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5509 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5510 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5511 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5512 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5513 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5514 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5515 | break; |
| 5516 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5517 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5518 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5519 | curr_sess->listener->luid, |
| 5520 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5521 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5522 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5523 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5524 | break; |
| 5525 | } |
| 5526 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5527 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5528 | " ts=%02x age=%s calls=%d", |
| 5529 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5530 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5531 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5532 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5533 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5534 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5535 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5536 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5537 | curr_sess->req->analysers, |
| 5538 | curr_sess->req->rex ? |
| 5539 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 5540 | TICKS_TO_MS(1000)) : ""); |
| 5541 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5542 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5543 | ",wx=%s", |
| 5544 | curr_sess->req->wex ? |
| 5545 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 5546 | TICKS_TO_MS(1000)) : ""); |
| 5547 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5548 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5549 | ",ax=%s]", |
| 5550 | curr_sess->req->analyse_exp ? |
| 5551 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 5552 | TICKS_TO_MS(1000)) : ""); |
| 5553 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5554 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5555 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5556 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5557 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5558 | curr_sess->rep->analysers, |
| 5559 | curr_sess->rep->rex ? |
| 5560 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5561 | TICKS_TO_MS(1000)) : ""); |
| 5562 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5563 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5564 | ",wx=%s", |
| 5565 | curr_sess->rep->wex ? |
| 5566 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 5567 | TICKS_TO_MS(1000)) : ""); |
| 5568 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5569 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5570 | ",ax=%s]", |
| 5571 | curr_sess->rep->analyse_exp ? |
| 5572 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5573 | TICKS_TO_MS(1000)) : ""); |
| 5574 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5575 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5576 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5577 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5578 | curr_sess->si[0].state, |
| 5579 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5580 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5581 | curr_sess->si[0].exp ? |
| 5582 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5583 | TICKS_TO_MS(1000)) : ""); |
| 5584 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5585 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5586 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5587 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5588 | curr_sess->si[1].state, |
| 5589 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5590 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5591 | curr_sess->si[1].exp ? |
| 5592 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5593 | TICKS_TO_MS(1000)) : ""); |
| 5594 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5595 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5596 | " exp=%s", |
| 5597 | curr_sess->task->expire ? |
| 5598 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5599 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5600 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5601 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5602 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5603 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5604 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5605 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5606 | /* let's try again later from this session. We add ourselves into |
| 5607 | * this session's users so that it can remove us upon termination. |
| 5608 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5609 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5610 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5611 | } |
| 5612 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5613 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5614 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5615 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5616 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5617 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5618 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5619 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5620 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5621 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5622 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5623 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5624 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5625 | return 0; |
| 5626 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5627 | appctx->ctx.sess.target = NULL; |
| 5628 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5629 | return 1; |
| 5630 | } |
| 5631 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5632 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5633 | /* fall through */ |
| 5634 | |
| 5635 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5636 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5637 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5638 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5639 | } |
| 5640 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5641 | /* This is called when the stream interface is closed. For instance, upon an |
| 5642 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5643 | * remove back references to the session currently being dumped. |
| 5644 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5645 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5646 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5647 | struct appctx *appctx = __objt_appctx(si->end); |
| 5648 | |
| 5649 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5650 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5651 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5652 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5653 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5654 | free(appctx->ctx.cli.err); |
| 5655 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5656 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5657 | free(appctx->ctx.map.chunk.str); |
| 5658 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5659 | } |
| 5660 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5661 | /* This function is used to either dump tables states (when action is set |
| 5662 | * 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] | 5663 | * It returns 0 if the output buffer is full and it needs to be called |
| 5664 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5665 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5666 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5667 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5668 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5669 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5670 | struct ebmb_node *eb; |
| 5671 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5672 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5673 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5674 | |
| 5675 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5676 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5677 | * - STAT_ST_INIT : the first call |
| 5678 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5679 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5680 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5681 | * and the entry pointer points to the next entry to be dumped, |
| 5682 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5683 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5684 | * data though. |
| 5685 | */ |
| 5686 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5687 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5688 | /* 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] | 5689 | if (appctx->st2 == STAT_ST_LIST) { |
| 5690 | appctx->ctx.table.entry->ref_cnt--; |
| 5691 | 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] | 5692 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5693 | return 1; |
| 5694 | } |
| 5695 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5696 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5697 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5698 | while (appctx->st2 != STAT_ST_FIN) { |
| 5699 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5700 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5701 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5702 | if (!appctx->ctx.table.proxy) |
| 5703 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5704 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5705 | appctx->ctx.table.entry = NULL; |
| 5706 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5707 | break; |
| 5708 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5709 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5710 | if (!appctx->ctx.table.proxy || |
| 5711 | (appctx->ctx.table.target && |
| 5712 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5713 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5714 | break; |
| 5715 | } |
| 5716 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5717 | if (appctx->ctx.table.proxy->table.size) { |
| 5718 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5719 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5720 | return 0; |
| 5721 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5722 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5723 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5724 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5725 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5726 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5727 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5728 | appctx->ctx.table.entry->ref_cnt++; |
| 5729 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5730 | break; |
| 5731 | } |
| 5732 | } |
| 5733 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5734 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5735 | break; |
| 5736 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5737 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5738 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5739 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5740 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5741 | /* we're filtering on some data contents */ |
| 5742 | void *ptr; |
| 5743 | long long data; |
| 5744 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5745 | dt = appctx->ctx.table.data_type; |
| 5746 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5747 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5748 | dt); |
| 5749 | |
| 5750 | data = 0; |
| 5751 | switch (stktable_data_types[dt].std_type) { |
| 5752 | case STD_T_SINT: |
| 5753 | data = stktable_data_cast(ptr, std_t_sint); |
| 5754 | break; |
| 5755 | case STD_T_UINT: |
| 5756 | data = stktable_data_cast(ptr, std_t_uint); |
| 5757 | break; |
| 5758 | case STD_T_ULL: |
| 5759 | data = stktable_data_cast(ptr, std_t_ull); |
| 5760 | break; |
| 5761 | case STD_T_FRQP: |
| 5762 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5763 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5764 | break; |
| 5765 | } |
| 5766 | |
| 5767 | /* 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] | 5768 | if ((data < appctx->ctx.table.value && |
| 5769 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5770 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5771 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5772 | (data == appctx->ctx.table.value && |
| 5773 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5774 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5775 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5776 | (data > appctx->ctx.table.value && |
| 5777 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5778 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5779 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5780 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5781 | } |
| 5782 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5783 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5784 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5785 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5786 | return 0; |
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 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5789 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5790 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5791 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5792 | struct stksess *old = appctx->ctx.table.entry; |
| 5793 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5794 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5795 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5796 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5797 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5798 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5799 | break; |
| 5800 | } |
| 5801 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5802 | |
| 5803 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5804 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5805 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5806 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5807 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5808 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5809 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5810 | break; |
| 5811 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5812 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5813 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5814 | break; |
| 5815 | } |
| 5816 | } |
| 5817 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5818 | } |
| 5819 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5820 | /* 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] | 5821 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5822 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5823 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5824 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5825 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5826 | * after the offset. The new pointer is returned. |
| 5827 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5828 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5829 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5830 | { |
| 5831 | int end; |
| 5832 | unsigned char c; |
| 5833 | |
| 5834 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5835 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5836 | return ptr; |
| 5837 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5838 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5839 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5840 | while (ptr < len && ptr < bsize) { |
| 5841 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5842 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5843 | if (out->len > end - 2) |
| 5844 | break; |
| 5845 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5846 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5847 | if (out->len > end - 3) |
| 5848 | break; |
| 5849 | out->str[out->len++] = '\\'; |
| 5850 | switch (c) { |
| 5851 | case '\t': c = 't'; break; |
| 5852 | case '\n': c = 'n'; break; |
| 5853 | case '\r': c = 'r'; break; |
| 5854 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5855 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5856 | } |
| 5857 | out->str[out->len++] = c; |
| 5858 | } else { |
| 5859 | if (out->len > end - 5) |
| 5860 | break; |
| 5861 | out->str[out->len++] = '\\'; |
| 5862 | out->str[out->len++] = 'x'; |
| 5863 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5864 | out->str[out->len++] = hextab[c & 0xF]; |
| 5865 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5866 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5867 | /* we had a line break, let's return now */ |
| 5868 | out->str[out->len++] = '\n'; |
| 5869 | *line = ptr; |
| 5870 | return ptr; |
| 5871 | } |
| 5872 | } |
| 5873 | /* we have an incomplete line, we return it as-is */ |
| 5874 | out->str[out->len++] = '\n'; |
| 5875 | return ptr; |
| 5876 | } |
| 5877 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5878 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5879 | * 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] | 5880 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5881 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5882 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5883 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5884 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5885 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5886 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5887 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5888 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5889 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5890 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5891 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5892 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5893 | /* the function had not been called yet, let's prepare the |
| 5894 | * buffer for a response. |
| 5895 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5896 | struct tm tm; |
| 5897 | |
| 5898 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5899 | 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] | 5900 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5901 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5902 | error_snapshot_id); |
| 5903 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5904 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5905 | /* Socket buffer full. Let's try again later from the same point */ |
| 5906 | return 0; |
| 5907 | } |
| 5908 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5909 | appctx->ctx.errors.px = proxy; |
| 5910 | appctx->ctx.errors.buf = 0; |
| 5911 | appctx->ctx.errors.bol = 0; |
| 5912 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5913 | } |
| 5914 | |
| 5915 | /* we have two inner loops here, one for the proxy, the other one for |
| 5916 | * the buffer. |
| 5917 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5918 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5919 | struct error_snapshot *es; |
| 5920 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5921 | if (appctx->ctx.errors.buf == 0) |
| 5922 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5923 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5924 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5925 | |
| 5926 | if (!es->when.tv_sec) |
| 5927 | goto next; |
| 5928 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5929 | if (appctx->ctx.errors.iid >= 0 && |
| 5930 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 5931 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5932 | goto next; |
| 5933 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5934 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5935 | /* just print headers now */ |
| 5936 | |
| 5937 | char pn[INET6_ADDRSTRLEN]; |
| 5938 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5939 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5940 | |
| 5941 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5942 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5943 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5944 | 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] | 5945 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5946 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 5947 | case AF_INET: |
| 5948 | case AF_INET6: |
| 5949 | port = get_host_port(&es->src); |
| 5950 | break; |
| 5951 | default: |
| 5952 | port = 0; |
| 5953 | } |
| 5954 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5955 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5956 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5957 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5958 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5959 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5960 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5961 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 5962 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5963 | break; |
| 5964 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5965 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5966 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5967 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5968 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5969 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5970 | break; |
| 5971 | } |
| 5972 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5973 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5974 | ", server %s (#%d), event #%u\n" |
| 5975 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 5976 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 5977 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 5978 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 5979 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 5980 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 5981 | es->ev_id, |
| 5982 | pn, port, es->sid, es->s_flags, |
| 5983 | es->state, es->m_flags, es->t_flags, |
| 5984 | es->m_clen, es->m_blen, |
| 5985 | es->b_flags, es->b_out, es->b_tot, |
| 5986 | es->len, es->b_wrap, es->pos); |
| 5987 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5988 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5989 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5990 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5991 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5992 | appctx->ctx.errors.ptr = 0; |
| 5993 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5994 | } |
| 5995 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5996 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5997 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5998 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5999 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6000 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6001 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6002 | goto next; |
| 6003 | } |
| 6004 | |
| 6005 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6006 | 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] | 6007 | int newptr; |
| 6008 | int newline; |
| 6009 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6010 | newline = appctx->ctx.errors.bol; |
| 6011 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6012 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6013 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6014 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6015 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6016 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6017 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6018 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6019 | appctx->ctx.errors.ptr = newptr; |
| 6020 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6021 | }; |
| 6022 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6023 | appctx->ctx.errors.bol = 0; |
| 6024 | appctx->ctx.errors.ptr = -1; |
| 6025 | appctx->ctx.errors.buf++; |
| 6026 | if (appctx->ctx.errors.buf > 1) { |
| 6027 | appctx->ctx.errors.buf = 0; |
| 6028 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6029 | } |
| 6030 | } |
| 6031 | |
| 6032 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6033 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6034 | } |
| 6035 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6036 | /* parse the "level" argument on the bind lines */ |
| 6037 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6038 | { |
| 6039 | if (!*args[cur_arg + 1]) { |
| 6040 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6041 | return ERR_ALERT | ERR_FATAL; |
| 6042 | } |
| 6043 | |
| 6044 | if (!strcmp(args[cur_arg+1], "user")) |
| 6045 | conf->level = ACCESS_LVL_USER; |
| 6046 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6047 | conf->level = ACCESS_LVL_OPER; |
| 6048 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6049 | conf->level = ACCESS_LVL_ADMIN; |
| 6050 | else { |
| 6051 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6052 | args[cur_arg], args[cur_arg+1]); |
| 6053 | return ERR_ALERT | ERR_FATAL; |
| 6054 | } |
| 6055 | |
| 6056 | return 0; |
| 6057 | } |
| 6058 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6059 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6060 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6061 | .name = "<STATS>", /* used for logging */ |
| 6062 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6063 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6064 | }; |
| 6065 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6066 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6067 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6068 | .name = "<CLI>", /* used for logging */ |
| 6069 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6070 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6071 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6072 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6073 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6074 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6075 | { 0, NULL, NULL }, |
| 6076 | }}; |
| 6077 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6078 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6079 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6080 | { NULL, NULL, 0 }, |
| 6081 | }}; |
| 6082 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6083 | __attribute__((constructor)) |
| 6084 | static void __dumpstats_module_init(void) |
| 6085 | { |
| 6086 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6087 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6088 | } |
| 6089 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6090 | /* |
| 6091 | * Local variables: |
| 6092 | * c-indent-level: 8 |
| 6093 | * c-basic-offset: 8 |
| 6094 | * End: |
| 6095 | */ |