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 | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 985 | static inline |
| 986 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 987 | { |
| 988 | int id; |
| 989 | char *error; |
| 990 | |
| 991 | /* If the reference starts by a '#', this is numeric id. */ |
| 992 | if (reference[0] == '#') { |
| 993 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 994 | id = strtol(reference + 1, &error, 10); |
| 995 | if (*error != '\0') |
| 996 | return NULL; |
| 997 | |
| 998 | /* Perform the unique id lookup. */ |
| 999 | return pat_ref_lookupid(id); |
| 1000 | } |
| 1001 | |
| 1002 | /* Perform the string lookup. */ |
| 1003 | return pat_ref_lookup(reference); |
| 1004 | } |
| 1005 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1006 | /* This function is used with map and acl management. It permits to browse |
| 1007 | * each reference. |
| 1008 | */ |
| 1009 | static inline |
| 1010 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1011 | { |
| 1012 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1013 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1014 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1015 | return NULL; |
| 1016 | return expr; |
| 1017 | } |
| 1018 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1019 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1020 | * called from an applet running in a stream interface. The function returns 1 |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1021 | * if the request was understood, otherwise zero. It sets appctx->st0 to a value |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1022 | * designating the function which will have to process the request, which can |
| 1023 | * also be the print function to display the return message set into cli.msg. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1024 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1025 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1026 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 1027 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1028 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1029 | char *args[MAX_STATS_ARGS + 1]; |
| 1030 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1031 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1032 | |
| 1033 | while (isspace((unsigned char)*line)) |
| 1034 | line++; |
| 1035 | |
| 1036 | arg = 0; |
| 1037 | args[arg] = line; |
| 1038 | |
| 1039 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1040 | if (*line == '\\') { |
| 1041 | line++; |
| 1042 | if (*line == '\0') |
| 1043 | break; |
| 1044 | } |
| 1045 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1046 | *line++ = '\0'; |
| 1047 | |
| 1048 | while (isspace((unsigned char)*line)) |
| 1049 | line++; |
| 1050 | |
| 1051 | args[++arg] = line; |
| 1052 | continue; |
| 1053 | } |
| 1054 | |
| 1055 | line++; |
| 1056 | } |
| 1057 | |
| 1058 | while (++arg <= MAX_STATS_ARGS) |
| 1059 | args[arg] = line; |
| 1060 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1061 | /* remove \ */ |
| 1062 | arg = 0; |
| 1063 | while (*args[arg] != '\0') { |
| 1064 | j = 0; |
| 1065 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1066 | if (args[arg][i] == '\\') |
| 1067 | continue; |
| 1068 | args[arg][j] = args[arg][i]; |
| 1069 | j++; |
| 1070 | } |
| 1071 | args[arg][j] = '\0'; |
| 1072 | arg++; |
| 1073 | } |
| 1074 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1075 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1076 | if (strcmp(args[0], "show") == 0) { |
| 1077 | if (strcmp(args[1], "stat") == 0) { |
| 1078 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1079 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1080 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1081 | appctx->ctx.stats.type = atoi(args[3]); |
| 1082 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1083 | } |
| 1084 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1085 | appctx->st2 = STAT_ST_INIT; |
| 1086 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1087 | } |
| 1088 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1089 | appctx->st2 = STAT_ST_INIT; |
| 1090 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1091 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1092 | else if (strcmp(args[1], "pools") == 0) { |
| 1093 | appctx->st2 = STAT_ST_INIT; |
| 1094 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1095 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1096 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1097 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1098 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1099 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1100 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1101 | return 1; |
| 1102 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1103 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1104 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1105 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1106 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1107 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1108 | appctx->ctx.sess.target = NULL; |
| 1109 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1110 | appctx->ctx.sess.pos = 0; |
| 1111 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1112 | } |
| 1113 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1114 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1115 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1116 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1117 | return 1; |
| 1118 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1119 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1120 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1121 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1122 | appctx->ctx.errors.iid = -1; |
| 1123 | appctx->ctx.errors.px = NULL; |
| 1124 | appctx->st2 = STAT_ST_INIT; |
| 1125 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1126 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1127 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1128 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1129 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1130 | else if (strcmp(args[1], "map") == 0 || |
| 1131 | strcmp(args[1], "acl") == 0) { |
| 1132 | |
| 1133 | /* Set ACL or MAP flags. */ |
| 1134 | if (args[1][0] == 'm') |
| 1135 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1136 | else |
| 1137 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1138 | |
| 1139 | /* no parameter: display all map avalaible */ |
| 1140 | if (!*args[2]) { |
| 1141 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1142 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1143 | return 1; |
| 1144 | } |
| 1145 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1146 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1147 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1148 | if (!appctx->ctx.map.ref || |
| 1149 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1150 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1151 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <name>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1152 | else |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1153 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1154 | appctx->st0 = STAT_CLI_PRINT; |
| 1155 | return 1; |
| 1156 | } |
| 1157 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1158 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1159 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1160 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1161 | return 0; |
| 1162 | } |
| 1163 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1164 | else if (strcmp(args[0], "clear") == 0) { |
| 1165 | if (strcmp(args[1], "counters") == 0) { |
| 1166 | struct proxy *px; |
| 1167 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1168 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1169 | int clrall = 0; |
| 1170 | |
| 1171 | if (strcmp(args[2], "all") == 0) |
| 1172 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1173 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1174 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1175 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1176 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1177 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1178 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1179 | return 1; |
| 1180 | } |
| 1181 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1182 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1183 | if (clrall) { |
| 1184 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1185 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1186 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1187 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1188 | px->be_counters.conn_max = 0; |
| 1189 | px->be_counters.p.http.rps_max = 0; |
| 1190 | px->be_counters.sps_max = 0; |
| 1191 | px->be_counters.cps_max = 0; |
| 1192 | px->be_counters.nbpend_max = 0; |
| 1193 | |
| 1194 | px->fe_counters.conn_max = 0; |
| 1195 | px->fe_counters.p.http.rps_max = 0; |
| 1196 | px->fe_counters.sps_max = 0; |
| 1197 | px->fe_counters.cps_max = 0; |
| 1198 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1199 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1200 | |
| 1201 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1202 | if (clrall) |
| 1203 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1204 | else { |
| 1205 | sv->counters.cur_sess_max = 0; |
| 1206 | sv->counters.nbpend_max = 0; |
| 1207 | sv->counters.sps_max = 0; |
| 1208 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1209 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1210 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1211 | if (li->counters) { |
| 1212 | if (clrall) |
| 1213 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1214 | else |
| 1215 | li->counters->conn_max = 0; |
| 1216 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1217 | } |
| 1218 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1219 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1220 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1221 | return 1; |
| 1222 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1223 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1224 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1225 | /* end of processing */ |
| 1226 | return 1; |
| 1227 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1228 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1229 | /* Set ACL or MAP flags. */ |
| 1230 | if (args[1][0] == 'm') |
| 1231 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1232 | else |
| 1233 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1234 | |
| 1235 | /* no parameter */ |
| 1236 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1237 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1238 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1239 | else |
| 1240 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1241 | appctx->st0 = STAT_CLI_PRINT; |
| 1242 | return 1; |
| 1243 | } |
| 1244 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1245 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1246 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1247 | if (!appctx->ctx.map.ref || |
| 1248 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1249 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1250 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <name>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1251 | else |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1252 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1253 | appctx->st0 = STAT_CLI_PRINT; |
| 1254 | return 1; |
| 1255 | } |
| 1256 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1257 | /* Clear all. */ |
| 1258 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1259 | |
| 1260 | /* return response */ |
| 1261 | appctx->ctx.cli.msg = "Done.\n"; |
| 1262 | appctx->st0 = STAT_CLI_PRINT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1263 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1264 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1265 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1266 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1267 | return 0; |
| 1268 | } |
| 1269 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1270 | else if (strcmp(args[0], "get") == 0) { |
| 1271 | if (strcmp(args[1], "weight") == 0) { |
| 1272 | struct proxy *px; |
| 1273 | struct server *sv; |
| 1274 | |
| 1275 | /* split "backend/server" and make <line> point to server */ |
| 1276 | for (line = args[2]; *line; line++) |
| 1277 | if (*line == '/') { |
| 1278 | *line++ = '\0'; |
| 1279 | break; |
| 1280 | } |
| 1281 | |
| 1282 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1283 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1284 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1285 | return 1; |
| 1286 | } |
| 1287 | |
| 1288 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1289 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1290 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1291 | return 1; |
| 1292 | } |
| 1293 | |
| 1294 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1295 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1296 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1297 | return 1; |
| 1298 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1299 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1300 | /* Set flags. */ |
| 1301 | if (args[1][0] == 'm') |
| 1302 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1303 | else |
| 1304 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1305 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1306 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1307 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1308 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1309 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1310 | else |
| 1311 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1312 | appctx->st0 = STAT_CLI_PRINT; |
| 1313 | return 1; |
| 1314 | } |
| 1315 | |
| 1316 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1317 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1318 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1319 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1320 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <name>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1321 | else |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1322 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1323 | appctx->st0 = STAT_CLI_PRINT; |
| 1324 | return 1; |
| 1325 | } |
| 1326 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1327 | /* copy input string. The string must be allocated because |
| 1328 | * it may be used over multiple iterations. It's released |
| 1329 | * at the end and upon abort anyway. |
| 1330 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1331 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1332 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1333 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1334 | if (!appctx->ctx.map.chunk.str) { |
| 1335 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1336 | appctx->st0 = STAT_CLI_PRINT; |
| 1337 | return 1; |
| 1338 | } |
| 1339 | |
| 1340 | /* prepare response */ |
| 1341 | appctx->st2 = STAT_ST_INIT; |
| 1342 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1343 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1344 | else { /* not "get weight" */ |
| 1345 | return 0; |
| 1346 | } |
| 1347 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1348 | else if (strcmp(args[0], "set") == 0) { |
| 1349 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1350 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1351 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1352 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1353 | sv = expect_server_admin(s, si, args[2]); |
| 1354 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1355 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1356 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1357 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1358 | /* |
| 1359 | * The user-weight may now be zero and thus |
| 1360 | * the server considered to be draining. |
| 1361 | * Update the server's drain state as necessary. |
| 1362 | */ |
| 1363 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1364 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1365 | appctx->ctx.cli.msg = warning; |
| 1366 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1367 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1368 | return 1; |
| 1369 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1370 | else if (strcmp(args[1], "timeout") == 0) { |
| 1371 | if (strcmp(args[2], "cli") == 0) { |
| 1372 | unsigned timeout; |
| 1373 | const char *res; |
| 1374 | |
| 1375 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1376 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1377 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1378 | return 1; |
| 1379 | } |
| 1380 | |
| 1381 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1382 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1383 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1384 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1385 | return 1; |
| 1386 | } |
| 1387 | |
| 1388 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1389 | return 1; |
| 1390 | } |
| 1391 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1392 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1393 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1394 | return 1; |
| 1395 | } |
| 1396 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1397 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1398 | if (strcmp(args[2], "frontend") == 0) { |
| 1399 | struct proxy *px; |
| 1400 | struct listener *l; |
| 1401 | int v; |
| 1402 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1403 | px = expect_frontend_admin(s, si, args[3]); |
| 1404 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1405 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1406 | |
| 1407 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1408 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1409 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1410 | return 1; |
| 1411 | } |
| 1412 | |
| 1413 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1414 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1415 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1416 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1417 | return 1; |
| 1418 | } |
| 1419 | |
| 1420 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1421 | * its listeners. The blocked ones will be dequeued. |
| 1422 | */ |
| 1423 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1424 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1425 | l->maxconn = v; |
| 1426 | if (l->state == LI_FULL) |
| 1427 | resume_listener(l); |
| 1428 | } |
| 1429 | |
| 1430 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1431 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1432 | |
| 1433 | return 1; |
| 1434 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1435 | else if (strcmp(args[2], "global") == 0) { |
| 1436 | int v; |
| 1437 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1438 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1439 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1440 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1441 | return 1; |
| 1442 | } |
| 1443 | |
| 1444 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1445 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1446 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1447 | return 1; |
| 1448 | } |
| 1449 | |
| 1450 | v = atoi(args[3]); |
| 1451 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1452 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1453 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1454 | return 1; |
| 1455 | } |
| 1456 | |
| 1457 | /* check for unlimited values */ |
| 1458 | if (v <= 0) |
| 1459 | v = global.hardmaxconn; |
| 1460 | |
| 1461 | global.maxconn = v; |
| 1462 | |
| 1463 | /* Dequeues all of the listeners waiting for a resource */ |
| 1464 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1465 | dequeue_all_listeners(&global_listener_queue); |
| 1466 | |
| 1467 | return 1; |
| 1468 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1469 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1470 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1471 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1472 | return 1; |
| 1473 | } |
| 1474 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1475 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1476 | if (strcmp(args[2], "connections") == 0) { |
| 1477 | if (strcmp(args[3], "global") == 0) { |
| 1478 | int v; |
| 1479 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1480 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1481 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1482 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1483 | return 1; |
| 1484 | } |
| 1485 | |
| 1486 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1487 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1488 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1489 | return 1; |
| 1490 | } |
| 1491 | |
| 1492 | v = atoi(args[4]); |
| 1493 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1494 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1495 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1496 | return 1; |
| 1497 | } |
| 1498 | |
| 1499 | global.cps_lim = v; |
| 1500 | |
| 1501 | /* Dequeues all of the listeners waiting for a resource */ |
| 1502 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1503 | dequeue_all_listeners(&global_listener_queue); |
| 1504 | |
| 1505 | return 1; |
| 1506 | } |
| 1507 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1508 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1509 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1510 | return 1; |
| 1511 | } |
| 1512 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1513 | else if (strcmp(args[2], "sessions") == 0) { |
| 1514 | if (strcmp(args[3], "global") == 0) { |
| 1515 | int v; |
| 1516 | |
| 1517 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1518 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1519 | appctx->st0 = STAT_CLI_PRINT; |
| 1520 | return 1; |
| 1521 | } |
| 1522 | |
| 1523 | if (!*args[4]) { |
| 1524 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1525 | appctx->st0 = STAT_CLI_PRINT; |
| 1526 | return 1; |
| 1527 | } |
| 1528 | |
| 1529 | v = atoi(args[4]); |
| 1530 | if (v < 0) { |
| 1531 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1532 | appctx->st0 = STAT_CLI_PRINT; |
| 1533 | return 1; |
| 1534 | } |
| 1535 | |
| 1536 | global.sps_lim = v; |
| 1537 | |
| 1538 | /* Dequeues all of the listeners waiting for a resource */ |
| 1539 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1540 | dequeue_all_listeners(&global_listener_queue); |
| 1541 | |
| 1542 | return 1; |
| 1543 | } |
| 1544 | else { |
| 1545 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1546 | appctx->st0 = STAT_CLI_PRINT; |
| 1547 | return 1; |
| 1548 | } |
| 1549 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1550 | #ifdef USE_OPENSSL |
| 1551 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1552 | if (strcmp(args[3], "global") == 0) { |
| 1553 | int v; |
| 1554 | |
| 1555 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1556 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1557 | appctx->st0 = STAT_CLI_PRINT; |
| 1558 | return 1; |
| 1559 | } |
| 1560 | |
| 1561 | if (!*args[4]) { |
| 1562 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1563 | appctx->st0 = STAT_CLI_PRINT; |
| 1564 | return 1; |
| 1565 | } |
| 1566 | |
| 1567 | v = atoi(args[4]); |
| 1568 | if (v < 0) { |
| 1569 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1570 | appctx->st0 = STAT_CLI_PRINT; |
| 1571 | return 1; |
| 1572 | } |
| 1573 | |
| 1574 | global.ssl_lim = v; |
| 1575 | |
| 1576 | /* Dequeues all of the listeners waiting for a resource */ |
| 1577 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1578 | dequeue_all_listeners(&global_listener_queue); |
| 1579 | |
| 1580 | return 1; |
| 1581 | } |
| 1582 | else { |
| 1583 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1584 | appctx->st0 = STAT_CLI_PRINT; |
| 1585 | return 1; |
| 1586 | } |
| 1587 | } |
| 1588 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1589 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1590 | if (strcmp(args[3], "global") == 0) { |
| 1591 | int v; |
| 1592 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1593 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1594 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1595 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1596 | return 1; |
| 1597 | } |
| 1598 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1599 | v = atoi(args[4]); |
| 1600 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1601 | } |
| 1602 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1603 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1604 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1605 | return 1; |
| 1606 | } |
| 1607 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1608 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1609 | 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] | 1610 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1611 | return 1; |
| 1612 | } |
| 1613 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1614 | else if (strcmp(args[1], "table") == 0) { |
| 1615 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1616 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1617 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1618 | /* Set flags. */ |
| 1619 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1620 | |
| 1621 | /* Expect three parameters: map name, key and new value. */ |
| 1622 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1623 | 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] | 1624 | appctx->st0 = STAT_CLI_PRINT; |
| 1625 | return 1; |
| 1626 | } |
| 1627 | |
| 1628 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1629 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1630 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1631 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1632 | appctx->st0 = STAT_CLI_PRINT; |
| 1633 | return 1; |
| 1634 | } |
| 1635 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1636 | /* Update the value. */ |
| 1637 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4])) { |
| 1638 | appctx->ctx.cli.msg = "Pattern not found.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1639 | appctx->st0 = STAT_CLI_PRINT; |
| 1640 | return 1; |
| 1641 | } |
| 1642 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1643 | /* The set is done, send message. */ |
| 1644 | appctx->ctx.cli.msg = "Done.\n"; |
| 1645 | appctx->st0 = STAT_CLI_PRINT; |
| 1646 | return 1; |
| 1647 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1648 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1649 | return 0; |
| 1650 | } |
| 1651 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1652 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1653 | if (strcmp(args[1], "agent") == 0) { |
| 1654 | struct server *sv; |
| 1655 | |
| 1656 | sv = expect_server_admin(s, si, args[2]); |
| 1657 | if (!sv) |
| 1658 | return 1; |
| 1659 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1660 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1661 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1662 | appctx->st0 = STAT_CLI_PRINT; |
| 1663 | return 1; |
| 1664 | } |
| 1665 | |
| 1666 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1667 | return 1; |
| 1668 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1669 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1670 | struct server *sv; |
| 1671 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1672 | sv = expect_server_admin(s, si, args[2]); |
| 1673 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1674 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1675 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1676 | if (sv->state & SRV_MAINTAIN) { |
| 1677 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1678 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1679 | /* If this server tracks the status of another one, |
| 1680 | * we must restore the good status. |
| 1681 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1682 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1683 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1684 | 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] | 1685 | } else { |
| 1686 | sv->state &= ~SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1687 | sv->check.state &= ~CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1688 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1689 | } |
| 1690 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1691 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1692 | 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] | 1693 | } |
| 1694 | } |
| 1695 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1696 | return 1; |
| 1697 | } |
| 1698 | else if (strcmp(args[1], "frontend") == 0) { |
| 1699 | struct proxy *px; |
| 1700 | |
| 1701 | px = expect_frontend_admin(s, si, args[2]); |
| 1702 | if (!px) |
| 1703 | return 1; |
| 1704 | |
| 1705 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1706 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1707 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1708 | return 1; |
| 1709 | } |
| 1710 | |
| 1711 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1712 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1713 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1714 | return 1; |
| 1715 | } |
| 1716 | |
| 1717 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1718 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1719 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1720 | return 1; |
| 1721 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1722 | return 1; |
| 1723 | } |
| 1724 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1725 | appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1726 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1727 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1728 | } |
| 1729 | } |
| 1730 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1731 | if (strcmp(args[1], "agent") == 0) { |
| 1732 | struct server *sv; |
| 1733 | |
| 1734 | sv = expect_server_admin(s, si, args[2]); |
| 1735 | if (!sv) |
| 1736 | return 1; |
| 1737 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1738 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1739 | return 1; |
| 1740 | } |
| 1741 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1742 | struct server *sv; |
| 1743 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1744 | sv = expect_server_admin(s, si, args[2]); |
| 1745 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1746 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1747 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1748 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1749 | /* Not already in maintenance, we can change the server state */ |
| 1750 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1751 | sv->check.state |= CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1752 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1753 | } |
| 1754 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1755 | return 1; |
| 1756 | } |
| 1757 | else if (strcmp(args[1], "frontend") == 0) { |
| 1758 | struct proxy *px; |
| 1759 | |
| 1760 | px = expect_frontend_admin(s, si, args[2]); |
| 1761 | if (!px) |
| 1762 | return 1; |
| 1763 | |
| 1764 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1765 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1766 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1767 | return 1; |
| 1768 | } |
| 1769 | |
| 1770 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1771 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1772 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1773 | return 1; |
| 1774 | } |
| 1775 | |
| 1776 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1777 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1778 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1779 | return 1; |
| 1780 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1781 | return 1; |
| 1782 | } |
| 1783 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1784 | appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1785 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1786 | return 1; |
| 1787 | } |
| 1788 | } |
| 1789 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1790 | if (strcmp(args[1], "frontend") == 0) { |
| 1791 | struct proxy *px; |
| 1792 | |
| 1793 | px = expect_frontend_admin(s, si, args[2]); |
| 1794 | if (!px) |
| 1795 | return 1; |
| 1796 | |
| 1797 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1798 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1799 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1800 | return 1; |
| 1801 | } |
| 1802 | |
| 1803 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1804 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1805 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1806 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1807 | stop_proxy(px); |
| 1808 | return 1; |
| 1809 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1810 | else if (strcmp(args[1], "session") == 0) { |
| 1811 | struct session *sess, *ptr; |
| 1812 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1813 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1814 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1815 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1816 | return 1; |
| 1817 | } |
| 1818 | |
| 1819 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1820 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1821 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1822 | return 1; |
| 1823 | } |
| 1824 | |
| 1825 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1826 | |
| 1827 | /* first, look for the requested session in the session table */ |
| 1828 | list_for_each_entry(sess, &sessions, list) { |
| 1829 | if (sess == ptr) |
| 1830 | break; |
| 1831 | } |
| 1832 | |
| 1833 | /* do we have the session ? */ |
| 1834 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1835 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1836 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1837 | return 1; |
| 1838 | } |
| 1839 | |
| 1840 | session_shutdown(sess, SN_ERR_KILLED); |
| 1841 | return 1; |
| 1842 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1843 | else if (strcmp(args[1], "sessions") == 0) { |
| 1844 | if (strcmp(args[2], "server") == 0) { |
| 1845 | struct server *sv; |
| 1846 | struct session *sess, *sess_bck; |
| 1847 | |
| 1848 | sv = expect_server_admin(s, si, args[3]); |
| 1849 | if (!sv) |
| 1850 | return 1; |
| 1851 | |
| 1852 | /* kill all the session that are on this server */ |
| 1853 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1854 | if (sess->srv_conn == sv) |
| 1855 | session_shutdown(sess, SN_ERR_KILLED); |
| 1856 | |
| 1857 | return 1; |
| 1858 | } |
| 1859 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1860 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1861 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1862 | return 1; |
| 1863 | } |
| 1864 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1865 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1866 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1867 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1868 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1869 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1870 | } |
| 1871 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1872 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1873 | if (args[1][0] == 'm') |
| 1874 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1875 | else |
| 1876 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1877 | |
| 1878 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1879 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 1880 | if (!*args[2] || !*args[3]) { |
| 1881 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 1882 | appctx->st0 = STAT_CLI_PRINT; |
| 1883 | return 1; |
| 1884 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1885 | } |
| 1886 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1887 | else { |
| 1888 | if (!*args[2] || !*args[3]) { |
| 1889 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 1890 | appctx->st0 = STAT_CLI_PRINT; |
| 1891 | return 1; |
| 1892 | } |
| 1893 | } |
| 1894 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1895 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1896 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1897 | if (!appctx->ctx.map.ref || |
| 1898 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1899 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1900 | appctx->st0 = STAT_CLI_PRINT; |
| 1901 | return 1; |
| 1902 | } |
| 1903 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1904 | /* Try to delete the entry. */ |
| 1905 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 1906 | /* The entry is not found, send message. */ |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1907 | appctx->ctx.cli.msg = "Key not found.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1908 | appctx->st0 = STAT_CLI_PRINT; |
| 1909 | return 1; |
| 1910 | } |
| 1911 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1912 | /* The deletion is done, send message. */ |
| 1913 | appctx->ctx.cli.msg = "Done.\n"; |
| 1914 | appctx->st0 = STAT_CLI_PRINT; |
| 1915 | return 1; |
| 1916 | } |
| 1917 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1918 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1919 | appctx->st0 = STAT_CLI_PRINT; |
| 1920 | return 1; |
| 1921 | } |
| 1922 | } |
| 1923 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1924 | if (strcmp(args[1], "map") == 0 || |
| 1925 | strcmp(args[1], "acl") == 0) { |
| 1926 | int ret; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1927 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1928 | /* Set flags. */ |
| 1929 | if (args[1][0] == 'm') |
| 1930 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1931 | else |
| 1932 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 1933 | |
| 1934 | /* If the keywork is "map", we expect three parameters, if it |
| 1935 | * is "acl", we expect only two parameters |
| 1936 | */ |
| 1937 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 1938 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 1939 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 1940 | appctx->st0 = STAT_CLI_PRINT; |
| 1941 | return 1; |
| 1942 | } |
| 1943 | } |
| 1944 | else { |
| 1945 | if (!*args[2] || !*args[3]) { |
| 1946 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 1947 | appctx->st0 = STAT_CLI_PRINT; |
| 1948 | return 1; |
| 1949 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1950 | } |
| 1951 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1952 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1953 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1954 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1955 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1956 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <name>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1957 | else |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1958 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1959 | appctx->st0 = STAT_CLI_PRINT; |
| 1960 | return 1; |
| 1961 | } |
| 1962 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1963 | /* Add value. */ |
| 1964 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1965 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], NULL); |
| 1966 | else |
| 1967 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, NULL); |
| 1968 | if (!ret) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1969 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1970 | appctx->st0 = STAT_CLI_PRINT; |
| 1971 | return 1; |
| 1972 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1973 | |
| 1974 | /* The add is done, send message. */ |
| 1975 | appctx->ctx.cli.msg = "Done.\n"; |
| 1976 | appctx->st0 = STAT_CLI_PRINT; |
| 1977 | return 1; |
| 1978 | } |
| 1979 | else { /* unknown "del" parameter */ |
| 1980 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 1981 | appctx->st0 = STAT_CLI_PRINT; |
| 1982 | return 1; |
| 1983 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1984 | } |
| 1985 | 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] | 1986 | return 0; |
| 1987 | } |
| 1988 | return 1; |
| 1989 | } |
| 1990 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1991 | /* 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] | 1992 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 1993 | * state machine handling requests and various responses. We read a request, |
| 1994 | * 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] | 1995 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 1996 | * 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] | 1997 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1998 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1999 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2000 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2001 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2002 | struct channel *req = si->ob; |
| 2003 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2004 | int reql; |
| 2005 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2006 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2007 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2008 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2009 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2010 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2011 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2012 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2013 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2014 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2015 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2016 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2017 | /* Let's close for real now. We just close the request |
| 2018 | * side, the conditions below will complete if needed. |
| 2019 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2020 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2021 | break; |
| 2022 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2023 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2024 | /* ensure we have some output room left in the event we |
| 2025 | * would want to return some info right after parsing. |
| 2026 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2027 | if (buffer_almost_full(si->ib->buf)) { |
| 2028 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2029 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2030 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2031 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2032 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2033 | if (reql <= 0) { /* closed or EOL not found */ |
| 2034 | if (reql == 0) |
| 2035 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2036 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2037 | continue; |
| 2038 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2039 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2040 | /* seek for a possible semi-colon. If we find one, we |
| 2041 | * replace it with an LF and skip only this part. |
| 2042 | */ |
| 2043 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2044 | if (trash.str[len] == ';') { |
| 2045 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2046 | reql = len + 1; |
| 2047 | break; |
| 2048 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2049 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2050 | /* now it is time to check that we have a full line, |
| 2051 | * remove the trailing \n and possibly \r, then cut the |
| 2052 | * line. |
| 2053 | */ |
| 2054 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2055 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2056 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2057 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2058 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2059 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2060 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2061 | len--; |
| 2062 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2063 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2064 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2065 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2066 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2067 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2068 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2069 | continue; |
| 2070 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2071 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2072 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2073 | else if (strcmp(trash.str, "help") == 0 || |
| 2074 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2075 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2076 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2077 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2078 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2079 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2080 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2081 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2082 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2083 | /* if prompt is disabled, print help on empty lines, |
| 2084 | * so that the user at least knows how to enable |
| 2085 | * prompt and find help. |
| 2086 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2087 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2088 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2092 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2093 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2094 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2095 | 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] | 2096 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2097 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2098 | continue; |
| 2099 | } |
| 2100 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2101 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2102 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2103 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2104 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2105 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2106 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2107 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2108 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2109 | break; |
| 2110 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2111 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2112 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2113 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2114 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2115 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2116 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2117 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2118 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2119 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2120 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2121 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2122 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2123 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2124 | if (stats_table_request(si, appctx->st0)) |
| 2125 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2126 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2127 | case STAT_CLI_O_PATS: |
| 2128 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2129 | appctx->st0 = STAT_CLI_PROMPT; |
| 2130 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2131 | case STAT_CLI_O_PAT: |
| 2132 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2133 | appctx->st0 = STAT_CLI_PROMPT; |
| 2134 | break; |
| 2135 | case STAT_CLI_O_MLOOK: |
| 2136 | if (stats_map_lookup(si)) |
| 2137 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2138 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2139 | case STAT_CLI_O_POOLS: |
| 2140 | if (stats_dump_pools_to_buffer(si)) |
| 2141 | appctx->st0 = STAT_CLI_PROMPT; |
| 2142 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2143 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2144 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2145 | break; |
| 2146 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2147 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2148 | /* 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] | 2149 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2150 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2151 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2152 | } |
| 2153 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2154 | /* 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] | 2155 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2156 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2157 | |
| 2158 | /* Now we close the output if one of the writers did so, |
| 2159 | * or if we're not in interactive mode and the request |
| 2160 | * buffer is empty. This still allows pipelined requests |
| 2161 | * to be sent in non-interactive mode. |
| 2162 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2163 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2164 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2165 | continue; |
| 2166 | } |
| 2167 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2168 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2169 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2170 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2171 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2172 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2173 | 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] | 2174 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2175 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2176 | /* 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] | 2177 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2178 | * we forward the close to the request side so that it flows upstream to |
| 2179 | * the client. |
| 2180 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2181 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2182 | } |
| 2183 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2184 | 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] | 2185 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2186 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2187 | /* We have no more processing to do, and nothing more to send, and |
| 2188 | * the client side has closed. So we'll forward this state downstream |
| 2189 | * on the response buffer. |
| 2190 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2191 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2192 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2196 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2197 | |
| 2198 | /* we don't want to expire timeouts while we're processing requests */ |
| 2199 | si->ib->rex = TICK_ETERNITY; |
| 2200 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2201 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2202 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2203 | 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] | 2204 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2205 | 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] | 2206 | |
| 2207 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2208 | /* check that we have released everything then unregister */ |
| 2209 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2210 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2211 | } |
| 2212 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2213 | /* This function dumps information onto the stream interface's read buffer. |
| 2214 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2215 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2216 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2217 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2218 | { |
| 2219 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2220 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2221 | chunk_printf(&trash, |
| 2222 | "Name: " PRODUCT_NAME "\n" |
| 2223 | "Version: " HAPROXY_VERSION "\n" |
| 2224 | "Release_date: " HAPROXY_DATE "\n" |
| 2225 | "Nbproc: %d\n" |
| 2226 | "Process_num: %d\n" |
| 2227 | "Pid: %d\n" |
| 2228 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2229 | "Uptime_sec: %d\n" |
| 2230 | "Memmax_MB: %d\n" |
| 2231 | "Ulimit-n: %d\n" |
| 2232 | "Maxsock: %d\n" |
| 2233 | "Maxconn: %d\n" |
| 2234 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2235 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2236 | "CumConns: %d\n" |
| 2237 | "CumReq: %d\n" |
| 2238 | #ifdef USE_OPENSSL |
| 2239 | "MaxSslConns: %d\n" |
| 2240 | "CurrSslConns: %d\n" |
| 2241 | "CumSslConns: %d\n" |
| 2242 | #endif |
| 2243 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2244 | "PipesUsed: %d\n" |
| 2245 | "PipesFree: %d\n" |
| 2246 | "ConnRate: %d\n" |
| 2247 | "ConnRateLimit: %d\n" |
| 2248 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2249 | "SessRate: %d\n" |
| 2250 | "SessRateLimit: %d\n" |
| 2251 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2252 | #ifdef USE_OPENSSL |
| 2253 | "SslRate: %d\n" |
| 2254 | "SslRateLimit: %d\n" |
| 2255 | "MaxSslRate: %d\n" |
| 2256 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2257 | "CompressBpsIn: %u\n" |
| 2258 | "CompressBpsOut: %u\n" |
| 2259 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2260 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2261 | "ZlibMemUsage: %ld\n" |
| 2262 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2263 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2264 | "Tasks: %d\n" |
| 2265 | "Run_queue: %d\n" |
| 2266 | "Idle_pct: %d\n" |
| 2267 | "node: %s\n" |
| 2268 | "description: %s\n" |
| 2269 | "", |
| 2270 | global.nbproc, |
| 2271 | relative_pid, |
| 2272 | pid, |
| 2273 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2274 | up, |
| 2275 | global.rlimit_memmax, |
| 2276 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2277 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2278 | actconn, totalconn, global.req_count, |
| 2279 | #ifdef USE_OPENSSL |
| 2280 | global.maxsslconn, sslconns, totalsslconns, |
| 2281 | #endif |
| 2282 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2283 | 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] | 2284 | 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] | 2285 | #ifdef USE_OPENSSL |
| 2286 | read_freq_ctr(&global.ssl_per_sec), global.ssl_lim, global.ssl_max, |
| 2287 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2288 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2289 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2290 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2291 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2292 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2293 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2294 | global.node, global.desc ? global.desc : "" |
| 2295 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2296 | |
| 2297 | if (bi_putchk(si->ib, &trash) == -1) |
| 2298 | return 0; |
| 2299 | |
| 2300 | return 1; |
| 2301 | } |
| 2302 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2303 | /* This function dumps memory usage information onto the stream interface's |
| 2304 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2305 | * completion. No state is used. |
| 2306 | */ |
| 2307 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2308 | { |
| 2309 | dump_pools_to_trash(); |
| 2310 | if (bi_putchk(si->ib, &trash) == -1) |
| 2311 | return 0; |
| 2312 | return 1; |
| 2313 | } |
| 2314 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2315 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2316 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2317 | * 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] | 2318 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2319 | 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] | 2320 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2321 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2322 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2323 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2324 | if (!(px->cap & PR_CAP_FE)) |
| 2325 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2326 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2327 | 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] | 2328 | return 0; |
| 2329 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2330 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2331 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2332 | /* name, queue */ |
| 2333 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2334 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2335 | 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] | 2336 | /* Column sub-heading for Enable or Disable server */ |
| 2337 | chunk_appendf(&trash, "<td></td>"); |
| 2338 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2339 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2340 | chunk_appendf(&trash, |
| 2341 | "<td class=ac>" |
| 2342 | "<a name=\"%s/Frontend\"></a>" |
| 2343 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2344 | "<td colspan=3></td>" |
| 2345 | "", |
| 2346 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2347 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2348 | chunk_appendf(&trash, |
| 2349 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2350 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2351 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2352 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2353 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2354 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2355 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2356 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2357 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2358 | if (px->mode == PR_MODE_HTTP) |
| 2359 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2360 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2361 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2362 | |
| 2363 | chunk_appendf(&trash, |
| 2364 | "</table></div></u></td>" |
| 2365 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2366 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2367 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2368 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2369 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2370 | U2H(px->fe_counters.sps_max), |
| 2371 | U2H(px->fe_counters.cps_max), |
| 2372 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2373 | |
| 2374 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2375 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2376 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2377 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2378 | |
| 2379 | chunk_appendf(&trash, |
| 2380 | "</table></div></u></td>" |
| 2381 | /* sessions rate : limit */ |
| 2382 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2383 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2384 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2385 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2386 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2387 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2388 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2389 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2390 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2391 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2392 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2393 | U2H(px->fe_counters.cum_sess), |
| 2394 | U2H(px->fe_counters.cum_conn), |
| 2395 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2396 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2397 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2398 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2399 | chunk_appendf(&trash, |
| 2400 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2401 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2402 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2403 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2404 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2405 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2406 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2407 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2408 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2409 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2410 | U2H(px->fe_counters.p.http.cum_req), |
| 2411 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2412 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2413 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2414 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2415 | (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] | 2416 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2417 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2418 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2419 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2420 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2421 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2422 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2423 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2424 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2425 | /* sessions: lbtot, lastsess */ |
| 2426 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2427 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2428 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2429 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2430 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2431 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2432 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2433 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2434 | "<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] | 2435 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2436 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2437 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2438 | px->fe_counters.comp_in ? |
| 2439 | (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] | 2440 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2441 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2442 | chunk_appendf(&trash, |
| 2443 | /* denied: req, resp */ |
| 2444 | "<td>%s</td><td>%s</td>" |
| 2445 | /* errors : request, connect, response */ |
| 2446 | "<td>%s</td><td></td><td></td>" |
| 2447 | /* warnings: retries, redispatches */ |
| 2448 | "<td></td><td></td>" |
| 2449 | /* server status : reflect frontend status */ |
| 2450 | "<td class=ac>%s</td>" |
| 2451 | /* rest of server: nothing */ |
| 2452 | "<td class=ac colspan=8></td></tr>" |
| 2453 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2454 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2455 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2456 | px->state == PR_STREADY ? "OPEN" : |
| 2457 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2458 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2459 | else { /* CSV mode */ |
| 2460 | chunk_appendf(&trash, |
| 2461 | /* pxid, name, queue cur, queue max, */ |
| 2462 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2463 | /* sessions : current, max, limit, total */ |
| 2464 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2465 | /* bytes : in, out */ |
| 2466 | "%lld,%lld," |
| 2467 | /* denied: req, resp */ |
| 2468 | "%lld,%lld," |
| 2469 | /* errors : request, connect, response */ |
| 2470 | "%lld,,," |
| 2471 | /* warnings: retries, redispatches */ |
| 2472 | ",," |
| 2473 | /* server status : reflect frontend status */ |
| 2474 | "%s," |
| 2475 | /* rest of server: nothing */ |
| 2476 | ",,,,,,,," |
| 2477 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2478 | "%d,%d,0,,,,%d," |
| 2479 | /* rate, rate_lim, rate_max */ |
| 2480 | "%u,%u,%u," |
| 2481 | /* check_status, check_code, check_duration */ |
| 2482 | ",,,", |
| 2483 | px->id, |
| 2484 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2485 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2486 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2487 | px->fe_counters.failed_req, |
| 2488 | px->state == PR_STREADY ? "OPEN" : |
| 2489 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2490 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2491 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2492 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2493 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2494 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2495 | if (px->mode == PR_MODE_HTTP) { |
| 2496 | for (i=1; i<6; i++) |
| 2497 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2498 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2499 | } |
| 2500 | else |
| 2501 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2502 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2503 | /* failed health analyses */ |
| 2504 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2505 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2506 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2507 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2508 | read_freq_ctr(&px->fe_req_per_sec), |
| 2509 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2510 | |
| 2511 | /* errors: cli_aborts, srv_aborts */ |
| 2512 | chunk_appendf(&trash, ",,"); |
| 2513 | |
| 2514 | /* compression: in, out, bypassed */ |
| 2515 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2516 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2517 | |
| 2518 | /* compression: comp_rsp */ |
| 2519 | chunk_appendf(&trash, "%lld,", |
| 2520 | px->fe_counters.p.http.comp_rsp); |
| 2521 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2522 | /* lastsess */ |
| 2523 | chunk_appendf(&trash, ","); |
| 2524 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2525 | /* finish with EOL */ |
| 2526 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2527 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2528 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2529 | } |
| 2530 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2531 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2532 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2533 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2534 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2535 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2536 | 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] | 2537 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2538 | struct appctx *appctx = __objt_appctx(si->end); |
| 2539 | |
| 2540 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2541 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2542 | 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] | 2543 | /* Column sub-heading for Enable or Disable server */ |
| 2544 | chunk_appendf(&trash, "<td></td>"); |
| 2545 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2546 | chunk_appendf(&trash, |
| 2547 | /* frontend name, listener name */ |
| 2548 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2549 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2550 | "", |
| 2551 | px->id, l->name, |
| 2552 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2553 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2554 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2555 | if (flags & ST_SHLGNDS) { |
| 2556 | char str[INET6_ADDRSTRLEN]; |
| 2557 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2558 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2559 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2560 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2561 | port = get_host_port(&l->addr); |
| 2562 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2563 | case AF_INET: |
| 2564 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2565 | break; |
| 2566 | case AF_INET6: |
| 2567 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2568 | break; |
| 2569 | case AF_UNIX: |
| 2570 | chunk_appendf(&trash, "unix, "); |
| 2571 | break; |
| 2572 | case -1: |
| 2573 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2574 | break; |
| 2575 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2576 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2577 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2578 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2579 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2580 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2581 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2582 | /* queue */ |
| 2583 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2584 | /* sessions rate: current, max, limit */ |
| 2585 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2586 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2587 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2588 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2589 | /* bytes: in, out */ |
| 2590 | "<td>%s</td><td>%s</td>" |
| 2591 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2592 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2593 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2594 | 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] | 2595 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2596 | chunk_appendf(&trash, |
| 2597 | /* denied: req, resp */ |
| 2598 | "<td>%s</td><td>%s</td>" |
| 2599 | /* errors: request, connect, response */ |
| 2600 | "<td>%s</td><td></td><td></td>" |
| 2601 | /* warnings: retries, redispatches */ |
| 2602 | "<td></td><td></td>" |
| 2603 | /* server status: reflect listener status */ |
| 2604 | "<td class=ac>%s</td>" |
| 2605 | /* rest of server: nothing */ |
| 2606 | "<td class=ac colspan=8></td></tr>" |
| 2607 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2608 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2609 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2610 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2611 | } |
| 2612 | else { /* CSV mode */ |
| 2613 | chunk_appendf(&trash, |
| 2614 | /* pxid, name, queue cur, queue max, */ |
| 2615 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2616 | /* sessions: current, max, limit, total */ |
| 2617 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2618 | /* bytes: in, out */ |
| 2619 | "%lld,%lld," |
| 2620 | /* denied: req, resp */ |
| 2621 | "%lld,%lld," |
| 2622 | /* errors: request, connect, response */ |
| 2623 | "%lld,,," |
| 2624 | /* warnings: retries, redispatches */ |
| 2625 | ",," |
| 2626 | /* server status: reflect listener status */ |
| 2627 | "%s," |
| 2628 | /* rest of server: nothing */ |
| 2629 | ",,,,,,,," |
| 2630 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2631 | "%d,%d,%d,,,,%d," |
| 2632 | /* rate, rate_lim, rate_max */ |
| 2633 | ",,," |
| 2634 | /* check_status, check_code, check_duration */ |
| 2635 | ",,," |
| 2636 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2637 | ",,,,,," |
| 2638 | /* failed health analyses */ |
| 2639 | "," |
| 2640 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2641 | ",,," |
| 2642 | /* errors: cli_aborts, srv_aborts */ |
| 2643 | ",," |
| 2644 | /* compression: in, out, bypassed, comp_rsp */ |
| 2645 | ",,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2646 | /* lastsess */ |
| 2647 | "," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2648 | "\n", |
| 2649 | px->id, l->name, |
| 2650 | l->nbconn, l->counters->conn_max, |
| 2651 | l->maxconn, l->counters->cum_conn, |
| 2652 | l->counters->bytes_in, l->counters->bytes_out, |
| 2653 | l->counters->denied_req, l->counters->denied_resp, |
| 2654 | l->counters->failed_req, |
| 2655 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2656 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2657 | } |
| 2658 | return 1; |
| 2659 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2660 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2661 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2662 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2663 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2664 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2665 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2666 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2667 | */ |
| 2668 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2669 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2670 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2671 | struct server *ref = sv->track ? sv->track : sv; |
| 2672 | char str[INET6_ADDRSTRLEN]; |
| 2673 | struct chunk src; |
| 2674 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2675 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2676 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2677 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2678 | "DOWN", |
| 2679 | "DN %d/%d ↑", |
| 2680 | "UP %d/%d ↓", |
| 2681 | "UP", |
| 2682 | "NOLB %d/%d ↓", |
| 2683 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2684 | "DRAIN %d/%d ↓", |
| 2685 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2686 | "<i>no check</i>" |
| 2687 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2688 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2689 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2690 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2691 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2692 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2693 | "<tr class=\"%s%d\">", |
| 2694 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2695 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2696 | 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] | 2697 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2698 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2699 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2700 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2701 | chunk_appendf(&trash, |
| 2702 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2703 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2704 | "", |
| 2705 | px->id, sv->id, |
| 2706 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2707 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2708 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2709 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2710 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2711 | |
| 2712 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2713 | case AF_INET: |
| 2714 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2715 | break; |
| 2716 | case AF_INET6: |
| 2717 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2718 | break; |
| 2719 | case AF_UNIX: |
| 2720 | chunk_appendf(&trash, "unix, "); |
| 2721 | break; |
| 2722 | case -1: |
| 2723 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2724 | break; |
| 2725 | default: /* address family not supported */ |
| 2726 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2727 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2728 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2729 | /* id */ |
| 2730 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2731 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2732 | /* cookie */ |
| 2733 | if (sv->cookie) { |
| 2734 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2735 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2736 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2737 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2738 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2739 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2740 | } |
| 2741 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2742 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2743 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2744 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2745 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2746 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2747 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2748 | /* sessions rate : current, max, limit */ |
| 2749 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2750 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2751 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2752 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2753 | 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] | 2754 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2755 | |
| 2756 | chunk_appendf(&trash, |
| 2757 | /* sessions: current, max, limit, total */ |
| 2758 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2759 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2760 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2761 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2762 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2763 | U2H(sv->counters.cum_sess), |
| 2764 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2765 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2766 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2767 | if (px->mode == PR_MODE_HTTP) { |
| 2768 | unsigned long long tot; |
| 2769 | for (tot = i = 0; i < 6; i++) |
| 2770 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2771 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2772 | chunk_appendf(&trash, |
| 2773 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2774 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2775 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2776 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2777 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2778 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2779 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2780 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2781 | U2H(tot), |
| 2782 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2783 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2784 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2785 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2786 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2787 | 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] | 2788 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2789 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2790 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2791 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2792 | /* sessions: lbtot, last */ |
| 2793 | "<td>%s</td><td>%s</td>", |
| 2794 | U2H(sv->counters.cum_lbconn), |
| 2795 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2796 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2797 | chunk_appendf(&trash, |
| 2798 | /* bytes : in, out */ |
| 2799 | "<td>%s</td><td>%s</td>" |
| 2800 | /* denied: req, resp */ |
| 2801 | "<td></td><td>%s</td>" |
| 2802 | /* errors : request, connect */ |
| 2803 | "<td></td><td>%s</td>" |
| 2804 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2805 | "<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] | 2806 | /* warnings: retries, redispatches */ |
| 2807 | "<td>%lld</td><td>%lld</td>" |
| 2808 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2809 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2810 | U2H(sv->counters.failed_secu), |
| 2811 | U2H(sv->counters.failed_conns), |
| 2812 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2813 | sv->counters.cli_aborts, |
| 2814 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2815 | sv->counters.retries, sv->counters.redispatches); |
| 2816 | |
| 2817 | /* status, lest check */ |
| 2818 | chunk_appendf(&trash, "<td class=ac>"); |
| 2819 | |
| 2820 | if (sv->state & SRV_MAINTAIN) { |
| 2821 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2822 | chunk_appendf(&trash, "MAINT"); |
| 2823 | } |
| 2824 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2825 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2826 | chunk_appendf(&trash, "MAINT(via)"); |
| 2827 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2828 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2829 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2830 | chunk_appendf(&trash, |
| 2831 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2832 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2833 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2834 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2835 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2836 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2837 | chunk_appendf(&trash, |
| 2838 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 2839 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2840 | get_check_status_info(sv->check.status)); |
| 2841 | |
| 2842 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2843 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2844 | |
| 2845 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2846 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2847 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2848 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2849 | get_check_status_description(sv->check.status)); |
| 2850 | if (*sv->check.desc) { |
| 2851 | chunk_appendf(&trash, ": "); |
| 2852 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2853 | chunk_htmlencode(&trash, &src); |
| 2854 | } |
| 2855 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2856 | } |
| 2857 | else |
| 2858 | chunk_appendf(&trash, "</td><td>"); |
| 2859 | |
| 2860 | chunk_appendf(&trash, |
| 2861 | /* weight */ |
| 2862 | "</td><td class=ac>%d</td>" |
| 2863 | /* act, bck */ |
| 2864 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2865 | "", |
| 2866 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2867 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2868 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2869 | |
| 2870 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2871 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2872 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2873 | |
| 2874 | if (ref->observe) |
| 2875 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2876 | |
| 2877 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2878 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2879 | "<td>%lld</td><td>%s</td>" |
| 2880 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2881 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2882 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2883 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2884 | else if (sv != ref) { |
| 2885 | if (sv->state & SRV_MAINTAIN) |
| 2886 | chunk_appendf(&trash, |
| 2887 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2888 | ref->proxy->id, ref->id); |
| 2889 | else |
| 2890 | chunk_appendf(&trash, |
| 2891 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2892 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2893 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2894 | else |
| 2895 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2896 | |
| 2897 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2898 | if (sv->state & SRV_WARMINGUP) |
| 2899 | 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] | 2900 | else |
| 2901 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2902 | } |
| 2903 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2904 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2905 | "DOWN,", |
| 2906 | "DOWN %d/%d,", |
| 2907 | "UP %d/%d,", |
| 2908 | "UP,", |
| 2909 | "NOLB %d/%d,", |
| 2910 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2911 | "DRAIN %d/%d,", |
| 2912 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2913 | "no check," |
| 2914 | }; |
| 2915 | |
| 2916 | chunk_appendf(&trash, |
| 2917 | /* pxid, name */ |
| 2918 | "%s,%s," |
| 2919 | /* queue : current, max */ |
| 2920 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2921 | /* sessions : current, max, limit, total */ |
| 2922 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2923 | /* bytes : in, out */ |
| 2924 | "%lld,%lld," |
| 2925 | /* denied: req, resp */ |
| 2926 | ",%lld," |
| 2927 | /* errors : request, connect, response */ |
| 2928 | ",%lld,%lld," |
| 2929 | /* warnings: retries, redispatches */ |
| 2930 | "%lld,%lld," |
| 2931 | "", |
| 2932 | px->id, sv->id, |
| 2933 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2934 | 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] | 2935 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2936 | sv->counters.failed_secu, |
| 2937 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2938 | sv->counters.retries, sv->counters.redispatches); |
| 2939 | |
| 2940 | /* status */ |
| 2941 | if (sv->state & SRV_MAINTAIN) |
| 2942 | chunk_appendf(&trash, "MAINT,"); |
| 2943 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2944 | chunk_appendf(&trash, "MAINT(via),"); |
| 2945 | else |
| 2946 | chunk_appendf(&trash, |
| 2947 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2948 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2949 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2950 | |
| 2951 | chunk_appendf(&trash, |
| 2952 | /* weight, active, backup */ |
| 2953 | "%d,%d,%d," |
| 2954 | "", |
| 2955 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2956 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2957 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2958 | |
| 2959 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2960 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2961 | chunk_appendf(&trash, |
| 2962 | "%lld,%lld,%d,%d,", |
| 2963 | sv->counters.failed_checks, sv->counters.down_trans, |
| 2964 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 2965 | else |
| 2966 | chunk_appendf(&trash, ",,,,"); |
| 2967 | |
| 2968 | /* queue limit, pid, iid, sid, */ |
| 2969 | chunk_appendf(&trash, |
| 2970 | "%s," |
| 2971 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2972 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2973 | relative_pid, px->uuid, sv->puid); |
| 2974 | |
| 2975 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2976 | if (sv->state & SRV_WARMINGUP) |
| 2977 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2978 | |
| 2979 | /* sessions: lbtot */ |
| 2980 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 2981 | |
| 2982 | /* tracked */ |
| 2983 | if (sv->track) |
| 2984 | chunk_appendf(&trash, "%s/%s,", |
| 2985 | sv->track->proxy->id, sv->track->id); |
| 2986 | else |
| 2987 | chunk_appendf(&trash, ","); |
| 2988 | |
| 2989 | /* type */ |
| 2990 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 2991 | |
| 2992 | /* rate */ |
| 2993 | chunk_appendf(&trash, "%u,,%u,", |
| 2994 | read_freq_ctr(&sv->sess_per_sec), |
| 2995 | sv->counters.sps_max); |
| 2996 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2997 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2998 | /* check_status */ |
| 2999 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3000 | |
| 3001 | /* check_code */ |
| 3002 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3003 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3004 | else |
| 3005 | chunk_appendf(&trash, ","); |
| 3006 | |
| 3007 | /* check_duration */ |
| 3008 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3009 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3010 | else |
| 3011 | chunk_appendf(&trash, ","); |
| 3012 | |
| 3013 | } |
| 3014 | else |
| 3015 | chunk_appendf(&trash, ",,,"); |
| 3016 | |
| 3017 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3018 | if (px->mode == PR_MODE_HTTP) { |
| 3019 | for (i=1; i<6; i++) |
| 3020 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3021 | |
| 3022 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3023 | } |
| 3024 | else |
| 3025 | chunk_appendf(&trash, ",,,,,,"); |
| 3026 | |
| 3027 | /* failed health analyses */ |
| 3028 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3029 | |
| 3030 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3031 | chunk_appendf(&trash, ",,,"); |
| 3032 | |
| 3033 | /* errors: cli_aborts, srv_aborts */ |
| 3034 | chunk_appendf(&trash, "%lld,%lld,", |
| 3035 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3036 | |
| 3037 | /* compression: in, out, bypassed, comp_rsp */ |
| 3038 | chunk_appendf(&trash, ",,,,"); |
| 3039 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3040 | /* lastsess */ |
| 3041 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3042 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3043 | /* finish with EOL */ |
| 3044 | chunk_appendf(&trash, "\n"); |
| 3045 | } |
| 3046 | return 1; |
| 3047 | } |
| 3048 | |
| 3049 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3050 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3051 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3052 | */ |
| 3053 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3054 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3055 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3056 | struct chunk src; |
| 3057 | int i; |
| 3058 | |
| 3059 | if (!(px->cap & PR_CAP_BE)) |
| 3060 | return 0; |
| 3061 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3062 | 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] | 3063 | return 0; |
| 3064 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3065 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3066 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3067 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3068 | /* Column sub-heading for Enable or Disable server */ |
| 3069 | chunk_appendf(&trash, "<td></td>"); |
| 3070 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3071 | chunk_appendf(&trash, |
| 3072 | "<td class=ac>" |
| 3073 | /* name */ |
| 3074 | "%s<a name=\"%s/Backend\"></a>" |
| 3075 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3076 | "", |
| 3077 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3078 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3079 | |
| 3080 | if (flags & ST_SHLGNDS) { |
| 3081 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3082 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3083 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3084 | |
| 3085 | /* cookie */ |
| 3086 | if (px->cookie_name) { |
| 3087 | chunk_appendf(&trash, ", cookie: '"); |
| 3088 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3089 | chunk_htmlencode(&trash, &src); |
| 3090 | chunk_appendf(&trash, "'"); |
| 3091 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3092 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3096 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3097 | /* queue : current, max */ |
| 3098 | "<td>%s</td><td>%s</td><td></td>" |
| 3099 | /* sessions rate : current, max, limit */ |
| 3100 | "<td>%s</td><td>%s</td><td></td>" |
| 3101 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3102 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3103 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3104 | 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] | 3105 | |
| 3106 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3107 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3108 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3109 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3110 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3111 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3112 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3113 | U2H(px->be_counters.cum_conn), |
| 3114 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3115 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3116 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3117 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3118 | chunk_appendf(&trash, |
| 3119 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3120 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3121 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3122 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3123 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3124 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3125 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3126 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3127 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3128 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3129 | U2H(px->be_counters.p.http.cum_req), |
| 3130 | U2H(px->be_counters.p.http.rsp[1]), |
| 3131 | U2H(px->be_counters.p.http.rsp[2]), |
| 3132 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3133 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3134 | (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] | 3135 | U2H(px->be_counters.p.http.rsp[3]), |
| 3136 | U2H(px->be_counters.p.http.rsp[4]), |
| 3137 | U2H(px->be_counters.p.http.rsp[5]), |
| 3138 | U2H(px->be_counters.p.http.rsp[0]), |
| 3139 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3143 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3144 | /* sessions: lbtot, last */ |
| 3145 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3146 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3147 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3148 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3149 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3150 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3151 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3152 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3153 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3154 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3155 | "<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] | 3156 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3157 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3158 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3159 | px->be_counters.comp_in ? |
| 3160 | (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] | 3161 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3162 | |
| 3163 | chunk_appendf(&trash, |
| 3164 | /* denied: req, resp */ |
| 3165 | "<td>%s</td><td>%s</td>" |
| 3166 | /* errors : request, connect */ |
| 3167 | "<td></td><td>%s</td>" |
| 3168 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3169 | "<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] | 3170 | /* warnings: retries, redispatches */ |
| 3171 | "<td>%lld</td><td>%lld</td>" |
| 3172 | /* backend status: reflect backend status (up/down): we display UP |
| 3173 | * if the backend has known working servers or if it has no server at |
| 3174 | * all (eg: for stats). Then we display the total weight, number of |
| 3175 | * active and backups. */ |
| 3176 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3177 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3178 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3179 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3180 | U2H(px->be_counters.failed_conns), |
| 3181 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3182 | px->be_counters.cli_aborts, |
| 3183 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3184 | px->be_counters.retries, px->be_counters.redispatches, |
| 3185 | human_time(now.tv_sec - px->last_change, 1), |
| 3186 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3187 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3188 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3189 | px->srv_act, px->srv_bck); |
| 3190 | |
| 3191 | chunk_appendf(&trash, |
| 3192 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3193 | "<td class=ac> </td><td>%d</td>" |
| 3194 | "<td>%s</td>" |
| 3195 | "<td></td>" |
| 3196 | "</tr>", |
| 3197 | px->down_trans, |
| 3198 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3199 | } |
| 3200 | else { /* CSV mode */ |
| 3201 | chunk_appendf(&trash, |
| 3202 | /* pxid, name */ |
| 3203 | "%s,BACKEND," |
| 3204 | /* queue : current, max */ |
| 3205 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3206 | /* sessions : current, max, limit, total */ |
| 3207 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3208 | /* bytes : in, out */ |
| 3209 | "%lld,%lld," |
| 3210 | /* denied: req, resp */ |
| 3211 | "%lld,%lld," |
| 3212 | /* errors : request, connect, response */ |
| 3213 | ",%lld,%lld," |
| 3214 | /* warnings: retries, redispatches */ |
| 3215 | "%lld,%lld," |
| 3216 | /* backend status: reflect backend status (up/down): we display UP |
| 3217 | * if the backend has known working servers or if it has no server at |
| 3218 | * all (eg: for stats). Then we display the total weight, number of |
| 3219 | * active and backups. */ |
| 3220 | "%s," |
| 3221 | "%d,%d,%d," |
| 3222 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3223 | ",%d,%d,%d,," |
| 3224 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3225 | "%d,%d,0,,%lld,,%d," |
| 3226 | /* rate, rate_lim, rate_max, */ |
| 3227 | "%u,,%u," |
| 3228 | /* check_status, check_code, check_duration */ |
| 3229 | ",,,", |
| 3230 | px->id, |
| 3231 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3232 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3233 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3234 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3235 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3236 | px->be_counters.retries, px->be_counters.redispatches, |
| 3237 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3238 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3239 | px->srv_act, px->srv_bck, |
| 3240 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3241 | px->srv?be_downtime(px):0, |
| 3242 | relative_pid, px->uuid, |
| 3243 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3244 | read_freq_ctr(&px->be_sess_per_sec), |
| 3245 | px->be_counters.sps_max); |
| 3246 | |
| 3247 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3248 | if (px->mode == PR_MODE_HTTP) { |
| 3249 | for (i=1; i<6; i++) |
| 3250 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3251 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3252 | } |
| 3253 | else |
| 3254 | chunk_appendf(&trash, ",,,,,,"); |
| 3255 | |
| 3256 | /* failed health analyses */ |
| 3257 | chunk_appendf(&trash, ","); |
| 3258 | |
| 3259 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3260 | chunk_appendf(&trash, ",,,"); |
| 3261 | |
| 3262 | /* errors: cli_aborts, srv_aborts */ |
| 3263 | chunk_appendf(&trash, "%lld,%lld,", |
| 3264 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3265 | |
| 3266 | /* compression: in, out, bypassed */ |
| 3267 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3268 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3269 | |
| 3270 | /* compression: comp_rsp */ |
| 3271 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3272 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3273 | /* lastsess */ |
| 3274 | chunk_appendf(&trash, "%d,", be_lastsession(px)); |
| 3275 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3276 | /* finish with EOL */ |
| 3277 | chunk_appendf(&trash, "\n"); |
| 3278 | } |
| 3279 | return 1; |
| 3280 | } |
| 3281 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3282 | /* 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] | 3283 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3284 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3285 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3286 | 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] | 3287 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3288 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3289 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3290 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3291 | 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] | 3292 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3293 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3294 | /* 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] | 3295 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3296 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3297 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3298 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3299 | 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] | 3300 | } |
| 3301 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3302 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3303 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3304 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3305 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3306 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3307 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | /* print a new table */ |
| 3311 | chunk_appendf(&trash, |
| 3312 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3313 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3314 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3315 | |
| 3316 | chunk_appendf(&trash, |
| 3317 | "<a name=\"%s\"></a>%s" |
| 3318 | "<a class=px href=\"#%s\">%s</a>", |
| 3319 | px->id, |
| 3320 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3321 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3322 | |
| 3323 | if (uri->flags & ST_SHLGNDS) { |
| 3324 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3325 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3326 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3327 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3328 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3332 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3333 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3334 | "</tr>\n" |
| 3335 | "</table>\n" |
| 3336 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3337 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3338 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3339 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3340 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3341 | 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] | 3342 | /* Column heading for Enable or Disable server */ |
| 3343 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3344 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3345 | |
| 3346 | chunk_appendf(&trash, |
| 3347 | "<th rowspan=2></th>" |
| 3348 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3349 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3350 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3351 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3352 | "<th colspan=9>Server</th>" |
| 3353 | "</tr>\n" |
| 3354 | "<tr class=\"titre\">" |
| 3355 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3356 | "<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] | 3357 | "<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] | 3358 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3359 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3360 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3361 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3362 | "<th>Thrtle</th>\n" |
| 3363 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3364 | } |
| 3365 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3366 | /* 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] | 3367 | * 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] | 3368 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3369 | 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] | 3370 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3371 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3372 | chunk_appendf(&trash, "</table>"); |
| 3373 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3374 | 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] | 3375 | /* close the form used to enable/disable this proxy servers */ |
| 3376 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3377 | "Choose the action to perform on the checked servers : " |
| 3378 | "<select name=action>" |
| 3379 | "<option value=\"\"></option>" |
| 3380 | "<option value=\"disable\">Disable</option>" |
| 3381 | "<option value=\"enable\">Enable</option>" |
| 3382 | "<option value=\"stop\">Soft Stop</option>" |
| 3383 | "<option value=\"start\">Soft Start</option>" |
| 3384 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3385 | "</select>" |
| 3386 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3387 | " <input type=\"submit\" value=\"Apply\">" |
| 3388 | "</form>", |
| 3389 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3393 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3394 | |
| 3395 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3396 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3397 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3398 | * buffer space, or non-zero if everything completed. This function is used |
| 3399 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3400 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3401 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3402 | 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] | 3403 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3404 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3405 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3406 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3407 | 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] | 3408 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3409 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3410 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3411 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3412 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3413 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3414 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3415 | if (uri && uri->scope) { |
| 3416 | /* we have a limited scope, we have to check the proxy name */ |
| 3417 | struct stat_scope *scope; |
| 3418 | int len; |
| 3419 | |
| 3420 | len = strlen(px->id); |
| 3421 | scope = uri->scope; |
| 3422 | |
| 3423 | while (scope) { |
| 3424 | /* match exact proxy name */ |
| 3425 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3426 | break; |
| 3427 | |
| 3428 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3429 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3430 | break; |
| 3431 | scope = scope->next; |
| 3432 | } |
| 3433 | |
| 3434 | /* proxy name not found : don't dump anything */ |
| 3435 | if (scope == NULL) |
| 3436 | return 1; |
| 3437 | } |
| 3438 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3439 | /* if the user has requested a limited output and the proxy |
| 3440 | * name does not match, skip it. |
| 3441 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3442 | if (appctx->ctx.stats.scope_len && |
| 3443 | 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] | 3444 | return 1; |
| 3445 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3446 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3447 | (appctx->ctx.stats.iid != -1) && |
| 3448 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3449 | return 1; |
| 3450 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3451 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3452 | /* fall through */ |
| 3453 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3454 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3455 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3456 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3457 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3458 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3459 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3460 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3461 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3462 | /* fall through */ |
| 3463 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3464 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3465 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3466 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3467 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3468 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3469 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3470 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3471 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3472 | /* fall through */ |
| 3473 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3474 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3475 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3476 | 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] | 3477 | if (buffer_almost_full(rep->buf)) { |
| 3478 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3479 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3480 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3481 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3482 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3483 | if (!l->counters) |
| 3484 | continue; |
| 3485 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3486 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3487 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3488 | break; |
| 3489 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3490 | 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] | 3491 | continue; |
| 3492 | } |
| 3493 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3494 | /* print the frontend */ |
| 3495 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3496 | if (bi_putchk(rep, &trash) == -1) |
| 3497 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3498 | } |
| 3499 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3500 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3501 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3502 | /* fall through */ |
| 3503 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3504 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3505 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3506 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3507 | 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] | 3508 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3509 | if (buffer_almost_full(rep->buf)) { |
| 3510 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3511 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3512 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3513 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3514 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3515 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3516 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3517 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3518 | break; |
| 3519 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3520 | 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] | 3521 | continue; |
| 3522 | } |
| 3523 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3524 | if (sv->track) |
| 3525 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3526 | else |
| 3527 | svs = sv; |
| 3528 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3529 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3530 | if (!(svs->check.state & CHK_ST_ENABLED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3531 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3532 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 3533 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3534 | sv_state = 3; /* UP */ |
| 3535 | else |
| 3536 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3537 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3538 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3539 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3540 | else if (svs->state & SRV_GOINGDOWN) |
| 3541 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3542 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3543 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 3544 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3545 | sv_state = 1; /* going up */ |
| 3546 | else |
| 3547 | sv_state = 0; /* DOWN */ |
| 3548 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3549 | 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] | 3550 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3551 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3552 | continue; |
| 3553 | } |
| 3554 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3555 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3556 | if (bi_putchk(rep, &trash) == -1) |
| 3557 | return 0; |
| 3558 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3559 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3560 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3561 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3562 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3563 | case STAT_PX_ST_BE: |
| 3564 | /* print the backend */ |
| 3565 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3566 | if (bi_putchk(rep, &trash) == -1) |
| 3567 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3568 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3569 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3570 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3571 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3572 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3573 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3574 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3575 | if (bi_putchk(rep, &trash) == -1) |
| 3576 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3577 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3578 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3579 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3580 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3581 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3582 | case STAT_PX_ST_FIN: |
| 3583 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3584 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3585 | default: |
| 3586 | /* unknown state, we should put an abort() here ! */ |
| 3587 | return 1; |
| 3588 | } |
| 3589 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3590 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3591 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3592 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3593 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3594 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3595 | { |
| 3596 | /* WARNING! This must fit in the first buffer !!! */ |
| 3597 | chunk_appendf(&trash, |
| 3598 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3599 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3600 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3601 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3602 | "<style type=\"text/css\"><!--\n" |
| 3603 | "body {" |
| 3604 | " font-family: arial, helvetica, sans-serif;" |
| 3605 | " font-size: 12px;" |
| 3606 | " font-weight: normal;" |
| 3607 | " color: black;" |
| 3608 | " background: white;" |
| 3609 | "}\n" |
| 3610 | "th,td {" |
| 3611 | " font-size: 10px;" |
| 3612 | "}\n" |
| 3613 | "h1 {" |
| 3614 | " font-size: x-large;" |
| 3615 | " margin-bottom: 0.5em;" |
| 3616 | "}\n" |
| 3617 | "h2 {" |
| 3618 | " font-family: helvetica, arial;" |
| 3619 | " font-size: x-large;" |
| 3620 | " font-weight: bold;" |
| 3621 | " font-style: italic;" |
| 3622 | " color: #6020a0;" |
| 3623 | " margin-top: 0em;" |
| 3624 | " margin-bottom: 0em;" |
| 3625 | "}\n" |
| 3626 | "h3 {" |
| 3627 | " font-family: helvetica, arial;" |
| 3628 | " font-size: 16px;" |
| 3629 | " font-weight: bold;" |
| 3630 | " color: #b00040;" |
| 3631 | " background: #e8e8d0;" |
| 3632 | " margin-top: 0em;" |
| 3633 | " margin-bottom: 0em;" |
| 3634 | "}\n" |
| 3635 | "li {" |
| 3636 | " margin-top: 0.25em;" |
| 3637 | " margin-right: 2em;" |
| 3638 | "}\n" |
| 3639 | ".hr {margin-top: 0.25em;" |
| 3640 | " border-color: black;" |
| 3641 | " border-bottom-style: solid;" |
| 3642 | "}\n" |
| 3643 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3644 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3645 | ".frontend {background: #e8e8d0;}\n" |
| 3646 | ".socket {background: #d0d0d0;}\n" |
| 3647 | ".backend {background: #e8e8d0;}\n" |
| 3648 | ".active0 {background: #ff9090;}\n" |
| 3649 | ".active1 {background: #ffd020;}\n" |
| 3650 | ".active2 {background: #ffffa0;}\n" |
| 3651 | ".active3 {background: #c0ffc0;}\n" |
| 3652 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3653 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3654 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3655 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3656 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3657 | ".backup0 {background: #ff9090;}\n" |
| 3658 | ".backup1 {background: #ff80ff;}\n" |
| 3659 | ".backup2 {background: #c060ff;}\n" |
| 3660 | ".backup3 {background: #b0d0ff;}\n" |
| 3661 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3662 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3663 | ".backup6 {background: #c060ff;}\n" |
| 3664 | ".backup7 {background: #cc9900;}\n" |
| 3665 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3666 | ".maintain {background: #c07820;}\n" |
| 3667 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3668 | "\n" |
| 3669 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3670 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3671 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3672 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3673 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3674 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3675 | "\n" |
| 3676 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3677 | "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" |
| 3678 | "table.tbl td.ac { text-align: center;}\n" |
| 3679 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3680 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3681 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3682 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3683 | "\n" |
| 3684 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3685 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3686 | "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] | 3687 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3688 | "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] | 3689 | "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] | 3690 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3691 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3692 | " display:block;\n" |
| 3693 | " visibility:hidden;\n" |
| 3694 | " z-index:2147483647;\n" |
| 3695 | " position:absolute;\n" |
| 3696 | " padding:2px 4px 3px;\n" |
| 3697 | " background:#f0f060; color:#000000;\n" |
| 3698 | " border:1px solid #7040c0;\n" |
| 3699 | " white-space:nowrap;\n" |
| 3700 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3701 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3702 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3703 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3704 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3705 | "-->\n" |
| 3706 | "</style></head>\n", |
| 3707 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3708 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3709 | ); |
| 3710 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3711 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3712 | /* 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] | 3713 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3714 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3715 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3716 | 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] | 3717 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3718 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3719 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3720 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3721 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3722 | /* WARNING! this has to fit the first packet too. |
| 3723 | * We are around 3.5 kB, add adding entries will |
| 3724 | * become tricky if we want to support 4kB buffers ! |
| 3725 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3726 | chunk_appendf(&trash, |
| 3727 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3728 | PRODUCT_NAME "%s</a></h1>\n" |
| 3729 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3730 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3731 | "<h3>> General process information</h3>\n" |
| 3732 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3733 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3734 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3735 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3736 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3737 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3738 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3739 | "</td><td align=\"center\" nowrap>\n" |
| 3740 | "<table class=\"lgd\"><tr>\n" |
| 3741 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3742 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3743 | "</tr><tr>\n" |
| 3744 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3745 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3746 | "</tr><tr>\n" |
| 3747 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3748 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3749 | "</tr><tr>\n" |
| 3750 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3751 | "</tr><tr>\n" |
| 3752 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3753 | "</tr><tr>\n" |
| 3754 | "<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] | 3755 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3756 | "<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] | 3757 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3758 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3759 | "</td>" |
| 3760 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3761 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3762 | "", |
| 3763 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3764 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3765 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3766 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3767 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3768 | pid, relative_pid, global.nbproc, |
| 3769 | up / 86400, (up % 86400) / 3600, |
| 3770 | (up % 3600) / 60, (up % 60), |
| 3771 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3772 | global.rlimit_memmax ? " MB" : "", |
| 3773 | global.rlimit_nofile, |
| 3774 | global.maxsock, global.maxconn, global.maxpipes, |
| 3775 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3776 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3777 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3778 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3779 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3780 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3781 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3782 | |
| 3783 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3784 | "<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] | 3785 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3786 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3787 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3788 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3789 | STAT_SCOPE_TXT_MAXLEN); |
| 3790 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3791 | /* 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] | 3792 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3793 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3794 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3795 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3796 | 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] | 3797 | } |
| 3798 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3799 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3800 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3801 | "<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] | 3802 | uri->uri_prefix, |
| 3803 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3804 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3805 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3806 | else |
| 3807 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3808 | "<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] | 3809 | uri->uri_prefix, |
| 3810 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3811 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3812 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3813 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3814 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3815 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3816 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3817 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3818 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3819 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3820 | "", |
| 3821 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3822 | else |
| 3823 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3824 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3825 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3826 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3827 | ";norefresh", |
| 3828 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3829 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3830 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3831 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3832 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3833 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3834 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3835 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3836 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3837 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3838 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3839 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3840 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3841 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3842 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3843 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3844 | chunk_appendf(&trash, |
| 3845 | "</ul></td>" |
| 3846 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3847 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3848 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3849 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3850 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3851 | "</ul>" |
| 3852 | "</td>" |
| 3853 | "</tr></table>\n" |
| 3854 | "" |
| 3855 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3856 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3857 | if (appctx->ctx.stats.st_code) { |
| 3858 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3859 | case STAT_STATUS_DONE: |
| 3860 | chunk_appendf(&trash, |
| 3861 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3862 | "<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] | 3863 | "Action processed successfully." |
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_NONE: |
| 3870 | chunk_appendf(&trash, |
| 3871 | "<p><div class=active2>" |
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 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3874 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3875 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3876 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3877 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3878 | break; |
| 3879 | case STAT_STATUS_PART: |
| 3880 | chunk_appendf(&trash, |
| 3881 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3882 | "<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] | 3883 | "Action partially processed.<br>" |
| 3884 | "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] | 3885 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3886 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3887 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3888 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3889 | break; |
| 3890 | case STAT_STATUS_ERRP: |
| 3891 | chunk_appendf(&trash, |
| 3892 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3893 | "<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] | 3894 | "Action not processed because of invalid parameters." |
| 3895 | "<ul>" |
| 3896 | "<li>The action is maybe unknown.</li>" |
| 3897 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3898 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3899 | "</ul>" |
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 | case STAT_STATUS_EXCD: |
| 3906 | chunk_appendf(&trash, |
| 3907 | "<p><div class=active0>" |
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 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3910 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3911 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3912 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3913 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3914 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3915 | break; |
| 3916 | case STAT_STATUS_DENY: |
| 3917 | chunk_appendf(&trash, |
| 3918 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3919 | "<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] | 3920 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3921 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3922 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3923 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3924 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3925 | break; |
| 3926 | default: |
| 3927 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3928 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3929 | "<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] | 3930 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3931 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3932 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3933 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3934 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3935 | } |
| 3936 | chunk_appendf(&trash, "<p>\n"); |
| 3937 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3938 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3939 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3940 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3941 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3942 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3943 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3944 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3945 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3946 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3947 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3948 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3949 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3950 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3951 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3952 | * and the session must be closed, or -1 in case of any error. This function is |
| 3953 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3954 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3955 | 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] | 3956 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3957 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3958 | struct channel *rep = si->ib; |
| 3959 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3960 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3961 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3962 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3963 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3964 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3965 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3966 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3967 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3968 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3969 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3970 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3971 | else |
| 3972 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3973 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3974 | if (bi_putchk(rep, &trash) == -1) |
| 3975 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3976 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3977 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3978 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3979 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3980 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3981 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3982 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3983 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3984 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3985 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3986 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3987 | appctx->ctx.stats.px = proxy; |
| 3988 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3989 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3990 | /* fall through */ |
| 3991 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3992 | case STAT_ST_LIST: |
| 3993 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3994 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3995 | if (buffer_almost_full(rep->buf)) { |
| 3996 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3997 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3998 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3999 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4000 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4001 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4002 | 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] | 4003 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4004 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4005 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4006 | appctx->ctx.stats.px = px->next; |
| 4007 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4008 | } |
| 4009 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4010 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4011 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4012 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4013 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4014 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4015 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4016 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4017 | if (bi_putchk(rep, &trash) == -1) |
| 4018 | return 0; |
| 4019 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4020 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4021 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4022 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4023 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4024 | case STAT_ST_FIN: |
| 4025 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4026 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4027 | default: |
| 4028 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4029 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4030 | return -1; |
| 4031 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4032 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4033 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4034 | /* We reached the stats page through a POST request. The appctx is |
| 4035 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4036 | * Parse the posted data and enable/disable servers if necessary. |
| 4037 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4038 | */ |
| 4039 | static int stats_process_http_post(struct stream_interface *si) |
| 4040 | { |
| 4041 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4042 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4043 | |
| 4044 | struct proxy *px = NULL; |
| 4045 | struct server *sv = NULL; |
| 4046 | |
| 4047 | char key[LINESIZE]; |
| 4048 | int action = ST_ADM_ACTION_NONE; |
| 4049 | int reprocess = 0; |
| 4050 | |
| 4051 | int total_servers = 0; |
| 4052 | int altered_servers = 0; |
| 4053 | |
| 4054 | char *first_param, *cur_param, *next_param, *end_params; |
| 4055 | char *st_cur_param = NULL; |
| 4056 | char *st_next_param = NULL; |
| 4057 | |
| 4058 | struct chunk *temp; |
| 4059 | int reql; |
| 4060 | |
| 4061 | temp = get_trash_chunk(); |
| 4062 | if (temp->size < s->txn.req.body_len) { |
| 4063 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4064 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4065 | goto out; |
| 4066 | } |
| 4067 | |
| 4068 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 4069 | if (reql <= 0) { |
| 4070 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4071 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4072 | return 0; |
| 4073 | } |
| 4074 | |
| 4075 | first_param = temp->str; |
| 4076 | end_params = temp->str + reql; |
| 4077 | cur_param = next_param = end_params; |
| 4078 | *end_params = '\0'; |
| 4079 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4080 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4081 | |
| 4082 | /* |
| 4083 | * Parse the parameters in reverse order to only store the last value. |
| 4084 | * From the html form, the backend and the action are at the end. |
| 4085 | */ |
| 4086 | while (cur_param > first_param) { |
| 4087 | char *value; |
| 4088 | int poffset, plen; |
| 4089 | |
| 4090 | cur_param--; |
| 4091 | |
| 4092 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4093 | reprocess_servers: |
| 4094 | /* Parse the key */ |
| 4095 | poffset = (cur_param != first_param ? 1 : 0); |
| 4096 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4097 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4098 | strncpy(key, cur_param + poffset, plen); |
| 4099 | key[plen - 1] = '\0'; |
| 4100 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4101 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4102 | goto out; |
| 4103 | } |
| 4104 | |
| 4105 | /* Parse the value */ |
| 4106 | value = key; |
| 4107 | while (*value != '\0' && *value != '=') { |
| 4108 | value++; |
| 4109 | } |
| 4110 | if (*value == '=') { |
| 4111 | /* Ok, a value is found, we can mark the end of the key */ |
| 4112 | *value++ = '\0'; |
| 4113 | } |
| 4114 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4115 | break; |
| 4116 | |
| 4117 | /* Now we can check the key to see what to do */ |
| 4118 | if (!px && (strcmp(key, "b") == 0)) { |
| 4119 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4120 | /* the backend name is unknown or ambiguous (duplicate names) */ |
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 (!action && (strcmp(key, "action") == 0)) { |
| 4126 | if (strcmp(value, "disable") == 0) { |
| 4127 | action = ST_ADM_ACTION_DISABLE; |
| 4128 | } |
| 4129 | else if (strcmp(value, "enable") == 0) { |
| 4130 | action = ST_ADM_ACTION_ENABLE; |
| 4131 | } |
| 4132 | else if (strcmp(value, "stop") == 0) { |
| 4133 | action = ST_ADM_ACTION_STOP; |
| 4134 | } |
| 4135 | else if (strcmp(value, "start") == 0) { |
| 4136 | action = ST_ADM_ACTION_START; |
| 4137 | } |
| 4138 | else if (strcmp(value, "shutdown") == 0) { |
| 4139 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4140 | } |
| 4141 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4142 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4143 | goto out; |
| 4144 | } |
| 4145 | } |
| 4146 | else if (strcmp(key, "s") == 0) { |
| 4147 | if (!(px && action)) { |
| 4148 | /* |
| 4149 | * Indicates that we'll need to reprocess the parameters |
| 4150 | * as soon as backend and action are known |
| 4151 | */ |
| 4152 | if (!reprocess) { |
| 4153 | st_cur_param = cur_param; |
| 4154 | st_next_param = next_param; |
| 4155 | } |
| 4156 | reprocess = 1; |
| 4157 | } |
| 4158 | else if ((sv = findserver(px, value)) != NULL) { |
| 4159 | switch (action) { |
| 4160 | case ST_ADM_ACTION_DISABLE: |
| 4161 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 4162 | /* Not already in maintenance, we can change the server state */ |
| 4163 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 4164 | sv->check.state |= CHK_ST_PAUSED; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4165 | set_server_down(&sv->check); |
| 4166 | altered_servers++; |
| 4167 | total_servers++; |
| 4168 | } |
| 4169 | break; |
| 4170 | case ST_ADM_ACTION_ENABLE: |
| 4171 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
Willy Tarreau | a3ae932 | 2013-12-28 21:28:49 +0100 | [diff] [blame] | 4172 | /* Already in maintenance, we can change the server state. |
| 4173 | * If this server tracks the status of another one, |
| 4174 | * we must restore the good status. |
| 4175 | */ |
| 4176 | if (!sv->track || (sv->track->state & SRV_RUNNING)) { |
| 4177 | set_server_up(&sv->check); |
| 4178 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 4179 | } |
| 4180 | else { |
| 4181 | sv->state &= ~SRV_MAINTAIN; |
| 4182 | sv->check.state &= ~CHK_ST_PAUSED; |
| 4183 | set_server_down(&sv->check); |
| 4184 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4185 | altered_servers++; |
| 4186 | total_servers++; |
| 4187 | } |
| 4188 | break; |
| 4189 | case ST_ADM_ACTION_STOP: |
| 4190 | case ST_ADM_ACTION_START: |
| 4191 | if (action == ST_ADM_ACTION_START) |
| 4192 | sv->uweight = sv->iweight; |
| 4193 | else |
| 4194 | sv->uweight = 0; |
| 4195 | |
| 4196 | server_recalc_eweight(sv); |
| 4197 | set_server_drain_state(sv); |
| 4198 | |
| 4199 | altered_servers++; |
| 4200 | total_servers++; |
| 4201 | break; |
| 4202 | case ST_ADM_ACTION_SHUTDOWN: |
| 4203 | if (px->state != PR_STSTOPPED) { |
| 4204 | struct session *sess, *sess_bck; |
| 4205 | |
| 4206 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4207 | if (sess->srv_conn == sv) |
| 4208 | session_shutdown(sess, SN_ERR_KILLED); |
| 4209 | |
| 4210 | altered_servers++; |
| 4211 | total_servers++; |
| 4212 | } |
| 4213 | break; |
| 4214 | } |
| 4215 | } else { |
| 4216 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4217 | total_servers++; |
| 4218 | } |
| 4219 | } |
| 4220 | if (reprocess && px && action) { |
| 4221 | /* Now, we know the backend and the action chosen by the user. |
| 4222 | * We can safely restart from the first server parameter |
| 4223 | * to reprocess them |
| 4224 | */ |
| 4225 | cur_param = st_cur_param; |
| 4226 | next_param = st_next_param; |
| 4227 | reprocess = 0; |
| 4228 | goto reprocess_servers; |
| 4229 | } |
| 4230 | |
| 4231 | next_param = cur_param; |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4236 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4237 | } |
| 4238 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4239 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4240 | } |
| 4241 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4242 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4243 | } |
| 4244 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4245 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4246 | } |
| 4247 | out: |
| 4248 | return 1; |
| 4249 | } |
| 4250 | |
| 4251 | |
| 4252 | static int stats_send_http_headers(struct stream_interface *si) |
| 4253 | { |
| 4254 | struct session *s = session_from_task(si->owner); |
| 4255 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4256 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4257 | |
| 4258 | chunk_printf(&trash, |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4259 | "HTTP/1.0 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4260 | "Cache-Control: no-cache\r\n" |
| 4261 | "Connection: close\r\n" |
| 4262 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4263 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4264 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4265 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4266 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4267 | uri->refresh); |
| 4268 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4269 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4270 | |
| 4271 | s->txn.status = 200; |
| 4272 | s->logs.tv_request = now; |
| 4273 | |
| 4274 | if (bi_putchk(si->ib, &trash) == -1) |
| 4275 | return 0; |
| 4276 | |
| 4277 | return 1; |
| 4278 | } |
| 4279 | |
| 4280 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4281 | { |
| 4282 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4283 | struct session *s = session_from_task(si->owner); |
| 4284 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4285 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4286 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4287 | /* 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] | 4288 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4289 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4290 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4291 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4292 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4293 | } |
| 4294 | |
| 4295 | /* We don't want to land on the posted stats page because a refresh will |
| 4296 | * repost the data. We don't want this to happen on accident so we redirect |
| 4297 | * the browse to the stats page with a GET. |
| 4298 | */ |
| 4299 | chunk_printf(&trash, |
| 4300 | "HTTP/1.1 303 See Other\r\n" |
| 4301 | "Cache-Control: no-cache\r\n" |
| 4302 | "Content-Type: text/plain\r\n" |
| 4303 | "Connection: close\r\n" |
| 4304 | "Location: %s;st=%s%s%s%s\r\n" |
| 4305 | "\r\n", |
| 4306 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4307 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4308 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4309 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4310 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4311 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4312 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4313 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4314 | scope_txt); |
| 4315 | |
| 4316 | s->txn.status = 303; |
| 4317 | s->logs.tv_request = now; |
| 4318 | |
| 4319 | if (bi_putchk(si->ib, &trash) == -1) |
| 4320 | return 0; |
| 4321 | |
| 4322 | return 1; |
| 4323 | } |
| 4324 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4325 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4326 | * 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] | 4327 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4328 | * automatically unregisters itself once transfer is complete. |
| 4329 | */ |
| 4330 | static void http_stats_io_handler(struct stream_interface *si) |
| 4331 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4332 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4333 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4334 | struct channel *req = si->ob; |
| 4335 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4336 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4337 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4338 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4339 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4340 | /* check that the output is not closed */ |
| 4341 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4342 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4343 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4344 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4345 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4346 | if (stats_send_http_headers(si)) { |
| 4347 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4348 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4349 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4350 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4351 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4352 | } |
| 4353 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4354 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4355 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4356 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4357 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4358 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4359 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4360 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4361 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4362 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4363 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4364 | } |
| 4365 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4366 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4367 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4368 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4369 | } |
| 4370 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4371 | if (appctx->st0 == STAT_HTTP_DONE) |
| 4372 | si_shutw(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4373 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4374 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4375 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4376 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4377 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4378 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4379 | si_shutr(si); |
| 4380 | res->flags |= CF_READ_NULL; |
| 4381 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4382 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4383 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4384 | /* update all other flags and resync with the other side */ |
| 4385 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4386 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4387 | /* we don't want to expire timeouts while we're processing requests */ |
| 4388 | si->ib->rex = TICK_ETERNITY; |
| 4389 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4390 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4391 | out: |
| 4392 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4393 | /* check that we have released everything then unregister */ |
| 4394 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4395 | } |
| 4396 | } |
| 4397 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4398 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4399 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4400 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4401 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4402 | return "NONE"; |
| 4403 | return conn->ctrl->name; |
| 4404 | } |
| 4405 | |
| 4406 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4407 | { |
| 4408 | static char ptr[17]; |
| 4409 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4410 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4411 | return "NONE"; |
| 4412 | |
| 4413 | if (conn->xprt == &raw_sock) |
| 4414 | return "RAW"; |
| 4415 | |
| 4416 | #ifdef USE_OPENSSL |
| 4417 | if (conn->xprt == &ssl_sock) |
| 4418 | return "SSL"; |
| 4419 | #endif |
| 4420 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4421 | return ptr; |
| 4422 | } |
| 4423 | |
| 4424 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4425 | { |
| 4426 | static char ptr[17]; |
| 4427 | |
| 4428 | if (!conn->data) |
| 4429 | return "NONE"; |
| 4430 | |
| 4431 | if (conn->data == &sess_conn_cb) |
| 4432 | return "SESS"; |
| 4433 | |
| 4434 | if (conn->data == &si_conn_cb) |
| 4435 | return "STRM"; |
| 4436 | |
| 4437 | if (conn->data == &check_conn_cb) |
| 4438 | return "CHCK"; |
| 4439 | |
| 4440 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4441 | return ptr; |
| 4442 | } |
| 4443 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4444 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4445 | * 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] | 4446 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4447 | * 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] | 4448 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4449 | 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] | 4450 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4451 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4452 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4453 | extern const char *monthname[12]; |
| 4454 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4455 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4456 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4457 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4458 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4459 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4460 | 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] | 4461 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4462 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4463 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4464 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4465 | appctx->ctx.sess.uid = 0; |
| 4466 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4467 | return 1; |
| 4468 | } |
| 4469 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4470 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4471 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4472 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4473 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4474 | /* fall through */ |
| 4475 | |
| 4476 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4477 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4478 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4479 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4480 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4481 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4482 | 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] | 4483 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 4484 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4485 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4486 | conn = objt_conn(sess->si[0].end); |
| 4487 | 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] | 4488 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4489 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4490 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4491 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4492 | break; |
| 4493 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4494 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4495 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4496 | default: |
| 4497 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4498 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4499 | break; |
| 4500 | } |
| 4501 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4502 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4503 | " 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] | 4504 | 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] | 4505 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4506 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4507 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4508 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 4509 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 4510 | sess->listener ? sess->listener->luid : 0); |
| 4511 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4512 | if (conn) |
| 4513 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4514 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4515 | 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] | 4516 | case AF_INET: |
| 4517 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4518 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4519 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4520 | break; |
| 4521 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4522 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4523 | break; |
| 4524 | default: |
| 4525 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4526 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4527 | break; |
| 4528 | } |
| 4529 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4530 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4531 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4532 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4533 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4534 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 4535 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4536 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4537 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4538 | conn = objt_conn(sess->si[1].end); |
| 4539 | if (conn) |
| 4540 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4541 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4542 | 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] | 4543 | case AF_INET: |
| 4544 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4545 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4546 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4547 | break; |
| 4548 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4549 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4550 | break; |
| 4551 | default: |
| 4552 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4553 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4554 | break; |
| 4555 | } |
| 4556 | |
| 4557 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4558 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4559 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4560 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 4561 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4562 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4563 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4564 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4565 | if (conn) |
| 4566 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4567 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4568 | 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] | 4569 | case AF_INET: |
| 4570 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4571 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4572 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4573 | break; |
| 4574 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4575 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4576 | break; |
| 4577 | default: |
| 4578 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4579 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4580 | break; |
| 4581 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4582 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4583 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4584 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4585 | sess->task, |
| 4586 | sess->task->state, |
| 4587 | sess->task->nice, sess->task->calls, |
| 4588 | sess->task->expire ? |
| 4589 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4590 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4591 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4592 | task_in_rq(sess->task) ? ", running" : ""); |
| 4593 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4594 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4595 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4596 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4597 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4598 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4599 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4600 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4601 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4602 | |
| 4603 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4604 | " 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] | 4605 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4606 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4607 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4608 | obj_type_name(sess->si[0].end), |
| 4609 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4610 | sess->si[0].exp ? |
| 4611 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4612 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4613 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4614 | sess->si[0].err_type); |
| 4615 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4616 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4617 | " 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] | 4618 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4619 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4620 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4621 | obj_type_name(sess->si[1].end), |
| 4622 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4623 | sess->si[1].exp ? |
| 4624 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4625 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4626 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4627 | sess->si[1].err_type); |
| 4628 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4629 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4630 | chunk_appendf(&trash, |
| 4631 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4632 | conn, |
| 4633 | get_conn_ctrl_name(conn), |
| 4634 | get_conn_xprt_name(conn), |
| 4635 | get_conn_data_name(conn), |
| 4636 | obj_type_name(conn->target), |
| 4637 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4638 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4639 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 4640 | " 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] | 4641 | conn->flags, |
| 4642 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4643 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4644 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4645 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4646 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4647 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 4648 | chunk_appendf(&trash, |
| 4649 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4650 | tmpctx, |
| 4651 | tmpctx->st0, |
| 4652 | tmpctx->st1, |
| 4653 | tmpctx->st2, |
| 4654 | tmpctx->applet->name); |
| 4655 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4656 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4657 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4658 | chunk_appendf(&trash, |
| 4659 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4660 | conn, |
| 4661 | get_conn_ctrl_name(conn), |
| 4662 | get_conn_xprt_name(conn), |
| 4663 | get_conn_data_name(conn), |
| 4664 | obj_type_name(conn->target), |
| 4665 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4666 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4667 | chunk_appendf(&trash, |
| 4668 | " 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] | 4669 | conn->flags, |
| 4670 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4671 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4672 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4673 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4674 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4675 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 4676 | chunk_appendf(&trash, |
| 4677 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4678 | tmpctx, |
| 4679 | tmpctx->st0, |
| 4680 | tmpctx->st1, |
| 4681 | tmpctx->st2, |
| 4682 | tmpctx->applet->name); |
| 4683 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4684 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4685 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4686 | " 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] | 4687 | " an_exp=%s", |
| 4688 | sess->req, |
| 4689 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4690 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4691 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4692 | sess->req->analyse_exp ? |
| 4693 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4694 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4695 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4696 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4697 | " rex=%s", |
| 4698 | sess->req->rex ? |
| 4699 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4700 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4701 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4702 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4703 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4704 | " 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] | 4705 | sess->req->wex ? |
| 4706 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4707 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4708 | sess->req->buf, |
| 4709 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4710 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4711 | sess->txn.req.next, sess->req->buf->i, |
| 4712 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4713 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4714 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4715 | " 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] | 4716 | " an_exp=%s", |
| 4717 | sess->rep, |
| 4718 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4719 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4720 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4721 | sess->rep->analyse_exp ? |
| 4722 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4723 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4724 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4725 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4726 | " rex=%s", |
| 4727 | sess->rep->rex ? |
| 4728 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4729 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4730 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4731 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4732 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4733 | " 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] | 4734 | sess->rep->wex ? |
| 4735 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4736 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4737 | sess->rep->buf, |
| 4738 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4739 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4740 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4741 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4742 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4743 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4744 | return 0; |
| 4745 | |
| 4746 | /* use other states to dump the contents */ |
| 4747 | } |
| 4748 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4749 | appctx->ctx.sess.uid = 0; |
| 4750 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4751 | return 1; |
| 4752 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4753 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4754 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4755 | { |
| 4756 | struct appctx *appctx = __objt_appctx(si->end); |
| 4757 | |
| 4758 | switch (appctx->st2) { |
| 4759 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4760 | /* Display the column headers. If the message cannot be sent, |
| 4761 | * quit the fucntion with returning 0. The function is called |
| 4762 | * later and restart at the state "STAT_ST_INIT". |
| 4763 | */ |
| 4764 | chunk_reset(&trash); |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 4765 | chunk_appendf(&trash, "# id (name) description\n"); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4766 | if (bi_putchk(si->ib, &trash) == -1) |
| 4767 | return 0; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4768 | |
| 4769 | /* Now, we start the browsing of the references lists. |
| 4770 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 4771 | * avalaible field of this pointer is <list>. It is used with the function |
| 4772 | * pat_list_get_next() for retruning the first avalaible entry |
| 4773 | */ |
| 4774 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 4775 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 4776 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4777 | appctx->st2 = STAT_ST_LIST; |
| 4778 | /* fall through */ |
| 4779 | |
| 4780 | case STAT_ST_LIST: |
| 4781 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4782 | chunk_reset(&trash); |
| 4783 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4784 | /* Build messages. If the reference is used by another category than |
| 4785 | * the listed categorie, display the information in the massage. |
| 4786 | */ |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 4787 | chunk_appendf(&trash, "%d (%s) %s", appctx->ctx.map.ref->unique_id, |
| 4788 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 4789 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4790 | |
| 4791 | if (appctx->ctx.map.display_flags & PAT_REF_MAP) { |
| 4792 | if (appctx->ctx.map.ref->flags & PAT_REF_ACL) |
| 4793 | chunk_appendf(&trash, " - also used by an ACL"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4794 | } |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4795 | else { |
| 4796 | if (appctx->ctx.map.ref->flags & PAT_REF_MAP) |
| 4797 | chunk_appendf(&trash, " - also used by a map"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4798 | } |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4799 | chunk_appendf(&trash, "\n"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4800 | |
| 4801 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4802 | /* let's try again later from this session. We add ourselves into |
| 4803 | * this session's users so that it can remove us upon termination. |
| 4804 | */ |
| 4805 | return 0; |
| 4806 | } |
| 4807 | |
| 4808 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4809 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 4810 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4811 | } |
| 4812 | |
| 4813 | appctx->st2 = STAT_ST_FIN; |
| 4814 | /* fall through */ |
| 4815 | |
| 4816 | default: |
| 4817 | appctx->st2 = STAT_ST_FIN; |
| 4818 | return 1; |
| 4819 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4820 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4821 | } |
| 4822 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4823 | static int stats_map_lookup(struct stream_interface *si) |
| 4824 | { |
| 4825 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4826 | struct sample sample; |
| 4827 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4828 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4829 | |
| 4830 | switch (appctx->st2) { |
| 4831 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4832 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 4833 | 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] | 4834 | 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] | 4835 | appctx->st2 = STAT_ST_LIST; |
| 4836 | /* fall through */ |
| 4837 | |
| 4838 | case STAT_ST_LIST: |
| 4839 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4840 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4841 | /* initialise chunk to build new message */ |
| 4842 | chunk_reset(&trash); |
| 4843 | |
| 4844 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 4845 | sample.type = SMP_T_STR; |
| 4846 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4847 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 4848 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 4849 | if (appctx->ctx.map.expr->pat_head->match && |
| 4850 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4851 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 4852 | else |
| 4853 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4854 | |
| 4855 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4856 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 4857 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 4858 | break; |
| 4859 | if (match_method >= PAT_MATCH_NUM) |
| 4860 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 4861 | else |
| 4862 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4863 | |
| 4864 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4865 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4866 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 4867 | chunk_appendf(&trash, ", found=no"); |
| 4868 | else |
| 4869 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4870 | } |
| 4871 | |
| 4872 | /* Display match and match info */ |
| 4873 | else { |
| 4874 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4875 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 4876 | chunk_appendf(&trash, ", found=yes"); |
| 4877 | else |
| 4878 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4879 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4880 | /* display index mode */ |
| 4881 | if (pat->flags & PAT_F_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4882 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4883 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4884 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4885 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4886 | /* case sensitive */ |
| 4887 | if (pat->flags & PAT_F_IGNORE_CASE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4888 | chunk_appendf(&trash, ", case=insensitive"); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4889 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4890 | chunk_appendf(&trash, ", case=sensitive"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4891 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4892 | /* display source */ |
| 4893 | if (pat->flags & PAT_F_FROM_FILE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4894 | chunk_appendf(&trash, ", src=file"); |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 4895 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4896 | chunk_appendf(&trash, ", src=conf"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4897 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame^] | 4898 | /* display pattern */ |
| 4899 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 4900 | if (pat->ref && pat->ref->pattern) |
| 4901 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 4902 | else |
| 4903 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4904 | } |
| 4905 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame^] | 4906 | if (pat->ref && pat->ref->pattern) |
| 4907 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 4908 | else |
| 4909 | chunk_appendf(&trash, ", pattern=unknown"); |
| 4910 | } |
| 4911 | |
| 4912 | /* display return value */ |
| 4913 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 4914 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4915 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame^] | 4916 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4917 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame^] | 4918 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4919 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4920 | } |
| 4921 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4922 | chunk_appendf(&trash, "\n"); |
| 4923 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4924 | /* display response */ |
| 4925 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4926 | /* let's try again later from this session. We add ourselves into |
| 4927 | * this session's users so that it can remove us upon termination. |
| 4928 | */ |
| 4929 | return 0; |
| 4930 | } |
| 4931 | |
| 4932 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4933 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 4934 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4935 | } |
| 4936 | |
| 4937 | appctx->st2 = STAT_ST_FIN; |
| 4938 | /* fall through */ |
| 4939 | |
| 4940 | default: |
| 4941 | appctx->st2 = STAT_ST_FIN; |
| 4942 | free(appctx->ctx.map.chunk.str); |
| 4943 | return 1; |
| 4944 | } |
| 4945 | } |
| 4946 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4947 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4948 | { |
| 4949 | struct appctx *appctx = __objt_appctx(si->end); |
| 4950 | |
| 4951 | switch (appctx->st2) { |
| 4952 | |
| 4953 | case STAT_ST_INIT: |
| 4954 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4955 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 4956 | struct pat_ref_elt *, list); |
| 4957 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 4958 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4959 | appctx->st2 = STAT_ST_LIST; |
| 4960 | /* fall through */ |
| 4961 | |
| 4962 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4963 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4964 | chunk_reset(&trash); |
| 4965 | |
| 4966 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4967 | if (appctx->ctx.map.elt->sample) |
| 4968 | chunk_appendf(&trash, "%s %s\n", |
| 4969 | appctx->ctx.map.elt->pattern, appctx->ctx.map.elt->sample); |
| 4970 | else |
| 4971 | chunk_appendf(&trash, "%s\n", appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4972 | |
| 4973 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4974 | /* let's try again later from this session. We add ourselves into |
| 4975 | * this session's users so that it can remove us upon termination. |
| 4976 | */ |
| 4977 | return 0; |
| 4978 | } |
| 4979 | |
| 4980 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4981 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 4982 | struct pat_ref_elt *, list); |
| 4983 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4984 | break; |
| 4985 | } |
| 4986 | |
| 4987 | appctx->st2 = STAT_ST_FIN; |
| 4988 | /* fall through */ |
| 4989 | |
| 4990 | default: |
| 4991 | appctx->st2 = STAT_ST_FIN; |
| 4992 | return 1; |
| 4993 | } |
| 4994 | } |
| 4995 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4996 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4997 | * 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] | 4998 | * to be called again, otherwise non-zero. It is designed to be called |
| 4999 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5000 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5001 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5002 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5003 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5004 | struct connection *conn; |
| 5005 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5006 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5007 | /* If we're forced to shut down, we might have to remove our |
| 5008 | * reference to the last session being dumped. |
| 5009 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5010 | if (appctx->st2 == STAT_ST_LIST) { |
| 5011 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5012 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5013 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5014 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5015 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5016 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5017 | } |
| 5018 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5019 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5020 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5021 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5022 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5023 | /* the function had not been called yet, let's prepare the |
| 5024 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5025 | * pointer to the first in the global list. When a target |
| 5026 | * session is being destroyed, it is responsible for updating |
| 5027 | * this pointer. We know we have reached the end when this |
| 5028 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5029 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5030 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5031 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5032 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5033 | /* fall through */ |
| 5034 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5035 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5036 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5037 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5038 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5039 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5043 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5044 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5045 | struct session *curr_sess; |
| 5046 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5047 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5048 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5049 | if (appctx->ctx.sess.target) { |
| 5050 | 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] | 5051 | goto next_sess; |
| 5052 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5053 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5054 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5055 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5056 | return 0; |
| 5057 | |
| 5058 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5059 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5060 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5061 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5062 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5063 | break; |
| 5064 | } |
| 5065 | else |
| 5066 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5067 | } |
| 5068 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5069 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5070 | "%p: proto=%s", |
| 5071 | curr_sess, |
| 5072 | curr_sess->listener->proto->name); |
| 5073 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5074 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5075 | conn = objt_conn(curr_sess->si[0].end); |
| 5076 | 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] | 5077 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5078 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5079 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5080 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5081 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5082 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5083 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5084 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5085 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5086 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5087 | break; |
| 5088 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5089 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5090 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5091 | curr_sess->listener->luid, |
| 5092 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5093 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5094 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5095 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5096 | break; |
| 5097 | } |
| 5098 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5099 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5100 | " ts=%02x age=%s calls=%d", |
| 5101 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5102 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5103 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5104 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5105 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5106 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5107 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5108 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5109 | curr_sess->req->analysers, |
| 5110 | curr_sess->req->rex ? |
| 5111 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 5112 | TICKS_TO_MS(1000)) : ""); |
| 5113 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5114 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5115 | ",wx=%s", |
| 5116 | curr_sess->req->wex ? |
| 5117 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 5118 | TICKS_TO_MS(1000)) : ""); |
| 5119 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5120 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5121 | ",ax=%s]", |
| 5122 | curr_sess->req->analyse_exp ? |
| 5123 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 5124 | TICKS_TO_MS(1000)) : ""); |
| 5125 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5126 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5127 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5128 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5129 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5130 | curr_sess->rep->analysers, |
| 5131 | curr_sess->rep->rex ? |
| 5132 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5133 | TICKS_TO_MS(1000)) : ""); |
| 5134 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5135 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5136 | ",wx=%s", |
| 5137 | curr_sess->rep->wex ? |
| 5138 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 5139 | TICKS_TO_MS(1000)) : ""); |
| 5140 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5141 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5142 | ",ax=%s]", |
| 5143 | curr_sess->rep->analyse_exp ? |
| 5144 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5145 | TICKS_TO_MS(1000)) : ""); |
| 5146 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5147 | conn = objt_conn(curr_sess->si[0].end); |
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 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5150 | curr_sess->si[0].state, |
| 5151 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5152 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5153 | curr_sess->si[0].exp ? |
| 5154 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5155 | TICKS_TO_MS(1000)) : ""); |
| 5156 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5157 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5158 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5159 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5160 | curr_sess->si[1].state, |
| 5161 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5162 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5163 | curr_sess->si[1].exp ? |
| 5164 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5165 | TICKS_TO_MS(1000)) : ""); |
| 5166 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5167 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5168 | " exp=%s", |
| 5169 | curr_sess->task->expire ? |
| 5170 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5171 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5172 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5173 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5174 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5175 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5176 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5177 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5178 | /* let's try again later from this session. We add ourselves into |
| 5179 | * this session's users so that it can remove us upon termination. |
| 5180 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5181 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5182 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5183 | } |
| 5184 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5185 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5186 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5187 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5188 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5189 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5190 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5191 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5192 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5193 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5194 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5195 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5196 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5197 | return 0; |
| 5198 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5199 | appctx->ctx.sess.target = NULL; |
| 5200 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5201 | return 1; |
| 5202 | } |
| 5203 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5204 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5205 | /* fall through */ |
| 5206 | |
| 5207 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5208 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5209 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5210 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5211 | } |
| 5212 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5213 | /* This is called when the stream interface is closed. For instance, upon an |
| 5214 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5215 | * remove back references to the session currently being dumped. |
| 5216 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5217 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5218 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5219 | struct appctx *appctx = __objt_appctx(si->end); |
| 5220 | |
| 5221 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5222 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5223 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5224 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5225 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5226 | free(appctx->ctx.map.chunk.str); |
| 5227 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5228 | } |
| 5229 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5230 | /* This function is used to either dump tables states (when action is set |
| 5231 | * 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] | 5232 | * It returns 0 if the output buffer is full and it needs to be called |
| 5233 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5234 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5235 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5236 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5237 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5238 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5239 | struct ebmb_node *eb; |
| 5240 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5241 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5242 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5243 | |
| 5244 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5245 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5246 | * - STAT_ST_INIT : the first call |
| 5247 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5248 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5249 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5250 | * and the entry pointer points to the next entry to be dumped, |
| 5251 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5252 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5253 | * data though. |
| 5254 | */ |
| 5255 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5256 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5257 | /* 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] | 5258 | if (appctx->st2 == STAT_ST_LIST) { |
| 5259 | appctx->ctx.table.entry->ref_cnt--; |
| 5260 | 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] | 5261 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5262 | return 1; |
| 5263 | } |
| 5264 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5265 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5266 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5267 | while (appctx->st2 != STAT_ST_FIN) { |
| 5268 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5269 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5270 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5271 | if (!appctx->ctx.table.proxy) |
| 5272 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5273 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5274 | appctx->ctx.table.entry = NULL; |
| 5275 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5276 | break; |
| 5277 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5278 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5279 | if (!appctx->ctx.table.proxy || |
| 5280 | (appctx->ctx.table.target && |
| 5281 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5282 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5283 | break; |
| 5284 | } |
| 5285 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5286 | if (appctx->ctx.table.proxy->table.size) { |
| 5287 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5288 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5289 | return 0; |
| 5290 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5291 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5292 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5293 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5294 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5295 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5296 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5297 | appctx->ctx.table.entry->ref_cnt++; |
| 5298 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5299 | break; |
| 5300 | } |
| 5301 | } |
| 5302 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5303 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5304 | break; |
| 5305 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5306 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5307 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5308 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5309 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5310 | /* we're filtering on some data contents */ |
| 5311 | void *ptr; |
| 5312 | long long data; |
| 5313 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5314 | dt = appctx->ctx.table.data_type; |
| 5315 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5316 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5317 | dt); |
| 5318 | |
| 5319 | data = 0; |
| 5320 | switch (stktable_data_types[dt].std_type) { |
| 5321 | case STD_T_SINT: |
| 5322 | data = stktable_data_cast(ptr, std_t_sint); |
| 5323 | break; |
| 5324 | case STD_T_UINT: |
| 5325 | data = stktable_data_cast(ptr, std_t_uint); |
| 5326 | break; |
| 5327 | case STD_T_ULL: |
| 5328 | data = stktable_data_cast(ptr, std_t_ull); |
| 5329 | break; |
| 5330 | case STD_T_FRQP: |
| 5331 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5332 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5333 | break; |
| 5334 | } |
| 5335 | |
| 5336 | /* 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] | 5337 | if ((data < appctx->ctx.table.value && |
| 5338 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5339 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5340 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5341 | (data == appctx->ctx.table.value && |
| 5342 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5343 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5344 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5345 | (data > appctx->ctx.table.value && |
| 5346 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5347 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5348 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5349 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5350 | } |
| 5351 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5352 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5353 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5354 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5355 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5356 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5357 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5358 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5359 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5360 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5361 | struct stksess *old = appctx->ctx.table.entry; |
| 5362 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5363 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5364 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5365 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5366 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5367 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5368 | break; |
| 5369 | } |
| 5370 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5371 | |
| 5372 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5373 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5374 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5375 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5376 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5377 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5378 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5379 | break; |
| 5380 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5381 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5382 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5383 | break; |
| 5384 | } |
| 5385 | } |
| 5386 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5387 | } |
| 5388 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5389 | /* 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] | 5390 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5391 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5392 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5393 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5394 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5395 | * after the offset. The new pointer is returned. |
| 5396 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5397 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5398 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5399 | { |
| 5400 | int end; |
| 5401 | unsigned char c; |
| 5402 | |
| 5403 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5404 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5405 | return ptr; |
| 5406 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5407 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5408 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5409 | while (ptr < len && ptr < bsize) { |
| 5410 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5411 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5412 | if (out->len > end - 2) |
| 5413 | break; |
| 5414 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5415 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5416 | if (out->len > end - 3) |
| 5417 | break; |
| 5418 | out->str[out->len++] = '\\'; |
| 5419 | switch (c) { |
| 5420 | case '\t': c = 't'; break; |
| 5421 | case '\n': c = 'n'; break; |
| 5422 | case '\r': c = 'r'; break; |
| 5423 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5424 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5425 | } |
| 5426 | out->str[out->len++] = c; |
| 5427 | } else { |
| 5428 | if (out->len > end - 5) |
| 5429 | break; |
| 5430 | out->str[out->len++] = '\\'; |
| 5431 | out->str[out->len++] = 'x'; |
| 5432 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5433 | out->str[out->len++] = hextab[c & 0xF]; |
| 5434 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5435 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5436 | /* we had a line break, let's return now */ |
| 5437 | out->str[out->len++] = '\n'; |
| 5438 | *line = ptr; |
| 5439 | return ptr; |
| 5440 | } |
| 5441 | } |
| 5442 | /* we have an incomplete line, we return it as-is */ |
| 5443 | out->str[out->len++] = '\n'; |
| 5444 | return ptr; |
| 5445 | } |
| 5446 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5447 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5448 | * 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] | 5449 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5450 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5451 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5452 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5453 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5454 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5455 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5456 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5457 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5458 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5459 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5460 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5461 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5462 | /* the function had not been called yet, let's prepare the |
| 5463 | * buffer for a response. |
| 5464 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5465 | struct tm tm; |
| 5466 | |
| 5467 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5468 | 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] | 5469 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5470 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5471 | error_snapshot_id); |
| 5472 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5473 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5474 | /* Socket buffer full. Let's try again later from the same point */ |
| 5475 | return 0; |
| 5476 | } |
| 5477 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5478 | appctx->ctx.errors.px = proxy; |
| 5479 | appctx->ctx.errors.buf = 0; |
| 5480 | appctx->ctx.errors.bol = 0; |
| 5481 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | /* we have two inner loops here, one for the proxy, the other one for |
| 5485 | * the buffer. |
| 5486 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5487 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5488 | struct error_snapshot *es; |
| 5489 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5490 | if (appctx->ctx.errors.buf == 0) |
| 5491 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5492 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5493 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5494 | |
| 5495 | if (!es->when.tv_sec) |
| 5496 | goto next; |
| 5497 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5498 | if (appctx->ctx.errors.iid >= 0 && |
| 5499 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 5500 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5501 | goto next; |
| 5502 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5503 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5504 | /* just print headers now */ |
| 5505 | |
| 5506 | char pn[INET6_ADDRSTRLEN]; |
| 5507 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5508 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5509 | |
| 5510 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5511 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5512 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5513 | 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] | 5514 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5515 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 5516 | case AF_INET: |
| 5517 | case AF_INET6: |
| 5518 | port = get_host_port(&es->src); |
| 5519 | break; |
| 5520 | default: |
| 5521 | port = 0; |
| 5522 | } |
| 5523 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5524 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5525 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5526 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5527 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5528 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5529 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5530 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 5531 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5532 | break; |
| 5533 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5534 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5535 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5536 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5537 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5538 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5539 | break; |
| 5540 | } |
| 5541 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5542 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5543 | ", server %s (#%d), event #%u\n" |
| 5544 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 5545 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 5546 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 5547 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 5548 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 5549 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 5550 | es->ev_id, |
| 5551 | pn, port, es->sid, es->s_flags, |
| 5552 | es->state, es->m_flags, es->t_flags, |
| 5553 | es->m_clen, es->m_blen, |
| 5554 | es->b_flags, es->b_out, es->b_tot, |
| 5555 | es->len, es->b_wrap, es->pos); |
| 5556 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5557 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5558 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5559 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5560 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5561 | appctx->ctx.errors.ptr = 0; |
| 5562 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5563 | } |
| 5564 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5565 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5566 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5567 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5568 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5569 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5570 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5571 | goto next; |
| 5572 | } |
| 5573 | |
| 5574 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5575 | 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] | 5576 | int newptr; |
| 5577 | int newline; |
| 5578 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5579 | newline = appctx->ctx.errors.bol; |
| 5580 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 5581 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5582 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5583 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5584 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5585 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5586 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5587 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5588 | appctx->ctx.errors.ptr = newptr; |
| 5589 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5590 | }; |
| 5591 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5592 | appctx->ctx.errors.bol = 0; |
| 5593 | appctx->ctx.errors.ptr = -1; |
| 5594 | appctx->ctx.errors.buf++; |
| 5595 | if (appctx->ctx.errors.buf > 1) { |
| 5596 | appctx->ctx.errors.buf = 0; |
| 5597 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5598 | } |
| 5599 | } |
| 5600 | |
| 5601 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5602 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5603 | } |
| 5604 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5605 | /* parse the "level" argument on the bind lines */ |
| 5606 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 5607 | { |
| 5608 | if (!*args[cur_arg + 1]) { |
| 5609 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 5610 | return ERR_ALERT | ERR_FATAL; |
| 5611 | } |
| 5612 | |
| 5613 | if (!strcmp(args[cur_arg+1], "user")) |
| 5614 | conf->level = ACCESS_LVL_USER; |
| 5615 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 5616 | conf->level = ACCESS_LVL_OPER; |
| 5617 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 5618 | conf->level = ACCESS_LVL_ADMIN; |
| 5619 | else { |
| 5620 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 5621 | args[cur_arg], args[cur_arg+1]); |
| 5622 | return ERR_ALERT | ERR_FATAL; |
| 5623 | } |
| 5624 | |
| 5625 | return 0; |
| 5626 | } |
| 5627 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5628 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5629 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5630 | .name = "<STATS>", /* used for logging */ |
| 5631 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 5632 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5633 | }; |
| 5634 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5635 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5636 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5637 | .name = "<CLI>", /* used for logging */ |
| 5638 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5639 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5640 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5641 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 5642 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5643 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 5644 | { 0, NULL, NULL }, |
| 5645 | }}; |
| 5646 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5647 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 5648 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 5649 | { NULL, NULL, 0 }, |
| 5650 | }}; |
| 5651 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5652 | __attribute__((constructor)) |
| 5653 | static void __dumpstats_module_init(void) |
| 5654 | { |
| 5655 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5656 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5657 | } |
| 5658 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5659 | /* |
| 5660 | * Local variables: |
| 5661 | * c-indent-level: 8 |
| 5662 | * c-basic-offset: 8 |
| 5663 | * End: |
| 5664 | */ |