Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 2 | * Functions dedicated to statistics output and the stats socket |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 27 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/debug.h> |
| 31 | #include <common/memory.h> |
| 32 | #include <common/mini-clist.h> |
| 33 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 34 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 35 | #include <common/time.h> |
| 36 | #include <common/uri_auth.h> |
| 37 | #include <common/version.h> |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 38 | #include <common/base64.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 41 | |
| 42 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 43 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 44 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 45 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 46 | #include <proto/dumpstats.h> |
| 47 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 48 | #include <proto/freq_ctr.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 49 | #include <proto/log.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 50 | #include <proto/pattern.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 51 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 52 | #include <proto/listener.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 53 | #include <proto/map.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 54 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 55 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 56 | #include <proto/proxy.h> |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 57 | #include <proto/sample.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 58 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 59 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 60 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 61 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 62 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 63 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 64 | #ifdef USE_OPENSSL |
| 65 | #include <proto/ssl_sock.h> |
| 66 | #endif |
| 67 | |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 68 | /* stats socket states */ |
| 69 | enum { |
| 70 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 71 | STAT_CLI_END, /* final state, let's close */ |
| 72 | STAT_CLI_GETREQ, /* wait for a request */ |
| 73 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 74 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 75 | STAT_CLI_PRINT, /* display message in cli->msg */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 76 | STAT_CLI_PRINT_FREE, /* display message in cli->msg. After the display, free the pointer */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 77 | STAT_CLI_O_INFO, /* dump info */ |
| 78 | STAT_CLI_O_SESS, /* dump sessions */ |
| 79 | STAT_CLI_O_ERR, /* dump errors */ |
| 80 | STAT_CLI_O_TAB, /* dump tables */ |
| 81 | STAT_CLI_O_CLR, /* clear tables */ |
| 82 | STAT_CLI_O_SET, /* set entries in tables */ |
| 83 | STAT_CLI_O_STAT, /* dump stats */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 84 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 85 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 86 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 87 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 90 | /* Actions available for the stats admin forms */ |
| 91 | enum { |
| 92 | ST_ADM_ACTION_NONE = 0, |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 93 | |
| 94 | /* enable/disable health checks */ |
| 95 | ST_ADM_ACTION_DHLTH, |
| 96 | ST_ADM_ACTION_EHLTH, |
| 97 | |
| 98 | /* force health check status */ |
| 99 | ST_ADM_ACTION_HRUNN, |
| 100 | ST_ADM_ACTION_HNOLB, |
| 101 | ST_ADM_ACTION_HDOWN, |
| 102 | |
| 103 | /* enable/disable agent checks */ |
| 104 | ST_ADM_ACTION_DAGENT, |
| 105 | ST_ADM_ACTION_EAGENT, |
| 106 | |
| 107 | /* force agent check status */ |
| 108 | ST_ADM_ACTION_ARUNN, |
| 109 | ST_ADM_ACTION_ADOWN, |
| 110 | |
| 111 | /* set admin state */ |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 112 | ST_ADM_ACTION_READY, |
| 113 | ST_ADM_ACTION_DRAIN, |
| 114 | ST_ADM_ACTION_MAINT, |
| 115 | ST_ADM_ACTION_SHUTDOWN, |
| 116 | /* these are the ancient actions, still available for compatibility */ |
| 117 | ST_ADM_ACTION_DISABLE, |
| 118 | ST_ADM_ACTION_ENABLE, |
| 119 | ST_ADM_ACTION_STOP, |
| 120 | ST_ADM_ACTION_START, |
| 121 | }; |
| 122 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 123 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 124 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 125 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 126 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 127 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 128 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 129 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 130 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 131 | static int stats_pats_list(struct stream_interface *si); |
| 132 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 133 | static int stats_map_lookup(struct stream_interface *si); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 134 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 135 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 136 | * cli_io_handler() |
| 137 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 138 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 139 | * -> stats_dump_info_to_buffer() // "show info" |
| 140 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 141 | * -> stats_dump_csv_header() |
| 142 | * -> stats_dump_proxy_to_buffer() |
| 143 | * -> stats_dump_fe_stats() |
| 144 | * -> stats_dump_li_stats() |
| 145 | * -> stats_dump_sv_stats() |
| 146 | * -> stats_dump_be_stats() |
| 147 | * |
| 148 | * http_stats_io_handler() |
| 149 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 150 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 151 | * -> stats_dump_html_head() // emits the HTML headers |
| 152 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 153 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 154 | * -> stats_dump_html_px_hdr() |
| 155 | * -> stats_dump_fe_stats() |
| 156 | * -> stats_dump_li_stats() |
| 157 | * -> stats_dump_sv_stats() |
| 158 | * -> stats_dump_be_stats() |
| 159 | * -> stats_dump_html_px_end() |
| 160 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 161 | */ |
| 162 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 163 | static struct si_applet cli_applet; |
| 164 | |
| 165 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 166 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 167 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 168 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 169 | " help : this message\n" |
| 170 | " prompt : toggle interactive mode with prompt\n" |
| 171 | " quit : disconnect\n" |
| 172 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 173 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 174 | " show stat : report counters for each proxy and server\n" |
| 175 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 176 | " 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] | 177 | " 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] | 178 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 179 | " set weight : change a server's weight\n" |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 180 | " set server : change a server's state or weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 181 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 182 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 183 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 184 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 185 | " disable : put a server or frontend in maintenance mode\n" |
| 186 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 187 | " 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] | 188 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 189 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 190 | " add acl : add acl entry\n" |
| 191 | " del acl : delete acl entry\n" |
| 192 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 193 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 194 | " get map : reports the keys and values matching a sample for a map\n" |
| 195 | " set map : modify map entry\n" |
| 196 | " add map : add map entry\n" |
| 197 | " del map : delete map entry\n" |
| 198 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 199 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 200 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 201 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 202 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 203 | "Permission denied\n" |
| 204 | ""; |
| 205 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 206 | /* data transmission states for the stats responses */ |
| 207 | enum { |
| 208 | STAT_ST_INIT = 0, |
| 209 | STAT_ST_HEAD, |
| 210 | STAT_ST_INFO, |
| 211 | STAT_ST_LIST, |
| 212 | STAT_ST_END, |
| 213 | STAT_ST_FIN, |
| 214 | }; |
| 215 | |
| 216 | /* data transmission states for the stats responses inside a proxy */ |
| 217 | enum { |
| 218 | STAT_PX_ST_INIT = 0, |
| 219 | STAT_PX_ST_TH, |
| 220 | STAT_PX_ST_FE, |
| 221 | STAT_PX_ST_LI, |
| 222 | STAT_PX_ST_SV, |
| 223 | STAT_PX_ST_BE, |
| 224 | STAT_PX_ST_END, |
| 225 | STAT_PX_ST_FIN, |
| 226 | }; |
| 227 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 228 | extern const char *stat_status_codes[]; |
| 229 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 230 | /* 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] | 231 | * 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] | 232 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 233 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 234 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 235 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 236 | s->target = &cli_applet.obj_type; |
Willy Tarreau | 4171e9e | 2013-12-01 12:32:30 +0100 | [diff] [blame] | 237 | /* 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] | 238 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 239 | tv_zero(&s->logs.tv_request); |
| 240 | s->logs.t_queue = 0; |
| 241 | s->logs.t_connect = 0; |
| 242 | s->logs.t_data = 0; |
| 243 | s->logs.t_close = 0; |
| 244 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 245 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 246 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 247 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 248 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 249 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 250 | if (s->listener->timeout) { |
| 251 | s->req->rto = *s->listener->timeout; |
| 252 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 253 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 254 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 255 | } |
| 256 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 257 | /* allocate a new stats frontend named <name>, and return it |
| 258 | * (or NULL in case of lack of memory). |
| 259 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 260 | 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] | 261 | { |
| 262 | struct proxy *fe; |
| 263 | |
| 264 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 265 | if (!fe) |
| 266 | return NULL; |
| 267 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 268 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 269 | fe->next = proxy; |
| 270 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 271 | fe->last_change = now.tv_sec; |
| 272 | fe->id = strdup("GLOBAL"); |
| 273 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 274 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 275 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 276 | fe->conf.file = strdup(file); |
| 277 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 278 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 279 | |
| 280 | /* the stats frontend is the only one able to assign ID #0 */ |
| 281 | fe->conf.id.key = fe->uuid = 0; |
| 282 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 283 | return fe; |
| 284 | } |
| 285 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 286 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 287 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 288 | * error message into the <err> buffer which will be preallocated. The trailing |
| 289 | * '\n' must not be written. The function must be called with <args> pointing to |
| 290 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 291 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 292 | 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] | 293 | struct proxy *defpx, const char *file, int line, |
| 294 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 295 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 296 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 297 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 298 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 299 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 300 | int cur_arg; |
| 301 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 302 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 303 | 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] | 304 | return -1; |
| 305 | } |
| 306 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 307 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 308 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 309 | 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] | 310 | return -1; |
| 311 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 314 | 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] | 315 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 316 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 317 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 318 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 319 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 320 | return -1; |
| 321 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 322 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 323 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 324 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 325 | static int bind_dumped; |
| 326 | struct bind_kw *kw; |
| 327 | |
| 328 | kw = bind_find_kw(args[cur_arg]); |
| 329 | if (kw) { |
| 330 | if (!kw->parse) { |
| 331 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 332 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 333 | return -1; |
| 334 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 335 | |
| 336 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 337 | if (err && *err) |
| 338 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 339 | else |
| 340 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 341 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 342 | return -1; |
| 343 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 344 | |
| 345 | cur_arg += 1 + kw->skip; |
| 346 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 347 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 348 | |
| 349 | if (!bind_dumped) { |
| 350 | bind_dump_kws(err); |
| 351 | indent_msg(err, 4); |
| 352 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 353 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 354 | |
| 355 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 356 | args[0], args[1], args[cur_arg], |
| 357 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 358 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 359 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 360 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 361 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 362 | l->maxconn = global.stats_fe->maxconn; |
| 363 | l->backlog = global.stats_fe->backlog; |
| 364 | l->timeout = &global.stats_fe->timeout.client; |
| 365 | l->accept = session_accept; |
| 366 | l->handler = process_session; |
| 367 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 368 | l->nice = -64; /* we want to boost priority for local stats */ |
| 369 | global.maxsock += l->maxconn; |
| 370 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 371 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 372 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 373 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 374 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 375 | |
| 376 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 377 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 378 | return -1; |
| 379 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 380 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 381 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 382 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 383 | return -1; |
| 384 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 385 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 386 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 387 | 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] | 388 | return -1; |
| 389 | } |
| 390 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 391 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 392 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 393 | else if (!strcmp(args[1], "maxconn")) { |
| 394 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 395 | |
| 396 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 397 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 398 | return -1; |
| 399 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 400 | |
| 401 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 402 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 403 | 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] | 404 | return -1; |
| 405 | } |
| 406 | } |
| 407 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 408 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 409 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 410 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 411 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 412 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 413 | if (!global.stats_fe) { |
| 414 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 415 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 416 | return -1; |
| 417 | } |
| 418 | } |
| 419 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 420 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 421 | unsigned int low, high; |
| 422 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 423 | if (strcmp(args[cur_arg], "all") == 0) { |
| 424 | set = 0; |
| 425 | break; |
| 426 | } |
| 427 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 428 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 429 | } |
| 430 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 431 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 432 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 433 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 434 | char *dash = strchr(args[cur_arg], '-'); |
| 435 | |
| 436 | low = high = str2uic(args[cur_arg]); |
| 437 | if (dash) |
| 438 | high = str2uic(dash + 1); |
| 439 | |
| 440 | if (high < low) { |
| 441 | unsigned int swap = low; |
| 442 | low = high; |
| 443 | high = swap; |
| 444 | } |
| 445 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 446 | if (low < 1 || high > LONGBITS) { |
| 447 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 448 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 449 | return -1; |
| 450 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 451 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 452 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 453 | } |
| 454 | else { |
| 455 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 456 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 457 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 458 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 459 | } |
| 460 | cur_arg++; |
| 461 | } |
| 462 | global.stats_fe->bind_proc = set; |
| 463 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 464 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 465 | 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] | 466 | return -1; |
| 467 | } |
| 468 | return 0; |
| 469 | } |
| 470 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 471 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 472 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 473 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 474 | * 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] | 475 | */ |
| 476 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 477 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 478 | chunk_appendf(&trash, |
| 479 | "# pxname,svname," |
| 480 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 481 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 482 | "bin,bout," |
| 483 | "dreq,dresp," |
| 484 | "ereq,econ,eresp," |
| 485 | "wretr,wredis," |
| 486 | "status,weight,act,bck," |
| 487 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 488 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 489 | "rate,rate_lim,rate_max," |
| 490 | "check_status,check_code,check_duration," |
| 491 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 492 | "req_rate,req_rate_max,req_tot," |
| 493 | "cli_abrt,srv_abrt," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 494 | "comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 495 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 496 | } |
| 497 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 498 | /* print a string of text buffer to <out>. The format is : |
| 499 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 500 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 501 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 502 | */ |
| 503 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 504 | { |
| 505 | unsigned char c; |
| 506 | int ptr = 0; |
| 507 | |
| 508 | while (buf[ptr] && ptr < bsize) { |
| 509 | c = buf[ptr]; |
| 510 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 511 | if (out->len > out->size - 1) |
| 512 | break; |
| 513 | out->str[out->len++] = c; |
| 514 | } |
| 515 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 516 | if (out->len > out->size - 2) |
| 517 | break; |
| 518 | out->str[out->len++] = '\\'; |
| 519 | switch (c) { |
| 520 | case ' ': c = ' '; break; |
| 521 | case '\t': c = 't'; break; |
| 522 | case '\n': c = 'n'; break; |
| 523 | case '\r': c = 'r'; break; |
| 524 | case '\e': c = 'e'; break; |
| 525 | case '\\': c = '\\'; break; |
| 526 | } |
| 527 | out->str[out->len++] = c; |
| 528 | } |
| 529 | else { |
| 530 | if (out->len > out->size - 4) |
| 531 | break; |
| 532 | out->str[out->len++] = '\\'; |
| 533 | out->str[out->len++] = 'x'; |
| 534 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 535 | out->str[out->len++] = hextab[c & 0xF]; |
| 536 | } |
| 537 | ptr++; |
| 538 | } |
| 539 | |
| 540 | return ptr; |
| 541 | } |
| 542 | |
| 543 | /* print a buffer in hexa. |
| 544 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 545 | */ |
| 546 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 547 | { |
| 548 | unsigned char c; |
| 549 | int ptr = 0; |
| 550 | |
| 551 | while (ptr < bsize) { |
| 552 | c = buf[ptr]; |
| 553 | |
| 554 | if (out->len > out->size - 2) |
| 555 | break; |
| 556 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 557 | out->str[out->len++] = hextab[c & 0xF]; |
| 558 | |
| 559 | ptr++; |
| 560 | } |
| 561 | return ptr; |
| 562 | } |
| 563 | |
| 564 | /* Dump the status of a table to a stream interface's |
| 565 | * read buffer. It returns 0 if the output buffer is full |
| 566 | * and needs to be called again, otherwise non-zero. |
| 567 | */ |
| 568 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 569 | struct proxy *proxy, struct proxy *target) |
| 570 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 571 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 572 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 573 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 574 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 575 | |
| 576 | /* any other information should be dumped here */ |
| 577 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 578 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 579 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 580 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 581 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 582 | return 0; |
| 583 | |
| 584 | return 1; |
| 585 | } |
| 586 | |
| 587 | /* Dump the a table entry to a stream interface's |
| 588 | * read buffer. It returns 0 if the output buffer is full |
| 589 | * and needs to be called again, otherwise non-zero. |
| 590 | */ |
| 591 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 592 | struct proxy *proxy, struct stksess *entry) |
| 593 | { |
| 594 | int dt; |
| 595 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 596 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 597 | |
| 598 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 599 | char addr[INET_ADDRSTRLEN]; |
| 600 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 601 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 602 | } |
| 603 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 604 | char addr[INET6_ADDRSTRLEN]; |
| 605 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 606 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 607 | } |
| 608 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 609 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 610 | } |
| 611 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 612 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 613 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 614 | } |
| 615 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 616 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 617 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 618 | } |
| 619 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 620 | 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] | 621 | |
| 622 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 623 | void *ptr; |
| 624 | |
| 625 | if (proxy->table.data_ofs[dt] == 0) |
| 626 | continue; |
| 627 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 628 | 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] | 629 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 630 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 631 | |
| 632 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 633 | switch (stktable_data_types[dt].std_type) { |
| 634 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 635 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 636 | break; |
| 637 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 638 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 639 | break; |
| 640 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 641 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 642 | break; |
| 643 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 644 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 645 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 646 | proxy->table.data_arg[dt].u)); |
| 647 | break; |
| 648 | } |
| 649 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 650 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 651 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 652 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 653 | return 0; |
| 654 | |
| 655 | return 1; |
| 656 | } |
| 657 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 658 | 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] | 659 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 660 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 661 | struct appctx *appctx = __objt_appctx(si->end); |
| 662 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 663 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 664 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 665 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 666 | long long value; |
| 667 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 668 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 669 | void *ptr; |
| 670 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 671 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 672 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 673 | |
| 674 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 675 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 676 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 677 | return; |
| 678 | } |
| 679 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 680 | switch (px->table.type) { |
| 681 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 682 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 683 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 684 | break; |
| 685 | case STKTABLE_TYPE_IPV6: |
| 686 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 687 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 688 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 689 | case STKTABLE_TYPE_INTEGER: |
| 690 | { |
| 691 | char *endptr; |
| 692 | unsigned long val; |
| 693 | errno = 0; |
| 694 | val = strtoul(args[4], &endptr, 10); |
| 695 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 696 | (errno != 0 && val == 0) || endptr == args[4] || |
| 697 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 698 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 699 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 700 | return; |
| 701 | } |
| 702 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 703 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 704 | break; |
| 705 | } |
| 706 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 707 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 708 | static_table_key->key = args[4]; |
| 709 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 710 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 711 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 712 | switch (action) { |
| 713 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 714 | 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] | 715 | break; |
| 716 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 717 | 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] | 718 | break; |
| 719 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 720 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 721 | break; |
| 722 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 723 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | |
| 727 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 728 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 729 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 730 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 731 | return; |
| 732 | } |
| 733 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 734 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 735 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 736 | switch (action) { |
| 737 | case STAT_CLI_O_TAB: |
| 738 | if (!ts) |
| 739 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 740 | chunk_reset(&trash); |
| 741 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 742 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 743 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 744 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 745 | |
| 746 | case STAT_CLI_O_CLR: |
| 747 | if (!ts) |
| 748 | return; |
| 749 | if (ts->ref_cnt) { |
| 750 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 751 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 752 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 753 | return; |
| 754 | } |
| 755 | stksess_kill(&px->table, ts); |
| 756 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 757 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 758 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 759 | if (ts) |
| 760 | stktable_touch(&px->table, ts, 1); |
| 761 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 762 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 763 | if (!ts) { |
| 764 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 765 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 766 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 767 | return; |
| 768 | } |
| 769 | stktable_store(&px->table, ts, 1); |
| 770 | } |
| 771 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 772 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 773 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 774 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 775 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 776 | return; |
| 777 | } |
| 778 | |
| 779 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 780 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 781 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 782 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 783 | return; |
| 784 | } |
| 785 | |
| 786 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 787 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 788 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 789 | return; |
| 790 | } |
| 791 | |
| 792 | 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] | 793 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 794 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 795 | return; |
| 796 | } |
| 797 | |
| 798 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 799 | |
| 800 | switch (stktable_data_types[data_type].std_type) { |
| 801 | case STD_T_SINT: |
| 802 | stktable_data_cast(ptr, std_t_sint) = value; |
| 803 | break; |
| 804 | case STD_T_UINT: |
| 805 | stktable_data_cast(ptr, std_t_uint) = value; |
| 806 | break; |
| 807 | case STD_T_ULL: |
| 808 | stktable_data_cast(ptr, std_t_ull) = value; |
| 809 | break; |
| 810 | case STD_T_FRQP: |
| 811 | /* We set both the current and previous values. That way |
| 812 | * the reported frequency is stable during all the period |
| 813 | * then slowly fades out. This allows external tools to |
| 814 | * push measures without having to update them too often. |
| 815 | */ |
| 816 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 817 | frqp->curr_tick = now_ms; |
| 818 | frqp->prev_ctr = 0; |
| 819 | frqp->curr_ctr = value; |
| 820 | break; |
| 821 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 822 | } |
| 823 | break; |
| 824 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 825 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 826 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 827 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 828 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 829 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 830 | } |
| 831 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 832 | 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] | 833 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 834 | struct appctx *appctx = __objt_appctx(si->end); |
| 835 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 836 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 837 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 838 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 839 | return; |
| 840 | } |
| 841 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 842 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 843 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 844 | if (appctx->ctx.table.data_type < 0) { |
| 845 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 846 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 847 | return; |
| 848 | } |
| 849 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 850 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 851 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 852 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 853 | return; |
| 854 | } |
| 855 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 856 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 857 | if (appctx->ctx.table.data_op < 0) { |
| 858 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 859 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 860 | return; |
| 861 | } |
| 862 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 863 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 864 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 865 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 866 | return; |
| 867 | } |
| 868 | } |
| 869 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 870 | 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] | 871 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 872 | struct appctx *appctx = __objt_appctx(si->end); |
| 873 | |
| 874 | appctx->ctx.table.data_type = -1; |
| 875 | appctx->st2 = STAT_ST_INIT; |
| 876 | appctx->ctx.table.target = NULL; |
| 877 | appctx->ctx.table.proxy = NULL; |
| 878 | appctx->ctx.table.entry = NULL; |
| 879 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 880 | |
| 881 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 882 | appctx->ctx.table.target = find_stktable(args[2]); |
| 883 | if (!appctx->ctx.table.target) { |
| 884 | appctx->ctx.cli.msg = "No such table\n"; |
| 885 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 886 | return; |
| 887 | } |
| 888 | } |
| 889 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 890 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 891 | goto err_args; |
| 892 | return; |
| 893 | } |
| 894 | |
| 895 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 896 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 897 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 898 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 899 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 900 | goto err_args; |
| 901 | |
| 902 | return; |
| 903 | |
| 904 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 905 | switch (action) { |
| 906 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 907 | 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] | 908 | break; |
| 909 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 910 | 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] | 911 | break; |
| 912 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 913 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 914 | break; |
| 915 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 916 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 917 | } |
| 918 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 919 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 920 | * adequate error messages and returns NULL. This function also expects the session |
| 921 | * level to be admin. |
| 922 | */ |
| 923 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 924 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 925 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 926 | struct proxy *px; |
| 927 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 928 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 929 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 930 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 931 | return NULL; |
| 932 | } |
| 933 | |
| 934 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 935 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 936 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 937 | return NULL; |
| 938 | } |
| 939 | |
| 940 | px = findproxy(arg, PR_CAP_FE); |
| 941 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 942 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 943 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 944 | return NULL; |
| 945 | } |
| 946 | return px; |
| 947 | } |
| 948 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 949 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 950 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 951 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 952 | * the <arg> is modified to remove the '/'. |
| 953 | */ |
| 954 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 955 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 956 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 957 | struct proxy *px; |
| 958 | struct server *sv; |
| 959 | char *line; |
| 960 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 961 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 962 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 963 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 964 | return NULL; |
| 965 | } |
| 966 | |
| 967 | /* split "backend/server" and make <line> point to server */ |
| 968 | for (line = arg; *line; line++) |
| 969 | if (*line == '/') { |
| 970 | *line++ = '\0'; |
| 971 | break; |
| 972 | } |
| 973 | |
| 974 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 975 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 976 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 977 | return NULL; |
| 978 | } |
| 979 | |
| 980 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 981 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 982 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 983 | return NULL; |
| 984 | } |
| 985 | |
| 986 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 987 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 988 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 989 | return NULL; |
| 990 | } |
| 991 | |
| 992 | return sv; |
| 993 | } |
| 994 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 995 | /* This function is used with map and acl management. It permits to browse |
| 996 | * each reference. The variable <getnext> must contain the current node, |
| 997 | * <end> point to the root node and the <flags> permit to filter required |
| 998 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 999 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1000 | static inline |
| 1001 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1002 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1003 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1004 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1005 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1006 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1007 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1008 | /* Get next list entry. */ |
| 1009 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1010 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1011 | /* If the entry is the last of the list, return NULL. */ |
| 1012 | if (&ref->list == end) |
| 1013 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1014 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1015 | /* If the entry match the flag, return it. */ |
| 1016 | if (ref->flags & flags) |
| 1017 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1018 | } |
| 1019 | } |
| 1020 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1021 | static inline |
| 1022 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1023 | { |
| 1024 | int id; |
| 1025 | char *error; |
| 1026 | |
| 1027 | /* If the reference starts by a '#', this is numeric id. */ |
| 1028 | if (reference[0] == '#') { |
| 1029 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1030 | id = strtol(reference + 1, &error, 10); |
| 1031 | if (*error != '\0') |
| 1032 | return NULL; |
| 1033 | |
| 1034 | /* Perform the unique id lookup. */ |
| 1035 | return pat_ref_lookupid(id); |
| 1036 | } |
| 1037 | |
| 1038 | /* Perform the string lookup. */ |
| 1039 | return pat_ref_lookup(reference); |
| 1040 | } |
| 1041 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1042 | /* This function is used with map and acl management. It permits to browse |
| 1043 | * each reference. |
| 1044 | */ |
| 1045 | static inline |
| 1046 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1047 | { |
| 1048 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1049 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1050 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1051 | return NULL; |
| 1052 | return expr; |
| 1053 | } |
| 1054 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1055 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1056 | * 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] | 1057 | * 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] | 1058 | * designating the function which will have to process the request, which can |
| 1059 | * 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] | 1060 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1061 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1062 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 1063 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1064 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1065 | char *args[MAX_STATS_ARGS + 1]; |
| 1066 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1067 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1068 | |
| 1069 | while (isspace((unsigned char)*line)) |
| 1070 | line++; |
| 1071 | |
| 1072 | arg = 0; |
| 1073 | args[arg] = line; |
| 1074 | |
| 1075 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1076 | if (*line == '\\') { |
| 1077 | line++; |
| 1078 | if (*line == '\0') |
| 1079 | break; |
| 1080 | } |
| 1081 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1082 | *line++ = '\0'; |
| 1083 | |
| 1084 | while (isspace((unsigned char)*line)) |
| 1085 | line++; |
| 1086 | |
| 1087 | args[++arg] = line; |
| 1088 | continue; |
| 1089 | } |
| 1090 | |
| 1091 | line++; |
| 1092 | } |
| 1093 | |
| 1094 | while (++arg <= MAX_STATS_ARGS) |
| 1095 | args[arg] = line; |
| 1096 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1097 | /* remove \ */ |
| 1098 | arg = 0; |
| 1099 | while (*args[arg] != '\0') { |
| 1100 | j = 0; |
| 1101 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1102 | if (args[arg][i] == '\\') |
| 1103 | continue; |
| 1104 | args[arg][j] = args[arg][i]; |
| 1105 | j++; |
| 1106 | } |
| 1107 | args[arg][j] = '\0'; |
| 1108 | arg++; |
| 1109 | } |
| 1110 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1111 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1112 | if (strcmp(args[0], "show") == 0) { |
| 1113 | if (strcmp(args[1], "stat") == 0) { |
| 1114 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1115 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1116 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1117 | appctx->ctx.stats.type = atoi(args[3]); |
| 1118 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1119 | } |
| 1120 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1121 | appctx->st2 = STAT_ST_INIT; |
| 1122 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1123 | } |
| 1124 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1125 | appctx->st2 = STAT_ST_INIT; |
| 1126 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1127 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1128 | else if (strcmp(args[1], "pools") == 0) { |
| 1129 | appctx->st2 = STAT_ST_INIT; |
| 1130 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1131 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1132 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1133 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1134 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1135 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1136 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1137 | return 1; |
| 1138 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1139 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1140 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1141 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1142 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1143 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1144 | appctx->ctx.sess.target = NULL; |
| 1145 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1146 | appctx->ctx.sess.pos = 0; |
| 1147 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1148 | } |
| 1149 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1150 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1151 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1152 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1153 | return 1; |
| 1154 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1155 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1156 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1157 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1158 | appctx->ctx.errors.iid = -1; |
| 1159 | appctx->ctx.errors.px = NULL; |
| 1160 | appctx->st2 = STAT_ST_INIT; |
| 1161 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1162 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1163 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1164 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1165 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1166 | else if (strcmp(args[1], "map") == 0 || |
| 1167 | strcmp(args[1], "acl") == 0) { |
| 1168 | |
| 1169 | /* Set ACL or MAP flags. */ |
| 1170 | if (args[1][0] == 'm') |
| 1171 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1172 | else |
| 1173 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1174 | |
| 1175 | /* no parameter: display all map avalaible */ |
| 1176 | if (!*args[2]) { |
| 1177 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1178 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1179 | return 1; |
| 1180 | } |
| 1181 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1182 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1183 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1184 | if (!appctx->ctx.map.ref || |
| 1185 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1186 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1187 | 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] | 1188 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1189 | 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] | 1190 | appctx->st0 = STAT_CLI_PRINT; |
| 1191 | return 1; |
| 1192 | } |
| 1193 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1194 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1195 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1196 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1197 | return 0; |
| 1198 | } |
| 1199 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1200 | else if (strcmp(args[0], "clear") == 0) { |
| 1201 | if (strcmp(args[1], "counters") == 0) { |
| 1202 | struct proxy *px; |
| 1203 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1204 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1205 | int clrall = 0; |
| 1206 | |
| 1207 | if (strcmp(args[2], "all") == 0) |
| 1208 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1209 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1210 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1211 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1212 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1213 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1214 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1215 | return 1; |
| 1216 | } |
| 1217 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1218 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1219 | if (clrall) { |
| 1220 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1221 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1222 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1223 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1224 | px->be_counters.conn_max = 0; |
| 1225 | px->be_counters.p.http.rps_max = 0; |
| 1226 | px->be_counters.sps_max = 0; |
| 1227 | px->be_counters.cps_max = 0; |
| 1228 | px->be_counters.nbpend_max = 0; |
| 1229 | |
| 1230 | px->fe_counters.conn_max = 0; |
| 1231 | px->fe_counters.p.http.rps_max = 0; |
| 1232 | px->fe_counters.sps_max = 0; |
| 1233 | px->fe_counters.cps_max = 0; |
| 1234 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1235 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1236 | |
| 1237 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1238 | if (clrall) |
| 1239 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1240 | else { |
| 1241 | sv->counters.cur_sess_max = 0; |
| 1242 | sv->counters.nbpend_max = 0; |
| 1243 | sv->counters.sps_max = 0; |
| 1244 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1245 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1246 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1247 | if (li->counters) { |
| 1248 | if (clrall) |
| 1249 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1250 | else |
| 1251 | li->counters->conn_max = 0; |
| 1252 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1253 | } |
| 1254 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1255 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1256 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1257 | return 1; |
| 1258 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1259 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1260 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1261 | /* end of processing */ |
| 1262 | return 1; |
| 1263 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1264 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1265 | /* Set ACL or MAP flags. */ |
| 1266 | if (args[1][0] == 'm') |
| 1267 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1268 | else |
| 1269 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1270 | |
| 1271 | /* no parameter */ |
| 1272 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1273 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1274 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1275 | else |
| 1276 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1277 | appctx->st0 = STAT_CLI_PRINT; |
| 1278 | return 1; |
| 1279 | } |
| 1280 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1281 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1282 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1283 | if (!appctx->ctx.map.ref || |
| 1284 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1285 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1286 | 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] | 1287 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1288 | 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] | 1289 | appctx->st0 = STAT_CLI_PRINT; |
| 1290 | return 1; |
| 1291 | } |
| 1292 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1293 | /* Clear all. */ |
| 1294 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1295 | |
| 1296 | /* return response */ |
| 1297 | appctx->ctx.cli.msg = "Done.\n"; |
| 1298 | appctx->st0 = STAT_CLI_PRINT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1299 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1300 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1301 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1302 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1303 | return 0; |
| 1304 | } |
| 1305 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1306 | else if (strcmp(args[0], "get") == 0) { |
| 1307 | if (strcmp(args[1], "weight") == 0) { |
| 1308 | struct proxy *px; |
| 1309 | struct server *sv; |
| 1310 | |
| 1311 | /* split "backend/server" and make <line> point to server */ |
| 1312 | for (line = args[2]; *line; line++) |
| 1313 | if (*line == '/') { |
| 1314 | *line++ = '\0'; |
| 1315 | break; |
| 1316 | } |
| 1317 | |
| 1318 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1319 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1320 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1321 | return 1; |
| 1322 | } |
| 1323 | |
| 1324 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1325 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1326 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1327 | return 1; |
| 1328 | } |
| 1329 | |
| 1330 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1331 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1332 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1333 | return 1; |
| 1334 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1335 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1336 | /* Set flags. */ |
| 1337 | if (args[1][0] == 'm') |
| 1338 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1339 | else |
| 1340 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1341 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1342 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1343 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1344 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1345 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1346 | else |
| 1347 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1348 | appctx->st0 = STAT_CLI_PRINT; |
| 1349 | return 1; |
| 1350 | } |
| 1351 | |
| 1352 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1353 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1354 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1355 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1356 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1357 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1358 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1359 | appctx->st0 = STAT_CLI_PRINT; |
| 1360 | return 1; |
| 1361 | } |
| 1362 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1363 | /* copy input string. The string must be allocated because |
| 1364 | * it may be used over multiple iterations. It's released |
| 1365 | * at the end and upon abort anyway. |
| 1366 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1367 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1368 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1369 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1370 | if (!appctx->ctx.map.chunk.str) { |
| 1371 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1372 | appctx->st0 = STAT_CLI_PRINT; |
| 1373 | return 1; |
| 1374 | } |
| 1375 | |
| 1376 | /* prepare response */ |
| 1377 | appctx->st2 = STAT_ST_INIT; |
| 1378 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1379 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1380 | else { /* not "get weight" */ |
| 1381 | return 0; |
| 1382 | } |
| 1383 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1384 | else if (strcmp(args[0], "set") == 0) { |
| 1385 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1386 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1387 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1388 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1389 | sv = expect_server_admin(s, si, args[2]); |
| 1390 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1391 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1392 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1393 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1394 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1395 | appctx->ctx.cli.msg = warning; |
| 1396 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1397 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1398 | return 1; |
| 1399 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1400 | else if (strcmp(args[1], "server") == 0) { |
| 1401 | struct server *sv; |
| 1402 | const char *warning; |
| 1403 | |
| 1404 | sv = expect_server_admin(s, si, args[2]); |
| 1405 | if (!sv) |
| 1406 | return 1; |
| 1407 | |
| 1408 | if (strcmp(args[3], "weight") == 0) { |
| 1409 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1410 | if (warning) { |
| 1411 | appctx->ctx.cli.msg = warning; |
| 1412 | appctx->st0 = STAT_CLI_PRINT; |
| 1413 | } |
| 1414 | } |
| 1415 | else if (strcmp(args[3], "state") == 0) { |
| 1416 | if (strcmp(args[4], "ready") == 0) |
| 1417 | srv_adm_set_ready(sv); |
| 1418 | else if (strcmp(args[4], "drain") == 0) |
| 1419 | srv_adm_set_drain(sv); |
| 1420 | else if (strcmp(args[4], "maint") == 0) |
| 1421 | srv_adm_set_maint(sv); |
| 1422 | else { |
| 1423 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1424 | appctx->st0 = STAT_CLI_PRINT; |
| 1425 | } |
| 1426 | } |
| 1427 | else if (strcmp(args[3], "health") == 0) { |
| 1428 | if (sv->track) { |
| 1429 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1430 | appctx->st0 = STAT_CLI_PRINT; |
| 1431 | } |
| 1432 | else if (strcmp(args[4], "up") == 0) { |
| 1433 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1434 | srv_set_running(sv, "changed from CLI"); |
| 1435 | } |
| 1436 | else if (strcmp(args[4], "stopping") == 0) { |
| 1437 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1438 | srv_set_stopping(sv, "changed from CLI"); |
| 1439 | } |
| 1440 | else if (strcmp(args[4], "down") == 0) { |
| 1441 | sv->check.health = 0; |
| 1442 | srv_set_stopped(sv, "changed from CLI"); |
| 1443 | } |
| 1444 | else { |
| 1445 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1446 | appctx->st0 = STAT_CLI_PRINT; |
| 1447 | } |
| 1448 | } |
| 1449 | else if (strcmp(args[3], "agent") == 0) { |
| 1450 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1451 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1452 | appctx->st0 = STAT_CLI_PRINT; |
| 1453 | } |
| 1454 | else if (strcmp(args[4], "up") == 0) { |
| 1455 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1456 | srv_set_running(sv, "changed from CLI"); |
| 1457 | } |
| 1458 | else if (strcmp(args[4], "down") == 0) { |
| 1459 | sv->agent.health = 0; |
| 1460 | srv_set_stopped(sv, "changed from CLI"); |
| 1461 | } |
| 1462 | else { |
| 1463 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1464 | appctx->st0 = STAT_CLI_PRINT; |
| 1465 | } |
| 1466 | } |
| 1467 | else { |
| 1468 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state' and 'weight'.\n"; |
| 1469 | appctx->st0 = STAT_CLI_PRINT; |
| 1470 | } |
| 1471 | return 1; |
| 1472 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1473 | else if (strcmp(args[1], "timeout") == 0) { |
| 1474 | if (strcmp(args[2], "cli") == 0) { |
| 1475 | unsigned timeout; |
| 1476 | const char *res; |
| 1477 | |
| 1478 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1479 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1480 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1481 | return 1; |
| 1482 | } |
| 1483 | |
| 1484 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1485 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1486 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1487 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1488 | return 1; |
| 1489 | } |
| 1490 | |
| 1491 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1492 | return 1; |
| 1493 | } |
| 1494 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1495 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1496 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1497 | return 1; |
| 1498 | } |
| 1499 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1500 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1501 | if (strcmp(args[2], "frontend") == 0) { |
| 1502 | struct proxy *px; |
| 1503 | struct listener *l; |
| 1504 | int v; |
| 1505 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1506 | px = expect_frontend_admin(s, si, args[3]); |
| 1507 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1508 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1509 | |
| 1510 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1511 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1512 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1513 | return 1; |
| 1514 | } |
| 1515 | |
| 1516 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1517 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1518 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1519 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1520 | return 1; |
| 1521 | } |
| 1522 | |
| 1523 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1524 | * its listeners. The blocked ones will be dequeued. |
| 1525 | */ |
| 1526 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1527 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1528 | l->maxconn = v; |
| 1529 | if (l->state == LI_FULL) |
| 1530 | resume_listener(l); |
| 1531 | } |
| 1532 | |
| 1533 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1534 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1535 | |
| 1536 | return 1; |
| 1537 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1538 | else if (strcmp(args[2], "global") == 0) { |
| 1539 | int v; |
| 1540 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1541 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1542 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1543 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1544 | return 1; |
| 1545 | } |
| 1546 | |
| 1547 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1548 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1549 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1550 | return 1; |
| 1551 | } |
| 1552 | |
| 1553 | v = atoi(args[3]); |
| 1554 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1555 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1556 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1557 | return 1; |
| 1558 | } |
| 1559 | |
| 1560 | /* check for unlimited values */ |
| 1561 | if (v <= 0) |
| 1562 | v = global.hardmaxconn; |
| 1563 | |
| 1564 | global.maxconn = v; |
| 1565 | |
| 1566 | /* Dequeues all of the listeners waiting for a resource */ |
| 1567 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1568 | dequeue_all_listeners(&global_listener_queue); |
| 1569 | |
| 1570 | return 1; |
| 1571 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1572 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1573 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1574 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1575 | return 1; |
| 1576 | } |
| 1577 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1578 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1579 | if (strcmp(args[2], "connections") == 0) { |
| 1580 | if (strcmp(args[3], "global") == 0) { |
| 1581 | int v; |
| 1582 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1583 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1584 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1585 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1586 | return 1; |
| 1587 | } |
| 1588 | |
| 1589 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1590 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1591 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1592 | return 1; |
| 1593 | } |
| 1594 | |
| 1595 | v = atoi(args[4]); |
| 1596 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1597 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1598 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1599 | return 1; |
| 1600 | } |
| 1601 | |
| 1602 | global.cps_lim = v; |
| 1603 | |
| 1604 | /* Dequeues all of the listeners waiting for a resource */ |
| 1605 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1606 | dequeue_all_listeners(&global_listener_queue); |
| 1607 | |
| 1608 | return 1; |
| 1609 | } |
| 1610 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1611 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1612 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1613 | return 1; |
| 1614 | } |
| 1615 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1616 | else if (strcmp(args[2], "sessions") == 0) { |
| 1617 | if (strcmp(args[3], "global") == 0) { |
| 1618 | int v; |
| 1619 | |
| 1620 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1621 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1622 | appctx->st0 = STAT_CLI_PRINT; |
| 1623 | return 1; |
| 1624 | } |
| 1625 | |
| 1626 | if (!*args[4]) { |
| 1627 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1628 | appctx->st0 = STAT_CLI_PRINT; |
| 1629 | return 1; |
| 1630 | } |
| 1631 | |
| 1632 | v = atoi(args[4]); |
| 1633 | if (v < 0) { |
| 1634 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1635 | appctx->st0 = STAT_CLI_PRINT; |
| 1636 | return 1; |
| 1637 | } |
| 1638 | |
| 1639 | global.sps_lim = v; |
| 1640 | |
| 1641 | /* Dequeues all of the listeners waiting for a resource */ |
| 1642 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1643 | dequeue_all_listeners(&global_listener_queue); |
| 1644 | |
| 1645 | return 1; |
| 1646 | } |
| 1647 | else { |
| 1648 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1649 | appctx->st0 = STAT_CLI_PRINT; |
| 1650 | return 1; |
| 1651 | } |
| 1652 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1653 | #ifdef USE_OPENSSL |
| 1654 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1655 | if (strcmp(args[3], "global") == 0) { |
| 1656 | int v; |
| 1657 | |
| 1658 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1659 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1660 | appctx->st0 = STAT_CLI_PRINT; |
| 1661 | return 1; |
| 1662 | } |
| 1663 | |
| 1664 | if (!*args[4]) { |
| 1665 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1666 | appctx->st0 = STAT_CLI_PRINT; |
| 1667 | return 1; |
| 1668 | } |
| 1669 | |
| 1670 | v = atoi(args[4]); |
| 1671 | if (v < 0) { |
| 1672 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1673 | appctx->st0 = STAT_CLI_PRINT; |
| 1674 | return 1; |
| 1675 | } |
| 1676 | |
| 1677 | global.ssl_lim = v; |
| 1678 | |
| 1679 | /* Dequeues all of the listeners waiting for a resource */ |
| 1680 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1681 | dequeue_all_listeners(&global_listener_queue); |
| 1682 | |
| 1683 | return 1; |
| 1684 | } |
| 1685 | else { |
| 1686 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1687 | appctx->st0 = STAT_CLI_PRINT; |
| 1688 | return 1; |
| 1689 | } |
| 1690 | } |
| 1691 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1692 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1693 | if (strcmp(args[3], "global") == 0) { |
| 1694 | int v; |
| 1695 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1696 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1697 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1698 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1699 | return 1; |
| 1700 | } |
| 1701 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1702 | v = atoi(args[4]); |
| 1703 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1704 | } |
| 1705 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1706 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1707 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1708 | return 1; |
| 1709 | } |
| 1710 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1711 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1712 | appctx->ctx.cli.msg = "'set rate-limit' supports 'connections', 'sessions', 'ssl-sessions', and 'http-compression'.\n"; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1713 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1714 | return 1; |
| 1715 | } |
| 1716 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1717 | else if (strcmp(args[1], "table") == 0) { |
| 1718 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1719 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1720 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1721 | char *err; |
| 1722 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1723 | /* Set flags. */ |
| 1724 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1725 | |
| 1726 | /* Expect three parameters: map name, key and new value. */ |
| 1727 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1728 | appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1729 | appctx->st0 = STAT_CLI_PRINT; |
| 1730 | return 1; |
| 1731 | } |
| 1732 | |
| 1733 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1734 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1735 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1736 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1737 | appctx->st0 = STAT_CLI_PRINT; |
| 1738 | return 1; |
| 1739 | } |
| 1740 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1741 | /* If the entry identifier start with a '#', it is considered as |
| 1742 | * pointer id |
| 1743 | */ |
| 1744 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1745 | struct pat_ref_elt *ref; |
| 1746 | long long int conv; |
| 1747 | char *error; |
| 1748 | |
| 1749 | /* Convert argument to integer value. */ |
| 1750 | conv = strtoll(&args[3][1], &error, 16); |
| 1751 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1752 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1753 | appctx->st0 = STAT_CLI_PRINT; |
| 1754 | return 1; |
| 1755 | } |
| 1756 | |
| 1757 | /* Convert and check integer to pointer. */ |
| 1758 | ref = (struct pat_ref_elt *)(long)conv; |
| 1759 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1760 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1761 | appctx->st0 = STAT_CLI_PRINT; |
| 1762 | return 1; |
| 1763 | } |
| 1764 | |
| 1765 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1766 | err = NULL; |
| 1767 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1768 | if (err) |
| 1769 | memprintf(&err, "%s.\n", err); |
| 1770 | appctx->ctx.cli.err = err; |
| 1771 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1772 | return 1; |
| 1773 | } |
| 1774 | } |
| 1775 | else { |
| 1776 | /* Else, use the entry identifier as pattern |
| 1777 | * string, and update the value. |
| 1778 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1779 | err = NULL; |
| 1780 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1781 | if (err) |
| 1782 | memprintf(&err, "%s.\n", err); |
| 1783 | appctx->ctx.cli.err = err; |
| 1784 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1785 | return 1; |
| 1786 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1787 | } |
| 1788 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1789 | /* The set is done, send message. */ |
| 1790 | appctx->ctx.cli.msg = "Done.\n"; |
| 1791 | appctx->st0 = STAT_CLI_PRINT; |
| 1792 | return 1; |
| 1793 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1794 | #ifdef USE_OPENSSL |
| 1795 | else if (strcmp(args[1], "ssl") == 0) { |
| 1796 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | 656c5fa | 2014-08-18 00:56:31 +0200 | [diff] [blame] | 1797 | #if (defined SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB && !defined OPENSSL_IS_BORINGSSL) |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1798 | char *err = NULL; |
| 1799 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 1800 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1801 | if (!*args[3]) { |
| 1802 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 1803 | appctx->st0 = STAT_CLI_PRINT; |
| 1804 | return 1; |
| 1805 | } |
| 1806 | |
| 1807 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 1808 | if (trash.len < 0) { |
| 1809 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 1810 | appctx->st0 = STAT_CLI_PRINT; |
| 1811 | return 1; |
| 1812 | } |
| 1813 | |
| 1814 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 1815 | if (err) { |
| 1816 | memprintf(&err, "%s.\n", err); |
| 1817 | appctx->ctx.cli.err = err; |
| 1818 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 1819 | } |
| 1820 | return 1; |
| 1821 | } |
| 1822 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 1823 | appctx->st0 = STAT_CLI_PRINT; |
| 1824 | return 1; |
| 1825 | #else |
| 1826 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 1827 | appctx->st0 = STAT_CLI_PRINT; |
| 1828 | return 1; |
| 1829 | #endif |
| 1830 | } |
| 1831 | else { |
| 1832 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 1833 | appctx->st0 = STAT_CLI_PRINT; |
| 1834 | return 1; |
| 1835 | } |
| 1836 | } |
| 1837 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1838 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1839 | return 0; |
| 1840 | } |
| 1841 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1842 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1843 | if (strcmp(args[1], "agent") == 0) { |
| 1844 | struct server *sv; |
| 1845 | |
| 1846 | sv = expect_server_admin(s, si, args[2]); |
| 1847 | if (!sv) |
| 1848 | return 1; |
| 1849 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1850 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1851 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1852 | appctx->st0 = STAT_CLI_PRINT; |
| 1853 | return 1; |
| 1854 | } |
| 1855 | |
| 1856 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1857 | return 1; |
| 1858 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1859 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1860 | struct server *sv; |
| 1861 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1862 | sv = expect_server_admin(s, si, args[2]); |
| 1863 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1864 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1865 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1866 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 1867 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 1868 | appctx->st0 = STAT_CLI_PRINT; |
| 1869 | return 1; |
| 1870 | } |
| 1871 | |
| 1872 | sv->check.state |= CHK_ST_ENABLED; |
| 1873 | return 1; |
| 1874 | } |
| 1875 | else if (strcmp(args[1], "server") == 0) { |
| 1876 | struct server *sv; |
| 1877 | |
| 1878 | sv = expect_server_admin(s, si, args[2]); |
| 1879 | if (!sv) |
| 1880 | return 1; |
| 1881 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1882 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1883 | return 1; |
| 1884 | } |
| 1885 | else if (strcmp(args[1], "frontend") == 0) { |
| 1886 | struct proxy *px; |
| 1887 | |
| 1888 | px = expect_frontend_admin(s, si, args[2]); |
| 1889 | if (!px) |
| 1890 | return 1; |
| 1891 | |
| 1892 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1893 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1894 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1895 | return 1; |
| 1896 | } |
| 1897 | |
| 1898 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1899 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1900 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1901 | return 1; |
| 1902 | } |
| 1903 | |
| 1904 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1905 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1906 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1907 | return 1; |
| 1908 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1909 | return 1; |
| 1910 | } |
| 1911 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1912 | 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] | 1913 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1914 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1915 | } |
| 1916 | } |
| 1917 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1918 | if (strcmp(args[1], "agent") == 0) { |
| 1919 | struct server *sv; |
| 1920 | |
| 1921 | sv = expect_server_admin(s, si, args[2]); |
| 1922 | if (!sv) |
| 1923 | return 1; |
| 1924 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1925 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1926 | return 1; |
| 1927 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1928 | else if (strcmp(args[1], "health") == 0) { |
| 1929 | struct server *sv; |
| 1930 | |
| 1931 | sv = expect_server_admin(s, si, args[2]); |
| 1932 | if (!sv) |
| 1933 | return 1; |
| 1934 | |
| 1935 | sv->check.state &= ~CHK_ST_ENABLED; |
| 1936 | return 1; |
| 1937 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1938 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1939 | struct server *sv; |
| 1940 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1941 | sv = expect_server_admin(s, si, args[2]); |
| 1942 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1943 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1944 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1945 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1946 | return 1; |
| 1947 | } |
| 1948 | else if (strcmp(args[1], "frontend") == 0) { |
| 1949 | struct proxy *px; |
| 1950 | |
| 1951 | px = expect_frontend_admin(s, si, args[2]); |
| 1952 | if (!px) |
| 1953 | return 1; |
| 1954 | |
| 1955 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1956 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1957 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1958 | return 1; |
| 1959 | } |
| 1960 | |
| 1961 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1962 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1963 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1964 | return 1; |
| 1965 | } |
| 1966 | |
| 1967 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1968 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1969 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1970 | return 1; |
| 1971 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1972 | return 1; |
| 1973 | } |
| 1974 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1975 | 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] | 1976 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1977 | return 1; |
| 1978 | } |
| 1979 | } |
| 1980 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1981 | if (strcmp(args[1], "frontend") == 0) { |
| 1982 | struct proxy *px; |
| 1983 | |
| 1984 | px = expect_frontend_admin(s, si, args[2]); |
| 1985 | if (!px) |
| 1986 | return 1; |
| 1987 | |
| 1988 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1989 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1990 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1991 | return 1; |
| 1992 | } |
| 1993 | |
| 1994 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1995 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1996 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1997 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1998 | stop_proxy(px); |
| 1999 | return 1; |
| 2000 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2001 | else if (strcmp(args[1], "session") == 0) { |
| 2002 | struct session *sess, *ptr; |
| 2003 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 2004 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2005 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2006 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2007 | return 1; |
| 2008 | } |
| 2009 | |
| 2010 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2011 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2012 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2013 | return 1; |
| 2014 | } |
| 2015 | |
| 2016 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2017 | |
| 2018 | /* first, look for the requested session in the session table */ |
| 2019 | list_for_each_entry(sess, &sessions, list) { |
| 2020 | if (sess == ptr) |
| 2021 | break; |
| 2022 | } |
| 2023 | |
| 2024 | /* do we have the session ? */ |
| 2025 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2026 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2027 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2028 | return 1; |
| 2029 | } |
| 2030 | |
| 2031 | session_shutdown(sess, SN_ERR_KILLED); |
| 2032 | return 1; |
| 2033 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2034 | else if (strcmp(args[1], "sessions") == 0) { |
| 2035 | if (strcmp(args[2], "server") == 0) { |
| 2036 | struct server *sv; |
| 2037 | struct session *sess, *sess_bck; |
| 2038 | |
| 2039 | sv = expect_server_admin(s, si, args[3]); |
| 2040 | if (!sv) |
| 2041 | return 1; |
| 2042 | |
| 2043 | /* kill all the session that are on this server */ |
| 2044 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2045 | if (sess->srv_conn == sv) |
| 2046 | session_shutdown(sess, SN_ERR_KILLED); |
| 2047 | |
| 2048 | return 1; |
| 2049 | } |
| 2050 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2051 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2052 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2053 | return 1; |
| 2054 | } |
| 2055 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2056 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2057 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2058 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2059 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2060 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2061 | } |
| 2062 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2063 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2064 | if (args[1][0] == 'm') |
| 2065 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2066 | else |
| 2067 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2068 | |
| 2069 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2070 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2071 | if (!*args[2] || !*args[3]) { |
| 2072 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2073 | appctx->st0 = STAT_CLI_PRINT; |
| 2074 | return 1; |
| 2075 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2076 | } |
| 2077 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2078 | else { |
| 2079 | if (!*args[2] || !*args[3]) { |
| 2080 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2081 | appctx->st0 = STAT_CLI_PRINT; |
| 2082 | return 1; |
| 2083 | } |
| 2084 | } |
| 2085 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2086 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2087 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2088 | if (!appctx->ctx.map.ref || |
| 2089 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2090 | 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] | 2091 | appctx->st0 = STAT_CLI_PRINT; |
| 2092 | return 1; |
| 2093 | } |
| 2094 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2095 | /* If the entry identifier start with a '#', it is considered as |
| 2096 | * pointer id |
| 2097 | */ |
| 2098 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2099 | struct pat_ref_elt *ref; |
| 2100 | long long int conv; |
| 2101 | char *error; |
| 2102 | |
| 2103 | /* Convert argument to integer value. */ |
| 2104 | conv = strtoll(&args[3][1], &error, 16); |
| 2105 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2106 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2107 | appctx->st0 = STAT_CLI_PRINT; |
| 2108 | return 1; |
| 2109 | } |
| 2110 | |
| 2111 | /* Convert and check integer to pointer. */ |
| 2112 | ref = (struct pat_ref_elt *)(long)conv; |
| 2113 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2114 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2115 | appctx->st0 = STAT_CLI_PRINT; |
| 2116 | return 1; |
| 2117 | } |
| 2118 | |
| 2119 | /* Try to delete the entry. */ |
| 2120 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2121 | /* The entry is not found, send message. */ |
| 2122 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2123 | appctx->st0 = STAT_CLI_PRINT; |
| 2124 | return 1; |
| 2125 | } |
| 2126 | } |
| 2127 | else { |
| 2128 | /* Else, use the entry identifier as pattern |
| 2129 | * string and try to delete the entry. |
| 2130 | */ |
| 2131 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2132 | /* The entry is not found, send message. */ |
| 2133 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2134 | appctx->st0 = STAT_CLI_PRINT; |
| 2135 | return 1; |
| 2136 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2137 | } |
| 2138 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2139 | /* The deletion is done, send message. */ |
| 2140 | appctx->ctx.cli.msg = "Done.\n"; |
| 2141 | appctx->st0 = STAT_CLI_PRINT; |
| 2142 | return 1; |
| 2143 | } |
| 2144 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2145 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2146 | appctx->st0 = STAT_CLI_PRINT; |
| 2147 | return 1; |
| 2148 | } |
| 2149 | } |
| 2150 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2151 | if (strcmp(args[1], "map") == 0 || |
| 2152 | strcmp(args[1], "acl") == 0) { |
| 2153 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2154 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2155 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2156 | /* Set flags. */ |
| 2157 | if (args[1][0] == 'm') |
| 2158 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2159 | else |
| 2160 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2161 | |
| 2162 | /* If the keywork is "map", we expect three parameters, if it |
| 2163 | * is "acl", we expect only two parameters |
| 2164 | */ |
| 2165 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2166 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2167 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2168 | appctx->st0 = STAT_CLI_PRINT; |
| 2169 | return 1; |
| 2170 | } |
| 2171 | } |
| 2172 | else { |
| 2173 | if (!*args[2] || !*args[3]) { |
| 2174 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2175 | appctx->st0 = STAT_CLI_PRINT; |
| 2176 | return 1; |
| 2177 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2178 | } |
| 2179 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2180 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2181 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2182 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2183 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2184 | 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] | 2185 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2186 | 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] | 2187 | appctx->st0 = STAT_CLI_PRINT; |
| 2188 | return 1; |
| 2189 | } |
| 2190 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2191 | /* The command "add acl" is prohibited if the reference |
| 2192 | * use samples. |
| 2193 | */ |
| 2194 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2195 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2196 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2197 | "You must use the command 'add map' to add values.\n"; |
| 2198 | appctx->st0 = STAT_CLI_PRINT; |
| 2199 | return 1; |
| 2200 | } |
| 2201 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2202 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2203 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2204 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2205 | 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] | 2206 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2207 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2208 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2209 | if (err) |
| 2210 | memprintf(&err, "%s.\n", err); |
| 2211 | appctx->ctx.cli.err = err; |
| 2212 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2213 | return 1; |
| 2214 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2215 | |
| 2216 | /* The add is done, send message. */ |
| 2217 | appctx->ctx.cli.msg = "Done.\n"; |
| 2218 | appctx->st0 = STAT_CLI_PRINT; |
| 2219 | return 1; |
| 2220 | } |
| 2221 | else { /* unknown "del" parameter */ |
| 2222 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2223 | appctx->st0 = STAT_CLI_PRINT; |
| 2224 | return 1; |
| 2225 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2226 | } |
| 2227 | 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] | 2228 | return 0; |
| 2229 | } |
| 2230 | return 1; |
| 2231 | } |
| 2232 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2233 | /* 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] | 2234 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2235 | * state machine handling requests and various responses. We read a request, |
| 2236 | * 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] | 2237 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2238 | * 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] | 2239 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2240 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2241 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2242 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2243 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2244 | struct channel *req = si->ob; |
| 2245 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2246 | int reql; |
| 2247 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2248 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2249 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2250 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2251 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2252 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2253 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2254 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2255 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2256 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2257 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2258 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2259 | /* Let's close for real now. We just close the request |
| 2260 | * side, the conditions below will complete if needed. |
| 2261 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2262 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2263 | break; |
| 2264 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2265 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2266 | /* ensure we have some output room left in the event we |
| 2267 | * would want to return some info right after parsing. |
| 2268 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2269 | if (buffer_almost_full(si->ib->buf)) { |
| 2270 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2271 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2272 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2273 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2274 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2275 | if (reql <= 0) { /* closed or EOL not found */ |
| 2276 | if (reql == 0) |
| 2277 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2278 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2279 | continue; |
| 2280 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2281 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2282 | /* seek for a possible semi-colon. If we find one, we |
| 2283 | * replace it with an LF and skip only this part. |
| 2284 | */ |
| 2285 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2286 | if (trash.str[len] == ';') { |
| 2287 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2288 | reql = len + 1; |
| 2289 | break; |
| 2290 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2291 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2292 | /* now it is time to check that we have a full line, |
| 2293 | * remove the trailing \n and possibly \r, then cut the |
| 2294 | * line. |
| 2295 | */ |
| 2296 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2297 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2298 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2299 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2300 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2301 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2302 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2303 | len--; |
| 2304 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2305 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2306 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2307 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2308 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2309 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2310 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2311 | continue; |
| 2312 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2313 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2314 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2315 | else if (strcmp(trash.str, "help") == 0 || |
| 2316 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2317 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2318 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2319 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2320 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2321 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2322 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2323 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2324 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2325 | /* if prompt is disabled, print help on empty lines, |
| 2326 | * so that the user at least knows how to enable |
| 2327 | * prompt and find help. |
| 2328 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2329 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2330 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2334 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2335 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2336 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2337 | 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] | 2338 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2339 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2340 | continue; |
| 2341 | } |
| 2342 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2343 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2344 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2345 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2346 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2347 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2348 | case STAT_CLI_PRINT_FREE: |
| 2349 | if (bi_putstr(si->ib, appctx->ctx.cli.err) != -1) { |
| 2350 | free(appctx->ctx.cli.err); |
| 2351 | appctx->st0 = STAT_CLI_PROMPT; |
| 2352 | } |
| 2353 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2354 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2355 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2356 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2357 | break; |
| 2358 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2359 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2360 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2361 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2362 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2363 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2364 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2365 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2366 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2367 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2368 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2369 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2370 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2371 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2372 | if (stats_table_request(si, appctx->st0)) |
| 2373 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2374 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2375 | case STAT_CLI_O_PATS: |
| 2376 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2377 | appctx->st0 = STAT_CLI_PROMPT; |
| 2378 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2379 | case STAT_CLI_O_PAT: |
| 2380 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2381 | appctx->st0 = STAT_CLI_PROMPT; |
| 2382 | break; |
| 2383 | case STAT_CLI_O_MLOOK: |
| 2384 | if (stats_map_lookup(si)) |
| 2385 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2386 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2387 | case STAT_CLI_O_POOLS: |
| 2388 | if (stats_dump_pools_to_buffer(si)) |
| 2389 | appctx->st0 = STAT_CLI_PROMPT; |
| 2390 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2391 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2392 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2393 | break; |
| 2394 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2395 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2396 | /* 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] | 2397 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2398 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2399 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2400 | } |
| 2401 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2402 | /* 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] | 2403 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2404 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2405 | |
| 2406 | /* Now we close the output if one of the writers did so, |
| 2407 | * or if we're not in interactive mode and the request |
| 2408 | * buffer is empty. This still allows pipelined requests |
| 2409 | * to be sent in non-interactive mode. |
| 2410 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2411 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2412 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2413 | continue; |
| 2414 | } |
| 2415 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2416 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2417 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2418 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2419 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2420 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2421 | 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] | 2422 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2423 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2424 | /* 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] | 2425 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2426 | * we forward the close to the request side so that it flows upstream to |
| 2427 | * the client. |
| 2428 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2429 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2430 | } |
| 2431 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2432 | 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] | 2433 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2434 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2435 | /* We have no more processing to do, and nothing more to send, and |
| 2436 | * the client side has closed. So we'll forward this state downstream |
| 2437 | * on the response buffer. |
| 2438 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2439 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2440 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2444 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2445 | |
| 2446 | /* we don't want to expire timeouts while we're processing requests */ |
| 2447 | si->ib->rex = TICK_ETERNITY; |
| 2448 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2449 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2450 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2451 | 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] | 2452 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2453 | 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] | 2454 | |
| 2455 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2456 | /* check that we have released everything then unregister */ |
| 2457 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2458 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2459 | } |
| 2460 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2461 | /* This function dumps information onto the stream interface's read buffer. |
| 2462 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2463 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2464 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2465 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2466 | { |
| 2467 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2468 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2469 | #ifdef USE_OPENSSL |
| 2470 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2471 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2472 | int ssl_reuse = 0; |
| 2473 | |
| 2474 | if (ssl_key_rate < ssl_sess_rate) { |
| 2475 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2476 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2477 | } |
| 2478 | #endif |
| 2479 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2480 | chunk_printf(&trash, |
| 2481 | "Name: " PRODUCT_NAME "\n" |
| 2482 | "Version: " HAPROXY_VERSION "\n" |
| 2483 | "Release_date: " HAPROXY_DATE "\n" |
| 2484 | "Nbproc: %d\n" |
| 2485 | "Process_num: %d\n" |
| 2486 | "Pid: %d\n" |
| 2487 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2488 | "Uptime_sec: %d\n" |
| 2489 | "Memmax_MB: %d\n" |
| 2490 | "Ulimit-n: %d\n" |
| 2491 | "Maxsock: %d\n" |
| 2492 | "Maxconn: %d\n" |
| 2493 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2494 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2495 | "CumConns: %d\n" |
| 2496 | "CumReq: %d\n" |
| 2497 | #ifdef USE_OPENSSL |
| 2498 | "MaxSslConns: %d\n" |
| 2499 | "CurrSslConns: %d\n" |
| 2500 | "CumSslConns: %d\n" |
| 2501 | #endif |
| 2502 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2503 | "PipesUsed: %d\n" |
| 2504 | "PipesFree: %d\n" |
| 2505 | "ConnRate: %d\n" |
| 2506 | "ConnRateLimit: %d\n" |
| 2507 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2508 | "SessRate: %d\n" |
| 2509 | "SessRateLimit: %d\n" |
| 2510 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2511 | #ifdef USE_OPENSSL |
| 2512 | "SslRate: %d\n" |
| 2513 | "SslRateLimit: %d\n" |
| 2514 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2515 | "SslFrontendKeyRate: %d\n" |
| 2516 | "SslFrontendMaxKeyRate: %d\n" |
| 2517 | "SslFrontendSessionReuse_pct: %d\n" |
| 2518 | "SslBackendKeyRate: %d\n" |
| 2519 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2520 | "SslCacheLookups: %u\n" |
| 2521 | "SslCacheMisses: %u\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2522 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2523 | "CompressBpsIn: %u\n" |
| 2524 | "CompressBpsOut: %u\n" |
| 2525 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2526 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2527 | "ZlibMemUsage: %ld\n" |
| 2528 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2529 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2530 | "Tasks: %d\n" |
| 2531 | "Run_queue: %d\n" |
| 2532 | "Idle_pct: %d\n" |
| 2533 | "node: %s\n" |
| 2534 | "description: %s\n" |
| 2535 | "", |
| 2536 | global.nbproc, |
| 2537 | relative_pid, |
| 2538 | pid, |
| 2539 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2540 | up, |
| 2541 | global.rlimit_memmax, |
| 2542 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2543 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2544 | actconn, totalconn, global.req_count, |
| 2545 | #ifdef USE_OPENSSL |
| 2546 | global.maxsslconn, sslconns, totalsslconns, |
| 2547 | #endif |
| 2548 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2549 | 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] | 2550 | 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] | 2551 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2552 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2553 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2554 | ssl_reuse, |
| 2555 | read_freq_ctr(&global.ssl_be_keys_per_sec), global.ssl_be_keys_max, |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2556 | global.shctx_lookups, global.shctx_misses, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2557 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2558 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2559 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2560 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2561 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2562 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2563 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2564 | global.node, global.desc ? global.desc : "" |
| 2565 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2566 | |
| 2567 | if (bi_putchk(si->ib, &trash) == -1) |
| 2568 | return 0; |
| 2569 | |
| 2570 | return 1; |
| 2571 | } |
| 2572 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2573 | /* This function dumps memory usage information onto the stream interface's |
| 2574 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2575 | * completion. No state is used. |
| 2576 | */ |
| 2577 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2578 | { |
| 2579 | dump_pools_to_trash(); |
| 2580 | if (bi_putchk(si->ib, &trash) == -1) |
| 2581 | return 0; |
| 2582 | return 1; |
| 2583 | } |
| 2584 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2585 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2586 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2587 | * 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] | 2588 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2589 | 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] | 2590 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2591 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2592 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2593 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2594 | if (!(px->cap & PR_CAP_FE)) |
| 2595 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2596 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2597 | 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] | 2598 | return 0; |
| 2599 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2600 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2601 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2602 | /* name, queue */ |
| 2603 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2604 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2605 | 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] | 2606 | /* Column sub-heading for Enable or Disable server */ |
| 2607 | chunk_appendf(&trash, "<td></td>"); |
| 2608 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2609 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2610 | chunk_appendf(&trash, |
| 2611 | "<td class=ac>" |
| 2612 | "<a name=\"%s/Frontend\"></a>" |
| 2613 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2614 | "<td colspan=3></td>" |
| 2615 | "", |
| 2616 | px->id, px->id); |
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 | chunk_appendf(&trash, |
| 2619 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2620 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2621 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2622 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2623 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2624 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2625 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2626 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2627 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2628 | if (px->mode == PR_MODE_HTTP) |
| 2629 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2630 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2631 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2632 | |
| 2633 | chunk_appendf(&trash, |
| 2634 | "</table></div></u></td>" |
| 2635 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2636 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2637 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2638 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2639 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2640 | U2H(px->fe_counters.sps_max), |
| 2641 | U2H(px->fe_counters.cps_max), |
| 2642 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2643 | |
| 2644 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2645 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2646 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2647 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2648 | |
| 2649 | chunk_appendf(&trash, |
| 2650 | "</table></div></u></td>" |
| 2651 | /* sessions rate : limit */ |
| 2652 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2653 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2654 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2655 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2656 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2657 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2658 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2659 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2660 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2661 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2662 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2663 | U2H(px->fe_counters.cum_sess), |
| 2664 | U2H(px->fe_counters.cum_conn), |
| 2665 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2666 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2667 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2668 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2669 | chunk_appendf(&trash, |
| 2670 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2671 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2672 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2673 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2674 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2675 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2676 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2677 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2678 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2679 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2680 | U2H(px->fe_counters.p.http.cum_req), |
| 2681 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2682 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2683 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2684 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2685 | (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] | 2686 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2687 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2688 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2689 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2690 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2691 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2692 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2693 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2694 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2695 | /* sessions: lbtot, lastsess */ |
| 2696 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2697 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2698 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2699 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2700 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2701 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2702 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2703 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2704 | "<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] | 2705 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2706 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2707 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2708 | px->fe_counters.comp_in ? |
| 2709 | (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] | 2710 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2711 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2712 | chunk_appendf(&trash, |
| 2713 | /* denied: req, resp */ |
| 2714 | "<td>%s</td><td>%s</td>" |
| 2715 | /* errors : request, connect, response */ |
| 2716 | "<td>%s</td><td></td><td></td>" |
| 2717 | /* warnings: retries, redispatches */ |
| 2718 | "<td></td><td></td>" |
| 2719 | /* server status : reflect frontend status */ |
| 2720 | "<td class=ac>%s</td>" |
| 2721 | /* rest of server: nothing */ |
| 2722 | "<td class=ac colspan=8></td></tr>" |
| 2723 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2724 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2725 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2726 | px->state == PR_STREADY ? "OPEN" : |
| 2727 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2728 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2729 | else { /* CSV mode */ |
| 2730 | chunk_appendf(&trash, |
| 2731 | /* pxid, name, queue cur, queue max, */ |
| 2732 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2733 | /* sessions : current, max, limit, total */ |
| 2734 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2735 | /* bytes : in, out */ |
| 2736 | "%lld,%lld," |
| 2737 | /* denied: req, resp */ |
| 2738 | "%lld,%lld," |
| 2739 | /* errors : request, connect, response */ |
| 2740 | "%lld,,," |
| 2741 | /* warnings: retries, redispatches */ |
| 2742 | ",," |
| 2743 | /* server status : reflect frontend status */ |
| 2744 | "%s," |
| 2745 | /* rest of server: nothing */ |
| 2746 | ",,,,,,,," |
| 2747 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2748 | "%d,%d,0,,,,%d," |
| 2749 | /* rate, rate_lim, rate_max */ |
| 2750 | "%u,%u,%u," |
| 2751 | /* check_status, check_code, check_duration */ |
| 2752 | ",,,", |
| 2753 | px->id, |
| 2754 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2755 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2756 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2757 | px->fe_counters.failed_req, |
| 2758 | px->state == PR_STREADY ? "OPEN" : |
| 2759 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2760 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2761 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2762 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2763 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2764 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2765 | if (px->mode == PR_MODE_HTTP) { |
| 2766 | for (i=1; i<6; i++) |
| 2767 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2768 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2769 | } |
| 2770 | else |
| 2771 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2772 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2773 | /* failed health analyses */ |
| 2774 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2775 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2776 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2777 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2778 | read_freq_ctr(&px->fe_req_per_sec), |
| 2779 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2780 | |
| 2781 | /* errors: cli_aborts, srv_aborts */ |
| 2782 | chunk_appendf(&trash, ",,"); |
| 2783 | |
| 2784 | /* compression: in, out, bypassed */ |
| 2785 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2786 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2787 | |
| 2788 | /* compression: comp_rsp */ |
| 2789 | chunk_appendf(&trash, "%lld,", |
| 2790 | px->fe_counters.p.http.comp_rsp); |
| 2791 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2792 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2793 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2794 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2795 | /* finish with EOL */ |
| 2796 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2797 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2798 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2799 | } |
| 2800 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2801 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2802 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2803 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2804 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2805 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2806 | 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] | 2807 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2808 | struct appctx *appctx = __objt_appctx(si->end); |
| 2809 | |
| 2810 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2811 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2812 | 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] | 2813 | /* Column sub-heading for Enable or Disable server */ |
| 2814 | chunk_appendf(&trash, "<td></td>"); |
| 2815 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2816 | chunk_appendf(&trash, |
| 2817 | /* frontend name, listener name */ |
| 2818 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2819 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2820 | "", |
| 2821 | px->id, l->name, |
| 2822 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2823 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2824 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2825 | if (flags & ST_SHLGNDS) { |
| 2826 | char str[INET6_ADDRSTRLEN]; |
| 2827 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2828 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2829 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2830 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2831 | port = get_host_port(&l->addr); |
| 2832 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2833 | case AF_INET: |
| 2834 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2835 | break; |
| 2836 | case AF_INET6: |
| 2837 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2838 | break; |
| 2839 | case AF_UNIX: |
| 2840 | chunk_appendf(&trash, "unix, "); |
| 2841 | break; |
| 2842 | case -1: |
| 2843 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2844 | break; |
| 2845 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2846 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2847 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2848 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2849 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2850 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2851 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2852 | /* queue */ |
| 2853 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2854 | /* sessions rate: current, max, limit */ |
| 2855 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2856 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2857 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2858 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2859 | /* bytes: in, out */ |
| 2860 | "<td>%s</td><td>%s</td>" |
| 2861 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2862 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2863 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2864 | 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] | 2865 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2866 | chunk_appendf(&trash, |
| 2867 | /* denied: req, resp */ |
| 2868 | "<td>%s</td><td>%s</td>" |
| 2869 | /* errors: request, connect, response */ |
| 2870 | "<td>%s</td><td></td><td></td>" |
| 2871 | /* warnings: retries, redispatches */ |
| 2872 | "<td></td><td></td>" |
| 2873 | /* server status: reflect listener status */ |
| 2874 | "<td class=ac>%s</td>" |
| 2875 | /* rest of server: nothing */ |
| 2876 | "<td class=ac colspan=8></td></tr>" |
| 2877 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2878 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2879 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2880 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2881 | } |
| 2882 | else { /* CSV mode */ |
| 2883 | chunk_appendf(&trash, |
| 2884 | /* pxid, name, queue cur, queue max, */ |
| 2885 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2886 | /* sessions: current, max, limit, total */ |
| 2887 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2888 | /* bytes: in, out */ |
| 2889 | "%lld,%lld," |
| 2890 | /* denied: req, resp */ |
| 2891 | "%lld,%lld," |
| 2892 | /* errors: request, connect, response */ |
| 2893 | "%lld,,," |
| 2894 | /* warnings: retries, redispatches */ |
| 2895 | ",," |
| 2896 | /* server status: reflect listener status */ |
| 2897 | "%s," |
| 2898 | /* rest of server: nothing */ |
| 2899 | ",,,,,,,," |
| 2900 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2901 | "%d,%d,%d,,,,%d," |
| 2902 | /* rate, rate_lim, rate_max */ |
| 2903 | ",,," |
| 2904 | /* check_status, check_code, check_duration */ |
| 2905 | ",,," |
| 2906 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2907 | ",,,,,," |
| 2908 | /* failed health analyses */ |
| 2909 | "," |
| 2910 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2911 | ",,," |
| 2912 | /* errors: cli_aborts, srv_aborts */ |
| 2913 | ",," |
| 2914 | /* compression: in, out, bypassed, comp_rsp */ |
| 2915 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2916 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2917 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2918 | "\n", |
| 2919 | px->id, l->name, |
| 2920 | l->nbconn, l->counters->conn_max, |
| 2921 | l->maxconn, l->counters->cum_conn, |
| 2922 | l->counters->bytes_in, l->counters->bytes_out, |
| 2923 | l->counters->denied_req, l->counters->denied_resp, |
| 2924 | l->counters->failed_req, |
| 2925 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2926 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2927 | } |
| 2928 | return 1; |
| 2929 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2930 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2931 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2932 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2933 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2934 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2935 | * following values : 0=DOWN, 1=DOWN(agent) 2=going up, 3=going down, 4=UP, 5,6=NOLB, |
| 2936 | * 7,8=DRAIN, 9=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2937 | */ |
| 2938 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2939 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2940 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2941 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2942 | char str[INET6_ADDRSTRLEN]; |
| 2943 | struct chunk src; |
| 2944 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2945 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2946 | /* we have "via" which is the tracked server as described in the configuration, |
| 2947 | * and "ref" which is the checked server and the end of the chain. |
| 2948 | */ |
| 2949 | via = sv->track ? sv->track : sv; |
| 2950 | ref = via; |
| 2951 | while (ref->track) |
| 2952 | ref = ref->track; |
| 2953 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2954 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2955 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2956 | "DOWN", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2957 | "DOWN (agent)", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2958 | "DN %d/%d ↑", |
| 2959 | "UP %d/%d ↓", |
| 2960 | "UP", |
| 2961 | "NOLB %d/%d ↓", |
| 2962 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2963 | "DRAIN %d/%d ↓", |
| 2964 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2965 | "<i>no check</i>" |
| 2966 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2967 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 2968 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2969 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2970 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2971 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2972 | "<tr class=\"%s%d\">", |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 2973 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2974 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2975 | 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] | 2976 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2977 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2978 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2979 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2980 | chunk_appendf(&trash, |
| 2981 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2982 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2983 | "", |
| 2984 | px->id, sv->id, |
| 2985 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2986 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2987 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2988 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2989 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2990 | |
| 2991 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2992 | case AF_INET: |
| 2993 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2994 | break; |
| 2995 | case AF_INET6: |
| 2996 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2997 | break; |
| 2998 | case AF_UNIX: |
| 2999 | chunk_appendf(&trash, "unix, "); |
| 3000 | break; |
| 3001 | case -1: |
| 3002 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3003 | break; |
| 3004 | default: /* address family not supported */ |
| 3005 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3006 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3007 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3008 | /* id */ |
| 3009 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3010 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3011 | /* cookie */ |
| 3012 | if (sv->cookie) { |
| 3013 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3014 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3015 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3016 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3017 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3018 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3019 | } |
| 3020 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3021 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3022 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3023 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3024 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3025 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3026 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3027 | /* sessions rate : current, max, limit */ |
| 3028 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3029 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3030 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3031 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3032 | 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] | 3033 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3034 | |
| 3035 | chunk_appendf(&trash, |
| 3036 | /* sessions: current, max, limit, total */ |
| 3037 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3038 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3039 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3040 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3041 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3042 | U2H(sv->counters.cum_sess), |
| 3043 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3044 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3045 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3046 | if (px->mode == PR_MODE_HTTP) { |
| 3047 | unsigned long long tot; |
| 3048 | for (tot = i = 0; i < 6; i++) |
| 3049 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3050 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3051 | chunk_appendf(&trash, |
| 3052 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3053 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3054 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3055 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3056 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3057 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3058 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3059 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3060 | U2H(tot), |
| 3061 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3062 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3063 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3064 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3065 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3066 | 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] | 3067 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3068 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3069 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3070 | chunk_appendf(&trash, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES))); |
| 3071 | chunk_appendf(&trash, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES))); |
| 3072 | if (px->mode == PR_MODE_HTTP) |
| 3073 | chunk_appendf(&trash, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES))); |
| 3074 | chunk_appendf(&trash, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES))); |
| 3075 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3076 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3077 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3078 | /* sessions: lbtot, last */ |
| 3079 | "<td>%s</td><td>%s</td>", |
| 3080 | U2H(sv->counters.cum_lbconn), |
| 3081 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3082 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3083 | chunk_appendf(&trash, |
| 3084 | /* bytes : in, out */ |
| 3085 | "<td>%s</td><td>%s</td>" |
| 3086 | /* denied: req, resp */ |
| 3087 | "<td></td><td>%s</td>" |
| 3088 | /* errors : request, connect */ |
| 3089 | "<td></td><td>%s</td>" |
| 3090 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3091 | "<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] | 3092 | /* warnings: retries, redispatches */ |
| 3093 | "<td>%lld</td><td>%lld</td>" |
| 3094 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3095 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3096 | U2H(sv->counters.failed_secu), |
| 3097 | U2H(sv->counters.failed_conns), |
| 3098 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3099 | sv->counters.cli_aborts, |
| 3100 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3101 | sv->counters.retries, sv->counters.redispatches); |
| 3102 | |
| 3103 | /* status, lest check */ |
| 3104 | chunk_appendf(&trash, "<td class=ac>"); |
| 3105 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3106 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3107 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3108 | chunk_appendf(&trash, "MAINT"); |
| 3109 | } |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3110 | else if ((ref->agent.state & CHK_ST_ENABLED) && (ref->state == SRV_ST_STOPPED)) { |
| 3111 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
Willy Tarreau | ac49707 | 2014-05-29 01:04:35 +0200 | [diff] [blame] | 3112 | /* DOWN (agent) */ |
| 3113 | chunk_appendf(&trash, srv_hlt_st[1], "GCC: your -Werror=format-security is bogus, annoying, and hides real bugs, I don't thank you, really!"); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3114 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3115 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3116 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3117 | chunk_appendf(&trash, |
| 3118 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3119 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3120 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3121 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3122 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3123 | if ((sv->state == SRV_ST_STOPPED) && |
| 3124 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3125 | chunk_appendf(&trash, |
| 3126 | "</td><td class=ac><u> %s%s", |
| 3127 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3128 | get_check_status_info(sv->agent.status)); |
| 3129 | |
| 3130 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3131 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3132 | |
| 3133 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3134 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3135 | |
| 3136 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3137 | get_check_status_description(sv->agent.status)); |
| 3138 | if (*sv->agent.desc) { |
| 3139 | chunk_appendf(&trash, ": "); |
| 3140 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3141 | chunk_htmlencode(&trash, &src); |
| 3142 | } |
| 3143 | chunk_appendf(&trash, "</div></u>"); |
| 3144 | } |
| 3145 | 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] | 3146 | chunk_appendf(&trash, |
| 3147 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3148 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3149 | get_check_status_info(sv->check.status)); |
| 3150 | |
| 3151 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3152 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3153 | |
| 3154 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3155 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3156 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3157 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3158 | get_check_status_description(sv->check.status)); |
| 3159 | if (*sv->check.desc) { |
| 3160 | chunk_appendf(&trash, ": "); |
| 3161 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3162 | chunk_htmlencode(&trash, &src); |
| 3163 | } |
| 3164 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3165 | } |
| 3166 | else |
| 3167 | chunk_appendf(&trash, "</td><td>"); |
| 3168 | |
| 3169 | chunk_appendf(&trash, |
| 3170 | /* weight */ |
| 3171 | "</td><td class=ac>%d</td>" |
| 3172 | /* act, bck */ |
| 3173 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3174 | "", |
| 3175 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3176 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3177 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3178 | |
| 3179 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3180 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3181 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3182 | |
| 3183 | if (ref->observe) |
| 3184 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3185 | |
| 3186 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3187 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3188 | "<td>%lld</td><td>%s</td>" |
| 3189 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3190 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3191 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3192 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3193 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3194 | /* tracking a server */ |
| 3195 | chunk_appendf(&trash, |
| 3196 | "<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] | 3197 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3198 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3199 | else |
| 3200 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3201 | |
| 3202 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3203 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3204 | 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] | 3205 | else |
| 3206 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3207 | } |
| 3208 | else { /* CSV mode */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3209 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3210 | "DOWN,", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3211 | "DOWN (agent),", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3212 | "DOWN %d/%d,", |
| 3213 | "UP %d/%d,", |
| 3214 | "UP,", |
| 3215 | "NOLB %d/%d,", |
| 3216 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3217 | "DRAIN %d/%d,", |
| 3218 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3219 | "no check," |
| 3220 | }; |
| 3221 | |
| 3222 | chunk_appendf(&trash, |
| 3223 | /* pxid, name */ |
| 3224 | "%s,%s," |
| 3225 | /* queue : current, max */ |
| 3226 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3227 | /* sessions : current, max, limit, total */ |
| 3228 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3229 | /* bytes : in, out */ |
| 3230 | "%lld,%lld," |
| 3231 | /* denied: req, resp */ |
| 3232 | ",%lld," |
| 3233 | /* errors : request, connect, response */ |
| 3234 | ",%lld,%lld," |
| 3235 | /* warnings: retries, redispatches */ |
| 3236 | "%lld,%lld," |
| 3237 | "", |
| 3238 | px->id, sv->id, |
| 3239 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3240 | 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] | 3241 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3242 | sv->counters.failed_secu, |
| 3243 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3244 | sv->counters.retries, sv->counters.redispatches); |
| 3245 | |
| 3246 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3247 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3248 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3249 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3250 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3251 | else |
| 3252 | chunk_appendf(&trash, |
| 3253 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3254 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3255 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3256 | |
| 3257 | chunk_appendf(&trash, |
| 3258 | /* weight, active, backup */ |
| 3259 | "%d,%d,%d," |
| 3260 | "", |
| 3261 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3262 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3263 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3264 | |
| 3265 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3266 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3267 | chunk_appendf(&trash, |
| 3268 | "%lld,%lld,%d,%d,", |
| 3269 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3270 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3271 | else |
| 3272 | chunk_appendf(&trash, ",,,,"); |
| 3273 | |
| 3274 | /* queue limit, pid, iid, sid, */ |
| 3275 | chunk_appendf(&trash, |
| 3276 | "%s," |
| 3277 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3278 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3279 | relative_pid, px->uuid, sv->puid); |
| 3280 | |
| 3281 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3282 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3283 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3284 | |
| 3285 | /* sessions: lbtot */ |
| 3286 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3287 | |
| 3288 | /* tracked */ |
| 3289 | if (sv->track) |
| 3290 | chunk_appendf(&trash, "%s/%s,", |
| 3291 | sv->track->proxy->id, sv->track->id); |
| 3292 | else |
| 3293 | chunk_appendf(&trash, ","); |
| 3294 | |
| 3295 | /* type */ |
| 3296 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3297 | |
| 3298 | /* rate */ |
| 3299 | chunk_appendf(&trash, "%u,,%u,", |
| 3300 | read_freq_ctr(&sv->sess_per_sec), |
| 3301 | sv->counters.sps_max); |
| 3302 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3303 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3304 | /* check_status */ |
| 3305 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3306 | |
| 3307 | /* check_code */ |
| 3308 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3309 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3310 | else |
| 3311 | chunk_appendf(&trash, ","); |
| 3312 | |
| 3313 | /* check_duration */ |
| 3314 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3315 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3316 | else |
| 3317 | chunk_appendf(&trash, ","); |
| 3318 | |
| 3319 | } |
| 3320 | else |
| 3321 | chunk_appendf(&trash, ",,,"); |
| 3322 | |
| 3323 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3324 | if (px->mode == PR_MODE_HTTP) { |
| 3325 | for (i=1; i<6; i++) |
| 3326 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3327 | |
| 3328 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3329 | } |
| 3330 | else |
| 3331 | chunk_appendf(&trash, ",,,,,,"); |
| 3332 | |
| 3333 | /* failed health analyses */ |
| 3334 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3335 | |
| 3336 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3337 | chunk_appendf(&trash, ",,,"); |
| 3338 | |
| 3339 | /* errors: cli_aborts, srv_aborts */ |
| 3340 | chunk_appendf(&trash, "%lld,%lld,", |
| 3341 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3342 | |
| 3343 | /* compression: in, out, bypassed, comp_rsp */ |
| 3344 | chunk_appendf(&trash, ",,,,"); |
| 3345 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3346 | /* lastsess */ |
| 3347 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3348 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3349 | /* capture of last check and agent statuses */ |
| 3350 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->check.desc) : ""); |
| 3351 | chunk_appendf(&trash, "%s,", ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->agent.desc) : ""); |
| 3352 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3353 | /* qtime, ctime, rtime, ttime, */ |
| 3354 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3355 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3356 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3357 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3358 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3359 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3360 | /* finish with EOL */ |
| 3361 | chunk_appendf(&trash, "\n"); |
| 3362 | } |
| 3363 | return 1; |
| 3364 | } |
| 3365 | |
| 3366 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3367 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3368 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3369 | */ |
| 3370 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3371 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3372 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3373 | struct chunk src; |
| 3374 | int i; |
| 3375 | |
| 3376 | if (!(px->cap & PR_CAP_BE)) |
| 3377 | return 0; |
| 3378 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3379 | 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] | 3380 | return 0; |
| 3381 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3382 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3383 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3384 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3385 | /* Column sub-heading for Enable or Disable server */ |
| 3386 | chunk_appendf(&trash, "<td></td>"); |
| 3387 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3388 | chunk_appendf(&trash, |
| 3389 | "<td class=ac>" |
| 3390 | /* name */ |
| 3391 | "%s<a name=\"%s/Backend\"></a>" |
| 3392 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3393 | "", |
| 3394 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3395 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3396 | |
| 3397 | if (flags & ST_SHLGNDS) { |
| 3398 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3399 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3400 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3401 | |
| 3402 | /* cookie */ |
| 3403 | if (px->cookie_name) { |
| 3404 | chunk_appendf(&trash, ", cookie: '"); |
| 3405 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3406 | chunk_htmlencode(&trash, &src); |
| 3407 | chunk_appendf(&trash, "'"); |
| 3408 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3409 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3413 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3414 | /* queue : current, max */ |
| 3415 | "<td>%s</td><td>%s</td><td></td>" |
| 3416 | /* sessions rate : current, max, limit */ |
| 3417 | "<td>%s</td><td>%s</td><td></td>" |
| 3418 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3419 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3420 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3421 | 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] | 3422 | |
| 3423 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3424 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3425 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3426 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3427 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3428 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3429 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3430 | U2H(px->be_counters.cum_conn), |
| 3431 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3432 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3433 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3434 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3435 | chunk_appendf(&trash, |
| 3436 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3437 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3438 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3439 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3440 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3441 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3442 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3443 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3444 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3445 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3446 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3447 | U2H(px->be_counters.p.http.cum_req), |
| 3448 | U2H(px->be_counters.p.http.rsp[1]), |
| 3449 | U2H(px->be_counters.p.http.rsp[2]), |
| 3450 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3451 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3452 | (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] | 3453 | U2H(px->be_counters.p.http.rsp[3]), |
| 3454 | U2H(px->be_counters.p.http.rsp[4]), |
| 3455 | U2H(px->be_counters.p.http.rsp[5]), |
| 3456 | U2H(px->be_counters.p.http.rsp[0]), |
| 3457 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3458 | } |
| 3459 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3460 | chunk_appendf(&trash, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES))); |
| 3461 | chunk_appendf(&trash, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES))); |
| 3462 | if (px->mode == PR_MODE_HTTP) |
| 3463 | chunk_appendf(&trash, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES))); |
| 3464 | chunk_appendf(&trash, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES))); |
| 3465 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3466 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3467 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3468 | /* sessions: lbtot, last */ |
| 3469 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3470 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3471 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3472 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3473 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3474 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3475 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3476 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3477 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3478 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3479 | "<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] | 3480 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3481 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3482 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3483 | px->be_counters.comp_in ? |
| 3484 | (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] | 3485 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3486 | |
| 3487 | chunk_appendf(&trash, |
| 3488 | /* denied: req, resp */ |
| 3489 | "<td>%s</td><td>%s</td>" |
| 3490 | /* errors : request, connect */ |
| 3491 | "<td></td><td>%s</td>" |
| 3492 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3493 | "<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] | 3494 | /* warnings: retries, redispatches */ |
| 3495 | "<td>%lld</td><td>%lld</td>" |
| 3496 | /* backend status: reflect backend status (up/down): we display UP |
| 3497 | * if the backend has known working servers or if it has no server at |
| 3498 | * all (eg: for stats). Then we display the total weight, number of |
| 3499 | * active and backups. */ |
| 3500 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3501 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3502 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3503 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3504 | U2H(px->be_counters.failed_conns), |
| 3505 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3506 | px->be_counters.cli_aborts, |
| 3507 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3508 | px->be_counters.retries, px->be_counters.redispatches, |
| 3509 | human_time(now.tv_sec - px->last_change, 1), |
| 3510 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3511 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3512 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3513 | px->srv_act, px->srv_bck); |
| 3514 | |
| 3515 | chunk_appendf(&trash, |
| 3516 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3517 | "<td class=ac> </td><td>%d</td>" |
| 3518 | "<td>%s</td>" |
| 3519 | "<td></td>" |
| 3520 | "</tr>", |
| 3521 | px->down_trans, |
| 3522 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3523 | } |
| 3524 | else { /* CSV mode */ |
| 3525 | chunk_appendf(&trash, |
| 3526 | /* pxid, name */ |
| 3527 | "%s,BACKEND," |
| 3528 | /* queue : current, max */ |
| 3529 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3530 | /* sessions : current, max, limit, total */ |
| 3531 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3532 | /* bytes : in, out */ |
| 3533 | "%lld,%lld," |
| 3534 | /* denied: req, resp */ |
| 3535 | "%lld,%lld," |
| 3536 | /* errors : request, connect, response */ |
| 3537 | ",%lld,%lld," |
| 3538 | /* warnings: retries, redispatches */ |
| 3539 | "%lld,%lld," |
| 3540 | /* backend status: reflect backend status (up/down): we display UP |
| 3541 | * if the backend has known working servers or if it has no server at |
| 3542 | * all (eg: for stats). Then we display the total weight, number of |
| 3543 | * active and backups. */ |
| 3544 | "%s," |
| 3545 | "%d,%d,%d," |
| 3546 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3547 | ",%d,%d,%d,," |
| 3548 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3549 | "%d,%d,0,,%lld,,%d," |
| 3550 | /* rate, rate_lim, rate_max, */ |
| 3551 | "%u,,%u," |
| 3552 | /* check_status, check_code, check_duration */ |
| 3553 | ",,,", |
| 3554 | px->id, |
| 3555 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3556 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3557 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3558 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3559 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3560 | px->be_counters.retries, px->be_counters.redispatches, |
| 3561 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3562 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3563 | px->srv_act, px->srv_bck, |
| 3564 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3565 | px->srv?be_downtime(px):0, |
| 3566 | relative_pid, px->uuid, |
| 3567 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3568 | read_freq_ctr(&px->be_sess_per_sec), |
| 3569 | px->be_counters.sps_max); |
| 3570 | |
| 3571 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3572 | if (px->mode == PR_MODE_HTTP) { |
| 3573 | for (i=1; i<6; i++) |
| 3574 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3575 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3576 | } |
| 3577 | else |
| 3578 | chunk_appendf(&trash, ",,,,,,"); |
| 3579 | |
| 3580 | /* failed health analyses */ |
| 3581 | chunk_appendf(&trash, ","); |
| 3582 | |
| 3583 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3584 | chunk_appendf(&trash, ",,,"); |
| 3585 | |
| 3586 | /* errors: cli_aborts, srv_aborts */ |
| 3587 | chunk_appendf(&trash, "%lld,%lld,", |
| 3588 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3589 | |
| 3590 | /* compression: in, out, bypassed */ |
| 3591 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3592 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3593 | |
| 3594 | /* compression: comp_rsp */ |
| 3595 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3596 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3597 | /* lastsess, last_chk, last_agt, */ |
| 3598 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3599 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3600 | /* qtime, ctime, rtime, ttime, */ |
| 3601 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3602 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 3603 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 3604 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 3605 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 3606 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3607 | /* finish with EOL */ |
| 3608 | chunk_appendf(&trash, "\n"); |
| 3609 | } |
| 3610 | return 1; |
| 3611 | } |
| 3612 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3613 | /* 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] | 3614 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3615 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3616 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3617 | 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] | 3618 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3619 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3620 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3621 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3622 | 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] | 3623 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3624 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3625 | /* 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] | 3626 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3627 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3628 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3629 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3630 | 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] | 3631 | } |
| 3632 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3633 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3634 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3635 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3636 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3637 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3638 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | /* print a new table */ |
| 3642 | chunk_appendf(&trash, |
| 3643 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3644 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3645 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3646 | |
| 3647 | chunk_appendf(&trash, |
| 3648 | "<a name=\"%s\"></a>%s" |
| 3649 | "<a class=px href=\"#%s\">%s</a>", |
| 3650 | px->id, |
| 3651 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3652 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3653 | |
| 3654 | if (uri->flags & ST_SHLGNDS) { |
| 3655 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3656 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3657 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3658 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3659 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3663 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3664 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3665 | "</tr>\n" |
| 3666 | "</table>\n" |
| 3667 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3668 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3669 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3670 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3671 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3672 | 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] | 3673 | /* Column heading for Enable or Disable server */ |
| 3674 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3675 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3676 | |
| 3677 | chunk_appendf(&trash, |
| 3678 | "<th rowspan=2></th>" |
| 3679 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3680 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3681 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3682 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3683 | "<th colspan=9>Server</th>" |
| 3684 | "</tr>\n" |
| 3685 | "<tr class=\"titre\">" |
| 3686 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3687 | "<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] | 3688 | "<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] | 3689 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3690 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3691 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3692 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3693 | "<th>Thrtle</th>\n" |
| 3694 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3695 | } |
| 3696 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3697 | /* 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] | 3698 | * 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] | 3699 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3700 | 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] | 3701 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3702 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3703 | chunk_appendf(&trash, "</table>"); |
| 3704 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3705 | 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] | 3706 | /* close the form used to enable/disable this proxy servers */ |
| 3707 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3708 | "Choose the action to perform on the checked servers : " |
| 3709 | "<select name=action>" |
| 3710 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 3711 | "<option value=\"ready\">Set state to READY</option>" |
| 3712 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 3713 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 3714 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3715 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3716 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3717 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3718 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3719 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3720 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3721 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3722 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3723 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3724 | "</select>" |
| 3725 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3726 | " <input type=\"submit\" value=\"Apply\">" |
| 3727 | "</form>", |
| 3728 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3732 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3733 | |
| 3734 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3735 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3736 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3737 | * buffer space, or non-zero if everything completed. This function is used |
| 3738 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3739 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3740 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3741 | 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] | 3742 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3743 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3744 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3745 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3746 | 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] | 3747 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3748 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3749 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3750 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3751 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3752 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3753 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3754 | if (uri && uri->scope) { |
| 3755 | /* we have a limited scope, we have to check the proxy name */ |
| 3756 | struct stat_scope *scope; |
| 3757 | int len; |
| 3758 | |
| 3759 | len = strlen(px->id); |
| 3760 | scope = uri->scope; |
| 3761 | |
| 3762 | while (scope) { |
| 3763 | /* match exact proxy name */ |
| 3764 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3765 | break; |
| 3766 | |
| 3767 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3768 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3769 | break; |
| 3770 | scope = scope->next; |
| 3771 | } |
| 3772 | |
| 3773 | /* proxy name not found : don't dump anything */ |
| 3774 | if (scope == NULL) |
| 3775 | return 1; |
| 3776 | } |
| 3777 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3778 | /* if the user has requested a limited output and the proxy |
| 3779 | * name does not match, skip it. |
| 3780 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3781 | if (appctx->ctx.stats.scope_len && |
| 3782 | 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] | 3783 | return 1; |
| 3784 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3785 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3786 | (appctx->ctx.stats.iid != -1) && |
| 3787 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3788 | return 1; |
| 3789 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3790 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3791 | /* fall through */ |
| 3792 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3793 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3794 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3795 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3796 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3797 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3798 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3799 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3800 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3801 | /* fall through */ |
| 3802 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3803 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3804 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3805 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3806 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3807 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3808 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3809 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3810 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3811 | /* fall through */ |
| 3812 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3813 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3814 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3815 | 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] | 3816 | if (buffer_almost_full(rep->buf)) { |
| 3817 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3818 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3819 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3820 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3821 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3822 | if (!l->counters) |
| 3823 | continue; |
| 3824 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3825 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3826 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3827 | break; |
| 3828 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3829 | 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] | 3830 | continue; |
| 3831 | } |
| 3832 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3833 | /* print the frontend */ |
| 3834 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3835 | if (bi_putchk(rep, &trash) == -1) |
| 3836 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3837 | } |
| 3838 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3839 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3840 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3841 | /* fall through */ |
| 3842 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3843 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3844 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3845 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3846 | int sv_state; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3847 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3848 | if (buffer_almost_full(rep->buf)) { |
| 3849 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3850 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3851 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3852 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3853 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3854 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3855 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3856 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3857 | break; |
| 3858 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3859 | 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] | 3860 | continue; |
| 3861 | } |
| 3862 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3863 | svs = sv; |
| 3864 | while (svs->track) |
| 3865 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3866 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3867 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 3868 | /* server is UP. The possibilities are : |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3869 | * - UP, draining, going down => state = 7 |
| 3870 | * - UP, going down => state = 3 |
| 3871 | * - UP, draining => state = 8 |
| 3872 | * - UP, checked => state = 4 |
| 3873 | * - UP, not checked nor tracked => state = 9 |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3874 | */ |
| 3875 | |
| 3876 | if ((svs->check.state & CHK_ST_ENABLED) && |
| 3877 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3878 | sv_state = 3; |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3879 | else |
| 3880 | sv_state = 4; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3881 | |
Willy Tarreau | efe2822 | 2014-05-21 17:13:13 +0200 | [diff] [blame] | 3882 | if (server_is_draining(sv)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3883 | sv_state += 4; |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3884 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3885 | if (sv_state == 4 && !(svs->check.state & CHK_ST_ENABLED)) |
| 3886 | sv_state = 9; /* unchecked UP */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3887 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3888 | else if (sv->state == SRV_ST_STOPPING) { |
| 3889 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 3890 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3891 | sv_state = 6; /* NOLB */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3892 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3893 | sv_state = 5; /* NOLB going down */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3894 | } |
| 3895 | else { /* stopped */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3896 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) |
| 3897 | sv_state = 1; /* DOWN (agent) */ |
| 3898 | else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3899 | sv_state = 0; /* DOWN */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3900 | else if ((svs->agent.state & CHK_ST_ENABLED) || (svs->check.state & CHK_ST_ENABLED)) |
| 3901 | sv_state = 2; /* going up */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3902 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3903 | sv_state = 0; /* DOWN, unchecked */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3904 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3905 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3906 | 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] | 3907 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3908 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3909 | continue; |
| 3910 | } |
| 3911 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3912 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3913 | if (bi_putchk(rep, &trash) == -1) |
| 3914 | return 0; |
| 3915 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3916 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3917 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3918 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3919 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3920 | case STAT_PX_ST_BE: |
| 3921 | /* print the backend */ |
| 3922 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3923 | if (bi_putchk(rep, &trash) == -1) |
| 3924 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3925 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3926 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3927 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3928 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3929 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3930 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3931 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3932 | if (bi_putchk(rep, &trash) == -1) |
| 3933 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3934 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3935 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3936 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3937 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3938 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3939 | case STAT_PX_ST_FIN: |
| 3940 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3941 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3942 | default: |
| 3943 | /* unknown state, we should put an abort() here ! */ |
| 3944 | return 1; |
| 3945 | } |
| 3946 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3947 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3948 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3949 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3950 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3951 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3952 | { |
| 3953 | /* WARNING! This must fit in the first buffer !!! */ |
| 3954 | chunk_appendf(&trash, |
| 3955 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3956 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3957 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3958 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3959 | "<style type=\"text/css\"><!--\n" |
| 3960 | "body {" |
| 3961 | " font-family: arial, helvetica, sans-serif;" |
| 3962 | " font-size: 12px;" |
| 3963 | " font-weight: normal;" |
| 3964 | " color: black;" |
| 3965 | " background: white;" |
| 3966 | "}\n" |
| 3967 | "th,td {" |
| 3968 | " font-size: 10px;" |
| 3969 | "}\n" |
| 3970 | "h1 {" |
| 3971 | " font-size: x-large;" |
| 3972 | " margin-bottom: 0.5em;" |
| 3973 | "}\n" |
| 3974 | "h2 {" |
| 3975 | " font-family: helvetica, arial;" |
| 3976 | " font-size: x-large;" |
| 3977 | " font-weight: bold;" |
| 3978 | " font-style: italic;" |
| 3979 | " color: #6020a0;" |
| 3980 | " margin-top: 0em;" |
| 3981 | " margin-bottom: 0em;" |
| 3982 | "}\n" |
| 3983 | "h3 {" |
| 3984 | " font-family: helvetica, arial;" |
| 3985 | " font-size: 16px;" |
| 3986 | " font-weight: bold;" |
| 3987 | " color: #b00040;" |
| 3988 | " background: #e8e8d0;" |
| 3989 | " margin-top: 0em;" |
| 3990 | " margin-bottom: 0em;" |
| 3991 | "}\n" |
| 3992 | "li {" |
| 3993 | " margin-top: 0.25em;" |
| 3994 | " margin-right: 2em;" |
| 3995 | "}\n" |
| 3996 | ".hr {margin-top: 0.25em;" |
| 3997 | " border-color: black;" |
| 3998 | " border-bottom-style: solid;" |
| 3999 | "}\n" |
| 4000 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4001 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4002 | ".frontend {background: #e8e8d0;}\n" |
| 4003 | ".socket {background: #d0d0d0;}\n" |
| 4004 | ".backend {background: #e8e8d0;}\n" |
| 4005 | ".active0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4006 | ".active1 {background: #ff9090;}\n" |
| 4007 | ".active2 {background: #ffd020;}\n" |
| 4008 | ".active3 {background: #ffffa0;}\n" |
| 4009 | ".active4 {background: #c0ffc0;}\n" |
| 4010 | ".active5 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 4011 | ".active6 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 4012 | ".active7 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 4013 | ".active8 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
| 4014 | ".active9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4015 | ".backup0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4016 | ".backup1 {background: #ff9090;}\n" |
| 4017 | ".backup2 {background: #ff80ff;}\n" |
| 4018 | ".backup3 {background: #c060ff;}\n" |
| 4019 | ".backup4 {background: #b0d0ff;}\n" |
| 4020 | ".backup5 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 4021 | ".backup6 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 4022 | ".backup7 {background: #c060ff;}\n" |
| 4023 | ".backup8 {background: #cc9900;}\n" |
| 4024 | ".backup9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4025 | ".maintain {background: #c07820;}\n" |
| 4026 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4027 | "\n" |
| 4028 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4029 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4030 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4031 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4032 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4033 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4034 | "\n" |
| 4035 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4036 | "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" |
| 4037 | "table.tbl td.ac { text-align: center;}\n" |
| 4038 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4039 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4040 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4041 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4042 | "\n" |
| 4043 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4044 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4045 | "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] | 4046 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4047 | "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] | 4048 | "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] | 4049 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4050 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4051 | " display:block;\n" |
| 4052 | " visibility:hidden;\n" |
| 4053 | " z-index:2147483647;\n" |
| 4054 | " position:absolute;\n" |
| 4055 | " padding:2px 4px 3px;\n" |
| 4056 | " background:#f0f060; color:#000000;\n" |
| 4057 | " border:1px solid #7040c0;\n" |
| 4058 | " white-space:nowrap;\n" |
| 4059 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4060 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4061 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4062 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4063 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4064 | "-->\n" |
| 4065 | "</style></head>\n", |
| 4066 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4067 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4068 | ); |
| 4069 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4070 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4071 | /* 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] | 4072 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4073 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4074 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4075 | 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] | 4076 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4077 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4078 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4079 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4080 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4081 | /* WARNING! this has to fit the first packet too. |
| 4082 | * We are around 3.5 kB, add adding entries will |
| 4083 | * become tricky if we want to support 4kB buffers ! |
| 4084 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4085 | chunk_appendf(&trash, |
| 4086 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4087 | PRODUCT_NAME "%s</a></h1>\n" |
| 4088 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4089 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4090 | "<h3>> General process information</h3>\n" |
| 4091 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4092 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4093 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4094 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4095 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4096 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4097 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4098 | "</td><td align=\"center\" nowrap>\n" |
| 4099 | "<table class=\"lgd\"><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4100 | "<td class=\"active4\"> </td><td class=\"noborder\">active UP </td>" |
| 4101 | "<td class=\"backup4\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4102 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4103 | "<td class=\"active3\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4104 | "<td class=\"backup3\"></td><td class=\"noborder\">backup UP, going down </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4105 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4106 | "<td class=\"active2\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4107 | "<td class=\"backup2\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4108 | "</tr><tr>\n" |
| 4109 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4110 | "<td class=\"active9\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4111 | "</tr><tr>\n" |
| 4112 | "<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] | 4113 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4114 | "<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] | 4115 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4116 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4117 | "</td>" |
| 4118 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4119 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4120 | "", |
| 4121 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4122 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4123 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4124 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4125 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4126 | pid, relative_pid, global.nbproc, |
| 4127 | up / 86400, (up % 86400) / 3600, |
| 4128 | (up % 3600) / 60, (up % 60), |
| 4129 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4130 | global.rlimit_memmax ? " MB" : "", |
| 4131 | global.rlimit_nofile, |
| 4132 | global.maxsock, global.maxconn, global.maxpipes, |
| 4133 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4134 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4135 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4136 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4137 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 4138 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4139 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4140 | |
| 4141 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 4142 | "<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] | 4143 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4144 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4145 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 4146 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4147 | STAT_SCOPE_TXT_MAXLEN); |
| 4148 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4149 | /* 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] | 4150 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4151 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4152 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4153 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4154 | 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] | 4155 | } |
| 4156 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4157 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4158 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4159 | "<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] | 4160 | uri->uri_prefix, |
| 4161 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4162 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4163 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4164 | else |
| 4165 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4166 | "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4167 | uri->uri_prefix, |
| 4168 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4169 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4170 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4171 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4172 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4173 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4174 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4175 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4176 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4177 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4178 | "", |
| 4179 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4180 | else |
| 4181 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4182 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4183 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4184 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4185 | ";norefresh", |
| 4186 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4187 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4188 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4189 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4190 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4191 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4192 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4193 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4194 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4195 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4196 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4197 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4198 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4199 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4200 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4201 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4202 | chunk_appendf(&trash, |
| 4203 | "</ul></td>" |
| 4204 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4205 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4206 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4207 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4208 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4209 | "</ul>" |
| 4210 | "</td>" |
| 4211 | "</tr></table>\n" |
| 4212 | "" |
| 4213 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4214 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4215 | if (appctx->ctx.stats.st_code) { |
| 4216 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4217 | case STAT_STATUS_DONE: |
| 4218 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4219 | "<p><div class=active4>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4220 | "<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] | 4221 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4222 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4223 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4224 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4225 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4226 | break; |
| 4227 | case STAT_STATUS_NONE: |
| 4228 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4229 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4230 | "<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] | 4231 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4232 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4233 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4234 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4235 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4236 | break; |
| 4237 | case STAT_STATUS_PART: |
| 4238 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4239 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4240 | "<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] | 4241 | "Action partially processed.<br>" |
| 4242 | "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] | 4243 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4244 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4245 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4246 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4247 | break; |
| 4248 | case STAT_STATUS_ERRP: |
| 4249 | chunk_appendf(&trash, |
| 4250 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4251 | "<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] | 4252 | "Action not processed because of invalid parameters." |
| 4253 | "<ul>" |
| 4254 | "<li>The action is maybe unknown.</li>" |
| 4255 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4256 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4257 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4258 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4259 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4260 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4261 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4262 | break; |
| 4263 | case STAT_STATUS_EXCD: |
| 4264 | chunk_appendf(&trash, |
| 4265 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4266 | "<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] | 4267 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4268 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4269 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4270 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4271 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4272 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4273 | break; |
| 4274 | case STAT_STATUS_DENY: |
| 4275 | chunk_appendf(&trash, |
| 4276 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4277 | "<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] | 4278 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4279 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4280 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4281 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4282 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4283 | break; |
| 4284 | default: |
| 4285 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4286 | "<p><div class=active9>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4287 | "<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] | 4288 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4289 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4290 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4291 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4292 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4293 | } |
| 4294 | chunk_appendf(&trash, "<p>\n"); |
| 4295 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4296 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4297 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4298 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4299 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4300 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4301 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4302 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4303 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4304 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4305 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4306 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4307 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4308 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4309 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 4310 | * and the session must be closed, or -1 in case of any error. This function is |
| 4311 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4312 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4313 | 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] | 4314 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4315 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4316 | struct channel *rep = si->ib; |
| 4317 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4318 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4319 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4320 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4321 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4322 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4323 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4324 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4325 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4326 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4327 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4328 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4329 | else |
| 4330 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4331 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4332 | if (bi_putchk(rep, &trash) == -1) |
| 4333 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4334 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4335 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4336 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4337 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4338 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4339 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4340 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4341 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4342 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4343 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4344 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4345 | appctx->ctx.stats.px = proxy; |
| 4346 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4347 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4348 | /* fall through */ |
| 4349 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4350 | case STAT_ST_LIST: |
| 4351 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4352 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4353 | if (buffer_almost_full(rep->buf)) { |
| 4354 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4355 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4356 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4357 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4358 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4359 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4360 | 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] | 4361 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4362 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4363 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4364 | appctx->ctx.stats.px = px->next; |
| 4365 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4366 | } |
| 4367 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4368 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4369 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4370 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4371 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4372 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4373 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4374 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4375 | if (bi_putchk(rep, &trash) == -1) |
| 4376 | return 0; |
| 4377 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4378 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4379 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4380 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4381 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4382 | case STAT_ST_FIN: |
| 4383 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4384 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4385 | default: |
| 4386 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4387 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4388 | return -1; |
| 4389 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4390 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4391 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4392 | /* We reached the stats page through a POST request. The appctx is |
| 4393 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4394 | * Parse the posted data and enable/disable servers if necessary. |
| 4395 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4396 | */ |
| 4397 | static int stats_process_http_post(struct stream_interface *si) |
| 4398 | { |
| 4399 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4400 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4401 | |
| 4402 | struct proxy *px = NULL; |
| 4403 | struct server *sv = NULL; |
| 4404 | |
| 4405 | char key[LINESIZE]; |
| 4406 | int action = ST_ADM_ACTION_NONE; |
| 4407 | int reprocess = 0; |
| 4408 | |
| 4409 | int total_servers = 0; |
| 4410 | int altered_servers = 0; |
| 4411 | |
| 4412 | char *first_param, *cur_param, *next_param, *end_params; |
| 4413 | char *st_cur_param = NULL; |
| 4414 | char *st_next_param = NULL; |
| 4415 | |
| 4416 | struct chunk *temp; |
| 4417 | int reql; |
| 4418 | |
| 4419 | temp = get_trash_chunk(); |
| 4420 | if (temp->size < s->txn.req.body_len) { |
| 4421 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4422 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4423 | goto out; |
| 4424 | } |
| 4425 | |
| 4426 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 4427 | if (reql <= 0) { |
| 4428 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4429 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4430 | return 0; |
| 4431 | } |
| 4432 | |
| 4433 | first_param = temp->str; |
| 4434 | end_params = temp->str + reql; |
| 4435 | cur_param = next_param = end_params; |
| 4436 | *end_params = '\0'; |
| 4437 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4438 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4439 | |
| 4440 | /* |
| 4441 | * Parse the parameters in reverse order to only store the last value. |
| 4442 | * From the html form, the backend and the action are at the end. |
| 4443 | */ |
| 4444 | while (cur_param > first_param) { |
| 4445 | char *value; |
| 4446 | int poffset, plen; |
| 4447 | |
| 4448 | cur_param--; |
| 4449 | |
| 4450 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4451 | reprocess_servers: |
| 4452 | /* Parse the key */ |
| 4453 | poffset = (cur_param != first_param ? 1 : 0); |
| 4454 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4455 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4456 | strncpy(key, cur_param + poffset, plen); |
| 4457 | key[plen - 1] = '\0'; |
| 4458 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4459 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4460 | goto out; |
| 4461 | } |
| 4462 | |
| 4463 | /* Parse the value */ |
| 4464 | value = key; |
| 4465 | while (*value != '\0' && *value != '=') { |
| 4466 | value++; |
| 4467 | } |
| 4468 | if (*value == '=') { |
| 4469 | /* Ok, a value is found, we can mark the end of the key */ |
| 4470 | *value++ = '\0'; |
| 4471 | } |
| 4472 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4473 | break; |
| 4474 | |
| 4475 | /* Now we can check the key to see what to do */ |
| 4476 | if (!px && (strcmp(key, "b") == 0)) { |
| 4477 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4478 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4479 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4480 | goto out; |
| 4481 | } |
| 4482 | } |
| 4483 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4484 | if (strcmp(value, "ready") == 0) { |
| 4485 | action = ST_ADM_ACTION_READY; |
| 4486 | } |
| 4487 | else if (strcmp(value, "drain") == 0) { |
| 4488 | action = ST_ADM_ACTION_DRAIN; |
| 4489 | } |
| 4490 | else if (strcmp(value, "maint") == 0) { |
| 4491 | action = ST_ADM_ACTION_MAINT; |
| 4492 | } |
| 4493 | else if (strcmp(value, "shutdown") == 0) { |
| 4494 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4495 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4496 | else if (strcmp(value, "dhlth") == 0) { |
| 4497 | action = ST_ADM_ACTION_DHLTH; |
| 4498 | } |
| 4499 | else if (strcmp(value, "ehlth") == 0) { |
| 4500 | action = ST_ADM_ACTION_EHLTH; |
| 4501 | } |
| 4502 | else if (strcmp(value, "hrunn") == 0) { |
| 4503 | action = ST_ADM_ACTION_HRUNN; |
| 4504 | } |
| 4505 | else if (strcmp(value, "hnolb") == 0) { |
| 4506 | action = ST_ADM_ACTION_HNOLB; |
| 4507 | } |
| 4508 | else if (strcmp(value, "hdown") == 0) { |
| 4509 | action = ST_ADM_ACTION_HDOWN; |
| 4510 | } |
| 4511 | else if (strcmp(value, "dagent") == 0) { |
| 4512 | action = ST_ADM_ACTION_DAGENT; |
| 4513 | } |
| 4514 | else if (strcmp(value, "eagent") == 0) { |
| 4515 | action = ST_ADM_ACTION_EAGENT; |
| 4516 | } |
| 4517 | else if (strcmp(value, "arunn") == 0) { |
| 4518 | action = ST_ADM_ACTION_ARUNN; |
| 4519 | } |
| 4520 | else if (strcmp(value, "adown") == 0) { |
| 4521 | action = ST_ADM_ACTION_ADOWN; |
| 4522 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4523 | /* else these are the old supported methods */ |
| 4524 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4525 | action = ST_ADM_ACTION_DISABLE; |
| 4526 | } |
| 4527 | else if (strcmp(value, "enable") == 0) { |
| 4528 | action = ST_ADM_ACTION_ENABLE; |
| 4529 | } |
| 4530 | else if (strcmp(value, "stop") == 0) { |
| 4531 | action = ST_ADM_ACTION_STOP; |
| 4532 | } |
| 4533 | else if (strcmp(value, "start") == 0) { |
| 4534 | action = ST_ADM_ACTION_START; |
| 4535 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4536 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4537 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4538 | goto out; |
| 4539 | } |
| 4540 | } |
| 4541 | else if (strcmp(key, "s") == 0) { |
| 4542 | if (!(px && action)) { |
| 4543 | /* |
| 4544 | * Indicates that we'll need to reprocess the parameters |
| 4545 | * as soon as backend and action are known |
| 4546 | */ |
| 4547 | if (!reprocess) { |
| 4548 | st_cur_param = cur_param; |
| 4549 | st_next_param = next_param; |
| 4550 | } |
| 4551 | reprocess = 1; |
| 4552 | } |
| 4553 | else if ((sv = findserver(px, value)) != NULL) { |
| 4554 | switch (action) { |
| 4555 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4556 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4557 | altered_servers++; |
| 4558 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4559 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4560 | } |
| 4561 | break; |
| 4562 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4563 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4564 | altered_servers++; |
| 4565 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4566 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4567 | } |
| 4568 | break; |
| 4569 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4570 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 4571 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4572 | altered_servers++; |
| 4573 | total_servers++; |
| 4574 | } |
| 4575 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4576 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4577 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 4578 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4579 | altered_servers++; |
| 4580 | total_servers++; |
| 4581 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4582 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4583 | case ST_ADM_ACTION_DHLTH: |
| 4584 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4585 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4586 | altered_servers++; |
| 4587 | total_servers++; |
| 4588 | } |
| 4589 | break; |
| 4590 | case ST_ADM_ACTION_EHLTH: |
| 4591 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4592 | sv->check.state |= CHK_ST_ENABLED; |
| 4593 | altered_servers++; |
| 4594 | total_servers++; |
| 4595 | } |
| 4596 | break; |
| 4597 | case ST_ADM_ACTION_HRUNN: |
| 4598 | if (!(sv->track)) { |
| 4599 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4600 | srv_set_running(sv, "changed from Web interface"); |
| 4601 | altered_servers++; |
| 4602 | total_servers++; |
| 4603 | } |
| 4604 | break; |
| 4605 | case ST_ADM_ACTION_HNOLB: |
| 4606 | if (!(sv->track)) { |
| 4607 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4608 | srv_set_stopping(sv, "changed from Web interface"); |
| 4609 | altered_servers++; |
| 4610 | total_servers++; |
| 4611 | } |
| 4612 | break; |
| 4613 | case ST_ADM_ACTION_HDOWN: |
| 4614 | if (!(sv->track)) { |
| 4615 | sv->check.health = 0; |
| 4616 | srv_set_stopped(sv, "changed from Web interface"); |
| 4617 | altered_servers++; |
| 4618 | total_servers++; |
| 4619 | } |
| 4620 | break; |
| 4621 | case ST_ADM_ACTION_DAGENT: |
| 4622 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4623 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4624 | altered_servers++; |
| 4625 | total_servers++; |
| 4626 | } |
| 4627 | break; |
| 4628 | case ST_ADM_ACTION_EAGENT: |
| 4629 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4630 | sv->agent.state |= CHK_ST_ENABLED; |
| 4631 | altered_servers++; |
| 4632 | total_servers++; |
| 4633 | } |
| 4634 | break; |
| 4635 | case ST_ADM_ACTION_ARUNN: |
| 4636 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4637 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 4638 | srv_set_running(sv, "changed from Web interface"); |
| 4639 | altered_servers++; |
| 4640 | total_servers++; |
| 4641 | } |
| 4642 | break; |
| 4643 | case ST_ADM_ACTION_ADOWN: |
| 4644 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4645 | sv->agent.health = 0; |
| 4646 | srv_set_stopped(sv, "changed from Web interface"); |
| 4647 | altered_servers++; |
| 4648 | total_servers++; |
| 4649 | } |
| 4650 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4651 | case ST_ADM_ACTION_READY: |
| 4652 | srv_adm_set_ready(sv); |
| 4653 | altered_servers++; |
| 4654 | total_servers++; |
| 4655 | break; |
| 4656 | case ST_ADM_ACTION_DRAIN: |
| 4657 | srv_adm_set_drain(sv); |
| 4658 | altered_servers++; |
| 4659 | total_servers++; |
| 4660 | break; |
| 4661 | case ST_ADM_ACTION_MAINT: |
| 4662 | srv_adm_set_maint(sv); |
| 4663 | altered_servers++; |
| 4664 | total_servers++; |
| 4665 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4666 | case ST_ADM_ACTION_SHUTDOWN: |
| 4667 | if (px->state != PR_STSTOPPED) { |
| 4668 | struct session *sess, *sess_bck; |
| 4669 | |
| 4670 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4671 | if (sess->srv_conn == sv) |
| 4672 | session_shutdown(sess, SN_ERR_KILLED); |
| 4673 | |
| 4674 | altered_servers++; |
| 4675 | total_servers++; |
| 4676 | } |
| 4677 | break; |
| 4678 | } |
| 4679 | } else { |
| 4680 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4681 | total_servers++; |
| 4682 | } |
| 4683 | } |
| 4684 | if (reprocess && px && action) { |
| 4685 | /* Now, we know the backend and the action chosen by the user. |
| 4686 | * We can safely restart from the first server parameter |
| 4687 | * to reprocess them |
| 4688 | */ |
| 4689 | cur_param = st_cur_param; |
| 4690 | next_param = st_next_param; |
| 4691 | reprocess = 0; |
| 4692 | goto reprocess_servers; |
| 4693 | } |
| 4694 | |
| 4695 | next_param = cur_param; |
| 4696 | } |
| 4697 | } |
| 4698 | |
| 4699 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4700 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4701 | } |
| 4702 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4703 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4704 | } |
| 4705 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4706 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4707 | } |
| 4708 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4709 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4710 | } |
| 4711 | out: |
| 4712 | return 1; |
| 4713 | } |
| 4714 | |
| 4715 | |
| 4716 | static int stats_send_http_headers(struct stream_interface *si) |
| 4717 | { |
| 4718 | struct session *s = session_from_task(si->owner); |
| 4719 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4720 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4721 | |
| 4722 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4723 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4724 | "Cache-Control: no-cache\r\n" |
| 4725 | "Connection: close\r\n" |
| 4726 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4727 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4728 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4729 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4730 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4731 | uri->refresh); |
| 4732 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4733 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4734 | |
| 4735 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4736 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4737 | else |
| 4738 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4739 | |
| 4740 | s->txn.status = 200; |
| 4741 | s->logs.tv_request = now; |
| 4742 | |
| 4743 | if (bi_putchk(si->ib, &trash) == -1) |
| 4744 | return 0; |
| 4745 | |
| 4746 | return 1; |
| 4747 | } |
| 4748 | |
| 4749 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4750 | { |
| 4751 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4752 | struct session *s = session_from_task(si->owner); |
| 4753 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4754 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4755 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4756 | /* 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] | 4757 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4758 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4759 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4760 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4761 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4762 | } |
| 4763 | |
| 4764 | /* We don't want to land on the posted stats page because a refresh will |
| 4765 | * repost the data. We don't want this to happen on accident so we redirect |
| 4766 | * the browse to the stats page with a GET. |
| 4767 | */ |
| 4768 | chunk_printf(&trash, |
| 4769 | "HTTP/1.1 303 See Other\r\n" |
| 4770 | "Cache-Control: no-cache\r\n" |
| 4771 | "Content-Type: text/plain\r\n" |
| 4772 | "Connection: close\r\n" |
| 4773 | "Location: %s;st=%s%s%s%s\r\n" |
| 4774 | "\r\n", |
| 4775 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4776 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4777 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4778 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4779 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4780 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4781 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4782 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4783 | scope_txt); |
| 4784 | |
| 4785 | s->txn.status = 303; |
| 4786 | s->logs.tv_request = now; |
| 4787 | |
| 4788 | if (bi_putchk(si->ib, &trash) == -1) |
| 4789 | return 0; |
| 4790 | |
| 4791 | return 1; |
| 4792 | } |
| 4793 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4794 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4795 | * 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] | 4796 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4797 | * automatically unregisters itself once transfer is complete. |
| 4798 | */ |
| 4799 | static void http_stats_io_handler(struct stream_interface *si) |
| 4800 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4801 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4802 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4803 | struct channel *req = si->ob; |
| 4804 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4805 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4806 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4807 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4808 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4809 | /* check that the output is not closed */ |
| 4810 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4811 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4812 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4813 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4814 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4815 | if (stats_send_http_headers(si)) { |
| 4816 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4817 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4818 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4819 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4820 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4821 | } |
| 4822 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4823 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4824 | unsigned int prev_len = si->ib->buf->i; |
| 4825 | unsigned int data_len; |
| 4826 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 4827 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4828 | |
| 4829 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4830 | /* One difficulty we're facing is that we must prevent |
| 4831 | * the input data from being automatically forwarded to |
| 4832 | * the output area. For this, we temporarily disable |
| 4833 | * forwarding on the channel. |
| 4834 | */ |
| 4835 | last_fwd = si->ib->to_forward; |
| 4836 | si->ib->to_forward = 0; |
| 4837 | chunk_printf(&trash, "\r\n000000\r\n"); |
| 4838 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4839 | si->ib->to_forward = last_fwd; |
| 4840 | goto fail; |
| 4841 | } |
| 4842 | } |
| 4843 | |
| 4844 | data_len = si->ib->buf->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4845 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4846 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4847 | |
| 4848 | last_len = si->ib->buf->i; |
| 4849 | |
| 4850 | /* Now we must either adjust or remove the chunk size. This is |
| 4851 | * not easy because the chunk size might wrap at the end of the |
| 4852 | * buffer, so we pretend we have nothing in the buffer, we write |
| 4853 | * the size, then restore the buffer's contents. Note that we can |
| 4854 | * only do that because no forwarding is scheduled on the stats |
| 4855 | * applet. |
| 4856 | */ |
| 4857 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4858 | si->ib->total -= (last_len - prev_len); |
| 4859 | si->ib->buf->i -= (last_len - prev_len); |
| 4860 | |
| 4861 | if (last_len != data_len) { |
| 4862 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
| 4863 | bi_putchk(si->ib, &trash); |
| 4864 | |
| 4865 | si->ib->total += (last_len - data_len); |
| 4866 | si->ib->buf->i += (last_len - data_len); |
| 4867 | } |
| 4868 | /* now re-enable forwarding */ |
| 4869 | channel_forward(si->ib, last_fwd); |
| 4870 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4871 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4872 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4873 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4874 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4875 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4876 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4877 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4878 | } |
| 4879 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4880 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4881 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4882 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4883 | } |
| 4884 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4885 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 4886 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4887 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
| 4888 | if (bi_putchk(si->ib, &trash) == -1) |
| 4889 | goto fail; |
| 4890 | } |
| 4891 | /* eat the whole request */ |
| 4892 | bo_skip(si->ob, si->ob->buf->o); |
| 4893 | res->flags |= CF_READ_NULL; |
| 4894 | si_shutr(si); |
| 4895 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4896 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4897 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4898 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4899 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4900 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4901 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4902 | si_shutr(si); |
| 4903 | res->flags |= CF_READ_NULL; |
| 4904 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4905 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4906 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4907 | fail: |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4908 | /* update all other flags and resync with the other side */ |
| 4909 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4910 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4911 | /* we don't want to expire timeouts while we're processing requests */ |
| 4912 | si->ib->rex = TICK_ETERNITY; |
| 4913 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4914 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4915 | out: |
| 4916 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4917 | /* check that we have released everything then unregister */ |
| 4918 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4919 | } |
| 4920 | } |
| 4921 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4922 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4923 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4924 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4925 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4926 | return "NONE"; |
| 4927 | return conn->ctrl->name; |
| 4928 | } |
| 4929 | |
| 4930 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4931 | { |
| 4932 | static char ptr[17]; |
| 4933 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4934 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4935 | return "NONE"; |
| 4936 | |
| 4937 | if (conn->xprt == &raw_sock) |
| 4938 | return "RAW"; |
| 4939 | |
| 4940 | #ifdef USE_OPENSSL |
| 4941 | if (conn->xprt == &ssl_sock) |
| 4942 | return "SSL"; |
| 4943 | #endif |
| 4944 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4945 | return ptr; |
| 4946 | } |
| 4947 | |
| 4948 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4949 | { |
| 4950 | static char ptr[17]; |
| 4951 | |
| 4952 | if (!conn->data) |
| 4953 | return "NONE"; |
| 4954 | |
| 4955 | if (conn->data == &sess_conn_cb) |
| 4956 | return "SESS"; |
| 4957 | |
| 4958 | if (conn->data == &si_conn_cb) |
| 4959 | return "STRM"; |
| 4960 | |
| 4961 | if (conn->data == &check_conn_cb) |
| 4962 | return "CHCK"; |
| 4963 | |
| 4964 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4965 | return ptr; |
| 4966 | } |
| 4967 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4968 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4969 | * 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] | 4970 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4971 | * 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] | 4972 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4973 | 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] | 4974 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4975 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4976 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4977 | extern const char *monthname[12]; |
| 4978 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4979 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4980 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4981 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4982 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4983 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4984 | 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] | 4985 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4986 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4987 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4988 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4989 | appctx->ctx.sess.uid = 0; |
| 4990 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4991 | return 1; |
| 4992 | } |
| 4993 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4994 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4995 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4996 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4997 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4998 | /* fall through */ |
| 4999 | |
| 5000 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5001 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5002 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5003 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5004 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5005 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5006 | 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] | 5007 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 5008 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5009 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5010 | conn = objt_conn(sess->si[0].end); |
| 5011 | 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] | 5012 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5013 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5014 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5015 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5016 | break; |
| 5017 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5018 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5019 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5020 | default: |
| 5021 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5022 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5023 | break; |
| 5024 | } |
| 5025 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5026 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5027 | " 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] | 5028 | 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] | 5029 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5030 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5031 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5032 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 5033 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 5034 | sess->listener ? sess->listener->luid : 0); |
| 5035 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5036 | if (conn) |
| 5037 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5038 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5039 | 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] | 5040 | case AF_INET: |
| 5041 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5042 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5043 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5044 | break; |
| 5045 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5046 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5047 | break; |
| 5048 | default: |
| 5049 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5050 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5051 | break; |
| 5052 | } |
| 5053 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5054 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5055 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5056 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5057 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5058 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5059 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5060 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5061 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5062 | conn = objt_conn(sess->si[1].end); |
| 5063 | if (conn) |
| 5064 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5065 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5066 | 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] | 5067 | case AF_INET: |
| 5068 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5069 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5070 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5071 | break; |
| 5072 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5073 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5074 | break; |
| 5075 | default: |
| 5076 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5077 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5078 | break; |
| 5079 | } |
| 5080 | |
| 5081 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5082 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5083 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5084 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5085 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5086 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5087 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5088 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5089 | if (conn) |
| 5090 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5091 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5092 | 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] | 5093 | case AF_INET: |
| 5094 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5095 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5096 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5097 | break; |
| 5098 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5099 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5100 | break; |
| 5101 | default: |
| 5102 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5103 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5104 | break; |
| 5105 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5106 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5107 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5108 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5109 | sess->task, |
| 5110 | sess->task->state, |
| 5111 | sess->task->nice, sess->task->calls, |
| 5112 | sess->task->expire ? |
| 5113 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5114 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5115 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5116 | task_in_rq(sess->task) ? ", running" : ""); |
| 5117 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5118 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5119 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5120 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5121 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5122 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5123 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 5124 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 5125 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 5126 | |
| 5127 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5128 | " 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] | 5129 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5130 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5131 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5132 | obj_type_name(sess->si[0].end), |
| 5133 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5134 | sess->si[0].exp ? |
| 5135 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5136 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5137 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5138 | sess->si[0].err_type); |
| 5139 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5140 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5141 | " 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] | 5142 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5143 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5144 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5145 | obj_type_name(sess->si[1].end), |
| 5146 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5147 | sess->si[1].exp ? |
| 5148 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5149 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5150 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5151 | sess->si[1].err_type); |
| 5152 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5153 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5154 | chunk_appendf(&trash, |
| 5155 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5156 | conn, |
| 5157 | get_conn_ctrl_name(conn), |
| 5158 | get_conn_xprt_name(conn), |
| 5159 | get_conn_data_name(conn), |
| 5160 | obj_type_name(conn->target), |
| 5161 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5162 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5163 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5164 | " 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] | 5165 | conn->flags, |
| 5166 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5167 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5168 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5169 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5170 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5171 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5172 | chunk_appendf(&trash, |
| 5173 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5174 | tmpctx, |
| 5175 | tmpctx->st0, |
| 5176 | tmpctx->st1, |
| 5177 | tmpctx->st2, |
| 5178 | tmpctx->applet->name); |
| 5179 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5180 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5181 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5182 | chunk_appendf(&trash, |
| 5183 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5184 | conn, |
| 5185 | get_conn_ctrl_name(conn), |
| 5186 | get_conn_xprt_name(conn), |
| 5187 | get_conn_data_name(conn), |
| 5188 | obj_type_name(conn->target), |
| 5189 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5190 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5191 | chunk_appendf(&trash, |
| 5192 | " 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] | 5193 | conn->flags, |
| 5194 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5195 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5196 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5197 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5198 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5199 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5200 | chunk_appendf(&trash, |
| 5201 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5202 | tmpctx, |
| 5203 | tmpctx->st0, |
| 5204 | tmpctx->st1, |
| 5205 | tmpctx->st2, |
| 5206 | tmpctx->applet->name); |
| 5207 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5208 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5209 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5210 | " 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] | 5211 | " an_exp=%s", |
| 5212 | sess->req, |
| 5213 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5214 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5215 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5216 | sess->req->analyse_exp ? |
| 5217 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 5218 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5219 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5220 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5221 | " rex=%s", |
| 5222 | sess->req->rex ? |
| 5223 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 5224 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5225 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5226 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5227 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5228 | " 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] | 5229 | sess->req->wex ? |
| 5230 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 5231 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5232 | sess->req->buf, |
| 5233 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5234 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5235 | sess->txn.req.next, sess->req->buf->i, |
| 5236 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5237 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5238 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5239 | " 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] | 5240 | " an_exp=%s", |
| 5241 | sess->rep, |
| 5242 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5243 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5244 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5245 | sess->rep->analyse_exp ? |
| 5246 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 5247 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5248 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5249 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5250 | " rex=%s", |
| 5251 | sess->rep->rex ? |
| 5252 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 5253 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5254 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5255 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5256 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5257 | " 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] | 5258 | sess->rep->wex ? |
| 5259 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 5260 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5261 | sess->rep->buf, |
| 5262 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5263 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5264 | sess->txn.rsp.next, sess->rep->buf->i, |
| 5265 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5266 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5267 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5268 | return 0; |
| 5269 | |
| 5270 | /* use other states to dump the contents */ |
| 5271 | } |
| 5272 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5273 | appctx->ctx.sess.uid = 0; |
| 5274 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5275 | return 1; |
| 5276 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5277 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5278 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5279 | { |
| 5280 | struct appctx *appctx = __objt_appctx(si->end); |
| 5281 | |
| 5282 | switch (appctx->st2) { |
| 5283 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5284 | /* Display the column headers. If the message cannot be sent, |
| 5285 | * quit the fucntion with returning 0. The function is called |
| 5286 | * later and restart at the state "STAT_ST_INIT". |
| 5287 | */ |
| 5288 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5289 | chunk_appendf(&trash, "# id (file) description\n"); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5290 | if (bi_putchk(si->ib, &trash) == -1) |
| 5291 | return 0; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5292 | |
| 5293 | /* Now, we start the browsing of the references lists. |
| 5294 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5295 | * avalaible field of this pointer is <list>. It is used with the function |
| 5296 | * pat_list_get_next() for retruning the first avalaible entry |
| 5297 | */ |
| 5298 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5299 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5300 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5301 | appctx->st2 = STAT_ST_LIST; |
| 5302 | /* fall through */ |
| 5303 | |
| 5304 | case STAT_ST_LIST: |
| 5305 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5306 | chunk_reset(&trash); |
| 5307 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5308 | /* Build messages. If the reference is used by another category than |
| 5309 | * the listed categorie, display the information in the massage. |
| 5310 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5311 | 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] | 5312 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5313 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5314 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5315 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5316 | /* let's try again later from this session. We add ourselves into |
| 5317 | * this session's users so that it can remove us upon termination. |
| 5318 | */ |
| 5319 | return 0; |
| 5320 | } |
| 5321 | |
| 5322 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5323 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5324 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | appctx->st2 = STAT_ST_FIN; |
| 5328 | /* fall through */ |
| 5329 | |
| 5330 | default: |
| 5331 | appctx->st2 = STAT_ST_FIN; |
| 5332 | return 1; |
| 5333 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5334 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5335 | } |
| 5336 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5337 | static int stats_map_lookup(struct stream_interface *si) |
| 5338 | { |
| 5339 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5340 | struct sample sample; |
| 5341 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5342 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5343 | |
| 5344 | switch (appctx->st2) { |
| 5345 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5346 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5347 | 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] | 5348 | 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] | 5349 | appctx->st2 = STAT_ST_LIST; |
| 5350 | /* fall through */ |
| 5351 | |
| 5352 | case STAT_ST_LIST: |
| 5353 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5354 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5355 | /* initialise chunk to build new message */ |
| 5356 | chunk_reset(&trash); |
| 5357 | |
| 5358 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 5359 | sample.type = SMP_T_STR; |
| 5360 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5361 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 5362 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5363 | if (appctx->ctx.map.expr->pat_head->match && |
| 5364 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5365 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5366 | else |
| 5367 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5368 | |
| 5369 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5370 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5371 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5372 | break; |
| 5373 | if (match_method >= PAT_MATCH_NUM) |
| 5374 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5375 | else |
| 5376 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5377 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5378 | /* case sensitive */ |
| 5379 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5380 | chunk_appendf(&trash, ", case=insensitive"); |
| 5381 | else |
| 5382 | chunk_appendf(&trash, ", case=sensitive"); |
| 5383 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5384 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5385 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5386 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5387 | chunk_appendf(&trash, ", found=no"); |
| 5388 | else |
| 5389 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | /* Display match and match info */ |
| 5393 | else { |
| 5394 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5395 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5396 | chunk_appendf(&trash, ", found=yes"); |
| 5397 | else |
| 5398 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5399 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5400 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5401 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5402 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5403 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5404 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5405 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5406 | /* display pattern */ |
| 5407 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5408 | if (pat->ref && pat->ref->pattern) |
| 5409 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5410 | else |
| 5411 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5412 | } |
| 5413 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5414 | if (pat->ref && pat->ref->pattern) |
| 5415 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5416 | else |
| 5417 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5418 | } |
| 5419 | |
| 5420 | /* display return value */ |
| 5421 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5422 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5423 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5424 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5425 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5426 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5427 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5428 | } |
| 5429 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5430 | chunk_appendf(&trash, "\n"); |
| 5431 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5432 | /* display response */ |
| 5433 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5434 | /* let's try again later from this session. We add ourselves into |
| 5435 | * this session's users so that it can remove us upon termination. |
| 5436 | */ |
| 5437 | return 0; |
| 5438 | } |
| 5439 | |
| 5440 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5441 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5442 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5443 | } |
| 5444 | |
| 5445 | appctx->st2 = STAT_ST_FIN; |
| 5446 | /* fall through */ |
| 5447 | |
| 5448 | default: |
| 5449 | appctx->st2 = STAT_ST_FIN; |
| 5450 | free(appctx->ctx.map.chunk.str); |
| 5451 | return 1; |
| 5452 | } |
| 5453 | } |
| 5454 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5455 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5456 | { |
| 5457 | struct appctx *appctx = __objt_appctx(si->end); |
| 5458 | |
| 5459 | switch (appctx->st2) { |
| 5460 | |
| 5461 | case STAT_ST_INIT: |
| 5462 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5463 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5464 | struct pat_ref_elt *, list); |
| 5465 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5466 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5467 | appctx->st2 = STAT_ST_LIST; |
| 5468 | /* fall through */ |
| 5469 | |
| 5470 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5471 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5472 | chunk_reset(&trash); |
| 5473 | |
| 5474 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5475 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5476 | chunk_appendf(&trash, "%p %s %s\n", |
| 5477 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5478 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5479 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5480 | chunk_appendf(&trash, "%p %s\n", |
| 5481 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5482 | |
| 5483 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5484 | /* let's try again later from this session. We add ourselves into |
| 5485 | * this session's users so that it can remove us upon termination. |
| 5486 | */ |
| 5487 | return 0; |
| 5488 | } |
| 5489 | |
| 5490 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5491 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5492 | struct pat_ref_elt *, list); |
| 5493 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5494 | break; |
| 5495 | } |
| 5496 | |
| 5497 | appctx->st2 = STAT_ST_FIN; |
| 5498 | /* fall through */ |
| 5499 | |
| 5500 | default: |
| 5501 | appctx->st2 = STAT_ST_FIN; |
| 5502 | return 1; |
| 5503 | } |
| 5504 | } |
| 5505 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5506 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5507 | * 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] | 5508 | * to be called again, otherwise non-zero. It is designed to be called |
| 5509 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5510 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5511 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5512 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5513 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5514 | struct connection *conn; |
| 5515 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5516 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5517 | /* If we're forced to shut down, we might have to remove our |
| 5518 | * reference to the last session being dumped. |
| 5519 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5520 | if (appctx->st2 == STAT_ST_LIST) { |
| 5521 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5522 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5523 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5524 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5525 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5526 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5527 | } |
| 5528 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5529 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5530 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5531 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5532 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5533 | /* the function had not been called yet, let's prepare the |
| 5534 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5535 | * pointer to the first in the global list. When a target |
| 5536 | * session is being destroyed, it is responsible for updating |
| 5537 | * this pointer. We know we have reached the end when this |
| 5538 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5539 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5540 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5541 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5542 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5543 | /* fall through */ |
| 5544 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5545 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5546 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5547 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5548 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5549 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5553 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5554 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5555 | struct session *curr_sess; |
| 5556 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5557 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5558 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5559 | if (appctx->ctx.sess.target) { |
| 5560 | 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] | 5561 | goto next_sess; |
| 5562 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5563 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5564 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5565 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5566 | return 0; |
| 5567 | |
| 5568 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5569 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5570 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5571 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5572 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5573 | break; |
| 5574 | } |
| 5575 | else |
| 5576 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5577 | } |
| 5578 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5579 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5580 | "%p: proto=%s", |
| 5581 | curr_sess, |
| 5582 | curr_sess->listener->proto->name); |
| 5583 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5584 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5585 | conn = objt_conn(curr_sess->si[0].end); |
| 5586 | 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] | 5587 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5588 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5589 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5590 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5591 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5592 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5593 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5594 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5595 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5596 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5597 | break; |
| 5598 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5599 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5600 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5601 | curr_sess->listener->luid, |
| 5602 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5603 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5604 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5605 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5606 | break; |
| 5607 | } |
| 5608 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5609 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5610 | " ts=%02x age=%s calls=%d", |
| 5611 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5612 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5613 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5614 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5615 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5616 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5617 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5618 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5619 | curr_sess->req->analysers, |
| 5620 | curr_sess->req->rex ? |
| 5621 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 5622 | TICKS_TO_MS(1000)) : ""); |
| 5623 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5624 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5625 | ",wx=%s", |
| 5626 | curr_sess->req->wex ? |
| 5627 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 5628 | TICKS_TO_MS(1000)) : ""); |
| 5629 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5630 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5631 | ",ax=%s]", |
| 5632 | curr_sess->req->analyse_exp ? |
| 5633 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 5634 | TICKS_TO_MS(1000)) : ""); |
| 5635 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5636 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5637 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5638 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5639 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5640 | curr_sess->rep->analysers, |
| 5641 | curr_sess->rep->rex ? |
| 5642 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5643 | TICKS_TO_MS(1000)) : ""); |
| 5644 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5645 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5646 | ",wx=%s", |
| 5647 | curr_sess->rep->wex ? |
| 5648 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 5649 | TICKS_TO_MS(1000)) : ""); |
| 5650 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5651 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5652 | ",ax=%s]", |
| 5653 | curr_sess->rep->analyse_exp ? |
| 5654 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5655 | TICKS_TO_MS(1000)) : ""); |
| 5656 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5657 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5658 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5659 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5660 | curr_sess->si[0].state, |
| 5661 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5662 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5663 | curr_sess->si[0].exp ? |
| 5664 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5665 | TICKS_TO_MS(1000)) : ""); |
| 5666 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5667 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5668 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5669 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5670 | curr_sess->si[1].state, |
| 5671 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5672 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5673 | curr_sess->si[1].exp ? |
| 5674 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5675 | TICKS_TO_MS(1000)) : ""); |
| 5676 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5677 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5678 | " exp=%s", |
| 5679 | curr_sess->task->expire ? |
| 5680 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5681 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5682 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5683 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5684 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5685 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5686 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5687 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5688 | /* let's try again later from this session. We add ourselves into |
| 5689 | * this session's users so that it can remove us upon termination. |
| 5690 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5691 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5692 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5693 | } |
| 5694 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5695 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5696 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5697 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5698 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5699 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5700 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5701 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5702 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5703 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5704 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5705 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5706 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5707 | return 0; |
| 5708 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5709 | appctx->ctx.sess.target = NULL; |
| 5710 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5711 | return 1; |
| 5712 | } |
| 5713 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5714 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5715 | /* fall through */ |
| 5716 | |
| 5717 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5718 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5719 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5720 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5721 | } |
| 5722 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5723 | /* This is called when the stream interface is closed. For instance, upon an |
| 5724 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5725 | * remove back references to the session currently being dumped. |
| 5726 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5727 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5728 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5729 | struct appctx *appctx = __objt_appctx(si->end); |
| 5730 | |
| 5731 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5732 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5733 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5734 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5735 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5736 | free(appctx->ctx.cli.err); |
| 5737 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5738 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5739 | free(appctx->ctx.map.chunk.str); |
| 5740 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5741 | } |
| 5742 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5743 | /* This function is used to either dump tables states (when action is set |
| 5744 | * 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] | 5745 | * It returns 0 if the output buffer is full and it needs to be called |
| 5746 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5747 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5748 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5749 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5750 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5751 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5752 | struct ebmb_node *eb; |
| 5753 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5754 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5755 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5756 | |
| 5757 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5758 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5759 | * - STAT_ST_INIT : the first call |
| 5760 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5761 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5762 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5763 | * and the entry pointer points to the next entry to be dumped, |
| 5764 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5765 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5766 | * data though. |
| 5767 | */ |
| 5768 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5769 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5770 | /* 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] | 5771 | if (appctx->st2 == STAT_ST_LIST) { |
| 5772 | appctx->ctx.table.entry->ref_cnt--; |
| 5773 | 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] | 5774 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5775 | return 1; |
| 5776 | } |
| 5777 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5778 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5779 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5780 | while (appctx->st2 != STAT_ST_FIN) { |
| 5781 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5782 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5783 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5784 | if (!appctx->ctx.table.proxy) |
| 5785 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5786 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5787 | appctx->ctx.table.entry = NULL; |
| 5788 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5789 | break; |
| 5790 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5791 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5792 | if (!appctx->ctx.table.proxy || |
| 5793 | (appctx->ctx.table.target && |
| 5794 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5795 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5796 | break; |
| 5797 | } |
| 5798 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5799 | if (appctx->ctx.table.proxy->table.size) { |
| 5800 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5801 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5802 | return 0; |
| 5803 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5804 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5805 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5806 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5807 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5808 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5809 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5810 | appctx->ctx.table.entry->ref_cnt++; |
| 5811 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5812 | break; |
| 5813 | } |
| 5814 | } |
| 5815 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5816 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5817 | break; |
| 5818 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5819 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5820 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5821 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5822 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5823 | /* we're filtering on some data contents */ |
| 5824 | void *ptr; |
| 5825 | long long data; |
| 5826 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5827 | dt = appctx->ctx.table.data_type; |
| 5828 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5829 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5830 | dt); |
| 5831 | |
| 5832 | data = 0; |
| 5833 | switch (stktable_data_types[dt].std_type) { |
| 5834 | case STD_T_SINT: |
| 5835 | data = stktable_data_cast(ptr, std_t_sint); |
| 5836 | break; |
| 5837 | case STD_T_UINT: |
| 5838 | data = stktable_data_cast(ptr, std_t_uint); |
| 5839 | break; |
| 5840 | case STD_T_ULL: |
| 5841 | data = stktable_data_cast(ptr, std_t_ull); |
| 5842 | break; |
| 5843 | case STD_T_FRQP: |
| 5844 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5845 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5846 | break; |
| 5847 | } |
| 5848 | |
| 5849 | /* 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] | 5850 | if ((data < appctx->ctx.table.value && |
| 5851 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5852 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5853 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5854 | (data == appctx->ctx.table.value && |
| 5855 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5856 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5857 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5858 | (data > appctx->ctx.table.value && |
| 5859 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5860 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5861 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5862 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5863 | } |
| 5864 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5865 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5866 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5867 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5868 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5869 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5870 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5871 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5872 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5873 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5874 | struct stksess *old = appctx->ctx.table.entry; |
| 5875 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5876 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5877 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5878 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5879 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5880 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5881 | break; |
| 5882 | } |
| 5883 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5884 | |
| 5885 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5886 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5887 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5888 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5889 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5890 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5891 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5892 | break; |
| 5893 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5894 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5895 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5896 | break; |
| 5897 | } |
| 5898 | } |
| 5899 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5900 | } |
| 5901 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5902 | /* 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] | 5903 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5904 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5905 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5906 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5907 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5908 | * after the offset. The new pointer is returned. |
| 5909 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5910 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5911 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5912 | { |
| 5913 | int end; |
| 5914 | unsigned char c; |
| 5915 | |
| 5916 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5917 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5918 | return ptr; |
| 5919 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5920 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5921 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5922 | while (ptr < len && ptr < bsize) { |
| 5923 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5924 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5925 | if (out->len > end - 2) |
| 5926 | break; |
| 5927 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5928 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5929 | if (out->len > end - 3) |
| 5930 | break; |
| 5931 | out->str[out->len++] = '\\'; |
| 5932 | switch (c) { |
| 5933 | case '\t': c = 't'; break; |
| 5934 | case '\n': c = 'n'; break; |
| 5935 | case '\r': c = 'r'; break; |
| 5936 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5937 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5938 | } |
| 5939 | out->str[out->len++] = c; |
| 5940 | } else { |
| 5941 | if (out->len > end - 5) |
| 5942 | break; |
| 5943 | out->str[out->len++] = '\\'; |
| 5944 | out->str[out->len++] = 'x'; |
| 5945 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5946 | out->str[out->len++] = hextab[c & 0xF]; |
| 5947 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5948 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5949 | /* we had a line break, let's return now */ |
| 5950 | out->str[out->len++] = '\n'; |
| 5951 | *line = ptr; |
| 5952 | return ptr; |
| 5953 | } |
| 5954 | } |
| 5955 | /* we have an incomplete line, we return it as-is */ |
| 5956 | out->str[out->len++] = '\n'; |
| 5957 | return ptr; |
| 5958 | } |
| 5959 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5960 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5961 | * 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] | 5962 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5963 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5964 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5965 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5966 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5967 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5968 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5969 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5970 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5971 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5972 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5973 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5974 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5975 | /* the function had not been called yet, let's prepare the |
| 5976 | * buffer for a response. |
| 5977 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5978 | struct tm tm; |
| 5979 | |
| 5980 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5981 | 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] | 5982 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5983 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5984 | error_snapshot_id); |
| 5985 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5986 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5987 | /* Socket buffer full. Let's try again later from the same point */ |
| 5988 | return 0; |
| 5989 | } |
| 5990 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5991 | appctx->ctx.errors.px = proxy; |
| 5992 | appctx->ctx.errors.buf = 0; |
| 5993 | appctx->ctx.errors.bol = 0; |
| 5994 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5995 | } |
| 5996 | |
| 5997 | /* we have two inner loops here, one for the proxy, the other one for |
| 5998 | * the buffer. |
| 5999 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6000 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6001 | struct error_snapshot *es; |
| 6002 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6003 | if (appctx->ctx.errors.buf == 0) |
| 6004 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6005 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6006 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6007 | |
| 6008 | if (!es->when.tv_sec) |
| 6009 | goto next; |
| 6010 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6011 | if (appctx->ctx.errors.iid >= 0 && |
| 6012 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6013 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6014 | goto next; |
| 6015 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6016 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6017 | /* just print headers now */ |
| 6018 | |
| 6019 | char pn[INET6_ADDRSTRLEN]; |
| 6020 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6021 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6022 | |
| 6023 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6024 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6025 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6026 | 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] | 6027 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6028 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6029 | case AF_INET: |
| 6030 | case AF_INET6: |
| 6031 | port = get_host_port(&es->src); |
| 6032 | break; |
| 6033 | default: |
| 6034 | port = 0; |
| 6035 | } |
| 6036 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6037 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6038 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6039 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6040 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6041 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6042 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6043 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6044 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6045 | break; |
| 6046 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6047 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame^] | 6048 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6049 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6050 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6051 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6052 | break; |
| 6053 | } |
| 6054 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6055 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6056 | ", server %s (#%d), event #%u\n" |
| 6057 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6058 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6059 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6060 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6061 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6062 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6063 | es->ev_id, |
| 6064 | pn, port, es->sid, es->s_flags, |
| 6065 | es->state, es->m_flags, es->t_flags, |
| 6066 | es->m_clen, es->m_blen, |
| 6067 | es->b_flags, es->b_out, es->b_tot, |
| 6068 | es->len, es->b_wrap, es->pos); |
| 6069 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6070 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6071 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6072 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6073 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6074 | appctx->ctx.errors.ptr = 0; |
| 6075 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6076 | } |
| 6077 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6078 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6079 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6080 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6081 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6082 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6083 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6084 | goto next; |
| 6085 | } |
| 6086 | |
| 6087 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6088 | 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] | 6089 | int newptr; |
| 6090 | int newline; |
| 6091 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6092 | newline = appctx->ctx.errors.bol; |
| 6093 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6094 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6095 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6096 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6097 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6098 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6099 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6100 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6101 | appctx->ctx.errors.ptr = newptr; |
| 6102 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6103 | }; |
| 6104 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6105 | appctx->ctx.errors.bol = 0; |
| 6106 | appctx->ctx.errors.ptr = -1; |
| 6107 | appctx->ctx.errors.buf++; |
| 6108 | if (appctx->ctx.errors.buf > 1) { |
| 6109 | appctx->ctx.errors.buf = 0; |
| 6110 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6111 | } |
| 6112 | } |
| 6113 | |
| 6114 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6115 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6116 | } |
| 6117 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6118 | /* parse the "level" argument on the bind lines */ |
| 6119 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6120 | { |
| 6121 | if (!*args[cur_arg + 1]) { |
| 6122 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6123 | return ERR_ALERT | ERR_FATAL; |
| 6124 | } |
| 6125 | |
| 6126 | if (!strcmp(args[cur_arg+1], "user")) |
| 6127 | conf->level = ACCESS_LVL_USER; |
| 6128 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6129 | conf->level = ACCESS_LVL_OPER; |
| 6130 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6131 | conf->level = ACCESS_LVL_ADMIN; |
| 6132 | else { |
| 6133 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6134 | args[cur_arg], args[cur_arg+1]); |
| 6135 | return ERR_ALERT | ERR_FATAL; |
| 6136 | } |
| 6137 | |
| 6138 | return 0; |
| 6139 | } |
| 6140 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6141 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6142 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6143 | .name = "<STATS>", /* used for logging */ |
| 6144 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6145 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6146 | }; |
| 6147 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6148 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6149 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6150 | .name = "<CLI>", /* used for logging */ |
| 6151 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6152 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6153 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6154 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6155 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6156 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6157 | { 0, NULL, NULL }, |
| 6158 | }}; |
| 6159 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6160 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6161 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6162 | { NULL, NULL, 0 }, |
| 6163 | }}; |
| 6164 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6165 | __attribute__((constructor)) |
| 6166 | static void __dumpstats_module_init(void) |
| 6167 | { |
| 6168 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6169 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6170 | } |
| 6171 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6172 | /* |
| 6173 | * Local variables: |
| 6174 | * c-indent-level: 8 |
| 6175 | * c-basic-offset: 8 |
| 6176 | * End: |
| 6177 | */ |