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 */ |
| 75 | STAT_CLI_O_INFO, /* dump info */ |
| 76 | STAT_CLI_O_SESS, /* dump sessions */ |
| 77 | STAT_CLI_O_ERR, /* dump errors */ |
| 78 | STAT_CLI_O_TAB, /* dump tables */ |
| 79 | STAT_CLI_O_CLR, /* clear tables */ |
| 80 | STAT_CLI_O_SET, /* set entries in tables */ |
| 81 | STAT_CLI_O_STAT, /* dump stats */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 82 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 83 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 84 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 85 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 88 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 89 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 90 | 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] | 91 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 92 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 93 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 94 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 95 | 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] | 96 | static int stats_pats_list(struct stream_interface *si); |
| 97 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 98 | static int stats_map_lookup(struct stream_interface *si); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 99 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 100 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 101 | * cli_io_handler() |
| 102 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 103 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 104 | * -> stats_dump_info_to_buffer() // "show info" |
| 105 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 106 | * -> stats_dump_csv_header() |
| 107 | * -> stats_dump_proxy_to_buffer() |
| 108 | * -> stats_dump_fe_stats() |
| 109 | * -> stats_dump_li_stats() |
| 110 | * -> stats_dump_sv_stats() |
| 111 | * -> stats_dump_be_stats() |
| 112 | * |
| 113 | * http_stats_io_handler() |
| 114 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 115 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 116 | * -> stats_dump_html_head() // emits the HTML headers |
| 117 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 118 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 119 | * -> stats_dump_html_px_hdr() |
| 120 | * -> stats_dump_fe_stats() |
| 121 | * -> stats_dump_li_stats() |
| 122 | * -> stats_dump_sv_stats() |
| 123 | * -> stats_dump_be_stats() |
| 124 | * -> stats_dump_html_px_end() |
| 125 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 126 | */ |
| 127 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 128 | static struct si_applet cli_applet; |
| 129 | |
| 130 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 131 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 132 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 133 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 134 | " help : this message\n" |
| 135 | " prompt : toggle interactive mode with prompt\n" |
| 136 | " quit : disconnect\n" |
| 137 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 138 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 139 | " show stat : report counters for each proxy and server\n" |
| 140 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 141 | " 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] | 142 | " 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] | 143 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 144 | " set weight : change a server's weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 145 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 146 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 147 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 148 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 149 | " disable : put a server or frontend in maintenance mode\n" |
| 150 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 151 | " 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] | 152 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 153 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 154 | " add acl : add acl entry\n" |
| 155 | " del acl : delete acl entry\n" |
| 156 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 157 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 158 | " get map : reports the keys and values matching a sample for a map\n" |
| 159 | " set map : modify map entry\n" |
| 160 | " add map : add map entry\n" |
| 161 | " del map : delete map entry\n" |
| 162 | " clear map <id> : clear the content of this map\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 163 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 164 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 165 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 166 | "Permission denied\n" |
| 167 | ""; |
| 168 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 169 | /* data transmission states for the stats responses */ |
| 170 | enum { |
| 171 | STAT_ST_INIT = 0, |
| 172 | STAT_ST_HEAD, |
| 173 | STAT_ST_INFO, |
| 174 | STAT_ST_LIST, |
| 175 | STAT_ST_END, |
| 176 | STAT_ST_FIN, |
| 177 | }; |
| 178 | |
| 179 | /* data transmission states for the stats responses inside a proxy */ |
| 180 | enum { |
| 181 | STAT_PX_ST_INIT = 0, |
| 182 | STAT_PX_ST_TH, |
| 183 | STAT_PX_ST_FE, |
| 184 | STAT_PX_ST_LI, |
| 185 | STAT_PX_ST_SV, |
| 186 | STAT_PX_ST_BE, |
| 187 | STAT_PX_ST_END, |
| 188 | STAT_PX_ST_FIN, |
| 189 | }; |
| 190 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 191 | extern const char *stat_status_codes[]; |
| 192 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 193 | /* 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] | 194 | * 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] | 195 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 196 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 197 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 198 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 199 | s->target = &cli_applet.obj_type; |
Willy Tarreau | 4171e9e | 2013-12-01 12:32:30 +0100 | [diff] [blame] | 200 | /* 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] | 201 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 202 | tv_zero(&s->logs.tv_request); |
| 203 | s->logs.t_queue = 0; |
| 204 | s->logs.t_connect = 0; |
| 205 | s->logs.t_data = 0; |
| 206 | s->logs.t_close = 0; |
| 207 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 208 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 209 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 210 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 211 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 212 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 213 | if (s->listener->timeout) { |
| 214 | s->req->rto = *s->listener->timeout; |
| 215 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 216 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 217 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 220 | /* allocate a new stats frontend named <name>, and return it |
| 221 | * (or NULL in case of lack of memory). |
| 222 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 223 | 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] | 224 | { |
| 225 | struct proxy *fe; |
| 226 | |
| 227 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 228 | if (!fe) |
| 229 | return NULL; |
| 230 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 231 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 232 | fe->next = proxy; |
| 233 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 234 | fe->last_change = now.tv_sec; |
| 235 | fe->id = strdup("GLOBAL"); |
| 236 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 237 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 238 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 239 | fe->conf.file = strdup(file); |
| 240 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 241 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 242 | |
| 243 | /* the stats frontend is the only one able to assign ID #0 */ |
| 244 | fe->conf.id.key = fe->uuid = 0; |
| 245 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 246 | return fe; |
| 247 | } |
| 248 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 249 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 250 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 251 | * error message into the <err> buffer which will be preallocated. The trailing |
| 252 | * '\n' must not be written. The function must be called with <args> pointing to |
| 253 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 254 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 255 | 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] | 256 | struct proxy *defpx, const char *file, int line, |
| 257 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 258 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 259 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 260 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 261 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 262 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 263 | int cur_arg; |
| 264 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 265 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 266 | 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] | 267 | return -1; |
| 268 | } |
| 269 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 270 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 271 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 272 | 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] | 273 | return -1; |
| 274 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 277 | 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] | 278 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 279 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 280 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 281 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 282 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 283 | return -1; |
| 284 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 285 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 286 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 287 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 288 | static int bind_dumped; |
| 289 | struct bind_kw *kw; |
| 290 | |
| 291 | kw = bind_find_kw(args[cur_arg]); |
| 292 | if (kw) { |
| 293 | if (!kw->parse) { |
| 294 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 295 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 296 | return -1; |
| 297 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 298 | |
| 299 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 300 | if (err && *err) |
| 301 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 302 | else |
| 303 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 304 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 305 | return -1; |
| 306 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 307 | |
| 308 | cur_arg += 1 + kw->skip; |
| 309 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 310 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 311 | |
| 312 | if (!bind_dumped) { |
| 313 | bind_dump_kws(err); |
| 314 | indent_msg(err, 4); |
| 315 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 316 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 317 | |
| 318 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 319 | args[0], args[1], args[cur_arg], |
| 320 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 321 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 322 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 323 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 324 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 325 | l->maxconn = global.stats_fe->maxconn; |
| 326 | l->backlog = global.stats_fe->backlog; |
| 327 | l->timeout = &global.stats_fe->timeout.client; |
| 328 | l->accept = session_accept; |
| 329 | l->handler = process_session; |
| 330 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 331 | l->nice = -64; /* we want to boost priority for local stats */ |
| 332 | global.maxsock += l->maxconn; |
| 333 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 334 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 335 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 336 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 337 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 338 | |
| 339 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 340 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 341 | return -1; |
| 342 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 343 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 344 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 345 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 346 | return -1; |
| 347 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 348 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 349 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 350 | 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] | 351 | return -1; |
| 352 | } |
| 353 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 354 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 355 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 356 | else if (!strcmp(args[1], "maxconn")) { |
| 357 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 358 | |
| 359 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 360 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 361 | return -1; |
| 362 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 363 | |
| 364 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 365 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 366 | 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] | 367 | return -1; |
| 368 | } |
| 369 | } |
| 370 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 371 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 372 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 373 | int cur_arg = 2; |
| 374 | unsigned int set = 0; |
| 375 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 376 | if (!global.stats_fe) { |
| 377 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 378 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 379 | return -1; |
| 380 | } |
| 381 | } |
| 382 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 383 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 384 | unsigned int low, high; |
| 385 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 386 | if (strcmp(args[cur_arg], "all") == 0) { |
| 387 | set = 0; |
| 388 | break; |
| 389 | } |
| 390 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 391 | set |= 0x55555555; |
| 392 | } |
| 393 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 394 | set |= 0xAAAAAAAA; |
| 395 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 396 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 397 | char *dash = strchr(args[cur_arg], '-'); |
| 398 | |
| 399 | low = high = str2uic(args[cur_arg]); |
| 400 | if (dash) |
| 401 | high = str2uic(dash + 1); |
| 402 | |
| 403 | if (high < low) { |
| 404 | unsigned int swap = low; |
| 405 | low = high; |
| 406 | high = swap; |
| 407 | } |
| 408 | |
| 409 | if (low < 1 || high > 32) { |
| 410 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 411 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 412 | return -1; |
| 413 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 414 | |
| 415 | while (low <= high) |
| 416 | set |= 1 << (low++ - 1); |
| 417 | } |
| 418 | else { |
| 419 | memprintf(err, |
| 420 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 421 | args[0], args[1]); |
| 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 | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 985 | /* This function is used with map and acl management. It permits to browse |
| 986 | * each reference. |
| 987 | */ |
| 988 | static inline |
| 989 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 990 | { |
| 991 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 992 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 993 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 994 | return NULL; |
| 995 | return expr; |
| 996 | } |
| 997 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 998 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 999 | * 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] | 1000 | * 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] | 1001 | * designating the function which will have to process the request, which can |
| 1002 | * 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] | 1003 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1004 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1005 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 1006 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1007 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1008 | char *args[MAX_STATS_ARGS + 1]; |
| 1009 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1010 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1011 | |
| 1012 | while (isspace((unsigned char)*line)) |
| 1013 | line++; |
| 1014 | |
| 1015 | arg = 0; |
| 1016 | args[arg] = line; |
| 1017 | |
| 1018 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1019 | if (*line == '\\') { |
| 1020 | line++; |
| 1021 | if (*line == '\0') |
| 1022 | break; |
| 1023 | } |
| 1024 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1025 | *line++ = '\0'; |
| 1026 | |
| 1027 | while (isspace((unsigned char)*line)) |
| 1028 | line++; |
| 1029 | |
| 1030 | args[++arg] = line; |
| 1031 | continue; |
| 1032 | } |
| 1033 | |
| 1034 | line++; |
| 1035 | } |
| 1036 | |
| 1037 | while (++arg <= MAX_STATS_ARGS) |
| 1038 | args[arg] = line; |
| 1039 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1040 | /* remove \ */ |
| 1041 | arg = 0; |
| 1042 | while (*args[arg] != '\0') { |
| 1043 | j = 0; |
| 1044 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1045 | if (args[arg][i] == '\\') |
| 1046 | continue; |
| 1047 | args[arg][j] = args[arg][i]; |
| 1048 | j++; |
| 1049 | } |
| 1050 | args[arg][j] = '\0'; |
| 1051 | arg++; |
| 1052 | } |
| 1053 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1054 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1055 | if (strcmp(args[0], "show") == 0) { |
| 1056 | if (strcmp(args[1], "stat") == 0) { |
| 1057 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1058 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1059 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1060 | appctx->ctx.stats.type = atoi(args[3]); |
| 1061 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1064 | appctx->st2 = STAT_ST_INIT; |
| 1065 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1066 | } |
| 1067 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1068 | appctx->st2 = STAT_ST_INIT; |
| 1069 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1070 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1071 | else if (strcmp(args[1], "pools") == 0) { |
| 1072 | appctx->st2 = STAT_ST_INIT; |
| 1073 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1074 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1075 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1076 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1077 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1078 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1079 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1080 | return 1; |
| 1081 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1082 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1083 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1084 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1085 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1086 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1087 | appctx->ctx.sess.target = NULL; |
| 1088 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1089 | appctx->ctx.sess.pos = 0; |
| 1090 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1091 | } |
| 1092 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1093 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1094 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1095 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1096 | return 1; |
| 1097 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1098 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1099 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1100 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1101 | appctx->ctx.errors.iid = -1; |
| 1102 | appctx->ctx.errors.px = NULL; |
| 1103 | appctx->st2 = STAT_ST_INIT; |
| 1104 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1105 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1106 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1107 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1108 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1109 | else if (strcmp(args[1], "map") == 0 || |
| 1110 | strcmp(args[1], "acl") == 0) { |
| 1111 | |
| 1112 | /* Set ACL or MAP flags. */ |
| 1113 | if (args[1][0] == 'm') |
| 1114 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1115 | else |
| 1116 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1117 | |
| 1118 | /* no parameter: display all map avalaible */ |
| 1119 | if (!*args[2]) { |
| 1120 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1121 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1122 | return 1; |
| 1123 | } |
| 1124 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1125 | /* lookup into the refs and check the map flag */ |
| 1126 | appctx->ctx.map.ref = pat_ref_lookup(args[2]); |
| 1127 | if (!appctx->ctx.map.ref || |
| 1128 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1129 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1130 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
| 1131 | else |
| 1132 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1133 | appctx->st0 = STAT_CLI_PRINT; |
| 1134 | return 1; |
| 1135 | } |
| 1136 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1137 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1138 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1139 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1140 | return 0; |
| 1141 | } |
| 1142 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1143 | else if (strcmp(args[0], "clear") == 0) { |
| 1144 | if (strcmp(args[1], "counters") == 0) { |
| 1145 | struct proxy *px; |
| 1146 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1147 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1148 | int clrall = 0; |
| 1149 | |
| 1150 | if (strcmp(args[2], "all") == 0) |
| 1151 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1152 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1153 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1154 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1155 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1156 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1157 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1158 | return 1; |
| 1159 | } |
| 1160 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1161 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1162 | if (clrall) { |
| 1163 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1164 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1165 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1166 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1167 | px->be_counters.conn_max = 0; |
| 1168 | px->be_counters.p.http.rps_max = 0; |
| 1169 | px->be_counters.sps_max = 0; |
| 1170 | px->be_counters.cps_max = 0; |
| 1171 | px->be_counters.nbpend_max = 0; |
| 1172 | |
| 1173 | px->fe_counters.conn_max = 0; |
| 1174 | px->fe_counters.p.http.rps_max = 0; |
| 1175 | px->fe_counters.sps_max = 0; |
| 1176 | px->fe_counters.cps_max = 0; |
| 1177 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1178 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1179 | |
| 1180 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1181 | if (clrall) |
| 1182 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1183 | else { |
| 1184 | sv->counters.cur_sess_max = 0; |
| 1185 | sv->counters.nbpend_max = 0; |
| 1186 | sv->counters.sps_max = 0; |
| 1187 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1188 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1189 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1190 | if (li->counters) { |
| 1191 | if (clrall) |
| 1192 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1193 | else |
| 1194 | li->counters->conn_max = 0; |
| 1195 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1196 | } |
| 1197 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1198 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1199 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1200 | return 1; |
| 1201 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1202 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1203 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1204 | /* end of processing */ |
| 1205 | return 1; |
| 1206 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1207 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1208 | /* Set ACL or MAP flags. */ |
| 1209 | if (args[1][0] == 'm') |
| 1210 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1211 | else |
| 1212 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1213 | |
| 1214 | /* no parameter */ |
| 1215 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1216 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1217 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1218 | else |
| 1219 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1220 | appctx->st0 = STAT_CLI_PRINT; |
| 1221 | return 1; |
| 1222 | } |
| 1223 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1224 | /* lookup into the refs and check the map flag */ |
| 1225 | appctx->ctx.map.ref = pat_ref_lookup(args[2]); |
| 1226 | if (!appctx->ctx.map.ref || |
| 1227 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1228 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1229 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
| 1230 | else |
| 1231 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1232 | appctx->st0 = STAT_CLI_PRINT; |
| 1233 | return 1; |
| 1234 | } |
| 1235 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1236 | /* Clear all. */ |
| 1237 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1238 | |
| 1239 | /* return response */ |
| 1240 | appctx->ctx.cli.msg = "Done.\n"; |
| 1241 | appctx->st0 = STAT_CLI_PRINT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1242 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1243 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1244 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1245 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1246 | return 0; |
| 1247 | } |
| 1248 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1249 | else if (strcmp(args[0], "get") == 0) { |
| 1250 | if (strcmp(args[1], "weight") == 0) { |
| 1251 | struct proxy *px; |
| 1252 | struct server *sv; |
| 1253 | |
| 1254 | /* split "backend/server" and make <line> point to server */ |
| 1255 | for (line = args[2]; *line; line++) |
| 1256 | if (*line == '/') { |
| 1257 | *line++ = '\0'; |
| 1258 | break; |
| 1259 | } |
| 1260 | |
| 1261 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1262 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1263 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1264 | return 1; |
| 1265 | } |
| 1266 | |
| 1267 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1268 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1269 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1270 | return 1; |
| 1271 | } |
| 1272 | |
| 1273 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1274 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1275 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1276 | return 1; |
| 1277 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1278 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1279 | /* Set flags. */ |
| 1280 | if (args[1][0] == 'm') |
| 1281 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1282 | else |
| 1283 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1284 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1285 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1286 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1287 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1288 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1289 | else |
| 1290 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1291 | appctx->st0 = STAT_CLI_PRINT; |
| 1292 | return 1; |
| 1293 | } |
| 1294 | |
| 1295 | /* lookup into the maps */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1296 | appctx->ctx.map.ref = pat_ref_lookup(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1297 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1298 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1299 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
| 1300 | else |
| 1301 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1302 | appctx->st0 = STAT_CLI_PRINT; |
| 1303 | return 1; |
| 1304 | } |
| 1305 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1306 | /* copy input string. The string must be allocated because |
| 1307 | * it may be used over multiple iterations. It's released |
| 1308 | * at the end and upon abort anyway. |
| 1309 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1310 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1311 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1312 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1313 | if (!appctx->ctx.map.chunk.str) { |
| 1314 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1315 | appctx->st0 = STAT_CLI_PRINT; |
| 1316 | return 1; |
| 1317 | } |
| 1318 | |
| 1319 | /* prepare response */ |
| 1320 | appctx->st2 = STAT_ST_INIT; |
| 1321 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1322 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1323 | else { /* not "get weight" */ |
| 1324 | return 0; |
| 1325 | } |
| 1326 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1327 | else if (strcmp(args[0], "set") == 0) { |
| 1328 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1329 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1330 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1331 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1332 | sv = expect_server_admin(s, si, args[2]); |
| 1333 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1334 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1335 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1336 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1337 | /* |
| 1338 | * The user-weight may now be zero and thus |
| 1339 | * the server considered to be draining. |
| 1340 | * Update the server's drain state as necessary. |
| 1341 | */ |
| 1342 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1343 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1344 | appctx->ctx.cli.msg = warning; |
| 1345 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1346 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1347 | return 1; |
| 1348 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1349 | else if (strcmp(args[1], "timeout") == 0) { |
| 1350 | if (strcmp(args[2], "cli") == 0) { |
| 1351 | unsigned timeout; |
| 1352 | const char *res; |
| 1353 | |
| 1354 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1355 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1356 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1357 | return 1; |
| 1358 | } |
| 1359 | |
| 1360 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1361 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1362 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1363 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1364 | return 1; |
| 1365 | } |
| 1366 | |
| 1367 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1368 | return 1; |
| 1369 | } |
| 1370 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1371 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1372 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1373 | return 1; |
| 1374 | } |
| 1375 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1376 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1377 | if (strcmp(args[2], "frontend") == 0) { |
| 1378 | struct proxy *px; |
| 1379 | struct listener *l; |
| 1380 | int v; |
| 1381 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1382 | px = expect_frontend_admin(s, si, args[3]); |
| 1383 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1384 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1385 | |
| 1386 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1387 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1388 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1389 | return 1; |
| 1390 | } |
| 1391 | |
| 1392 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1393 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1394 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1395 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1396 | return 1; |
| 1397 | } |
| 1398 | |
| 1399 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1400 | * its listeners. The blocked ones will be dequeued. |
| 1401 | */ |
| 1402 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1403 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1404 | l->maxconn = v; |
| 1405 | if (l->state == LI_FULL) |
| 1406 | resume_listener(l); |
| 1407 | } |
| 1408 | |
| 1409 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1410 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1411 | |
| 1412 | return 1; |
| 1413 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1414 | else if (strcmp(args[2], "global") == 0) { |
| 1415 | int v; |
| 1416 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1417 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1418 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1419 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1420 | return 1; |
| 1421 | } |
| 1422 | |
| 1423 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1424 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1425 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1426 | return 1; |
| 1427 | } |
| 1428 | |
| 1429 | v = atoi(args[3]); |
| 1430 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1431 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1432 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1433 | return 1; |
| 1434 | } |
| 1435 | |
| 1436 | /* check for unlimited values */ |
| 1437 | if (v <= 0) |
| 1438 | v = global.hardmaxconn; |
| 1439 | |
| 1440 | global.maxconn = v; |
| 1441 | |
| 1442 | /* Dequeues all of the listeners waiting for a resource */ |
| 1443 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1444 | dequeue_all_listeners(&global_listener_queue); |
| 1445 | |
| 1446 | return 1; |
| 1447 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1448 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1449 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1450 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1451 | return 1; |
| 1452 | } |
| 1453 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1454 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1455 | if (strcmp(args[2], "connections") == 0) { |
| 1456 | if (strcmp(args[3], "global") == 0) { |
| 1457 | int v; |
| 1458 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1459 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1460 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1461 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1462 | return 1; |
| 1463 | } |
| 1464 | |
| 1465 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1466 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1467 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1468 | return 1; |
| 1469 | } |
| 1470 | |
| 1471 | v = atoi(args[4]); |
| 1472 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1473 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1474 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1475 | return 1; |
| 1476 | } |
| 1477 | |
| 1478 | global.cps_lim = v; |
| 1479 | |
| 1480 | /* Dequeues all of the listeners waiting for a resource */ |
| 1481 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1482 | dequeue_all_listeners(&global_listener_queue); |
| 1483 | |
| 1484 | return 1; |
| 1485 | } |
| 1486 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1487 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1488 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1489 | return 1; |
| 1490 | } |
| 1491 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1492 | else if (strcmp(args[2], "sessions") == 0) { |
| 1493 | if (strcmp(args[3], "global") == 0) { |
| 1494 | int v; |
| 1495 | |
| 1496 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1497 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1498 | appctx->st0 = STAT_CLI_PRINT; |
| 1499 | return 1; |
| 1500 | } |
| 1501 | |
| 1502 | if (!*args[4]) { |
| 1503 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1504 | appctx->st0 = STAT_CLI_PRINT; |
| 1505 | return 1; |
| 1506 | } |
| 1507 | |
| 1508 | v = atoi(args[4]); |
| 1509 | if (v < 0) { |
| 1510 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1511 | appctx->st0 = STAT_CLI_PRINT; |
| 1512 | return 1; |
| 1513 | } |
| 1514 | |
| 1515 | global.sps_lim = v; |
| 1516 | |
| 1517 | /* Dequeues all of the listeners waiting for a resource */ |
| 1518 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1519 | dequeue_all_listeners(&global_listener_queue); |
| 1520 | |
| 1521 | return 1; |
| 1522 | } |
| 1523 | else { |
| 1524 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1525 | appctx->st0 = STAT_CLI_PRINT; |
| 1526 | return 1; |
| 1527 | } |
| 1528 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1529 | #ifdef USE_OPENSSL |
| 1530 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1531 | if (strcmp(args[3], "global") == 0) { |
| 1532 | int v; |
| 1533 | |
| 1534 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1535 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1536 | appctx->st0 = STAT_CLI_PRINT; |
| 1537 | return 1; |
| 1538 | } |
| 1539 | |
| 1540 | if (!*args[4]) { |
| 1541 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1542 | appctx->st0 = STAT_CLI_PRINT; |
| 1543 | return 1; |
| 1544 | } |
| 1545 | |
| 1546 | v = atoi(args[4]); |
| 1547 | if (v < 0) { |
| 1548 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1549 | appctx->st0 = STAT_CLI_PRINT; |
| 1550 | return 1; |
| 1551 | } |
| 1552 | |
| 1553 | global.ssl_lim = v; |
| 1554 | |
| 1555 | /* Dequeues all of the listeners waiting for a resource */ |
| 1556 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1557 | dequeue_all_listeners(&global_listener_queue); |
| 1558 | |
| 1559 | return 1; |
| 1560 | } |
| 1561 | else { |
| 1562 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1563 | appctx->st0 = STAT_CLI_PRINT; |
| 1564 | return 1; |
| 1565 | } |
| 1566 | } |
| 1567 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1568 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1569 | if (strcmp(args[3], "global") == 0) { |
| 1570 | int v; |
| 1571 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1572 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1573 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1574 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1575 | return 1; |
| 1576 | } |
| 1577 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1578 | v = atoi(args[4]); |
| 1579 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1580 | } |
| 1581 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1582 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1583 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1584 | return 1; |
| 1585 | } |
| 1586 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1587 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1588 | 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] | 1589 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1590 | return 1; |
| 1591 | } |
| 1592 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1593 | else if (strcmp(args[1], "table") == 0) { |
| 1594 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1595 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1596 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1597 | /* Set flags. */ |
| 1598 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1599 | |
| 1600 | /* Expect three parameters: map name, key and new value. */ |
| 1601 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1602 | 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] | 1603 | appctx->st0 = STAT_CLI_PRINT; |
| 1604 | return 1; |
| 1605 | } |
| 1606 | |
| 1607 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1608 | appctx->ctx.map.ref = pat_ref_lookup(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1609 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1610 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1611 | appctx->st0 = STAT_CLI_PRINT; |
| 1612 | return 1; |
| 1613 | } |
| 1614 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1615 | /* Update the value. */ |
| 1616 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4])) { |
| 1617 | appctx->ctx.cli.msg = "Pattern not found.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1618 | appctx->st0 = STAT_CLI_PRINT; |
| 1619 | return 1; |
| 1620 | } |
| 1621 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1622 | /* The set is done, send message. */ |
| 1623 | appctx->ctx.cli.msg = "Done.\n"; |
| 1624 | appctx->st0 = STAT_CLI_PRINT; |
| 1625 | return 1; |
| 1626 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1627 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1628 | return 0; |
| 1629 | } |
| 1630 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1631 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1632 | if (strcmp(args[1], "agent") == 0) { |
| 1633 | struct server *sv; |
| 1634 | |
| 1635 | sv = expect_server_admin(s, si, args[2]); |
| 1636 | if (!sv) |
| 1637 | return 1; |
| 1638 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1639 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1640 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1641 | appctx->st0 = STAT_CLI_PRINT; |
| 1642 | return 1; |
| 1643 | } |
| 1644 | |
| 1645 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1646 | return 1; |
| 1647 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1648 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1649 | struct server *sv; |
| 1650 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1651 | sv = expect_server_admin(s, si, args[2]); |
| 1652 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1653 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1654 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1655 | if (sv->state & SRV_MAINTAIN) { |
| 1656 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1657 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1658 | /* If this server tracks the status of another one, |
| 1659 | * we must restore the good status. |
| 1660 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1661 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1662 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1663 | 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] | 1664 | } else { |
| 1665 | sv->state &= ~SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1666 | sv->check.state &= ~CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1667 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1668 | } |
| 1669 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1670 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1671 | 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] | 1672 | } |
| 1673 | } |
| 1674 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1675 | return 1; |
| 1676 | } |
| 1677 | else if (strcmp(args[1], "frontend") == 0) { |
| 1678 | struct proxy *px; |
| 1679 | |
| 1680 | px = expect_frontend_admin(s, si, args[2]); |
| 1681 | if (!px) |
| 1682 | return 1; |
| 1683 | |
| 1684 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1685 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1686 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1687 | return 1; |
| 1688 | } |
| 1689 | |
| 1690 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1691 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1692 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1693 | return 1; |
| 1694 | } |
| 1695 | |
| 1696 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1697 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1698 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1699 | return 1; |
| 1700 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1701 | return 1; |
| 1702 | } |
| 1703 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1704 | appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1705 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1706 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1710 | if (strcmp(args[1], "agent") == 0) { |
| 1711 | struct server *sv; |
| 1712 | |
| 1713 | sv = expect_server_admin(s, si, args[2]); |
| 1714 | if (!sv) |
| 1715 | return 1; |
| 1716 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1717 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1718 | return 1; |
| 1719 | } |
| 1720 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1721 | struct server *sv; |
| 1722 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1723 | sv = expect_server_admin(s, si, args[2]); |
| 1724 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1725 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1726 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1727 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1728 | /* Not already in maintenance, we can change the server state */ |
| 1729 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1730 | sv->check.state |= CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1731 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1732 | } |
| 1733 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1734 | return 1; |
| 1735 | } |
| 1736 | else if (strcmp(args[1], "frontend") == 0) { |
| 1737 | struct proxy *px; |
| 1738 | |
| 1739 | px = expect_frontend_admin(s, si, args[2]); |
| 1740 | if (!px) |
| 1741 | return 1; |
| 1742 | |
| 1743 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1744 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1745 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1746 | return 1; |
| 1747 | } |
| 1748 | |
| 1749 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1750 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1751 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1752 | return 1; |
| 1753 | } |
| 1754 | |
| 1755 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1756 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1757 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1758 | return 1; |
| 1759 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1760 | return 1; |
| 1761 | } |
| 1762 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1763 | appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1764 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1765 | return 1; |
| 1766 | } |
| 1767 | } |
| 1768 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1769 | if (strcmp(args[1], "frontend") == 0) { |
| 1770 | struct proxy *px; |
| 1771 | |
| 1772 | px = expect_frontend_admin(s, si, args[2]); |
| 1773 | if (!px) |
| 1774 | return 1; |
| 1775 | |
| 1776 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1777 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1778 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1779 | return 1; |
| 1780 | } |
| 1781 | |
| 1782 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1783 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1784 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1785 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1786 | stop_proxy(px); |
| 1787 | return 1; |
| 1788 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1789 | else if (strcmp(args[1], "session") == 0) { |
| 1790 | struct session *sess, *ptr; |
| 1791 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1792 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1793 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1794 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1795 | return 1; |
| 1796 | } |
| 1797 | |
| 1798 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1799 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1800 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1801 | return 1; |
| 1802 | } |
| 1803 | |
| 1804 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1805 | |
| 1806 | /* first, look for the requested session in the session table */ |
| 1807 | list_for_each_entry(sess, &sessions, list) { |
| 1808 | if (sess == ptr) |
| 1809 | break; |
| 1810 | } |
| 1811 | |
| 1812 | /* do we have the session ? */ |
| 1813 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1814 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1815 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1816 | return 1; |
| 1817 | } |
| 1818 | |
| 1819 | session_shutdown(sess, SN_ERR_KILLED); |
| 1820 | return 1; |
| 1821 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1822 | else if (strcmp(args[1], "sessions") == 0) { |
| 1823 | if (strcmp(args[2], "server") == 0) { |
| 1824 | struct server *sv; |
| 1825 | struct session *sess, *sess_bck; |
| 1826 | |
| 1827 | sv = expect_server_admin(s, si, args[3]); |
| 1828 | if (!sv) |
| 1829 | return 1; |
| 1830 | |
| 1831 | /* kill all the session that are on this server */ |
| 1832 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1833 | if (sess->srv_conn == sv) |
| 1834 | session_shutdown(sess, SN_ERR_KILLED); |
| 1835 | |
| 1836 | return 1; |
| 1837 | } |
| 1838 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1839 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1840 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1841 | return 1; |
| 1842 | } |
| 1843 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1844 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1845 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1846 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1847 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1848 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1849 | } |
| 1850 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1851 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1852 | if (args[1][0] == 'm') |
| 1853 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1854 | else |
| 1855 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1856 | |
| 1857 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1858 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 1859 | if (!*args[2] || !*args[3]) { |
| 1860 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 1861 | appctx->st0 = STAT_CLI_PRINT; |
| 1862 | return 1; |
| 1863 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1864 | } |
| 1865 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1866 | else { |
| 1867 | if (!*args[2] || !*args[3]) { |
| 1868 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 1869 | appctx->st0 = STAT_CLI_PRINT; |
| 1870 | return 1; |
| 1871 | } |
| 1872 | } |
| 1873 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1874 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1875 | appctx->ctx.map.ref = pat_ref_lookup(args[2]); |
| 1876 | if (!appctx->ctx.map.ref || |
| 1877 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1878 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1879 | appctx->st0 = STAT_CLI_PRINT; |
| 1880 | return 1; |
| 1881 | } |
| 1882 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1883 | /* Try to delete the entry. */ |
| 1884 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 1885 | /* The entry is not found, send message. */ |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1886 | appctx->ctx.cli.msg = "Key not found.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1887 | appctx->st0 = STAT_CLI_PRINT; |
| 1888 | return 1; |
| 1889 | } |
| 1890 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1891 | /* The deletion is done, send message. */ |
| 1892 | appctx->ctx.cli.msg = "Done.\n"; |
| 1893 | appctx->st0 = STAT_CLI_PRINT; |
| 1894 | return 1; |
| 1895 | } |
| 1896 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1897 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1898 | appctx->st0 = STAT_CLI_PRINT; |
| 1899 | return 1; |
| 1900 | } |
| 1901 | } |
| 1902 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1903 | if (strcmp(args[1], "map") == 0 || |
| 1904 | strcmp(args[1], "acl") == 0) { |
| 1905 | int ret; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1906 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1907 | /* Set flags. */ |
| 1908 | if (args[1][0] == 'm') |
| 1909 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1910 | else |
| 1911 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 1912 | |
| 1913 | /* If the keywork is "map", we expect three parameters, if it |
| 1914 | * is "acl", we expect only two parameters |
| 1915 | */ |
| 1916 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 1917 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 1918 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 1919 | appctx->st0 = STAT_CLI_PRINT; |
| 1920 | return 1; |
| 1921 | } |
| 1922 | } |
| 1923 | else { |
| 1924 | if (!*args[2] || !*args[3]) { |
| 1925 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 1926 | appctx->st0 = STAT_CLI_PRINT; |
| 1927 | return 1; |
| 1928 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1929 | } |
| 1930 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1931 | /* Lookup for the reference. */ |
| 1932 | appctx->ctx.map.ref = pat_ref_lookup(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1933 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1934 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1935 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
| 1936 | else |
| 1937 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1938 | appctx->st0 = STAT_CLI_PRINT; |
| 1939 | return 1; |
| 1940 | } |
| 1941 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1942 | /* Add value. */ |
| 1943 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1944 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], NULL); |
| 1945 | else |
| 1946 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, NULL); |
| 1947 | if (!ret) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1948 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1949 | appctx->st0 = STAT_CLI_PRINT; |
| 1950 | return 1; |
| 1951 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1952 | |
| 1953 | /* The add is done, send message. */ |
| 1954 | appctx->ctx.cli.msg = "Done.\n"; |
| 1955 | appctx->st0 = STAT_CLI_PRINT; |
| 1956 | return 1; |
| 1957 | } |
| 1958 | else { /* unknown "del" parameter */ |
| 1959 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 1960 | appctx->st0 = STAT_CLI_PRINT; |
| 1961 | return 1; |
| 1962 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1963 | } |
| 1964 | 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] | 1965 | return 0; |
| 1966 | } |
| 1967 | return 1; |
| 1968 | } |
| 1969 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1970 | /* 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] | 1971 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 1972 | * state machine handling requests and various responses. We read a request, |
| 1973 | * 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] | 1974 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 1975 | * 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] | 1976 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1977 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1978 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1979 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1980 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1981 | struct channel *req = si->ob; |
| 1982 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1983 | int reql; |
| 1984 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1985 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1986 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1987 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1988 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1989 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1990 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1991 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1992 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 1993 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1994 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1995 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1996 | /* Let's close for real now. We just close the request |
| 1997 | * side, the conditions below will complete if needed. |
| 1998 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1999 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2000 | break; |
| 2001 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2002 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2003 | /* ensure we have some output room left in the event we |
| 2004 | * would want to return some info right after parsing. |
| 2005 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2006 | if (buffer_almost_full(si->ib->buf)) { |
| 2007 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2008 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2009 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2010 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2011 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2012 | if (reql <= 0) { /* closed or EOL not found */ |
| 2013 | if (reql == 0) |
| 2014 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2015 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2016 | continue; |
| 2017 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2018 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2019 | /* seek for a possible semi-colon. If we find one, we |
| 2020 | * replace it with an LF and skip only this part. |
| 2021 | */ |
| 2022 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2023 | if (trash.str[len] == ';') { |
| 2024 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2025 | reql = len + 1; |
| 2026 | break; |
| 2027 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2028 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2029 | /* now it is time to check that we have a full line, |
| 2030 | * remove the trailing \n and possibly \r, then cut the |
| 2031 | * line. |
| 2032 | */ |
| 2033 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2034 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2035 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2036 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2037 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2038 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2039 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2040 | len--; |
| 2041 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2042 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2043 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2044 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2045 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2046 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2047 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2048 | continue; |
| 2049 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2050 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2051 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2052 | else if (strcmp(trash.str, "help") == 0 || |
| 2053 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2054 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2055 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2056 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2057 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2058 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2059 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2060 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2061 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2062 | /* if prompt is disabled, print help on empty lines, |
| 2063 | * so that the user at least knows how to enable |
| 2064 | * prompt and find help. |
| 2065 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2066 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2067 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2071 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2072 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2073 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2074 | 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] | 2075 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2076 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2077 | continue; |
| 2078 | } |
| 2079 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2080 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2081 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2082 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2083 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2084 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2085 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2086 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2087 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2088 | break; |
| 2089 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2090 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2091 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2092 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2093 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2094 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2095 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2096 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2097 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2098 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2099 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2100 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2101 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2102 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2103 | if (stats_table_request(si, appctx->st0)) |
| 2104 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2105 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2106 | case STAT_CLI_O_PATS: |
| 2107 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2108 | appctx->st0 = STAT_CLI_PROMPT; |
| 2109 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2110 | case STAT_CLI_O_PAT: |
| 2111 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2112 | appctx->st0 = STAT_CLI_PROMPT; |
| 2113 | break; |
| 2114 | case STAT_CLI_O_MLOOK: |
| 2115 | if (stats_map_lookup(si)) |
| 2116 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2117 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2118 | case STAT_CLI_O_POOLS: |
| 2119 | if (stats_dump_pools_to_buffer(si)) |
| 2120 | appctx->st0 = STAT_CLI_PROMPT; |
| 2121 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2122 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2123 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2124 | break; |
| 2125 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2126 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2127 | /* 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] | 2128 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2129 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2130 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2131 | } |
| 2132 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2133 | /* 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] | 2134 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2135 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2136 | |
| 2137 | /* Now we close the output if one of the writers did so, |
| 2138 | * or if we're not in interactive mode and the request |
| 2139 | * buffer is empty. This still allows pipelined requests |
| 2140 | * to be sent in non-interactive mode. |
| 2141 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2142 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2143 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2144 | continue; |
| 2145 | } |
| 2146 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2147 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2148 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2149 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2150 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2151 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2152 | 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] | 2153 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2154 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2155 | /* 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] | 2156 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2157 | * we forward the close to the request side so that it flows upstream to |
| 2158 | * the client. |
| 2159 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2160 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2161 | } |
| 2162 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2163 | 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] | 2164 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2165 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2166 | /* We have no more processing to do, and nothing more to send, and |
| 2167 | * the client side has closed. So we'll forward this state downstream |
| 2168 | * on the response buffer. |
| 2169 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2170 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2171 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2175 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2176 | |
| 2177 | /* we don't want to expire timeouts while we're processing requests */ |
| 2178 | si->ib->rex = TICK_ETERNITY; |
| 2179 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2180 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2181 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2182 | 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] | 2183 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2184 | 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] | 2185 | |
| 2186 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2187 | /* check that we have released everything then unregister */ |
| 2188 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2189 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2190 | } |
| 2191 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2192 | /* This function dumps information onto the stream interface's read buffer. |
| 2193 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2194 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2195 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2196 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2197 | { |
| 2198 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2199 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2200 | chunk_printf(&trash, |
| 2201 | "Name: " PRODUCT_NAME "\n" |
| 2202 | "Version: " HAPROXY_VERSION "\n" |
| 2203 | "Release_date: " HAPROXY_DATE "\n" |
| 2204 | "Nbproc: %d\n" |
| 2205 | "Process_num: %d\n" |
| 2206 | "Pid: %d\n" |
| 2207 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2208 | "Uptime_sec: %d\n" |
| 2209 | "Memmax_MB: %d\n" |
| 2210 | "Ulimit-n: %d\n" |
| 2211 | "Maxsock: %d\n" |
| 2212 | "Maxconn: %d\n" |
| 2213 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2214 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2215 | "CumConns: %d\n" |
| 2216 | "CumReq: %d\n" |
| 2217 | #ifdef USE_OPENSSL |
| 2218 | "MaxSslConns: %d\n" |
| 2219 | "CurrSslConns: %d\n" |
| 2220 | "CumSslConns: %d\n" |
| 2221 | #endif |
| 2222 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2223 | "PipesUsed: %d\n" |
| 2224 | "PipesFree: %d\n" |
| 2225 | "ConnRate: %d\n" |
| 2226 | "ConnRateLimit: %d\n" |
| 2227 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2228 | "SessRate: %d\n" |
| 2229 | "SessRateLimit: %d\n" |
| 2230 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2231 | #ifdef USE_OPENSSL |
| 2232 | "SslRate: %d\n" |
| 2233 | "SslRateLimit: %d\n" |
| 2234 | "MaxSslRate: %d\n" |
| 2235 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2236 | "CompressBpsIn: %u\n" |
| 2237 | "CompressBpsOut: %u\n" |
| 2238 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2239 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2240 | "ZlibMemUsage: %ld\n" |
| 2241 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2242 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2243 | "Tasks: %d\n" |
| 2244 | "Run_queue: %d\n" |
| 2245 | "Idle_pct: %d\n" |
| 2246 | "node: %s\n" |
| 2247 | "description: %s\n" |
| 2248 | "", |
| 2249 | global.nbproc, |
| 2250 | relative_pid, |
| 2251 | pid, |
| 2252 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2253 | up, |
| 2254 | global.rlimit_memmax, |
| 2255 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2256 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2257 | actconn, totalconn, global.req_count, |
| 2258 | #ifdef USE_OPENSSL |
| 2259 | global.maxsslconn, sslconns, totalsslconns, |
| 2260 | #endif |
| 2261 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2262 | 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] | 2263 | 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] | 2264 | #ifdef USE_OPENSSL |
| 2265 | read_freq_ctr(&global.ssl_per_sec), global.ssl_lim, global.ssl_max, |
| 2266 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2267 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2268 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2269 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2270 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2271 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2272 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2273 | global.node, global.desc ? global.desc : "" |
| 2274 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2275 | |
| 2276 | if (bi_putchk(si->ib, &trash) == -1) |
| 2277 | return 0; |
| 2278 | |
| 2279 | return 1; |
| 2280 | } |
| 2281 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2282 | /* This function dumps memory usage information onto the stream interface's |
| 2283 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2284 | * completion. No state is used. |
| 2285 | */ |
| 2286 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2287 | { |
| 2288 | dump_pools_to_trash(); |
| 2289 | if (bi_putchk(si->ib, &trash) == -1) |
| 2290 | return 0; |
| 2291 | return 1; |
| 2292 | } |
| 2293 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2294 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2295 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2296 | * 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] | 2297 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2298 | 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] | 2299 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2300 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2301 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2302 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2303 | if (!(px->cap & PR_CAP_FE)) |
| 2304 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2305 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2306 | 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] | 2307 | return 0; |
| 2308 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2309 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2310 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2311 | /* name, queue */ |
| 2312 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2313 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2314 | 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] | 2315 | /* Column sub-heading for Enable or Disable server */ |
| 2316 | chunk_appendf(&trash, "<td></td>"); |
| 2317 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2318 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2319 | chunk_appendf(&trash, |
| 2320 | "<td class=ac>" |
| 2321 | "<a name=\"%s/Frontend\"></a>" |
| 2322 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2323 | "<td colspan=3></td>" |
| 2324 | "", |
| 2325 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2326 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2327 | chunk_appendf(&trash, |
| 2328 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2329 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2330 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2331 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2332 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2333 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2334 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2335 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2336 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2337 | if (px->mode == PR_MODE_HTTP) |
| 2338 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2339 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2340 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2341 | |
| 2342 | chunk_appendf(&trash, |
| 2343 | "</table></div></u></td>" |
| 2344 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2345 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2346 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2347 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2348 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2349 | U2H(px->fe_counters.sps_max), |
| 2350 | U2H(px->fe_counters.cps_max), |
| 2351 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2352 | |
| 2353 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2354 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2355 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2356 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2357 | |
| 2358 | chunk_appendf(&trash, |
| 2359 | "</table></div></u></td>" |
| 2360 | /* sessions rate : limit */ |
| 2361 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2362 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2363 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2364 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2365 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2366 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2367 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2368 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2369 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2370 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2371 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2372 | U2H(px->fe_counters.cum_sess), |
| 2373 | U2H(px->fe_counters.cum_conn), |
| 2374 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2375 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2376 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2377 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2378 | chunk_appendf(&trash, |
| 2379 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2380 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2381 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2382 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2383 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2384 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2385 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2386 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2387 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2388 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2389 | U2H(px->fe_counters.p.http.cum_req), |
| 2390 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2391 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2392 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2393 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2394 | (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] | 2395 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2396 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2397 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2398 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2399 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2400 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2401 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2402 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2403 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2404 | /* sessions: lbtot, lastsess */ |
| 2405 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2406 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2407 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2408 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2409 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2410 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2411 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2412 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2413 | "<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] | 2414 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2415 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2416 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2417 | px->fe_counters.comp_in ? |
| 2418 | (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] | 2419 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2420 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2421 | chunk_appendf(&trash, |
| 2422 | /* denied: req, resp */ |
| 2423 | "<td>%s</td><td>%s</td>" |
| 2424 | /* errors : request, connect, response */ |
| 2425 | "<td>%s</td><td></td><td></td>" |
| 2426 | /* warnings: retries, redispatches */ |
| 2427 | "<td></td><td></td>" |
| 2428 | /* server status : reflect frontend status */ |
| 2429 | "<td class=ac>%s</td>" |
| 2430 | /* rest of server: nothing */ |
| 2431 | "<td class=ac colspan=8></td></tr>" |
| 2432 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2433 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2434 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2435 | px->state == PR_STREADY ? "OPEN" : |
| 2436 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2437 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2438 | else { /* CSV mode */ |
| 2439 | chunk_appendf(&trash, |
| 2440 | /* pxid, name, queue cur, queue max, */ |
| 2441 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2442 | /* sessions : current, max, limit, total */ |
| 2443 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2444 | /* bytes : in, out */ |
| 2445 | "%lld,%lld," |
| 2446 | /* denied: req, resp */ |
| 2447 | "%lld,%lld," |
| 2448 | /* errors : request, connect, response */ |
| 2449 | "%lld,,," |
| 2450 | /* warnings: retries, redispatches */ |
| 2451 | ",," |
| 2452 | /* server status : reflect frontend status */ |
| 2453 | "%s," |
| 2454 | /* rest of server: nothing */ |
| 2455 | ",,,,,,,," |
| 2456 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2457 | "%d,%d,0,,,,%d," |
| 2458 | /* rate, rate_lim, rate_max */ |
| 2459 | "%u,%u,%u," |
| 2460 | /* check_status, check_code, check_duration */ |
| 2461 | ",,,", |
| 2462 | px->id, |
| 2463 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2464 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2465 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2466 | px->fe_counters.failed_req, |
| 2467 | px->state == PR_STREADY ? "OPEN" : |
| 2468 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2469 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2470 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2471 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2472 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2473 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2474 | if (px->mode == PR_MODE_HTTP) { |
| 2475 | for (i=1; i<6; i++) |
| 2476 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2477 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2478 | } |
| 2479 | else |
| 2480 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2481 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2482 | /* failed health analyses */ |
| 2483 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2484 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2485 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2486 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2487 | read_freq_ctr(&px->fe_req_per_sec), |
| 2488 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2489 | |
| 2490 | /* errors: cli_aborts, srv_aborts */ |
| 2491 | chunk_appendf(&trash, ",,"); |
| 2492 | |
| 2493 | /* compression: in, out, bypassed */ |
| 2494 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2495 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2496 | |
| 2497 | /* compression: comp_rsp */ |
| 2498 | chunk_appendf(&trash, "%lld,", |
| 2499 | px->fe_counters.p.http.comp_rsp); |
| 2500 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2501 | /* lastsess */ |
| 2502 | chunk_appendf(&trash, ","); |
| 2503 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2504 | /* finish with EOL */ |
| 2505 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2506 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2507 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2508 | } |
| 2509 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2510 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2511 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2512 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2513 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2514 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2515 | 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] | 2516 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2517 | struct appctx *appctx = __objt_appctx(si->end); |
| 2518 | |
| 2519 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2520 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2521 | 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] | 2522 | /* Column sub-heading for Enable or Disable server */ |
| 2523 | chunk_appendf(&trash, "<td></td>"); |
| 2524 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2525 | chunk_appendf(&trash, |
| 2526 | /* frontend name, listener name */ |
| 2527 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2528 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2529 | "", |
| 2530 | px->id, l->name, |
| 2531 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2532 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2533 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2534 | if (flags & ST_SHLGNDS) { |
| 2535 | char str[INET6_ADDRSTRLEN]; |
| 2536 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2537 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2538 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2539 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2540 | port = get_host_port(&l->addr); |
| 2541 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2542 | case AF_INET: |
| 2543 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2544 | break; |
| 2545 | case AF_INET6: |
| 2546 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2547 | break; |
| 2548 | case AF_UNIX: |
| 2549 | chunk_appendf(&trash, "unix, "); |
| 2550 | break; |
| 2551 | case -1: |
| 2552 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2553 | break; |
| 2554 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2555 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2556 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2557 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2558 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2559 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2560 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2561 | /* queue */ |
| 2562 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2563 | /* sessions rate: current, max, limit */ |
| 2564 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2565 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2566 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2567 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2568 | /* bytes: in, out */ |
| 2569 | "<td>%s</td><td>%s</td>" |
| 2570 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2571 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2572 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2573 | 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] | 2574 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2575 | chunk_appendf(&trash, |
| 2576 | /* denied: req, resp */ |
| 2577 | "<td>%s</td><td>%s</td>" |
| 2578 | /* errors: request, connect, response */ |
| 2579 | "<td>%s</td><td></td><td></td>" |
| 2580 | /* warnings: retries, redispatches */ |
| 2581 | "<td></td><td></td>" |
| 2582 | /* server status: reflect listener status */ |
| 2583 | "<td class=ac>%s</td>" |
| 2584 | /* rest of server: nothing */ |
| 2585 | "<td class=ac colspan=8></td></tr>" |
| 2586 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2587 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2588 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2589 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2590 | } |
| 2591 | else { /* CSV mode */ |
| 2592 | chunk_appendf(&trash, |
| 2593 | /* pxid, name, queue cur, queue max, */ |
| 2594 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2595 | /* sessions: current, max, limit, total */ |
| 2596 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2597 | /* bytes: in, out */ |
| 2598 | "%lld,%lld," |
| 2599 | /* denied: req, resp */ |
| 2600 | "%lld,%lld," |
| 2601 | /* errors: request, connect, response */ |
| 2602 | "%lld,,," |
| 2603 | /* warnings: retries, redispatches */ |
| 2604 | ",," |
| 2605 | /* server status: reflect listener status */ |
| 2606 | "%s," |
| 2607 | /* rest of server: nothing */ |
| 2608 | ",,,,,,,," |
| 2609 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2610 | "%d,%d,%d,,,,%d," |
| 2611 | /* rate, rate_lim, rate_max */ |
| 2612 | ",,," |
| 2613 | /* check_status, check_code, check_duration */ |
| 2614 | ",,," |
| 2615 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2616 | ",,,,,," |
| 2617 | /* failed health analyses */ |
| 2618 | "," |
| 2619 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2620 | ",,," |
| 2621 | /* errors: cli_aborts, srv_aborts */ |
| 2622 | ",," |
| 2623 | /* compression: in, out, bypassed, comp_rsp */ |
| 2624 | ",,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2625 | /* lastsess */ |
| 2626 | "," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2627 | "\n", |
| 2628 | px->id, l->name, |
| 2629 | l->nbconn, l->counters->conn_max, |
| 2630 | l->maxconn, l->counters->cum_conn, |
| 2631 | l->counters->bytes_in, l->counters->bytes_out, |
| 2632 | l->counters->denied_req, l->counters->denied_resp, |
| 2633 | l->counters->failed_req, |
| 2634 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2635 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2636 | } |
| 2637 | return 1; |
| 2638 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2639 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2640 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2641 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2642 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2643 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2644 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2645 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2646 | */ |
| 2647 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2648 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2649 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2650 | struct server *ref = sv->track ? sv->track : sv; |
| 2651 | char str[INET6_ADDRSTRLEN]; |
| 2652 | struct chunk src; |
| 2653 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2654 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2655 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2656 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2657 | "DOWN", |
| 2658 | "DN %d/%d ↑", |
| 2659 | "UP %d/%d ↓", |
| 2660 | "UP", |
| 2661 | "NOLB %d/%d ↓", |
| 2662 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2663 | "DRAIN %d/%d ↓", |
| 2664 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2665 | "<i>no check</i>" |
| 2666 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2667 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2668 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2669 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2670 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2671 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2672 | "<tr class=\"%s%d\">", |
| 2673 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2674 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2675 | 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] | 2676 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2677 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2678 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2679 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2680 | chunk_appendf(&trash, |
| 2681 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2682 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2683 | "", |
| 2684 | px->id, sv->id, |
| 2685 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2686 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2687 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2688 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2689 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2690 | |
| 2691 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2692 | case AF_INET: |
| 2693 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2694 | break; |
| 2695 | case AF_INET6: |
| 2696 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2697 | break; |
| 2698 | case AF_UNIX: |
| 2699 | chunk_appendf(&trash, "unix, "); |
| 2700 | break; |
| 2701 | case -1: |
| 2702 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2703 | break; |
| 2704 | default: /* address family not supported */ |
| 2705 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2706 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2707 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2708 | /* id */ |
| 2709 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2710 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2711 | /* cookie */ |
| 2712 | if (sv->cookie) { |
| 2713 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2714 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2715 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2716 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2717 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2718 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2719 | } |
| 2720 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2721 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2722 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2723 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2724 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2725 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2726 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2727 | /* sessions rate : current, max, limit */ |
| 2728 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2729 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2730 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2731 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2732 | 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] | 2733 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2734 | |
| 2735 | chunk_appendf(&trash, |
| 2736 | /* sessions: current, max, limit, total */ |
| 2737 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2738 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2739 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2740 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2741 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2742 | U2H(sv->counters.cum_sess), |
| 2743 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2744 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2745 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2746 | if (px->mode == PR_MODE_HTTP) { |
| 2747 | unsigned long long tot; |
| 2748 | for (tot = i = 0; i < 6; i++) |
| 2749 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2750 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2751 | chunk_appendf(&trash, |
| 2752 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2753 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2754 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2755 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2756 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2757 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2758 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2759 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2760 | U2H(tot), |
| 2761 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2762 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2763 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2764 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2765 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2766 | 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] | 2767 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2768 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2769 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2770 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2771 | /* sessions: lbtot, last */ |
| 2772 | "<td>%s</td><td>%s</td>", |
| 2773 | U2H(sv->counters.cum_lbconn), |
| 2774 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2775 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2776 | chunk_appendf(&trash, |
| 2777 | /* bytes : in, out */ |
| 2778 | "<td>%s</td><td>%s</td>" |
| 2779 | /* denied: req, resp */ |
| 2780 | "<td></td><td>%s</td>" |
| 2781 | /* errors : request, connect */ |
| 2782 | "<td></td><td>%s</td>" |
| 2783 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2784 | "<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] | 2785 | /* warnings: retries, redispatches */ |
| 2786 | "<td>%lld</td><td>%lld</td>" |
| 2787 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2788 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2789 | U2H(sv->counters.failed_secu), |
| 2790 | U2H(sv->counters.failed_conns), |
| 2791 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2792 | sv->counters.cli_aborts, |
| 2793 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2794 | sv->counters.retries, sv->counters.redispatches); |
| 2795 | |
| 2796 | /* status, lest check */ |
| 2797 | chunk_appendf(&trash, "<td class=ac>"); |
| 2798 | |
| 2799 | if (sv->state & SRV_MAINTAIN) { |
| 2800 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2801 | chunk_appendf(&trash, "MAINT"); |
| 2802 | } |
| 2803 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2804 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2805 | chunk_appendf(&trash, "MAINT(via)"); |
| 2806 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2807 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2808 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2809 | chunk_appendf(&trash, |
| 2810 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2811 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2812 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2813 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2814 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2815 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2816 | chunk_appendf(&trash, |
| 2817 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 2818 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2819 | get_check_status_info(sv->check.status)); |
| 2820 | |
| 2821 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2822 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2823 | |
| 2824 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2825 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2826 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2827 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2828 | get_check_status_description(sv->check.status)); |
| 2829 | if (*sv->check.desc) { |
| 2830 | chunk_appendf(&trash, ": "); |
| 2831 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2832 | chunk_htmlencode(&trash, &src); |
| 2833 | } |
| 2834 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2835 | } |
| 2836 | else |
| 2837 | chunk_appendf(&trash, "</td><td>"); |
| 2838 | |
| 2839 | chunk_appendf(&trash, |
| 2840 | /* weight */ |
| 2841 | "</td><td class=ac>%d</td>" |
| 2842 | /* act, bck */ |
| 2843 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2844 | "", |
| 2845 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2846 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2847 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2848 | |
| 2849 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2850 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2851 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2852 | |
| 2853 | if (ref->observe) |
| 2854 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2855 | |
| 2856 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2857 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2858 | "<td>%lld</td><td>%s</td>" |
| 2859 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2860 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2861 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2862 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2863 | else if (sv != ref) { |
| 2864 | if (sv->state & SRV_MAINTAIN) |
| 2865 | chunk_appendf(&trash, |
| 2866 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2867 | ref->proxy->id, ref->id); |
| 2868 | else |
| 2869 | chunk_appendf(&trash, |
| 2870 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2871 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2872 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2873 | else |
| 2874 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2875 | |
| 2876 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2877 | if (sv->state & SRV_WARMINGUP) |
| 2878 | 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] | 2879 | else |
| 2880 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2881 | } |
| 2882 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2883 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2884 | "DOWN,", |
| 2885 | "DOWN %d/%d,", |
| 2886 | "UP %d/%d,", |
| 2887 | "UP,", |
| 2888 | "NOLB %d/%d,", |
| 2889 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2890 | "DRAIN %d/%d,", |
| 2891 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2892 | "no check," |
| 2893 | }; |
| 2894 | |
| 2895 | chunk_appendf(&trash, |
| 2896 | /* pxid, name */ |
| 2897 | "%s,%s," |
| 2898 | /* queue : current, max */ |
| 2899 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2900 | /* sessions : current, max, limit, total */ |
| 2901 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2902 | /* bytes : in, out */ |
| 2903 | "%lld,%lld," |
| 2904 | /* denied: req, resp */ |
| 2905 | ",%lld," |
| 2906 | /* errors : request, connect, response */ |
| 2907 | ",%lld,%lld," |
| 2908 | /* warnings: retries, redispatches */ |
| 2909 | "%lld,%lld," |
| 2910 | "", |
| 2911 | px->id, sv->id, |
| 2912 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2913 | 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] | 2914 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2915 | sv->counters.failed_secu, |
| 2916 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2917 | sv->counters.retries, sv->counters.redispatches); |
| 2918 | |
| 2919 | /* status */ |
| 2920 | if (sv->state & SRV_MAINTAIN) |
| 2921 | chunk_appendf(&trash, "MAINT,"); |
| 2922 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2923 | chunk_appendf(&trash, "MAINT(via),"); |
| 2924 | else |
| 2925 | chunk_appendf(&trash, |
| 2926 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2927 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2928 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2929 | |
| 2930 | chunk_appendf(&trash, |
| 2931 | /* weight, active, backup */ |
| 2932 | "%d,%d,%d," |
| 2933 | "", |
| 2934 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2935 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2936 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2937 | |
| 2938 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2939 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2940 | chunk_appendf(&trash, |
| 2941 | "%lld,%lld,%d,%d,", |
| 2942 | sv->counters.failed_checks, sv->counters.down_trans, |
| 2943 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 2944 | else |
| 2945 | chunk_appendf(&trash, ",,,,"); |
| 2946 | |
| 2947 | /* queue limit, pid, iid, sid, */ |
| 2948 | chunk_appendf(&trash, |
| 2949 | "%s," |
| 2950 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2951 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2952 | relative_pid, px->uuid, sv->puid); |
| 2953 | |
| 2954 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2955 | if (sv->state & SRV_WARMINGUP) |
| 2956 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2957 | |
| 2958 | /* sessions: lbtot */ |
| 2959 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 2960 | |
| 2961 | /* tracked */ |
| 2962 | if (sv->track) |
| 2963 | chunk_appendf(&trash, "%s/%s,", |
| 2964 | sv->track->proxy->id, sv->track->id); |
| 2965 | else |
| 2966 | chunk_appendf(&trash, ","); |
| 2967 | |
| 2968 | /* type */ |
| 2969 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 2970 | |
| 2971 | /* rate */ |
| 2972 | chunk_appendf(&trash, "%u,,%u,", |
| 2973 | read_freq_ctr(&sv->sess_per_sec), |
| 2974 | sv->counters.sps_max); |
| 2975 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2976 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2977 | /* check_status */ |
| 2978 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 2979 | |
| 2980 | /* check_code */ |
| 2981 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2982 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 2983 | else |
| 2984 | chunk_appendf(&trash, ","); |
| 2985 | |
| 2986 | /* check_duration */ |
| 2987 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 2988 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 2989 | else |
| 2990 | chunk_appendf(&trash, ","); |
| 2991 | |
| 2992 | } |
| 2993 | else |
| 2994 | chunk_appendf(&trash, ",,,"); |
| 2995 | |
| 2996 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2997 | if (px->mode == PR_MODE_HTTP) { |
| 2998 | for (i=1; i<6; i++) |
| 2999 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3000 | |
| 3001 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3002 | } |
| 3003 | else |
| 3004 | chunk_appendf(&trash, ",,,,,,"); |
| 3005 | |
| 3006 | /* failed health analyses */ |
| 3007 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3008 | |
| 3009 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3010 | chunk_appendf(&trash, ",,,"); |
| 3011 | |
| 3012 | /* errors: cli_aborts, srv_aborts */ |
| 3013 | chunk_appendf(&trash, "%lld,%lld,", |
| 3014 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3015 | |
| 3016 | /* compression: in, out, bypassed, comp_rsp */ |
| 3017 | chunk_appendf(&trash, ",,,,"); |
| 3018 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3019 | /* lastsess */ |
| 3020 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3021 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3022 | /* finish with EOL */ |
| 3023 | chunk_appendf(&trash, "\n"); |
| 3024 | } |
| 3025 | return 1; |
| 3026 | } |
| 3027 | |
| 3028 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3029 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3030 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3031 | */ |
| 3032 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3033 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3034 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3035 | struct chunk src; |
| 3036 | int i; |
| 3037 | |
| 3038 | if (!(px->cap & PR_CAP_BE)) |
| 3039 | return 0; |
| 3040 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3041 | 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] | 3042 | return 0; |
| 3043 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3044 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3045 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3046 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3047 | /* Column sub-heading for Enable or Disable server */ |
| 3048 | chunk_appendf(&trash, "<td></td>"); |
| 3049 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3050 | chunk_appendf(&trash, |
| 3051 | "<td class=ac>" |
| 3052 | /* name */ |
| 3053 | "%s<a name=\"%s/Backend\"></a>" |
| 3054 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3055 | "", |
| 3056 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3057 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3058 | |
| 3059 | if (flags & ST_SHLGNDS) { |
| 3060 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3061 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3062 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3063 | |
| 3064 | /* cookie */ |
| 3065 | if (px->cookie_name) { |
| 3066 | chunk_appendf(&trash, ", cookie: '"); |
| 3067 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3068 | chunk_htmlencode(&trash, &src); |
| 3069 | chunk_appendf(&trash, "'"); |
| 3070 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3071 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3075 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3076 | /* queue : current, max */ |
| 3077 | "<td>%s</td><td>%s</td><td></td>" |
| 3078 | /* sessions rate : current, max, limit */ |
| 3079 | "<td>%s</td><td>%s</td><td></td>" |
| 3080 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3081 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3082 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3083 | 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] | 3084 | |
| 3085 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3086 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3087 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3088 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3089 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3090 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3091 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3092 | U2H(px->be_counters.cum_conn), |
| 3093 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3094 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3095 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3096 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3097 | chunk_appendf(&trash, |
| 3098 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3099 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3100 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3101 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3102 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3103 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3104 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3105 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3106 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3107 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3108 | U2H(px->be_counters.p.http.cum_req), |
| 3109 | U2H(px->be_counters.p.http.rsp[1]), |
| 3110 | U2H(px->be_counters.p.http.rsp[2]), |
| 3111 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3112 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3113 | (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] | 3114 | U2H(px->be_counters.p.http.rsp[3]), |
| 3115 | U2H(px->be_counters.p.http.rsp[4]), |
| 3116 | U2H(px->be_counters.p.http.rsp[5]), |
| 3117 | U2H(px->be_counters.p.http.rsp[0]), |
| 3118 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3122 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3123 | /* sessions: lbtot, last */ |
| 3124 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3125 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3126 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3127 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3128 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3129 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3130 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3131 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3132 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3133 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3134 | "<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] | 3135 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3136 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3137 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3138 | px->be_counters.comp_in ? |
| 3139 | (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] | 3140 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3141 | |
| 3142 | chunk_appendf(&trash, |
| 3143 | /* denied: req, resp */ |
| 3144 | "<td>%s</td><td>%s</td>" |
| 3145 | /* errors : request, connect */ |
| 3146 | "<td></td><td>%s</td>" |
| 3147 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3148 | "<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] | 3149 | /* warnings: retries, redispatches */ |
| 3150 | "<td>%lld</td><td>%lld</td>" |
| 3151 | /* backend status: reflect backend status (up/down): we display UP |
| 3152 | * if the backend has known working servers or if it has no server at |
| 3153 | * all (eg: for stats). Then we display the total weight, number of |
| 3154 | * active and backups. */ |
| 3155 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3156 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3157 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3158 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3159 | U2H(px->be_counters.failed_conns), |
| 3160 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3161 | px->be_counters.cli_aborts, |
| 3162 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3163 | px->be_counters.retries, px->be_counters.redispatches, |
| 3164 | human_time(now.tv_sec - px->last_change, 1), |
| 3165 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3166 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3167 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3168 | px->srv_act, px->srv_bck); |
| 3169 | |
| 3170 | chunk_appendf(&trash, |
| 3171 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3172 | "<td class=ac> </td><td>%d</td>" |
| 3173 | "<td>%s</td>" |
| 3174 | "<td></td>" |
| 3175 | "</tr>", |
| 3176 | px->down_trans, |
| 3177 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3178 | } |
| 3179 | else { /* CSV mode */ |
| 3180 | chunk_appendf(&trash, |
| 3181 | /* pxid, name */ |
| 3182 | "%s,BACKEND," |
| 3183 | /* queue : current, max */ |
| 3184 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3185 | /* sessions : current, max, limit, total */ |
| 3186 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3187 | /* bytes : in, out */ |
| 3188 | "%lld,%lld," |
| 3189 | /* denied: req, resp */ |
| 3190 | "%lld,%lld," |
| 3191 | /* errors : request, connect, response */ |
| 3192 | ",%lld,%lld," |
| 3193 | /* warnings: retries, redispatches */ |
| 3194 | "%lld,%lld," |
| 3195 | /* backend status: reflect backend status (up/down): we display UP |
| 3196 | * if the backend has known working servers or if it has no server at |
| 3197 | * all (eg: for stats). Then we display the total weight, number of |
| 3198 | * active and backups. */ |
| 3199 | "%s," |
| 3200 | "%d,%d,%d," |
| 3201 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3202 | ",%d,%d,%d,," |
| 3203 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3204 | "%d,%d,0,,%lld,,%d," |
| 3205 | /* rate, rate_lim, rate_max, */ |
| 3206 | "%u,,%u," |
| 3207 | /* check_status, check_code, check_duration */ |
| 3208 | ",,,", |
| 3209 | px->id, |
| 3210 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3211 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3212 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3213 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3214 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3215 | px->be_counters.retries, px->be_counters.redispatches, |
| 3216 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3217 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3218 | px->srv_act, px->srv_bck, |
| 3219 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3220 | px->srv?be_downtime(px):0, |
| 3221 | relative_pid, px->uuid, |
| 3222 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3223 | read_freq_ctr(&px->be_sess_per_sec), |
| 3224 | px->be_counters.sps_max); |
| 3225 | |
| 3226 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3227 | if (px->mode == PR_MODE_HTTP) { |
| 3228 | for (i=1; i<6; i++) |
| 3229 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3230 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3231 | } |
| 3232 | else |
| 3233 | chunk_appendf(&trash, ",,,,,,"); |
| 3234 | |
| 3235 | /* failed health analyses */ |
| 3236 | chunk_appendf(&trash, ","); |
| 3237 | |
| 3238 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3239 | chunk_appendf(&trash, ",,,"); |
| 3240 | |
| 3241 | /* errors: cli_aborts, srv_aborts */ |
| 3242 | chunk_appendf(&trash, "%lld,%lld,", |
| 3243 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3244 | |
| 3245 | /* compression: in, out, bypassed */ |
| 3246 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3247 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3248 | |
| 3249 | /* compression: comp_rsp */ |
| 3250 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3251 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3252 | /* lastsess */ |
| 3253 | chunk_appendf(&trash, "%d,", be_lastsession(px)); |
| 3254 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3255 | /* finish with EOL */ |
| 3256 | chunk_appendf(&trash, "\n"); |
| 3257 | } |
| 3258 | return 1; |
| 3259 | } |
| 3260 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3261 | /* 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] | 3262 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3263 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3264 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3265 | 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] | 3266 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3267 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3268 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3269 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3270 | 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] | 3271 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3272 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3273 | /* 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] | 3274 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3275 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3276 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3277 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3278 | 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] | 3279 | } |
| 3280 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3281 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3282 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3283 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3284 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3285 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3286 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | /* print a new table */ |
| 3290 | chunk_appendf(&trash, |
| 3291 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3292 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3293 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3294 | |
| 3295 | chunk_appendf(&trash, |
| 3296 | "<a name=\"%s\"></a>%s" |
| 3297 | "<a class=px href=\"#%s\">%s</a>", |
| 3298 | px->id, |
| 3299 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3300 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3301 | |
| 3302 | if (uri->flags & ST_SHLGNDS) { |
| 3303 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3304 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3305 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3306 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3307 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3311 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3312 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3313 | "</tr>\n" |
| 3314 | "</table>\n" |
| 3315 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3316 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3317 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3318 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3319 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3320 | 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] | 3321 | /* Column heading for Enable or Disable server */ |
| 3322 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3323 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3324 | |
| 3325 | chunk_appendf(&trash, |
| 3326 | "<th rowspan=2></th>" |
| 3327 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3328 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3329 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3330 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3331 | "<th colspan=9>Server</th>" |
| 3332 | "</tr>\n" |
| 3333 | "<tr class=\"titre\">" |
| 3334 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3335 | "<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] | 3336 | "<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] | 3337 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3338 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3339 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3340 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3341 | "<th>Thrtle</th>\n" |
| 3342 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3343 | } |
| 3344 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3345 | /* 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] | 3346 | * 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] | 3347 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3348 | 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] | 3349 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3350 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3351 | chunk_appendf(&trash, "</table>"); |
| 3352 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3353 | 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] | 3354 | /* close the form used to enable/disable this proxy servers */ |
| 3355 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3356 | "Choose the action to perform on the checked servers : " |
| 3357 | "<select name=action>" |
| 3358 | "<option value=\"\"></option>" |
| 3359 | "<option value=\"disable\">Disable</option>" |
| 3360 | "<option value=\"enable\">Enable</option>" |
| 3361 | "<option value=\"stop\">Soft Stop</option>" |
| 3362 | "<option value=\"start\">Soft Start</option>" |
| 3363 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3364 | "</select>" |
| 3365 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3366 | " <input type=\"submit\" value=\"Apply\">" |
| 3367 | "</form>", |
| 3368 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3369 | } |
| 3370 | |
| 3371 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3372 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3373 | |
| 3374 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3375 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3376 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3377 | * buffer space, or non-zero if everything completed. This function is used |
| 3378 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3379 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3380 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3381 | 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] | 3382 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3383 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3384 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3385 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3386 | 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] | 3387 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3388 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3389 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3390 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3391 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3392 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3393 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3394 | if (uri && uri->scope) { |
| 3395 | /* we have a limited scope, we have to check the proxy name */ |
| 3396 | struct stat_scope *scope; |
| 3397 | int len; |
| 3398 | |
| 3399 | len = strlen(px->id); |
| 3400 | scope = uri->scope; |
| 3401 | |
| 3402 | while (scope) { |
| 3403 | /* match exact proxy name */ |
| 3404 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3405 | break; |
| 3406 | |
| 3407 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3408 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3409 | break; |
| 3410 | scope = scope->next; |
| 3411 | } |
| 3412 | |
| 3413 | /* proxy name not found : don't dump anything */ |
| 3414 | if (scope == NULL) |
| 3415 | return 1; |
| 3416 | } |
| 3417 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3418 | /* if the user has requested a limited output and the proxy |
| 3419 | * name does not match, skip it. |
| 3420 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3421 | if (appctx->ctx.stats.scope_len && |
| 3422 | 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] | 3423 | return 1; |
| 3424 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3425 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3426 | (appctx->ctx.stats.iid != -1) && |
| 3427 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3428 | return 1; |
| 3429 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3430 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3431 | /* fall through */ |
| 3432 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3433 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3434 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3435 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3436 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3437 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3438 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3439 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3440 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3441 | /* fall through */ |
| 3442 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3443 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3444 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3445 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3446 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3447 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3448 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3449 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3450 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3451 | /* fall through */ |
| 3452 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3453 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3454 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3455 | 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] | 3456 | if (buffer_almost_full(rep->buf)) { |
| 3457 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3458 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3459 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3460 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3461 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3462 | if (!l->counters) |
| 3463 | continue; |
| 3464 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3465 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3466 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3467 | break; |
| 3468 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3469 | 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] | 3470 | continue; |
| 3471 | } |
| 3472 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3473 | /* print the frontend */ |
| 3474 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3475 | if (bi_putchk(rep, &trash) == -1) |
| 3476 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3477 | } |
| 3478 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3479 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3480 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3481 | /* fall through */ |
| 3482 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3483 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3484 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3485 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3486 | 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] | 3487 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3488 | if (buffer_almost_full(rep->buf)) { |
| 3489 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3490 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3491 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3492 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3493 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3494 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3495 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3496 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3497 | break; |
| 3498 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3499 | 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] | 3500 | continue; |
| 3501 | } |
| 3502 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3503 | if (sv->track) |
| 3504 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3505 | else |
| 3506 | svs = sv; |
| 3507 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3508 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3509 | if (!(svs->check.state & CHK_ST_ENABLED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3510 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3511 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 3512 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3513 | sv_state = 3; /* UP */ |
| 3514 | else |
| 3515 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3516 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3517 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3518 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3519 | else if (svs->state & SRV_GOINGDOWN) |
| 3520 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3521 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3522 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 3523 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3524 | sv_state = 1; /* going up */ |
| 3525 | else |
| 3526 | sv_state = 0; /* DOWN */ |
| 3527 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3528 | if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (appctx->ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3529 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3530 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3531 | continue; |
| 3532 | } |
| 3533 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3534 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3535 | if (bi_putchk(rep, &trash) == -1) |
| 3536 | return 0; |
| 3537 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3538 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3539 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3540 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3541 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3542 | case STAT_PX_ST_BE: |
| 3543 | /* print the backend */ |
| 3544 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3545 | if (bi_putchk(rep, &trash) == -1) |
| 3546 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3547 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3548 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3549 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3550 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3551 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3552 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3553 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3554 | if (bi_putchk(rep, &trash) == -1) |
| 3555 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3556 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3557 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3558 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3559 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3560 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3561 | case STAT_PX_ST_FIN: |
| 3562 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3563 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3564 | default: |
| 3565 | /* unknown state, we should put an abort() here ! */ |
| 3566 | return 1; |
| 3567 | } |
| 3568 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3569 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3570 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3571 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3572 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3573 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3574 | { |
| 3575 | /* WARNING! This must fit in the first buffer !!! */ |
| 3576 | chunk_appendf(&trash, |
| 3577 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3578 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3579 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3580 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3581 | "<style type=\"text/css\"><!--\n" |
| 3582 | "body {" |
| 3583 | " font-family: arial, helvetica, sans-serif;" |
| 3584 | " font-size: 12px;" |
| 3585 | " font-weight: normal;" |
| 3586 | " color: black;" |
| 3587 | " background: white;" |
| 3588 | "}\n" |
| 3589 | "th,td {" |
| 3590 | " font-size: 10px;" |
| 3591 | "}\n" |
| 3592 | "h1 {" |
| 3593 | " font-size: x-large;" |
| 3594 | " margin-bottom: 0.5em;" |
| 3595 | "}\n" |
| 3596 | "h2 {" |
| 3597 | " font-family: helvetica, arial;" |
| 3598 | " font-size: x-large;" |
| 3599 | " font-weight: bold;" |
| 3600 | " font-style: italic;" |
| 3601 | " color: #6020a0;" |
| 3602 | " margin-top: 0em;" |
| 3603 | " margin-bottom: 0em;" |
| 3604 | "}\n" |
| 3605 | "h3 {" |
| 3606 | " font-family: helvetica, arial;" |
| 3607 | " font-size: 16px;" |
| 3608 | " font-weight: bold;" |
| 3609 | " color: #b00040;" |
| 3610 | " background: #e8e8d0;" |
| 3611 | " margin-top: 0em;" |
| 3612 | " margin-bottom: 0em;" |
| 3613 | "}\n" |
| 3614 | "li {" |
| 3615 | " margin-top: 0.25em;" |
| 3616 | " margin-right: 2em;" |
| 3617 | "}\n" |
| 3618 | ".hr {margin-top: 0.25em;" |
| 3619 | " border-color: black;" |
| 3620 | " border-bottom-style: solid;" |
| 3621 | "}\n" |
| 3622 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3623 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3624 | ".frontend {background: #e8e8d0;}\n" |
| 3625 | ".socket {background: #d0d0d0;}\n" |
| 3626 | ".backend {background: #e8e8d0;}\n" |
| 3627 | ".active0 {background: #ff9090;}\n" |
| 3628 | ".active1 {background: #ffd020;}\n" |
| 3629 | ".active2 {background: #ffffa0;}\n" |
| 3630 | ".active3 {background: #c0ffc0;}\n" |
| 3631 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3632 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3633 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3634 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3635 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3636 | ".backup0 {background: #ff9090;}\n" |
| 3637 | ".backup1 {background: #ff80ff;}\n" |
| 3638 | ".backup2 {background: #c060ff;}\n" |
| 3639 | ".backup3 {background: #b0d0ff;}\n" |
| 3640 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3641 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3642 | ".backup6 {background: #c060ff;}\n" |
| 3643 | ".backup7 {background: #cc9900;}\n" |
| 3644 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3645 | ".maintain {background: #c07820;}\n" |
| 3646 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3647 | "\n" |
| 3648 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3649 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3650 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3651 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3652 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3653 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3654 | "\n" |
| 3655 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3656 | "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" |
| 3657 | "table.tbl td.ac { text-align: center;}\n" |
| 3658 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3659 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3660 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3661 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3662 | "\n" |
| 3663 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3664 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3665 | "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] | 3666 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3667 | "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] | 3668 | "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] | 3669 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3670 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3671 | " display:block;\n" |
| 3672 | " visibility:hidden;\n" |
| 3673 | " z-index:2147483647;\n" |
| 3674 | " position:absolute;\n" |
| 3675 | " padding:2px 4px 3px;\n" |
| 3676 | " background:#f0f060; color:#000000;\n" |
| 3677 | " border:1px solid #7040c0;\n" |
| 3678 | " white-space:nowrap;\n" |
| 3679 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3680 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3681 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3682 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3683 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3684 | "-->\n" |
| 3685 | "</style></head>\n", |
| 3686 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3687 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3688 | ); |
| 3689 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3690 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3691 | /* 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] | 3692 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3693 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3694 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3695 | static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3696 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3697 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3698 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3699 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3700 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3701 | /* WARNING! this has to fit the first packet too. |
| 3702 | * We are around 3.5 kB, add adding entries will |
| 3703 | * become tricky if we want to support 4kB buffers ! |
| 3704 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3705 | chunk_appendf(&trash, |
| 3706 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3707 | PRODUCT_NAME "%s</a></h1>\n" |
| 3708 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3709 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3710 | "<h3>> General process information</h3>\n" |
| 3711 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3712 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3713 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3714 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3715 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3716 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3717 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3718 | "</td><td align=\"center\" nowrap>\n" |
| 3719 | "<table class=\"lgd\"><tr>\n" |
| 3720 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3721 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3722 | "</tr><tr>\n" |
| 3723 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3724 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3725 | "</tr><tr>\n" |
| 3726 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3727 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3728 | "</tr><tr>\n" |
| 3729 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3730 | "</tr><tr>\n" |
| 3731 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3732 | "</tr><tr>\n" |
| 3733 | "<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] | 3734 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3735 | "<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] | 3736 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3737 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3738 | "</td>" |
| 3739 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3740 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3741 | "", |
| 3742 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3743 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3744 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3745 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3746 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3747 | pid, relative_pid, global.nbproc, |
| 3748 | up / 86400, (up % 86400) / 3600, |
| 3749 | (up % 3600) / 60, (up % 60), |
| 3750 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3751 | global.rlimit_memmax ? " MB" : "", |
| 3752 | global.rlimit_nofile, |
| 3753 | global.maxsock, global.maxconn, global.maxpipes, |
| 3754 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3755 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3756 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3757 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3758 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3759 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3760 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3761 | |
| 3762 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3763 | "<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] | 3764 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3765 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3766 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3767 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3768 | STAT_SCOPE_TXT_MAXLEN); |
| 3769 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3770 | /* 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] | 3771 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3772 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3773 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3774 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3775 | 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] | 3776 | } |
| 3777 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3778 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3779 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3780 | "<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] | 3781 | uri->uri_prefix, |
| 3782 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3783 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3784 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3785 | else |
| 3786 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3787 | "<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] | 3788 | uri->uri_prefix, |
| 3789 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3790 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3791 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3792 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3793 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3794 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3795 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3796 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3797 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3798 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3799 | "", |
| 3800 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3801 | else |
| 3802 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3803 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3804 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3805 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3806 | ";norefresh", |
| 3807 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3808 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3809 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3810 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3811 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3812 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3813 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3814 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3815 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3816 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3817 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3818 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3819 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3820 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3821 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3822 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3823 | chunk_appendf(&trash, |
| 3824 | "</ul></td>" |
| 3825 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3826 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3827 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3828 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3829 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3830 | "</ul>" |
| 3831 | "</td>" |
| 3832 | "</tr></table>\n" |
| 3833 | "" |
| 3834 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3835 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3836 | if (appctx->ctx.stats.st_code) { |
| 3837 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3838 | case STAT_STATUS_DONE: |
| 3839 | chunk_appendf(&trash, |
| 3840 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3841 | "<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] | 3842 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3843 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3844 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3845 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3846 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3847 | break; |
| 3848 | case STAT_STATUS_NONE: |
| 3849 | chunk_appendf(&trash, |
| 3850 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3851 | "<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] | 3852 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3853 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3854 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3855 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3856 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3857 | break; |
| 3858 | case STAT_STATUS_PART: |
| 3859 | chunk_appendf(&trash, |
| 3860 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3861 | "<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] | 3862 | "Action partially processed.<br>" |
| 3863 | "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] | 3864 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3865 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3866 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3867 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3868 | break; |
| 3869 | case STAT_STATUS_ERRP: |
| 3870 | chunk_appendf(&trash, |
| 3871 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3872 | "<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] | 3873 | "Action not processed because of invalid parameters." |
| 3874 | "<ul>" |
| 3875 | "<li>The action is maybe unknown.</li>" |
| 3876 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3877 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3878 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3879 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3880 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3881 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3882 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3883 | break; |
| 3884 | case STAT_STATUS_EXCD: |
| 3885 | chunk_appendf(&trash, |
| 3886 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3887 | "<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] | 3888 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3889 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3890 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3891 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3892 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3893 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3894 | break; |
| 3895 | case STAT_STATUS_DENY: |
| 3896 | chunk_appendf(&trash, |
| 3897 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3898 | "<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] | 3899 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3900 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3901 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3902 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3903 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3904 | break; |
| 3905 | default: |
| 3906 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3907 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3908 | "<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] | 3909 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3910 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3911 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3912 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3913 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3914 | } |
| 3915 | chunk_appendf(&trash, "<p>\n"); |
| 3916 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3917 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3918 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3919 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3920 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3921 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3922 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3923 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3924 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3925 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3926 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3927 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3928 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3929 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3930 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3931 | * and the session must be closed, or -1 in case of any error. This function is |
| 3932 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3933 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3934 | 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] | 3935 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3936 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3937 | struct channel *rep = si->ib; |
| 3938 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3939 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3940 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3941 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3942 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3943 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3944 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3945 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3946 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3947 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3948 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3949 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3950 | else |
| 3951 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3952 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3953 | if (bi_putchk(rep, &trash) == -1) |
| 3954 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3955 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3956 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3957 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3958 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3959 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3960 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3961 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3962 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3963 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3964 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3965 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3966 | appctx->ctx.stats.px = proxy; |
| 3967 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3968 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3969 | /* fall through */ |
| 3970 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3971 | case STAT_ST_LIST: |
| 3972 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3973 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3974 | if (buffer_almost_full(rep->buf)) { |
| 3975 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3976 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3977 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3978 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3979 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3980 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 3981 | 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] | 3982 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3983 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3984 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3985 | appctx->ctx.stats.px = px->next; |
| 3986 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3987 | } |
| 3988 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3989 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3990 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3991 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3992 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3993 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3994 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3995 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3996 | if (bi_putchk(rep, &trash) == -1) |
| 3997 | return 0; |
| 3998 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3999 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4000 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4001 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4002 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4003 | case STAT_ST_FIN: |
| 4004 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4005 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4006 | default: |
| 4007 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4008 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4009 | return -1; |
| 4010 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4011 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4012 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4013 | /* We reached the stats page through a POST request. The appctx is |
| 4014 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4015 | * Parse the posted data and enable/disable servers if necessary. |
| 4016 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4017 | */ |
| 4018 | static int stats_process_http_post(struct stream_interface *si) |
| 4019 | { |
| 4020 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4021 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4022 | |
| 4023 | struct proxy *px = NULL; |
| 4024 | struct server *sv = NULL; |
| 4025 | |
| 4026 | char key[LINESIZE]; |
| 4027 | int action = ST_ADM_ACTION_NONE; |
| 4028 | int reprocess = 0; |
| 4029 | |
| 4030 | int total_servers = 0; |
| 4031 | int altered_servers = 0; |
| 4032 | |
| 4033 | char *first_param, *cur_param, *next_param, *end_params; |
| 4034 | char *st_cur_param = NULL; |
| 4035 | char *st_next_param = NULL; |
| 4036 | |
| 4037 | struct chunk *temp; |
| 4038 | int reql; |
| 4039 | |
| 4040 | temp = get_trash_chunk(); |
| 4041 | if (temp->size < s->txn.req.body_len) { |
| 4042 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4043 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4044 | goto out; |
| 4045 | } |
| 4046 | |
| 4047 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 4048 | if (reql <= 0) { |
| 4049 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4050 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4051 | return 0; |
| 4052 | } |
| 4053 | |
| 4054 | first_param = temp->str; |
| 4055 | end_params = temp->str + reql; |
| 4056 | cur_param = next_param = end_params; |
| 4057 | *end_params = '\0'; |
| 4058 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4059 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4060 | |
| 4061 | /* |
| 4062 | * Parse the parameters in reverse order to only store the last value. |
| 4063 | * From the html form, the backend and the action are at the end. |
| 4064 | */ |
| 4065 | while (cur_param > first_param) { |
| 4066 | char *value; |
| 4067 | int poffset, plen; |
| 4068 | |
| 4069 | cur_param--; |
| 4070 | |
| 4071 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4072 | reprocess_servers: |
| 4073 | /* Parse the key */ |
| 4074 | poffset = (cur_param != first_param ? 1 : 0); |
| 4075 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4076 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4077 | strncpy(key, cur_param + poffset, plen); |
| 4078 | key[plen - 1] = '\0'; |
| 4079 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4080 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4081 | goto out; |
| 4082 | } |
| 4083 | |
| 4084 | /* Parse the value */ |
| 4085 | value = key; |
| 4086 | while (*value != '\0' && *value != '=') { |
| 4087 | value++; |
| 4088 | } |
| 4089 | if (*value == '=') { |
| 4090 | /* Ok, a value is found, we can mark the end of the key */ |
| 4091 | *value++ = '\0'; |
| 4092 | } |
| 4093 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4094 | break; |
| 4095 | |
| 4096 | /* Now we can check the key to see what to do */ |
| 4097 | if (!px && (strcmp(key, "b") == 0)) { |
| 4098 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4099 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4100 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4101 | goto out; |
| 4102 | } |
| 4103 | } |
| 4104 | else if (!action && (strcmp(key, "action") == 0)) { |
| 4105 | if (strcmp(value, "disable") == 0) { |
| 4106 | action = ST_ADM_ACTION_DISABLE; |
| 4107 | } |
| 4108 | else if (strcmp(value, "enable") == 0) { |
| 4109 | action = ST_ADM_ACTION_ENABLE; |
| 4110 | } |
| 4111 | else if (strcmp(value, "stop") == 0) { |
| 4112 | action = ST_ADM_ACTION_STOP; |
| 4113 | } |
| 4114 | else if (strcmp(value, "start") == 0) { |
| 4115 | action = ST_ADM_ACTION_START; |
| 4116 | } |
| 4117 | else if (strcmp(value, "shutdown") == 0) { |
| 4118 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4119 | } |
| 4120 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4121 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4122 | goto out; |
| 4123 | } |
| 4124 | } |
| 4125 | else if (strcmp(key, "s") == 0) { |
| 4126 | if (!(px && action)) { |
| 4127 | /* |
| 4128 | * Indicates that we'll need to reprocess the parameters |
| 4129 | * as soon as backend and action are known |
| 4130 | */ |
| 4131 | if (!reprocess) { |
| 4132 | st_cur_param = cur_param; |
| 4133 | st_next_param = next_param; |
| 4134 | } |
| 4135 | reprocess = 1; |
| 4136 | } |
| 4137 | else if ((sv = findserver(px, value)) != NULL) { |
| 4138 | switch (action) { |
| 4139 | case ST_ADM_ACTION_DISABLE: |
| 4140 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 4141 | /* Not already in maintenance, we can change the server state */ |
| 4142 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 4143 | sv->check.state |= CHK_ST_PAUSED; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4144 | set_server_down(&sv->check); |
| 4145 | altered_servers++; |
| 4146 | total_servers++; |
| 4147 | } |
| 4148 | break; |
| 4149 | case ST_ADM_ACTION_ENABLE: |
| 4150 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
Willy Tarreau | a3ae932 | 2013-12-28 21:28:49 +0100 | [diff] [blame] | 4151 | /* Already in maintenance, we can change the server state. |
| 4152 | * If this server tracks the status of another one, |
| 4153 | * we must restore the good status. |
| 4154 | */ |
| 4155 | if (!sv->track || (sv->track->state & SRV_RUNNING)) { |
| 4156 | set_server_up(&sv->check); |
| 4157 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 4158 | } |
| 4159 | else { |
| 4160 | sv->state &= ~SRV_MAINTAIN; |
| 4161 | sv->check.state &= ~CHK_ST_PAUSED; |
| 4162 | set_server_down(&sv->check); |
| 4163 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4164 | altered_servers++; |
| 4165 | total_servers++; |
| 4166 | } |
| 4167 | break; |
| 4168 | case ST_ADM_ACTION_STOP: |
| 4169 | case ST_ADM_ACTION_START: |
| 4170 | if (action == ST_ADM_ACTION_START) |
| 4171 | sv->uweight = sv->iweight; |
| 4172 | else |
| 4173 | sv->uweight = 0; |
| 4174 | |
| 4175 | server_recalc_eweight(sv); |
| 4176 | set_server_drain_state(sv); |
| 4177 | |
| 4178 | altered_servers++; |
| 4179 | total_servers++; |
| 4180 | break; |
| 4181 | case ST_ADM_ACTION_SHUTDOWN: |
| 4182 | if (px->state != PR_STSTOPPED) { |
| 4183 | struct session *sess, *sess_bck; |
| 4184 | |
| 4185 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4186 | if (sess->srv_conn == sv) |
| 4187 | session_shutdown(sess, SN_ERR_KILLED); |
| 4188 | |
| 4189 | altered_servers++; |
| 4190 | total_servers++; |
| 4191 | } |
| 4192 | break; |
| 4193 | } |
| 4194 | } else { |
| 4195 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4196 | total_servers++; |
| 4197 | } |
| 4198 | } |
| 4199 | if (reprocess && px && action) { |
| 4200 | /* Now, we know the backend and the action chosen by the user. |
| 4201 | * We can safely restart from the first server parameter |
| 4202 | * to reprocess them |
| 4203 | */ |
| 4204 | cur_param = st_cur_param; |
| 4205 | next_param = st_next_param; |
| 4206 | reprocess = 0; |
| 4207 | goto reprocess_servers; |
| 4208 | } |
| 4209 | |
| 4210 | next_param = cur_param; |
| 4211 | } |
| 4212 | } |
| 4213 | |
| 4214 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4215 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4216 | } |
| 4217 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4218 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4219 | } |
| 4220 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4221 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4222 | } |
| 4223 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4224 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4225 | } |
| 4226 | out: |
| 4227 | return 1; |
| 4228 | } |
| 4229 | |
| 4230 | |
| 4231 | static int stats_send_http_headers(struct stream_interface *si) |
| 4232 | { |
| 4233 | struct session *s = session_from_task(si->owner); |
| 4234 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4235 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4236 | |
| 4237 | chunk_printf(&trash, |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4238 | "HTTP/1.0 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4239 | "Cache-Control: no-cache\r\n" |
| 4240 | "Connection: close\r\n" |
| 4241 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4242 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4243 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4244 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4245 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4246 | uri->refresh); |
| 4247 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4248 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4249 | |
| 4250 | s->txn.status = 200; |
| 4251 | s->logs.tv_request = now; |
| 4252 | |
| 4253 | if (bi_putchk(si->ib, &trash) == -1) |
| 4254 | return 0; |
| 4255 | |
| 4256 | return 1; |
| 4257 | } |
| 4258 | |
| 4259 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4260 | { |
| 4261 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4262 | struct session *s = session_from_task(si->owner); |
| 4263 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4264 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4265 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4266 | /* 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] | 4267 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4268 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4269 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4270 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4271 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | /* We don't want to land on the posted stats page because a refresh will |
| 4275 | * repost the data. We don't want this to happen on accident so we redirect |
| 4276 | * the browse to the stats page with a GET. |
| 4277 | */ |
| 4278 | chunk_printf(&trash, |
| 4279 | "HTTP/1.1 303 See Other\r\n" |
| 4280 | "Cache-Control: no-cache\r\n" |
| 4281 | "Content-Type: text/plain\r\n" |
| 4282 | "Connection: close\r\n" |
| 4283 | "Location: %s;st=%s%s%s%s\r\n" |
| 4284 | "\r\n", |
| 4285 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4286 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4287 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4288 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4289 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4290 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4291 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4292 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4293 | scope_txt); |
| 4294 | |
| 4295 | s->txn.status = 303; |
| 4296 | s->logs.tv_request = now; |
| 4297 | |
| 4298 | if (bi_putchk(si->ib, &trash) == -1) |
| 4299 | return 0; |
| 4300 | |
| 4301 | return 1; |
| 4302 | } |
| 4303 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4304 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4305 | * 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] | 4306 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4307 | * automatically unregisters itself once transfer is complete. |
| 4308 | */ |
| 4309 | static void http_stats_io_handler(struct stream_interface *si) |
| 4310 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4311 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4312 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4313 | struct channel *req = si->ob; |
| 4314 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4315 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4316 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4317 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4318 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4319 | /* check that the output is not closed */ |
| 4320 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4321 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4322 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4323 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4324 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4325 | if (stats_send_http_headers(si)) { |
| 4326 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4327 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4328 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4329 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4330 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4331 | } |
| 4332 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4333 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4334 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4335 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4336 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4337 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4338 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4339 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4340 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4341 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4342 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4343 | } |
| 4344 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4345 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4346 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4347 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4348 | } |
| 4349 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4350 | if (appctx->st0 == STAT_HTTP_DONE) |
| 4351 | si_shutw(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4352 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4353 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4354 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4355 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4356 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4357 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4358 | si_shutr(si); |
| 4359 | res->flags |= CF_READ_NULL; |
| 4360 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4361 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4362 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4363 | /* update all other flags and resync with the other side */ |
| 4364 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4365 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4366 | /* we don't want to expire timeouts while we're processing requests */ |
| 4367 | si->ib->rex = TICK_ETERNITY; |
| 4368 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4369 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4370 | out: |
| 4371 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4372 | /* check that we have released everything then unregister */ |
| 4373 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4374 | } |
| 4375 | } |
| 4376 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4377 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4378 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4379 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4380 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4381 | return "NONE"; |
| 4382 | return conn->ctrl->name; |
| 4383 | } |
| 4384 | |
| 4385 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4386 | { |
| 4387 | static char ptr[17]; |
| 4388 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4389 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4390 | return "NONE"; |
| 4391 | |
| 4392 | if (conn->xprt == &raw_sock) |
| 4393 | return "RAW"; |
| 4394 | |
| 4395 | #ifdef USE_OPENSSL |
| 4396 | if (conn->xprt == &ssl_sock) |
| 4397 | return "SSL"; |
| 4398 | #endif |
| 4399 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4400 | return ptr; |
| 4401 | } |
| 4402 | |
| 4403 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4404 | { |
| 4405 | static char ptr[17]; |
| 4406 | |
| 4407 | if (!conn->data) |
| 4408 | return "NONE"; |
| 4409 | |
| 4410 | if (conn->data == &sess_conn_cb) |
| 4411 | return "SESS"; |
| 4412 | |
| 4413 | if (conn->data == &si_conn_cb) |
| 4414 | return "STRM"; |
| 4415 | |
| 4416 | if (conn->data == &check_conn_cb) |
| 4417 | return "CHCK"; |
| 4418 | |
| 4419 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4420 | return ptr; |
| 4421 | } |
| 4422 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4423 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4424 | * 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] | 4425 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4426 | * 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] | 4427 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4428 | 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] | 4429 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4430 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4431 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4432 | extern const char *monthname[12]; |
| 4433 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4434 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4435 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4436 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4437 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4438 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4439 | 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] | 4440 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4441 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4442 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4443 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4444 | appctx->ctx.sess.uid = 0; |
| 4445 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4446 | return 1; |
| 4447 | } |
| 4448 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4449 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4450 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4451 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4452 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4453 | /* fall through */ |
| 4454 | |
| 4455 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4456 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4457 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4458 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4459 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4460 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4461 | 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] | 4462 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 4463 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4464 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4465 | conn = objt_conn(sess->si[0].end); |
| 4466 | 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] | 4467 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4468 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4469 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4470 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4471 | break; |
| 4472 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4473 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4474 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4475 | default: |
| 4476 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4477 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4478 | break; |
| 4479 | } |
| 4480 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4481 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4482 | " 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] | 4483 | 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] | 4484 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4485 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4486 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4487 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 4488 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 4489 | sess->listener ? sess->listener->luid : 0); |
| 4490 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4491 | if (conn) |
| 4492 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4493 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4494 | 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] | 4495 | case AF_INET: |
| 4496 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4497 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4498 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4499 | break; |
| 4500 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4501 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4502 | break; |
| 4503 | default: |
| 4504 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4505 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4506 | break; |
| 4507 | } |
| 4508 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4509 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4510 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4511 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4512 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4513 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 4514 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4515 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4516 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4517 | conn = objt_conn(sess->si[1].end); |
| 4518 | if (conn) |
| 4519 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4520 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4521 | 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] | 4522 | case AF_INET: |
| 4523 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4524 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4525 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4526 | break; |
| 4527 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4528 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4529 | break; |
| 4530 | default: |
| 4531 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4532 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4533 | break; |
| 4534 | } |
| 4535 | |
| 4536 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4537 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4538 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4539 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 4540 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4541 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4542 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4543 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4544 | if (conn) |
| 4545 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4546 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4547 | 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] | 4548 | case AF_INET: |
| 4549 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4550 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4551 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4552 | break; |
| 4553 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4554 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4555 | break; |
| 4556 | default: |
| 4557 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4558 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4559 | break; |
| 4560 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4561 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4562 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4563 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4564 | sess->task, |
| 4565 | sess->task->state, |
| 4566 | sess->task->nice, sess->task->calls, |
| 4567 | sess->task->expire ? |
| 4568 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4569 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4570 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4571 | task_in_rq(sess->task) ? ", running" : ""); |
| 4572 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4573 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4574 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4575 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4576 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4577 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4578 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4579 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4580 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4581 | |
| 4582 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4583 | " 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] | 4584 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4585 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4586 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4587 | obj_type_name(sess->si[0].end), |
| 4588 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4589 | sess->si[0].exp ? |
| 4590 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4591 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4592 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4593 | sess->si[0].err_type); |
| 4594 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4595 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4596 | " 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] | 4597 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4598 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4599 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4600 | obj_type_name(sess->si[1].end), |
| 4601 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4602 | sess->si[1].exp ? |
| 4603 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4604 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4605 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4606 | sess->si[1].err_type); |
| 4607 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4608 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4609 | chunk_appendf(&trash, |
| 4610 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4611 | conn, |
| 4612 | get_conn_ctrl_name(conn), |
| 4613 | get_conn_xprt_name(conn), |
| 4614 | get_conn_data_name(conn), |
| 4615 | obj_type_name(conn->target), |
| 4616 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4617 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4618 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 4619 | " 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] | 4620 | conn->flags, |
| 4621 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4622 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4623 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4624 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4625 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4626 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 4627 | chunk_appendf(&trash, |
| 4628 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4629 | tmpctx, |
| 4630 | tmpctx->st0, |
| 4631 | tmpctx->st1, |
| 4632 | tmpctx->st2, |
| 4633 | tmpctx->applet->name); |
| 4634 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4635 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4636 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4637 | chunk_appendf(&trash, |
| 4638 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4639 | conn, |
| 4640 | get_conn_ctrl_name(conn), |
| 4641 | get_conn_xprt_name(conn), |
| 4642 | get_conn_data_name(conn), |
| 4643 | obj_type_name(conn->target), |
| 4644 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4645 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4646 | chunk_appendf(&trash, |
| 4647 | " 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] | 4648 | conn->flags, |
| 4649 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4650 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4651 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4652 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4653 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4654 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 4655 | chunk_appendf(&trash, |
| 4656 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4657 | tmpctx, |
| 4658 | tmpctx->st0, |
| 4659 | tmpctx->st1, |
| 4660 | tmpctx->st2, |
| 4661 | tmpctx->applet->name); |
| 4662 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4663 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4664 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4665 | " 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] | 4666 | " an_exp=%s", |
| 4667 | sess->req, |
| 4668 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4669 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4670 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4671 | sess->req->analyse_exp ? |
| 4672 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4673 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4674 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4675 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4676 | " rex=%s", |
| 4677 | sess->req->rex ? |
| 4678 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4679 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4680 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4681 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4682 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4683 | " 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] | 4684 | sess->req->wex ? |
| 4685 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4686 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4687 | sess->req->buf, |
| 4688 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4689 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4690 | sess->txn.req.next, sess->req->buf->i, |
| 4691 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4692 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4693 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4694 | " 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] | 4695 | " an_exp=%s", |
| 4696 | sess->rep, |
| 4697 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4698 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4699 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4700 | sess->rep->analyse_exp ? |
| 4701 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4702 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4703 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4704 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4705 | " rex=%s", |
| 4706 | sess->rep->rex ? |
| 4707 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4708 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4709 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4710 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4711 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4712 | " 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] | 4713 | sess->rep->wex ? |
| 4714 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4715 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4716 | sess->rep->buf, |
| 4717 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4718 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4719 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4720 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4721 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4722 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4723 | return 0; |
| 4724 | |
| 4725 | /* use other states to dump the contents */ |
| 4726 | } |
| 4727 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4728 | appctx->ctx.sess.uid = 0; |
| 4729 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4730 | return 1; |
| 4731 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4732 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4733 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4734 | { |
| 4735 | struct appctx *appctx = __objt_appctx(si->end); |
| 4736 | |
| 4737 | switch (appctx->st2) { |
| 4738 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4739 | |
| 4740 | /* Now, we start the browsing of the references lists. |
| 4741 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 4742 | * avalaible field of this pointer is <list>. It is used with the function |
| 4743 | * pat_list_get_next() for retruning the first avalaible entry |
| 4744 | */ |
| 4745 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 4746 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 4747 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4748 | appctx->st2 = STAT_ST_LIST; |
| 4749 | /* fall through */ |
| 4750 | |
| 4751 | case STAT_ST_LIST: |
| 4752 | while (appctx->ctx.map.ref) { |
| 4753 | |
| 4754 | chunk_reset(&trash); |
| 4755 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4756 | /* Build messages. If the reference is used by another category than |
| 4757 | * the listed categorie, display the information in the massage. |
| 4758 | */ |
| 4759 | if ((appctx->ctx.map.display_flags & PAT_REF_MAP) && |
| 4760 | (appctx->ctx.map.ref->flags & PAT_REF_ACL)) { |
| 4761 | chunk_appendf(&trash, "%s (also used by an ACL)\n", |
| 4762 | appctx->ctx.map.ref->reference); |
| 4763 | } |
| 4764 | else if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 4765 | (appctx->ctx.map.ref->flags & PAT_REF_MAP)) { |
| 4766 | chunk_appendf(&trash, "%s (also used by a map)\n", |
| 4767 | appctx->ctx.map.ref->reference); |
| 4768 | } |
| 4769 | else |
| 4770 | chunk_appendf(&trash, "%s\n", appctx->ctx.map.ref->reference); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4771 | |
| 4772 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4773 | /* let's try again later from this session. We add ourselves into |
| 4774 | * this session's users so that it can remove us upon termination. |
| 4775 | */ |
| 4776 | return 0; |
| 4777 | } |
| 4778 | |
| 4779 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4780 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 4781 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | appctx->st2 = STAT_ST_FIN; |
| 4785 | /* fall through */ |
| 4786 | |
| 4787 | default: |
| 4788 | appctx->st2 = STAT_ST_FIN; |
| 4789 | return 1; |
| 4790 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4791 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4792 | } |
| 4793 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4794 | static int stats_map_lookup(struct stream_interface *si) |
| 4795 | { |
| 4796 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4797 | struct sample sample; |
| 4798 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4799 | int match_method; |
| 4800 | struct sample_storage *smp; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4801 | struct sockaddr_storage addr; |
| 4802 | char s_addr[INET_ADDRSTRLEN]; |
| 4803 | char s_mask[INET_ADDRSTRLEN]; |
| 4804 | char s_addr6[INET6_ADDRSTRLEN]; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4805 | const char *keystr; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4806 | |
| 4807 | switch (appctx->st2) { |
| 4808 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4809 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 4810 | 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] | 4811 | 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] | 4812 | appctx->st2 = STAT_ST_LIST; |
| 4813 | /* fall through */ |
| 4814 | |
| 4815 | case STAT_ST_LIST: |
| 4816 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4817 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4818 | /* initialise chunk to build new message */ |
| 4819 | chunk_reset(&trash); |
| 4820 | |
| 4821 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 4822 | sample.type = SMP_T_STR; |
| 4823 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4824 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 4825 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame^] | 4826 | if (appctx->ctx.map.expr->pat_head->match && |
| 4827 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4828 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 4829 | else |
| 4830 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4831 | |
| 4832 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4833 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 4834 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 4835 | break; |
| 4836 | if (match_method >= PAT_MATCH_NUM) |
| 4837 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 4838 | else |
| 4839 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4840 | |
| 4841 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4842 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4843 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 4844 | chunk_appendf(&trash, ", found=no"); |
| 4845 | else |
| 4846 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | /* Display match and match info */ |
| 4850 | else { |
| 4851 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4852 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 4853 | chunk_appendf(&trash, ", found=yes"); |
| 4854 | else |
| 4855 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4856 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4857 | /* display index mode */ |
| 4858 | if (pat->flags & PAT_F_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4859 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4860 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4861 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4862 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4863 | /* case sensitive */ |
| 4864 | if (pat->flags & PAT_F_IGNORE_CASE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4865 | chunk_appendf(&trash, ", case=insensitive"); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4866 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4867 | chunk_appendf(&trash, ", case=sensitive"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4868 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4869 | /* display source */ |
| 4870 | if (pat->flags & PAT_F_FROM_FILE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4871 | chunk_appendf(&trash, ", src=file"); |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 4872 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4873 | chunk_appendf(&trash, ", src=conf"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4874 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4875 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 4876 | keystr = "key"; |
| 4877 | else |
| 4878 | keystr = "pattern"; |
| 4879 | |
| 4880 | switch (match_method) { |
| 4881 | case PAT_MATCH_STR: |
| 4882 | case PAT_MATCH_BEG: |
| 4883 | case PAT_MATCH_SUB: |
| 4884 | case PAT_MATCH_DIR: |
| 4885 | case PAT_MATCH_DOM: |
| 4886 | case PAT_MATCH_END: |
| 4887 | /* display string */ |
| 4888 | chunk_appendf(&trash, ", %s=\"%s\"", keystr, pat->ptr.str); |
| 4889 | break; |
| 4890 | |
| 4891 | case PAT_MATCH_IP: |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4892 | /* display IPv4/v6 */ |
| 4893 | if (pat->type == SMP_T_IPV4) { |
| 4894 | ((struct sockaddr_in *)&addr)->sin_family = AF_INET; |
| 4895 | memcpy(&((struct sockaddr_in *)&addr)->sin_addr, &pat->val.ipv4.addr, |
| 4896 | sizeof(pat->val.ipv4.addr)); |
| 4897 | if (addr_to_str(&addr, s_addr, INET_ADDRSTRLEN)) { |
| 4898 | memcpy(&((struct sockaddr_in *)&addr)->sin_addr, &pat->val.ipv4.mask, |
| 4899 | sizeof(pat->val.ipv4.mask)); |
| 4900 | if (addr_to_str(&addr, s_mask, INET_ADDRSTRLEN)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4901 | chunk_appendf(&trash, ", %s=\"%s/%s\"", keystr, s_addr, s_mask); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4902 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4903 | } |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4904 | else if (pat->type == SMP_T_IPV6) { |
| 4905 | ((struct sockaddr_in6 *)&addr)->sin6_family = AF_INET6; |
| 4906 | memcpy(&((struct sockaddr_in6 *)&addr)->sin6_addr, &pat->val.ipv6.addr, |
| 4907 | sizeof(pat->val.ipv6.addr)); |
| 4908 | if (addr_to_str(&addr, s_addr6, INET6_ADDRSTRLEN)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4909 | chunk_appendf(&trash, ", %s=\"%s/%d\"", keystr, s_addr6, pat->val.ipv6.mask); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4910 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4911 | break; |
| 4912 | |
| 4913 | case PAT_MATCH_INT: |
Thierry FOURNIER | b4be129 | 2014-01-17 15:14:41 +0100 | [diff] [blame] | 4914 | /* display int */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4915 | chunk_appendf(&trash, ", %s=\"", keystr); |
Thierry FOURNIER | b4be129 | 2014-01-17 15:14:41 +0100 | [diff] [blame] | 4916 | if (pat->val.range.min_set && pat->val.range.max_set && |
| 4917 | pat->val.range.min == pat->val.range.max) { |
| 4918 | chunk_appendf(&trash, "%lld", pat->val.range.min); |
| 4919 | } |
| 4920 | else { |
| 4921 | if (pat->val.range.min_set) |
| 4922 | chunk_appendf(&trash, "is >= %lld", pat->val.range.min); |
| 4923 | if (pat->val.range.min_set && pat->val.range.max_set) |
| 4924 | chunk_appendf(&trash, " and "); |
| 4925 | if (pat->val.range.max_set) |
| 4926 | chunk_appendf(&trash, "is <= %lld", pat->val.range.max); |
| 4927 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4928 | chunk_appendf(&trash, "\""); |
| 4929 | break; |
| 4930 | |
| 4931 | /* Dont display other types. */ |
| 4932 | default: |
| 4933 | break; |
Thierry FOURNIER | b4be129 | 2014-01-17 15:14:41 +0100 | [diff] [blame] | 4934 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4935 | } |
| 4936 | |
| 4937 | /* display return value */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4938 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 4939 | if (!pat || !pat->smp) { |
| 4940 | chunk_appendf(&trash, ", value=nothing"); |
| 4941 | } |
| 4942 | else { |
| 4943 | smp = pat->smp; |
| 4944 | memcpy(&sample.data, &smp->data, sizeof(sample.data)); |
| 4945 | sample.type = smp->type; |
| 4946 | if (sample_casts[sample.type][SMP_T_STR] && |
| 4947 | sample_casts[sample.type][SMP_T_STR](&sample)) |
| 4948 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
| 4949 | sample.data.str.str, smp_to_type[smp->type]); |
| 4950 | else |
| 4951 | chunk_appendf(&trash, ", value=cannot-display, type=\"%s\"", |
| 4952 | smp_to_type[smp->type]); |
| 4953 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4954 | } |
| 4955 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4956 | chunk_appendf(&trash, "\n"); |
| 4957 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4958 | /* display response */ |
| 4959 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4960 | /* let's try again later from this session. We add ourselves into |
| 4961 | * this session's users so that it can remove us upon termination. |
| 4962 | */ |
| 4963 | return 0; |
| 4964 | } |
| 4965 | |
| 4966 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4967 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 4968 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4969 | } |
| 4970 | |
| 4971 | appctx->st2 = STAT_ST_FIN; |
| 4972 | /* fall through */ |
| 4973 | |
| 4974 | default: |
| 4975 | appctx->st2 = STAT_ST_FIN; |
| 4976 | free(appctx->ctx.map.chunk.str); |
| 4977 | return 1; |
| 4978 | } |
| 4979 | } |
| 4980 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4981 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4982 | { |
| 4983 | struct appctx *appctx = __objt_appctx(si->end); |
| 4984 | |
| 4985 | switch (appctx->st2) { |
| 4986 | |
| 4987 | case STAT_ST_INIT: |
| 4988 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4989 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 4990 | struct pat_ref_elt *, list); |
| 4991 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 4992 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4993 | appctx->st2 = STAT_ST_LIST; |
| 4994 | /* fall through */ |
| 4995 | |
| 4996 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4997 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4998 | chunk_reset(&trash); |
| 4999 | |
| 5000 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5001 | if (appctx->ctx.map.elt->sample) |
| 5002 | chunk_appendf(&trash, "%s %s\n", |
| 5003 | appctx->ctx.map.elt->pattern, appctx->ctx.map.elt->sample); |
| 5004 | else |
| 5005 | chunk_appendf(&trash, "%s\n", appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5006 | |
| 5007 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5008 | /* let's try again later from this session. We add ourselves into |
| 5009 | * this session's users so that it can remove us upon termination. |
| 5010 | */ |
| 5011 | return 0; |
| 5012 | } |
| 5013 | |
| 5014 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5015 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5016 | struct pat_ref_elt *, list); |
| 5017 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5018 | break; |
| 5019 | } |
| 5020 | |
| 5021 | appctx->st2 = STAT_ST_FIN; |
| 5022 | /* fall through */ |
| 5023 | |
| 5024 | default: |
| 5025 | appctx->st2 = STAT_ST_FIN; |
| 5026 | return 1; |
| 5027 | } |
| 5028 | } |
| 5029 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5030 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5031 | * 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] | 5032 | * to be called again, otherwise non-zero. It is designed to be called |
| 5033 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5034 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5035 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5036 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5037 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5038 | struct connection *conn; |
| 5039 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5040 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5041 | /* If we're forced to shut down, we might have to remove our |
| 5042 | * reference to the last session being dumped. |
| 5043 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5044 | if (appctx->st2 == STAT_ST_LIST) { |
| 5045 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5046 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5047 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5048 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5049 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5050 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5051 | } |
| 5052 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5053 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5054 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5055 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5056 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5057 | /* the function had not been called yet, let's prepare the |
| 5058 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5059 | * pointer to the first in the global list. When a target |
| 5060 | * session is being destroyed, it is responsible for updating |
| 5061 | * this pointer. We know we have reached the end when this |
| 5062 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5063 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5064 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5065 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5066 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5067 | /* fall through */ |
| 5068 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5069 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5070 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5071 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5072 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5073 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5074 | } |
| 5075 | |
| 5076 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5077 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5078 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5079 | struct session *curr_sess; |
| 5080 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5081 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5082 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5083 | if (appctx->ctx.sess.target) { |
| 5084 | 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] | 5085 | goto next_sess; |
| 5086 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5087 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5088 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5089 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5090 | return 0; |
| 5091 | |
| 5092 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5093 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5094 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5095 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5096 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5097 | break; |
| 5098 | } |
| 5099 | else |
| 5100 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5101 | } |
| 5102 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5103 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5104 | "%p: proto=%s", |
| 5105 | curr_sess, |
| 5106 | curr_sess->listener->proto->name); |
| 5107 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5108 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5109 | conn = objt_conn(curr_sess->si[0].end); |
| 5110 | 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] | 5111 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5112 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5113 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5114 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5115 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5116 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5117 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5118 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5119 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5120 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5121 | break; |
| 5122 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5123 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5124 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5125 | curr_sess->listener->luid, |
| 5126 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5127 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5128 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5129 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5130 | break; |
| 5131 | } |
| 5132 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5133 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5134 | " ts=%02x age=%s calls=%d", |
| 5135 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5136 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5137 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5138 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5139 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5140 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5141 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5142 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5143 | curr_sess->req->analysers, |
| 5144 | curr_sess->req->rex ? |
| 5145 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 5146 | TICKS_TO_MS(1000)) : ""); |
| 5147 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5148 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5149 | ",wx=%s", |
| 5150 | curr_sess->req->wex ? |
| 5151 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 5152 | TICKS_TO_MS(1000)) : ""); |
| 5153 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5154 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5155 | ",ax=%s]", |
| 5156 | curr_sess->req->analyse_exp ? |
| 5157 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 5158 | TICKS_TO_MS(1000)) : ""); |
| 5159 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5160 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5161 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5162 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5163 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5164 | curr_sess->rep->analysers, |
| 5165 | curr_sess->rep->rex ? |
| 5166 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5167 | TICKS_TO_MS(1000)) : ""); |
| 5168 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5169 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5170 | ",wx=%s", |
| 5171 | curr_sess->rep->wex ? |
| 5172 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 5173 | TICKS_TO_MS(1000)) : ""); |
| 5174 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5175 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5176 | ",ax=%s]", |
| 5177 | curr_sess->rep->analyse_exp ? |
| 5178 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5179 | TICKS_TO_MS(1000)) : ""); |
| 5180 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5181 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5182 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5183 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5184 | curr_sess->si[0].state, |
| 5185 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5186 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5187 | curr_sess->si[0].exp ? |
| 5188 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5189 | TICKS_TO_MS(1000)) : ""); |
| 5190 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5191 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5192 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5193 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5194 | curr_sess->si[1].state, |
| 5195 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5196 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5197 | curr_sess->si[1].exp ? |
| 5198 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5199 | TICKS_TO_MS(1000)) : ""); |
| 5200 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5201 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5202 | " exp=%s", |
| 5203 | curr_sess->task->expire ? |
| 5204 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5205 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5206 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5207 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5208 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5209 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5210 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5211 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5212 | /* let's try again later from this session. We add ourselves into |
| 5213 | * this session's users so that it can remove us upon termination. |
| 5214 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5215 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5216 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5217 | } |
| 5218 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5219 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5220 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5221 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5222 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5223 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5224 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5225 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5226 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5227 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5228 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5229 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5230 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5231 | return 0; |
| 5232 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5233 | appctx->ctx.sess.target = NULL; |
| 5234 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5235 | return 1; |
| 5236 | } |
| 5237 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5238 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5239 | /* fall through */ |
| 5240 | |
| 5241 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5242 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5243 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5244 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5245 | } |
| 5246 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5247 | /* This is called when the stream interface is closed. For instance, upon an |
| 5248 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5249 | * remove back references to the session currently being dumped. |
| 5250 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5251 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5252 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5253 | struct appctx *appctx = __objt_appctx(si->end); |
| 5254 | |
| 5255 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5256 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5257 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5258 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5259 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5260 | free(appctx->ctx.map.chunk.str); |
| 5261 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5262 | } |
| 5263 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5264 | /* This function is used to either dump tables states (when action is set |
| 5265 | * 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] | 5266 | * It returns 0 if the output buffer is full and it needs to be called |
| 5267 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5268 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5269 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5270 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5271 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5272 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5273 | struct ebmb_node *eb; |
| 5274 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5275 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5276 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5277 | |
| 5278 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5279 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5280 | * - STAT_ST_INIT : the first call |
| 5281 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5282 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5283 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5284 | * and the entry pointer points to the next entry to be dumped, |
| 5285 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5286 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5287 | * data though. |
| 5288 | */ |
| 5289 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5290 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5291 | /* 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] | 5292 | if (appctx->st2 == STAT_ST_LIST) { |
| 5293 | appctx->ctx.table.entry->ref_cnt--; |
| 5294 | 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] | 5295 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5296 | return 1; |
| 5297 | } |
| 5298 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5299 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5300 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5301 | while (appctx->st2 != STAT_ST_FIN) { |
| 5302 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5303 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5304 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5305 | if (!appctx->ctx.table.proxy) |
| 5306 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5307 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5308 | appctx->ctx.table.entry = NULL; |
| 5309 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5310 | break; |
| 5311 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5312 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5313 | if (!appctx->ctx.table.proxy || |
| 5314 | (appctx->ctx.table.target && |
| 5315 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5316 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5317 | break; |
| 5318 | } |
| 5319 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5320 | if (appctx->ctx.table.proxy->table.size) { |
| 5321 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5322 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5323 | return 0; |
| 5324 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5325 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5326 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5327 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5328 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5329 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5330 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5331 | appctx->ctx.table.entry->ref_cnt++; |
| 5332 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5333 | break; |
| 5334 | } |
| 5335 | } |
| 5336 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5337 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5338 | break; |
| 5339 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5340 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5341 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5342 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5343 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5344 | /* we're filtering on some data contents */ |
| 5345 | void *ptr; |
| 5346 | long long data; |
| 5347 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5348 | dt = appctx->ctx.table.data_type; |
| 5349 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5350 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5351 | dt); |
| 5352 | |
| 5353 | data = 0; |
| 5354 | switch (stktable_data_types[dt].std_type) { |
| 5355 | case STD_T_SINT: |
| 5356 | data = stktable_data_cast(ptr, std_t_sint); |
| 5357 | break; |
| 5358 | case STD_T_UINT: |
| 5359 | data = stktable_data_cast(ptr, std_t_uint); |
| 5360 | break; |
| 5361 | case STD_T_ULL: |
| 5362 | data = stktable_data_cast(ptr, std_t_ull); |
| 5363 | break; |
| 5364 | case STD_T_FRQP: |
| 5365 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5366 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5367 | break; |
| 5368 | } |
| 5369 | |
| 5370 | /* 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] | 5371 | if ((data < appctx->ctx.table.value && |
| 5372 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5373 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5374 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5375 | (data == appctx->ctx.table.value && |
| 5376 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5377 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5378 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5379 | (data > appctx->ctx.table.value && |
| 5380 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5381 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5382 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5383 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5384 | } |
| 5385 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5386 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5387 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5388 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5389 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5390 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5391 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5392 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5393 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5394 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5395 | struct stksess *old = appctx->ctx.table.entry; |
| 5396 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5397 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5398 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5399 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5400 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5401 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5402 | break; |
| 5403 | } |
| 5404 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5405 | |
| 5406 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5407 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5408 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5409 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5410 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5411 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5412 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5413 | break; |
| 5414 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5415 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5416 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5417 | break; |
| 5418 | } |
| 5419 | } |
| 5420 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5421 | } |
| 5422 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5423 | /* 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] | 5424 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5425 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5426 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5427 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5428 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5429 | * after the offset. The new pointer is returned. |
| 5430 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5431 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5432 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5433 | { |
| 5434 | int end; |
| 5435 | unsigned char c; |
| 5436 | |
| 5437 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5438 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5439 | return ptr; |
| 5440 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5441 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5442 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5443 | while (ptr < len && ptr < bsize) { |
| 5444 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5445 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5446 | if (out->len > end - 2) |
| 5447 | break; |
| 5448 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5449 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5450 | if (out->len > end - 3) |
| 5451 | break; |
| 5452 | out->str[out->len++] = '\\'; |
| 5453 | switch (c) { |
| 5454 | case '\t': c = 't'; break; |
| 5455 | case '\n': c = 'n'; break; |
| 5456 | case '\r': c = 'r'; break; |
| 5457 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5458 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5459 | } |
| 5460 | out->str[out->len++] = c; |
| 5461 | } else { |
| 5462 | if (out->len > end - 5) |
| 5463 | break; |
| 5464 | out->str[out->len++] = '\\'; |
| 5465 | out->str[out->len++] = 'x'; |
| 5466 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5467 | out->str[out->len++] = hextab[c & 0xF]; |
| 5468 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5469 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5470 | /* we had a line break, let's return now */ |
| 5471 | out->str[out->len++] = '\n'; |
| 5472 | *line = ptr; |
| 5473 | return ptr; |
| 5474 | } |
| 5475 | } |
| 5476 | /* we have an incomplete line, we return it as-is */ |
| 5477 | out->str[out->len++] = '\n'; |
| 5478 | return ptr; |
| 5479 | } |
| 5480 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5481 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5482 | * 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] | 5483 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5484 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5485 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5486 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5487 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5488 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5489 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5490 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5491 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5492 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5493 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5494 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5495 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5496 | /* the function had not been called yet, let's prepare the |
| 5497 | * buffer for a response. |
| 5498 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5499 | struct tm tm; |
| 5500 | |
| 5501 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5502 | 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] | 5503 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5504 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5505 | error_snapshot_id); |
| 5506 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5507 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5508 | /* Socket buffer full. Let's try again later from the same point */ |
| 5509 | return 0; |
| 5510 | } |
| 5511 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5512 | appctx->ctx.errors.px = proxy; |
| 5513 | appctx->ctx.errors.buf = 0; |
| 5514 | appctx->ctx.errors.bol = 0; |
| 5515 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | /* we have two inner loops here, one for the proxy, the other one for |
| 5519 | * the buffer. |
| 5520 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5521 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5522 | struct error_snapshot *es; |
| 5523 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5524 | if (appctx->ctx.errors.buf == 0) |
| 5525 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5526 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5527 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5528 | |
| 5529 | if (!es->when.tv_sec) |
| 5530 | goto next; |
| 5531 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5532 | if (appctx->ctx.errors.iid >= 0 && |
| 5533 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 5534 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5535 | goto next; |
| 5536 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5537 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5538 | /* just print headers now */ |
| 5539 | |
| 5540 | char pn[INET6_ADDRSTRLEN]; |
| 5541 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5542 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5543 | |
| 5544 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5545 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5546 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5547 | 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] | 5548 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5549 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 5550 | case AF_INET: |
| 5551 | case AF_INET6: |
| 5552 | port = get_host_port(&es->src); |
| 5553 | break; |
| 5554 | default: |
| 5555 | port = 0; |
| 5556 | } |
| 5557 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5558 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5559 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5560 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5561 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5562 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5563 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5564 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 5565 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5566 | break; |
| 5567 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5568 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5569 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5570 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5571 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5572 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5573 | break; |
| 5574 | } |
| 5575 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5576 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5577 | ", server %s (#%d), event #%u\n" |
| 5578 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 5579 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 5580 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 5581 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 5582 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 5583 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 5584 | es->ev_id, |
| 5585 | pn, port, es->sid, es->s_flags, |
| 5586 | es->state, es->m_flags, es->t_flags, |
| 5587 | es->m_clen, es->m_blen, |
| 5588 | es->b_flags, es->b_out, es->b_tot, |
| 5589 | es->len, es->b_wrap, es->pos); |
| 5590 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5591 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5592 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5593 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5594 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5595 | appctx->ctx.errors.ptr = 0; |
| 5596 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5597 | } |
| 5598 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5599 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5600 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5601 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5602 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5603 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5604 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5605 | goto next; |
| 5606 | } |
| 5607 | |
| 5608 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5609 | 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] | 5610 | int newptr; |
| 5611 | int newline; |
| 5612 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5613 | newline = appctx->ctx.errors.bol; |
| 5614 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 5615 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5616 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5617 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5618 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5619 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5620 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5621 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5622 | appctx->ctx.errors.ptr = newptr; |
| 5623 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5624 | }; |
| 5625 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5626 | appctx->ctx.errors.bol = 0; |
| 5627 | appctx->ctx.errors.ptr = -1; |
| 5628 | appctx->ctx.errors.buf++; |
| 5629 | if (appctx->ctx.errors.buf > 1) { |
| 5630 | appctx->ctx.errors.buf = 0; |
| 5631 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5632 | } |
| 5633 | } |
| 5634 | |
| 5635 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5636 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5637 | } |
| 5638 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5639 | /* parse the "level" argument on the bind lines */ |
| 5640 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 5641 | { |
| 5642 | if (!*args[cur_arg + 1]) { |
| 5643 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 5644 | return ERR_ALERT | ERR_FATAL; |
| 5645 | } |
| 5646 | |
| 5647 | if (!strcmp(args[cur_arg+1], "user")) |
| 5648 | conf->level = ACCESS_LVL_USER; |
| 5649 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 5650 | conf->level = ACCESS_LVL_OPER; |
| 5651 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 5652 | conf->level = ACCESS_LVL_ADMIN; |
| 5653 | else { |
| 5654 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 5655 | args[cur_arg], args[cur_arg+1]); |
| 5656 | return ERR_ALERT | ERR_FATAL; |
| 5657 | } |
| 5658 | |
| 5659 | return 0; |
| 5660 | } |
| 5661 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5662 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5663 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5664 | .name = "<STATS>", /* used for logging */ |
| 5665 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 5666 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5667 | }; |
| 5668 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5669 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5670 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5671 | .name = "<CLI>", /* used for logging */ |
| 5672 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5673 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5674 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5675 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 5676 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5677 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 5678 | { 0, NULL, NULL }, |
| 5679 | }}; |
| 5680 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5681 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 5682 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 5683 | { NULL, NULL, 0 }, |
| 5684 | }}; |
| 5685 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5686 | __attribute__((constructor)) |
| 5687 | static void __dumpstats_module_init(void) |
| 5688 | { |
| 5689 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5690 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5691 | } |
| 5692 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5693 | /* |
| 5694 | * Local variables: |
| 5695 | * c-indent-level: 8 |
| 5696 | * c-basic-offset: 8 |
| 5697 | * End: |
| 5698 | */ |