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 */ |
| 82 | STAT_CLI_O_MAPS, /* list all maps */ |
| 83 | STAT_CLI_O_MAP, /* list all map entries of a map */ |
| 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 | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 96 | static int stats_maps_list(struct stream_interface *si); |
| 97 | static int stats_map_list(struct stream_interface *si); |
| 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 | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 152 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 153 | " get map : reports the keys and values matching a sample for a map\n" |
| 154 | " set map : modify map entry\n" |
| 155 | " add map : add map entry\n" |
| 156 | " del map : delete map entry\n" |
| 157 | " clear map <id> : clear the content of this map\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 158 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 159 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 160 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 161 | "Permission denied\n" |
| 162 | ""; |
| 163 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 164 | /* data transmission states for the stats responses */ |
| 165 | enum { |
| 166 | STAT_ST_INIT = 0, |
| 167 | STAT_ST_HEAD, |
| 168 | STAT_ST_INFO, |
| 169 | STAT_ST_LIST, |
| 170 | STAT_ST_END, |
| 171 | STAT_ST_FIN, |
| 172 | }; |
| 173 | |
| 174 | /* data transmission states for the stats responses inside a proxy */ |
| 175 | enum { |
| 176 | STAT_PX_ST_INIT = 0, |
| 177 | STAT_PX_ST_TH, |
| 178 | STAT_PX_ST_FE, |
| 179 | STAT_PX_ST_LI, |
| 180 | STAT_PX_ST_SV, |
| 181 | STAT_PX_ST_BE, |
| 182 | STAT_PX_ST_END, |
| 183 | STAT_PX_ST_FIN, |
| 184 | }; |
| 185 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 186 | extern const char *stat_status_codes[]; |
| 187 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 188 | /* 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] | 189 | * 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] | 190 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 191 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 192 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 193 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 194 | s->target = &cli_applet.obj_type; |
Willy Tarreau | 4171e9e | 2013-12-01 12:32:30 +0100 | [diff] [blame] | 195 | /* 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] | 196 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 197 | tv_zero(&s->logs.tv_request); |
| 198 | s->logs.t_queue = 0; |
| 199 | s->logs.t_connect = 0; |
| 200 | s->logs.t_data = 0; |
| 201 | s->logs.t_close = 0; |
| 202 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 203 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 204 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 205 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 206 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 207 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 208 | if (s->listener->timeout) { |
| 209 | s->req->rto = *s->listener->timeout; |
| 210 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 211 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 212 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 213 | } |
| 214 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 215 | /* allocate a new stats frontend named <name>, and return it |
| 216 | * (or NULL in case of lack of memory). |
| 217 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 218 | 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] | 219 | { |
| 220 | struct proxy *fe; |
| 221 | |
| 222 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 223 | if (!fe) |
| 224 | return NULL; |
| 225 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 226 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 227 | fe->next = proxy; |
| 228 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 229 | fe->last_change = now.tv_sec; |
| 230 | fe->id = strdup("GLOBAL"); |
| 231 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 232 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 233 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 234 | fe->conf.file = strdup(file); |
| 235 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 236 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 237 | |
| 238 | /* the stats frontend is the only one able to assign ID #0 */ |
| 239 | fe->conf.id.key = fe->uuid = 0; |
| 240 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 241 | return fe; |
| 242 | } |
| 243 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 244 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 245 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 246 | * error message into the <err> buffer which will be preallocated. The trailing |
| 247 | * '\n' must not be written. The function must be called with <args> pointing to |
| 248 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 249 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 250 | 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] | 251 | struct proxy *defpx, const char *file, int line, |
| 252 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 253 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 254 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 255 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 256 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 257 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 258 | int cur_arg; |
| 259 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 260 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 261 | 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] | 262 | return -1; |
| 263 | } |
| 264 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 265 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 266 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 267 | 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] | 268 | return -1; |
| 269 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 270 | } |
| 271 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 272 | 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] | 273 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 274 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 275 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 276 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 277 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 278 | return -1; |
| 279 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 280 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 281 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 282 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 283 | static int bind_dumped; |
| 284 | struct bind_kw *kw; |
| 285 | |
| 286 | kw = bind_find_kw(args[cur_arg]); |
| 287 | if (kw) { |
| 288 | if (!kw->parse) { |
| 289 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 290 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 291 | return -1; |
| 292 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 293 | |
| 294 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 295 | if (err && *err) |
| 296 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 297 | else |
| 298 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 299 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 300 | return -1; |
| 301 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 302 | |
| 303 | cur_arg += 1 + kw->skip; |
| 304 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 305 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 306 | |
| 307 | if (!bind_dumped) { |
| 308 | bind_dump_kws(err); |
| 309 | indent_msg(err, 4); |
| 310 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 311 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 312 | |
| 313 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 314 | args[0], args[1], args[cur_arg], |
| 315 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 316 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 317 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 318 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 319 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 320 | l->maxconn = global.stats_fe->maxconn; |
| 321 | l->backlog = global.stats_fe->backlog; |
| 322 | l->timeout = &global.stats_fe->timeout.client; |
| 323 | l->accept = session_accept; |
| 324 | l->handler = process_session; |
| 325 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 326 | l->nice = -64; /* we want to boost priority for local stats */ |
| 327 | global.maxsock += l->maxconn; |
| 328 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 329 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 330 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 331 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 332 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 333 | |
| 334 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 335 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 336 | return -1; |
| 337 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 338 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 339 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 340 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 341 | return -1; |
| 342 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 343 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 344 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 345 | 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] | 346 | return -1; |
| 347 | } |
| 348 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 349 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 350 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 351 | else if (!strcmp(args[1], "maxconn")) { |
| 352 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 353 | |
| 354 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 355 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 356 | return -1; |
| 357 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 358 | |
| 359 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 360 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 361 | 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] | 362 | return -1; |
| 363 | } |
| 364 | } |
| 365 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 366 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 367 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 368 | int cur_arg = 2; |
| 369 | unsigned int set = 0; |
| 370 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 371 | if (!global.stats_fe) { |
| 372 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 373 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 374 | return -1; |
| 375 | } |
| 376 | } |
| 377 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 378 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 379 | unsigned int low, high; |
| 380 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 381 | if (strcmp(args[cur_arg], "all") == 0) { |
| 382 | set = 0; |
| 383 | break; |
| 384 | } |
| 385 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 386 | set |= 0x55555555; |
| 387 | } |
| 388 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 389 | set |= 0xAAAAAAAA; |
| 390 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 391 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 392 | char *dash = strchr(args[cur_arg], '-'); |
| 393 | |
| 394 | low = high = str2uic(args[cur_arg]); |
| 395 | if (dash) |
| 396 | high = str2uic(dash + 1); |
| 397 | |
| 398 | if (high < low) { |
| 399 | unsigned int swap = low; |
| 400 | low = high; |
| 401 | high = swap; |
| 402 | } |
| 403 | |
| 404 | if (low < 1 || high > 32) { |
| 405 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 406 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 407 | return -1; |
| 408 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 409 | |
| 410 | while (low <= high) |
| 411 | set |= 1 << (low++ - 1); |
| 412 | } |
| 413 | else { |
| 414 | memprintf(err, |
| 415 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 416 | args[0], args[1]); |
| 417 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 418 | } |
| 419 | cur_arg++; |
| 420 | } |
| 421 | global.stats_fe->bind_proc = set; |
| 422 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 423 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 424 | 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] | 425 | return -1; |
| 426 | } |
| 427 | return 0; |
| 428 | } |
| 429 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 430 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 431 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 432 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 433 | * 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] | 434 | */ |
| 435 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 436 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 437 | chunk_appendf(&trash, |
| 438 | "# pxname,svname," |
| 439 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 440 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 441 | "bin,bout," |
| 442 | "dreq,dresp," |
| 443 | "ereq,econ,eresp," |
| 444 | "wretr,wredis," |
| 445 | "status,weight,act,bck," |
| 446 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 447 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 448 | "rate,rate_lim,rate_max," |
| 449 | "check_status,check_code,check_duration," |
| 450 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 451 | "req_rate,req_rate_max,req_tot," |
| 452 | "cli_abrt,srv_abrt," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 453 | "comp_in,comp_out,comp_byp,comp_rsp,lastsess," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 454 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 455 | } |
| 456 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 457 | /* print a string of text buffer to <out>. The format is : |
| 458 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 459 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 460 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 461 | */ |
| 462 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 463 | { |
| 464 | unsigned char c; |
| 465 | int ptr = 0; |
| 466 | |
| 467 | while (buf[ptr] && ptr < bsize) { |
| 468 | c = buf[ptr]; |
| 469 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 470 | if (out->len > out->size - 1) |
| 471 | break; |
| 472 | out->str[out->len++] = c; |
| 473 | } |
| 474 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 475 | if (out->len > out->size - 2) |
| 476 | break; |
| 477 | out->str[out->len++] = '\\'; |
| 478 | switch (c) { |
| 479 | case ' ': c = ' '; break; |
| 480 | case '\t': c = 't'; break; |
| 481 | case '\n': c = 'n'; break; |
| 482 | case '\r': c = 'r'; break; |
| 483 | case '\e': c = 'e'; break; |
| 484 | case '\\': c = '\\'; break; |
| 485 | } |
| 486 | out->str[out->len++] = c; |
| 487 | } |
| 488 | else { |
| 489 | if (out->len > out->size - 4) |
| 490 | break; |
| 491 | out->str[out->len++] = '\\'; |
| 492 | out->str[out->len++] = 'x'; |
| 493 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 494 | out->str[out->len++] = hextab[c & 0xF]; |
| 495 | } |
| 496 | ptr++; |
| 497 | } |
| 498 | |
| 499 | return ptr; |
| 500 | } |
| 501 | |
| 502 | /* print a buffer in hexa. |
| 503 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 504 | */ |
| 505 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 506 | { |
| 507 | unsigned char c; |
| 508 | int ptr = 0; |
| 509 | |
| 510 | while (ptr < bsize) { |
| 511 | c = buf[ptr]; |
| 512 | |
| 513 | if (out->len > out->size - 2) |
| 514 | break; |
| 515 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 516 | out->str[out->len++] = hextab[c & 0xF]; |
| 517 | |
| 518 | ptr++; |
| 519 | } |
| 520 | return ptr; |
| 521 | } |
| 522 | |
| 523 | /* Dump the status of a table to a stream interface's |
| 524 | * read buffer. It returns 0 if the output buffer is full |
| 525 | * and needs to be called again, otherwise non-zero. |
| 526 | */ |
| 527 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 528 | struct proxy *proxy, struct proxy *target) |
| 529 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 530 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 531 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 532 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 533 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 534 | |
| 535 | /* any other information should be dumped here */ |
| 536 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 537 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 538 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 539 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 540 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 541 | return 0; |
| 542 | |
| 543 | return 1; |
| 544 | } |
| 545 | |
| 546 | /* Dump the a table entry to a stream interface's |
| 547 | * read buffer. It returns 0 if the output buffer is full |
| 548 | * and needs to be called again, otherwise non-zero. |
| 549 | */ |
| 550 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 551 | struct proxy *proxy, struct stksess *entry) |
| 552 | { |
| 553 | int dt; |
| 554 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 555 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 556 | |
| 557 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 558 | char addr[INET_ADDRSTRLEN]; |
| 559 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 560 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 561 | } |
| 562 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 563 | char addr[INET6_ADDRSTRLEN]; |
| 564 | inet_ntop(AF_INET6, (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_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 568 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 569 | } |
| 570 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 571 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 572 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 573 | } |
| 574 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 575 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 576 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 577 | } |
| 578 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 579 | 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] | 580 | |
| 581 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 582 | void *ptr; |
| 583 | |
| 584 | if (proxy->table.data_ofs[dt] == 0) |
| 585 | continue; |
| 586 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 587 | 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] | 588 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 589 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 590 | |
| 591 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 592 | switch (stktable_data_types[dt].std_type) { |
| 593 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 594 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 595 | break; |
| 596 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 597 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 598 | break; |
| 599 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 600 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 601 | break; |
| 602 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 603 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 604 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 605 | proxy->table.data_arg[dt].u)); |
| 606 | break; |
| 607 | } |
| 608 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 609 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 610 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 611 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 612 | return 0; |
| 613 | |
| 614 | return 1; |
| 615 | } |
| 616 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 617 | 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] | 618 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 619 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 620 | struct appctx *appctx = __objt_appctx(si->end); |
| 621 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 622 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 623 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 624 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 625 | long long value; |
| 626 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 627 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 628 | void *ptr; |
| 629 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 630 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 631 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 632 | |
| 633 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 634 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 635 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 636 | return; |
| 637 | } |
| 638 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 639 | switch (px->table.type) { |
| 640 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 641 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 642 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 643 | break; |
| 644 | case STKTABLE_TYPE_IPV6: |
| 645 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 646 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 647 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 648 | case STKTABLE_TYPE_INTEGER: |
| 649 | { |
| 650 | char *endptr; |
| 651 | unsigned long val; |
| 652 | errno = 0; |
| 653 | val = strtoul(args[4], &endptr, 10); |
| 654 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 655 | (errno != 0 && val == 0) || endptr == args[4] || |
| 656 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 657 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 658 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 659 | return; |
| 660 | } |
| 661 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 662 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 663 | break; |
| 664 | } |
| 665 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 666 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 667 | static_table_key->key = args[4]; |
| 668 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 669 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 670 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 671 | switch (action) { |
| 672 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 673 | 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] | 674 | break; |
| 675 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 676 | 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] | 677 | break; |
| 678 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 679 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 680 | break; |
| 681 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 682 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 683 | return; |
| 684 | } |
| 685 | |
| 686 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 687 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 688 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 689 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 690 | return; |
| 691 | } |
| 692 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 693 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 694 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 695 | switch (action) { |
| 696 | case STAT_CLI_O_TAB: |
| 697 | if (!ts) |
| 698 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 699 | chunk_reset(&trash); |
| 700 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 701 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 702 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 703 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 704 | |
| 705 | case STAT_CLI_O_CLR: |
| 706 | if (!ts) |
| 707 | return; |
| 708 | if (ts->ref_cnt) { |
| 709 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 710 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 711 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | stksess_kill(&px->table, ts); |
| 715 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 716 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 717 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 718 | if (ts) |
| 719 | stktable_touch(&px->table, ts, 1); |
| 720 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 721 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 722 | if (!ts) { |
| 723 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 724 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 725 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 726 | return; |
| 727 | } |
| 728 | stktable_store(&px->table, ts, 1); |
| 729 | } |
| 730 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 731 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 732 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 733 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 734 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 735 | return; |
| 736 | } |
| 737 | |
| 738 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 739 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 740 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 741 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 742 | return; |
| 743 | } |
| 744 | |
| 745 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 746 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 747 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 748 | return; |
| 749 | } |
| 750 | |
| 751 | 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] | 752 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 753 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 754 | return; |
| 755 | } |
| 756 | |
| 757 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 758 | |
| 759 | switch (stktable_data_types[data_type].std_type) { |
| 760 | case STD_T_SINT: |
| 761 | stktable_data_cast(ptr, std_t_sint) = value; |
| 762 | break; |
| 763 | case STD_T_UINT: |
| 764 | stktable_data_cast(ptr, std_t_uint) = value; |
| 765 | break; |
| 766 | case STD_T_ULL: |
| 767 | stktable_data_cast(ptr, std_t_ull) = value; |
| 768 | break; |
| 769 | case STD_T_FRQP: |
| 770 | /* We set both the current and previous values. That way |
| 771 | * the reported frequency is stable during all the period |
| 772 | * then slowly fades out. This allows external tools to |
| 773 | * push measures without having to update them too often. |
| 774 | */ |
| 775 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 776 | frqp->curr_tick = now_ms; |
| 777 | frqp->prev_ctr = 0; |
| 778 | frqp->curr_ctr = value; |
| 779 | break; |
| 780 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 781 | } |
| 782 | break; |
| 783 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 784 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 785 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 786 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 787 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 788 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 789 | } |
| 790 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 791 | 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] | 792 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 793 | struct appctx *appctx = __objt_appctx(si->end); |
| 794 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 795 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 796 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 797 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 798 | return; |
| 799 | } |
| 800 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 801 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 802 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 803 | if (appctx->ctx.table.data_type < 0) { |
| 804 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 805 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 806 | return; |
| 807 | } |
| 808 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 809 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 810 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 811 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 812 | return; |
| 813 | } |
| 814 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 815 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 816 | if (appctx->ctx.table.data_op < 0) { |
| 817 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 818 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 819 | return; |
| 820 | } |
| 821 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 822 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 823 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 824 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 825 | return; |
| 826 | } |
| 827 | } |
| 828 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 829 | 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] | 830 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 831 | struct appctx *appctx = __objt_appctx(si->end); |
| 832 | |
| 833 | appctx->ctx.table.data_type = -1; |
| 834 | appctx->st2 = STAT_ST_INIT; |
| 835 | appctx->ctx.table.target = NULL; |
| 836 | appctx->ctx.table.proxy = NULL; |
| 837 | appctx->ctx.table.entry = NULL; |
| 838 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 839 | |
| 840 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 841 | appctx->ctx.table.target = find_stktable(args[2]); |
| 842 | if (!appctx->ctx.table.target) { |
| 843 | appctx->ctx.cli.msg = "No such table\n"; |
| 844 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 845 | return; |
| 846 | } |
| 847 | } |
| 848 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 849 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 850 | goto err_args; |
| 851 | return; |
| 852 | } |
| 853 | |
| 854 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 855 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 856 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 857 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 858 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 859 | goto err_args; |
| 860 | |
| 861 | return; |
| 862 | |
| 863 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 864 | switch (action) { |
| 865 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 866 | 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] | 867 | break; |
| 868 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 869 | 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] | 870 | break; |
| 871 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 872 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 873 | break; |
| 874 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 875 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 876 | } |
| 877 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 878 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 879 | * adequate error messages and returns NULL. This function also expects the session |
| 880 | * level to be admin. |
| 881 | */ |
| 882 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 883 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 884 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 885 | struct proxy *px; |
| 886 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 887 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 888 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 889 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 890 | return NULL; |
| 891 | } |
| 892 | |
| 893 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 894 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 895 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 896 | return NULL; |
| 897 | } |
| 898 | |
| 899 | px = findproxy(arg, PR_CAP_FE); |
| 900 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 901 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 902 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 903 | return NULL; |
| 904 | } |
| 905 | return px; |
| 906 | } |
| 907 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 908 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 909 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 910 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 911 | * the <arg> is modified to remove the '/'. |
| 912 | */ |
| 913 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 914 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 915 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 916 | struct proxy *px; |
| 917 | struct server *sv; |
| 918 | char *line; |
| 919 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 920 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 921 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 922 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 923 | return NULL; |
| 924 | } |
| 925 | |
| 926 | /* split "backend/server" and make <line> point to server */ |
| 927 | for (line = arg; *line; line++) |
| 928 | if (*line == '/') { |
| 929 | *line++ = '\0'; |
| 930 | break; |
| 931 | } |
| 932 | |
| 933 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 934 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 935 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 936 | return NULL; |
| 937 | } |
| 938 | |
| 939 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 940 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 941 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 942 | return NULL; |
| 943 | } |
| 944 | |
| 945 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 946 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 947 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 948 | return NULL; |
| 949 | } |
| 950 | |
| 951 | return sv; |
| 952 | } |
| 953 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 954 | /* This function is used with map management. It permits to browse each |
| 955 | * really allocated descriptors of one map reference. The variable |
| 956 | * <appctx->ctx.map.ref> must contain the map reference to browse. |
| 957 | * The variable <appctx->ctx.map.desc> contain the descriptor of the |
| 958 | * current allocated map descriptor. This variable must be initialized |
| 959 | * to NULL. |
| 960 | */ |
| 961 | static inline void stats_map_lookup_next(struct stream_interface *si) |
| 962 | { |
| 963 | struct appctx *appctx = __objt_appctx(si->end); |
| 964 | |
| 965 | /* search the next allocated map */ |
| 966 | while (1) { |
| 967 | /* get next descriptor */ |
| 968 | if (!appctx->ctx.map.desc) |
| 969 | appctx->ctx.map.desc = LIST_NEXT(&appctx->ctx.map.ref->maps, |
| 970 | struct map_descriptor *, list); |
| 971 | else |
| 972 | appctx->ctx.map.desc = LIST_NEXT(&appctx->ctx.map.desc->list, |
| 973 | struct map_descriptor *, list); |
| 974 | |
| 975 | /* detect end of list */ |
| 976 | if (&appctx->ctx.map.desc->list == &appctx->ctx.map.ref->maps) { |
| 977 | appctx->ctx.map.desc = NULL; |
| 978 | return; |
| 979 | } |
| 980 | |
| 981 | /* do not lookup this entry */ |
| 982 | if (!appctx->ctx.map.desc->do_free) |
| 983 | continue; |
| 984 | |
| 985 | /* avalaible descriptor */ |
| 986 | return; |
| 987 | } |
| 988 | } |
| 989 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 990 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 991 | * 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] | 992 | * 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] | 993 | * designating the function which will have to process the request, which can |
| 994 | * 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] | 995 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 996 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 997 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 998 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 999 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1000 | char *args[MAX_STATS_ARGS + 1]; |
| 1001 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1002 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1003 | |
| 1004 | while (isspace((unsigned char)*line)) |
| 1005 | line++; |
| 1006 | |
| 1007 | arg = 0; |
| 1008 | args[arg] = line; |
| 1009 | |
| 1010 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1011 | if (*line == '\\') { |
| 1012 | line++; |
| 1013 | if (*line == '\0') |
| 1014 | break; |
| 1015 | } |
| 1016 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1017 | *line++ = '\0'; |
| 1018 | |
| 1019 | while (isspace((unsigned char)*line)) |
| 1020 | line++; |
| 1021 | |
| 1022 | args[++arg] = line; |
| 1023 | continue; |
| 1024 | } |
| 1025 | |
| 1026 | line++; |
| 1027 | } |
| 1028 | |
| 1029 | while (++arg <= MAX_STATS_ARGS) |
| 1030 | args[arg] = line; |
| 1031 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1032 | /* remove \ */ |
| 1033 | arg = 0; |
| 1034 | while (*args[arg] != '\0') { |
| 1035 | j = 0; |
| 1036 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1037 | if (args[arg][i] == '\\') |
| 1038 | continue; |
| 1039 | args[arg][j] = args[arg][i]; |
| 1040 | j++; |
| 1041 | } |
| 1042 | args[arg][j] = '\0'; |
| 1043 | arg++; |
| 1044 | } |
| 1045 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1046 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1047 | if (strcmp(args[0], "show") == 0) { |
| 1048 | if (strcmp(args[1], "stat") == 0) { |
| 1049 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1050 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1051 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1052 | appctx->ctx.stats.type = atoi(args[3]); |
| 1053 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1054 | } |
| 1055 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1056 | appctx->st2 = STAT_ST_INIT; |
| 1057 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1058 | } |
| 1059 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1060 | appctx->st2 = STAT_ST_INIT; |
| 1061 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1062 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1063 | else if (strcmp(args[1], "pools") == 0) { |
| 1064 | appctx->st2 = STAT_ST_INIT; |
| 1065 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1066 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1067 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1068 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1069 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1070 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1071 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1072 | return 1; |
| 1073 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1074 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1075 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1076 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1077 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1078 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1079 | appctx->ctx.sess.target = NULL; |
| 1080 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1081 | appctx->ctx.sess.pos = 0; |
| 1082 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1083 | } |
| 1084 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1085 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1086 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1087 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1088 | return 1; |
| 1089 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1090 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1091 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1092 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1093 | appctx->ctx.errors.iid = -1; |
| 1094 | appctx->ctx.errors.px = NULL; |
| 1095 | appctx->st2 = STAT_ST_INIT; |
| 1096 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1097 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1098 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1099 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1100 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1101 | else if (strcmp(args[1], "map") == 0) { |
| 1102 | |
| 1103 | /* no parameter: display all map avalaible */ |
| 1104 | if (!*args[2]) { |
| 1105 | appctx->st2 = STAT_ST_INIT; |
| 1106 | appctx->st0 = STAT_CLI_O_MAPS; |
| 1107 | return 1; |
| 1108 | } |
| 1109 | |
| 1110 | /* lookup into the maps */ |
| 1111 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1112 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1113 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1114 | appctx->st0 = STAT_CLI_PRINT; |
| 1115 | return 1; |
| 1116 | } |
| 1117 | appctx->st2 = STAT_ST_INIT; |
| 1118 | appctx->st0 = STAT_CLI_O_MAP; |
| 1119 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1120 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1121 | return 0; |
| 1122 | } |
| 1123 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1124 | else if (strcmp(args[0], "clear") == 0) { |
| 1125 | if (strcmp(args[1], "counters") == 0) { |
| 1126 | struct proxy *px; |
| 1127 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1128 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1129 | int clrall = 0; |
| 1130 | |
| 1131 | if (strcmp(args[2], "all") == 0) |
| 1132 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1133 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1134 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1135 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1136 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1137 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1138 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1139 | return 1; |
| 1140 | } |
| 1141 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1142 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1143 | if (clrall) { |
| 1144 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1145 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1146 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1147 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1148 | px->be_counters.conn_max = 0; |
| 1149 | px->be_counters.p.http.rps_max = 0; |
| 1150 | px->be_counters.sps_max = 0; |
| 1151 | px->be_counters.cps_max = 0; |
| 1152 | px->be_counters.nbpend_max = 0; |
| 1153 | |
| 1154 | px->fe_counters.conn_max = 0; |
| 1155 | px->fe_counters.p.http.rps_max = 0; |
| 1156 | px->fe_counters.sps_max = 0; |
| 1157 | px->fe_counters.cps_max = 0; |
| 1158 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1159 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1160 | |
| 1161 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1162 | if (clrall) |
| 1163 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1164 | else { |
| 1165 | sv->counters.cur_sess_max = 0; |
| 1166 | sv->counters.nbpend_max = 0; |
| 1167 | sv->counters.sps_max = 0; |
| 1168 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1169 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1170 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1171 | if (li->counters) { |
| 1172 | if (clrall) |
| 1173 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1174 | else |
| 1175 | li->counters->conn_max = 0; |
| 1176 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1177 | } |
| 1178 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1179 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1180 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1181 | return 1; |
| 1182 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1183 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1184 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1185 | /* end of processing */ |
| 1186 | return 1; |
| 1187 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1188 | else if (strcmp(args[1], "map") == 0) { |
| 1189 | struct map_reference *mref; |
| 1190 | struct map_descriptor *mdesc; |
| 1191 | struct map_entry *ent, *nent; |
| 1192 | |
| 1193 | /* no parameter */ |
| 1194 | if (!*args[2]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1195 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1196 | appctx->st0 = STAT_CLI_PRINT; |
| 1197 | return 1; |
| 1198 | } |
| 1199 | |
| 1200 | /* lookup into the maps */ |
| 1201 | mref = map_get_reference(args[2]); |
| 1202 | if (!mref) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1203 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1204 | appctx->st0 = STAT_CLI_PRINT; |
| 1205 | return 1; |
| 1206 | } |
| 1207 | |
| 1208 | /* clear all maps */ |
| 1209 | list_for_each_entry(mdesc, &mref->maps, list) |
| 1210 | if (mdesc->do_free) |
| 1211 | pattern_prune_expr(mdesc->pat); |
| 1212 | |
| 1213 | /* clear map reference */ |
| 1214 | list_for_each_entry_safe(ent, nent, &mref->entries, list) { |
| 1215 | LIST_DEL(&ent->list); |
| 1216 | free(ent->key); |
| 1217 | free(ent->value); |
| 1218 | free(ent); |
| 1219 | } |
| 1220 | |
| 1221 | /* return response */ |
| 1222 | appctx->ctx.cli.msg = "Done.\n"; |
| 1223 | appctx->st0 = STAT_CLI_PRINT; |
| 1224 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1225 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1226 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1227 | return 0; |
| 1228 | } |
| 1229 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1230 | else if (strcmp(args[0], "get") == 0) { |
| 1231 | if (strcmp(args[1], "weight") == 0) { |
| 1232 | struct proxy *px; |
| 1233 | struct server *sv; |
| 1234 | |
| 1235 | /* split "backend/server" and make <line> point to server */ |
| 1236 | for (line = args[2]; *line; line++) |
| 1237 | if (*line == '/') { |
| 1238 | *line++ = '\0'; |
| 1239 | break; |
| 1240 | } |
| 1241 | |
| 1242 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1243 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1244 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1245 | return 1; |
| 1246 | } |
| 1247 | |
| 1248 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1249 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1250 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1251 | return 1; |
| 1252 | } |
| 1253 | |
| 1254 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1255 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1256 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1257 | return 1; |
| 1258 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1259 | else if (strcmp(args[1], "map") == 0) { |
| 1260 | |
| 1261 | /* no parameter */ |
| 1262 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1263 | appctx->ctx.cli.msg = "Missing identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1264 | appctx->st0 = STAT_CLI_PRINT; |
| 1265 | return 1; |
| 1266 | } |
| 1267 | |
| 1268 | /* lookup into the maps */ |
| 1269 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1270 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1271 | 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] | 1272 | appctx->st0 = STAT_CLI_PRINT; |
| 1273 | return 1; |
| 1274 | } |
| 1275 | |
| 1276 | /* copy input string */ |
| 1277 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1278 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1279 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1280 | if (!appctx->ctx.map.chunk.str) { |
| 1281 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1282 | appctx->st0 = STAT_CLI_PRINT; |
| 1283 | return 1; |
| 1284 | } |
| 1285 | |
| 1286 | /* prepare response */ |
| 1287 | appctx->st2 = STAT_ST_INIT; |
| 1288 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1289 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1290 | else { /* not "get weight" */ |
| 1291 | return 0; |
| 1292 | } |
| 1293 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1294 | else if (strcmp(args[0], "set") == 0) { |
| 1295 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1296 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1297 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1298 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1299 | sv = expect_server_admin(s, si, args[2]); |
| 1300 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1301 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1302 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1303 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1304 | /* |
| 1305 | * The user-weight may now be zero and thus |
| 1306 | * the server considered to be draining. |
| 1307 | * Update the server's drain state as necessary. |
| 1308 | */ |
| 1309 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1310 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1311 | appctx->ctx.cli.msg = warning; |
| 1312 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1313 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1314 | return 1; |
| 1315 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1316 | else if (strcmp(args[1], "timeout") == 0) { |
| 1317 | if (strcmp(args[2], "cli") == 0) { |
| 1318 | unsigned timeout; |
| 1319 | const char *res; |
| 1320 | |
| 1321 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1322 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1323 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1324 | return 1; |
| 1325 | } |
| 1326 | |
| 1327 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1328 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1329 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1330 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1331 | return 1; |
| 1332 | } |
| 1333 | |
| 1334 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1335 | return 1; |
| 1336 | } |
| 1337 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1338 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1339 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1340 | return 1; |
| 1341 | } |
| 1342 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1343 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1344 | if (strcmp(args[2], "frontend") == 0) { |
| 1345 | struct proxy *px; |
| 1346 | struct listener *l; |
| 1347 | int v; |
| 1348 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1349 | px = expect_frontend_admin(s, si, args[3]); |
| 1350 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1351 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1352 | |
| 1353 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1354 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1355 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1356 | return 1; |
| 1357 | } |
| 1358 | |
| 1359 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1360 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1361 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1362 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1363 | return 1; |
| 1364 | } |
| 1365 | |
| 1366 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1367 | * its listeners. The blocked ones will be dequeued. |
| 1368 | */ |
| 1369 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1370 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1371 | l->maxconn = v; |
| 1372 | if (l->state == LI_FULL) |
| 1373 | resume_listener(l); |
| 1374 | } |
| 1375 | |
| 1376 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1377 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1378 | |
| 1379 | return 1; |
| 1380 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1381 | else if (strcmp(args[2], "global") == 0) { |
| 1382 | int v; |
| 1383 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1384 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1385 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1386 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1387 | return 1; |
| 1388 | } |
| 1389 | |
| 1390 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1391 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1392 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1393 | return 1; |
| 1394 | } |
| 1395 | |
| 1396 | v = atoi(args[3]); |
| 1397 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1398 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1399 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1400 | return 1; |
| 1401 | } |
| 1402 | |
| 1403 | /* check for unlimited values */ |
| 1404 | if (v <= 0) |
| 1405 | v = global.hardmaxconn; |
| 1406 | |
| 1407 | global.maxconn = v; |
| 1408 | |
| 1409 | /* Dequeues all of the listeners waiting for a resource */ |
| 1410 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1411 | dequeue_all_listeners(&global_listener_queue); |
| 1412 | |
| 1413 | return 1; |
| 1414 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1415 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1416 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1417 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1418 | return 1; |
| 1419 | } |
| 1420 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1421 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1422 | if (strcmp(args[2], "connections") == 0) { |
| 1423 | if (strcmp(args[3], "global") == 0) { |
| 1424 | int v; |
| 1425 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1426 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1427 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1428 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1429 | return 1; |
| 1430 | } |
| 1431 | |
| 1432 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1433 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1434 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1435 | return 1; |
| 1436 | } |
| 1437 | |
| 1438 | v = atoi(args[4]); |
| 1439 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1440 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1441 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1442 | return 1; |
| 1443 | } |
| 1444 | |
| 1445 | global.cps_lim = v; |
| 1446 | |
| 1447 | /* Dequeues all of the listeners waiting for a resource */ |
| 1448 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1449 | dequeue_all_listeners(&global_listener_queue); |
| 1450 | |
| 1451 | return 1; |
| 1452 | } |
| 1453 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1454 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1455 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1456 | return 1; |
| 1457 | } |
| 1458 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1459 | else if (strcmp(args[2], "sessions") == 0) { |
| 1460 | if (strcmp(args[3], "global") == 0) { |
| 1461 | int v; |
| 1462 | |
| 1463 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1464 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1465 | appctx->st0 = STAT_CLI_PRINT; |
| 1466 | return 1; |
| 1467 | } |
| 1468 | |
| 1469 | if (!*args[4]) { |
| 1470 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1471 | appctx->st0 = STAT_CLI_PRINT; |
| 1472 | return 1; |
| 1473 | } |
| 1474 | |
| 1475 | v = atoi(args[4]); |
| 1476 | if (v < 0) { |
| 1477 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1478 | appctx->st0 = STAT_CLI_PRINT; |
| 1479 | return 1; |
| 1480 | } |
| 1481 | |
| 1482 | global.sps_lim = v; |
| 1483 | |
| 1484 | /* Dequeues all of the listeners waiting for a resource */ |
| 1485 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1486 | dequeue_all_listeners(&global_listener_queue); |
| 1487 | |
| 1488 | return 1; |
| 1489 | } |
| 1490 | else { |
| 1491 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1492 | appctx->st0 = STAT_CLI_PRINT; |
| 1493 | return 1; |
| 1494 | } |
| 1495 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1496 | #ifdef USE_OPENSSL |
| 1497 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1498 | if (strcmp(args[3], "global") == 0) { |
| 1499 | int v; |
| 1500 | |
| 1501 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1502 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1503 | appctx->st0 = STAT_CLI_PRINT; |
| 1504 | return 1; |
| 1505 | } |
| 1506 | |
| 1507 | if (!*args[4]) { |
| 1508 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1509 | appctx->st0 = STAT_CLI_PRINT; |
| 1510 | return 1; |
| 1511 | } |
| 1512 | |
| 1513 | v = atoi(args[4]); |
| 1514 | if (v < 0) { |
| 1515 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1516 | appctx->st0 = STAT_CLI_PRINT; |
| 1517 | return 1; |
| 1518 | } |
| 1519 | |
| 1520 | global.ssl_lim = v; |
| 1521 | |
| 1522 | /* Dequeues all of the listeners waiting for a resource */ |
| 1523 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1524 | dequeue_all_listeners(&global_listener_queue); |
| 1525 | |
| 1526 | return 1; |
| 1527 | } |
| 1528 | else { |
| 1529 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1530 | appctx->st0 = STAT_CLI_PRINT; |
| 1531 | return 1; |
| 1532 | } |
| 1533 | } |
| 1534 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1535 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1536 | if (strcmp(args[3], "global") == 0) { |
| 1537 | int v; |
| 1538 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1539 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1540 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1541 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1542 | return 1; |
| 1543 | } |
| 1544 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1545 | v = atoi(args[4]); |
| 1546 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1547 | } |
| 1548 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1549 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1550 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1551 | return 1; |
| 1552 | } |
| 1553 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1554 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1555 | 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] | 1556 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1557 | return 1; |
| 1558 | } |
| 1559 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1560 | else if (strcmp(args[1], "table") == 0) { |
| 1561 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1562 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1563 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 3ead5b9 | 2013-12-13 12:12:18 +0100 | [diff] [blame] | 1564 | struct pattern_list *pat_elt; |
Thierry FOURNIER | e1bcac5 | 2013-12-13 16:09:50 +0100 | [diff] [blame] | 1565 | struct pattern_tree *idx_elt; |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1566 | char *value = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1567 | |
| 1568 | /* Expect three parameters: map name, key and new value. */ |
| 1569 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1570 | 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] | 1571 | appctx->st0 = STAT_CLI_PRINT; |
| 1572 | return 1; |
| 1573 | } |
| 1574 | |
| 1575 | /* Lookup the reference in the maps. */ |
| 1576 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1577 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1578 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1579 | appctx->st0 = STAT_CLI_PRINT; |
| 1580 | return 1; |
| 1581 | } |
| 1582 | |
| 1583 | /* Lookup the entry in the reference values. */ |
| 1584 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) |
| 1585 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) |
| 1586 | break; |
| 1587 | |
| 1588 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1589 | appctx->ctx.cli.msg = "\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1590 | appctx->st0 = STAT_CLI_PRINT; |
| 1591 | return 1; |
| 1592 | } |
| 1593 | |
| 1594 | /* Update each reference entries. */ |
| 1595 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) { |
| 1596 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) { |
| 1597 | value = strdup(args[4]); |
| 1598 | if (!value) { |
| 1599 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1600 | appctx->st0 = STAT_CLI_PRINT; |
| 1601 | return 1; |
| 1602 | } |
| 1603 | free(appctx->ctx.map.ent->value); |
| 1604 | appctx->ctx.map.ent->value = value; |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | /* Change the sample. The lookup juste return the first entry, other |
| 1609 | * entries are not changed, but are never matched. |
| 1610 | */ |
| 1611 | appctx->ctx.map.desc = NULL; |
| 1612 | for (stats_map_lookup_next(si); |
| 1613 | appctx->ctx.map.desc; |
| 1614 | stats_map_lookup_next(si)) { |
| 1615 | pattern_lookup(args[3], appctx->ctx.map.desc->pat, &pat_elt, &idx_elt, NULL); |
| 1616 | if (pat_elt != NULL) |
Thierry FOURNIER | 3ead5b9 | 2013-12-13 12:12:18 +0100 | [diff] [blame] | 1617 | appctx->ctx.map.desc->parse(value, pat_elt->pat.smp); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1618 | if (idx_elt != NULL) |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1619 | appctx->ctx.map.desc->parse(value, idx_elt->smp); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | /* The set is done, send message. */ |
| 1623 | appctx->ctx.cli.msg = "Done.\n"; |
| 1624 | appctx->st0 = STAT_CLI_PRINT; |
| 1625 | return 1; |
| 1626 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1627 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1628 | return 0; |
| 1629 | } |
| 1630 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1631 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1632 | if (strcmp(args[1], "agent") == 0) { |
| 1633 | struct server *sv; |
| 1634 | |
| 1635 | sv = expect_server_admin(s, si, args[2]); |
| 1636 | if (!sv) |
| 1637 | return 1; |
| 1638 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1639 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1640 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1641 | appctx->st0 = STAT_CLI_PRINT; |
| 1642 | return 1; |
| 1643 | } |
| 1644 | |
| 1645 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1646 | return 1; |
| 1647 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1648 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1649 | struct server *sv; |
| 1650 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1651 | sv = expect_server_admin(s, si, args[2]); |
| 1652 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1653 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1654 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1655 | if (sv->state & SRV_MAINTAIN) { |
| 1656 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1657 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1658 | /* If this server tracks the status of another one, |
| 1659 | * we must restore the good status. |
| 1660 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1661 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1662 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1663 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1664 | } else { |
| 1665 | sv->state &= ~SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1666 | sv->check.state &= ~CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1667 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1668 | } |
| 1669 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1670 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1671 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1675 | return 1; |
| 1676 | } |
| 1677 | else if (strcmp(args[1], "frontend") == 0) { |
| 1678 | struct proxy *px; |
| 1679 | |
| 1680 | px = expect_frontend_admin(s, si, args[2]); |
| 1681 | if (!px) |
| 1682 | return 1; |
| 1683 | |
| 1684 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1685 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1686 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1687 | return 1; |
| 1688 | } |
| 1689 | |
| 1690 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1691 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1692 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1693 | return 1; |
| 1694 | } |
| 1695 | |
| 1696 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1697 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1698 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1699 | return 1; |
| 1700 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1701 | return 1; |
| 1702 | } |
| 1703 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1704 | appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1705 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1706 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1710 | if (strcmp(args[1], "agent") == 0) { |
| 1711 | struct server *sv; |
| 1712 | |
| 1713 | sv = expect_server_admin(s, si, args[2]); |
| 1714 | if (!sv) |
| 1715 | return 1; |
| 1716 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1717 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1718 | return 1; |
| 1719 | } |
| 1720 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1721 | struct server *sv; |
| 1722 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1723 | sv = expect_server_admin(s, si, args[2]); |
| 1724 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1725 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1726 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1727 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1728 | /* Not already in maintenance, we can change the server state */ |
| 1729 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1730 | sv->check.state |= CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1731 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1732 | } |
| 1733 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1734 | return 1; |
| 1735 | } |
| 1736 | else if (strcmp(args[1], "frontend") == 0) { |
| 1737 | struct proxy *px; |
| 1738 | |
| 1739 | px = expect_frontend_admin(s, si, args[2]); |
| 1740 | if (!px) |
| 1741 | return 1; |
| 1742 | |
| 1743 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1744 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1745 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1746 | return 1; |
| 1747 | } |
| 1748 | |
| 1749 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1750 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1751 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1752 | return 1; |
| 1753 | } |
| 1754 | |
| 1755 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1756 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1757 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1758 | return 1; |
| 1759 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1760 | return 1; |
| 1761 | } |
| 1762 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1763 | appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1764 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1765 | return 1; |
| 1766 | } |
| 1767 | } |
| 1768 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1769 | if (strcmp(args[1], "frontend") == 0) { |
| 1770 | struct proxy *px; |
| 1771 | |
| 1772 | px = expect_frontend_admin(s, si, args[2]); |
| 1773 | if (!px) |
| 1774 | return 1; |
| 1775 | |
| 1776 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1777 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1778 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1779 | return 1; |
| 1780 | } |
| 1781 | |
| 1782 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1783 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1784 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1785 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1786 | stop_proxy(px); |
| 1787 | return 1; |
| 1788 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1789 | else if (strcmp(args[1], "session") == 0) { |
| 1790 | struct session *sess, *ptr; |
| 1791 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1792 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1793 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1794 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1795 | return 1; |
| 1796 | } |
| 1797 | |
| 1798 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1799 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1800 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1801 | return 1; |
| 1802 | } |
| 1803 | |
| 1804 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1805 | |
| 1806 | /* first, look for the requested session in the session table */ |
| 1807 | list_for_each_entry(sess, &sessions, list) { |
| 1808 | if (sess == ptr) |
| 1809 | break; |
| 1810 | } |
| 1811 | |
| 1812 | /* do we have the session ? */ |
| 1813 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1814 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1815 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1816 | return 1; |
| 1817 | } |
| 1818 | |
| 1819 | session_shutdown(sess, SN_ERR_KILLED); |
| 1820 | return 1; |
| 1821 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1822 | else if (strcmp(args[1], "sessions") == 0) { |
| 1823 | if (strcmp(args[2], "server") == 0) { |
| 1824 | struct server *sv; |
| 1825 | struct session *sess, *sess_bck; |
| 1826 | |
| 1827 | sv = expect_server_admin(s, si, args[3]); |
| 1828 | if (!sv) |
| 1829 | return 1; |
| 1830 | |
| 1831 | /* kill all the session that are on this server */ |
| 1832 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1833 | if (sess->srv_conn == sv) |
| 1834 | session_shutdown(sess, SN_ERR_KILLED); |
| 1835 | |
| 1836 | return 1; |
| 1837 | } |
| 1838 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1839 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1840 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1841 | return 1; |
| 1842 | } |
| 1843 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1844 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1845 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1846 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1847 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1848 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1849 | } |
| 1850 | else if (strcmp(args[0], "del") == 0) { |
| 1851 | if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 3ead5b9 | 2013-12-13 12:12:18 +0100 | [diff] [blame] | 1852 | struct pattern_list *pat_elt; |
Thierry FOURNIER | e1bcac5 | 2013-12-13 16:09:50 +0100 | [diff] [blame] | 1853 | struct pattern_tree *idx_elt; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1854 | struct map_entry *ent; |
| 1855 | |
| 1856 | /* Expect two parameters: map name and key. */ |
| 1857 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1858 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1859 | appctx->st0 = STAT_CLI_PRINT; |
| 1860 | return 1; |
| 1861 | } |
| 1862 | |
| 1863 | /* Lookup the reference in the maps. */ |
| 1864 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1865 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1866 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1867 | appctx->st0 = STAT_CLI_PRINT; |
| 1868 | return 1; |
| 1869 | } |
| 1870 | |
| 1871 | /* Lookup the entry in the reference values. |
| 1872 | * If the entry is not found in the reference, return error message. |
| 1873 | */ |
| 1874 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) |
| 1875 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) |
| 1876 | break; |
| 1877 | |
| 1878 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1879 | appctx->ctx.cli.msg = "Key not found.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1880 | appctx->st0 = STAT_CLI_PRINT; |
| 1881 | return 1; |
| 1882 | } |
| 1883 | |
| 1884 | /* Delete each enties from reference. */ |
| 1885 | list_for_each_entry_safe(appctx->ctx.map.ent, ent, &appctx->ctx.map.ref->entries, list) { |
| 1886 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) { |
| 1887 | LIST_DEL(&appctx->ctx.map.ent->list); |
| 1888 | free(appctx->ctx.map.ent->key); |
| 1889 | free(appctx->ctx.map.ent->value); |
| 1890 | free(appctx->ctx.map.ent); |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | /* Delete all matching entries for each map descritor. */ |
| 1895 | appctx->ctx.map.desc = NULL; |
| 1896 | stats_map_lookup_next(si); |
| 1897 | while (appctx->ctx.map.desc) { |
| 1898 | while (pattern_lookup(args[3], appctx->ctx.map.desc->pat, &pat_elt, &idx_elt, NULL)) { |
| 1899 | if (pat_elt != NULL) { |
| 1900 | LIST_DEL(&pat_elt->list); |
| 1901 | pattern_free(pat_elt); |
| 1902 | } |
| 1903 | if (idx_elt != NULL) { |
| 1904 | ebmb_delete(&idx_elt->node); |
| 1905 | free(idx_elt); |
| 1906 | } |
| 1907 | } |
| 1908 | stats_map_lookup_next(si); |
| 1909 | } |
| 1910 | |
| 1911 | /* The deletion is done, send message. */ |
| 1912 | appctx->ctx.cli.msg = "Done.\n"; |
| 1913 | appctx->st0 = STAT_CLI_PRINT; |
| 1914 | return 1; |
| 1915 | } |
| 1916 | else { /* unknown "del" parameter */ |
| 1917 | appctx->ctx.cli.msg = "'del' only supports 'map'.\n"; |
| 1918 | appctx->st0 = STAT_CLI_PRINT; |
| 1919 | return 1; |
| 1920 | } |
| 1921 | } |
| 1922 | else if (strcmp(args[0], "add") == 0) { |
| 1923 | if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1924 | struct map_entry *ent; |
| 1925 | struct sample_storage *smp; |
| 1926 | |
| 1927 | /* Expect three parameters: map name, key and new value. */ |
| 1928 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1929 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1930 | appctx->st0 = STAT_CLI_PRINT; |
| 1931 | return 1; |
| 1932 | } |
| 1933 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1934 | /* Lookup the reference in the maps. */ |
| 1935 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1936 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1937 | appctx->ctx.cli.msg = "Unknown map identifier. Please use <name>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1938 | appctx->st0 = STAT_CLI_PRINT; |
| 1939 | return 1; |
| 1940 | } |
| 1941 | |
| 1942 | /* Prepare and link the new map_entry element. If out of memory |
| 1943 | * error the action is cancelled and the descriptor are left |
| 1944 | * coherents. |
| 1945 | */ |
| 1946 | ent = malloc(sizeof(*ent)); |
| 1947 | if (!ent) { |
| 1948 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1949 | appctx->st0 = STAT_CLI_PRINT; |
| 1950 | return 1; |
| 1951 | } |
| 1952 | ent->key = strdup(args[3]); |
| 1953 | if (!ent->key) { |
| 1954 | free(ent); |
| 1955 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1956 | appctx->st0 = STAT_CLI_PRINT; |
| 1957 | return 1; |
| 1958 | } |
| 1959 | ent->value = strdup(args[4]); |
| 1960 | if (!ent->value) { |
| 1961 | free(ent->key); |
| 1962 | free(ent); |
| 1963 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1964 | appctx->st0 = STAT_CLI_PRINT; |
| 1965 | return 1; |
| 1966 | } |
| 1967 | LIST_ADDQ(&appctx->ctx.map.ref->entries, &ent->list); |
| 1968 | |
| 1969 | /* Browse each map descritor and try to insert this new value. */ |
| 1970 | appctx->ctx.map.desc = NULL; |
| 1971 | for (stats_map_lookup_next(si); |
| 1972 | appctx->ctx.map.desc; |
| 1973 | stats_map_lookup_next(si)) { |
| 1974 | |
| 1975 | /* Create new sample. Return out of memory error |
| 1976 | * if the memory cannot be allocated. The 'add' process |
| 1977 | * is aborted, but the already inserted entries are not |
| 1978 | * deleted. |
| 1979 | */ |
| 1980 | smp = calloc(1, sizeof(*smp)); |
| 1981 | if (!smp) { |
| 1982 | appctx->ctx.cli.msg = "Out of memory error. The value is not added in all maps.\n"; |
| 1983 | appctx->st0 = STAT_CLI_PRINT; |
| 1984 | return 1; |
| 1985 | } |
| 1986 | |
| 1987 | /* Create sample. If this function fails, the insertion |
| 1988 | * is canceled for this 'descriptor', but continue, for |
| 1989 | * the other descriptors. |
| 1990 | */ |
| 1991 | if (!appctx->ctx.map.desc->parse(ent->value, smp)) { |
| 1992 | free(smp); |
| 1993 | continue; |
| 1994 | } |
| 1995 | |
Thierry FOURNIER | b9b0846 | 2013-12-13 15:12:32 +0100 | [diff] [blame] | 1996 | if (!pattern_register(appctx->ctx.map.desc->pat, args[3], smp, 0, NULL)) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1997 | free(smp); |
| 1998 | continue; |
| 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | /* The add is done, send message. */ |
| 2003 | appctx->ctx.cli.msg = "Done.\n"; |
| 2004 | appctx->st0 = STAT_CLI_PRINT; |
| 2005 | return 1; |
| 2006 | } |
| 2007 | else { /* unknown "del" parameter */ |
| 2008 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2009 | appctx->st0 = STAT_CLI_PRINT; |
| 2010 | return 1; |
| 2011 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2012 | } |
| 2013 | 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] | 2014 | return 0; |
| 2015 | } |
| 2016 | return 1; |
| 2017 | } |
| 2018 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2019 | /* 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] | 2020 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2021 | * state machine handling requests and various responses. We read a request, |
| 2022 | * 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] | 2023 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2024 | * 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] | 2025 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2026 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2027 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2028 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2029 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2030 | struct channel *req = si->ob; |
| 2031 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2032 | int reql; |
| 2033 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2034 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2035 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2036 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2037 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2038 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2039 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2040 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2041 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2042 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2043 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2044 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2045 | /* Let's close for real now. We just close the request |
| 2046 | * side, the conditions below will complete if needed. |
| 2047 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2048 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2049 | break; |
| 2050 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2051 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2052 | /* ensure we have some output room left in the event we |
| 2053 | * would want to return some info right after parsing. |
| 2054 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2055 | if (buffer_almost_full(si->ib->buf)) { |
| 2056 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2057 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2058 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2059 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2060 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2061 | if (reql <= 0) { /* closed or EOL not found */ |
| 2062 | if (reql == 0) |
| 2063 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2064 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2065 | continue; |
| 2066 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2067 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2068 | /* seek for a possible semi-colon. If we find one, we |
| 2069 | * replace it with an LF and skip only this part. |
| 2070 | */ |
| 2071 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2072 | if (trash.str[len] == ';') { |
| 2073 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2074 | reql = len + 1; |
| 2075 | break; |
| 2076 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2077 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2078 | /* now it is time to check that we have a full line, |
| 2079 | * remove the trailing \n and possibly \r, then cut the |
| 2080 | * line. |
| 2081 | */ |
| 2082 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2083 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2084 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2085 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2086 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2087 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2088 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2089 | len--; |
| 2090 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2091 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2092 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2093 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2094 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2095 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2096 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2097 | continue; |
| 2098 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2099 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2100 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2101 | else if (strcmp(trash.str, "help") == 0 || |
| 2102 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2103 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2104 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2105 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2106 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2107 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2108 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2109 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2110 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2111 | /* if prompt is disabled, print help on empty lines, |
| 2112 | * so that the user at least knows how to enable |
| 2113 | * prompt and find help. |
| 2114 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2115 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2116 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2120 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2121 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2122 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2123 | 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] | 2124 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2125 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2126 | continue; |
| 2127 | } |
| 2128 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2129 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2130 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2131 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2132 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2133 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2134 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2135 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2136 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2137 | break; |
| 2138 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2139 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2140 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2141 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2142 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2143 | if (stats_dump_sess_to_buffer(si)) |
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; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2146 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2147 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2148 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2149 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2150 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2151 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2152 | if (stats_table_request(si, appctx->st0)) |
| 2153 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2154 | break; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2155 | case STAT_CLI_O_MAPS: |
| 2156 | if (stats_maps_list(si)) |
| 2157 | appctx->st0 = STAT_CLI_PROMPT; |
| 2158 | break; |
| 2159 | case STAT_CLI_O_MAP: |
| 2160 | if (stats_map_list(si)) |
| 2161 | appctx->st0 = STAT_CLI_PROMPT; |
| 2162 | break; |
| 2163 | case STAT_CLI_O_MLOOK: |
| 2164 | if (stats_map_lookup(si)) |
| 2165 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2166 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2167 | case STAT_CLI_O_POOLS: |
| 2168 | if (stats_dump_pools_to_buffer(si)) |
| 2169 | appctx->st0 = STAT_CLI_PROMPT; |
| 2170 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2171 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2172 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2173 | break; |
| 2174 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2175 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2176 | /* 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] | 2177 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2178 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2179 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2180 | } |
| 2181 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2182 | /* 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] | 2183 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2184 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2185 | |
| 2186 | /* Now we close the output if one of the writers did so, |
| 2187 | * or if we're not in interactive mode and the request |
| 2188 | * buffer is empty. This still allows pipelined requests |
| 2189 | * to be sent in non-interactive mode. |
| 2190 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2191 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2192 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2193 | continue; |
| 2194 | } |
| 2195 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2196 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2197 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2198 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2199 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2200 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2201 | 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] | 2202 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2203 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2204 | /* 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] | 2205 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2206 | * we forward the close to the request side so that it flows upstream to |
| 2207 | * the client. |
| 2208 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2209 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2210 | } |
| 2211 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2212 | 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] | 2213 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2214 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2215 | /* We have no more processing to do, and nothing more to send, and |
| 2216 | * the client side has closed. So we'll forward this state downstream |
| 2217 | * on the response buffer. |
| 2218 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2219 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2220 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2224 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2225 | |
| 2226 | /* we don't want to expire timeouts while we're processing requests */ |
| 2227 | si->ib->rex = TICK_ETERNITY; |
| 2228 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2229 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2230 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2231 | 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] | 2232 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2233 | 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] | 2234 | |
| 2235 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2236 | /* check that we have released everything then unregister */ |
| 2237 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2238 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2239 | } |
| 2240 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2241 | /* This function dumps information onto the stream interface's read buffer. |
| 2242 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2243 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2244 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2245 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2246 | { |
| 2247 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2248 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2249 | chunk_printf(&trash, |
| 2250 | "Name: " PRODUCT_NAME "\n" |
| 2251 | "Version: " HAPROXY_VERSION "\n" |
| 2252 | "Release_date: " HAPROXY_DATE "\n" |
| 2253 | "Nbproc: %d\n" |
| 2254 | "Process_num: %d\n" |
| 2255 | "Pid: %d\n" |
| 2256 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2257 | "Uptime_sec: %d\n" |
| 2258 | "Memmax_MB: %d\n" |
| 2259 | "Ulimit-n: %d\n" |
| 2260 | "Maxsock: %d\n" |
| 2261 | "Maxconn: %d\n" |
| 2262 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2263 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2264 | "CumConns: %d\n" |
| 2265 | "CumReq: %d\n" |
| 2266 | #ifdef USE_OPENSSL |
| 2267 | "MaxSslConns: %d\n" |
| 2268 | "CurrSslConns: %d\n" |
| 2269 | "CumSslConns: %d\n" |
| 2270 | #endif |
| 2271 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2272 | "PipesUsed: %d\n" |
| 2273 | "PipesFree: %d\n" |
| 2274 | "ConnRate: %d\n" |
| 2275 | "ConnRateLimit: %d\n" |
| 2276 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2277 | "SessRate: %d\n" |
| 2278 | "SessRateLimit: %d\n" |
| 2279 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2280 | #ifdef USE_OPENSSL |
| 2281 | "SslRate: %d\n" |
| 2282 | "SslRateLimit: %d\n" |
| 2283 | "MaxSslRate: %d\n" |
| 2284 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2285 | "CompressBpsIn: %u\n" |
| 2286 | "CompressBpsOut: %u\n" |
| 2287 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2288 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2289 | "ZlibMemUsage: %ld\n" |
| 2290 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2291 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2292 | "Tasks: %d\n" |
| 2293 | "Run_queue: %d\n" |
| 2294 | "Idle_pct: %d\n" |
| 2295 | "node: %s\n" |
| 2296 | "description: %s\n" |
| 2297 | "", |
| 2298 | global.nbproc, |
| 2299 | relative_pid, |
| 2300 | pid, |
| 2301 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2302 | up, |
| 2303 | global.rlimit_memmax, |
| 2304 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2305 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2306 | actconn, totalconn, global.req_count, |
| 2307 | #ifdef USE_OPENSSL |
| 2308 | global.maxsslconn, sslconns, totalsslconns, |
| 2309 | #endif |
| 2310 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2311 | 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] | 2312 | 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] | 2313 | #ifdef USE_OPENSSL |
| 2314 | read_freq_ctr(&global.ssl_per_sec), global.ssl_lim, global.ssl_max, |
| 2315 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2316 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2317 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2318 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2319 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2320 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2321 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2322 | global.node, global.desc ? global.desc : "" |
| 2323 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2324 | |
| 2325 | if (bi_putchk(si->ib, &trash) == -1) |
| 2326 | return 0; |
| 2327 | |
| 2328 | return 1; |
| 2329 | } |
| 2330 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2331 | /* This function dumps memory usage information onto the stream interface's |
| 2332 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2333 | * completion. No state is used. |
| 2334 | */ |
| 2335 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2336 | { |
| 2337 | dump_pools_to_trash(); |
| 2338 | if (bi_putchk(si->ib, &trash) == -1) |
| 2339 | return 0; |
| 2340 | return 1; |
| 2341 | } |
| 2342 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2343 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2344 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2345 | * 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] | 2346 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2347 | 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] | 2348 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2349 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2350 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2351 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2352 | if (!(px->cap & PR_CAP_FE)) |
| 2353 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2354 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2355 | 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] | 2356 | return 0; |
| 2357 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2358 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2359 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2360 | /* name, queue */ |
| 2361 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2362 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2363 | 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] | 2364 | /* Column sub-heading for Enable or Disable server */ |
| 2365 | chunk_appendf(&trash, "<td></td>"); |
| 2366 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2367 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2368 | chunk_appendf(&trash, |
| 2369 | "<td class=ac>" |
| 2370 | "<a name=\"%s/Frontend\"></a>" |
| 2371 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2372 | "<td colspan=3></td>" |
| 2373 | "", |
| 2374 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2375 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2376 | chunk_appendf(&trash, |
| 2377 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2378 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2379 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2380 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2381 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2382 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2383 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2384 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2385 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2386 | if (px->mode == PR_MODE_HTTP) |
| 2387 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2388 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2389 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2390 | |
| 2391 | chunk_appendf(&trash, |
| 2392 | "</table></div></u></td>" |
| 2393 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2394 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2395 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2396 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2397 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2398 | U2H(px->fe_counters.sps_max), |
| 2399 | U2H(px->fe_counters.cps_max), |
| 2400 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2401 | |
| 2402 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2403 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2404 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2405 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2406 | |
| 2407 | chunk_appendf(&trash, |
| 2408 | "</table></div></u></td>" |
| 2409 | /* sessions rate : limit */ |
| 2410 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2411 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2412 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2413 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2414 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2415 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2416 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2417 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2418 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2419 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2420 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2421 | U2H(px->fe_counters.cum_sess), |
| 2422 | U2H(px->fe_counters.cum_conn), |
| 2423 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2424 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2425 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2426 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2427 | chunk_appendf(&trash, |
| 2428 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2429 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2430 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2431 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2432 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2433 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2434 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2435 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2436 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2437 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2438 | U2H(px->fe_counters.p.http.cum_req), |
| 2439 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2440 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2441 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2442 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2443 | (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] | 2444 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2445 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2446 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2447 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2448 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2449 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2450 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2451 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2452 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2453 | /* sessions: lbtot, lastsess */ |
| 2454 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2455 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2456 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2457 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2458 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2459 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2460 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2461 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2462 | "<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] | 2463 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2464 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2465 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2466 | px->fe_counters.comp_in ? |
| 2467 | (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] | 2468 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2469 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2470 | chunk_appendf(&trash, |
| 2471 | /* denied: req, resp */ |
| 2472 | "<td>%s</td><td>%s</td>" |
| 2473 | /* errors : request, connect, response */ |
| 2474 | "<td>%s</td><td></td><td></td>" |
| 2475 | /* warnings: retries, redispatches */ |
| 2476 | "<td></td><td></td>" |
| 2477 | /* server status : reflect frontend status */ |
| 2478 | "<td class=ac>%s</td>" |
| 2479 | /* rest of server: nothing */ |
| 2480 | "<td class=ac colspan=8></td></tr>" |
| 2481 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2482 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2483 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2484 | px->state == PR_STREADY ? "OPEN" : |
| 2485 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2486 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2487 | else { /* CSV mode */ |
| 2488 | chunk_appendf(&trash, |
| 2489 | /* pxid, name, queue cur, queue max, */ |
| 2490 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2491 | /* sessions : current, max, limit, total */ |
| 2492 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2493 | /* bytes : in, out */ |
| 2494 | "%lld,%lld," |
| 2495 | /* denied: req, resp */ |
| 2496 | "%lld,%lld," |
| 2497 | /* errors : request, connect, response */ |
| 2498 | "%lld,,," |
| 2499 | /* warnings: retries, redispatches */ |
| 2500 | ",," |
| 2501 | /* server status : reflect frontend status */ |
| 2502 | "%s," |
| 2503 | /* rest of server: nothing */ |
| 2504 | ",,,,,,,," |
| 2505 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2506 | "%d,%d,0,,,,%d," |
| 2507 | /* rate, rate_lim, rate_max */ |
| 2508 | "%u,%u,%u," |
| 2509 | /* check_status, check_code, check_duration */ |
| 2510 | ",,,", |
| 2511 | px->id, |
| 2512 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2513 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2514 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2515 | px->fe_counters.failed_req, |
| 2516 | px->state == PR_STREADY ? "OPEN" : |
| 2517 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2518 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2519 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2520 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2521 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2522 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2523 | if (px->mode == PR_MODE_HTTP) { |
| 2524 | for (i=1; i<6; i++) |
| 2525 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2526 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2527 | } |
| 2528 | else |
| 2529 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2530 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2531 | /* failed health analyses */ |
| 2532 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2533 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2534 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2535 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2536 | read_freq_ctr(&px->fe_req_per_sec), |
| 2537 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2538 | |
| 2539 | /* errors: cli_aborts, srv_aborts */ |
| 2540 | chunk_appendf(&trash, ",,"); |
| 2541 | |
| 2542 | /* compression: in, out, bypassed */ |
| 2543 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2544 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2545 | |
| 2546 | /* compression: comp_rsp */ |
| 2547 | chunk_appendf(&trash, "%lld,", |
| 2548 | px->fe_counters.p.http.comp_rsp); |
| 2549 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2550 | /* lastsess */ |
| 2551 | chunk_appendf(&trash, ","); |
| 2552 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2553 | /* finish with EOL */ |
| 2554 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2555 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2556 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2557 | } |
| 2558 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2559 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2560 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2561 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2562 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2563 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2564 | 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] | 2565 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2566 | struct appctx *appctx = __objt_appctx(si->end); |
| 2567 | |
| 2568 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2569 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2570 | 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] | 2571 | /* Column sub-heading for Enable or Disable server */ |
| 2572 | chunk_appendf(&trash, "<td></td>"); |
| 2573 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2574 | chunk_appendf(&trash, |
| 2575 | /* frontend name, listener name */ |
| 2576 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2577 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2578 | "", |
| 2579 | px->id, l->name, |
| 2580 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2581 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2582 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2583 | if (flags & ST_SHLGNDS) { |
| 2584 | char str[INET6_ADDRSTRLEN]; |
| 2585 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2586 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2587 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2588 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2589 | port = get_host_port(&l->addr); |
| 2590 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2591 | case AF_INET: |
| 2592 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2593 | break; |
| 2594 | case AF_INET6: |
| 2595 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2596 | break; |
| 2597 | case AF_UNIX: |
| 2598 | chunk_appendf(&trash, "unix, "); |
| 2599 | break; |
| 2600 | case -1: |
| 2601 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2602 | break; |
| 2603 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2604 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2605 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2606 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2607 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2608 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2609 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2610 | /* queue */ |
| 2611 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2612 | /* sessions rate: current, max, limit */ |
| 2613 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2614 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2615 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2616 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2617 | /* bytes: in, out */ |
| 2618 | "<td>%s</td><td>%s</td>" |
| 2619 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2620 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2621 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2622 | 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] | 2623 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2624 | chunk_appendf(&trash, |
| 2625 | /* denied: req, resp */ |
| 2626 | "<td>%s</td><td>%s</td>" |
| 2627 | /* errors: request, connect, response */ |
| 2628 | "<td>%s</td><td></td><td></td>" |
| 2629 | /* warnings: retries, redispatches */ |
| 2630 | "<td></td><td></td>" |
| 2631 | /* server status: reflect listener status */ |
| 2632 | "<td class=ac>%s</td>" |
| 2633 | /* rest of server: nothing */ |
| 2634 | "<td class=ac colspan=8></td></tr>" |
| 2635 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2636 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2637 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2638 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2639 | } |
| 2640 | else { /* CSV mode */ |
| 2641 | chunk_appendf(&trash, |
| 2642 | /* pxid, name, queue cur, queue max, */ |
| 2643 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2644 | /* sessions: current, max, limit, total */ |
| 2645 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2646 | /* bytes: in, out */ |
| 2647 | "%lld,%lld," |
| 2648 | /* denied: req, resp */ |
| 2649 | "%lld,%lld," |
| 2650 | /* errors: request, connect, response */ |
| 2651 | "%lld,,," |
| 2652 | /* warnings: retries, redispatches */ |
| 2653 | ",," |
| 2654 | /* server status: reflect listener status */ |
| 2655 | "%s," |
| 2656 | /* rest of server: nothing */ |
| 2657 | ",,,,,,,," |
| 2658 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2659 | "%d,%d,%d,,,,%d," |
| 2660 | /* rate, rate_lim, rate_max */ |
| 2661 | ",,," |
| 2662 | /* check_status, check_code, check_duration */ |
| 2663 | ",,," |
| 2664 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2665 | ",,,,,," |
| 2666 | /* failed health analyses */ |
| 2667 | "," |
| 2668 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2669 | ",,," |
| 2670 | /* errors: cli_aborts, srv_aborts */ |
| 2671 | ",," |
| 2672 | /* compression: in, out, bypassed, comp_rsp */ |
| 2673 | ",,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2674 | /* lastsess */ |
| 2675 | "," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2676 | "\n", |
| 2677 | px->id, l->name, |
| 2678 | l->nbconn, l->counters->conn_max, |
| 2679 | l->maxconn, l->counters->cum_conn, |
| 2680 | l->counters->bytes_in, l->counters->bytes_out, |
| 2681 | l->counters->denied_req, l->counters->denied_resp, |
| 2682 | l->counters->failed_req, |
| 2683 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2684 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2685 | } |
| 2686 | return 1; |
| 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 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2690 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2691 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2692 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2693 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2694 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2695 | */ |
| 2696 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2697 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2698 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2699 | struct server *ref = sv->track ? sv->track : sv; |
| 2700 | char str[INET6_ADDRSTRLEN]; |
| 2701 | struct chunk src; |
| 2702 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2703 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2704 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2705 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2706 | "DOWN", |
| 2707 | "DN %d/%d ↑", |
| 2708 | "UP %d/%d ↓", |
| 2709 | "UP", |
| 2710 | "NOLB %d/%d ↓", |
| 2711 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2712 | "DRAIN %d/%d ↓", |
| 2713 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2714 | "<i>no check</i>" |
| 2715 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2716 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2717 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2718 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2719 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2720 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2721 | "<tr class=\"%s%d\">", |
| 2722 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2723 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2724 | 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] | 2725 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2726 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2727 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2728 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2729 | chunk_appendf(&trash, |
| 2730 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2731 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2732 | "", |
| 2733 | px->id, sv->id, |
| 2734 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2735 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2736 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2737 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2738 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2739 | |
| 2740 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2741 | case AF_INET: |
| 2742 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2743 | break; |
| 2744 | case AF_INET6: |
| 2745 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2746 | break; |
| 2747 | case AF_UNIX: |
| 2748 | chunk_appendf(&trash, "unix, "); |
| 2749 | break; |
| 2750 | case -1: |
| 2751 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2752 | break; |
| 2753 | default: /* address family not supported */ |
| 2754 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2755 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2756 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2757 | /* id */ |
| 2758 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2759 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2760 | /* cookie */ |
| 2761 | if (sv->cookie) { |
| 2762 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2763 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2764 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2765 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2766 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2767 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2768 | } |
| 2769 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2770 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2771 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2772 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2773 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2774 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2775 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2776 | /* sessions rate : current, max, limit */ |
| 2777 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2778 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2779 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2780 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2781 | 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] | 2782 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2783 | |
| 2784 | chunk_appendf(&trash, |
| 2785 | /* sessions: current, max, limit, total */ |
| 2786 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2787 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2788 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2789 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2790 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2791 | U2H(sv->counters.cum_sess), |
| 2792 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2793 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2794 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2795 | if (px->mode == PR_MODE_HTTP) { |
| 2796 | unsigned long long tot; |
| 2797 | for (tot = i = 0; i < 6; i++) |
| 2798 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2799 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2800 | chunk_appendf(&trash, |
| 2801 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2802 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2803 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2804 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2805 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2806 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2807 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2808 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2809 | U2H(tot), |
| 2810 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2811 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2812 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2813 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2814 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2815 | 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] | 2816 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2817 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2818 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2819 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2820 | /* sessions: lbtot, last */ |
| 2821 | "<td>%s</td><td>%s</td>", |
| 2822 | U2H(sv->counters.cum_lbconn), |
| 2823 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2824 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2825 | chunk_appendf(&trash, |
| 2826 | /* bytes : in, out */ |
| 2827 | "<td>%s</td><td>%s</td>" |
| 2828 | /* denied: req, resp */ |
| 2829 | "<td></td><td>%s</td>" |
| 2830 | /* errors : request, connect */ |
| 2831 | "<td></td><td>%s</td>" |
| 2832 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2833 | "<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] | 2834 | /* warnings: retries, redispatches */ |
| 2835 | "<td>%lld</td><td>%lld</td>" |
| 2836 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2837 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2838 | U2H(sv->counters.failed_secu), |
| 2839 | U2H(sv->counters.failed_conns), |
| 2840 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2841 | sv->counters.cli_aborts, |
| 2842 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2843 | sv->counters.retries, sv->counters.redispatches); |
| 2844 | |
| 2845 | /* status, lest check */ |
| 2846 | chunk_appendf(&trash, "<td class=ac>"); |
| 2847 | |
| 2848 | if (sv->state & SRV_MAINTAIN) { |
| 2849 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2850 | chunk_appendf(&trash, "MAINT"); |
| 2851 | } |
| 2852 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2853 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2854 | chunk_appendf(&trash, "MAINT(via)"); |
| 2855 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2856 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2857 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2858 | chunk_appendf(&trash, |
| 2859 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2860 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2861 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2862 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2863 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2864 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2865 | chunk_appendf(&trash, |
| 2866 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 2867 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2868 | get_check_status_info(sv->check.status)); |
| 2869 | |
| 2870 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2871 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2872 | |
| 2873 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2874 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2875 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2876 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2877 | get_check_status_description(sv->check.status)); |
| 2878 | if (*sv->check.desc) { |
| 2879 | chunk_appendf(&trash, ": "); |
| 2880 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2881 | chunk_htmlencode(&trash, &src); |
| 2882 | } |
| 2883 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2884 | } |
| 2885 | else |
| 2886 | chunk_appendf(&trash, "</td><td>"); |
| 2887 | |
| 2888 | chunk_appendf(&trash, |
| 2889 | /* weight */ |
| 2890 | "</td><td class=ac>%d</td>" |
| 2891 | /* act, bck */ |
| 2892 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2893 | "", |
| 2894 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2895 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2896 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2897 | |
| 2898 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2899 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2900 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2901 | |
| 2902 | if (ref->observe) |
| 2903 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2904 | |
| 2905 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2906 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2907 | "<td>%lld</td><td>%s</td>" |
| 2908 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2909 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2910 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2911 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2912 | else if (sv != ref) { |
| 2913 | if (sv->state & SRV_MAINTAIN) |
| 2914 | chunk_appendf(&trash, |
| 2915 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2916 | ref->proxy->id, ref->id); |
| 2917 | else |
| 2918 | chunk_appendf(&trash, |
| 2919 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2920 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2921 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2922 | else |
| 2923 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2924 | |
| 2925 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2926 | if (sv->state & SRV_WARMINGUP) |
| 2927 | 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] | 2928 | else |
| 2929 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2930 | } |
| 2931 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2932 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2933 | "DOWN,", |
| 2934 | "DOWN %d/%d,", |
| 2935 | "UP %d/%d,", |
| 2936 | "UP,", |
| 2937 | "NOLB %d/%d,", |
| 2938 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2939 | "DRAIN %d/%d,", |
| 2940 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2941 | "no check," |
| 2942 | }; |
| 2943 | |
| 2944 | chunk_appendf(&trash, |
| 2945 | /* pxid, name */ |
| 2946 | "%s,%s," |
| 2947 | /* queue : current, max */ |
| 2948 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2949 | /* sessions : current, max, limit, total */ |
| 2950 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2951 | /* bytes : in, out */ |
| 2952 | "%lld,%lld," |
| 2953 | /* denied: req, resp */ |
| 2954 | ",%lld," |
| 2955 | /* errors : request, connect, response */ |
| 2956 | ",%lld,%lld," |
| 2957 | /* warnings: retries, redispatches */ |
| 2958 | "%lld,%lld," |
| 2959 | "", |
| 2960 | px->id, sv->id, |
| 2961 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2962 | 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] | 2963 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2964 | sv->counters.failed_secu, |
| 2965 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2966 | sv->counters.retries, sv->counters.redispatches); |
| 2967 | |
| 2968 | /* status */ |
| 2969 | if (sv->state & SRV_MAINTAIN) |
| 2970 | chunk_appendf(&trash, "MAINT,"); |
| 2971 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2972 | chunk_appendf(&trash, "MAINT(via),"); |
| 2973 | else |
| 2974 | chunk_appendf(&trash, |
| 2975 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2976 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2977 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2978 | |
| 2979 | chunk_appendf(&trash, |
| 2980 | /* weight, active, backup */ |
| 2981 | "%d,%d,%d," |
| 2982 | "", |
| 2983 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2984 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2985 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2986 | |
| 2987 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2988 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2989 | chunk_appendf(&trash, |
| 2990 | "%lld,%lld,%d,%d,", |
| 2991 | sv->counters.failed_checks, sv->counters.down_trans, |
| 2992 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 2993 | else |
| 2994 | chunk_appendf(&trash, ",,,,"); |
| 2995 | |
| 2996 | /* queue limit, pid, iid, sid, */ |
| 2997 | chunk_appendf(&trash, |
| 2998 | "%s," |
| 2999 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3000 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3001 | relative_pid, px->uuid, sv->puid); |
| 3002 | |
| 3003 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3004 | if (sv->state & SRV_WARMINGUP) |
| 3005 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3006 | |
| 3007 | /* sessions: lbtot */ |
| 3008 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3009 | |
| 3010 | /* tracked */ |
| 3011 | if (sv->track) |
| 3012 | chunk_appendf(&trash, "%s/%s,", |
| 3013 | sv->track->proxy->id, sv->track->id); |
| 3014 | else |
| 3015 | chunk_appendf(&trash, ","); |
| 3016 | |
| 3017 | /* type */ |
| 3018 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3019 | |
| 3020 | /* rate */ |
| 3021 | chunk_appendf(&trash, "%u,,%u,", |
| 3022 | read_freq_ctr(&sv->sess_per_sec), |
| 3023 | sv->counters.sps_max); |
| 3024 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3025 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3026 | /* check_status */ |
| 3027 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3028 | |
| 3029 | /* check_code */ |
| 3030 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3031 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3032 | else |
| 3033 | chunk_appendf(&trash, ","); |
| 3034 | |
| 3035 | /* check_duration */ |
| 3036 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3037 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3038 | else |
| 3039 | chunk_appendf(&trash, ","); |
| 3040 | |
| 3041 | } |
| 3042 | else |
| 3043 | chunk_appendf(&trash, ",,,"); |
| 3044 | |
| 3045 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3046 | if (px->mode == PR_MODE_HTTP) { |
| 3047 | for (i=1; i<6; i++) |
| 3048 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3049 | |
| 3050 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3051 | } |
| 3052 | else |
| 3053 | chunk_appendf(&trash, ",,,,,,"); |
| 3054 | |
| 3055 | /* failed health analyses */ |
| 3056 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3057 | |
| 3058 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3059 | chunk_appendf(&trash, ",,,"); |
| 3060 | |
| 3061 | /* errors: cli_aborts, srv_aborts */ |
| 3062 | chunk_appendf(&trash, "%lld,%lld,", |
| 3063 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3064 | |
| 3065 | /* compression: in, out, bypassed, comp_rsp */ |
| 3066 | chunk_appendf(&trash, ",,,,"); |
| 3067 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3068 | /* lastsess */ |
| 3069 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3070 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3071 | /* finish with EOL */ |
| 3072 | chunk_appendf(&trash, "\n"); |
| 3073 | } |
| 3074 | return 1; |
| 3075 | } |
| 3076 | |
| 3077 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3078 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3079 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3080 | */ |
| 3081 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3082 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3083 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3084 | struct chunk src; |
| 3085 | int i; |
| 3086 | |
| 3087 | if (!(px->cap & PR_CAP_BE)) |
| 3088 | return 0; |
| 3089 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3090 | 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] | 3091 | return 0; |
| 3092 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3093 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3094 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3095 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3096 | /* Column sub-heading for Enable or Disable server */ |
| 3097 | chunk_appendf(&trash, "<td></td>"); |
| 3098 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3099 | chunk_appendf(&trash, |
| 3100 | "<td class=ac>" |
| 3101 | /* name */ |
| 3102 | "%s<a name=\"%s/Backend\"></a>" |
| 3103 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3104 | "", |
| 3105 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3106 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3107 | |
| 3108 | if (flags & ST_SHLGNDS) { |
| 3109 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3110 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3111 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3112 | |
| 3113 | /* cookie */ |
| 3114 | if (px->cookie_name) { |
| 3115 | chunk_appendf(&trash, ", cookie: '"); |
| 3116 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3117 | chunk_htmlencode(&trash, &src); |
| 3118 | chunk_appendf(&trash, "'"); |
| 3119 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3120 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3124 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3125 | /* queue : current, max */ |
| 3126 | "<td>%s</td><td>%s</td><td></td>" |
| 3127 | /* sessions rate : current, max, limit */ |
| 3128 | "<td>%s</td><td>%s</td><td></td>" |
| 3129 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3130 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3131 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3132 | 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] | 3133 | |
| 3134 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3135 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3136 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3137 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3138 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3139 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3140 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3141 | U2H(px->be_counters.cum_conn), |
| 3142 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3143 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3144 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3145 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3146 | chunk_appendf(&trash, |
| 3147 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3148 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3149 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3150 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3151 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3152 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3153 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3154 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3155 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3156 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3157 | U2H(px->be_counters.p.http.cum_req), |
| 3158 | U2H(px->be_counters.p.http.rsp[1]), |
| 3159 | U2H(px->be_counters.p.http.rsp[2]), |
| 3160 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3161 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3162 | (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] | 3163 | U2H(px->be_counters.p.http.rsp[3]), |
| 3164 | U2H(px->be_counters.p.http.rsp[4]), |
| 3165 | U2H(px->be_counters.p.http.rsp[5]), |
| 3166 | U2H(px->be_counters.p.http.rsp[0]), |
| 3167 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3171 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3172 | /* sessions: lbtot, last */ |
| 3173 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3174 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3175 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3176 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3177 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3178 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3179 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3180 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3181 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3182 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3183 | "<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] | 3184 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3185 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3186 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3187 | px->be_counters.comp_in ? |
| 3188 | (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] | 3189 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3190 | |
| 3191 | chunk_appendf(&trash, |
| 3192 | /* denied: req, resp */ |
| 3193 | "<td>%s</td><td>%s</td>" |
| 3194 | /* errors : request, connect */ |
| 3195 | "<td></td><td>%s</td>" |
| 3196 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3197 | "<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] | 3198 | /* warnings: retries, redispatches */ |
| 3199 | "<td>%lld</td><td>%lld</td>" |
| 3200 | /* backend status: reflect backend status (up/down): we display UP |
| 3201 | * if the backend has known working servers or if it has no server at |
| 3202 | * all (eg: for stats). Then we display the total weight, number of |
| 3203 | * active and backups. */ |
| 3204 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3205 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3206 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3207 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3208 | U2H(px->be_counters.failed_conns), |
| 3209 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3210 | px->be_counters.cli_aborts, |
| 3211 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3212 | px->be_counters.retries, px->be_counters.redispatches, |
| 3213 | human_time(now.tv_sec - px->last_change, 1), |
| 3214 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3215 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3216 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3217 | px->srv_act, px->srv_bck); |
| 3218 | |
| 3219 | chunk_appendf(&trash, |
| 3220 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3221 | "<td class=ac> </td><td>%d</td>" |
| 3222 | "<td>%s</td>" |
| 3223 | "<td></td>" |
| 3224 | "</tr>", |
| 3225 | px->down_trans, |
| 3226 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3227 | } |
| 3228 | else { /* CSV mode */ |
| 3229 | chunk_appendf(&trash, |
| 3230 | /* pxid, name */ |
| 3231 | "%s,BACKEND," |
| 3232 | /* queue : current, max */ |
| 3233 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3234 | /* sessions : current, max, limit, total */ |
| 3235 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3236 | /* bytes : in, out */ |
| 3237 | "%lld,%lld," |
| 3238 | /* denied: req, resp */ |
| 3239 | "%lld,%lld," |
| 3240 | /* errors : request, connect, response */ |
| 3241 | ",%lld,%lld," |
| 3242 | /* warnings: retries, redispatches */ |
| 3243 | "%lld,%lld," |
| 3244 | /* backend status: reflect backend status (up/down): we display UP |
| 3245 | * if the backend has known working servers or if it has no server at |
| 3246 | * all (eg: for stats). Then we display the total weight, number of |
| 3247 | * active and backups. */ |
| 3248 | "%s," |
| 3249 | "%d,%d,%d," |
| 3250 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3251 | ",%d,%d,%d,," |
| 3252 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3253 | "%d,%d,0,,%lld,,%d," |
| 3254 | /* rate, rate_lim, rate_max, */ |
| 3255 | "%u,,%u," |
| 3256 | /* check_status, check_code, check_duration */ |
| 3257 | ",,,", |
| 3258 | px->id, |
| 3259 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3260 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3261 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3262 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3263 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3264 | px->be_counters.retries, px->be_counters.redispatches, |
| 3265 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3266 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3267 | px->srv_act, px->srv_bck, |
| 3268 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3269 | px->srv?be_downtime(px):0, |
| 3270 | relative_pid, px->uuid, |
| 3271 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3272 | read_freq_ctr(&px->be_sess_per_sec), |
| 3273 | px->be_counters.sps_max); |
| 3274 | |
| 3275 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3276 | if (px->mode == PR_MODE_HTTP) { |
| 3277 | for (i=1; i<6; i++) |
| 3278 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3279 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3280 | } |
| 3281 | else |
| 3282 | chunk_appendf(&trash, ",,,,,,"); |
| 3283 | |
| 3284 | /* failed health analyses */ |
| 3285 | chunk_appendf(&trash, ","); |
| 3286 | |
| 3287 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3288 | chunk_appendf(&trash, ",,,"); |
| 3289 | |
| 3290 | /* errors: cli_aborts, srv_aborts */ |
| 3291 | chunk_appendf(&trash, "%lld,%lld,", |
| 3292 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3293 | |
| 3294 | /* compression: in, out, bypassed */ |
| 3295 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3296 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3297 | |
| 3298 | /* compression: comp_rsp */ |
| 3299 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3300 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3301 | /* lastsess */ |
| 3302 | chunk_appendf(&trash, "%d,", be_lastsession(px)); |
| 3303 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3304 | /* finish with EOL */ |
| 3305 | chunk_appendf(&trash, "\n"); |
| 3306 | } |
| 3307 | return 1; |
| 3308 | } |
| 3309 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3310 | /* 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] | 3311 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3312 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3313 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3314 | 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] | 3315 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3316 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3317 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3318 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3319 | 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] | 3320 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3321 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3322 | /* 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] | 3323 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3324 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3325 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3326 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3327 | 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] | 3328 | } |
| 3329 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3330 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3331 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3332 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3333 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3334 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3335 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | /* print a new table */ |
| 3339 | chunk_appendf(&trash, |
| 3340 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3341 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3342 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3343 | |
| 3344 | chunk_appendf(&trash, |
| 3345 | "<a name=\"%s\"></a>%s" |
| 3346 | "<a class=px href=\"#%s\">%s</a>", |
| 3347 | px->id, |
| 3348 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3349 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3350 | |
| 3351 | if (uri->flags & ST_SHLGNDS) { |
| 3352 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3353 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3354 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3355 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3356 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3360 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3361 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3362 | "</tr>\n" |
| 3363 | "</table>\n" |
| 3364 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3365 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3366 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3367 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3368 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3369 | 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] | 3370 | /* Column heading for Enable or Disable server */ |
| 3371 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3372 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3373 | |
| 3374 | chunk_appendf(&trash, |
| 3375 | "<th rowspan=2></th>" |
| 3376 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3377 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3378 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3379 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3380 | "<th colspan=9>Server</th>" |
| 3381 | "</tr>\n" |
| 3382 | "<tr class=\"titre\">" |
| 3383 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3384 | "<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] | 3385 | "<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] | 3386 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3387 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3388 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3389 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3390 | "<th>Thrtle</th>\n" |
| 3391 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3392 | } |
| 3393 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3394 | /* 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] | 3395 | * 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] | 3396 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3397 | 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] | 3398 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3399 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3400 | chunk_appendf(&trash, "</table>"); |
| 3401 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3402 | 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] | 3403 | /* close the form used to enable/disable this proxy servers */ |
| 3404 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3405 | "Choose the action to perform on the checked servers : " |
| 3406 | "<select name=action>" |
| 3407 | "<option value=\"\"></option>" |
| 3408 | "<option value=\"disable\">Disable</option>" |
| 3409 | "<option value=\"enable\">Enable</option>" |
| 3410 | "<option value=\"stop\">Soft Stop</option>" |
| 3411 | "<option value=\"start\">Soft Start</option>" |
| 3412 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3413 | "</select>" |
| 3414 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3415 | " <input type=\"submit\" value=\"Apply\">" |
| 3416 | "</form>", |
| 3417 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3418 | } |
| 3419 | |
| 3420 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3421 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3422 | |
| 3423 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3424 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3425 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3426 | * buffer space, or non-zero if everything completed. This function is used |
| 3427 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3428 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3429 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3430 | 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] | 3431 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3432 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3433 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3434 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3435 | 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] | 3436 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3437 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3438 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3439 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3440 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3441 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3442 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3443 | if (uri && uri->scope) { |
| 3444 | /* we have a limited scope, we have to check the proxy name */ |
| 3445 | struct stat_scope *scope; |
| 3446 | int len; |
| 3447 | |
| 3448 | len = strlen(px->id); |
| 3449 | scope = uri->scope; |
| 3450 | |
| 3451 | while (scope) { |
| 3452 | /* match exact proxy name */ |
| 3453 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3454 | break; |
| 3455 | |
| 3456 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3457 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3458 | break; |
| 3459 | scope = scope->next; |
| 3460 | } |
| 3461 | |
| 3462 | /* proxy name not found : don't dump anything */ |
| 3463 | if (scope == NULL) |
| 3464 | return 1; |
| 3465 | } |
| 3466 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3467 | /* if the user has requested a limited output and the proxy |
| 3468 | * name does not match, skip it. |
| 3469 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3470 | if (appctx->ctx.stats.scope_len && |
| 3471 | 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] | 3472 | return 1; |
| 3473 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3474 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3475 | (appctx->ctx.stats.iid != -1) && |
| 3476 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3477 | return 1; |
| 3478 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3479 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3480 | /* fall through */ |
| 3481 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3482 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3483 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3484 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3485 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3486 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3487 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3488 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3489 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3490 | /* fall through */ |
| 3491 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3492 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3493 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3494 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3495 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3496 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3497 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3498 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3499 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3500 | /* fall through */ |
| 3501 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3502 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3503 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3504 | 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] | 3505 | if (buffer_almost_full(rep->buf)) { |
| 3506 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3507 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3508 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3509 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3510 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3511 | if (!l->counters) |
| 3512 | continue; |
| 3513 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3514 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3515 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3516 | break; |
| 3517 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3518 | 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] | 3519 | continue; |
| 3520 | } |
| 3521 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3522 | /* print the frontend */ |
| 3523 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3524 | if (bi_putchk(rep, &trash) == -1) |
| 3525 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3526 | } |
| 3527 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3528 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3529 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3530 | /* fall through */ |
| 3531 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3532 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3533 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3534 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3535 | 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] | 3536 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3537 | if (buffer_almost_full(rep->buf)) { |
| 3538 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3539 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3540 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3541 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3542 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3543 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3544 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3545 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3546 | break; |
| 3547 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3548 | 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] | 3549 | continue; |
| 3550 | } |
| 3551 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3552 | if (sv->track) |
| 3553 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3554 | else |
| 3555 | svs = sv; |
| 3556 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3557 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3558 | if (!(svs->check.state & CHK_ST_ENABLED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3559 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3560 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 3561 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3562 | sv_state = 3; /* UP */ |
| 3563 | else |
| 3564 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3565 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3566 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3567 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3568 | else if (svs->state & SRV_GOINGDOWN) |
| 3569 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3570 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3571 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 3572 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3573 | sv_state = 1; /* going up */ |
| 3574 | else |
| 3575 | sv_state = 0; /* DOWN */ |
| 3576 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3577 | 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] | 3578 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3579 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3580 | continue; |
| 3581 | } |
| 3582 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3583 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3584 | if (bi_putchk(rep, &trash) == -1) |
| 3585 | return 0; |
| 3586 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3587 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3588 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3589 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3590 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3591 | case STAT_PX_ST_BE: |
| 3592 | /* print the backend */ |
| 3593 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3594 | if (bi_putchk(rep, &trash) == -1) |
| 3595 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3596 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3597 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3598 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3599 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3600 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3601 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3602 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3603 | if (bi_putchk(rep, &trash) == -1) |
| 3604 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3605 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3606 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3607 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3608 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3609 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3610 | case STAT_PX_ST_FIN: |
| 3611 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3612 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3613 | default: |
| 3614 | /* unknown state, we should put an abort() here ! */ |
| 3615 | return 1; |
| 3616 | } |
| 3617 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3618 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3619 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3620 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3621 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3622 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3623 | { |
| 3624 | /* WARNING! This must fit in the first buffer !!! */ |
| 3625 | chunk_appendf(&trash, |
| 3626 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3627 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3628 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3629 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3630 | "<style type=\"text/css\"><!--\n" |
| 3631 | "body {" |
| 3632 | " font-family: arial, helvetica, sans-serif;" |
| 3633 | " font-size: 12px;" |
| 3634 | " font-weight: normal;" |
| 3635 | " color: black;" |
| 3636 | " background: white;" |
| 3637 | "}\n" |
| 3638 | "th,td {" |
| 3639 | " font-size: 10px;" |
| 3640 | "}\n" |
| 3641 | "h1 {" |
| 3642 | " font-size: x-large;" |
| 3643 | " margin-bottom: 0.5em;" |
| 3644 | "}\n" |
| 3645 | "h2 {" |
| 3646 | " font-family: helvetica, arial;" |
| 3647 | " font-size: x-large;" |
| 3648 | " font-weight: bold;" |
| 3649 | " font-style: italic;" |
| 3650 | " color: #6020a0;" |
| 3651 | " margin-top: 0em;" |
| 3652 | " margin-bottom: 0em;" |
| 3653 | "}\n" |
| 3654 | "h3 {" |
| 3655 | " font-family: helvetica, arial;" |
| 3656 | " font-size: 16px;" |
| 3657 | " font-weight: bold;" |
| 3658 | " color: #b00040;" |
| 3659 | " background: #e8e8d0;" |
| 3660 | " margin-top: 0em;" |
| 3661 | " margin-bottom: 0em;" |
| 3662 | "}\n" |
| 3663 | "li {" |
| 3664 | " margin-top: 0.25em;" |
| 3665 | " margin-right: 2em;" |
| 3666 | "}\n" |
| 3667 | ".hr {margin-top: 0.25em;" |
| 3668 | " border-color: black;" |
| 3669 | " border-bottom-style: solid;" |
| 3670 | "}\n" |
| 3671 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3672 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3673 | ".frontend {background: #e8e8d0;}\n" |
| 3674 | ".socket {background: #d0d0d0;}\n" |
| 3675 | ".backend {background: #e8e8d0;}\n" |
| 3676 | ".active0 {background: #ff9090;}\n" |
| 3677 | ".active1 {background: #ffd020;}\n" |
| 3678 | ".active2 {background: #ffffa0;}\n" |
| 3679 | ".active3 {background: #c0ffc0;}\n" |
| 3680 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3681 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3682 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3683 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3684 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3685 | ".backup0 {background: #ff9090;}\n" |
| 3686 | ".backup1 {background: #ff80ff;}\n" |
| 3687 | ".backup2 {background: #c060ff;}\n" |
| 3688 | ".backup3 {background: #b0d0ff;}\n" |
| 3689 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3690 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3691 | ".backup6 {background: #c060ff;}\n" |
| 3692 | ".backup7 {background: #cc9900;}\n" |
| 3693 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3694 | ".maintain {background: #c07820;}\n" |
| 3695 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3696 | "\n" |
| 3697 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3698 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3699 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3700 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3701 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3702 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3703 | "\n" |
| 3704 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3705 | "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" |
| 3706 | "table.tbl td.ac { text-align: center;}\n" |
| 3707 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3708 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3709 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3710 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3711 | "\n" |
| 3712 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3713 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3714 | "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] | 3715 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3716 | "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] | 3717 | "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] | 3718 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3719 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3720 | " display:block;\n" |
| 3721 | " visibility:hidden;\n" |
| 3722 | " z-index:2147483647;\n" |
| 3723 | " position:absolute;\n" |
| 3724 | " padding:2px 4px 3px;\n" |
| 3725 | " background:#f0f060; color:#000000;\n" |
| 3726 | " border:1px solid #7040c0;\n" |
| 3727 | " white-space:nowrap;\n" |
| 3728 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3729 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3730 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3731 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3732 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3733 | "-->\n" |
| 3734 | "</style></head>\n", |
| 3735 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3736 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3737 | ); |
| 3738 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3739 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3740 | /* 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] | 3741 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3742 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3743 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3744 | 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] | 3745 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3746 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3747 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3748 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3749 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3750 | /* WARNING! this has to fit the first packet too. |
| 3751 | * We are around 3.5 kB, add adding entries will |
| 3752 | * become tricky if we want to support 4kB buffers ! |
| 3753 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3754 | chunk_appendf(&trash, |
| 3755 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3756 | PRODUCT_NAME "%s</a></h1>\n" |
| 3757 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3758 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3759 | "<h3>> General process information</h3>\n" |
| 3760 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3761 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3762 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3763 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3764 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3765 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3766 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3767 | "</td><td align=\"center\" nowrap>\n" |
| 3768 | "<table class=\"lgd\"><tr>\n" |
| 3769 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3770 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3771 | "</tr><tr>\n" |
| 3772 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3773 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3774 | "</tr><tr>\n" |
| 3775 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3776 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3777 | "</tr><tr>\n" |
| 3778 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3779 | "</tr><tr>\n" |
| 3780 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3781 | "</tr><tr>\n" |
| 3782 | "<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] | 3783 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3784 | "<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] | 3785 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3786 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3787 | "</td>" |
| 3788 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3789 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3790 | "", |
| 3791 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3792 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3793 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3794 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3795 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3796 | pid, relative_pid, global.nbproc, |
| 3797 | up / 86400, (up % 86400) / 3600, |
| 3798 | (up % 3600) / 60, (up % 60), |
| 3799 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3800 | global.rlimit_memmax ? " MB" : "", |
| 3801 | global.rlimit_nofile, |
| 3802 | global.maxsock, global.maxconn, global.maxpipes, |
| 3803 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3804 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3805 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3806 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3807 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3808 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3809 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3810 | |
| 3811 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3812 | "<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] | 3813 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3814 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3815 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3816 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3817 | STAT_SCOPE_TXT_MAXLEN); |
| 3818 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3819 | /* 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] | 3820 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3821 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3822 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3823 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3824 | 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] | 3825 | } |
| 3826 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3827 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3828 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3829 | "<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] | 3830 | uri->uri_prefix, |
| 3831 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3832 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3833 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3834 | else |
| 3835 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3836 | "<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] | 3837 | uri->uri_prefix, |
| 3838 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3839 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3840 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3841 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3842 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3843 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3844 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3845 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3846 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3847 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3848 | "", |
| 3849 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3850 | else |
| 3851 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3852 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3853 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3854 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3855 | ";norefresh", |
| 3856 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3857 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3858 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3859 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3860 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3861 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3862 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3863 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3864 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3865 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3866 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3867 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3868 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3869 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3870 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3871 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3872 | chunk_appendf(&trash, |
| 3873 | "</ul></td>" |
| 3874 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3875 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3876 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3877 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3878 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3879 | "</ul>" |
| 3880 | "</td>" |
| 3881 | "</tr></table>\n" |
| 3882 | "" |
| 3883 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3884 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3885 | if (appctx->ctx.stats.st_code) { |
| 3886 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3887 | case STAT_STATUS_DONE: |
| 3888 | chunk_appendf(&trash, |
| 3889 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3890 | "<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] | 3891 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3892 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3893 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3894 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3895 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3896 | break; |
| 3897 | case STAT_STATUS_NONE: |
| 3898 | chunk_appendf(&trash, |
| 3899 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3900 | "<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] | 3901 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3902 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3903 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3904 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3905 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3906 | break; |
| 3907 | case STAT_STATUS_PART: |
| 3908 | chunk_appendf(&trash, |
| 3909 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3910 | "<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] | 3911 | "Action partially processed.<br>" |
| 3912 | "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] | 3913 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3914 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3915 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3916 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3917 | break; |
| 3918 | case STAT_STATUS_ERRP: |
| 3919 | chunk_appendf(&trash, |
| 3920 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3921 | "<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] | 3922 | "Action not processed because of invalid parameters." |
| 3923 | "<ul>" |
| 3924 | "<li>The action is maybe unknown.</li>" |
| 3925 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3926 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3927 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3928 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3929 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3930 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3931 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3932 | break; |
| 3933 | case STAT_STATUS_EXCD: |
| 3934 | chunk_appendf(&trash, |
| 3935 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3936 | "<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] | 3937 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3938 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3939 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3940 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3941 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3942 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3943 | break; |
| 3944 | case STAT_STATUS_DENY: |
| 3945 | chunk_appendf(&trash, |
| 3946 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3947 | "<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] | 3948 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3949 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3950 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3951 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3952 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3953 | break; |
| 3954 | default: |
| 3955 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3956 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3957 | "<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] | 3958 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3959 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3960 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3961 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3962 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3963 | } |
| 3964 | chunk_appendf(&trash, "<p>\n"); |
| 3965 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3966 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3967 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3968 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3969 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3970 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3971 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3972 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3973 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3974 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3975 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3976 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3977 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3978 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3979 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3980 | * and the session must be closed, or -1 in case of any error. This function is |
| 3981 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3982 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3983 | 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] | 3984 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3985 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3986 | struct channel *rep = si->ib; |
| 3987 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3988 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3989 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3990 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3991 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3992 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3993 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3994 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3995 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3996 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3997 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3998 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3999 | else |
| 4000 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4001 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4002 | if (bi_putchk(rep, &trash) == -1) |
| 4003 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4004 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4005 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4006 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4007 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4008 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4009 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4010 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4011 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4012 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4013 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4014 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4015 | appctx->ctx.stats.px = proxy; |
| 4016 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4017 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4018 | /* fall through */ |
| 4019 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4020 | case STAT_ST_LIST: |
| 4021 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4022 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4023 | if (buffer_almost_full(rep->buf)) { |
| 4024 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4025 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4026 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4027 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4028 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4029 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4030 | 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] | 4031 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4032 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4033 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4034 | appctx->ctx.stats.px = px->next; |
| 4035 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4036 | } |
| 4037 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4038 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4039 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4040 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4041 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4042 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4043 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4044 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4045 | if (bi_putchk(rep, &trash) == -1) |
| 4046 | return 0; |
| 4047 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4048 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4049 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4050 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4051 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4052 | case STAT_ST_FIN: |
| 4053 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4054 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4055 | default: |
| 4056 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4057 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4058 | return -1; |
| 4059 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4060 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4061 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4062 | /* We reached the stats page through a POST request. The appctx is |
| 4063 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4064 | * Parse the posted data and enable/disable servers if necessary. |
| 4065 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4066 | */ |
| 4067 | static int stats_process_http_post(struct stream_interface *si) |
| 4068 | { |
| 4069 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4070 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4071 | |
| 4072 | struct proxy *px = NULL; |
| 4073 | struct server *sv = NULL; |
| 4074 | |
| 4075 | char key[LINESIZE]; |
| 4076 | int action = ST_ADM_ACTION_NONE; |
| 4077 | int reprocess = 0; |
| 4078 | |
| 4079 | int total_servers = 0; |
| 4080 | int altered_servers = 0; |
| 4081 | |
| 4082 | char *first_param, *cur_param, *next_param, *end_params; |
| 4083 | char *st_cur_param = NULL; |
| 4084 | char *st_next_param = NULL; |
| 4085 | |
| 4086 | struct chunk *temp; |
| 4087 | int reql; |
| 4088 | |
| 4089 | temp = get_trash_chunk(); |
| 4090 | if (temp->size < s->txn.req.body_len) { |
| 4091 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4092 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4093 | goto out; |
| 4094 | } |
| 4095 | |
| 4096 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 4097 | if (reql <= 0) { |
| 4098 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4099 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4100 | return 0; |
| 4101 | } |
| 4102 | |
| 4103 | first_param = temp->str; |
| 4104 | end_params = temp->str + reql; |
| 4105 | cur_param = next_param = end_params; |
| 4106 | *end_params = '\0'; |
| 4107 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4108 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4109 | |
| 4110 | /* |
| 4111 | * Parse the parameters in reverse order to only store the last value. |
| 4112 | * From the html form, the backend and the action are at the end. |
| 4113 | */ |
| 4114 | while (cur_param > first_param) { |
| 4115 | char *value; |
| 4116 | int poffset, plen; |
| 4117 | |
| 4118 | cur_param--; |
| 4119 | |
| 4120 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4121 | reprocess_servers: |
| 4122 | /* Parse the key */ |
| 4123 | poffset = (cur_param != first_param ? 1 : 0); |
| 4124 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4125 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4126 | strncpy(key, cur_param + poffset, plen); |
| 4127 | key[plen - 1] = '\0'; |
| 4128 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4129 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4130 | goto out; |
| 4131 | } |
| 4132 | |
| 4133 | /* Parse the value */ |
| 4134 | value = key; |
| 4135 | while (*value != '\0' && *value != '=') { |
| 4136 | value++; |
| 4137 | } |
| 4138 | if (*value == '=') { |
| 4139 | /* Ok, a value is found, we can mark the end of the key */ |
| 4140 | *value++ = '\0'; |
| 4141 | } |
| 4142 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4143 | break; |
| 4144 | |
| 4145 | /* Now we can check the key to see what to do */ |
| 4146 | if (!px && (strcmp(key, "b") == 0)) { |
| 4147 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4148 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4149 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4150 | goto out; |
| 4151 | } |
| 4152 | } |
| 4153 | else if (!action && (strcmp(key, "action") == 0)) { |
| 4154 | if (strcmp(value, "disable") == 0) { |
| 4155 | action = ST_ADM_ACTION_DISABLE; |
| 4156 | } |
| 4157 | else if (strcmp(value, "enable") == 0) { |
| 4158 | action = ST_ADM_ACTION_ENABLE; |
| 4159 | } |
| 4160 | else if (strcmp(value, "stop") == 0) { |
| 4161 | action = ST_ADM_ACTION_STOP; |
| 4162 | } |
| 4163 | else if (strcmp(value, "start") == 0) { |
| 4164 | action = ST_ADM_ACTION_START; |
| 4165 | } |
| 4166 | else if (strcmp(value, "shutdown") == 0) { |
| 4167 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4168 | } |
| 4169 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4170 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4171 | goto out; |
| 4172 | } |
| 4173 | } |
| 4174 | else if (strcmp(key, "s") == 0) { |
| 4175 | if (!(px && action)) { |
| 4176 | /* |
| 4177 | * Indicates that we'll need to reprocess the parameters |
| 4178 | * as soon as backend and action are known |
| 4179 | */ |
| 4180 | if (!reprocess) { |
| 4181 | st_cur_param = cur_param; |
| 4182 | st_next_param = next_param; |
| 4183 | } |
| 4184 | reprocess = 1; |
| 4185 | } |
| 4186 | else if ((sv = findserver(px, value)) != NULL) { |
| 4187 | switch (action) { |
| 4188 | case ST_ADM_ACTION_DISABLE: |
| 4189 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 4190 | /* Not already in maintenance, we can change the server state */ |
| 4191 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 4192 | sv->check.state |= CHK_ST_PAUSED; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4193 | set_server_down(&sv->check); |
| 4194 | altered_servers++; |
| 4195 | total_servers++; |
| 4196 | } |
| 4197 | break; |
| 4198 | case ST_ADM_ACTION_ENABLE: |
| 4199 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
Willy Tarreau | a3ae932 | 2013-12-28 21:28:49 +0100 | [diff] [blame] | 4200 | /* Already in maintenance, we can change the server state. |
| 4201 | * If this server tracks the status of another one, |
| 4202 | * we must restore the good status. |
| 4203 | */ |
| 4204 | if (!sv->track || (sv->track->state & SRV_RUNNING)) { |
| 4205 | set_server_up(&sv->check); |
| 4206 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 4207 | } |
| 4208 | else { |
| 4209 | sv->state &= ~SRV_MAINTAIN; |
| 4210 | sv->check.state &= ~CHK_ST_PAUSED; |
| 4211 | set_server_down(&sv->check); |
| 4212 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4213 | altered_servers++; |
| 4214 | total_servers++; |
| 4215 | } |
| 4216 | break; |
| 4217 | case ST_ADM_ACTION_STOP: |
| 4218 | case ST_ADM_ACTION_START: |
| 4219 | if (action == ST_ADM_ACTION_START) |
| 4220 | sv->uweight = sv->iweight; |
| 4221 | else |
| 4222 | sv->uweight = 0; |
| 4223 | |
| 4224 | server_recalc_eweight(sv); |
| 4225 | set_server_drain_state(sv); |
| 4226 | |
| 4227 | altered_servers++; |
| 4228 | total_servers++; |
| 4229 | break; |
| 4230 | case ST_ADM_ACTION_SHUTDOWN: |
| 4231 | if (px->state != PR_STSTOPPED) { |
| 4232 | struct session *sess, *sess_bck; |
| 4233 | |
| 4234 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4235 | if (sess->srv_conn == sv) |
| 4236 | session_shutdown(sess, SN_ERR_KILLED); |
| 4237 | |
| 4238 | altered_servers++; |
| 4239 | total_servers++; |
| 4240 | } |
| 4241 | break; |
| 4242 | } |
| 4243 | } else { |
| 4244 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4245 | total_servers++; |
| 4246 | } |
| 4247 | } |
| 4248 | if (reprocess && px && action) { |
| 4249 | /* Now, we know the backend and the action chosen by the user. |
| 4250 | * We can safely restart from the first server parameter |
| 4251 | * to reprocess them |
| 4252 | */ |
| 4253 | cur_param = st_cur_param; |
| 4254 | next_param = st_next_param; |
| 4255 | reprocess = 0; |
| 4256 | goto reprocess_servers; |
| 4257 | } |
| 4258 | |
| 4259 | next_param = cur_param; |
| 4260 | } |
| 4261 | } |
| 4262 | |
| 4263 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4264 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4265 | } |
| 4266 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4267 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4268 | } |
| 4269 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4270 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4271 | } |
| 4272 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4273 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4274 | } |
| 4275 | out: |
| 4276 | return 1; |
| 4277 | } |
| 4278 | |
| 4279 | |
| 4280 | static int stats_send_http_headers(struct stream_interface *si) |
| 4281 | { |
| 4282 | struct session *s = session_from_task(si->owner); |
| 4283 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4284 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4285 | |
| 4286 | chunk_printf(&trash, |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4287 | "HTTP/1.0 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4288 | "Cache-Control: no-cache\r\n" |
| 4289 | "Connection: close\r\n" |
| 4290 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4291 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4292 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4293 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4294 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4295 | uri->refresh); |
| 4296 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4297 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4298 | |
| 4299 | s->txn.status = 200; |
| 4300 | s->logs.tv_request = now; |
| 4301 | |
| 4302 | if (bi_putchk(si->ib, &trash) == -1) |
| 4303 | return 0; |
| 4304 | |
| 4305 | return 1; |
| 4306 | } |
| 4307 | |
| 4308 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4309 | { |
| 4310 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4311 | struct session *s = session_from_task(si->owner); |
| 4312 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4313 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4314 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4315 | /* 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] | 4316 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4317 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4318 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4319 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4320 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | /* We don't want to land on the posted stats page because a refresh will |
| 4324 | * repost the data. We don't want this to happen on accident so we redirect |
| 4325 | * the browse to the stats page with a GET. |
| 4326 | */ |
| 4327 | chunk_printf(&trash, |
| 4328 | "HTTP/1.1 303 See Other\r\n" |
| 4329 | "Cache-Control: no-cache\r\n" |
| 4330 | "Content-Type: text/plain\r\n" |
| 4331 | "Connection: close\r\n" |
| 4332 | "Location: %s;st=%s%s%s%s\r\n" |
| 4333 | "\r\n", |
| 4334 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4335 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4336 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4337 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4338 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4339 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4340 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4341 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4342 | scope_txt); |
| 4343 | |
| 4344 | s->txn.status = 303; |
| 4345 | s->logs.tv_request = now; |
| 4346 | |
| 4347 | if (bi_putchk(si->ib, &trash) == -1) |
| 4348 | return 0; |
| 4349 | |
| 4350 | return 1; |
| 4351 | } |
| 4352 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4353 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4354 | * 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] | 4355 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4356 | * automatically unregisters itself once transfer is complete. |
| 4357 | */ |
| 4358 | static void http_stats_io_handler(struct stream_interface *si) |
| 4359 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4360 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4361 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4362 | struct channel *req = si->ob; |
| 4363 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4364 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4365 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4366 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4367 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4368 | /* check that the output is not closed */ |
| 4369 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4370 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4371 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4372 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4373 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4374 | if (stats_send_http_headers(si)) { |
| 4375 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4376 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4377 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4378 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4379 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4380 | } |
| 4381 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4382 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4383 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4384 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4385 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4386 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4387 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4388 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4389 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4390 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4391 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4392 | } |
| 4393 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4394 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4395 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4396 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4397 | } |
| 4398 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4399 | if (appctx->st0 == STAT_HTTP_DONE) |
| 4400 | si_shutw(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4401 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4402 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4403 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4404 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4405 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4406 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4407 | si_shutr(si); |
| 4408 | res->flags |= CF_READ_NULL; |
| 4409 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4410 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4411 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4412 | /* update all other flags and resync with the other side */ |
| 4413 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4414 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4415 | /* we don't want to expire timeouts while we're processing requests */ |
| 4416 | si->ib->rex = TICK_ETERNITY; |
| 4417 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4418 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4419 | out: |
| 4420 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4421 | /* check that we have released everything then unregister */ |
| 4422 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4423 | } |
| 4424 | } |
| 4425 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4426 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4427 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4428 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4429 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4430 | return "NONE"; |
| 4431 | return conn->ctrl->name; |
| 4432 | } |
| 4433 | |
| 4434 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4435 | { |
| 4436 | static char ptr[17]; |
| 4437 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4438 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4439 | return "NONE"; |
| 4440 | |
| 4441 | if (conn->xprt == &raw_sock) |
| 4442 | return "RAW"; |
| 4443 | |
| 4444 | #ifdef USE_OPENSSL |
| 4445 | if (conn->xprt == &ssl_sock) |
| 4446 | return "SSL"; |
| 4447 | #endif |
| 4448 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4449 | return ptr; |
| 4450 | } |
| 4451 | |
| 4452 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4453 | { |
| 4454 | static char ptr[17]; |
| 4455 | |
| 4456 | if (!conn->data) |
| 4457 | return "NONE"; |
| 4458 | |
| 4459 | if (conn->data == &sess_conn_cb) |
| 4460 | return "SESS"; |
| 4461 | |
| 4462 | if (conn->data == &si_conn_cb) |
| 4463 | return "STRM"; |
| 4464 | |
| 4465 | if (conn->data == &check_conn_cb) |
| 4466 | return "CHCK"; |
| 4467 | |
| 4468 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4469 | return ptr; |
| 4470 | } |
| 4471 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4472 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4473 | * 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] | 4474 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4475 | * 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] | 4476 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4477 | 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] | 4478 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4479 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4480 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4481 | extern const char *monthname[12]; |
| 4482 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4483 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4484 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4485 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4486 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4487 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4488 | 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] | 4489 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4490 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4491 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4492 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4493 | appctx->ctx.sess.uid = 0; |
| 4494 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4495 | return 1; |
| 4496 | } |
| 4497 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4498 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4499 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4500 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4501 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4502 | /* fall through */ |
| 4503 | |
| 4504 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4505 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4506 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4507 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4508 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4509 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4510 | 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] | 4511 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 4512 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4513 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4514 | conn = objt_conn(sess->si[0].end); |
| 4515 | 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] | 4516 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4517 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4518 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4519 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4520 | break; |
| 4521 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4522 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4523 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 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"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4527 | break; |
| 4528 | } |
| 4529 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4530 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4531 | " 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] | 4532 | 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] | 4533 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4534 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4535 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4536 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 4537 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 4538 | sess->listener ? sess->listener->luid : 0); |
| 4539 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4540 | if (conn) |
| 4541 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4542 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4543 | 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] | 4544 | case AF_INET: |
| 4545 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4546 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4547 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4548 | break; |
| 4549 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4550 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4551 | break; |
| 4552 | default: |
| 4553 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4554 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4555 | break; |
| 4556 | } |
| 4557 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4558 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4559 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4560 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4561 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4562 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 4563 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4564 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4565 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4566 | conn = objt_conn(sess->si[1].end); |
| 4567 | if (conn) |
| 4568 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4569 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4570 | 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] | 4571 | case AF_INET: |
| 4572 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4573 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4574 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4575 | break; |
| 4576 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4577 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4578 | break; |
| 4579 | default: |
| 4580 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4581 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4582 | break; |
| 4583 | } |
| 4584 | |
| 4585 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4586 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4587 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4588 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 4589 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4590 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4591 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4592 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4593 | if (conn) |
| 4594 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4595 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4596 | 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] | 4597 | case AF_INET: |
| 4598 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4599 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4600 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4601 | break; |
| 4602 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4603 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4604 | break; |
| 4605 | default: |
| 4606 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4607 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4608 | break; |
| 4609 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4610 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4611 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4612 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4613 | sess->task, |
| 4614 | sess->task->state, |
| 4615 | sess->task->nice, sess->task->calls, |
| 4616 | sess->task->expire ? |
| 4617 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4618 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4619 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4620 | task_in_rq(sess->task) ? ", running" : ""); |
| 4621 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4622 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4623 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4624 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4625 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4626 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4627 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4628 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4629 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4630 | |
| 4631 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4632 | " 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] | 4633 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4634 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4635 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4636 | obj_type_name(sess->si[0].end), |
| 4637 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4638 | sess->si[0].exp ? |
| 4639 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4640 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4641 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4642 | sess->si[0].err_type); |
| 4643 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4644 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4645 | " 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] | 4646 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4647 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4648 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4649 | obj_type_name(sess->si[1].end), |
| 4650 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4651 | sess->si[1].exp ? |
| 4652 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4653 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4654 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4655 | sess->si[1].err_type); |
| 4656 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4657 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4658 | chunk_appendf(&trash, |
| 4659 | " co0=%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, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 4668 | " 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] | 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[0].end)) != NULL) { |
| 4676 | chunk_appendf(&trash, |
| 4677 | " app0=%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 | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4684 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4685 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4686 | chunk_appendf(&trash, |
| 4687 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4688 | conn, |
| 4689 | get_conn_ctrl_name(conn), |
| 4690 | get_conn_xprt_name(conn), |
| 4691 | get_conn_data_name(conn), |
| 4692 | obj_type_name(conn->target), |
| 4693 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4694 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4695 | chunk_appendf(&trash, |
| 4696 | " 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] | 4697 | conn->flags, |
| 4698 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4699 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4700 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4701 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4702 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4703 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 4704 | chunk_appendf(&trash, |
| 4705 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4706 | tmpctx, |
| 4707 | tmpctx->st0, |
| 4708 | tmpctx->st1, |
| 4709 | tmpctx->st2, |
| 4710 | tmpctx->applet->name); |
| 4711 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4712 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4713 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4714 | " 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] | 4715 | " an_exp=%s", |
| 4716 | sess->req, |
| 4717 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4718 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4719 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4720 | sess->req->analyse_exp ? |
| 4721 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4722 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4723 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4724 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4725 | " rex=%s", |
| 4726 | sess->req->rex ? |
| 4727 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4728 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4729 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4730 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4731 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4732 | " 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] | 4733 | sess->req->wex ? |
| 4734 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4735 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4736 | sess->req->buf, |
| 4737 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4738 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4739 | sess->txn.req.next, sess->req->buf->i, |
| 4740 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4741 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4742 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4743 | " 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] | 4744 | " an_exp=%s", |
| 4745 | sess->rep, |
| 4746 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4747 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4748 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4749 | sess->rep->analyse_exp ? |
| 4750 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4751 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4752 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4753 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4754 | " rex=%s", |
| 4755 | sess->rep->rex ? |
| 4756 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4757 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4758 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4759 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4760 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4761 | " 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] | 4762 | sess->rep->wex ? |
| 4763 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4764 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4765 | sess->rep->buf, |
| 4766 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4767 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4768 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4769 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4770 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4771 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4772 | return 0; |
| 4773 | |
| 4774 | /* use other states to dump the contents */ |
| 4775 | } |
| 4776 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4777 | appctx->ctx.sess.uid = 0; |
| 4778 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4779 | return 1; |
| 4780 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4781 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4782 | static int stats_maps_list(struct stream_interface *si) |
| 4783 | { |
| 4784 | struct appctx *appctx = __objt_appctx(si->end); |
| 4785 | |
| 4786 | switch (appctx->st2) { |
| 4787 | case STAT_ST_INIT: |
| 4788 | /* Init to the first entry. The list cannot be change */ |
| 4789 | appctx->ctx.map.ref = LIST_NEXT(&maps, struct map_reference *, list); |
| 4790 | appctx->st2 = STAT_ST_LIST; |
| 4791 | /* fall through */ |
| 4792 | |
| 4793 | case STAT_ST_LIST: |
| 4794 | while (appctx->ctx.map.ref) { |
| 4795 | |
| 4796 | chunk_reset(&trash); |
| 4797 | |
| 4798 | /* build messages */ |
| 4799 | chunk_appendf(&trash, "%s\n", appctx->ctx.map.ref->reference); |
| 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 */ |
| 4809 | appctx->ctx.map.ref = LIST_NEXT(&appctx->ctx.map.ref->list, |
| 4810 | struct map_reference *, list); |
| 4811 | if (&appctx->ctx.map.ref->list == &maps) |
| 4812 | break; |
| 4813 | } |
| 4814 | |
| 4815 | appctx->st2 = STAT_ST_FIN; |
| 4816 | /* fall through */ |
| 4817 | |
| 4818 | default: |
| 4819 | appctx->st2 = STAT_ST_FIN; |
| 4820 | return 1; |
| 4821 | } |
| 4822 | } |
| 4823 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4824 | static int stats_map_lookup(struct stream_interface *si) |
| 4825 | { |
| 4826 | struct appctx *appctx = __objt_appctx(si->end); |
| 4827 | struct sample_storage *smp; |
| 4828 | struct sample sample; |
| 4829 | struct pattern *pat; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4830 | struct sockaddr_storage addr; |
| 4831 | char s_addr[INET_ADDRSTRLEN]; |
| 4832 | char s_mask[INET_ADDRSTRLEN]; |
| 4833 | char s_addr6[INET6_ADDRSTRLEN]; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4834 | |
| 4835 | switch (appctx->st2) { |
| 4836 | case STAT_ST_INIT: |
| 4837 | appctx->ctx.map.desc = NULL; |
| 4838 | stats_map_lookup_next(si); |
| 4839 | appctx->st2 = STAT_ST_LIST; |
| 4840 | /* fall through */ |
| 4841 | |
| 4842 | case STAT_ST_LIST: |
| 4843 | /* for each lookup type */ |
| 4844 | while (appctx->ctx.map.desc) { |
| 4845 | /* initialise chunk to build new message */ |
| 4846 | chunk_reset(&trash); |
| 4847 | |
| 4848 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 4849 | sample.type = SMP_T_STR; |
| 4850 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4851 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 4852 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4853 | pat = pattern_exec_match(appctx->ctx.map.desc->pat, &sample, 1); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4854 | |
| 4855 | /* build return message: set type of match */ |
| 4856 | /**/ if (appctx->ctx.map.desc->pat->match == NULL) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4857 | chunk_appendf(&trash, "type=found"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4858 | else if (appctx->ctx.map.desc->pat->match == pat_match_nothing) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4859 | chunk_appendf(&trash, "type=bool"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4860 | else if (appctx->ctx.map.desc->pat->match == pat_match_int) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4861 | chunk_appendf(&trash, "type=int"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4862 | else if (appctx->ctx.map.desc->pat->match == pat_match_ip) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4863 | chunk_appendf(&trash, "type=ip"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4864 | else if (appctx->ctx.map.desc->pat->match == pat_match_bin) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4865 | chunk_appendf(&trash, "type=bin"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4866 | else if (appctx->ctx.map.desc->pat->match == pat_match_len) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4867 | chunk_appendf(&trash, "type=len"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4868 | else if (appctx->ctx.map.desc->pat->match == pat_match_str) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4869 | chunk_appendf(&trash, "type=str"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4870 | else if (appctx->ctx.map.desc->pat->match == pat_match_beg) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4871 | chunk_appendf(&trash, "type=beg"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4872 | else if (appctx->ctx.map.desc->pat->match == pat_match_sub) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4873 | chunk_appendf(&trash, "type=sub"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4874 | else if (appctx->ctx.map.desc->pat->match == pat_match_dir) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4875 | chunk_appendf(&trash, "type=dir"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4876 | else if (appctx->ctx.map.desc->pat->match == pat_match_dom) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4877 | chunk_appendf(&trash, "type=dom"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4878 | else if (appctx->ctx.map.desc->pat->match == pat_match_end) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4879 | chunk_appendf(&trash, "type=end"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4880 | else if (appctx->ctx.map.desc->pat->match == pat_match_reg) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4881 | chunk_appendf(&trash, "type=reg"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4882 | else /* The never appens case */ |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4883 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.desc->pat->match); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4884 | |
| 4885 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4886 | if (!pat) { |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4887 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4888 | } |
| 4889 | |
| 4890 | /* Display match and match info */ |
| 4891 | else { |
| 4892 | /* display match */ |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4893 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4894 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4895 | /* display index mode */ |
| 4896 | if (pat->flags & PAT_F_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4897 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4898 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4899 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4900 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4901 | /* case sensitive */ |
| 4902 | if (pat->flags & PAT_F_IGNORE_CASE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4903 | chunk_appendf(&trash, ", case=insensitive"); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4904 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4905 | chunk_appendf(&trash, ", case=sensitive"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4906 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4907 | /* display source */ |
| 4908 | if (pat->flags & PAT_F_FROM_FILE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4909 | chunk_appendf(&trash, ", src=file"); |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 4910 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4911 | chunk_appendf(&trash, ", src=conf"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4912 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4913 | /* display string */ |
| 4914 | if (appctx->ctx.map.desc->pat->match == pat_match_str || |
| 4915 | appctx->ctx.map.desc->pat->match == pat_match_str || |
| 4916 | appctx->ctx.map.desc->pat->match == pat_match_beg || |
| 4917 | appctx->ctx.map.desc->pat->match == pat_match_sub || |
| 4918 | appctx->ctx.map.desc->pat->match == pat_match_dir || |
| 4919 | appctx->ctx.map.desc->pat->match == pat_match_dom || |
| 4920 | appctx->ctx.map.desc->pat->match == pat_match_end) { |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4921 | chunk_appendf(&trash, ", key=\"%s\"", pat->ptr.str); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4922 | } |
| 4923 | else if (appctx->ctx.map.desc->pat->match == pat_match_ip) { |
| 4924 | /* display IPv4/v6 */ |
| 4925 | if (pat->type == SMP_T_IPV4) { |
| 4926 | ((struct sockaddr_in *)&addr)->sin_family = AF_INET; |
| 4927 | memcpy(&((struct sockaddr_in *)&addr)->sin_addr, &pat->val.ipv4.addr, |
| 4928 | sizeof(pat->val.ipv4.addr)); |
| 4929 | if (addr_to_str(&addr, s_addr, INET_ADDRSTRLEN)) { |
| 4930 | memcpy(&((struct sockaddr_in *)&addr)->sin_addr, &pat->val.ipv4.mask, |
| 4931 | sizeof(pat->val.ipv4.mask)); |
| 4932 | if (addr_to_str(&addr, s_mask, INET_ADDRSTRLEN)) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4933 | chunk_appendf(&trash, ", key=\"%s/%s\"", s_addr, s_mask); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4934 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4935 | } |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4936 | else if (pat->type == SMP_T_IPV6) { |
| 4937 | ((struct sockaddr_in6 *)&addr)->sin6_family = AF_INET6; |
| 4938 | memcpy(&((struct sockaddr_in6 *)&addr)->sin6_addr, &pat->val.ipv6.addr, |
| 4939 | sizeof(pat->val.ipv6.addr)); |
| 4940 | if (addr_to_str(&addr, s_addr6, INET6_ADDRSTRLEN)) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4941 | chunk_appendf(&trash, ", key=\"%s/%d\"", s_addr6, pat->val.ipv6.mask); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4942 | } |
| 4943 | } |
Thierry FOURNIER | b4be129 | 2014-01-17 15:14:41 +0100 | [diff] [blame] | 4944 | else if (appctx->ctx.map.desc->pat->match == pat_match_int) { |
| 4945 | /* display int */ |
| 4946 | chunk_appendf(&trash, "match=\""); |
| 4947 | if (pat->val.range.min_set && pat->val.range.max_set && |
| 4948 | pat->val.range.min == pat->val.range.max) { |
| 4949 | chunk_appendf(&trash, "%lld", pat->val.range.min); |
| 4950 | } |
| 4951 | else { |
| 4952 | if (pat->val.range.min_set) |
| 4953 | chunk_appendf(&trash, "is >= %lld", pat->val.range.min); |
| 4954 | if (pat->val.range.min_set && pat->val.range.max_set) |
| 4955 | chunk_appendf(&trash, " and "); |
| 4956 | if (pat->val.range.max_set) |
| 4957 | chunk_appendf(&trash, "is <= %lld", pat->val.range.max); |
| 4958 | } |
| 4959 | chunk_appendf(&trash, "\", "); |
| 4960 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | /* display return value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4964 | if (!pat || !pat->smp) { |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4965 | chunk_appendf(&trash, ", value=nothing"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4966 | } |
| 4967 | else { |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4968 | smp = pat->smp; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4969 | memcpy(&sample.data, &smp->data, sizeof(sample.data)); |
| 4970 | sample.type = smp->type; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 4971 | if (sample_casts[sample.type][SMP_T_STR] && |
| 4972 | sample_casts[sample.type][SMP_T_STR](&sample)) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4973 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4974 | sample.data.str.str, smp_to_type[smp->type]); |
| 4975 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4976 | chunk_appendf(&trash, ", value=cannot-display, type=\"%s\"", |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4977 | smp_to_type[smp->type]); |
| 4978 | } |
| 4979 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4980 | chunk_appendf(&trash, "\n"); |
| 4981 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4982 | /* display response */ |
| 4983 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4984 | /* let's try again later from this session. We add ourselves into |
| 4985 | * this session's users so that it can remove us upon termination. |
| 4986 | */ |
| 4987 | return 0; |
| 4988 | } |
| 4989 | |
| 4990 | /* get next entry */ |
| 4991 | stats_map_lookup_next(si); |
| 4992 | } |
| 4993 | |
| 4994 | appctx->st2 = STAT_ST_FIN; |
| 4995 | /* fall through */ |
| 4996 | |
| 4997 | default: |
| 4998 | appctx->st2 = STAT_ST_FIN; |
| 4999 | free(appctx->ctx.map.chunk.str); |
| 5000 | return 1; |
| 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | static int stats_map_list(struct stream_interface *si) |
| 5005 | { |
| 5006 | struct appctx *appctx = __objt_appctx(si->end); |
| 5007 | |
| 5008 | switch (appctx->st2) { |
| 5009 | |
| 5010 | case STAT_ST_INIT: |
| 5011 | /* Init to the first entry. The list cannot be change */ |
| 5012 | appctx->ctx.map.ent = LIST_NEXT(&appctx->ctx.map.ref->entries, |
| 5013 | struct map_entry *, list); |
| 5014 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) |
| 5015 | appctx->ctx.map.ent = NULL; |
| 5016 | appctx->st2 = STAT_ST_LIST; |
| 5017 | /* fall through */ |
| 5018 | |
| 5019 | case STAT_ST_LIST: |
| 5020 | while (appctx->ctx.map.ent) { |
| 5021 | chunk_reset(&trash); |
| 5022 | |
| 5023 | /* build messages */ |
| 5024 | chunk_appendf(&trash, "%s %s\n", appctx->ctx.map.ent->key, appctx->ctx.map.ent->value); |
| 5025 | |
| 5026 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5027 | /* let's try again later from this session. We add ourselves into |
| 5028 | * this session's users so that it can remove us upon termination. |
| 5029 | */ |
| 5030 | return 0; |
| 5031 | } |
| 5032 | |
| 5033 | /* get next list entry and check the end of the list */ |
| 5034 | appctx->ctx.map.ent = LIST_NEXT(&appctx->ctx.map.ent->list, |
| 5035 | struct map_entry *, list); |
| 5036 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) |
| 5037 | break; |
| 5038 | } |
| 5039 | |
| 5040 | appctx->st2 = STAT_ST_FIN; |
| 5041 | /* fall through */ |
| 5042 | |
| 5043 | default: |
| 5044 | appctx->st2 = STAT_ST_FIN; |
| 5045 | return 1; |
| 5046 | } |
| 5047 | } |
| 5048 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5049 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5050 | * 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] | 5051 | * to be called again, otherwise non-zero. It is designed to be called |
| 5052 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5053 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5054 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5055 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5056 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5057 | struct connection *conn; |
| 5058 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5059 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5060 | /* If we're forced to shut down, we might have to remove our |
| 5061 | * reference to the last session being dumped. |
| 5062 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5063 | if (appctx->st2 == STAT_ST_LIST) { |
| 5064 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5065 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5066 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5067 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5068 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5069 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5070 | } |
| 5071 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5072 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5073 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5074 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5075 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5076 | /* the function had not been called yet, let's prepare the |
| 5077 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5078 | * pointer to the first in the global list. When a target |
| 5079 | * session is being destroyed, it is responsible for updating |
| 5080 | * this pointer. We know we have reached the end when this |
| 5081 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5082 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5083 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5084 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5085 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5086 | /* fall through */ |
| 5087 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5088 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5089 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5090 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5091 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5092 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5096 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5097 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5098 | struct session *curr_sess; |
| 5099 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5100 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5101 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5102 | if (appctx->ctx.sess.target) { |
| 5103 | 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] | 5104 | goto next_sess; |
| 5105 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5106 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5107 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5108 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5109 | return 0; |
| 5110 | |
| 5111 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5112 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5113 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5114 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5115 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5116 | break; |
| 5117 | } |
| 5118 | else |
| 5119 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5120 | } |
| 5121 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5122 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5123 | "%p: proto=%s", |
| 5124 | curr_sess, |
| 5125 | curr_sess->listener->proto->name); |
| 5126 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5127 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5128 | conn = objt_conn(curr_sess->si[0].end); |
| 5129 | 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] | 5130 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5131 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5132 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5133 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5134 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5135 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5136 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5137 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5138 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5139 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5140 | break; |
| 5141 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5142 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5143 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5144 | curr_sess->listener->luid, |
| 5145 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5146 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5147 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5148 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5149 | break; |
| 5150 | } |
| 5151 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5152 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5153 | " ts=%02x age=%s calls=%d", |
| 5154 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5155 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5156 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5157 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5158 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5159 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5160 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5161 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5162 | curr_sess->req->analysers, |
| 5163 | curr_sess->req->rex ? |
| 5164 | human_time(TICKS_TO_MS(curr_sess->req->rex - 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 | ",wx=%s", |
| 5169 | curr_sess->req->wex ? |
| 5170 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 5171 | TICKS_TO_MS(1000)) : ""); |
| 5172 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5173 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5174 | ",ax=%s]", |
| 5175 | curr_sess->req->analyse_exp ? |
| 5176 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 5177 | TICKS_TO_MS(1000)) : ""); |
| 5178 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5179 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5180 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5181 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5182 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5183 | curr_sess->rep->analysers, |
| 5184 | curr_sess->rep->rex ? |
| 5185 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5186 | TICKS_TO_MS(1000)) : ""); |
| 5187 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5188 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5189 | ",wx=%s", |
| 5190 | curr_sess->rep->wex ? |
| 5191 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 5192 | TICKS_TO_MS(1000)) : ""); |
| 5193 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5194 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5195 | ",ax=%s]", |
| 5196 | curr_sess->rep->analyse_exp ? |
| 5197 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5198 | TICKS_TO_MS(1000)) : ""); |
| 5199 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5200 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5201 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5202 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5203 | curr_sess->si[0].state, |
| 5204 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5205 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5206 | curr_sess->si[0].exp ? |
| 5207 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5208 | TICKS_TO_MS(1000)) : ""); |
| 5209 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5210 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5211 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5212 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5213 | curr_sess->si[1].state, |
| 5214 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5215 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5216 | curr_sess->si[1].exp ? |
| 5217 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5218 | TICKS_TO_MS(1000)) : ""); |
| 5219 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5220 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5221 | " exp=%s", |
| 5222 | curr_sess->task->expire ? |
| 5223 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5224 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5225 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5226 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5227 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5228 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5229 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5230 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5231 | /* let's try again later from this session. We add ourselves into |
| 5232 | * this session's users so that it can remove us upon termination. |
| 5233 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5234 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5235 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5236 | } |
| 5237 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5238 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5239 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5240 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5241 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5242 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5243 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5244 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5245 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5246 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5247 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5248 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5249 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5250 | return 0; |
| 5251 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5252 | appctx->ctx.sess.target = NULL; |
| 5253 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5254 | return 1; |
| 5255 | } |
| 5256 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5257 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5258 | /* fall through */ |
| 5259 | |
| 5260 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5261 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5262 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5263 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5264 | } |
| 5265 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5266 | /* This is called when the stream interface is closed. For instance, upon an |
| 5267 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5268 | * remove back references to the session currently being dumped. |
| 5269 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5270 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5271 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5272 | struct appctx *appctx = __objt_appctx(si->end); |
| 5273 | |
| 5274 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5275 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5276 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5277 | } |
| 5278 | } |
| 5279 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5280 | /* This function is used to either dump tables states (when action is set |
| 5281 | * 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] | 5282 | * It returns 0 if the output buffer is full and it needs to be called |
| 5283 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5284 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5285 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5286 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5287 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5288 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5289 | struct ebmb_node *eb; |
| 5290 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5291 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5292 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5293 | |
| 5294 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5295 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5296 | * - STAT_ST_INIT : the first call |
| 5297 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5298 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5299 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5300 | * and the entry pointer points to the next entry to be dumped, |
| 5301 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5302 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5303 | * data though. |
| 5304 | */ |
| 5305 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5306 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5307 | /* 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] | 5308 | if (appctx->st2 == STAT_ST_LIST) { |
| 5309 | appctx->ctx.table.entry->ref_cnt--; |
| 5310 | 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] | 5311 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5312 | return 1; |
| 5313 | } |
| 5314 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5315 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5316 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5317 | while (appctx->st2 != STAT_ST_FIN) { |
| 5318 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5319 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5320 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5321 | if (!appctx->ctx.table.proxy) |
| 5322 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5323 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5324 | appctx->ctx.table.entry = NULL; |
| 5325 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5326 | break; |
| 5327 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5328 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5329 | if (!appctx->ctx.table.proxy || |
| 5330 | (appctx->ctx.table.target && |
| 5331 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5332 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5333 | break; |
| 5334 | } |
| 5335 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5336 | if (appctx->ctx.table.proxy->table.size) { |
| 5337 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5338 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5339 | return 0; |
| 5340 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5341 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5342 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5343 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5344 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5345 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5346 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5347 | appctx->ctx.table.entry->ref_cnt++; |
| 5348 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5349 | break; |
| 5350 | } |
| 5351 | } |
| 5352 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5353 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5354 | break; |
| 5355 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5356 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5357 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5358 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5359 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5360 | /* we're filtering on some data contents */ |
| 5361 | void *ptr; |
| 5362 | long long data; |
| 5363 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5364 | dt = appctx->ctx.table.data_type; |
| 5365 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5366 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5367 | dt); |
| 5368 | |
| 5369 | data = 0; |
| 5370 | switch (stktable_data_types[dt].std_type) { |
| 5371 | case STD_T_SINT: |
| 5372 | data = stktable_data_cast(ptr, std_t_sint); |
| 5373 | break; |
| 5374 | case STD_T_UINT: |
| 5375 | data = stktable_data_cast(ptr, std_t_uint); |
| 5376 | break; |
| 5377 | case STD_T_ULL: |
| 5378 | data = stktable_data_cast(ptr, std_t_ull); |
| 5379 | break; |
| 5380 | case STD_T_FRQP: |
| 5381 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5382 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5383 | break; |
| 5384 | } |
| 5385 | |
| 5386 | /* 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] | 5387 | if ((data < appctx->ctx.table.value && |
| 5388 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5389 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5390 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5391 | (data == appctx->ctx.table.value && |
| 5392 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5393 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5394 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5395 | (data > appctx->ctx.table.value && |
| 5396 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5397 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5398 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5399 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5400 | } |
| 5401 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5402 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5403 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5404 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5405 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5406 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5407 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5408 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5409 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5410 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5411 | struct stksess *old = appctx->ctx.table.entry; |
| 5412 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5413 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5414 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5415 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5416 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5417 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5418 | break; |
| 5419 | } |
| 5420 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5421 | |
| 5422 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5423 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5424 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5425 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5426 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5427 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5428 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5429 | break; |
| 5430 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5431 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5432 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5433 | break; |
| 5434 | } |
| 5435 | } |
| 5436 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5437 | } |
| 5438 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5439 | /* 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] | 5440 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5441 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5442 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5443 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5444 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5445 | * after the offset. The new pointer is returned. |
| 5446 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5447 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5448 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5449 | { |
| 5450 | int end; |
| 5451 | unsigned char c; |
| 5452 | |
| 5453 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5454 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5455 | return ptr; |
| 5456 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5457 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5458 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5459 | while (ptr < len && ptr < bsize) { |
| 5460 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5461 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5462 | if (out->len > end - 2) |
| 5463 | break; |
| 5464 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5465 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5466 | if (out->len > end - 3) |
| 5467 | break; |
| 5468 | out->str[out->len++] = '\\'; |
| 5469 | switch (c) { |
| 5470 | case '\t': c = 't'; break; |
| 5471 | case '\n': c = 'n'; break; |
| 5472 | case '\r': c = 'r'; break; |
| 5473 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5474 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5475 | } |
| 5476 | out->str[out->len++] = c; |
| 5477 | } else { |
| 5478 | if (out->len > end - 5) |
| 5479 | break; |
| 5480 | out->str[out->len++] = '\\'; |
| 5481 | out->str[out->len++] = 'x'; |
| 5482 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5483 | out->str[out->len++] = hextab[c & 0xF]; |
| 5484 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5485 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5486 | /* we had a line break, let's return now */ |
| 5487 | out->str[out->len++] = '\n'; |
| 5488 | *line = ptr; |
| 5489 | return ptr; |
| 5490 | } |
| 5491 | } |
| 5492 | /* we have an incomplete line, we return it as-is */ |
| 5493 | out->str[out->len++] = '\n'; |
| 5494 | return ptr; |
| 5495 | } |
| 5496 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5497 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5498 | * 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] | 5499 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5500 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5501 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5502 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5503 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5504 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5505 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5506 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5507 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5508 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5509 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5510 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5511 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5512 | /* the function had not been called yet, let's prepare the |
| 5513 | * buffer for a response. |
| 5514 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5515 | struct tm tm; |
| 5516 | |
| 5517 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5518 | 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] | 5519 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5520 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5521 | error_snapshot_id); |
| 5522 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5523 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5524 | /* Socket buffer full. Let's try again later from the same point */ |
| 5525 | return 0; |
| 5526 | } |
| 5527 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5528 | appctx->ctx.errors.px = proxy; |
| 5529 | appctx->ctx.errors.buf = 0; |
| 5530 | appctx->ctx.errors.bol = 0; |
| 5531 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | /* we have two inner loops here, one for the proxy, the other one for |
| 5535 | * the buffer. |
| 5536 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5537 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5538 | struct error_snapshot *es; |
| 5539 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5540 | if (appctx->ctx.errors.buf == 0) |
| 5541 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5542 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5543 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5544 | |
| 5545 | if (!es->when.tv_sec) |
| 5546 | goto next; |
| 5547 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5548 | if (appctx->ctx.errors.iid >= 0 && |
| 5549 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 5550 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5551 | goto next; |
| 5552 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5553 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5554 | /* just print headers now */ |
| 5555 | |
| 5556 | char pn[INET6_ADDRSTRLEN]; |
| 5557 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5558 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5559 | |
| 5560 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5561 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5562 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5563 | 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] | 5564 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5565 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 5566 | case AF_INET: |
| 5567 | case AF_INET6: |
| 5568 | port = get_host_port(&es->src); |
| 5569 | break; |
| 5570 | default: |
| 5571 | port = 0; |
| 5572 | } |
| 5573 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5574 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5575 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5576 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5577 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5578 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5579 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5580 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 5581 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5582 | break; |
| 5583 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5584 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5585 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5586 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5587 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5588 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5589 | break; |
| 5590 | } |
| 5591 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5592 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5593 | ", server %s (#%d), event #%u\n" |
| 5594 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 5595 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 5596 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 5597 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 5598 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 5599 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 5600 | es->ev_id, |
| 5601 | pn, port, es->sid, es->s_flags, |
| 5602 | es->state, es->m_flags, es->t_flags, |
| 5603 | es->m_clen, es->m_blen, |
| 5604 | es->b_flags, es->b_out, es->b_tot, |
| 5605 | es->len, es->b_wrap, es->pos); |
| 5606 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5607 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5608 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5609 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5610 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5611 | appctx->ctx.errors.ptr = 0; |
| 5612 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5613 | } |
| 5614 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5615 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5616 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5617 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5618 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5619 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5620 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5621 | goto next; |
| 5622 | } |
| 5623 | |
| 5624 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5625 | 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] | 5626 | int newptr; |
| 5627 | int newline; |
| 5628 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5629 | newline = appctx->ctx.errors.bol; |
| 5630 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 5631 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5632 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5633 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5634 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5635 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5636 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5637 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5638 | appctx->ctx.errors.ptr = newptr; |
| 5639 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5640 | }; |
| 5641 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5642 | appctx->ctx.errors.bol = 0; |
| 5643 | appctx->ctx.errors.ptr = -1; |
| 5644 | appctx->ctx.errors.buf++; |
| 5645 | if (appctx->ctx.errors.buf > 1) { |
| 5646 | appctx->ctx.errors.buf = 0; |
| 5647 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5652 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5653 | } |
| 5654 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5655 | /* parse the "level" argument on the bind lines */ |
| 5656 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 5657 | { |
| 5658 | if (!*args[cur_arg + 1]) { |
| 5659 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 5660 | return ERR_ALERT | ERR_FATAL; |
| 5661 | } |
| 5662 | |
| 5663 | if (!strcmp(args[cur_arg+1], "user")) |
| 5664 | conf->level = ACCESS_LVL_USER; |
| 5665 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 5666 | conf->level = ACCESS_LVL_OPER; |
| 5667 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 5668 | conf->level = ACCESS_LVL_ADMIN; |
| 5669 | else { |
| 5670 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 5671 | args[cur_arg], args[cur_arg+1]); |
| 5672 | return ERR_ALERT | ERR_FATAL; |
| 5673 | } |
| 5674 | |
| 5675 | return 0; |
| 5676 | } |
| 5677 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5678 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5679 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5680 | .name = "<STATS>", /* used for logging */ |
| 5681 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 5682 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5683 | }; |
| 5684 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5685 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5686 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5687 | .name = "<CLI>", /* used for logging */ |
| 5688 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5689 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5690 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5691 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 5692 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5693 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 5694 | { 0, NULL, NULL }, |
| 5695 | }}; |
| 5696 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5697 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 5698 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 5699 | { NULL, NULL, 0 }, |
| 5700 | }}; |
| 5701 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5702 | __attribute__((constructor)) |
| 5703 | static void __dumpstats_module_init(void) |
| 5704 | { |
| 5705 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5706 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5707 | } |
| 5708 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5709 | /* |
| 5710 | * Local variables: |
| 5711 | * c-indent-level: 8 |
| 5712 | * c-basic-offset: 8 |
| 5713 | * End: |
| 5714 | */ |