Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 2 | * Functions dedicated to statistics output and the stats socket |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 27 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/debug.h> |
| 31 | #include <common/memory.h> |
| 32 | #include <common/mini-clist.h> |
| 33 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 34 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 35 | #include <common/time.h> |
| 36 | #include <common/uri_auth.h> |
| 37 | #include <common/version.h> |
| 38 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | |
| 41 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 42 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 43 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 44 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 45 | #include <proto/dumpstats.h> |
| 46 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 47 | #include <proto/freq_ctr.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 48 | #include <proto/log.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 49 | #include <proto/pattern.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 50 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 51 | #include <proto/listener.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 52 | #include <proto/map.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 53 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 54 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 55 | #include <proto/proxy.h> |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 56 | #include <proto/sample.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 57 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 58 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 59 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 60 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 61 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 62 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 63 | #ifdef USE_OPENSSL |
| 64 | #include <proto/ssl_sock.h> |
| 65 | #endif |
| 66 | |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 67 | /* stats socket states */ |
| 68 | enum { |
| 69 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 70 | STAT_CLI_END, /* final state, let's close */ |
| 71 | STAT_CLI_GETREQ, /* wait for a request */ |
| 72 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 73 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 74 | STAT_CLI_PRINT, /* display message in cli->msg */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 75 | STAT_CLI_PRINT_FREE, /* display message in cli->msg. After the display, free the pointer */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 76 | STAT_CLI_O_INFO, /* dump info */ |
| 77 | STAT_CLI_O_SESS, /* dump sessions */ |
| 78 | STAT_CLI_O_ERR, /* dump errors */ |
| 79 | STAT_CLI_O_TAB, /* dump tables */ |
| 80 | STAT_CLI_O_CLR, /* clear tables */ |
| 81 | STAT_CLI_O_SET, /* set entries in tables */ |
| 82 | STAT_CLI_O_STAT, /* dump stats */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 83 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 84 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 85 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 86 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 89 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 90 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 91 | 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] | 92 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 93 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 94 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 95 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 96 | 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] | 97 | static int stats_pats_list(struct stream_interface *si); |
| 98 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 99 | static int stats_map_lookup(struct stream_interface *si); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 100 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 101 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 102 | * cli_io_handler() |
| 103 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 104 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 105 | * -> stats_dump_info_to_buffer() // "show info" |
| 106 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 107 | * -> stats_dump_csv_header() |
| 108 | * -> stats_dump_proxy_to_buffer() |
| 109 | * -> stats_dump_fe_stats() |
| 110 | * -> stats_dump_li_stats() |
| 111 | * -> stats_dump_sv_stats() |
| 112 | * -> stats_dump_be_stats() |
| 113 | * |
| 114 | * http_stats_io_handler() |
| 115 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 116 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 117 | * -> stats_dump_html_head() // emits the HTML headers |
| 118 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 119 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 120 | * -> stats_dump_html_px_hdr() |
| 121 | * -> stats_dump_fe_stats() |
| 122 | * -> stats_dump_li_stats() |
| 123 | * -> stats_dump_sv_stats() |
| 124 | * -> stats_dump_be_stats() |
| 125 | * -> stats_dump_html_px_end() |
| 126 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 127 | */ |
| 128 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 129 | static struct si_applet cli_applet; |
| 130 | |
| 131 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 132 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 133 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 134 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 135 | " help : this message\n" |
| 136 | " prompt : toggle interactive mode with prompt\n" |
| 137 | " quit : disconnect\n" |
| 138 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 139 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 140 | " show stat : report counters for each proxy and server\n" |
| 141 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 142 | " 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] | 143 | " 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] | 144 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 145 | " set weight : change a server's weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 146 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 147 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 148 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 149 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 150 | " disable : put a server or frontend in maintenance mode\n" |
| 151 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 152 | " 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] | 153 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 154 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 155 | " add acl : add acl entry\n" |
| 156 | " del acl : delete acl entry\n" |
| 157 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 158 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 159 | " get map : reports the keys and values matching a sample for a map\n" |
| 160 | " set map : modify map entry\n" |
| 161 | " add map : add map entry\n" |
| 162 | " del map : delete map entry\n" |
| 163 | " clear map <id> : clear the content of this map\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 164 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 165 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 166 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 167 | "Permission denied\n" |
| 168 | ""; |
| 169 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 170 | /* data transmission states for the stats responses */ |
| 171 | enum { |
| 172 | STAT_ST_INIT = 0, |
| 173 | STAT_ST_HEAD, |
| 174 | STAT_ST_INFO, |
| 175 | STAT_ST_LIST, |
| 176 | STAT_ST_END, |
| 177 | STAT_ST_FIN, |
| 178 | }; |
| 179 | |
| 180 | /* data transmission states for the stats responses inside a proxy */ |
| 181 | enum { |
| 182 | STAT_PX_ST_INIT = 0, |
| 183 | STAT_PX_ST_TH, |
| 184 | STAT_PX_ST_FE, |
| 185 | STAT_PX_ST_LI, |
| 186 | STAT_PX_ST_SV, |
| 187 | STAT_PX_ST_BE, |
| 188 | STAT_PX_ST_END, |
| 189 | STAT_PX_ST_FIN, |
| 190 | }; |
| 191 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 192 | extern const char *stat_status_codes[]; |
| 193 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 194 | /* 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] | 195 | * 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] | 196 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 197 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 198 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 199 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 200 | s->target = &cli_applet.obj_type; |
Willy Tarreau | 4171e9e | 2013-12-01 12:32:30 +0100 | [diff] [blame] | 201 | /* 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] | 202 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 203 | tv_zero(&s->logs.tv_request); |
| 204 | s->logs.t_queue = 0; |
| 205 | s->logs.t_connect = 0; |
| 206 | s->logs.t_data = 0; |
| 207 | s->logs.t_close = 0; |
| 208 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 209 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 210 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 211 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 212 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 213 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 214 | if (s->listener->timeout) { |
| 215 | s->req->rto = *s->listener->timeout; |
| 216 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 217 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 218 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 221 | /* allocate a new stats frontend named <name>, and return it |
| 222 | * (or NULL in case of lack of memory). |
| 223 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 224 | 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] | 225 | { |
| 226 | struct proxy *fe; |
| 227 | |
| 228 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 229 | if (!fe) |
| 230 | return NULL; |
| 231 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 232 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 233 | fe->next = proxy; |
| 234 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 235 | fe->last_change = now.tv_sec; |
| 236 | fe->id = strdup("GLOBAL"); |
| 237 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 238 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 239 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 240 | fe->conf.file = strdup(file); |
| 241 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 242 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 243 | |
| 244 | /* the stats frontend is the only one able to assign ID #0 */ |
| 245 | fe->conf.id.key = fe->uuid = 0; |
| 246 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 247 | return fe; |
| 248 | } |
| 249 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 250 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 251 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 252 | * error message into the <err> buffer which will be preallocated. The trailing |
| 253 | * '\n' must not be written. The function must be called with <args> pointing to |
| 254 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 255 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 256 | 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] | 257 | struct proxy *defpx, const char *file, int line, |
| 258 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 259 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 260 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 261 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 262 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 263 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 264 | int cur_arg; |
| 265 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 266 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 267 | 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] | 268 | return -1; |
| 269 | } |
| 270 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 271 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 272 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 273 | 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] | 274 | return -1; |
| 275 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 276 | } |
| 277 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 278 | 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] | 279 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 280 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 281 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 282 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 283 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 284 | return -1; |
| 285 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 286 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 287 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 288 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 289 | static int bind_dumped; |
| 290 | struct bind_kw *kw; |
| 291 | |
| 292 | kw = bind_find_kw(args[cur_arg]); |
| 293 | if (kw) { |
| 294 | if (!kw->parse) { |
| 295 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 296 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 297 | return -1; |
| 298 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 299 | |
| 300 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 301 | if (err && *err) |
| 302 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 303 | else |
| 304 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 305 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 306 | return -1; |
| 307 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 308 | |
| 309 | cur_arg += 1 + kw->skip; |
| 310 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 311 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 312 | |
| 313 | if (!bind_dumped) { |
| 314 | bind_dump_kws(err); |
| 315 | indent_msg(err, 4); |
| 316 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 317 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 318 | |
| 319 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 320 | args[0], args[1], args[cur_arg], |
| 321 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 322 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 323 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 324 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 325 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 326 | l->maxconn = global.stats_fe->maxconn; |
| 327 | l->backlog = global.stats_fe->backlog; |
| 328 | l->timeout = &global.stats_fe->timeout.client; |
| 329 | l->accept = session_accept; |
| 330 | l->handler = process_session; |
| 331 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 332 | l->nice = -64; /* we want to boost priority for local stats */ |
| 333 | global.maxsock += l->maxconn; |
| 334 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 335 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 336 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 337 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 338 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 339 | |
| 340 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 341 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 342 | return -1; |
| 343 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 344 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 345 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 346 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 347 | return -1; |
| 348 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 349 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 350 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 351 | 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] | 352 | return -1; |
| 353 | } |
| 354 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 355 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 356 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 357 | else if (!strcmp(args[1], "maxconn")) { |
| 358 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 359 | |
| 360 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 361 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 362 | return -1; |
| 363 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 364 | |
| 365 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 366 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 367 | 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] | 368 | return -1; |
| 369 | } |
| 370 | } |
| 371 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 372 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 373 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 374 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 375 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 376 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 377 | if (!global.stats_fe) { |
| 378 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 379 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 380 | return -1; |
| 381 | } |
| 382 | } |
| 383 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 384 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 385 | unsigned int low, high; |
| 386 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 387 | if (strcmp(args[cur_arg], "all") == 0) { |
| 388 | set = 0; |
| 389 | break; |
| 390 | } |
| 391 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 392 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 393 | } |
| 394 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 395 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 396 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 397 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 398 | char *dash = strchr(args[cur_arg], '-'); |
| 399 | |
| 400 | low = high = str2uic(args[cur_arg]); |
| 401 | if (dash) |
| 402 | high = str2uic(dash + 1); |
| 403 | |
| 404 | if (high < low) { |
| 405 | unsigned int swap = low; |
| 406 | low = high; |
| 407 | high = swap; |
| 408 | } |
| 409 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 410 | if (low < 1 || high > LONGBITS) { |
| 411 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 412 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 413 | return -1; |
| 414 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 415 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 416 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 417 | } |
| 418 | else { |
| 419 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 420 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 421 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 422 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 423 | } |
| 424 | cur_arg++; |
| 425 | } |
| 426 | global.stats_fe->bind_proc = set; |
| 427 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 428 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 429 | 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] | 430 | return -1; |
| 431 | } |
| 432 | return 0; |
| 433 | } |
| 434 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 435 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 436 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 437 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 438 | * 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] | 439 | */ |
| 440 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 441 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 442 | chunk_appendf(&trash, |
| 443 | "# pxname,svname," |
| 444 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 445 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 446 | "bin,bout," |
| 447 | "dreq,dresp," |
| 448 | "ereq,econ,eresp," |
| 449 | "wretr,wredis," |
| 450 | "status,weight,act,bck," |
| 451 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 452 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 453 | "rate,rate_lim,rate_max," |
| 454 | "check_status,check_code,check_duration," |
| 455 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 456 | "req_rate,req_rate_max,req_tot," |
| 457 | "cli_abrt,srv_abrt," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 458 | "comp_in,comp_out,comp_byp,comp_rsp,lastsess," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 459 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 460 | } |
| 461 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 462 | /* print a string of text buffer to <out>. The format is : |
| 463 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 464 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 465 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 466 | */ |
| 467 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 468 | { |
| 469 | unsigned char c; |
| 470 | int ptr = 0; |
| 471 | |
| 472 | while (buf[ptr] && ptr < bsize) { |
| 473 | c = buf[ptr]; |
| 474 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 475 | if (out->len > out->size - 1) |
| 476 | break; |
| 477 | out->str[out->len++] = c; |
| 478 | } |
| 479 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 480 | if (out->len > out->size - 2) |
| 481 | break; |
| 482 | out->str[out->len++] = '\\'; |
| 483 | switch (c) { |
| 484 | case ' ': c = ' '; break; |
| 485 | case '\t': c = 't'; break; |
| 486 | case '\n': c = 'n'; break; |
| 487 | case '\r': c = 'r'; break; |
| 488 | case '\e': c = 'e'; break; |
| 489 | case '\\': c = '\\'; break; |
| 490 | } |
| 491 | out->str[out->len++] = c; |
| 492 | } |
| 493 | else { |
| 494 | if (out->len > out->size - 4) |
| 495 | break; |
| 496 | out->str[out->len++] = '\\'; |
| 497 | out->str[out->len++] = 'x'; |
| 498 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 499 | out->str[out->len++] = hextab[c & 0xF]; |
| 500 | } |
| 501 | ptr++; |
| 502 | } |
| 503 | |
| 504 | return ptr; |
| 505 | } |
| 506 | |
| 507 | /* print a buffer in hexa. |
| 508 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 509 | */ |
| 510 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 511 | { |
| 512 | unsigned char c; |
| 513 | int ptr = 0; |
| 514 | |
| 515 | while (ptr < bsize) { |
| 516 | c = buf[ptr]; |
| 517 | |
| 518 | if (out->len > out->size - 2) |
| 519 | break; |
| 520 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 521 | out->str[out->len++] = hextab[c & 0xF]; |
| 522 | |
| 523 | ptr++; |
| 524 | } |
| 525 | return ptr; |
| 526 | } |
| 527 | |
| 528 | /* Dump the status of a table to a stream interface's |
| 529 | * read buffer. It returns 0 if the output buffer is full |
| 530 | * and needs to be called again, otherwise non-zero. |
| 531 | */ |
| 532 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 533 | struct proxy *proxy, struct proxy *target) |
| 534 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 535 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 536 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 537 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 538 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 539 | |
| 540 | /* any other information should be dumped here */ |
| 541 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 542 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 543 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 544 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 545 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 546 | return 0; |
| 547 | |
| 548 | return 1; |
| 549 | } |
| 550 | |
| 551 | /* Dump the a table entry to a stream interface's |
| 552 | * read buffer. It returns 0 if the output buffer is full |
| 553 | * and needs to be called again, otherwise non-zero. |
| 554 | */ |
| 555 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 556 | struct proxy *proxy, struct stksess *entry) |
| 557 | { |
| 558 | int dt; |
| 559 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 560 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 561 | |
| 562 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 563 | char addr[INET_ADDRSTRLEN]; |
| 564 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 565 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 566 | } |
| 567 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 568 | char addr[INET6_ADDRSTRLEN]; |
| 569 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 570 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 571 | } |
| 572 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 573 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 574 | } |
| 575 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 576 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 577 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 578 | } |
| 579 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 580 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 581 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 582 | } |
| 583 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 584 | 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] | 585 | |
| 586 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 587 | void *ptr; |
| 588 | |
| 589 | if (proxy->table.data_ofs[dt] == 0) |
| 590 | continue; |
| 591 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 592 | 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] | 593 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 594 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 595 | |
| 596 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 597 | switch (stktable_data_types[dt].std_type) { |
| 598 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 599 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 600 | break; |
| 601 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 602 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 603 | break; |
| 604 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 605 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 606 | break; |
| 607 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 608 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 609 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 610 | proxy->table.data_arg[dt].u)); |
| 611 | break; |
| 612 | } |
| 613 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 614 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 615 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 616 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 617 | return 0; |
| 618 | |
| 619 | return 1; |
| 620 | } |
| 621 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 622 | 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] | 623 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 624 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 625 | struct appctx *appctx = __objt_appctx(si->end); |
| 626 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 627 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 628 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 629 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 630 | long long value; |
| 631 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 632 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 633 | void *ptr; |
| 634 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 635 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 636 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 637 | |
| 638 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 639 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 640 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 641 | return; |
| 642 | } |
| 643 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 644 | switch (px->table.type) { |
| 645 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 646 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 647 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 648 | break; |
| 649 | case STKTABLE_TYPE_IPV6: |
| 650 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 651 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 652 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 653 | case STKTABLE_TYPE_INTEGER: |
| 654 | { |
| 655 | char *endptr; |
| 656 | unsigned long val; |
| 657 | errno = 0; |
| 658 | val = strtoul(args[4], &endptr, 10); |
| 659 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 660 | (errno != 0 && val == 0) || endptr == args[4] || |
| 661 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 662 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 663 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 664 | return; |
| 665 | } |
| 666 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 667 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 668 | break; |
| 669 | } |
| 670 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 671 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 672 | static_table_key->key = args[4]; |
| 673 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 674 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 675 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 676 | switch (action) { |
| 677 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 678 | 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] | 679 | break; |
| 680 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 681 | 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] | 682 | break; |
| 683 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 684 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 685 | break; |
| 686 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 687 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 688 | return; |
| 689 | } |
| 690 | |
| 691 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 692 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 693 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 694 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 695 | return; |
| 696 | } |
| 697 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 698 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 699 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 700 | switch (action) { |
| 701 | case STAT_CLI_O_TAB: |
| 702 | if (!ts) |
| 703 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 704 | chunk_reset(&trash); |
| 705 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 706 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 707 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 708 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 709 | |
| 710 | case STAT_CLI_O_CLR: |
| 711 | if (!ts) |
| 712 | return; |
| 713 | if (ts->ref_cnt) { |
| 714 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 715 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 716 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 717 | return; |
| 718 | } |
| 719 | stksess_kill(&px->table, ts); |
| 720 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 721 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 722 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 723 | if (ts) |
| 724 | stktable_touch(&px->table, ts, 1); |
| 725 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 726 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 727 | if (!ts) { |
| 728 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 729 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 730 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 731 | return; |
| 732 | } |
| 733 | stktable_store(&px->table, ts, 1); |
| 734 | } |
| 735 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 736 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 737 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 738 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 739 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 740 | return; |
| 741 | } |
| 742 | |
| 743 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 744 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 745 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 746 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 747 | return; |
| 748 | } |
| 749 | |
| 750 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 751 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 752 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 753 | return; |
| 754 | } |
| 755 | |
| 756 | 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] | 757 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 758 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 759 | return; |
| 760 | } |
| 761 | |
| 762 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 763 | |
| 764 | switch (stktable_data_types[data_type].std_type) { |
| 765 | case STD_T_SINT: |
| 766 | stktable_data_cast(ptr, std_t_sint) = value; |
| 767 | break; |
| 768 | case STD_T_UINT: |
| 769 | stktable_data_cast(ptr, std_t_uint) = value; |
| 770 | break; |
| 771 | case STD_T_ULL: |
| 772 | stktable_data_cast(ptr, std_t_ull) = value; |
| 773 | break; |
| 774 | case STD_T_FRQP: |
| 775 | /* We set both the current and previous values. That way |
| 776 | * the reported frequency is stable during all the period |
| 777 | * then slowly fades out. This allows external tools to |
| 778 | * push measures without having to update them too often. |
| 779 | */ |
| 780 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 781 | frqp->curr_tick = now_ms; |
| 782 | frqp->prev_ctr = 0; |
| 783 | frqp->curr_ctr = value; |
| 784 | break; |
| 785 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 786 | } |
| 787 | break; |
| 788 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 789 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 790 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 791 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 792 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 793 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 794 | } |
| 795 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 796 | 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] | 797 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 798 | struct appctx *appctx = __objt_appctx(si->end); |
| 799 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 800 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 801 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 802 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 803 | return; |
| 804 | } |
| 805 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 806 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 807 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 808 | if (appctx->ctx.table.data_type < 0) { |
| 809 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 810 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 811 | return; |
| 812 | } |
| 813 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 814 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 815 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 816 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 817 | return; |
| 818 | } |
| 819 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 820 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 821 | if (appctx->ctx.table.data_op < 0) { |
| 822 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 823 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 824 | return; |
| 825 | } |
| 826 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 827 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 828 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 829 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 830 | return; |
| 831 | } |
| 832 | } |
| 833 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 834 | 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] | 835 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 836 | struct appctx *appctx = __objt_appctx(si->end); |
| 837 | |
| 838 | appctx->ctx.table.data_type = -1; |
| 839 | appctx->st2 = STAT_ST_INIT; |
| 840 | appctx->ctx.table.target = NULL; |
| 841 | appctx->ctx.table.proxy = NULL; |
| 842 | appctx->ctx.table.entry = NULL; |
| 843 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 844 | |
| 845 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 846 | appctx->ctx.table.target = find_stktable(args[2]); |
| 847 | if (!appctx->ctx.table.target) { |
| 848 | appctx->ctx.cli.msg = "No such table\n"; |
| 849 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 850 | return; |
| 851 | } |
| 852 | } |
| 853 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 854 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 855 | goto err_args; |
| 856 | return; |
| 857 | } |
| 858 | |
| 859 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 860 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 861 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 862 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 863 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 864 | goto err_args; |
| 865 | |
| 866 | return; |
| 867 | |
| 868 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 869 | switch (action) { |
| 870 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 871 | 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] | 872 | break; |
| 873 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 874 | 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] | 875 | break; |
| 876 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 877 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 878 | break; |
| 879 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 880 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 881 | } |
| 882 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 883 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 884 | * adequate error messages and returns NULL. This function also expects the session |
| 885 | * level to be admin. |
| 886 | */ |
| 887 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 888 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 889 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 890 | struct proxy *px; |
| 891 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 892 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 893 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 894 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 895 | return NULL; |
| 896 | } |
| 897 | |
| 898 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 899 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 900 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 901 | return NULL; |
| 902 | } |
| 903 | |
| 904 | px = findproxy(arg, PR_CAP_FE); |
| 905 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 906 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 907 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 908 | return NULL; |
| 909 | } |
| 910 | return px; |
| 911 | } |
| 912 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 913 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 914 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 915 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 916 | * the <arg> is modified to remove the '/'. |
| 917 | */ |
| 918 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 919 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 920 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 921 | struct proxy *px; |
| 922 | struct server *sv; |
| 923 | char *line; |
| 924 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 925 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 926 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 927 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 928 | return NULL; |
| 929 | } |
| 930 | |
| 931 | /* split "backend/server" and make <line> point to server */ |
| 932 | for (line = arg; *line; line++) |
| 933 | if (*line == '/') { |
| 934 | *line++ = '\0'; |
| 935 | break; |
| 936 | } |
| 937 | |
| 938 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 939 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 940 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 941 | return NULL; |
| 942 | } |
| 943 | |
| 944 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 945 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 946 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 947 | return NULL; |
| 948 | } |
| 949 | |
| 950 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 951 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 952 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 953 | return NULL; |
| 954 | } |
| 955 | |
| 956 | return sv; |
| 957 | } |
| 958 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 959 | /* This function is used with map and acl management. It permits to browse |
| 960 | * each reference. The variable <getnext> must contain the current node, |
| 961 | * <end> point to the root node and the <flags> permit to filter required |
| 962 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 963 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 964 | static inline |
| 965 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 966 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 967 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 968 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 969 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 970 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 971 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 972 | /* Get next list entry. */ |
| 973 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 974 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 975 | /* If the entry is the last of the list, return NULL. */ |
| 976 | if (&ref->list == end) |
| 977 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 978 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 979 | /* If the entry match the flag, return it. */ |
| 980 | if (ref->flags & flags) |
| 981 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 985 | static inline |
| 986 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 987 | { |
| 988 | int id; |
| 989 | char *error; |
| 990 | |
| 991 | /* If the reference starts by a '#', this is numeric id. */ |
| 992 | if (reference[0] == '#') { |
| 993 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 994 | id = strtol(reference + 1, &error, 10); |
| 995 | if (*error != '\0') |
| 996 | return NULL; |
| 997 | |
| 998 | /* Perform the unique id lookup. */ |
| 999 | return pat_ref_lookupid(id); |
| 1000 | } |
| 1001 | |
| 1002 | /* Perform the string lookup. */ |
| 1003 | return pat_ref_lookup(reference); |
| 1004 | } |
| 1005 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1006 | /* This function is used with map and acl management. It permits to browse |
| 1007 | * each reference. |
| 1008 | */ |
| 1009 | static inline |
| 1010 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1011 | { |
| 1012 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1013 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1014 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1015 | return NULL; |
| 1016 | return expr; |
| 1017 | } |
| 1018 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1019 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1020 | * 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] | 1021 | * 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] | 1022 | * designating the function which will have to process the request, which can |
| 1023 | * 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] | 1024 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1025 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1026 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 1027 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1028 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1029 | char *args[MAX_STATS_ARGS + 1]; |
| 1030 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1031 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1032 | |
| 1033 | while (isspace((unsigned char)*line)) |
| 1034 | line++; |
| 1035 | |
| 1036 | arg = 0; |
| 1037 | args[arg] = line; |
| 1038 | |
| 1039 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1040 | if (*line == '\\') { |
| 1041 | line++; |
| 1042 | if (*line == '\0') |
| 1043 | break; |
| 1044 | } |
| 1045 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1046 | *line++ = '\0'; |
| 1047 | |
| 1048 | while (isspace((unsigned char)*line)) |
| 1049 | line++; |
| 1050 | |
| 1051 | args[++arg] = line; |
| 1052 | continue; |
| 1053 | } |
| 1054 | |
| 1055 | line++; |
| 1056 | } |
| 1057 | |
| 1058 | while (++arg <= MAX_STATS_ARGS) |
| 1059 | args[arg] = line; |
| 1060 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1061 | /* remove \ */ |
| 1062 | arg = 0; |
| 1063 | while (*args[arg] != '\0') { |
| 1064 | j = 0; |
| 1065 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1066 | if (args[arg][i] == '\\') |
| 1067 | continue; |
| 1068 | args[arg][j] = args[arg][i]; |
| 1069 | j++; |
| 1070 | } |
| 1071 | args[arg][j] = '\0'; |
| 1072 | arg++; |
| 1073 | } |
| 1074 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1075 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1076 | if (strcmp(args[0], "show") == 0) { |
| 1077 | if (strcmp(args[1], "stat") == 0) { |
| 1078 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1079 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1080 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1081 | appctx->ctx.stats.type = atoi(args[3]); |
| 1082 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1083 | } |
| 1084 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1085 | appctx->st2 = STAT_ST_INIT; |
| 1086 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1087 | } |
| 1088 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1089 | appctx->st2 = STAT_ST_INIT; |
| 1090 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1091 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1092 | else if (strcmp(args[1], "pools") == 0) { |
| 1093 | appctx->st2 = STAT_ST_INIT; |
| 1094 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1095 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1096 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1097 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1098 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1099 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1100 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1101 | return 1; |
| 1102 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1103 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1104 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1105 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1106 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1107 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1108 | appctx->ctx.sess.target = NULL; |
| 1109 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1110 | appctx->ctx.sess.pos = 0; |
| 1111 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1112 | } |
| 1113 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1114 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1115 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1116 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1117 | return 1; |
| 1118 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1119 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1120 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1121 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1122 | appctx->ctx.errors.iid = -1; |
| 1123 | appctx->ctx.errors.px = NULL; |
| 1124 | appctx->st2 = STAT_ST_INIT; |
| 1125 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1126 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1127 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1128 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1129 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1130 | else if (strcmp(args[1], "map") == 0 || |
| 1131 | strcmp(args[1], "acl") == 0) { |
| 1132 | |
| 1133 | /* Set ACL or MAP flags. */ |
| 1134 | if (args[1][0] == 'm') |
| 1135 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1136 | else |
| 1137 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1138 | |
| 1139 | /* no parameter: display all map avalaible */ |
| 1140 | if (!*args[2]) { |
| 1141 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1142 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1143 | return 1; |
| 1144 | } |
| 1145 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1146 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1147 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1148 | if (!appctx->ctx.map.ref || |
| 1149 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1150 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1151 | 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] | 1152 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1153 | 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] | 1154 | appctx->st0 = STAT_CLI_PRINT; |
| 1155 | return 1; |
| 1156 | } |
| 1157 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1158 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1159 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1160 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1161 | return 0; |
| 1162 | } |
| 1163 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1164 | else if (strcmp(args[0], "clear") == 0) { |
| 1165 | if (strcmp(args[1], "counters") == 0) { |
| 1166 | struct proxy *px; |
| 1167 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1168 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1169 | int clrall = 0; |
| 1170 | |
| 1171 | if (strcmp(args[2], "all") == 0) |
| 1172 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1173 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1174 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1175 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1176 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1177 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1178 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1179 | return 1; |
| 1180 | } |
| 1181 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1182 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1183 | if (clrall) { |
| 1184 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1185 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1186 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1187 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1188 | px->be_counters.conn_max = 0; |
| 1189 | px->be_counters.p.http.rps_max = 0; |
| 1190 | px->be_counters.sps_max = 0; |
| 1191 | px->be_counters.cps_max = 0; |
| 1192 | px->be_counters.nbpend_max = 0; |
| 1193 | |
| 1194 | px->fe_counters.conn_max = 0; |
| 1195 | px->fe_counters.p.http.rps_max = 0; |
| 1196 | px->fe_counters.sps_max = 0; |
| 1197 | px->fe_counters.cps_max = 0; |
| 1198 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1199 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1200 | |
| 1201 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1202 | if (clrall) |
| 1203 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1204 | else { |
| 1205 | sv->counters.cur_sess_max = 0; |
| 1206 | sv->counters.nbpend_max = 0; |
| 1207 | sv->counters.sps_max = 0; |
| 1208 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1209 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1210 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1211 | if (li->counters) { |
| 1212 | if (clrall) |
| 1213 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1214 | else |
| 1215 | li->counters->conn_max = 0; |
| 1216 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1217 | } |
| 1218 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1219 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1220 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1221 | return 1; |
| 1222 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1223 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1224 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1225 | /* end of processing */ |
| 1226 | return 1; |
| 1227 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1228 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1229 | /* Set ACL or MAP flags. */ |
| 1230 | if (args[1][0] == 'm') |
| 1231 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1232 | else |
| 1233 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1234 | |
| 1235 | /* no parameter */ |
| 1236 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1237 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1238 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1239 | else |
| 1240 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1241 | appctx->st0 = STAT_CLI_PRINT; |
| 1242 | return 1; |
| 1243 | } |
| 1244 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1245 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1246 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1247 | if (!appctx->ctx.map.ref || |
| 1248 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1249 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1250 | 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] | 1251 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1252 | 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] | 1253 | appctx->st0 = STAT_CLI_PRINT; |
| 1254 | return 1; |
| 1255 | } |
| 1256 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1257 | /* Clear all. */ |
| 1258 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1259 | |
| 1260 | /* return response */ |
| 1261 | appctx->ctx.cli.msg = "Done.\n"; |
| 1262 | appctx->st0 = STAT_CLI_PRINT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1263 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1264 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1265 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1266 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1267 | return 0; |
| 1268 | } |
| 1269 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1270 | else if (strcmp(args[0], "get") == 0) { |
| 1271 | if (strcmp(args[1], "weight") == 0) { |
| 1272 | struct proxy *px; |
| 1273 | struct server *sv; |
| 1274 | |
| 1275 | /* split "backend/server" and make <line> point to server */ |
| 1276 | for (line = args[2]; *line; line++) |
| 1277 | if (*line == '/') { |
| 1278 | *line++ = '\0'; |
| 1279 | break; |
| 1280 | } |
| 1281 | |
| 1282 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1283 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1284 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1285 | return 1; |
| 1286 | } |
| 1287 | |
| 1288 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1289 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1290 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1291 | return 1; |
| 1292 | } |
| 1293 | |
| 1294 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1295 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1296 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1297 | return 1; |
| 1298 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1299 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1300 | /* Set flags. */ |
| 1301 | if (args[1][0] == 'm') |
| 1302 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1303 | else |
| 1304 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1305 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1306 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1307 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1308 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1309 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1310 | else |
| 1311 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1312 | appctx->st0 = STAT_CLI_PRINT; |
| 1313 | return 1; |
| 1314 | } |
| 1315 | |
| 1316 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1317 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1318 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1319 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1320 | 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] | 1321 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1322 | 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] | 1323 | appctx->st0 = STAT_CLI_PRINT; |
| 1324 | return 1; |
| 1325 | } |
| 1326 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1327 | /* copy input string. The string must be allocated because |
| 1328 | * it may be used over multiple iterations. It's released |
| 1329 | * at the end and upon abort anyway. |
| 1330 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1331 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1332 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1333 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1334 | if (!appctx->ctx.map.chunk.str) { |
| 1335 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1336 | appctx->st0 = STAT_CLI_PRINT; |
| 1337 | return 1; |
| 1338 | } |
| 1339 | |
| 1340 | /* prepare response */ |
| 1341 | appctx->st2 = STAT_ST_INIT; |
| 1342 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1343 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1344 | else { /* not "get weight" */ |
| 1345 | return 0; |
| 1346 | } |
| 1347 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1348 | else if (strcmp(args[0], "set") == 0) { |
| 1349 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1350 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1351 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1352 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1353 | sv = expect_server_admin(s, si, args[2]); |
| 1354 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1355 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1356 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1357 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1358 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1359 | appctx->ctx.cli.msg = warning; |
| 1360 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1361 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1362 | return 1; |
| 1363 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1364 | else if (strcmp(args[1], "timeout") == 0) { |
| 1365 | if (strcmp(args[2], "cli") == 0) { |
| 1366 | unsigned timeout; |
| 1367 | const char *res; |
| 1368 | |
| 1369 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1370 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1371 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1372 | return 1; |
| 1373 | } |
| 1374 | |
| 1375 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1376 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1377 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1378 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1379 | return 1; |
| 1380 | } |
| 1381 | |
| 1382 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1383 | return 1; |
| 1384 | } |
| 1385 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1386 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1387 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1388 | return 1; |
| 1389 | } |
| 1390 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1391 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1392 | if (strcmp(args[2], "frontend") == 0) { |
| 1393 | struct proxy *px; |
| 1394 | struct listener *l; |
| 1395 | int v; |
| 1396 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1397 | px = expect_frontend_admin(s, si, args[3]); |
| 1398 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1399 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1400 | |
| 1401 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1402 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1403 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1404 | return 1; |
| 1405 | } |
| 1406 | |
| 1407 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1408 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1409 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1410 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1411 | return 1; |
| 1412 | } |
| 1413 | |
| 1414 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1415 | * its listeners. The blocked ones will be dequeued. |
| 1416 | */ |
| 1417 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1418 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1419 | l->maxconn = v; |
| 1420 | if (l->state == LI_FULL) |
| 1421 | resume_listener(l); |
| 1422 | } |
| 1423 | |
| 1424 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1425 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1426 | |
| 1427 | return 1; |
| 1428 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1429 | else if (strcmp(args[2], "global") == 0) { |
| 1430 | int v; |
| 1431 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1432 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1433 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1434 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1435 | return 1; |
| 1436 | } |
| 1437 | |
| 1438 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1439 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1440 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1441 | return 1; |
| 1442 | } |
| 1443 | |
| 1444 | v = atoi(args[3]); |
| 1445 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1446 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1447 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1448 | return 1; |
| 1449 | } |
| 1450 | |
| 1451 | /* check for unlimited values */ |
| 1452 | if (v <= 0) |
| 1453 | v = global.hardmaxconn; |
| 1454 | |
| 1455 | global.maxconn = v; |
| 1456 | |
| 1457 | /* Dequeues all of the listeners waiting for a resource */ |
| 1458 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1459 | dequeue_all_listeners(&global_listener_queue); |
| 1460 | |
| 1461 | return 1; |
| 1462 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1463 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1464 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1465 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1466 | return 1; |
| 1467 | } |
| 1468 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1469 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1470 | if (strcmp(args[2], "connections") == 0) { |
| 1471 | if (strcmp(args[3], "global") == 0) { |
| 1472 | int v; |
| 1473 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1474 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1475 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1476 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1477 | return 1; |
| 1478 | } |
| 1479 | |
| 1480 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1481 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1482 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1483 | return 1; |
| 1484 | } |
| 1485 | |
| 1486 | v = atoi(args[4]); |
| 1487 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1488 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1489 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1490 | return 1; |
| 1491 | } |
| 1492 | |
| 1493 | global.cps_lim = v; |
| 1494 | |
| 1495 | /* Dequeues all of the listeners waiting for a resource */ |
| 1496 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1497 | dequeue_all_listeners(&global_listener_queue); |
| 1498 | |
| 1499 | return 1; |
| 1500 | } |
| 1501 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1502 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1503 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1504 | return 1; |
| 1505 | } |
| 1506 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1507 | else if (strcmp(args[2], "sessions") == 0) { |
| 1508 | if (strcmp(args[3], "global") == 0) { |
| 1509 | int v; |
| 1510 | |
| 1511 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1512 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1513 | appctx->st0 = STAT_CLI_PRINT; |
| 1514 | return 1; |
| 1515 | } |
| 1516 | |
| 1517 | if (!*args[4]) { |
| 1518 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1519 | appctx->st0 = STAT_CLI_PRINT; |
| 1520 | return 1; |
| 1521 | } |
| 1522 | |
| 1523 | v = atoi(args[4]); |
| 1524 | if (v < 0) { |
| 1525 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1526 | appctx->st0 = STAT_CLI_PRINT; |
| 1527 | return 1; |
| 1528 | } |
| 1529 | |
| 1530 | global.sps_lim = v; |
| 1531 | |
| 1532 | /* Dequeues all of the listeners waiting for a resource */ |
| 1533 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1534 | dequeue_all_listeners(&global_listener_queue); |
| 1535 | |
| 1536 | return 1; |
| 1537 | } |
| 1538 | else { |
| 1539 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1540 | appctx->st0 = STAT_CLI_PRINT; |
| 1541 | return 1; |
| 1542 | } |
| 1543 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1544 | #ifdef USE_OPENSSL |
| 1545 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1546 | if (strcmp(args[3], "global") == 0) { |
| 1547 | int v; |
| 1548 | |
| 1549 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1550 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1551 | appctx->st0 = STAT_CLI_PRINT; |
| 1552 | return 1; |
| 1553 | } |
| 1554 | |
| 1555 | if (!*args[4]) { |
| 1556 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1557 | appctx->st0 = STAT_CLI_PRINT; |
| 1558 | return 1; |
| 1559 | } |
| 1560 | |
| 1561 | v = atoi(args[4]); |
| 1562 | if (v < 0) { |
| 1563 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1564 | appctx->st0 = STAT_CLI_PRINT; |
| 1565 | return 1; |
| 1566 | } |
| 1567 | |
| 1568 | global.ssl_lim = v; |
| 1569 | |
| 1570 | /* Dequeues all of the listeners waiting for a resource */ |
| 1571 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1572 | dequeue_all_listeners(&global_listener_queue); |
| 1573 | |
| 1574 | return 1; |
| 1575 | } |
| 1576 | else { |
| 1577 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1578 | appctx->st0 = STAT_CLI_PRINT; |
| 1579 | return 1; |
| 1580 | } |
| 1581 | } |
| 1582 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1583 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1584 | if (strcmp(args[3], "global") == 0) { |
| 1585 | int v; |
| 1586 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1587 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1588 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1589 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1590 | return 1; |
| 1591 | } |
| 1592 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1593 | v = atoi(args[4]); |
| 1594 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1595 | } |
| 1596 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1597 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1598 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1599 | return 1; |
| 1600 | } |
| 1601 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1602 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1603 | 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] | 1604 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1605 | return 1; |
| 1606 | } |
| 1607 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1608 | else if (strcmp(args[1], "table") == 0) { |
| 1609 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1610 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1611 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1612 | char *err; |
| 1613 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1614 | /* Set flags. */ |
| 1615 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1616 | |
| 1617 | /* Expect three parameters: map name, key and new value. */ |
| 1618 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1619 | 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] | 1620 | appctx->st0 = STAT_CLI_PRINT; |
| 1621 | return 1; |
| 1622 | } |
| 1623 | |
| 1624 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1625 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1626 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1627 | 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] | 1628 | appctx->st0 = STAT_CLI_PRINT; |
| 1629 | return 1; |
| 1630 | } |
| 1631 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1632 | /* If the entry identifier start with a '#', it is considered as |
| 1633 | * pointer id |
| 1634 | */ |
| 1635 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1636 | struct pat_ref_elt *ref; |
| 1637 | long long int conv; |
| 1638 | char *error; |
| 1639 | |
| 1640 | /* Convert argument to integer value. */ |
| 1641 | conv = strtoll(&args[3][1], &error, 16); |
| 1642 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1643 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1644 | appctx->st0 = STAT_CLI_PRINT; |
| 1645 | return 1; |
| 1646 | } |
| 1647 | |
| 1648 | /* Convert and check integer to pointer. */ |
| 1649 | ref = (struct pat_ref_elt *)(long)conv; |
| 1650 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1651 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1652 | appctx->st0 = STAT_CLI_PRINT; |
| 1653 | return 1; |
| 1654 | } |
| 1655 | |
| 1656 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1657 | err = NULL; |
| 1658 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1659 | if (err) |
| 1660 | memprintf(&err, "%s.\n", err); |
| 1661 | appctx->ctx.cli.err = err; |
| 1662 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1663 | return 1; |
| 1664 | } |
| 1665 | } |
| 1666 | else { |
| 1667 | /* Else, use the entry identifier as pattern |
| 1668 | * string, and update the value. |
| 1669 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1670 | err = NULL; |
| 1671 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1672 | if (err) |
| 1673 | memprintf(&err, "%s.\n", err); |
| 1674 | appctx->ctx.cli.err = err; |
| 1675 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1676 | return 1; |
| 1677 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1678 | } |
| 1679 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1680 | /* The set is done, send message. */ |
| 1681 | appctx->ctx.cli.msg = "Done.\n"; |
| 1682 | appctx->st0 = STAT_CLI_PRINT; |
| 1683 | return 1; |
| 1684 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1685 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1686 | return 0; |
| 1687 | } |
| 1688 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1689 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1690 | if (strcmp(args[1], "agent") == 0) { |
| 1691 | struct server *sv; |
| 1692 | |
| 1693 | sv = expect_server_admin(s, si, args[2]); |
| 1694 | if (!sv) |
| 1695 | return 1; |
| 1696 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1697 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1698 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1699 | appctx->st0 = STAT_CLI_PRINT; |
| 1700 | return 1; |
| 1701 | } |
| 1702 | |
| 1703 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1704 | return 1; |
| 1705 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1706 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1707 | struct server *sv; |
| 1708 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1709 | sv = expect_server_admin(s, si, args[2]); |
| 1710 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1711 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1712 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 1713 | if (sv->admin & SRV_ADMF_MAINT) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1714 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1715 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1716 | /* If this server tracks the status of another one, |
| 1717 | * we must restore the good status. |
| 1718 | */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 1719 | if (sv->track->state != SRV_ST_STOPPED) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1720 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1721 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1722 | } else { |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 1723 | sv->admin &= ~SRV_ADMF_FMAINT; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1724 | sv->check.state &= ~CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1725 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1726 | } |
| 1727 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1728 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1729 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1733 | return 1; |
| 1734 | } |
| 1735 | else if (strcmp(args[1], "frontend") == 0) { |
| 1736 | struct proxy *px; |
| 1737 | |
| 1738 | px = expect_frontend_admin(s, si, args[2]); |
| 1739 | if (!px) |
| 1740 | return 1; |
| 1741 | |
| 1742 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1743 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1744 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1745 | return 1; |
| 1746 | } |
| 1747 | |
| 1748 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1749 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1750 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1751 | return 1; |
| 1752 | } |
| 1753 | |
| 1754 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1755 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1756 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1757 | return 1; |
| 1758 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1759 | return 1; |
| 1760 | } |
| 1761 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1762 | appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1763 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1764 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1765 | } |
| 1766 | } |
| 1767 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1768 | if (strcmp(args[1], "agent") == 0) { |
| 1769 | struct server *sv; |
| 1770 | |
| 1771 | sv = expect_server_admin(s, si, args[2]); |
| 1772 | if (!sv) |
| 1773 | return 1; |
| 1774 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1775 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1776 | return 1; |
| 1777 | } |
| 1778 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1779 | struct server *sv; |
| 1780 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1781 | sv = expect_server_admin(s, si, args[2]); |
| 1782 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1783 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1784 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 1785 | if (!(sv->admin & SRV_ADMF_MAINT)) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1786 | /* Not already in maintenance, we can change the server state */ |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 1787 | sv->admin |= SRV_ADMF_FMAINT; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1788 | sv->check.state |= CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1789 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1790 | } |
| 1791 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1792 | return 1; |
| 1793 | } |
| 1794 | else if (strcmp(args[1], "frontend") == 0) { |
| 1795 | struct proxy *px; |
| 1796 | |
| 1797 | px = expect_frontend_admin(s, si, args[2]); |
| 1798 | if (!px) |
| 1799 | return 1; |
| 1800 | |
| 1801 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1802 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1803 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1804 | return 1; |
| 1805 | } |
| 1806 | |
| 1807 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1808 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1809 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1810 | return 1; |
| 1811 | } |
| 1812 | |
| 1813 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1814 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1815 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1816 | return 1; |
| 1817 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1818 | return 1; |
| 1819 | } |
| 1820 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1821 | appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1822 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1823 | return 1; |
| 1824 | } |
| 1825 | } |
| 1826 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1827 | if (strcmp(args[1], "frontend") == 0) { |
| 1828 | struct proxy *px; |
| 1829 | |
| 1830 | px = expect_frontend_admin(s, si, args[2]); |
| 1831 | if (!px) |
| 1832 | return 1; |
| 1833 | |
| 1834 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1835 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1836 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1837 | return 1; |
| 1838 | } |
| 1839 | |
| 1840 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1841 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1842 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1843 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1844 | stop_proxy(px); |
| 1845 | return 1; |
| 1846 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1847 | else if (strcmp(args[1], "session") == 0) { |
| 1848 | struct session *sess, *ptr; |
| 1849 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1850 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1851 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1852 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1853 | return 1; |
| 1854 | } |
| 1855 | |
| 1856 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1857 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1858 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1859 | return 1; |
| 1860 | } |
| 1861 | |
| 1862 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1863 | |
| 1864 | /* first, look for the requested session in the session table */ |
| 1865 | list_for_each_entry(sess, &sessions, list) { |
| 1866 | if (sess == ptr) |
| 1867 | break; |
| 1868 | } |
| 1869 | |
| 1870 | /* do we have the session ? */ |
| 1871 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1872 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1873 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1874 | return 1; |
| 1875 | } |
| 1876 | |
| 1877 | session_shutdown(sess, SN_ERR_KILLED); |
| 1878 | return 1; |
| 1879 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1880 | else if (strcmp(args[1], "sessions") == 0) { |
| 1881 | if (strcmp(args[2], "server") == 0) { |
| 1882 | struct server *sv; |
| 1883 | struct session *sess, *sess_bck; |
| 1884 | |
| 1885 | sv = expect_server_admin(s, si, args[3]); |
| 1886 | if (!sv) |
| 1887 | return 1; |
| 1888 | |
| 1889 | /* kill all the session that are on this server */ |
| 1890 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1891 | if (sess->srv_conn == sv) |
| 1892 | session_shutdown(sess, SN_ERR_KILLED); |
| 1893 | |
| 1894 | return 1; |
| 1895 | } |
| 1896 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1897 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1898 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1899 | return 1; |
| 1900 | } |
| 1901 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1902 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1903 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1904 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1905 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1906 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1907 | } |
| 1908 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1909 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1910 | if (args[1][0] == 'm') |
| 1911 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1912 | else |
| 1913 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1914 | |
| 1915 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1916 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 1917 | if (!*args[2] || !*args[3]) { |
| 1918 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 1919 | appctx->st0 = STAT_CLI_PRINT; |
| 1920 | return 1; |
| 1921 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1922 | } |
| 1923 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1924 | else { |
| 1925 | if (!*args[2] || !*args[3]) { |
| 1926 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 1927 | appctx->st0 = STAT_CLI_PRINT; |
| 1928 | return 1; |
| 1929 | } |
| 1930 | } |
| 1931 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1932 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1933 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1934 | if (!appctx->ctx.map.ref || |
| 1935 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1936 | 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] | 1937 | appctx->st0 = STAT_CLI_PRINT; |
| 1938 | return 1; |
| 1939 | } |
| 1940 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1941 | /* If the entry identifier start with a '#', it is considered as |
| 1942 | * pointer id |
| 1943 | */ |
| 1944 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1945 | struct pat_ref_elt *ref; |
| 1946 | long long int conv; |
| 1947 | char *error; |
| 1948 | |
| 1949 | /* Convert argument to integer value. */ |
| 1950 | conv = strtoll(&args[3][1], &error, 16); |
| 1951 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1952 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1953 | appctx->st0 = STAT_CLI_PRINT; |
| 1954 | return 1; |
| 1955 | } |
| 1956 | |
| 1957 | /* Convert and check integer to pointer. */ |
| 1958 | ref = (struct pat_ref_elt *)(long)conv; |
| 1959 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1960 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1961 | appctx->st0 = STAT_CLI_PRINT; |
| 1962 | return 1; |
| 1963 | } |
| 1964 | |
| 1965 | /* Try to delete the entry. */ |
| 1966 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 1967 | /* The entry is not found, send message. */ |
| 1968 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 1969 | appctx->st0 = STAT_CLI_PRINT; |
| 1970 | return 1; |
| 1971 | } |
| 1972 | } |
| 1973 | else { |
| 1974 | /* Else, use the entry identifier as pattern |
| 1975 | * string and try to delete the entry. |
| 1976 | */ |
| 1977 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 1978 | /* The entry is not found, send message. */ |
| 1979 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 1980 | appctx->st0 = STAT_CLI_PRINT; |
| 1981 | return 1; |
| 1982 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1983 | } |
| 1984 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1985 | /* The deletion is done, send message. */ |
| 1986 | appctx->ctx.cli.msg = "Done.\n"; |
| 1987 | appctx->st0 = STAT_CLI_PRINT; |
| 1988 | return 1; |
| 1989 | } |
| 1990 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1991 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1992 | appctx->st0 = STAT_CLI_PRINT; |
| 1993 | return 1; |
| 1994 | } |
| 1995 | } |
| 1996 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1997 | if (strcmp(args[1], "map") == 0 || |
| 1998 | strcmp(args[1], "acl") == 0) { |
| 1999 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2000 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2001 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2002 | /* Set flags. */ |
| 2003 | if (args[1][0] == 'm') |
| 2004 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2005 | else |
| 2006 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2007 | |
| 2008 | /* If the keywork is "map", we expect three parameters, if it |
| 2009 | * is "acl", we expect only two parameters |
| 2010 | */ |
| 2011 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2012 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2013 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2014 | appctx->st0 = STAT_CLI_PRINT; |
| 2015 | return 1; |
| 2016 | } |
| 2017 | } |
| 2018 | else { |
| 2019 | if (!*args[2] || !*args[3]) { |
| 2020 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2021 | appctx->st0 = STAT_CLI_PRINT; |
| 2022 | return 1; |
| 2023 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2024 | } |
| 2025 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2026 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2027 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2028 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2029 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2030 | 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] | 2031 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2032 | 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] | 2033 | appctx->st0 = STAT_CLI_PRINT; |
| 2034 | return 1; |
| 2035 | } |
| 2036 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2037 | /* The command "add acl" is prohibited if the reference |
| 2038 | * use samples. |
| 2039 | */ |
| 2040 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2041 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2042 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2043 | "You must use the command 'add map' to add values.\n"; |
| 2044 | appctx->st0 = STAT_CLI_PRINT; |
| 2045 | return 1; |
| 2046 | } |
| 2047 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2048 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2049 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2050 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2051 | 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] | 2052 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2053 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2054 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2055 | if (err) |
| 2056 | memprintf(&err, "%s.\n", err); |
| 2057 | appctx->ctx.cli.err = err; |
| 2058 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2059 | return 1; |
| 2060 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2061 | |
| 2062 | /* The add is done, send message. */ |
| 2063 | appctx->ctx.cli.msg = "Done.\n"; |
| 2064 | appctx->st0 = STAT_CLI_PRINT; |
| 2065 | return 1; |
| 2066 | } |
| 2067 | else { /* unknown "del" parameter */ |
| 2068 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2069 | appctx->st0 = STAT_CLI_PRINT; |
| 2070 | return 1; |
| 2071 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2072 | } |
| 2073 | 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] | 2074 | return 0; |
| 2075 | } |
| 2076 | return 1; |
| 2077 | } |
| 2078 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2079 | /* 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] | 2080 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2081 | * state machine handling requests and various responses. We read a request, |
| 2082 | * 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] | 2083 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2084 | * 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] | 2085 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2086 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2087 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2088 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2089 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2090 | struct channel *req = si->ob; |
| 2091 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2092 | int reql; |
| 2093 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2094 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2095 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2096 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2097 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2098 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2099 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2100 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2101 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2102 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2103 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2104 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2105 | /* Let's close for real now. We just close the request |
| 2106 | * side, the conditions below will complete if needed. |
| 2107 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2108 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2109 | break; |
| 2110 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2111 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2112 | /* ensure we have some output room left in the event we |
| 2113 | * would want to return some info right after parsing. |
| 2114 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2115 | if (buffer_almost_full(si->ib->buf)) { |
| 2116 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2117 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2118 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2119 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2120 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2121 | if (reql <= 0) { /* closed or EOL not found */ |
| 2122 | if (reql == 0) |
| 2123 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2124 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2125 | continue; |
| 2126 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2127 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2128 | /* seek for a possible semi-colon. If we find one, we |
| 2129 | * replace it with an LF and skip only this part. |
| 2130 | */ |
| 2131 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2132 | if (trash.str[len] == ';') { |
| 2133 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2134 | reql = len + 1; |
| 2135 | break; |
| 2136 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2137 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2138 | /* now it is time to check that we have a full line, |
| 2139 | * remove the trailing \n and possibly \r, then cut the |
| 2140 | * line. |
| 2141 | */ |
| 2142 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2143 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2144 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2145 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2146 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2147 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2148 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2149 | len--; |
| 2150 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2151 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2152 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2153 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2154 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2155 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2156 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2157 | continue; |
| 2158 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2159 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2160 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2161 | else if (strcmp(trash.str, "help") == 0 || |
| 2162 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2163 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2164 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2165 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2166 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2167 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2168 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2169 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2170 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2171 | /* if prompt is disabled, print help on empty lines, |
| 2172 | * so that the user at least knows how to enable |
| 2173 | * prompt and find help. |
| 2174 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2175 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2176 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2180 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2181 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2182 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2183 | 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] | 2184 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2185 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2186 | continue; |
| 2187 | } |
| 2188 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2189 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2190 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2191 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2192 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2193 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2194 | case STAT_CLI_PRINT_FREE: |
| 2195 | if (bi_putstr(si->ib, appctx->ctx.cli.err) != -1) { |
| 2196 | free(appctx->ctx.cli.err); |
| 2197 | appctx->st0 = STAT_CLI_PROMPT; |
| 2198 | } |
| 2199 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2200 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2201 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2202 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2203 | break; |
| 2204 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2205 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2206 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2207 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2208 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2209 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2210 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2211 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2212 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2213 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2214 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2215 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2216 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2217 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2218 | if (stats_table_request(si, appctx->st0)) |
| 2219 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2220 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2221 | case STAT_CLI_O_PATS: |
| 2222 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2223 | appctx->st0 = STAT_CLI_PROMPT; |
| 2224 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2225 | case STAT_CLI_O_PAT: |
| 2226 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2227 | appctx->st0 = STAT_CLI_PROMPT; |
| 2228 | break; |
| 2229 | case STAT_CLI_O_MLOOK: |
| 2230 | if (stats_map_lookup(si)) |
| 2231 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2232 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2233 | case STAT_CLI_O_POOLS: |
| 2234 | if (stats_dump_pools_to_buffer(si)) |
| 2235 | appctx->st0 = STAT_CLI_PROMPT; |
| 2236 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2237 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2238 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2239 | break; |
| 2240 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2241 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2242 | /* 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] | 2243 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2244 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2245 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2246 | } |
| 2247 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2248 | /* 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] | 2249 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2250 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2251 | |
| 2252 | /* Now we close the output if one of the writers did so, |
| 2253 | * or if we're not in interactive mode and the request |
| 2254 | * buffer is empty. This still allows pipelined requests |
| 2255 | * to be sent in non-interactive mode. |
| 2256 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2257 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2258 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2259 | continue; |
| 2260 | } |
| 2261 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2262 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2263 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2264 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2265 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2266 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2267 | 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] | 2268 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2269 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2270 | /* 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] | 2271 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2272 | * we forward the close to the request side so that it flows upstream to |
| 2273 | * the client. |
| 2274 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2275 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2276 | } |
| 2277 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2278 | 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] | 2279 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2280 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2281 | /* We have no more processing to do, and nothing more to send, and |
| 2282 | * the client side has closed. So we'll forward this state downstream |
| 2283 | * on the response buffer. |
| 2284 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2285 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2286 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2290 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2291 | |
| 2292 | /* we don't want to expire timeouts while we're processing requests */ |
| 2293 | si->ib->rex = TICK_ETERNITY; |
| 2294 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2295 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2296 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2297 | 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] | 2298 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2299 | 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] | 2300 | |
| 2301 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2302 | /* check that we have released everything then unregister */ |
| 2303 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2304 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2305 | } |
| 2306 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2307 | /* This function dumps information onto the stream interface's read buffer. |
| 2308 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2309 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2310 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2311 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2312 | { |
| 2313 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2314 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2315 | chunk_printf(&trash, |
| 2316 | "Name: " PRODUCT_NAME "\n" |
| 2317 | "Version: " HAPROXY_VERSION "\n" |
| 2318 | "Release_date: " HAPROXY_DATE "\n" |
| 2319 | "Nbproc: %d\n" |
| 2320 | "Process_num: %d\n" |
| 2321 | "Pid: %d\n" |
| 2322 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2323 | "Uptime_sec: %d\n" |
| 2324 | "Memmax_MB: %d\n" |
| 2325 | "Ulimit-n: %d\n" |
| 2326 | "Maxsock: %d\n" |
| 2327 | "Maxconn: %d\n" |
| 2328 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2329 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2330 | "CumConns: %d\n" |
| 2331 | "CumReq: %d\n" |
| 2332 | #ifdef USE_OPENSSL |
| 2333 | "MaxSslConns: %d\n" |
| 2334 | "CurrSslConns: %d\n" |
| 2335 | "CumSslConns: %d\n" |
| 2336 | #endif |
| 2337 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2338 | "PipesUsed: %d\n" |
| 2339 | "PipesFree: %d\n" |
| 2340 | "ConnRate: %d\n" |
| 2341 | "ConnRateLimit: %d\n" |
| 2342 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2343 | "SessRate: %d\n" |
| 2344 | "SessRateLimit: %d\n" |
| 2345 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2346 | #ifdef USE_OPENSSL |
| 2347 | "SslRate: %d\n" |
| 2348 | "SslRateLimit: %d\n" |
| 2349 | "MaxSslRate: %d\n" |
| 2350 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2351 | "CompressBpsIn: %u\n" |
| 2352 | "CompressBpsOut: %u\n" |
| 2353 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2354 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2355 | "ZlibMemUsage: %ld\n" |
| 2356 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2357 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2358 | "Tasks: %d\n" |
| 2359 | "Run_queue: %d\n" |
| 2360 | "Idle_pct: %d\n" |
| 2361 | "node: %s\n" |
| 2362 | "description: %s\n" |
| 2363 | "", |
| 2364 | global.nbproc, |
| 2365 | relative_pid, |
| 2366 | pid, |
| 2367 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2368 | up, |
| 2369 | global.rlimit_memmax, |
| 2370 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2371 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2372 | actconn, totalconn, global.req_count, |
| 2373 | #ifdef USE_OPENSSL |
| 2374 | global.maxsslconn, sslconns, totalsslconns, |
| 2375 | #endif |
| 2376 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2377 | 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] | 2378 | 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] | 2379 | #ifdef USE_OPENSSL |
| 2380 | read_freq_ctr(&global.ssl_per_sec), global.ssl_lim, global.ssl_max, |
| 2381 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2382 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2383 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2384 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2385 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2386 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2387 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2388 | global.node, global.desc ? global.desc : "" |
| 2389 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2390 | |
| 2391 | if (bi_putchk(si->ib, &trash) == -1) |
| 2392 | return 0; |
| 2393 | |
| 2394 | return 1; |
| 2395 | } |
| 2396 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2397 | /* This function dumps memory usage information onto the stream interface's |
| 2398 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2399 | * completion. No state is used. |
| 2400 | */ |
| 2401 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2402 | { |
| 2403 | dump_pools_to_trash(); |
| 2404 | if (bi_putchk(si->ib, &trash) == -1) |
| 2405 | return 0; |
| 2406 | return 1; |
| 2407 | } |
| 2408 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2409 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2410 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2411 | * 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] | 2412 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2413 | 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] | 2414 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2415 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2416 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2417 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2418 | if (!(px->cap & PR_CAP_FE)) |
| 2419 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2420 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2421 | 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] | 2422 | return 0; |
| 2423 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2424 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2425 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2426 | /* name, queue */ |
| 2427 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2428 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2429 | 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] | 2430 | /* Column sub-heading for Enable or Disable server */ |
| 2431 | chunk_appendf(&trash, "<td></td>"); |
| 2432 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2433 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2434 | chunk_appendf(&trash, |
| 2435 | "<td class=ac>" |
| 2436 | "<a name=\"%s/Frontend\"></a>" |
| 2437 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2438 | "<td colspan=3></td>" |
| 2439 | "", |
| 2440 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2441 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2442 | chunk_appendf(&trash, |
| 2443 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2444 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2445 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2446 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2447 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2448 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2449 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2450 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2451 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2452 | if (px->mode == PR_MODE_HTTP) |
| 2453 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2454 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2455 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2456 | |
| 2457 | chunk_appendf(&trash, |
| 2458 | "</table></div></u></td>" |
| 2459 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2460 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2461 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2462 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2463 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2464 | U2H(px->fe_counters.sps_max), |
| 2465 | U2H(px->fe_counters.cps_max), |
| 2466 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2467 | |
| 2468 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2469 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2470 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2471 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2472 | |
| 2473 | chunk_appendf(&trash, |
| 2474 | "</table></div></u></td>" |
| 2475 | /* sessions rate : limit */ |
| 2476 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2477 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2478 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2479 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2480 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2481 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2482 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2483 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2484 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2485 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2486 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2487 | U2H(px->fe_counters.cum_sess), |
| 2488 | U2H(px->fe_counters.cum_conn), |
| 2489 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2490 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2491 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2492 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2493 | chunk_appendf(&trash, |
| 2494 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2495 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2496 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2497 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2498 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2499 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2500 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2501 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2502 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2503 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2504 | U2H(px->fe_counters.p.http.cum_req), |
| 2505 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2506 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2507 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2508 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2509 | (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] | 2510 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2511 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2512 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2513 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2514 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2515 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2516 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2517 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2518 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2519 | /* sessions: lbtot, lastsess */ |
| 2520 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2521 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2522 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2523 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2524 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2525 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2526 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2527 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2528 | "<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] | 2529 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2530 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2531 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2532 | px->fe_counters.comp_in ? |
| 2533 | (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] | 2534 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2535 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2536 | chunk_appendf(&trash, |
| 2537 | /* denied: req, resp */ |
| 2538 | "<td>%s</td><td>%s</td>" |
| 2539 | /* errors : request, connect, response */ |
| 2540 | "<td>%s</td><td></td><td></td>" |
| 2541 | /* warnings: retries, redispatches */ |
| 2542 | "<td></td><td></td>" |
| 2543 | /* server status : reflect frontend status */ |
| 2544 | "<td class=ac>%s</td>" |
| 2545 | /* rest of server: nothing */ |
| 2546 | "<td class=ac colspan=8></td></tr>" |
| 2547 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2548 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2549 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2550 | px->state == PR_STREADY ? "OPEN" : |
| 2551 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2552 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2553 | else { /* CSV mode */ |
| 2554 | chunk_appendf(&trash, |
| 2555 | /* pxid, name, queue cur, queue max, */ |
| 2556 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2557 | /* sessions : current, max, limit, total */ |
| 2558 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2559 | /* bytes : in, out */ |
| 2560 | "%lld,%lld," |
| 2561 | /* denied: req, resp */ |
| 2562 | "%lld,%lld," |
| 2563 | /* errors : request, connect, response */ |
| 2564 | "%lld,,," |
| 2565 | /* warnings: retries, redispatches */ |
| 2566 | ",," |
| 2567 | /* server status : reflect frontend status */ |
| 2568 | "%s," |
| 2569 | /* rest of server: nothing */ |
| 2570 | ",,,,,,,," |
| 2571 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2572 | "%d,%d,0,,,,%d," |
| 2573 | /* rate, rate_lim, rate_max */ |
| 2574 | "%u,%u,%u," |
| 2575 | /* check_status, check_code, check_duration */ |
| 2576 | ",,,", |
| 2577 | px->id, |
| 2578 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2579 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2580 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2581 | px->fe_counters.failed_req, |
| 2582 | px->state == PR_STREADY ? "OPEN" : |
| 2583 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2584 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2585 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2586 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2587 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2588 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2589 | if (px->mode == PR_MODE_HTTP) { |
| 2590 | for (i=1; i<6; i++) |
| 2591 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2592 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2593 | } |
| 2594 | else |
| 2595 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2596 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2597 | /* failed health analyses */ |
| 2598 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2599 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2600 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2601 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2602 | read_freq_ctr(&px->fe_req_per_sec), |
| 2603 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2604 | |
| 2605 | /* errors: cli_aborts, srv_aborts */ |
| 2606 | chunk_appendf(&trash, ",,"); |
| 2607 | |
| 2608 | /* compression: in, out, bypassed */ |
| 2609 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2610 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2611 | |
| 2612 | /* compression: comp_rsp */ |
| 2613 | chunk_appendf(&trash, "%lld,", |
| 2614 | px->fe_counters.p.http.comp_rsp); |
| 2615 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2616 | /* lastsess */ |
| 2617 | chunk_appendf(&trash, ","); |
| 2618 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2619 | /* finish with EOL */ |
| 2620 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2621 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2622 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2623 | } |
| 2624 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2625 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2626 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2627 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2628 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2629 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2630 | 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] | 2631 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2632 | struct appctx *appctx = __objt_appctx(si->end); |
| 2633 | |
| 2634 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2635 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2636 | 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] | 2637 | /* Column sub-heading for Enable or Disable server */ |
| 2638 | chunk_appendf(&trash, "<td></td>"); |
| 2639 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2640 | chunk_appendf(&trash, |
| 2641 | /* frontend name, listener name */ |
| 2642 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2643 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2644 | "", |
| 2645 | px->id, l->name, |
| 2646 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2647 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2648 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2649 | if (flags & ST_SHLGNDS) { |
| 2650 | char str[INET6_ADDRSTRLEN]; |
| 2651 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2652 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2653 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2654 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2655 | port = get_host_port(&l->addr); |
| 2656 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2657 | case AF_INET: |
| 2658 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2659 | break; |
| 2660 | case AF_INET6: |
| 2661 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2662 | break; |
| 2663 | case AF_UNIX: |
| 2664 | chunk_appendf(&trash, "unix, "); |
| 2665 | break; |
| 2666 | case -1: |
| 2667 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2668 | break; |
| 2669 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2670 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2671 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2672 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2673 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2674 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2675 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2676 | /* queue */ |
| 2677 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2678 | /* sessions rate: current, max, limit */ |
| 2679 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2680 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2681 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2682 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2683 | /* bytes: in, out */ |
| 2684 | "<td>%s</td><td>%s</td>" |
| 2685 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2686 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2687 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2688 | 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] | 2689 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2690 | chunk_appendf(&trash, |
| 2691 | /* denied: req, resp */ |
| 2692 | "<td>%s</td><td>%s</td>" |
| 2693 | /* errors: request, connect, response */ |
| 2694 | "<td>%s</td><td></td><td></td>" |
| 2695 | /* warnings: retries, redispatches */ |
| 2696 | "<td></td><td></td>" |
| 2697 | /* server status: reflect listener status */ |
| 2698 | "<td class=ac>%s</td>" |
| 2699 | /* rest of server: nothing */ |
| 2700 | "<td class=ac colspan=8></td></tr>" |
| 2701 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2702 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2703 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2704 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2705 | } |
| 2706 | else { /* CSV mode */ |
| 2707 | chunk_appendf(&trash, |
| 2708 | /* pxid, name, queue cur, queue max, */ |
| 2709 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2710 | /* sessions: current, max, limit, total */ |
| 2711 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2712 | /* bytes: in, out */ |
| 2713 | "%lld,%lld," |
| 2714 | /* denied: req, resp */ |
| 2715 | "%lld,%lld," |
| 2716 | /* errors: request, connect, response */ |
| 2717 | "%lld,,," |
| 2718 | /* warnings: retries, redispatches */ |
| 2719 | ",," |
| 2720 | /* server status: reflect listener status */ |
| 2721 | "%s," |
| 2722 | /* rest of server: nothing */ |
| 2723 | ",,,,,,,," |
| 2724 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2725 | "%d,%d,%d,,,,%d," |
| 2726 | /* rate, rate_lim, rate_max */ |
| 2727 | ",,," |
| 2728 | /* check_status, check_code, check_duration */ |
| 2729 | ",,," |
| 2730 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2731 | ",,,,,," |
| 2732 | /* failed health analyses */ |
| 2733 | "," |
| 2734 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2735 | ",,," |
| 2736 | /* errors: cli_aborts, srv_aborts */ |
| 2737 | ",," |
| 2738 | /* compression: in, out, bypassed, comp_rsp */ |
| 2739 | ",,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2740 | /* lastsess */ |
| 2741 | "," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2742 | "\n", |
| 2743 | px->id, l->name, |
| 2744 | l->nbconn, l->counters->conn_max, |
| 2745 | l->maxconn, l->counters->cum_conn, |
| 2746 | l->counters->bytes_in, l->counters->bytes_out, |
| 2747 | l->counters->denied_req, l->counters->denied_resp, |
| 2748 | l->counters->failed_req, |
| 2749 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2750 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2751 | } |
| 2752 | return 1; |
| 2753 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2754 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2755 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2756 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2757 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2758 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2759 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2760 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2761 | */ |
| 2762 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2763 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2764 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2765 | struct server *ref = sv->track ? sv->track : sv; |
| 2766 | char str[INET6_ADDRSTRLEN]; |
| 2767 | struct chunk src; |
| 2768 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2769 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2770 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2771 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2772 | "DOWN", |
| 2773 | "DN %d/%d ↑", |
| 2774 | "UP %d/%d ↓", |
| 2775 | "UP", |
| 2776 | "NOLB %d/%d ↓", |
| 2777 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2778 | "DRAIN %d/%d ↓", |
| 2779 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2780 | "<i>no check</i>" |
| 2781 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2782 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 2783 | if ((sv->admin | ref->admin) & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2784 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2785 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2786 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2787 | "<tr class=\"%s%d\">", |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 2788 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2789 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2790 | 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] | 2791 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2792 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2793 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2794 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2795 | chunk_appendf(&trash, |
| 2796 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2797 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2798 | "", |
| 2799 | px->id, sv->id, |
| 2800 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2801 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2802 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2803 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2804 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2805 | |
| 2806 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2807 | case AF_INET: |
| 2808 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2809 | break; |
| 2810 | case AF_INET6: |
| 2811 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2812 | break; |
| 2813 | case AF_UNIX: |
| 2814 | chunk_appendf(&trash, "unix, "); |
| 2815 | break; |
| 2816 | case -1: |
| 2817 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2818 | break; |
| 2819 | default: /* address family not supported */ |
| 2820 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2821 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2822 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2823 | /* id */ |
| 2824 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2825 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2826 | /* cookie */ |
| 2827 | if (sv->cookie) { |
| 2828 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2829 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2830 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2831 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2832 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2833 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2834 | } |
| 2835 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2836 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2837 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2838 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2839 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2840 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2841 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2842 | /* sessions rate : current, max, limit */ |
| 2843 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2844 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2845 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2846 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2847 | 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] | 2848 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2849 | |
| 2850 | chunk_appendf(&trash, |
| 2851 | /* sessions: current, max, limit, total */ |
| 2852 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2853 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2854 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2855 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2856 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2857 | U2H(sv->counters.cum_sess), |
| 2858 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2859 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2860 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2861 | if (px->mode == PR_MODE_HTTP) { |
| 2862 | unsigned long long tot; |
| 2863 | for (tot = i = 0; i < 6; i++) |
| 2864 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2865 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2866 | chunk_appendf(&trash, |
| 2867 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2868 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2869 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2870 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2871 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2872 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2873 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2874 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2875 | U2H(tot), |
| 2876 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2877 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2878 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2879 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2880 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2881 | 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] | 2882 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2883 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2884 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2885 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2886 | /* sessions: lbtot, last */ |
| 2887 | "<td>%s</td><td>%s</td>", |
| 2888 | U2H(sv->counters.cum_lbconn), |
| 2889 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2890 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2891 | chunk_appendf(&trash, |
| 2892 | /* bytes : in, out */ |
| 2893 | "<td>%s</td><td>%s</td>" |
| 2894 | /* denied: req, resp */ |
| 2895 | "<td></td><td>%s</td>" |
| 2896 | /* errors : request, connect */ |
| 2897 | "<td></td><td>%s</td>" |
| 2898 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2899 | "<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] | 2900 | /* warnings: retries, redispatches */ |
| 2901 | "<td>%lld</td><td>%lld</td>" |
| 2902 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2903 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2904 | U2H(sv->counters.failed_secu), |
| 2905 | U2H(sv->counters.failed_conns), |
| 2906 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2907 | sv->counters.cli_aborts, |
| 2908 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2909 | sv->counters.retries, sv->counters.redispatches); |
| 2910 | |
| 2911 | /* status, lest check */ |
| 2912 | chunk_appendf(&trash, "<td class=ac>"); |
| 2913 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 2914 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2915 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2916 | chunk_appendf(&trash, "MAINT"); |
| 2917 | } |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 2918 | else if (ref != sv && (ref->admin & SRV_ADMF_MAINT)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2919 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2920 | chunk_appendf(&trash, "MAINT(via)"); |
| 2921 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2922 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2923 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2924 | chunk_appendf(&trash, |
| 2925 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 2926 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2927 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2928 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2929 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2930 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2931 | chunk_appendf(&trash, |
| 2932 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 2933 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2934 | get_check_status_info(sv->check.status)); |
| 2935 | |
| 2936 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2937 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2938 | |
| 2939 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2940 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2941 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2942 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2943 | get_check_status_description(sv->check.status)); |
| 2944 | if (*sv->check.desc) { |
| 2945 | chunk_appendf(&trash, ": "); |
| 2946 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2947 | chunk_htmlencode(&trash, &src); |
| 2948 | } |
| 2949 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2950 | } |
| 2951 | else |
| 2952 | chunk_appendf(&trash, "</td><td>"); |
| 2953 | |
| 2954 | chunk_appendf(&trash, |
| 2955 | /* weight */ |
| 2956 | "</td><td class=ac>%d</td>" |
| 2957 | /* act, bck */ |
| 2958 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2959 | "", |
| 2960 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 2961 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 2962 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2963 | |
| 2964 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2965 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2966 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2967 | |
| 2968 | if (ref->observe) |
| 2969 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2970 | |
| 2971 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2972 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2973 | "<td>%lld</td><td>%s</td>" |
| 2974 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2975 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2976 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2977 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2978 | else if (sv != ref) { |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 2979 | if (sv->admin & SRV_ADMF_MAINT) |
Cyril Bonté | c7fa7db | 2014-05-11 23:10:19 +0200 | [diff] [blame] | 2980 | chunk_appendf(&trash, "<td class=ac colspan=3></td>"); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2981 | else |
| 2982 | chunk_appendf(&trash, |
Cyril Bonté | d5de76a | 2014-05-11 23:10:18 +0200 | [diff] [blame] | 2983 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s</a></td>", |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2984 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2985 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2986 | else |
| 2987 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2988 | |
| 2989 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 2990 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2991 | 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] | 2992 | else |
| 2993 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2994 | } |
| 2995 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2996 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2997 | "DOWN,", |
| 2998 | "DOWN %d/%d,", |
| 2999 | "UP %d/%d,", |
| 3000 | "UP,", |
| 3001 | "NOLB %d/%d,", |
| 3002 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3003 | "DRAIN %d/%d,", |
| 3004 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3005 | "no check," |
| 3006 | }; |
| 3007 | |
| 3008 | chunk_appendf(&trash, |
| 3009 | /* pxid, name */ |
| 3010 | "%s,%s," |
| 3011 | /* queue : current, max */ |
| 3012 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3013 | /* sessions : current, max, limit, total */ |
| 3014 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3015 | /* bytes : in, out */ |
| 3016 | "%lld,%lld," |
| 3017 | /* denied: req, resp */ |
| 3018 | ",%lld," |
| 3019 | /* errors : request, connect, response */ |
| 3020 | ",%lld,%lld," |
| 3021 | /* warnings: retries, redispatches */ |
| 3022 | "%lld,%lld," |
| 3023 | "", |
| 3024 | px->id, sv->id, |
| 3025 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3026 | 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] | 3027 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3028 | sv->counters.failed_secu, |
| 3029 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3030 | sv->counters.retries, sv->counters.redispatches); |
| 3031 | |
| 3032 | /* status */ |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3033 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3034 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3035 | else if (ref != sv && (ref->admin & SRV_ADMF_MAINT)) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3036 | chunk_appendf(&trash, "MAINT(via),"); |
| 3037 | else |
| 3038 | chunk_appendf(&trash, |
| 3039 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3040 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3041 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3042 | |
| 3043 | chunk_appendf(&trash, |
| 3044 | /* weight, active, backup */ |
| 3045 | "%d,%d,%d," |
| 3046 | "", |
| 3047 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3048 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3049 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3050 | |
| 3051 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3052 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3053 | chunk_appendf(&trash, |
| 3054 | "%lld,%lld,%d,%d,", |
| 3055 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3056 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3057 | else |
| 3058 | chunk_appendf(&trash, ",,,,"); |
| 3059 | |
| 3060 | /* queue limit, pid, iid, sid, */ |
| 3061 | chunk_appendf(&trash, |
| 3062 | "%s," |
| 3063 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3064 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3065 | relative_pid, px->uuid, sv->puid); |
| 3066 | |
| 3067 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3068 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3069 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3070 | |
| 3071 | /* sessions: lbtot */ |
| 3072 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3073 | |
| 3074 | /* tracked */ |
| 3075 | if (sv->track) |
| 3076 | chunk_appendf(&trash, "%s/%s,", |
| 3077 | sv->track->proxy->id, sv->track->id); |
| 3078 | else |
| 3079 | chunk_appendf(&trash, ","); |
| 3080 | |
| 3081 | /* type */ |
| 3082 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3083 | |
| 3084 | /* rate */ |
| 3085 | chunk_appendf(&trash, "%u,,%u,", |
| 3086 | read_freq_ctr(&sv->sess_per_sec), |
| 3087 | sv->counters.sps_max); |
| 3088 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3089 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3090 | /* check_status */ |
| 3091 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3092 | |
| 3093 | /* check_code */ |
| 3094 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3095 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3096 | else |
| 3097 | chunk_appendf(&trash, ","); |
| 3098 | |
| 3099 | /* check_duration */ |
| 3100 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3101 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3102 | else |
| 3103 | chunk_appendf(&trash, ","); |
| 3104 | |
| 3105 | } |
| 3106 | else |
| 3107 | chunk_appendf(&trash, ",,,"); |
| 3108 | |
| 3109 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3110 | if (px->mode == PR_MODE_HTTP) { |
| 3111 | for (i=1; i<6; i++) |
| 3112 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3113 | |
| 3114 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3115 | } |
| 3116 | else |
| 3117 | chunk_appendf(&trash, ",,,,,,"); |
| 3118 | |
| 3119 | /* failed health analyses */ |
| 3120 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3121 | |
| 3122 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3123 | chunk_appendf(&trash, ",,,"); |
| 3124 | |
| 3125 | /* errors: cli_aborts, srv_aborts */ |
| 3126 | chunk_appendf(&trash, "%lld,%lld,", |
| 3127 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3128 | |
| 3129 | /* compression: in, out, bypassed, comp_rsp */ |
| 3130 | chunk_appendf(&trash, ",,,,"); |
| 3131 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3132 | /* lastsess */ |
| 3133 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3134 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3135 | /* finish with EOL */ |
| 3136 | chunk_appendf(&trash, "\n"); |
| 3137 | } |
| 3138 | return 1; |
| 3139 | } |
| 3140 | |
| 3141 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3142 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3143 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3144 | */ |
| 3145 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3146 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3147 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3148 | struct chunk src; |
| 3149 | int i; |
| 3150 | |
| 3151 | if (!(px->cap & PR_CAP_BE)) |
| 3152 | return 0; |
| 3153 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3154 | 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] | 3155 | return 0; |
| 3156 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3157 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3158 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3159 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3160 | /* Column sub-heading for Enable or Disable server */ |
| 3161 | chunk_appendf(&trash, "<td></td>"); |
| 3162 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3163 | chunk_appendf(&trash, |
| 3164 | "<td class=ac>" |
| 3165 | /* name */ |
| 3166 | "%s<a name=\"%s/Backend\"></a>" |
| 3167 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3168 | "", |
| 3169 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3170 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3171 | |
| 3172 | if (flags & ST_SHLGNDS) { |
| 3173 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3174 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3175 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3176 | |
| 3177 | /* cookie */ |
| 3178 | if (px->cookie_name) { |
| 3179 | chunk_appendf(&trash, ", cookie: '"); |
| 3180 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3181 | chunk_htmlencode(&trash, &src); |
| 3182 | chunk_appendf(&trash, "'"); |
| 3183 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3184 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3188 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3189 | /* queue : current, max */ |
| 3190 | "<td>%s</td><td>%s</td><td></td>" |
| 3191 | /* sessions rate : current, max, limit */ |
| 3192 | "<td>%s</td><td>%s</td><td></td>" |
| 3193 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3194 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3195 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3196 | 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] | 3197 | |
| 3198 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3199 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3200 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3201 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3202 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3203 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3204 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3205 | U2H(px->be_counters.cum_conn), |
| 3206 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3207 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3208 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3209 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3210 | chunk_appendf(&trash, |
| 3211 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3212 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3213 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3214 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3215 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3216 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3217 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3218 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3219 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3220 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3221 | U2H(px->be_counters.p.http.cum_req), |
| 3222 | U2H(px->be_counters.p.http.rsp[1]), |
| 3223 | U2H(px->be_counters.p.http.rsp[2]), |
| 3224 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3225 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3226 | (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] | 3227 | U2H(px->be_counters.p.http.rsp[3]), |
| 3228 | U2H(px->be_counters.p.http.rsp[4]), |
| 3229 | U2H(px->be_counters.p.http.rsp[5]), |
| 3230 | U2H(px->be_counters.p.http.rsp[0]), |
| 3231 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3235 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3236 | /* sessions: lbtot, last */ |
| 3237 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3238 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3239 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3240 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3241 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3242 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3243 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3244 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3245 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3246 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3247 | "<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] | 3248 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3249 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3250 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3251 | px->be_counters.comp_in ? |
| 3252 | (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] | 3253 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3254 | |
| 3255 | chunk_appendf(&trash, |
| 3256 | /* denied: req, resp */ |
| 3257 | "<td>%s</td><td>%s</td>" |
| 3258 | /* errors : request, connect */ |
| 3259 | "<td></td><td>%s</td>" |
| 3260 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3261 | "<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] | 3262 | /* warnings: retries, redispatches */ |
| 3263 | "<td>%lld</td><td>%lld</td>" |
| 3264 | /* backend status: reflect backend status (up/down): we display UP |
| 3265 | * if the backend has known working servers or if it has no server at |
| 3266 | * all (eg: for stats). Then we display the total weight, number of |
| 3267 | * active and backups. */ |
| 3268 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3269 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3270 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3271 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3272 | U2H(px->be_counters.failed_conns), |
| 3273 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3274 | px->be_counters.cli_aborts, |
| 3275 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3276 | px->be_counters.retries, px->be_counters.redispatches, |
| 3277 | human_time(now.tv_sec - px->last_change, 1), |
| 3278 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3279 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3280 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3281 | px->srv_act, px->srv_bck); |
| 3282 | |
| 3283 | chunk_appendf(&trash, |
| 3284 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3285 | "<td class=ac> </td><td>%d</td>" |
| 3286 | "<td>%s</td>" |
| 3287 | "<td></td>" |
| 3288 | "</tr>", |
| 3289 | px->down_trans, |
| 3290 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3291 | } |
| 3292 | else { /* CSV mode */ |
| 3293 | chunk_appendf(&trash, |
| 3294 | /* pxid, name */ |
| 3295 | "%s,BACKEND," |
| 3296 | /* queue : current, max */ |
| 3297 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3298 | /* sessions : current, max, limit, total */ |
| 3299 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3300 | /* bytes : in, out */ |
| 3301 | "%lld,%lld," |
| 3302 | /* denied: req, resp */ |
| 3303 | "%lld,%lld," |
| 3304 | /* errors : request, connect, response */ |
| 3305 | ",%lld,%lld," |
| 3306 | /* warnings: retries, redispatches */ |
| 3307 | "%lld,%lld," |
| 3308 | /* backend status: reflect backend status (up/down): we display UP |
| 3309 | * if the backend has known working servers or if it has no server at |
| 3310 | * all (eg: for stats). Then we display the total weight, number of |
| 3311 | * active and backups. */ |
| 3312 | "%s," |
| 3313 | "%d,%d,%d," |
| 3314 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3315 | ",%d,%d,%d,," |
| 3316 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3317 | "%d,%d,0,,%lld,,%d," |
| 3318 | /* rate, rate_lim, rate_max, */ |
| 3319 | "%u,,%u," |
| 3320 | /* check_status, check_code, check_duration */ |
| 3321 | ",,,", |
| 3322 | px->id, |
| 3323 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3324 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3325 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3326 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3327 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3328 | px->be_counters.retries, px->be_counters.redispatches, |
| 3329 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3330 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3331 | px->srv_act, px->srv_bck, |
| 3332 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3333 | px->srv?be_downtime(px):0, |
| 3334 | relative_pid, px->uuid, |
| 3335 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3336 | read_freq_ctr(&px->be_sess_per_sec), |
| 3337 | px->be_counters.sps_max); |
| 3338 | |
| 3339 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3340 | if (px->mode == PR_MODE_HTTP) { |
| 3341 | for (i=1; i<6; i++) |
| 3342 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3343 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3344 | } |
| 3345 | else |
| 3346 | chunk_appendf(&trash, ",,,,,,"); |
| 3347 | |
| 3348 | /* failed health analyses */ |
| 3349 | chunk_appendf(&trash, ","); |
| 3350 | |
| 3351 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3352 | chunk_appendf(&trash, ",,,"); |
| 3353 | |
| 3354 | /* errors: cli_aborts, srv_aborts */ |
| 3355 | chunk_appendf(&trash, "%lld,%lld,", |
| 3356 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3357 | |
| 3358 | /* compression: in, out, bypassed */ |
| 3359 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3360 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3361 | |
| 3362 | /* compression: comp_rsp */ |
| 3363 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3364 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3365 | /* lastsess */ |
| 3366 | chunk_appendf(&trash, "%d,", be_lastsession(px)); |
| 3367 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3368 | /* finish with EOL */ |
| 3369 | chunk_appendf(&trash, "\n"); |
| 3370 | } |
| 3371 | return 1; |
| 3372 | } |
| 3373 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3374 | /* 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] | 3375 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3376 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3377 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3378 | 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] | 3379 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3380 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3381 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3382 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3383 | 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] | 3384 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3385 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3386 | /* 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] | 3387 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3388 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3389 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3390 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3391 | 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] | 3392 | } |
| 3393 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3394 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3395 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3396 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3397 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3398 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3399 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | /* print a new table */ |
| 3403 | chunk_appendf(&trash, |
| 3404 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3405 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3406 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3407 | |
| 3408 | chunk_appendf(&trash, |
| 3409 | "<a name=\"%s\"></a>%s" |
| 3410 | "<a class=px href=\"#%s\">%s</a>", |
| 3411 | px->id, |
| 3412 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3413 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3414 | |
| 3415 | if (uri->flags & ST_SHLGNDS) { |
| 3416 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3417 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3418 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3419 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3420 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3421 | } |
| 3422 | |
| 3423 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3424 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3425 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3426 | "</tr>\n" |
| 3427 | "</table>\n" |
| 3428 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3429 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3430 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3431 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3432 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3433 | 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] | 3434 | /* Column heading for Enable or Disable server */ |
| 3435 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3436 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3437 | |
| 3438 | chunk_appendf(&trash, |
| 3439 | "<th rowspan=2></th>" |
| 3440 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3441 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3442 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3443 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3444 | "<th colspan=9>Server</th>" |
| 3445 | "</tr>\n" |
| 3446 | "<tr class=\"titre\">" |
| 3447 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3448 | "<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] | 3449 | "<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] | 3450 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3451 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3452 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3453 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3454 | "<th>Thrtle</th>\n" |
| 3455 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3456 | } |
| 3457 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3458 | /* 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] | 3459 | * 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] | 3460 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3461 | 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] | 3462 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3463 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3464 | chunk_appendf(&trash, "</table>"); |
| 3465 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3466 | 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] | 3467 | /* close the form used to enable/disable this proxy servers */ |
| 3468 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3469 | "Choose the action to perform on the checked servers : " |
| 3470 | "<select name=action>" |
| 3471 | "<option value=\"\"></option>" |
| 3472 | "<option value=\"disable\">Disable</option>" |
| 3473 | "<option value=\"enable\">Enable</option>" |
| 3474 | "<option value=\"stop\">Soft Stop</option>" |
| 3475 | "<option value=\"start\">Soft Start</option>" |
| 3476 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3477 | "</select>" |
| 3478 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3479 | " <input type=\"submit\" value=\"Apply\">" |
| 3480 | "</form>", |
| 3481 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3485 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3486 | |
| 3487 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3488 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3489 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3490 | * buffer space, or non-zero if everything completed. This function is used |
| 3491 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3492 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3493 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3494 | 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] | 3495 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3496 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3497 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3498 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3499 | 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] | 3500 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3501 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3502 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3503 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3504 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3505 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3506 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3507 | if (uri && uri->scope) { |
| 3508 | /* we have a limited scope, we have to check the proxy name */ |
| 3509 | struct stat_scope *scope; |
| 3510 | int len; |
| 3511 | |
| 3512 | len = strlen(px->id); |
| 3513 | scope = uri->scope; |
| 3514 | |
| 3515 | while (scope) { |
| 3516 | /* match exact proxy name */ |
| 3517 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3518 | break; |
| 3519 | |
| 3520 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3521 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3522 | break; |
| 3523 | scope = scope->next; |
| 3524 | } |
| 3525 | |
| 3526 | /* proxy name not found : don't dump anything */ |
| 3527 | if (scope == NULL) |
| 3528 | return 1; |
| 3529 | } |
| 3530 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3531 | /* if the user has requested a limited output and the proxy |
| 3532 | * name does not match, skip it. |
| 3533 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3534 | if (appctx->ctx.stats.scope_len && |
| 3535 | 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] | 3536 | return 1; |
| 3537 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3538 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3539 | (appctx->ctx.stats.iid != -1) && |
| 3540 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3541 | return 1; |
| 3542 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3543 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3544 | /* fall through */ |
| 3545 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3546 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3547 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3548 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3549 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3550 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3551 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3552 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3553 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3554 | /* fall through */ |
| 3555 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3556 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3557 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3558 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3559 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3560 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3561 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3562 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3563 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3564 | /* fall through */ |
| 3565 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3566 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3567 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3568 | 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] | 3569 | if (buffer_almost_full(rep->buf)) { |
| 3570 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3571 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3572 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3573 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3574 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3575 | if (!l->counters) |
| 3576 | continue; |
| 3577 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3578 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3579 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3580 | break; |
| 3581 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3582 | 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] | 3583 | continue; |
| 3584 | } |
| 3585 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3586 | /* print the frontend */ |
| 3587 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3588 | if (bi_putchk(rep, &trash) == -1) |
| 3589 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3590 | } |
| 3591 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3592 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3593 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3594 | /* fall through */ |
| 3595 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3596 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3597 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3598 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3599 | int sv_state; /* 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, 6=unchecked */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3600 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3601 | if (buffer_almost_full(rep->buf)) { |
| 3602 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3603 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3604 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3605 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3606 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3607 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3608 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3609 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3610 | break; |
| 3611 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3612 | 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] | 3613 | continue; |
| 3614 | } |
| 3615 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3616 | if (sv->track) |
| 3617 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3618 | else |
| 3619 | svs = sv; |
| 3620 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3621 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3622 | if (!(svs->check.state & CHK_ST_ENABLED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3623 | sv_state = 8; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3624 | else if (svs->state != SRV_ST_STOPPED) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 3625 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3626 | sv_state = 3; /* UP */ |
| 3627 | else |
| 3628 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3629 | |
Willy Tarreau | efe2822 | 2014-05-21 17:13:13 +0200 | [diff] [blame] | 3630 | if (server_is_draining(sv)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3631 | sv_state += 4; |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3632 | else if (svs->state == SRV_ST_STOPPING) |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3633 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3634 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3635 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 3636 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3637 | sv_state = 1; /* going up */ |
| 3638 | else |
| 3639 | sv_state = 0; /* DOWN */ |
| 3640 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3641 | if (((sv_state == 0) || (sv->admin & SRV_ADMF_MAINT)) && (appctx->ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3642 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3643 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3644 | continue; |
| 3645 | } |
| 3646 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3647 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3648 | if (bi_putchk(rep, &trash) == -1) |
| 3649 | return 0; |
| 3650 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3651 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3652 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3653 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3654 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3655 | case STAT_PX_ST_BE: |
| 3656 | /* print the backend */ |
| 3657 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3658 | if (bi_putchk(rep, &trash) == -1) |
| 3659 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3660 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3661 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3662 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3663 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3664 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3665 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3666 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3667 | if (bi_putchk(rep, &trash) == -1) |
| 3668 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3669 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3670 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3671 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3672 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3673 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3674 | case STAT_PX_ST_FIN: |
| 3675 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3676 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3677 | default: |
| 3678 | /* unknown state, we should put an abort() here ! */ |
| 3679 | return 1; |
| 3680 | } |
| 3681 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3682 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3683 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3684 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3685 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3686 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3687 | { |
| 3688 | /* WARNING! This must fit in the first buffer !!! */ |
| 3689 | chunk_appendf(&trash, |
| 3690 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3691 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3692 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3693 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3694 | "<style type=\"text/css\"><!--\n" |
| 3695 | "body {" |
| 3696 | " font-family: arial, helvetica, sans-serif;" |
| 3697 | " font-size: 12px;" |
| 3698 | " font-weight: normal;" |
| 3699 | " color: black;" |
| 3700 | " background: white;" |
| 3701 | "}\n" |
| 3702 | "th,td {" |
| 3703 | " font-size: 10px;" |
| 3704 | "}\n" |
| 3705 | "h1 {" |
| 3706 | " font-size: x-large;" |
| 3707 | " margin-bottom: 0.5em;" |
| 3708 | "}\n" |
| 3709 | "h2 {" |
| 3710 | " font-family: helvetica, arial;" |
| 3711 | " font-size: x-large;" |
| 3712 | " font-weight: bold;" |
| 3713 | " font-style: italic;" |
| 3714 | " color: #6020a0;" |
| 3715 | " margin-top: 0em;" |
| 3716 | " margin-bottom: 0em;" |
| 3717 | "}\n" |
| 3718 | "h3 {" |
| 3719 | " font-family: helvetica, arial;" |
| 3720 | " font-size: 16px;" |
| 3721 | " font-weight: bold;" |
| 3722 | " color: #b00040;" |
| 3723 | " background: #e8e8d0;" |
| 3724 | " margin-top: 0em;" |
| 3725 | " margin-bottom: 0em;" |
| 3726 | "}\n" |
| 3727 | "li {" |
| 3728 | " margin-top: 0.25em;" |
| 3729 | " margin-right: 2em;" |
| 3730 | "}\n" |
| 3731 | ".hr {margin-top: 0.25em;" |
| 3732 | " border-color: black;" |
| 3733 | " border-bottom-style: solid;" |
| 3734 | "}\n" |
| 3735 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3736 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3737 | ".frontend {background: #e8e8d0;}\n" |
| 3738 | ".socket {background: #d0d0d0;}\n" |
| 3739 | ".backend {background: #e8e8d0;}\n" |
| 3740 | ".active0 {background: #ff9090;}\n" |
| 3741 | ".active1 {background: #ffd020;}\n" |
| 3742 | ".active2 {background: #ffffa0;}\n" |
| 3743 | ".active3 {background: #c0ffc0;}\n" |
| 3744 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3745 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3746 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3747 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3748 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3749 | ".backup0 {background: #ff9090;}\n" |
| 3750 | ".backup1 {background: #ff80ff;}\n" |
| 3751 | ".backup2 {background: #c060ff;}\n" |
| 3752 | ".backup3 {background: #b0d0ff;}\n" |
| 3753 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3754 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3755 | ".backup6 {background: #c060ff;}\n" |
| 3756 | ".backup7 {background: #cc9900;}\n" |
| 3757 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3758 | ".maintain {background: #c07820;}\n" |
| 3759 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3760 | "\n" |
| 3761 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3762 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3763 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3764 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3765 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3766 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3767 | "\n" |
| 3768 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3769 | "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" |
| 3770 | "table.tbl td.ac { text-align: center;}\n" |
| 3771 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3772 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3773 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3774 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3775 | "\n" |
| 3776 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3777 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3778 | "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] | 3779 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3780 | "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] | 3781 | "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] | 3782 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3783 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3784 | " display:block;\n" |
| 3785 | " visibility:hidden;\n" |
| 3786 | " z-index:2147483647;\n" |
| 3787 | " position:absolute;\n" |
| 3788 | " padding:2px 4px 3px;\n" |
| 3789 | " background:#f0f060; color:#000000;\n" |
| 3790 | " border:1px solid #7040c0;\n" |
| 3791 | " white-space:nowrap;\n" |
| 3792 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3793 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3794 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3795 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3796 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3797 | "-->\n" |
| 3798 | "</style></head>\n", |
| 3799 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3800 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3801 | ); |
| 3802 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3803 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3804 | /* 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] | 3805 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3806 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3807 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3808 | 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] | 3809 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3810 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3811 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3812 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3813 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3814 | /* WARNING! this has to fit the first packet too. |
| 3815 | * We are around 3.5 kB, add adding entries will |
| 3816 | * become tricky if we want to support 4kB buffers ! |
| 3817 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3818 | chunk_appendf(&trash, |
| 3819 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3820 | PRODUCT_NAME "%s</a></h1>\n" |
| 3821 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3822 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3823 | "<h3>> General process information</h3>\n" |
| 3824 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3825 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3826 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3827 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3828 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3829 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3830 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3831 | "</td><td align=\"center\" nowrap>\n" |
| 3832 | "<table class=\"lgd\"><tr>\n" |
| 3833 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3834 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3835 | "</tr><tr>\n" |
| 3836 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3837 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3838 | "</tr><tr>\n" |
| 3839 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3840 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3841 | "</tr><tr>\n" |
| 3842 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3843 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3844 | "</tr><tr>\n" |
| 3845 | "<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] | 3846 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3847 | "<td class=\"active7\"></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] | 3848 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3849 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3850 | "</td>" |
| 3851 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3852 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3853 | "", |
| 3854 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3855 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3856 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3857 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3858 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3859 | pid, relative_pid, global.nbproc, |
| 3860 | up / 86400, (up % 86400) / 3600, |
| 3861 | (up % 3600) / 60, (up % 60), |
| 3862 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3863 | global.rlimit_memmax ? " MB" : "", |
| 3864 | global.rlimit_nofile, |
| 3865 | global.maxsock, global.maxconn, global.maxpipes, |
| 3866 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3867 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3868 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3869 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3870 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3871 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3872 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3873 | |
| 3874 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3875 | "<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] | 3876 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3877 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3878 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3879 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3880 | STAT_SCOPE_TXT_MAXLEN); |
| 3881 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3882 | /* 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] | 3883 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3884 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3885 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3886 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3887 | 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] | 3888 | } |
| 3889 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3890 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3891 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3892 | "<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] | 3893 | uri->uri_prefix, |
| 3894 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3895 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3896 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3897 | else |
| 3898 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3899 | "<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] | 3900 | uri->uri_prefix, |
| 3901 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3902 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3903 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3904 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3905 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3906 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3907 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3908 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3909 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3910 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3911 | "", |
| 3912 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3913 | else |
| 3914 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3915 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3916 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3917 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3918 | ";norefresh", |
| 3919 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3920 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3921 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3922 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3923 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3924 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3925 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3926 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3927 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3928 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3929 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3930 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3931 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3932 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3933 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3934 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3935 | chunk_appendf(&trash, |
| 3936 | "</ul></td>" |
| 3937 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3938 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3939 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3940 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3941 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3942 | "</ul>" |
| 3943 | "</td>" |
| 3944 | "</tr></table>\n" |
| 3945 | "" |
| 3946 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3947 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3948 | if (appctx->ctx.stats.st_code) { |
| 3949 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3950 | case STAT_STATUS_DONE: |
| 3951 | chunk_appendf(&trash, |
| 3952 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3953 | "<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] | 3954 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3955 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3956 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3957 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3958 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3959 | break; |
| 3960 | case STAT_STATUS_NONE: |
| 3961 | chunk_appendf(&trash, |
| 3962 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3963 | "<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] | 3964 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3965 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3966 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3967 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3968 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3969 | break; |
| 3970 | case STAT_STATUS_PART: |
| 3971 | chunk_appendf(&trash, |
| 3972 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3973 | "<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] | 3974 | "Action partially processed.<br>" |
| 3975 | "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] | 3976 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3977 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3978 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3979 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3980 | break; |
| 3981 | case STAT_STATUS_ERRP: |
| 3982 | chunk_appendf(&trash, |
| 3983 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3984 | "<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] | 3985 | "Action not processed because of invalid parameters." |
| 3986 | "<ul>" |
| 3987 | "<li>The action is maybe unknown.</li>" |
| 3988 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3989 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3990 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3991 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3992 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3993 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3994 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3995 | break; |
| 3996 | case STAT_STATUS_EXCD: |
| 3997 | chunk_appendf(&trash, |
| 3998 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3999 | "<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] | 4000 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4001 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4002 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4003 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4004 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4005 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4006 | break; |
| 4007 | case STAT_STATUS_DENY: |
| 4008 | chunk_appendf(&trash, |
| 4009 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4010 | "<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] | 4011 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4012 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4013 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4014 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4015 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4016 | break; |
| 4017 | default: |
| 4018 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 4019 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4020 | "<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] | 4021 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4022 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4023 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4024 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4025 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4026 | } |
| 4027 | chunk_appendf(&trash, "<p>\n"); |
| 4028 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4029 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4030 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4031 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4032 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4033 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4034 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4035 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4036 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4037 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4038 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4039 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4040 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4041 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4042 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 4043 | * and the session must be closed, or -1 in case of any error. This function is |
| 4044 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4045 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4046 | 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] | 4047 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4048 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4049 | struct channel *rep = si->ib; |
| 4050 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4051 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4052 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4053 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4054 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4055 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4056 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4057 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4058 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4059 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4060 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4061 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4062 | else |
| 4063 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4064 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4065 | if (bi_putchk(rep, &trash) == -1) |
| 4066 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4067 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4068 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4069 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4070 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4071 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4072 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4073 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4074 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4075 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4076 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4077 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4078 | appctx->ctx.stats.px = proxy; |
| 4079 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4080 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4081 | /* fall through */ |
| 4082 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4083 | case STAT_ST_LIST: |
| 4084 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4085 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4086 | if (buffer_almost_full(rep->buf)) { |
| 4087 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4088 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4089 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4090 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4091 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4092 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4093 | 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] | 4094 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4095 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4096 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4097 | appctx->ctx.stats.px = px->next; |
| 4098 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4099 | } |
| 4100 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4101 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4102 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4103 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4104 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4105 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4106 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4107 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4108 | if (bi_putchk(rep, &trash) == -1) |
| 4109 | return 0; |
| 4110 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4111 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4112 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4113 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4114 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4115 | case STAT_ST_FIN: |
| 4116 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4117 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4118 | default: |
| 4119 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4120 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4121 | return -1; |
| 4122 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4123 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4124 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4125 | /* We reached the stats page through a POST request. The appctx is |
| 4126 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4127 | * Parse the posted data and enable/disable servers if necessary. |
| 4128 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4129 | */ |
| 4130 | static int stats_process_http_post(struct stream_interface *si) |
| 4131 | { |
| 4132 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4133 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4134 | |
| 4135 | struct proxy *px = NULL; |
| 4136 | struct server *sv = NULL; |
| 4137 | |
| 4138 | char key[LINESIZE]; |
| 4139 | int action = ST_ADM_ACTION_NONE; |
| 4140 | int reprocess = 0; |
| 4141 | |
| 4142 | int total_servers = 0; |
| 4143 | int altered_servers = 0; |
| 4144 | |
| 4145 | char *first_param, *cur_param, *next_param, *end_params; |
| 4146 | char *st_cur_param = NULL; |
| 4147 | char *st_next_param = NULL; |
| 4148 | |
| 4149 | struct chunk *temp; |
| 4150 | int reql; |
| 4151 | |
| 4152 | temp = get_trash_chunk(); |
| 4153 | if (temp->size < s->txn.req.body_len) { |
| 4154 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4155 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4156 | goto out; |
| 4157 | } |
| 4158 | |
| 4159 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 4160 | if (reql <= 0) { |
| 4161 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4162 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4163 | return 0; |
| 4164 | } |
| 4165 | |
| 4166 | first_param = temp->str; |
| 4167 | end_params = temp->str + reql; |
| 4168 | cur_param = next_param = end_params; |
| 4169 | *end_params = '\0'; |
| 4170 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4171 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4172 | |
| 4173 | /* |
| 4174 | * Parse the parameters in reverse order to only store the last value. |
| 4175 | * From the html form, the backend and the action are at the end. |
| 4176 | */ |
| 4177 | while (cur_param > first_param) { |
| 4178 | char *value; |
| 4179 | int poffset, plen; |
| 4180 | |
| 4181 | cur_param--; |
| 4182 | |
| 4183 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4184 | reprocess_servers: |
| 4185 | /* Parse the key */ |
| 4186 | poffset = (cur_param != first_param ? 1 : 0); |
| 4187 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4188 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4189 | strncpy(key, cur_param + poffset, plen); |
| 4190 | key[plen - 1] = '\0'; |
| 4191 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4192 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4193 | goto out; |
| 4194 | } |
| 4195 | |
| 4196 | /* Parse the value */ |
| 4197 | value = key; |
| 4198 | while (*value != '\0' && *value != '=') { |
| 4199 | value++; |
| 4200 | } |
| 4201 | if (*value == '=') { |
| 4202 | /* Ok, a value is found, we can mark the end of the key */ |
| 4203 | *value++ = '\0'; |
| 4204 | } |
| 4205 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4206 | break; |
| 4207 | |
| 4208 | /* Now we can check the key to see what to do */ |
| 4209 | if (!px && (strcmp(key, "b") == 0)) { |
| 4210 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4211 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4212 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4213 | goto out; |
| 4214 | } |
| 4215 | } |
| 4216 | else if (!action && (strcmp(key, "action") == 0)) { |
| 4217 | if (strcmp(value, "disable") == 0) { |
| 4218 | action = ST_ADM_ACTION_DISABLE; |
| 4219 | } |
| 4220 | else if (strcmp(value, "enable") == 0) { |
| 4221 | action = ST_ADM_ACTION_ENABLE; |
| 4222 | } |
| 4223 | else if (strcmp(value, "stop") == 0) { |
| 4224 | action = ST_ADM_ACTION_STOP; |
| 4225 | } |
| 4226 | else if (strcmp(value, "start") == 0) { |
| 4227 | action = ST_ADM_ACTION_START; |
| 4228 | } |
| 4229 | else if (strcmp(value, "shutdown") == 0) { |
| 4230 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4231 | } |
| 4232 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4233 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4234 | goto out; |
| 4235 | } |
| 4236 | } |
| 4237 | else if (strcmp(key, "s") == 0) { |
| 4238 | if (!(px && action)) { |
| 4239 | /* |
| 4240 | * Indicates that we'll need to reprocess the parameters |
| 4241 | * as soon as backend and action are known |
| 4242 | */ |
| 4243 | if (!reprocess) { |
| 4244 | st_cur_param = cur_param; |
| 4245 | st_next_param = next_param; |
| 4246 | } |
| 4247 | reprocess = 1; |
| 4248 | } |
| 4249 | else if ((sv = findserver(px, value)) != NULL) { |
| 4250 | switch (action) { |
| 4251 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 4252 | if ((px->state != PR_STSTOPPED) && !(sv->admin & SRV_ADMF_MAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4253 | /* Not already in maintenance, we can change the server state */ |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 4254 | sv->admin |= SRV_ADMF_FMAINT; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 4255 | sv->check.state |= CHK_ST_PAUSED; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4256 | set_server_down(&sv->check); |
| 4257 | altered_servers++; |
| 4258 | total_servers++; |
| 4259 | } |
| 4260 | break; |
| 4261 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 4262 | if ((px->state != PR_STSTOPPED) && (sv->admin & SRV_ADMF_MAINT)) { |
Willy Tarreau | a3ae932 | 2013-12-28 21:28:49 +0100 | [diff] [blame] | 4263 | /* Already in maintenance, we can change the server state. |
| 4264 | * If this server tracks the status of another one, |
| 4265 | * we must restore the good status. |
| 4266 | */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 4267 | if (!sv->track || (sv->track->state != SRV_ST_STOPPED)) { |
Willy Tarreau | a3ae932 | 2013-12-28 21:28:49 +0100 | [diff] [blame] | 4268 | set_server_up(&sv->check); |
| 4269 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 4270 | } |
| 4271 | else { |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 4272 | sv->admin &= ~SRV_ADMF_FMAINT; |
Willy Tarreau | a3ae932 | 2013-12-28 21:28:49 +0100 | [diff] [blame] | 4273 | sv->check.state &= ~CHK_ST_PAUSED; |
| 4274 | set_server_down(&sv->check); |
| 4275 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4276 | altered_servers++; |
| 4277 | total_servers++; |
| 4278 | } |
| 4279 | break; |
| 4280 | case ST_ADM_ACTION_STOP: |
| 4281 | case ST_ADM_ACTION_START: |
| 4282 | if (action == ST_ADM_ACTION_START) |
| 4283 | sv->uweight = sv->iweight; |
| 4284 | else |
| 4285 | sv->uweight = 0; |
| 4286 | |
| 4287 | server_recalc_eweight(sv); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4288 | |
| 4289 | altered_servers++; |
| 4290 | total_servers++; |
| 4291 | break; |
| 4292 | case ST_ADM_ACTION_SHUTDOWN: |
| 4293 | if (px->state != PR_STSTOPPED) { |
| 4294 | struct session *sess, *sess_bck; |
| 4295 | |
| 4296 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4297 | if (sess->srv_conn == sv) |
| 4298 | session_shutdown(sess, SN_ERR_KILLED); |
| 4299 | |
| 4300 | altered_servers++; |
| 4301 | total_servers++; |
| 4302 | } |
| 4303 | break; |
| 4304 | } |
| 4305 | } else { |
| 4306 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4307 | total_servers++; |
| 4308 | } |
| 4309 | } |
| 4310 | if (reprocess && px && action) { |
| 4311 | /* Now, we know the backend and the action chosen by the user. |
| 4312 | * We can safely restart from the first server parameter |
| 4313 | * to reprocess them |
| 4314 | */ |
| 4315 | cur_param = st_cur_param; |
| 4316 | next_param = st_next_param; |
| 4317 | reprocess = 0; |
| 4318 | goto reprocess_servers; |
| 4319 | } |
| 4320 | |
| 4321 | next_param = cur_param; |
| 4322 | } |
| 4323 | } |
| 4324 | |
| 4325 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4326 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4327 | } |
| 4328 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4329 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4330 | } |
| 4331 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4332 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4333 | } |
| 4334 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4335 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4336 | } |
| 4337 | out: |
| 4338 | return 1; |
| 4339 | } |
| 4340 | |
| 4341 | |
| 4342 | static int stats_send_http_headers(struct stream_interface *si) |
| 4343 | { |
| 4344 | struct session *s = session_from_task(si->owner); |
| 4345 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4346 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4347 | |
| 4348 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4349 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4350 | "Cache-Control: no-cache\r\n" |
| 4351 | "Connection: close\r\n" |
| 4352 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4353 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4354 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4355 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4356 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4357 | uri->refresh); |
| 4358 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4359 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4360 | |
| 4361 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4362 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4363 | else |
| 4364 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4365 | |
| 4366 | s->txn.status = 200; |
| 4367 | s->logs.tv_request = now; |
| 4368 | |
| 4369 | if (bi_putchk(si->ib, &trash) == -1) |
| 4370 | return 0; |
| 4371 | |
| 4372 | return 1; |
| 4373 | } |
| 4374 | |
| 4375 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4376 | { |
| 4377 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4378 | struct session *s = session_from_task(si->owner); |
| 4379 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4380 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4381 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4382 | /* 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] | 4383 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4384 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4385 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4386 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4387 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | /* We don't want to land on the posted stats page because a refresh will |
| 4391 | * repost the data. We don't want this to happen on accident so we redirect |
| 4392 | * the browse to the stats page with a GET. |
| 4393 | */ |
| 4394 | chunk_printf(&trash, |
| 4395 | "HTTP/1.1 303 See Other\r\n" |
| 4396 | "Cache-Control: no-cache\r\n" |
| 4397 | "Content-Type: text/plain\r\n" |
| 4398 | "Connection: close\r\n" |
| 4399 | "Location: %s;st=%s%s%s%s\r\n" |
| 4400 | "\r\n", |
| 4401 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4402 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4403 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4404 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4405 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4406 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4407 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4408 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4409 | scope_txt); |
| 4410 | |
| 4411 | s->txn.status = 303; |
| 4412 | s->logs.tv_request = now; |
| 4413 | |
| 4414 | if (bi_putchk(si->ib, &trash) == -1) |
| 4415 | return 0; |
| 4416 | |
| 4417 | return 1; |
| 4418 | } |
| 4419 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4420 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4421 | * 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] | 4422 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4423 | * automatically unregisters itself once transfer is complete. |
| 4424 | */ |
| 4425 | static void http_stats_io_handler(struct stream_interface *si) |
| 4426 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4427 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4428 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4429 | struct channel *req = si->ob; |
| 4430 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4431 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4432 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4433 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4434 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4435 | /* check that the output is not closed */ |
| 4436 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4437 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4438 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4439 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4440 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4441 | if (stats_send_http_headers(si)) { |
| 4442 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4443 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4444 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4445 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4446 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4447 | } |
| 4448 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4449 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4450 | unsigned int prev_len = si->ib->buf->i; |
| 4451 | unsigned int data_len; |
| 4452 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 4453 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4454 | |
| 4455 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4456 | /* One difficulty we're facing is that we must prevent |
| 4457 | * the input data from being automatically forwarded to |
| 4458 | * the output area. For this, we temporarily disable |
| 4459 | * forwarding on the channel. |
| 4460 | */ |
| 4461 | last_fwd = si->ib->to_forward; |
| 4462 | si->ib->to_forward = 0; |
| 4463 | chunk_printf(&trash, "\r\n000000\r\n"); |
| 4464 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4465 | si->ib->to_forward = last_fwd; |
| 4466 | goto fail; |
| 4467 | } |
| 4468 | } |
| 4469 | |
| 4470 | data_len = si->ib->buf->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4471 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4472 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4473 | |
| 4474 | last_len = si->ib->buf->i; |
| 4475 | |
| 4476 | /* Now we must either adjust or remove the chunk size. This is |
| 4477 | * not easy because the chunk size might wrap at the end of the |
| 4478 | * buffer, so we pretend we have nothing in the buffer, we write |
| 4479 | * the size, then restore the buffer's contents. Note that we can |
| 4480 | * only do that because no forwarding is scheduled on the stats |
| 4481 | * applet. |
| 4482 | */ |
| 4483 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4484 | si->ib->total -= (last_len - prev_len); |
| 4485 | si->ib->buf->i -= (last_len - prev_len); |
| 4486 | |
| 4487 | if (last_len != data_len) { |
| 4488 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
| 4489 | bi_putchk(si->ib, &trash); |
| 4490 | |
| 4491 | si->ib->total += (last_len - data_len); |
| 4492 | si->ib->buf->i += (last_len - data_len); |
| 4493 | } |
| 4494 | /* now re-enable forwarding */ |
| 4495 | channel_forward(si->ib, last_fwd); |
| 4496 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4497 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4498 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4499 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4500 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4501 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4502 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4503 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4504 | } |
| 4505 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4506 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4507 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4508 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4509 | } |
| 4510 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4511 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 4512 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4513 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
| 4514 | if (bi_putchk(si->ib, &trash) == -1) |
| 4515 | goto fail; |
| 4516 | } |
| 4517 | /* eat the whole request */ |
| 4518 | bo_skip(si->ob, si->ob->buf->o); |
| 4519 | res->flags |= CF_READ_NULL; |
| 4520 | si_shutr(si); |
| 4521 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4522 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4523 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4524 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4525 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4526 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4527 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4528 | si_shutr(si); |
| 4529 | res->flags |= CF_READ_NULL; |
| 4530 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4531 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4532 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4533 | fail: |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4534 | /* update all other flags and resync with the other side */ |
| 4535 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4536 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4537 | /* we don't want to expire timeouts while we're processing requests */ |
| 4538 | si->ib->rex = TICK_ETERNITY; |
| 4539 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4540 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4541 | out: |
| 4542 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4543 | /* check that we have released everything then unregister */ |
| 4544 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4545 | } |
| 4546 | } |
| 4547 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4548 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4549 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4550 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4551 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4552 | return "NONE"; |
| 4553 | return conn->ctrl->name; |
| 4554 | } |
| 4555 | |
| 4556 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4557 | { |
| 4558 | static char ptr[17]; |
| 4559 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4560 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4561 | return "NONE"; |
| 4562 | |
| 4563 | if (conn->xprt == &raw_sock) |
| 4564 | return "RAW"; |
| 4565 | |
| 4566 | #ifdef USE_OPENSSL |
| 4567 | if (conn->xprt == &ssl_sock) |
| 4568 | return "SSL"; |
| 4569 | #endif |
| 4570 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4571 | return ptr; |
| 4572 | } |
| 4573 | |
| 4574 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4575 | { |
| 4576 | static char ptr[17]; |
| 4577 | |
| 4578 | if (!conn->data) |
| 4579 | return "NONE"; |
| 4580 | |
| 4581 | if (conn->data == &sess_conn_cb) |
| 4582 | return "SESS"; |
| 4583 | |
| 4584 | if (conn->data == &si_conn_cb) |
| 4585 | return "STRM"; |
| 4586 | |
| 4587 | if (conn->data == &check_conn_cb) |
| 4588 | return "CHCK"; |
| 4589 | |
| 4590 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4591 | return ptr; |
| 4592 | } |
| 4593 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4594 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4595 | * 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] | 4596 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4597 | * 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] | 4598 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4599 | 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] | 4600 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4601 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4602 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4603 | extern const char *monthname[12]; |
| 4604 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4605 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4606 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4607 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4608 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4609 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4610 | 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] | 4611 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4612 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4613 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4614 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4615 | appctx->ctx.sess.uid = 0; |
| 4616 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4617 | return 1; |
| 4618 | } |
| 4619 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4620 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4621 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4622 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4623 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4624 | /* fall through */ |
| 4625 | |
| 4626 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4627 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4628 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4629 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4630 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4631 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4632 | 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] | 4633 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 4634 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4635 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4636 | conn = objt_conn(sess->si[0].end); |
| 4637 | 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] | 4638 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4639 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4640 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4641 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4642 | break; |
| 4643 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4644 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4645 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4646 | default: |
| 4647 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4648 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4649 | break; |
| 4650 | } |
| 4651 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4652 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4653 | " 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] | 4654 | 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] | 4655 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4656 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4657 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4658 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 4659 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 4660 | sess->listener ? sess->listener->luid : 0); |
| 4661 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4662 | if (conn) |
| 4663 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4664 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4665 | 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] | 4666 | case AF_INET: |
| 4667 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4668 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4669 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4670 | break; |
| 4671 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4672 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4673 | break; |
| 4674 | default: |
| 4675 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4676 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4677 | break; |
| 4678 | } |
| 4679 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4680 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4681 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4682 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4683 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4684 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 4685 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4686 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4687 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4688 | conn = objt_conn(sess->si[1].end); |
| 4689 | if (conn) |
| 4690 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4691 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4692 | 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] | 4693 | case AF_INET: |
| 4694 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4695 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4696 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4697 | break; |
| 4698 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4699 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4700 | break; |
| 4701 | default: |
| 4702 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4703 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4704 | break; |
| 4705 | } |
| 4706 | |
| 4707 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4708 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4709 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4710 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 4711 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4712 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4713 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4714 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4715 | if (conn) |
| 4716 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4717 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4718 | 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] | 4719 | case AF_INET: |
| 4720 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4721 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4722 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4723 | break; |
| 4724 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4725 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4726 | break; |
| 4727 | default: |
| 4728 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4729 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4730 | break; |
| 4731 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4732 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4733 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4734 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4735 | sess->task, |
| 4736 | sess->task->state, |
| 4737 | sess->task->nice, sess->task->calls, |
| 4738 | sess->task->expire ? |
| 4739 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4740 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4741 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4742 | task_in_rq(sess->task) ? ", running" : ""); |
| 4743 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4744 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4745 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4746 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4747 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4748 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4749 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4750 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4751 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4752 | |
| 4753 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4754 | " 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] | 4755 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4756 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4757 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4758 | obj_type_name(sess->si[0].end), |
| 4759 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4760 | sess->si[0].exp ? |
| 4761 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4762 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4763 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4764 | sess->si[0].err_type); |
| 4765 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4766 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4767 | " 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] | 4768 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4769 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4770 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4771 | obj_type_name(sess->si[1].end), |
| 4772 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4773 | sess->si[1].exp ? |
| 4774 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4775 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4776 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4777 | sess->si[1].err_type); |
| 4778 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4779 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4780 | chunk_appendf(&trash, |
| 4781 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4782 | conn, |
| 4783 | get_conn_ctrl_name(conn), |
| 4784 | get_conn_xprt_name(conn), |
| 4785 | get_conn_data_name(conn), |
| 4786 | obj_type_name(conn->target), |
| 4787 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4788 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4789 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 4790 | " 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] | 4791 | conn->flags, |
| 4792 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4793 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4794 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4795 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4796 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4797 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 4798 | chunk_appendf(&trash, |
| 4799 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4800 | tmpctx, |
| 4801 | tmpctx->st0, |
| 4802 | tmpctx->st1, |
| 4803 | tmpctx->st2, |
| 4804 | tmpctx->applet->name); |
| 4805 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4806 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4807 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4808 | chunk_appendf(&trash, |
| 4809 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4810 | conn, |
| 4811 | get_conn_ctrl_name(conn), |
| 4812 | get_conn_xprt_name(conn), |
| 4813 | get_conn_data_name(conn), |
| 4814 | obj_type_name(conn->target), |
| 4815 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4816 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4817 | chunk_appendf(&trash, |
| 4818 | " 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] | 4819 | conn->flags, |
| 4820 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4821 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4822 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4823 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4824 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4825 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 4826 | chunk_appendf(&trash, |
| 4827 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4828 | tmpctx, |
| 4829 | tmpctx->st0, |
| 4830 | tmpctx->st1, |
| 4831 | tmpctx->st2, |
| 4832 | tmpctx->applet->name); |
| 4833 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4834 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4835 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4836 | " 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] | 4837 | " an_exp=%s", |
| 4838 | sess->req, |
| 4839 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4840 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4841 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4842 | sess->req->analyse_exp ? |
| 4843 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4844 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4845 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4846 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4847 | " rex=%s", |
| 4848 | sess->req->rex ? |
| 4849 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4850 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4851 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4852 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4853 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4854 | " 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] | 4855 | sess->req->wex ? |
| 4856 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4857 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4858 | sess->req->buf, |
| 4859 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4860 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4861 | sess->txn.req.next, sess->req->buf->i, |
| 4862 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4863 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4864 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4865 | " 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] | 4866 | " an_exp=%s", |
| 4867 | sess->rep, |
| 4868 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4869 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4870 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4871 | sess->rep->analyse_exp ? |
| 4872 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4873 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4874 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4875 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4876 | " rex=%s", |
| 4877 | sess->rep->rex ? |
| 4878 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4879 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4880 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4881 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4882 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4883 | " 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] | 4884 | sess->rep->wex ? |
| 4885 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4886 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4887 | sess->rep->buf, |
| 4888 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4889 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4890 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4891 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4892 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4893 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4894 | return 0; |
| 4895 | |
| 4896 | /* use other states to dump the contents */ |
| 4897 | } |
| 4898 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4899 | appctx->ctx.sess.uid = 0; |
| 4900 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4901 | return 1; |
| 4902 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4903 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4904 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4905 | { |
| 4906 | struct appctx *appctx = __objt_appctx(si->end); |
| 4907 | |
| 4908 | switch (appctx->st2) { |
| 4909 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4910 | /* Display the column headers. If the message cannot be sent, |
| 4911 | * quit the fucntion with returning 0. The function is called |
| 4912 | * later and restart at the state "STAT_ST_INIT". |
| 4913 | */ |
| 4914 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 4915 | chunk_appendf(&trash, "# id (file) description\n"); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4916 | if (bi_putchk(si->ib, &trash) == -1) |
| 4917 | return 0; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4918 | |
| 4919 | /* Now, we start the browsing of the references lists. |
| 4920 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 4921 | * avalaible field of this pointer is <list>. It is used with the function |
| 4922 | * pat_list_get_next() for retruning the first avalaible entry |
| 4923 | */ |
| 4924 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 4925 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 4926 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4927 | appctx->st2 = STAT_ST_LIST; |
| 4928 | /* fall through */ |
| 4929 | |
| 4930 | case STAT_ST_LIST: |
| 4931 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4932 | chunk_reset(&trash); |
| 4933 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4934 | /* Build messages. If the reference is used by another category than |
| 4935 | * the listed categorie, display the information in the massage. |
| 4936 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 4937 | 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] | 4938 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 4939 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4940 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4941 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4942 | /* let's try again later from this session. We add ourselves into |
| 4943 | * this session's users so that it can remove us upon termination. |
| 4944 | */ |
| 4945 | return 0; |
| 4946 | } |
| 4947 | |
| 4948 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4949 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 4950 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4951 | } |
| 4952 | |
| 4953 | appctx->st2 = STAT_ST_FIN; |
| 4954 | /* fall through */ |
| 4955 | |
| 4956 | default: |
| 4957 | appctx->st2 = STAT_ST_FIN; |
| 4958 | return 1; |
| 4959 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4960 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4961 | } |
| 4962 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4963 | static int stats_map_lookup(struct stream_interface *si) |
| 4964 | { |
| 4965 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4966 | struct sample sample; |
| 4967 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4968 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4969 | |
| 4970 | switch (appctx->st2) { |
| 4971 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4972 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 4973 | 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] | 4974 | 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] | 4975 | appctx->st2 = STAT_ST_LIST; |
| 4976 | /* fall through */ |
| 4977 | |
| 4978 | case STAT_ST_LIST: |
| 4979 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4980 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4981 | /* initialise chunk to build new message */ |
| 4982 | chunk_reset(&trash); |
| 4983 | |
| 4984 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 4985 | sample.type = SMP_T_STR; |
| 4986 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4987 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 4988 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 4989 | if (appctx->ctx.map.expr->pat_head->match && |
| 4990 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4991 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 4992 | else |
| 4993 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4994 | |
| 4995 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4996 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 4997 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 4998 | break; |
| 4999 | if (match_method >= PAT_MATCH_NUM) |
| 5000 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5001 | else |
| 5002 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5003 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5004 | /* case sensitive */ |
| 5005 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5006 | chunk_appendf(&trash, ", case=insensitive"); |
| 5007 | else |
| 5008 | chunk_appendf(&trash, ", case=sensitive"); |
| 5009 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5010 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5011 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5012 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5013 | chunk_appendf(&trash, ", found=no"); |
| 5014 | else |
| 5015 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5016 | } |
| 5017 | |
| 5018 | /* Display match and match info */ |
| 5019 | else { |
| 5020 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5021 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5022 | chunk_appendf(&trash, ", found=yes"); |
| 5023 | else |
| 5024 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5025 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5026 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5027 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5028 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5029 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5030 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5031 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5032 | /* display pattern */ |
| 5033 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5034 | if (pat->ref && pat->ref->pattern) |
| 5035 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5036 | else |
| 5037 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5038 | } |
| 5039 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5040 | if (pat->ref && pat->ref->pattern) |
| 5041 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5042 | else |
| 5043 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5044 | } |
| 5045 | |
| 5046 | /* display return value */ |
| 5047 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5048 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5049 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5050 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5051 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5052 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5053 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5054 | } |
| 5055 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5056 | chunk_appendf(&trash, "\n"); |
| 5057 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5058 | /* display response */ |
| 5059 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5060 | /* let's try again later from this session. We add ourselves into |
| 5061 | * this session's users so that it can remove us upon termination. |
| 5062 | */ |
| 5063 | return 0; |
| 5064 | } |
| 5065 | |
| 5066 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5067 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5068 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | appctx->st2 = STAT_ST_FIN; |
| 5072 | /* fall through */ |
| 5073 | |
| 5074 | default: |
| 5075 | appctx->st2 = STAT_ST_FIN; |
| 5076 | free(appctx->ctx.map.chunk.str); |
| 5077 | return 1; |
| 5078 | } |
| 5079 | } |
| 5080 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5081 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5082 | { |
| 5083 | struct appctx *appctx = __objt_appctx(si->end); |
| 5084 | |
| 5085 | switch (appctx->st2) { |
| 5086 | |
| 5087 | case STAT_ST_INIT: |
| 5088 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5089 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5090 | struct pat_ref_elt *, list); |
| 5091 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5092 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5093 | appctx->st2 = STAT_ST_LIST; |
| 5094 | /* fall through */ |
| 5095 | |
| 5096 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5097 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5098 | chunk_reset(&trash); |
| 5099 | |
| 5100 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5101 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5102 | chunk_appendf(&trash, "%p %s %s\n", |
| 5103 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5104 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5105 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5106 | chunk_appendf(&trash, "%p %s\n", |
| 5107 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5108 | |
| 5109 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5110 | /* let's try again later from this session. We add ourselves into |
| 5111 | * this session's users so that it can remove us upon termination. |
| 5112 | */ |
| 5113 | return 0; |
| 5114 | } |
| 5115 | |
| 5116 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5117 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5118 | struct pat_ref_elt *, list); |
| 5119 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5120 | break; |
| 5121 | } |
| 5122 | |
| 5123 | appctx->st2 = STAT_ST_FIN; |
| 5124 | /* fall through */ |
| 5125 | |
| 5126 | default: |
| 5127 | appctx->st2 = STAT_ST_FIN; |
| 5128 | return 1; |
| 5129 | } |
| 5130 | } |
| 5131 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5132 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5133 | * 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] | 5134 | * to be called again, otherwise non-zero. It is designed to be called |
| 5135 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5136 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5137 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5138 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5139 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5140 | struct connection *conn; |
| 5141 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5142 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5143 | /* If we're forced to shut down, we might have to remove our |
| 5144 | * reference to the last session being dumped. |
| 5145 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5146 | if (appctx->st2 == STAT_ST_LIST) { |
| 5147 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5148 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5149 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5150 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5151 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5152 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5153 | } |
| 5154 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5155 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5156 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5157 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5158 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5159 | /* the function had not been called yet, let's prepare the |
| 5160 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5161 | * pointer to the first in the global list. When a target |
| 5162 | * session is being destroyed, it is responsible for updating |
| 5163 | * this pointer. We know we have reached the end when this |
| 5164 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5165 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5166 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5167 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5168 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5169 | /* fall through */ |
| 5170 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5171 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5172 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5173 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5174 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5175 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5179 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5180 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5181 | struct session *curr_sess; |
| 5182 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5183 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5184 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5185 | if (appctx->ctx.sess.target) { |
| 5186 | 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] | 5187 | goto next_sess; |
| 5188 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5189 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5190 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5191 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5192 | return 0; |
| 5193 | |
| 5194 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5195 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5196 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5197 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5198 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5199 | break; |
| 5200 | } |
| 5201 | else |
| 5202 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5203 | } |
| 5204 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5205 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5206 | "%p: proto=%s", |
| 5207 | curr_sess, |
| 5208 | curr_sess->listener->proto->name); |
| 5209 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5210 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5211 | conn = objt_conn(curr_sess->si[0].end); |
| 5212 | 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] | 5213 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5214 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5215 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5216 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5217 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5218 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5219 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5220 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5221 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5222 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5223 | break; |
| 5224 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5225 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5226 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5227 | curr_sess->listener->luid, |
| 5228 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5229 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5230 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5231 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5232 | break; |
| 5233 | } |
| 5234 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5235 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5236 | " ts=%02x age=%s calls=%d", |
| 5237 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5238 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5239 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5240 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5241 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5242 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5243 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5244 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5245 | curr_sess->req->analysers, |
| 5246 | curr_sess->req->rex ? |
| 5247 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 5248 | TICKS_TO_MS(1000)) : ""); |
| 5249 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5250 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5251 | ",wx=%s", |
| 5252 | curr_sess->req->wex ? |
| 5253 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 5254 | TICKS_TO_MS(1000)) : ""); |
| 5255 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5256 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5257 | ",ax=%s]", |
| 5258 | curr_sess->req->analyse_exp ? |
| 5259 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 5260 | TICKS_TO_MS(1000)) : ""); |
| 5261 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5262 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5263 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5264 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5265 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5266 | curr_sess->rep->analysers, |
| 5267 | curr_sess->rep->rex ? |
| 5268 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5269 | TICKS_TO_MS(1000)) : ""); |
| 5270 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5271 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5272 | ",wx=%s", |
| 5273 | curr_sess->rep->wex ? |
| 5274 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 5275 | TICKS_TO_MS(1000)) : ""); |
| 5276 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5277 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5278 | ",ax=%s]", |
| 5279 | curr_sess->rep->analyse_exp ? |
| 5280 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5281 | TICKS_TO_MS(1000)) : ""); |
| 5282 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5283 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5284 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5285 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5286 | curr_sess->si[0].state, |
| 5287 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5288 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5289 | curr_sess->si[0].exp ? |
| 5290 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5291 | TICKS_TO_MS(1000)) : ""); |
| 5292 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5293 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5294 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5295 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5296 | curr_sess->si[1].state, |
| 5297 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5298 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5299 | curr_sess->si[1].exp ? |
| 5300 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5301 | TICKS_TO_MS(1000)) : ""); |
| 5302 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5303 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5304 | " exp=%s", |
| 5305 | curr_sess->task->expire ? |
| 5306 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5307 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5308 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5309 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5310 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5311 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5312 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5313 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5314 | /* let's try again later from this session. We add ourselves into |
| 5315 | * this session's users so that it can remove us upon termination. |
| 5316 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5317 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5318 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5319 | } |
| 5320 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5321 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5322 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5323 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5324 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5325 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5326 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5327 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5328 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5329 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5330 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5331 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5332 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5333 | return 0; |
| 5334 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5335 | appctx->ctx.sess.target = NULL; |
| 5336 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5337 | return 1; |
| 5338 | } |
| 5339 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5340 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5341 | /* fall through */ |
| 5342 | |
| 5343 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5344 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5345 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5346 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5347 | } |
| 5348 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5349 | /* This is called when the stream interface is closed. For instance, upon an |
| 5350 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5351 | * remove back references to the session currently being dumped. |
| 5352 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5353 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5354 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5355 | struct appctx *appctx = __objt_appctx(si->end); |
| 5356 | |
| 5357 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5358 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5359 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5360 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5361 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5362 | free(appctx->ctx.cli.err); |
| 5363 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5364 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5365 | free(appctx->ctx.map.chunk.str); |
| 5366 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5367 | } |
| 5368 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5369 | /* This function is used to either dump tables states (when action is set |
| 5370 | * 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] | 5371 | * It returns 0 if the output buffer is full and it needs to be called |
| 5372 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5373 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5374 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5375 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5376 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5377 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5378 | struct ebmb_node *eb; |
| 5379 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5380 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5381 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5382 | |
| 5383 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5384 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5385 | * - STAT_ST_INIT : the first call |
| 5386 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5387 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5388 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5389 | * and the entry pointer points to the next entry to be dumped, |
| 5390 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5391 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5392 | * data though. |
| 5393 | */ |
| 5394 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5395 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5396 | /* 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] | 5397 | if (appctx->st2 == STAT_ST_LIST) { |
| 5398 | appctx->ctx.table.entry->ref_cnt--; |
| 5399 | 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] | 5400 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5401 | return 1; |
| 5402 | } |
| 5403 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5404 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5405 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5406 | while (appctx->st2 != STAT_ST_FIN) { |
| 5407 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5408 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5409 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5410 | if (!appctx->ctx.table.proxy) |
| 5411 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5412 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5413 | appctx->ctx.table.entry = NULL; |
| 5414 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5415 | break; |
| 5416 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5417 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5418 | if (!appctx->ctx.table.proxy || |
| 5419 | (appctx->ctx.table.target && |
| 5420 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5421 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5422 | break; |
| 5423 | } |
| 5424 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5425 | if (appctx->ctx.table.proxy->table.size) { |
| 5426 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5427 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5428 | return 0; |
| 5429 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5430 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5431 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5432 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5433 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5434 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5435 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5436 | appctx->ctx.table.entry->ref_cnt++; |
| 5437 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5438 | break; |
| 5439 | } |
| 5440 | } |
| 5441 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5442 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5443 | break; |
| 5444 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5445 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5446 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5447 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5448 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5449 | /* we're filtering on some data contents */ |
| 5450 | void *ptr; |
| 5451 | long long data; |
| 5452 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5453 | dt = appctx->ctx.table.data_type; |
| 5454 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5455 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5456 | dt); |
| 5457 | |
| 5458 | data = 0; |
| 5459 | switch (stktable_data_types[dt].std_type) { |
| 5460 | case STD_T_SINT: |
| 5461 | data = stktable_data_cast(ptr, std_t_sint); |
| 5462 | break; |
| 5463 | case STD_T_UINT: |
| 5464 | data = stktable_data_cast(ptr, std_t_uint); |
| 5465 | break; |
| 5466 | case STD_T_ULL: |
| 5467 | data = stktable_data_cast(ptr, std_t_ull); |
| 5468 | break; |
| 5469 | case STD_T_FRQP: |
| 5470 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5471 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5472 | break; |
| 5473 | } |
| 5474 | |
| 5475 | /* 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] | 5476 | if ((data < appctx->ctx.table.value && |
| 5477 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5478 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5479 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5480 | (data == appctx->ctx.table.value && |
| 5481 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5482 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5483 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5484 | (data > appctx->ctx.table.value && |
| 5485 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5486 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5487 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5488 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5489 | } |
| 5490 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5491 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5492 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5493 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5494 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5495 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5496 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5497 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5498 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5499 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5500 | struct stksess *old = appctx->ctx.table.entry; |
| 5501 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5502 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5503 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5504 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5505 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5506 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5507 | break; |
| 5508 | } |
| 5509 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5510 | |
| 5511 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5512 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5513 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5514 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5515 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5516 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5517 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5518 | break; |
| 5519 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5520 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5521 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5522 | break; |
| 5523 | } |
| 5524 | } |
| 5525 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5526 | } |
| 5527 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5528 | /* 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] | 5529 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5530 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5531 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5532 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5533 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5534 | * after the offset. The new pointer is returned. |
| 5535 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5536 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5537 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5538 | { |
| 5539 | int end; |
| 5540 | unsigned char c; |
| 5541 | |
| 5542 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5543 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5544 | return ptr; |
| 5545 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5546 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5547 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5548 | while (ptr < len && ptr < bsize) { |
| 5549 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5550 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5551 | if (out->len > end - 2) |
| 5552 | break; |
| 5553 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5554 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5555 | if (out->len > end - 3) |
| 5556 | break; |
| 5557 | out->str[out->len++] = '\\'; |
| 5558 | switch (c) { |
| 5559 | case '\t': c = 't'; break; |
| 5560 | case '\n': c = 'n'; break; |
| 5561 | case '\r': c = 'r'; break; |
| 5562 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5563 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5564 | } |
| 5565 | out->str[out->len++] = c; |
| 5566 | } else { |
| 5567 | if (out->len > end - 5) |
| 5568 | break; |
| 5569 | out->str[out->len++] = '\\'; |
| 5570 | out->str[out->len++] = 'x'; |
| 5571 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5572 | out->str[out->len++] = hextab[c & 0xF]; |
| 5573 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5574 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5575 | /* we had a line break, let's return now */ |
| 5576 | out->str[out->len++] = '\n'; |
| 5577 | *line = ptr; |
| 5578 | return ptr; |
| 5579 | } |
| 5580 | } |
| 5581 | /* we have an incomplete line, we return it as-is */ |
| 5582 | out->str[out->len++] = '\n'; |
| 5583 | return ptr; |
| 5584 | } |
| 5585 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5586 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5587 | * 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] | 5588 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5589 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5590 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5591 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5592 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5593 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5594 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5595 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5596 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5597 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5598 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5599 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5600 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5601 | /* the function had not been called yet, let's prepare the |
| 5602 | * buffer for a response. |
| 5603 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5604 | struct tm tm; |
| 5605 | |
| 5606 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5607 | 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] | 5608 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5609 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5610 | error_snapshot_id); |
| 5611 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5612 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5613 | /* Socket buffer full. Let's try again later from the same point */ |
| 5614 | return 0; |
| 5615 | } |
| 5616 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5617 | appctx->ctx.errors.px = proxy; |
| 5618 | appctx->ctx.errors.buf = 0; |
| 5619 | appctx->ctx.errors.bol = 0; |
| 5620 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5621 | } |
| 5622 | |
| 5623 | /* we have two inner loops here, one for the proxy, the other one for |
| 5624 | * the buffer. |
| 5625 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5626 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5627 | struct error_snapshot *es; |
| 5628 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5629 | if (appctx->ctx.errors.buf == 0) |
| 5630 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5631 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5632 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5633 | |
| 5634 | if (!es->when.tv_sec) |
| 5635 | goto next; |
| 5636 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5637 | if (appctx->ctx.errors.iid >= 0 && |
| 5638 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 5639 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5640 | goto next; |
| 5641 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5642 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5643 | /* just print headers now */ |
| 5644 | |
| 5645 | char pn[INET6_ADDRSTRLEN]; |
| 5646 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5647 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5648 | |
| 5649 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5650 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5651 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5652 | 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] | 5653 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5654 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 5655 | case AF_INET: |
| 5656 | case AF_INET6: |
| 5657 | port = get_host_port(&es->src); |
| 5658 | break; |
| 5659 | default: |
| 5660 | port = 0; |
| 5661 | } |
| 5662 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5663 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5664 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5665 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5666 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5667 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5668 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5669 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 5670 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5671 | break; |
| 5672 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5673 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5674 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5675 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5676 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5677 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5678 | break; |
| 5679 | } |
| 5680 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5681 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5682 | ", server %s (#%d), event #%u\n" |
| 5683 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 5684 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 5685 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 5686 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 5687 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 5688 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 5689 | es->ev_id, |
| 5690 | pn, port, es->sid, es->s_flags, |
| 5691 | es->state, es->m_flags, es->t_flags, |
| 5692 | es->m_clen, es->m_blen, |
| 5693 | es->b_flags, es->b_out, es->b_tot, |
| 5694 | es->len, es->b_wrap, es->pos); |
| 5695 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5696 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5697 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5698 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5699 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5700 | appctx->ctx.errors.ptr = 0; |
| 5701 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5702 | } |
| 5703 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5704 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5705 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5706 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5707 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5708 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5709 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5710 | goto next; |
| 5711 | } |
| 5712 | |
| 5713 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5714 | 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] | 5715 | int newptr; |
| 5716 | int newline; |
| 5717 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5718 | newline = appctx->ctx.errors.bol; |
| 5719 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 5720 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5721 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5722 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5723 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5724 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5725 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5726 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5727 | appctx->ctx.errors.ptr = newptr; |
| 5728 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5729 | }; |
| 5730 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5731 | appctx->ctx.errors.bol = 0; |
| 5732 | appctx->ctx.errors.ptr = -1; |
| 5733 | appctx->ctx.errors.buf++; |
| 5734 | if (appctx->ctx.errors.buf > 1) { |
| 5735 | appctx->ctx.errors.buf = 0; |
| 5736 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5741 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5742 | } |
| 5743 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5744 | /* parse the "level" argument on the bind lines */ |
| 5745 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 5746 | { |
| 5747 | if (!*args[cur_arg + 1]) { |
| 5748 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 5749 | return ERR_ALERT | ERR_FATAL; |
| 5750 | } |
| 5751 | |
| 5752 | if (!strcmp(args[cur_arg+1], "user")) |
| 5753 | conf->level = ACCESS_LVL_USER; |
| 5754 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 5755 | conf->level = ACCESS_LVL_OPER; |
| 5756 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 5757 | conf->level = ACCESS_LVL_ADMIN; |
| 5758 | else { |
| 5759 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 5760 | args[cur_arg], args[cur_arg+1]); |
| 5761 | return ERR_ALERT | ERR_FATAL; |
| 5762 | } |
| 5763 | |
| 5764 | return 0; |
| 5765 | } |
| 5766 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5767 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5768 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5769 | .name = "<STATS>", /* used for logging */ |
| 5770 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 5771 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5772 | }; |
| 5773 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5774 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5775 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5776 | .name = "<CLI>", /* used for logging */ |
| 5777 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5778 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5779 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5780 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 5781 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5782 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 5783 | { 0, NULL, NULL }, |
| 5784 | }}; |
| 5785 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5786 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 5787 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 5788 | { NULL, NULL, 0 }, |
| 5789 | }}; |
| 5790 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5791 | __attribute__((constructor)) |
| 5792 | static void __dumpstats_module_init(void) |
| 5793 | { |
| 5794 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5795 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5796 | } |
| 5797 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5798 | /* |
| 5799 | * Local variables: |
| 5800 | * c-indent-level: 8 |
| 5801 | * c-basic-offset: 8 |
| 5802 | * End: |
| 5803 | */ |