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 | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 56 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 57 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 58 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 59 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 60 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 61 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 62 | #ifdef USE_OPENSSL |
| 63 | #include <proto/ssl_sock.h> |
| 64 | #endif |
| 65 | |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 66 | /* stats socket states */ |
| 67 | enum { |
| 68 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 69 | STAT_CLI_END, /* final state, let's close */ |
| 70 | STAT_CLI_GETREQ, /* wait for a request */ |
| 71 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 72 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 73 | STAT_CLI_PRINT, /* display message in cli->msg */ |
| 74 | STAT_CLI_O_INFO, /* dump info */ |
| 75 | STAT_CLI_O_SESS, /* dump sessions */ |
| 76 | STAT_CLI_O_ERR, /* dump errors */ |
| 77 | STAT_CLI_O_TAB, /* dump tables */ |
| 78 | STAT_CLI_O_CLR, /* clear tables */ |
| 79 | STAT_CLI_O_SET, /* set entries in tables */ |
| 80 | STAT_CLI_O_STAT, /* dump stats */ |
| 81 | STAT_CLI_O_MAPS, /* list all maps */ |
| 82 | STAT_CLI_O_MAP, /* list all map entries of a map */ |
| 83 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 84 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 85 | }; |
| 86 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 87 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 88 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 89 | 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] | 90 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 91 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 92 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 93 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 94 | 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] | 95 | static int stats_maps_list(struct stream_interface *si); |
| 96 | static int stats_map_list(struct stream_interface *si); |
| 97 | static int stats_map_lookup(struct stream_interface *si); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 98 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 99 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 100 | * cli_io_handler() |
| 101 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 102 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 103 | * -> stats_dump_info_to_buffer() // "show info" |
| 104 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 105 | * -> stats_dump_csv_header() |
| 106 | * -> stats_dump_proxy_to_buffer() |
| 107 | * -> stats_dump_fe_stats() |
| 108 | * -> stats_dump_li_stats() |
| 109 | * -> stats_dump_sv_stats() |
| 110 | * -> stats_dump_be_stats() |
| 111 | * |
| 112 | * http_stats_io_handler() |
| 113 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 114 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 115 | * -> stats_dump_html_head() // emits the HTML headers |
| 116 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 117 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 118 | * -> stats_dump_html_px_hdr() |
| 119 | * -> stats_dump_fe_stats() |
| 120 | * -> stats_dump_li_stats() |
| 121 | * -> stats_dump_sv_stats() |
| 122 | * -> stats_dump_be_stats() |
| 123 | * -> stats_dump_html_px_end() |
| 124 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 125 | */ |
| 126 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 127 | static struct si_applet cli_applet; |
| 128 | |
| 129 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 130 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 131 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 132 | " clear table : remove an entry from a table\n" |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 133 | " clear map [id] : clear the content of this map\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" |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 143 | " show map [id] : report avalaible maps or dump this map's contents\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 144 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 145 | " set weight : change a server's weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 146 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 147 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 148 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 149 | " set rate-limit : change a rate limiting value\n" |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 150 | " set map [id] [key] [value] : modify map entry\n" |
| 151 | " add map [id] [key] [value] : add map entry\n" |
| 152 | " del map [id] [key] : delete map entry\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 153 | " disable : put a server or frontend in maintenance mode\n" |
| 154 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 155 | " shutdown : kill a session or a frontend (eg:to release listening ports)\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 156 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 157 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 158 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 159 | "Permission denied\n" |
| 160 | ""; |
| 161 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 162 | /* data transmission states for the stats responses */ |
| 163 | enum { |
| 164 | STAT_ST_INIT = 0, |
| 165 | STAT_ST_HEAD, |
| 166 | STAT_ST_INFO, |
| 167 | STAT_ST_LIST, |
| 168 | STAT_ST_END, |
| 169 | STAT_ST_FIN, |
| 170 | }; |
| 171 | |
| 172 | /* data transmission states for the stats responses inside a proxy */ |
| 173 | enum { |
| 174 | STAT_PX_ST_INIT = 0, |
| 175 | STAT_PX_ST_TH, |
| 176 | STAT_PX_ST_FE, |
| 177 | STAT_PX_ST_LI, |
| 178 | STAT_PX_ST_SV, |
| 179 | STAT_PX_ST_BE, |
| 180 | STAT_PX_ST_END, |
| 181 | STAT_PX_ST_FIN, |
| 182 | }; |
| 183 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 184 | extern const char *stat_status_codes[]; |
| 185 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 186 | /* 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] | 187 | * 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] | 188 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 189 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 190 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 191 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 192 | s->target = &cli_applet.obj_type; |
Willy Tarreau | 4171e9e | 2013-12-01 12:32:30 +0100 | [diff] [blame] | 193 | /* 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] | 194 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 195 | tv_zero(&s->logs.tv_request); |
| 196 | s->logs.t_queue = 0; |
| 197 | s->logs.t_connect = 0; |
| 198 | s->logs.t_data = 0; |
| 199 | s->logs.t_close = 0; |
| 200 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 201 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 202 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 203 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 204 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 205 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 206 | if (s->listener->timeout) { |
| 207 | s->req->rto = *s->listener->timeout; |
| 208 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 209 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 210 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 213 | /* allocate a new stats frontend named <name>, and return it |
| 214 | * (or NULL in case of lack of memory). |
| 215 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 216 | 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] | 217 | { |
| 218 | struct proxy *fe; |
| 219 | |
| 220 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 221 | if (!fe) |
| 222 | return NULL; |
| 223 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 224 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 225 | fe->next = proxy; |
| 226 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 227 | fe->last_change = now.tv_sec; |
| 228 | fe->id = strdup("GLOBAL"); |
| 229 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 230 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 231 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 232 | fe->conf.file = strdup(file); |
| 233 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 234 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 235 | |
| 236 | /* the stats frontend is the only one able to assign ID #0 */ |
| 237 | fe->conf.id.key = fe->uuid = 0; |
| 238 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 239 | return fe; |
| 240 | } |
| 241 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 242 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 243 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 244 | * error message into the <err> buffer which will be preallocated. The trailing |
| 245 | * '\n' must not be written. The function must be called with <args> pointing to |
| 246 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 247 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 248 | 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] | 249 | struct proxy *defpx, const char *file, int line, |
| 250 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 251 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 252 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 253 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 254 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 255 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 256 | int cur_arg; |
| 257 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 258 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 259 | 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] | 260 | return -1; |
| 261 | } |
| 262 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 263 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 264 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 265 | 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] | 266 | return -1; |
| 267 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 268 | } |
| 269 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 270 | 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] | 271 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 272 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 273 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 274 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 275 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 276 | return -1; |
| 277 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 278 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 279 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 280 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 281 | static int bind_dumped; |
| 282 | struct bind_kw *kw; |
| 283 | |
| 284 | kw = bind_find_kw(args[cur_arg]); |
| 285 | if (kw) { |
| 286 | if (!kw->parse) { |
| 287 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 288 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 289 | return -1; |
| 290 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 291 | |
| 292 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 293 | if (err && *err) |
| 294 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 295 | else |
| 296 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 297 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 298 | return -1; |
| 299 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 300 | |
| 301 | cur_arg += 1 + kw->skip; |
| 302 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 303 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 304 | |
| 305 | if (!bind_dumped) { |
| 306 | bind_dump_kws(err); |
| 307 | indent_msg(err, 4); |
| 308 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 309 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 310 | |
| 311 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 312 | args[0], args[1], args[cur_arg], |
| 313 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 314 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 315 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 316 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 317 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 318 | l->maxconn = global.stats_fe->maxconn; |
| 319 | l->backlog = global.stats_fe->backlog; |
| 320 | l->timeout = &global.stats_fe->timeout.client; |
| 321 | l->accept = session_accept; |
| 322 | l->handler = process_session; |
| 323 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 324 | l->nice = -64; /* we want to boost priority for local stats */ |
| 325 | global.maxsock += l->maxconn; |
| 326 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 327 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 328 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 329 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 330 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 331 | |
| 332 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 333 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 334 | return -1; |
| 335 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 336 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 337 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 338 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 339 | return -1; |
| 340 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 341 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 342 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 343 | 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] | 344 | return -1; |
| 345 | } |
| 346 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 347 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 348 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 349 | else if (!strcmp(args[1], "maxconn")) { |
| 350 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 351 | |
| 352 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 353 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 354 | return -1; |
| 355 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 356 | |
| 357 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 358 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 359 | 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] | 360 | return -1; |
| 361 | } |
| 362 | } |
| 363 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 364 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 365 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 366 | int cur_arg = 2; |
| 367 | unsigned int set = 0; |
| 368 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 369 | if (!global.stats_fe) { |
| 370 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 371 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 372 | return -1; |
| 373 | } |
| 374 | } |
| 375 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 376 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 377 | unsigned int low, high; |
| 378 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 379 | if (strcmp(args[cur_arg], "all") == 0) { |
| 380 | set = 0; |
| 381 | break; |
| 382 | } |
| 383 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 384 | set |= 0x55555555; |
| 385 | } |
| 386 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 387 | set |= 0xAAAAAAAA; |
| 388 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 389 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 390 | char *dash = strchr(args[cur_arg], '-'); |
| 391 | |
| 392 | low = high = str2uic(args[cur_arg]); |
| 393 | if (dash) |
| 394 | high = str2uic(dash + 1); |
| 395 | |
| 396 | if (high < low) { |
| 397 | unsigned int swap = low; |
| 398 | low = high; |
| 399 | high = swap; |
| 400 | } |
| 401 | |
| 402 | if (low < 1 || high > 32) { |
| 403 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 404 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 405 | return -1; |
| 406 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 407 | |
| 408 | while (low <= high) |
| 409 | set |= 1 << (low++ - 1); |
| 410 | } |
| 411 | else { |
| 412 | memprintf(err, |
| 413 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 414 | args[0], args[1]); |
| 415 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 416 | } |
| 417 | cur_arg++; |
| 418 | } |
| 419 | global.stats_fe->bind_proc = set; |
| 420 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 421 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 422 | 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] | 423 | return -1; |
| 424 | } |
| 425 | return 0; |
| 426 | } |
| 427 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 428 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 429 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 430 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 431 | * 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] | 432 | */ |
| 433 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 434 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 435 | chunk_appendf(&trash, |
| 436 | "# pxname,svname," |
| 437 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 438 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 439 | "bin,bout," |
| 440 | "dreq,dresp," |
| 441 | "ereq,econ,eresp," |
| 442 | "wretr,wredis," |
| 443 | "status,weight,act,bck," |
| 444 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 445 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 446 | "rate,rate_lim,rate_max," |
| 447 | "check_status,check_code,check_duration," |
| 448 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 449 | "req_rate,req_rate_max,req_tot," |
| 450 | "cli_abrt,srv_abrt," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 451 | "comp_in,comp_out,comp_byp,comp_rsp,lastsess," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 452 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 453 | } |
| 454 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 455 | /* print a string of text buffer to <out>. The format is : |
| 456 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 457 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 458 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 459 | */ |
| 460 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 461 | { |
| 462 | unsigned char c; |
| 463 | int ptr = 0; |
| 464 | |
| 465 | while (buf[ptr] && ptr < bsize) { |
| 466 | c = buf[ptr]; |
| 467 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 468 | if (out->len > out->size - 1) |
| 469 | break; |
| 470 | out->str[out->len++] = c; |
| 471 | } |
| 472 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 473 | if (out->len > out->size - 2) |
| 474 | break; |
| 475 | out->str[out->len++] = '\\'; |
| 476 | switch (c) { |
| 477 | case ' ': c = ' '; break; |
| 478 | case '\t': c = 't'; break; |
| 479 | case '\n': c = 'n'; break; |
| 480 | case '\r': c = 'r'; break; |
| 481 | case '\e': c = 'e'; break; |
| 482 | case '\\': c = '\\'; break; |
| 483 | } |
| 484 | out->str[out->len++] = c; |
| 485 | } |
| 486 | else { |
| 487 | if (out->len > out->size - 4) |
| 488 | break; |
| 489 | out->str[out->len++] = '\\'; |
| 490 | out->str[out->len++] = 'x'; |
| 491 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 492 | out->str[out->len++] = hextab[c & 0xF]; |
| 493 | } |
| 494 | ptr++; |
| 495 | } |
| 496 | |
| 497 | return ptr; |
| 498 | } |
| 499 | |
| 500 | /* print a buffer in hexa. |
| 501 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 502 | */ |
| 503 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 504 | { |
| 505 | unsigned char c; |
| 506 | int ptr = 0; |
| 507 | |
| 508 | while (ptr < bsize) { |
| 509 | c = buf[ptr]; |
| 510 | |
| 511 | if (out->len > out->size - 2) |
| 512 | break; |
| 513 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 514 | out->str[out->len++] = hextab[c & 0xF]; |
| 515 | |
| 516 | ptr++; |
| 517 | } |
| 518 | return ptr; |
| 519 | } |
| 520 | |
| 521 | /* Dump the status of a table to a stream interface's |
| 522 | * read buffer. It returns 0 if the output buffer is full |
| 523 | * and needs to be called again, otherwise non-zero. |
| 524 | */ |
| 525 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 526 | struct proxy *proxy, struct proxy *target) |
| 527 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 528 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 529 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 530 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 531 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 532 | |
| 533 | /* any other information should be dumped here */ |
| 534 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 535 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 536 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 537 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 538 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 539 | return 0; |
| 540 | |
| 541 | return 1; |
| 542 | } |
| 543 | |
| 544 | /* Dump the a table entry to a stream interface's |
| 545 | * read buffer. It returns 0 if the output buffer is full |
| 546 | * and needs to be called again, otherwise non-zero. |
| 547 | */ |
| 548 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 549 | struct proxy *proxy, struct stksess *entry) |
| 550 | { |
| 551 | int dt; |
| 552 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 553 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 554 | |
| 555 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 556 | char addr[INET_ADDRSTRLEN]; |
| 557 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 558 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 559 | } |
| 560 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 561 | char addr[INET6_ADDRSTRLEN]; |
| 562 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 563 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 564 | } |
| 565 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 566 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 567 | } |
| 568 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 569 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 570 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 571 | } |
| 572 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 573 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 574 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 575 | } |
| 576 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 577 | 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] | 578 | |
| 579 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 580 | void *ptr; |
| 581 | |
| 582 | if (proxy->table.data_ofs[dt] == 0) |
| 583 | continue; |
| 584 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 585 | 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] | 586 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 587 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 588 | |
| 589 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 590 | switch (stktable_data_types[dt].std_type) { |
| 591 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 592 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 593 | break; |
| 594 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 595 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 596 | break; |
| 597 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 598 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 599 | break; |
| 600 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 601 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 602 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 603 | proxy->table.data_arg[dt].u)); |
| 604 | break; |
| 605 | } |
| 606 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 607 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 608 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 609 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 610 | return 0; |
| 611 | |
| 612 | return 1; |
| 613 | } |
| 614 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 615 | 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] | 616 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 617 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 618 | struct appctx *appctx = __objt_appctx(si->end); |
| 619 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 620 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 621 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 622 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 623 | long long value; |
| 624 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 625 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 626 | void *ptr; |
| 627 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 628 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 629 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 630 | |
| 631 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 632 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 633 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 634 | return; |
| 635 | } |
| 636 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 637 | switch (px->table.type) { |
| 638 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 639 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 640 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 641 | break; |
| 642 | case STKTABLE_TYPE_IPV6: |
| 643 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 644 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 645 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 646 | case STKTABLE_TYPE_INTEGER: |
| 647 | { |
| 648 | char *endptr; |
| 649 | unsigned long val; |
| 650 | errno = 0; |
| 651 | val = strtoul(args[4], &endptr, 10); |
| 652 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 653 | (errno != 0 && val == 0) || endptr == args[4] || |
| 654 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 655 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 656 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 657 | return; |
| 658 | } |
| 659 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 660 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 661 | break; |
| 662 | } |
| 663 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 664 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 665 | static_table_key->key = args[4]; |
| 666 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 667 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 668 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 669 | switch (action) { |
| 670 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 671 | 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] | 672 | break; |
| 673 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 674 | 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] | 675 | break; |
| 676 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 677 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 678 | break; |
| 679 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 680 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 681 | return; |
| 682 | } |
| 683 | |
| 684 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 685 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 686 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 687 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 688 | return; |
| 689 | } |
| 690 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 691 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 692 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 693 | switch (action) { |
| 694 | case STAT_CLI_O_TAB: |
| 695 | if (!ts) |
| 696 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 697 | chunk_reset(&trash); |
| 698 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 699 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 700 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 701 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 702 | |
| 703 | case STAT_CLI_O_CLR: |
| 704 | if (!ts) |
| 705 | return; |
| 706 | if (ts->ref_cnt) { |
| 707 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 708 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 709 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 710 | return; |
| 711 | } |
| 712 | stksess_kill(&px->table, ts); |
| 713 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 714 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 715 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 716 | if (ts) |
| 717 | stktable_touch(&px->table, ts, 1); |
| 718 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 719 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 720 | if (!ts) { |
| 721 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 722 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 723 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | stktable_store(&px->table, ts, 1); |
| 727 | } |
| 728 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 729 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 730 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 731 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 732 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 733 | return; |
| 734 | } |
| 735 | |
| 736 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 737 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 738 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 739 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 740 | return; |
| 741 | } |
| 742 | |
| 743 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 744 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 745 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 746 | return; |
| 747 | } |
| 748 | |
| 749 | 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] | 750 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 751 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 752 | return; |
| 753 | } |
| 754 | |
| 755 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 756 | |
| 757 | switch (stktable_data_types[data_type].std_type) { |
| 758 | case STD_T_SINT: |
| 759 | stktable_data_cast(ptr, std_t_sint) = value; |
| 760 | break; |
| 761 | case STD_T_UINT: |
| 762 | stktable_data_cast(ptr, std_t_uint) = value; |
| 763 | break; |
| 764 | case STD_T_ULL: |
| 765 | stktable_data_cast(ptr, std_t_ull) = value; |
| 766 | break; |
| 767 | case STD_T_FRQP: |
| 768 | /* We set both the current and previous values. That way |
| 769 | * the reported frequency is stable during all the period |
| 770 | * then slowly fades out. This allows external tools to |
| 771 | * push measures without having to update them too often. |
| 772 | */ |
| 773 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 774 | frqp->curr_tick = now_ms; |
| 775 | frqp->prev_ctr = 0; |
| 776 | frqp->curr_ctr = value; |
| 777 | break; |
| 778 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 779 | } |
| 780 | break; |
| 781 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 782 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 783 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 784 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 785 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 786 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 787 | } |
| 788 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 789 | 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] | 790 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 791 | struct appctx *appctx = __objt_appctx(si->end); |
| 792 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 793 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 794 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 795 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 796 | return; |
| 797 | } |
| 798 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 799 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 800 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 801 | if (appctx->ctx.table.data_type < 0) { |
| 802 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 803 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 804 | return; |
| 805 | } |
| 806 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 807 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 808 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 809 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 810 | return; |
| 811 | } |
| 812 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 813 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 814 | if (appctx->ctx.table.data_op < 0) { |
| 815 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 816 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 817 | return; |
| 818 | } |
| 819 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 820 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 821 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 822 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 823 | return; |
| 824 | } |
| 825 | } |
| 826 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 827 | 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] | 828 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 829 | struct appctx *appctx = __objt_appctx(si->end); |
| 830 | |
| 831 | appctx->ctx.table.data_type = -1; |
| 832 | appctx->st2 = STAT_ST_INIT; |
| 833 | appctx->ctx.table.target = NULL; |
| 834 | appctx->ctx.table.proxy = NULL; |
| 835 | appctx->ctx.table.entry = NULL; |
| 836 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 837 | |
| 838 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 839 | appctx->ctx.table.target = find_stktable(args[2]); |
| 840 | if (!appctx->ctx.table.target) { |
| 841 | appctx->ctx.cli.msg = "No such table\n"; |
| 842 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 843 | return; |
| 844 | } |
| 845 | } |
| 846 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 847 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 848 | goto err_args; |
| 849 | return; |
| 850 | } |
| 851 | |
| 852 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 853 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 854 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 855 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 856 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 857 | goto err_args; |
| 858 | |
| 859 | return; |
| 860 | |
| 861 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 862 | switch (action) { |
| 863 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 864 | 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] | 865 | break; |
| 866 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 867 | 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] | 868 | break; |
| 869 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 870 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 871 | break; |
| 872 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 873 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 874 | } |
| 875 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 876 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 877 | * adequate error messages and returns NULL. This function also expects the session |
| 878 | * level to be admin. |
| 879 | */ |
| 880 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 881 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 882 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 883 | struct proxy *px; |
| 884 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 885 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 886 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 887 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 888 | return NULL; |
| 889 | } |
| 890 | |
| 891 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 892 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 893 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 894 | return NULL; |
| 895 | } |
| 896 | |
| 897 | px = findproxy(arg, PR_CAP_FE); |
| 898 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 899 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 900 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 901 | return NULL; |
| 902 | } |
| 903 | return px; |
| 904 | } |
| 905 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 906 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 907 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 908 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 909 | * the <arg> is modified to remove the '/'. |
| 910 | */ |
| 911 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 912 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 913 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 914 | struct proxy *px; |
| 915 | struct server *sv; |
| 916 | char *line; |
| 917 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 918 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 919 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 920 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 921 | return NULL; |
| 922 | } |
| 923 | |
| 924 | /* split "backend/server" and make <line> point to server */ |
| 925 | for (line = arg; *line; line++) |
| 926 | if (*line == '/') { |
| 927 | *line++ = '\0'; |
| 928 | break; |
| 929 | } |
| 930 | |
| 931 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 932 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 933 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 934 | return NULL; |
| 935 | } |
| 936 | |
| 937 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 938 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 939 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 940 | return NULL; |
| 941 | } |
| 942 | |
| 943 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 944 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 945 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 946 | return NULL; |
| 947 | } |
| 948 | |
| 949 | return sv; |
| 950 | } |
| 951 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 952 | /* This function is used with map management. It permits to browse each |
| 953 | * really allocated descriptors of one map reference. The variable |
| 954 | * <appctx->ctx.map.ref> must contain the map reference to browse. |
| 955 | * The variable <appctx->ctx.map.desc> contain the descriptor of the |
| 956 | * current allocated map descriptor. This variable must be initialized |
| 957 | * to NULL. |
| 958 | */ |
| 959 | static inline void stats_map_lookup_next(struct stream_interface *si) |
| 960 | { |
| 961 | struct appctx *appctx = __objt_appctx(si->end); |
| 962 | |
| 963 | /* search the next allocated map */ |
| 964 | while (1) { |
| 965 | /* get next descriptor */ |
| 966 | if (!appctx->ctx.map.desc) |
| 967 | appctx->ctx.map.desc = LIST_NEXT(&appctx->ctx.map.ref->maps, |
| 968 | struct map_descriptor *, list); |
| 969 | else |
| 970 | appctx->ctx.map.desc = LIST_NEXT(&appctx->ctx.map.desc->list, |
| 971 | struct map_descriptor *, list); |
| 972 | |
| 973 | /* detect end of list */ |
| 974 | if (&appctx->ctx.map.desc->list == &appctx->ctx.map.ref->maps) { |
| 975 | appctx->ctx.map.desc = NULL; |
| 976 | return; |
| 977 | } |
| 978 | |
| 979 | /* do not lookup this entry */ |
| 980 | if (!appctx->ctx.map.desc->do_free) |
| 981 | continue; |
| 982 | |
| 983 | /* avalaible descriptor */ |
| 984 | return; |
| 985 | } |
| 986 | } |
| 987 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 988 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 989 | * 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] | 990 | * 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] | 991 | * designating the function which will have to process the request, which can |
| 992 | * 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] | 993 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 994 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 995 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 996 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 997 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 998 | char *args[MAX_STATS_ARGS + 1]; |
| 999 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1000 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1001 | |
| 1002 | while (isspace((unsigned char)*line)) |
| 1003 | line++; |
| 1004 | |
| 1005 | arg = 0; |
| 1006 | args[arg] = line; |
| 1007 | |
| 1008 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1009 | if (*line == '\\') { |
| 1010 | line++; |
| 1011 | if (*line == '\0') |
| 1012 | break; |
| 1013 | } |
| 1014 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1015 | *line++ = '\0'; |
| 1016 | |
| 1017 | while (isspace((unsigned char)*line)) |
| 1018 | line++; |
| 1019 | |
| 1020 | args[++arg] = line; |
| 1021 | continue; |
| 1022 | } |
| 1023 | |
| 1024 | line++; |
| 1025 | } |
| 1026 | |
| 1027 | while (++arg <= MAX_STATS_ARGS) |
| 1028 | args[arg] = line; |
| 1029 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1030 | /* remove \ */ |
| 1031 | arg = 0; |
| 1032 | while (*args[arg] != '\0') { |
| 1033 | j = 0; |
| 1034 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1035 | if (args[arg][i] == '\\') |
| 1036 | continue; |
| 1037 | args[arg][j] = args[arg][i]; |
| 1038 | j++; |
| 1039 | } |
| 1040 | args[arg][j] = '\0'; |
| 1041 | arg++; |
| 1042 | } |
| 1043 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1044 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1045 | if (strcmp(args[0], "show") == 0) { |
| 1046 | if (strcmp(args[1], "stat") == 0) { |
| 1047 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1048 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1049 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1050 | appctx->ctx.stats.type = atoi(args[3]); |
| 1051 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1052 | } |
| 1053 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1054 | appctx->st2 = STAT_ST_INIT; |
| 1055 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1056 | } |
| 1057 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1058 | appctx->st2 = STAT_ST_INIT; |
| 1059 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1060 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1061 | else if (strcmp(args[1], "pools") == 0) { |
| 1062 | appctx->st2 = STAT_ST_INIT; |
| 1063 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1064 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1065 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1066 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1067 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1068 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1069 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1070 | return 1; |
| 1071 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1072 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1073 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1074 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1075 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1076 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1077 | appctx->ctx.sess.target = NULL; |
| 1078 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1079 | appctx->ctx.sess.pos = 0; |
| 1080 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1081 | } |
| 1082 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1083 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1084 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1085 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1086 | return 1; |
| 1087 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1088 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1089 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1090 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1091 | appctx->ctx.errors.iid = -1; |
| 1092 | appctx->ctx.errors.px = NULL; |
| 1093 | appctx->st2 = STAT_ST_INIT; |
| 1094 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1095 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1096 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1097 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1098 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1099 | else if (strcmp(args[1], "map") == 0) { |
| 1100 | |
| 1101 | /* no parameter: display all map avalaible */ |
| 1102 | if (!*args[2]) { |
| 1103 | appctx->st2 = STAT_ST_INIT; |
| 1104 | appctx->st0 = STAT_CLI_O_MAPS; |
| 1105 | return 1; |
| 1106 | } |
| 1107 | |
| 1108 | /* lookup into the maps */ |
| 1109 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1110 | if (!appctx->ctx.map.ref) { |
| 1111 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1112 | appctx->st0 = STAT_CLI_PRINT; |
| 1113 | return 1; |
| 1114 | } |
| 1115 | appctx->st2 = STAT_ST_INIT; |
| 1116 | appctx->st0 = STAT_CLI_O_MAP; |
| 1117 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1118 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1119 | return 0; |
| 1120 | } |
| 1121 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1122 | else if (strcmp(args[0], "clear") == 0) { |
| 1123 | if (strcmp(args[1], "counters") == 0) { |
| 1124 | struct proxy *px; |
| 1125 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1126 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1127 | int clrall = 0; |
| 1128 | |
| 1129 | if (strcmp(args[2], "all") == 0) |
| 1130 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1131 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1132 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1133 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1134 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1135 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1136 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1137 | return 1; |
| 1138 | } |
| 1139 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1140 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1141 | if (clrall) { |
| 1142 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1143 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1144 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1145 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1146 | px->be_counters.conn_max = 0; |
| 1147 | px->be_counters.p.http.rps_max = 0; |
| 1148 | px->be_counters.sps_max = 0; |
| 1149 | px->be_counters.cps_max = 0; |
| 1150 | px->be_counters.nbpend_max = 0; |
| 1151 | |
| 1152 | px->fe_counters.conn_max = 0; |
| 1153 | px->fe_counters.p.http.rps_max = 0; |
| 1154 | px->fe_counters.sps_max = 0; |
| 1155 | px->fe_counters.cps_max = 0; |
| 1156 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1157 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1158 | |
| 1159 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1160 | if (clrall) |
| 1161 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1162 | else { |
| 1163 | sv->counters.cur_sess_max = 0; |
| 1164 | sv->counters.nbpend_max = 0; |
| 1165 | sv->counters.sps_max = 0; |
| 1166 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1167 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1168 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1169 | if (li->counters) { |
| 1170 | if (clrall) |
| 1171 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1172 | else |
| 1173 | li->counters->conn_max = 0; |
| 1174 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1175 | } |
| 1176 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1177 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1178 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1179 | return 1; |
| 1180 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1181 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1182 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1183 | /* end of processing */ |
| 1184 | return 1; |
| 1185 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1186 | else if (strcmp(args[1], "map") == 0) { |
| 1187 | struct map_reference *mref; |
| 1188 | struct map_descriptor *mdesc; |
| 1189 | struct map_entry *ent, *nent; |
| 1190 | |
| 1191 | /* no parameter */ |
| 1192 | if (!*args[2]) { |
| 1193 | appctx->ctx.cli.msg = "Expect map reference.\n"; |
| 1194 | appctx->st0 = STAT_CLI_PRINT; |
| 1195 | return 1; |
| 1196 | } |
| 1197 | |
| 1198 | /* lookup into the maps */ |
| 1199 | mref = map_get_reference(args[2]); |
| 1200 | if (!mref) { |
| 1201 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1202 | appctx->st0 = STAT_CLI_PRINT; |
| 1203 | return 1; |
| 1204 | } |
| 1205 | |
| 1206 | /* clear all maps */ |
| 1207 | list_for_each_entry(mdesc, &mref->maps, list) |
| 1208 | if (mdesc->do_free) |
| 1209 | pattern_prune_expr(mdesc->pat); |
| 1210 | |
| 1211 | /* clear map reference */ |
| 1212 | list_for_each_entry_safe(ent, nent, &mref->entries, list) { |
| 1213 | LIST_DEL(&ent->list); |
| 1214 | free(ent->key); |
| 1215 | free(ent->value); |
| 1216 | free(ent); |
| 1217 | } |
| 1218 | |
| 1219 | /* return response */ |
| 1220 | appctx->ctx.cli.msg = "Done.\n"; |
| 1221 | appctx->st0 = STAT_CLI_PRINT; |
| 1222 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1223 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1224 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1225 | return 0; |
| 1226 | } |
| 1227 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1228 | else if (strcmp(args[0], "get") == 0) { |
| 1229 | if (strcmp(args[1], "weight") == 0) { |
| 1230 | struct proxy *px; |
| 1231 | struct server *sv; |
| 1232 | |
| 1233 | /* split "backend/server" and make <line> point to server */ |
| 1234 | for (line = args[2]; *line; line++) |
| 1235 | if (*line == '/') { |
| 1236 | *line++ = '\0'; |
| 1237 | break; |
| 1238 | } |
| 1239 | |
| 1240 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1241 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1242 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1243 | return 1; |
| 1244 | } |
| 1245 | |
| 1246 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1247 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1248 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1249 | return 1; |
| 1250 | } |
| 1251 | |
| 1252 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1253 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1254 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1255 | return 1; |
| 1256 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1257 | else if (strcmp(args[1], "map") == 0) { |
| 1258 | |
| 1259 | /* no parameter */ |
| 1260 | if (!*args[2] || !*args[3]) { |
| 1261 | appctx->ctx.cli.msg = "Expect map reference and required key.\n"; |
| 1262 | appctx->st0 = STAT_CLI_PRINT; |
| 1263 | return 1; |
| 1264 | } |
| 1265 | |
| 1266 | /* lookup into the maps */ |
| 1267 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1268 | if (!appctx->ctx.map.ref) { |
| 1269 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1270 | appctx->st0 = STAT_CLI_PRINT; |
| 1271 | return 1; |
| 1272 | } |
| 1273 | |
| 1274 | /* copy input string */ |
| 1275 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1276 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1277 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1278 | if (!appctx->ctx.map.chunk.str) { |
| 1279 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1280 | appctx->st0 = STAT_CLI_PRINT; |
| 1281 | return 1; |
| 1282 | } |
| 1283 | |
| 1284 | /* prepare response */ |
| 1285 | appctx->st2 = STAT_ST_INIT; |
| 1286 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1287 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1288 | else { /* not "get weight" */ |
| 1289 | return 0; |
| 1290 | } |
| 1291 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1292 | else if (strcmp(args[0], "set") == 0) { |
| 1293 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1294 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1295 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1296 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1297 | sv = expect_server_admin(s, si, args[2]); |
| 1298 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1299 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1300 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1301 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1302 | /* |
| 1303 | * The user-weight may now be zero and thus |
| 1304 | * the server considered to be draining. |
| 1305 | * Update the server's drain state as necessary. |
| 1306 | */ |
| 1307 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1308 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1309 | appctx->ctx.cli.msg = warning; |
| 1310 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1311 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1312 | return 1; |
| 1313 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1314 | else if (strcmp(args[1], "timeout") == 0) { |
| 1315 | if (strcmp(args[2], "cli") == 0) { |
| 1316 | unsigned timeout; |
| 1317 | const char *res; |
| 1318 | |
| 1319 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1320 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1321 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1322 | return 1; |
| 1323 | } |
| 1324 | |
| 1325 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1326 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1327 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1328 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1329 | return 1; |
| 1330 | } |
| 1331 | |
| 1332 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1333 | return 1; |
| 1334 | } |
| 1335 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1336 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1337 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1338 | return 1; |
| 1339 | } |
| 1340 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1341 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1342 | if (strcmp(args[2], "frontend") == 0) { |
| 1343 | struct proxy *px; |
| 1344 | struct listener *l; |
| 1345 | int v; |
| 1346 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1347 | px = expect_frontend_admin(s, si, args[3]); |
| 1348 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1349 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1350 | |
| 1351 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1352 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1353 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1354 | return 1; |
| 1355 | } |
| 1356 | |
| 1357 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1358 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1359 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1360 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1361 | return 1; |
| 1362 | } |
| 1363 | |
| 1364 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1365 | * its listeners. The blocked ones will be dequeued. |
| 1366 | */ |
| 1367 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1368 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1369 | l->maxconn = v; |
| 1370 | if (l->state == LI_FULL) |
| 1371 | resume_listener(l); |
| 1372 | } |
| 1373 | |
| 1374 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1375 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1376 | |
| 1377 | return 1; |
| 1378 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1379 | else if (strcmp(args[2], "global") == 0) { |
| 1380 | int v; |
| 1381 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1382 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1383 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1384 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1385 | return 1; |
| 1386 | } |
| 1387 | |
| 1388 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1389 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1390 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1391 | return 1; |
| 1392 | } |
| 1393 | |
| 1394 | v = atoi(args[3]); |
| 1395 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1396 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1397 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1398 | return 1; |
| 1399 | } |
| 1400 | |
| 1401 | /* check for unlimited values */ |
| 1402 | if (v <= 0) |
| 1403 | v = global.hardmaxconn; |
| 1404 | |
| 1405 | global.maxconn = v; |
| 1406 | |
| 1407 | /* Dequeues all of the listeners waiting for a resource */ |
| 1408 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1409 | dequeue_all_listeners(&global_listener_queue); |
| 1410 | |
| 1411 | return 1; |
| 1412 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1413 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1414 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1415 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1416 | return 1; |
| 1417 | } |
| 1418 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1419 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1420 | if (strcmp(args[2], "connections") == 0) { |
| 1421 | if (strcmp(args[3], "global") == 0) { |
| 1422 | int v; |
| 1423 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1424 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1425 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1426 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1427 | return 1; |
| 1428 | } |
| 1429 | |
| 1430 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1431 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1432 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1433 | return 1; |
| 1434 | } |
| 1435 | |
| 1436 | v = atoi(args[4]); |
| 1437 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1438 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1439 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1440 | return 1; |
| 1441 | } |
| 1442 | |
| 1443 | global.cps_lim = v; |
| 1444 | |
| 1445 | /* Dequeues all of the listeners waiting for a resource */ |
| 1446 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1447 | dequeue_all_listeners(&global_listener_queue); |
| 1448 | |
| 1449 | return 1; |
| 1450 | } |
| 1451 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1452 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1453 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1454 | return 1; |
| 1455 | } |
| 1456 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1457 | else if (strcmp(args[2], "sessions") == 0) { |
| 1458 | if (strcmp(args[3], "global") == 0) { |
| 1459 | int v; |
| 1460 | |
| 1461 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1462 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1463 | appctx->st0 = STAT_CLI_PRINT; |
| 1464 | return 1; |
| 1465 | } |
| 1466 | |
| 1467 | if (!*args[4]) { |
| 1468 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1469 | appctx->st0 = STAT_CLI_PRINT; |
| 1470 | return 1; |
| 1471 | } |
| 1472 | |
| 1473 | v = atoi(args[4]); |
| 1474 | if (v < 0) { |
| 1475 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1476 | appctx->st0 = STAT_CLI_PRINT; |
| 1477 | return 1; |
| 1478 | } |
| 1479 | |
| 1480 | global.sps_lim = v; |
| 1481 | |
| 1482 | /* Dequeues all of the listeners waiting for a resource */ |
| 1483 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1484 | dequeue_all_listeners(&global_listener_queue); |
| 1485 | |
| 1486 | return 1; |
| 1487 | } |
| 1488 | else { |
| 1489 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1490 | appctx->st0 = STAT_CLI_PRINT; |
| 1491 | return 1; |
| 1492 | } |
| 1493 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1494 | #ifdef USE_OPENSSL |
| 1495 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1496 | if (strcmp(args[3], "global") == 0) { |
| 1497 | int v; |
| 1498 | |
| 1499 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1500 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1501 | appctx->st0 = STAT_CLI_PRINT; |
| 1502 | return 1; |
| 1503 | } |
| 1504 | |
| 1505 | if (!*args[4]) { |
| 1506 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1507 | appctx->st0 = STAT_CLI_PRINT; |
| 1508 | return 1; |
| 1509 | } |
| 1510 | |
| 1511 | v = atoi(args[4]); |
| 1512 | if (v < 0) { |
| 1513 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1514 | appctx->st0 = STAT_CLI_PRINT; |
| 1515 | return 1; |
| 1516 | } |
| 1517 | |
| 1518 | global.ssl_lim = v; |
| 1519 | |
| 1520 | /* Dequeues all of the listeners waiting for a resource */ |
| 1521 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1522 | dequeue_all_listeners(&global_listener_queue); |
| 1523 | |
| 1524 | return 1; |
| 1525 | } |
| 1526 | else { |
| 1527 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1528 | appctx->st0 = STAT_CLI_PRINT; |
| 1529 | return 1; |
| 1530 | } |
| 1531 | } |
| 1532 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1533 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1534 | if (strcmp(args[3], "global") == 0) { |
| 1535 | int v; |
| 1536 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1537 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1538 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1539 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1540 | return 1; |
| 1541 | } |
| 1542 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1543 | v = atoi(args[4]); |
| 1544 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1545 | } |
| 1546 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1547 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1548 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1549 | return 1; |
| 1550 | } |
| 1551 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1552 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1553 | 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] | 1554 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1555 | return 1; |
| 1556 | } |
| 1557 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1558 | else if (strcmp(args[1], "table") == 0) { |
| 1559 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1560 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1561 | else if (strcmp(args[1], "map") == 0) { |
| 1562 | struct pattern *pat_elt; |
| 1563 | struct pat_idx_elt *idx_elt; |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1564 | char *value = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1565 | |
| 1566 | /* Expect three parameters: map name, key and new value. */ |
| 1567 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 1568 | appctx->ctx.cli.msg = "'set map' expect three parameters: map name, key and value.\n"; |
| 1569 | appctx->st0 = STAT_CLI_PRINT; |
| 1570 | return 1; |
| 1571 | } |
| 1572 | |
| 1573 | /* Lookup the reference in the maps. */ |
| 1574 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1575 | if (!appctx->ctx.map.ref) { |
| 1576 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1577 | appctx->st0 = STAT_CLI_PRINT; |
| 1578 | return 1; |
| 1579 | } |
| 1580 | |
| 1581 | /* Lookup the entry in the reference values. */ |
| 1582 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) |
| 1583 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) |
| 1584 | break; |
| 1585 | |
| 1586 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) { |
| 1587 | appctx->ctx.cli.msg = "Entry not found.\n"; |
| 1588 | appctx->st0 = STAT_CLI_PRINT; |
| 1589 | return 1; |
| 1590 | } |
| 1591 | |
| 1592 | /* Update each reference entries. */ |
| 1593 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) { |
| 1594 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) { |
| 1595 | value = strdup(args[4]); |
| 1596 | if (!value) { |
| 1597 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1598 | appctx->st0 = STAT_CLI_PRINT; |
| 1599 | return 1; |
| 1600 | } |
| 1601 | free(appctx->ctx.map.ent->value); |
| 1602 | appctx->ctx.map.ent->value = value; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | /* Change the sample. The lookup juste return the first entry, other |
| 1607 | * entries are not changed, but are never matched. |
| 1608 | */ |
| 1609 | appctx->ctx.map.desc = NULL; |
| 1610 | for (stats_map_lookup_next(si); |
| 1611 | appctx->ctx.map.desc; |
| 1612 | stats_map_lookup_next(si)) { |
| 1613 | pattern_lookup(args[3], appctx->ctx.map.desc->pat, &pat_elt, &idx_elt, NULL); |
| 1614 | if (pat_elt != NULL) |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1615 | appctx->ctx.map.desc->parse(value, pat_elt->smp); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1616 | if (idx_elt != NULL) |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1617 | appctx->ctx.map.desc->parse(value, idx_elt->smp); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | /* The set is done, send message. */ |
| 1621 | appctx->ctx.cli.msg = "Done.\n"; |
| 1622 | appctx->st0 = STAT_CLI_PRINT; |
| 1623 | return 1; |
| 1624 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1625 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1626 | return 0; |
| 1627 | } |
| 1628 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1629 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1630 | if (strcmp(args[1], "agent") == 0) { |
| 1631 | struct server *sv; |
| 1632 | |
| 1633 | sv = expect_server_admin(s, si, args[2]); |
| 1634 | if (!sv) |
| 1635 | return 1; |
| 1636 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1637 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1638 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1639 | appctx->st0 = STAT_CLI_PRINT; |
| 1640 | return 1; |
| 1641 | } |
| 1642 | |
| 1643 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1644 | return 1; |
| 1645 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1646 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1647 | struct server *sv; |
| 1648 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1649 | sv = expect_server_admin(s, si, args[2]); |
| 1650 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1651 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1652 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1653 | if (sv->state & SRV_MAINTAIN) { |
| 1654 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1655 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1656 | /* If this server tracks the status of another one, |
| 1657 | * we must restore the good status. |
| 1658 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1659 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1660 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1661 | 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] | 1662 | } else { |
| 1663 | sv->state &= ~SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1664 | sv->check.state &= ~CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1665 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1666 | } |
| 1667 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1668 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1669 | 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] | 1670 | } |
| 1671 | } |
| 1672 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1673 | return 1; |
| 1674 | } |
| 1675 | else if (strcmp(args[1], "frontend") == 0) { |
| 1676 | struct proxy *px; |
| 1677 | |
| 1678 | px = expect_frontend_admin(s, si, args[2]); |
| 1679 | if (!px) |
| 1680 | return 1; |
| 1681 | |
| 1682 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1683 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1684 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1685 | return 1; |
| 1686 | } |
| 1687 | |
| 1688 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1689 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1690 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1691 | return 1; |
| 1692 | } |
| 1693 | |
| 1694 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1695 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1696 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1697 | return 1; |
| 1698 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1699 | return 1; |
| 1700 | } |
| 1701 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1702 | appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1703 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1704 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1705 | } |
| 1706 | } |
| 1707 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1708 | if (strcmp(args[1], "agent") == 0) { |
| 1709 | struct server *sv; |
| 1710 | |
| 1711 | sv = expect_server_admin(s, si, args[2]); |
| 1712 | if (!sv) |
| 1713 | return 1; |
| 1714 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1715 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1716 | return 1; |
| 1717 | } |
| 1718 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1719 | struct server *sv; |
| 1720 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1721 | sv = expect_server_admin(s, si, args[2]); |
| 1722 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1723 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1724 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1725 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1726 | /* Not already in maintenance, we can change the server state */ |
| 1727 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1728 | sv->check.state |= CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1729 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1730 | } |
| 1731 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1732 | return 1; |
| 1733 | } |
| 1734 | else if (strcmp(args[1], "frontend") == 0) { |
| 1735 | struct proxy *px; |
| 1736 | |
| 1737 | px = expect_frontend_admin(s, si, args[2]); |
| 1738 | if (!px) |
| 1739 | return 1; |
| 1740 | |
| 1741 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1742 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1743 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1744 | return 1; |
| 1745 | } |
| 1746 | |
| 1747 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1748 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1749 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1750 | return 1; |
| 1751 | } |
| 1752 | |
| 1753 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1754 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1755 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1756 | return 1; |
| 1757 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1758 | return 1; |
| 1759 | } |
| 1760 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1761 | appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1762 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1763 | return 1; |
| 1764 | } |
| 1765 | } |
| 1766 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1767 | if (strcmp(args[1], "frontend") == 0) { |
| 1768 | struct proxy *px; |
| 1769 | |
| 1770 | px = expect_frontend_admin(s, si, args[2]); |
| 1771 | if (!px) |
| 1772 | return 1; |
| 1773 | |
| 1774 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1775 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1776 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1777 | return 1; |
| 1778 | } |
| 1779 | |
| 1780 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1781 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1782 | send_log(px, LOG_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 | stop_proxy(px); |
| 1785 | return 1; |
| 1786 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1787 | else if (strcmp(args[1], "session") == 0) { |
| 1788 | struct session *sess, *ptr; |
| 1789 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1790 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1791 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1792 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1793 | return 1; |
| 1794 | } |
| 1795 | |
| 1796 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1797 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1798 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1799 | return 1; |
| 1800 | } |
| 1801 | |
| 1802 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1803 | |
| 1804 | /* first, look for the requested session in the session table */ |
| 1805 | list_for_each_entry(sess, &sessions, list) { |
| 1806 | if (sess == ptr) |
| 1807 | break; |
| 1808 | } |
| 1809 | |
| 1810 | /* do we have the session ? */ |
| 1811 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1812 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1813 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1814 | return 1; |
| 1815 | } |
| 1816 | |
| 1817 | session_shutdown(sess, SN_ERR_KILLED); |
| 1818 | return 1; |
| 1819 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1820 | else if (strcmp(args[1], "sessions") == 0) { |
| 1821 | if (strcmp(args[2], "server") == 0) { |
| 1822 | struct server *sv; |
| 1823 | struct session *sess, *sess_bck; |
| 1824 | |
| 1825 | sv = expect_server_admin(s, si, args[3]); |
| 1826 | if (!sv) |
| 1827 | return 1; |
| 1828 | |
| 1829 | /* kill all the session that are on this server */ |
| 1830 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1831 | if (sess->srv_conn == sv) |
| 1832 | session_shutdown(sess, SN_ERR_KILLED); |
| 1833 | |
| 1834 | return 1; |
| 1835 | } |
| 1836 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1837 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1838 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1839 | return 1; |
| 1840 | } |
| 1841 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1842 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1843 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1844 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1845 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1846 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1847 | } |
| 1848 | else if (strcmp(args[0], "del") == 0) { |
| 1849 | if (strcmp(args[1], "map") == 0) { |
| 1850 | struct pattern *pat_elt; |
| 1851 | struct pat_idx_elt *idx_elt; |
| 1852 | struct map_entry *ent; |
| 1853 | |
| 1854 | /* Expect two parameters: map name and key. */ |
| 1855 | if (!*args[2] || !*args[3]) { |
| 1856 | appctx->ctx.cli.msg = "'del map' expect two parameters: map name and key.\n"; |
| 1857 | appctx->st0 = STAT_CLI_PRINT; |
| 1858 | return 1; |
| 1859 | } |
| 1860 | |
| 1861 | /* Lookup the reference in the maps. */ |
| 1862 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1863 | if (!appctx->ctx.map.ref) { |
| 1864 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1865 | appctx->st0 = STAT_CLI_PRINT; |
| 1866 | return 1; |
| 1867 | } |
| 1868 | |
| 1869 | /* Lookup the entry in the reference values. |
| 1870 | * If the entry is not found in the reference, return error message. |
| 1871 | */ |
| 1872 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) |
| 1873 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) |
| 1874 | break; |
| 1875 | |
| 1876 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) { |
| 1877 | appctx->ctx.cli.msg = "Entry not found.\n"; |
| 1878 | appctx->st0 = STAT_CLI_PRINT; |
| 1879 | return 1; |
| 1880 | } |
| 1881 | |
| 1882 | /* Delete each enties from reference. */ |
| 1883 | list_for_each_entry_safe(appctx->ctx.map.ent, ent, &appctx->ctx.map.ref->entries, list) { |
| 1884 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) { |
| 1885 | LIST_DEL(&appctx->ctx.map.ent->list); |
| 1886 | free(appctx->ctx.map.ent->key); |
| 1887 | free(appctx->ctx.map.ent->value); |
| 1888 | free(appctx->ctx.map.ent); |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | /* Delete all matching entries for each map descritor. */ |
| 1893 | appctx->ctx.map.desc = NULL; |
| 1894 | stats_map_lookup_next(si); |
| 1895 | while (appctx->ctx.map.desc) { |
| 1896 | while (pattern_lookup(args[3], appctx->ctx.map.desc->pat, &pat_elt, &idx_elt, NULL)) { |
| 1897 | if (pat_elt != NULL) { |
| 1898 | LIST_DEL(&pat_elt->list); |
| 1899 | pattern_free(pat_elt); |
| 1900 | } |
| 1901 | if (idx_elt != NULL) { |
| 1902 | ebmb_delete(&idx_elt->node); |
| 1903 | free(idx_elt); |
| 1904 | } |
| 1905 | } |
| 1906 | stats_map_lookup_next(si); |
| 1907 | } |
| 1908 | |
| 1909 | /* The deletion is done, send message. */ |
| 1910 | appctx->ctx.cli.msg = "Done.\n"; |
| 1911 | appctx->st0 = STAT_CLI_PRINT; |
| 1912 | return 1; |
| 1913 | } |
| 1914 | else { /* unknown "del" parameter */ |
| 1915 | appctx->ctx.cli.msg = "'del' only supports 'map'.\n"; |
| 1916 | appctx->st0 = STAT_CLI_PRINT; |
| 1917 | return 1; |
| 1918 | } |
| 1919 | } |
| 1920 | else if (strcmp(args[0], "add") == 0) { |
| 1921 | if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1922 | struct pattern *pat; |
| 1923 | struct map_entry *ent; |
| 1924 | struct sample_storage *smp; |
| 1925 | |
| 1926 | /* Expect three parameters: map name, key and new value. */ |
| 1927 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 1928 | appctx->ctx.cli.msg = "'add map' expect three parameters: map name, key and value.\n"; |
| 1929 | appctx->st0 = STAT_CLI_PRINT; |
| 1930 | return 1; |
| 1931 | } |
| 1932 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1933 | /* Lookup the reference in the maps. */ |
| 1934 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1935 | if (!appctx->ctx.map.ref) { |
| 1936 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1937 | appctx->st0 = STAT_CLI_PRINT; |
| 1938 | return 1; |
| 1939 | } |
| 1940 | |
| 1941 | /* Prepare and link the new map_entry element. If out of memory |
| 1942 | * error the action is cancelled and the descriptor are left |
| 1943 | * coherents. |
| 1944 | */ |
| 1945 | ent = malloc(sizeof(*ent)); |
| 1946 | if (!ent) { |
| 1947 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1948 | appctx->st0 = STAT_CLI_PRINT; |
| 1949 | return 1; |
| 1950 | } |
| 1951 | ent->key = strdup(args[3]); |
| 1952 | if (!ent->key) { |
| 1953 | free(ent); |
| 1954 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1955 | appctx->st0 = STAT_CLI_PRINT; |
| 1956 | return 1; |
| 1957 | } |
| 1958 | ent->value = strdup(args[4]); |
| 1959 | if (!ent->value) { |
| 1960 | free(ent->key); |
| 1961 | free(ent); |
| 1962 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1963 | appctx->st0 = STAT_CLI_PRINT; |
| 1964 | return 1; |
| 1965 | } |
| 1966 | LIST_ADDQ(&appctx->ctx.map.ref->entries, &ent->list); |
| 1967 | |
| 1968 | /* Browse each map descritor and try to insert this new value. */ |
| 1969 | appctx->ctx.map.desc = NULL; |
| 1970 | for (stats_map_lookup_next(si); |
| 1971 | appctx->ctx.map.desc; |
| 1972 | stats_map_lookup_next(si)) { |
| 1973 | |
| 1974 | /* Create new sample. Return out of memory error |
| 1975 | * if the memory cannot be allocated. The 'add' process |
| 1976 | * is aborted, but the already inserted entries are not |
| 1977 | * deleted. |
| 1978 | */ |
| 1979 | smp = calloc(1, sizeof(*smp)); |
| 1980 | if (!smp) { |
| 1981 | appctx->ctx.cli.msg = "Out of memory error. The value is not added in all maps.\n"; |
| 1982 | appctx->st0 = STAT_CLI_PRINT; |
| 1983 | return 1; |
| 1984 | } |
| 1985 | |
| 1986 | /* Create sample. If this function fails, the insertion |
| 1987 | * is canceled for this 'descriptor', but continue, for |
| 1988 | * the other descriptors. |
| 1989 | */ |
| 1990 | if (!appctx->ctx.map.desc->parse(ent->value, smp)) { |
| 1991 | free(smp); |
| 1992 | continue; |
| 1993 | } |
| 1994 | |
| 1995 | /* If the value can be indexed, get the first pattern. If |
| 1996 | * the return entry is not the indexed entry, new 'pattern' is |
| 1997 | * created by the function pattern_register(). If the 'pattern' |
| 1998 | * is NULL, new entry is created. This is ugly because the |
| 1999 | * following code interfers with the own code of the function |
| 2000 | * pattern_register(). |
| 2001 | */ |
| 2002 | if (appctx->ctx.map.desc->pat->match == pat_match_str || |
| 2003 | appctx->ctx.map.desc->pat->match == pat_match_ip) { |
| 2004 | pat = LIST_NEXT(&appctx->ctx.map.desc->pat->patterns, struct pattern *, list); |
| 2005 | if (&pat->list == &appctx->ctx.map.desc->pat->patterns) |
| 2006 | pat = NULL; |
| 2007 | } |
| 2008 | else |
| 2009 | pat = NULL; |
| 2010 | |
Thierry FOURNIER | 972028f | 2014-01-23 17:53:31 +0100 | [diff] [blame^] | 2011 | if (!pattern_register(appctx->ctx.map.desc->pat, args[3], smp, &pat, 0, NULL)) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2012 | free(smp); |
| 2013 | continue; |
| 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | /* The add is done, send message. */ |
| 2018 | appctx->ctx.cli.msg = "Done.\n"; |
| 2019 | appctx->st0 = STAT_CLI_PRINT; |
| 2020 | return 1; |
| 2021 | } |
| 2022 | else { /* unknown "del" parameter */ |
| 2023 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2024 | appctx->st0 = STAT_CLI_PRINT; |
| 2025 | return 1; |
| 2026 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2027 | } |
| 2028 | 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] | 2029 | return 0; |
| 2030 | } |
| 2031 | return 1; |
| 2032 | } |
| 2033 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2034 | /* 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] | 2035 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2036 | * state machine handling requests and various responses. We read a request, |
| 2037 | * 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] | 2038 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2039 | * 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] | 2040 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2041 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2042 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2043 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2044 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2045 | struct channel *req = si->ob; |
| 2046 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2047 | int reql; |
| 2048 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2049 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2050 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2051 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2052 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2053 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2054 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2055 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2056 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2057 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2058 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2059 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2060 | /* Let's close for real now. We just close the request |
| 2061 | * side, the conditions below will complete if needed. |
| 2062 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2063 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2064 | break; |
| 2065 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2066 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2067 | /* ensure we have some output room left in the event we |
| 2068 | * would want to return some info right after parsing. |
| 2069 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2070 | if (buffer_almost_full(si->ib->buf)) { |
| 2071 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2072 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2073 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2074 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2075 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2076 | if (reql <= 0) { /* closed or EOL not found */ |
| 2077 | if (reql == 0) |
| 2078 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2079 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2080 | continue; |
| 2081 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2082 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2083 | /* seek for a possible semi-colon. If we find one, we |
| 2084 | * replace it with an LF and skip only this part. |
| 2085 | */ |
| 2086 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2087 | if (trash.str[len] == ';') { |
| 2088 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2089 | reql = len + 1; |
| 2090 | break; |
| 2091 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2092 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2093 | /* now it is time to check that we have a full line, |
| 2094 | * remove the trailing \n and possibly \r, then cut the |
| 2095 | * line. |
| 2096 | */ |
| 2097 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2098 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2099 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2100 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2101 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2102 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2103 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2104 | len--; |
| 2105 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2106 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2107 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2108 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2109 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2110 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2111 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2112 | continue; |
| 2113 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2114 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2115 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2116 | else if (strcmp(trash.str, "help") == 0 || |
| 2117 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2118 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2119 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2120 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2121 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2122 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2123 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2124 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2125 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2126 | /* if prompt is disabled, print help on empty lines, |
| 2127 | * so that the user at least knows how to enable |
| 2128 | * prompt and find help. |
| 2129 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2130 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2131 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2135 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2136 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2137 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2138 | 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] | 2139 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2140 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2141 | continue; |
| 2142 | } |
| 2143 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2144 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2145 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2146 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2147 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2148 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2149 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2150 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2151 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2152 | break; |
| 2153 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2154 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2155 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2156 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2157 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2158 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2159 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2160 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2161 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2162 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2163 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2164 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2165 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2166 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2167 | if (stats_table_request(si, appctx->st0)) |
| 2168 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2169 | break; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2170 | case STAT_CLI_O_MAPS: |
| 2171 | if (stats_maps_list(si)) |
| 2172 | appctx->st0 = STAT_CLI_PROMPT; |
| 2173 | break; |
| 2174 | case STAT_CLI_O_MAP: |
| 2175 | if (stats_map_list(si)) |
| 2176 | appctx->st0 = STAT_CLI_PROMPT; |
| 2177 | break; |
| 2178 | case STAT_CLI_O_MLOOK: |
| 2179 | if (stats_map_lookup(si)) |
| 2180 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2181 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2182 | case STAT_CLI_O_POOLS: |
| 2183 | if (stats_dump_pools_to_buffer(si)) |
| 2184 | appctx->st0 = STAT_CLI_PROMPT; |
| 2185 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2186 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2187 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2188 | break; |
| 2189 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2190 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2191 | /* 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] | 2192 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2193 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2194 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2195 | } |
| 2196 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2197 | /* 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] | 2198 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2199 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2200 | |
| 2201 | /* Now we close the output if one of the writers did so, |
| 2202 | * or if we're not in interactive mode and the request |
| 2203 | * buffer is empty. This still allows pipelined requests |
| 2204 | * to be sent in non-interactive mode. |
| 2205 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2206 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2207 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2208 | continue; |
| 2209 | } |
| 2210 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2211 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2212 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2213 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2214 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2215 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2216 | 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] | 2217 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2218 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2219 | /* 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] | 2220 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2221 | * we forward the close to the request side so that it flows upstream to |
| 2222 | * the client. |
| 2223 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2224 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2225 | } |
| 2226 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2227 | 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] | 2228 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2229 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2230 | /* We have no more processing to do, and nothing more to send, and |
| 2231 | * the client side has closed. So we'll forward this state downstream |
| 2232 | * on the response buffer. |
| 2233 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2234 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2235 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2239 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2240 | |
| 2241 | /* we don't want to expire timeouts while we're processing requests */ |
| 2242 | si->ib->rex = TICK_ETERNITY; |
| 2243 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2244 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2245 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2246 | 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] | 2247 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2248 | 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] | 2249 | |
| 2250 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2251 | /* check that we have released everything then unregister */ |
| 2252 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2253 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2254 | } |
| 2255 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2256 | /* This function dumps information onto the stream interface's read buffer. |
| 2257 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2258 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2259 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2260 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2261 | { |
| 2262 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2263 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2264 | chunk_printf(&trash, |
| 2265 | "Name: " PRODUCT_NAME "\n" |
| 2266 | "Version: " HAPROXY_VERSION "\n" |
| 2267 | "Release_date: " HAPROXY_DATE "\n" |
| 2268 | "Nbproc: %d\n" |
| 2269 | "Process_num: %d\n" |
| 2270 | "Pid: %d\n" |
| 2271 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2272 | "Uptime_sec: %d\n" |
| 2273 | "Memmax_MB: %d\n" |
| 2274 | "Ulimit-n: %d\n" |
| 2275 | "Maxsock: %d\n" |
| 2276 | "Maxconn: %d\n" |
| 2277 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2278 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2279 | "CumConns: %d\n" |
| 2280 | "CumReq: %d\n" |
| 2281 | #ifdef USE_OPENSSL |
| 2282 | "MaxSslConns: %d\n" |
| 2283 | "CurrSslConns: %d\n" |
| 2284 | "CumSslConns: %d\n" |
| 2285 | #endif |
| 2286 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2287 | "PipesUsed: %d\n" |
| 2288 | "PipesFree: %d\n" |
| 2289 | "ConnRate: %d\n" |
| 2290 | "ConnRateLimit: %d\n" |
| 2291 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2292 | "SessRate: %d\n" |
| 2293 | "SessRateLimit: %d\n" |
| 2294 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2295 | #ifdef USE_OPENSSL |
| 2296 | "SslRate: %d\n" |
| 2297 | "SslRateLimit: %d\n" |
| 2298 | "MaxSslRate: %d\n" |
| 2299 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2300 | "CompressBpsIn: %u\n" |
| 2301 | "CompressBpsOut: %u\n" |
| 2302 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2303 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2304 | "ZlibMemUsage: %ld\n" |
| 2305 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2306 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2307 | "Tasks: %d\n" |
| 2308 | "Run_queue: %d\n" |
| 2309 | "Idle_pct: %d\n" |
| 2310 | "node: %s\n" |
| 2311 | "description: %s\n" |
| 2312 | "", |
| 2313 | global.nbproc, |
| 2314 | relative_pid, |
| 2315 | pid, |
| 2316 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2317 | up, |
| 2318 | global.rlimit_memmax, |
| 2319 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2320 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2321 | actconn, totalconn, global.req_count, |
| 2322 | #ifdef USE_OPENSSL |
| 2323 | global.maxsslconn, sslconns, totalsslconns, |
| 2324 | #endif |
| 2325 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2326 | 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] | 2327 | 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] | 2328 | #ifdef USE_OPENSSL |
| 2329 | read_freq_ctr(&global.ssl_per_sec), global.ssl_lim, global.ssl_max, |
| 2330 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2331 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2332 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2333 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2334 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2335 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2336 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2337 | global.node, global.desc ? global.desc : "" |
| 2338 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2339 | |
| 2340 | if (bi_putchk(si->ib, &trash) == -1) |
| 2341 | return 0; |
| 2342 | |
| 2343 | return 1; |
| 2344 | } |
| 2345 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2346 | /* This function dumps memory usage information onto the stream interface's |
| 2347 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2348 | * completion. No state is used. |
| 2349 | */ |
| 2350 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2351 | { |
| 2352 | dump_pools_to_trash(); |
| 2353 | if (bi_putchk(si->ib, &trash) == -1) |
| 2354 | return 0; |
| 2355 | return 1; |
| 2356 | } |
| 2357 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2358 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2359 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2360 | * 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] | 2361 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2362 | 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] | 2363 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2364 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2365 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2366 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2367 | if (!(px->cap & PR_CAP_FE)) |
| 2368 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2369 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2370 | 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] | 2371 | return 0; |
| 2372 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2373 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2374 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2375 | /* name, queue */ |
| 2376 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2377 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2378 | 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] | 2379 | /* Column sub-heading for Enable or Disable server */ |
| 2380 | chunk_appendf(&trash, "<td></td>"); |
| 2381 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2382 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2383 | chunk_appendf(&trash, |
| 2384 | "<td class=ac>" |
| 2385 | "<a name=\"%s/Frontend\"></a>" |
| 2386 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2387 | "<td colspan=3></td>" |
| 2388 | "", |
| 2389 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2390 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2391 | chunk_appendf(&trash, |
| 2392 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2393 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2394 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2395 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2396 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2397 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2398 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2399 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2400 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2401 | if (px->mode == PR_MODE_HTTP) |
| 2402 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2403 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2404 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2405 | |
| 2406 | chunk_appendf(&trash, |
| 2407 | "</table></div></u></td>" |
| 2408 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2409 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2410 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2411 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2412 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2413 | U2H(px->fe_counters.sps_max), |
| 2414 | U2H(px->fe_counters.cps_max), |
| 2415 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2416 | |
| 2417 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2418 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2419 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2420 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2421 | |
| 2422 | chunk_appendf(&trash, |
| 2423 | "</table></div></u></td>" |
| 2424 | /* sessions rate : limit */ |
| 2425 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2426 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2427 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2428 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2429 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2430 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2431 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2432 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2433 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2434 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2435 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2436 | U2H(px->fe_counters.cum_sess), |
| 2437 | U2H(px->fe_counters.cum_conn), |
| 2438 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2439 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2440 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2441 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2442 | chunk_appendf(&trash, |
| 2443 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2444 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2445 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2446 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2447 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2448 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2449 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2450 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2451 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2452 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2453 | U2H(px->fe_counters.p.http.cum_req), |
| 2454 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2455 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2456 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2457 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2458 | (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] | 2459 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2460 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2461 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2462 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2463 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2464 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2465 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2466 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2467 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2468 | /* sessions: lbtot, lastsess */ |
| 2469 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2470 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2471 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2472 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2473 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2474 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2475 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2476 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2477 | "<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] | 2478 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2479 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2480 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2481 | px->fe_counters.comp_in ? |
| 2482 | (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] | 2483 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2484 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2485 | chunk_appendf(&trash, |
| 2486 | /* denied: req, resp */ |
| 2487 | "<td>%s</td><td>%s</td>" |
| 2488 | /* errors : request, connect, response */ |
| 2489 | "<td>%s</td><td></td><td></td>" |
| 2490 | /* warnings: retries, redispatches */ |
| 2491 | "<td></td><td></td>" |
| 2492 | /* server status : reflect frontend status */ |
| 2493 | "<td class=ac>%s</td>" |
| 2494 | /* rest of server: nothing */ |
| 2495 | "<td class=ac colspan=8></td></tr>" |
| 2496 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2497 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2498 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2499 | px->state == PR_STREADY ? "OPEN" : |
| 2500 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2501 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2502 | else { /* CSV mode */ |
| 2503 | chunk_appendf(&trash, |
| 2504 | /* pxid, name, queue cur, queue max, */ |
| 2505 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2506 | /* sessions : current, max, limit, total */ |
| 2507 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2508 | /* bytes : in, out */ |
| 2509 | "%lld,%lld," |
| 2510 | /* denied: req, resp */ |
| 2511 | "%lld,%lld," |
| 2512 | /* errors : request, connect, response */ |
| 2513 | "%lld,,," |
| 2514 | /* warnings: retries, redispatches */ |
| 2515 | ",," |
| 2516 | /* server status : reflect frontend status */ |
| 2517 | "%s," |
| 2518 | /* rest of server: nothing */ |
| 2519 | ",,,,,,,," |
| 2520 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2521 | "%d,%d,0,,,,%d," |
| 2522 | /* rate, rate_lim, rate_max */ |
| 2523 | "%u,%u,%u," |
| 2524 | /* check_status, check_code, check_duration */ |
| 2525 | ",,,", |
| 2526 | px->id, |
| 2527 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2528 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2529 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2530 | px->fe_counters.failed_req, |
| 2531 | px->state == PR_STREADY ? "OPEN" : |
| 2532 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2533 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2534 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2535 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2536 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2537 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2538 | if (px->mode == PR_MODE_HTTP) { |
| 2539 | for (i=1; i<6; i++) |
| 2540 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2541 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2542 | } |
| 2543 | else |
| 2544 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2545 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2546 | /* failed health analyses */ |
| 2547 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2548 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2549 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2550 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2551 | read_freq_ctr(&px->fe_req_per_sec), |
| 2552 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2553 | |
| 2554 | /* errors: cli_aborts, srv_aborts */ |
| 2555 | chunk_appendf(&trash, ",,"); |
| 2556 | |
| 2557 | /* compression: in, out, bypassed */ |
| 2558 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2559 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2560 | |
| 2561 | /* compression: comp_rsp */ |
| 2562 | chunk_appendf(&trash, "%lld,", |
| 2563 | px->fe_counters.p.http.comp_rsp); |
| 2564 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2565 | /* lastsess */ |
| 2566 | chunk_appendf(&trash, ","); |
| 2567 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2568 | /* finish with EOL */ |
| 2569 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2570 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2571 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2572 | } |
| 2573 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2574 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2575 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2576 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2577 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2578 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2579 | 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] | 2580 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2581 | struct appctx *appctx = __objt_appctx(si->end); |
| 2582 | |
| 2583 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2584 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2585 | 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] | 2586 | /* Column sub-heading for Enable or Disable server */ |
| 2587 | chunk_appendf(&trash, "<td></td>"); |
| 2588 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2589 | chunk_appendf(&trash, |
| 2590 | /* frontend name, listener name */ |
| 2591 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2592 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2593 | "", |
| 2594 | px->id, l->name, |
| 2595 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2596 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2597 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2598 | if (flags & ST_SHLGNDS) { |
| 2599 | char str[INET6_ADDRSTRLEN]; |
| 2600 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2601 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2602 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2603 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2604 | port = get_host_port(&l->addr); |
| 2605 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2606 | case AF_INET: |
| 2607 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2608 | break; |
| 2609 | case AF_INET6: |
| 2610 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2611 | break; |
| 2612 | case AF_UNIX: |
| 2613 | chunk_appendf(&trash, "unix, "); |
| 2614 | break; |
| 2615 | case -1: |
| 2616 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2617 | break; |
| 2618 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2619 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2620 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2621 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2622 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2623 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2624 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2625 | /* queue */ |
| 2626 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2627 | /* sessions rate: current, max, limit */ |
| 2628 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2629 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2630 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2631 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2632 | /* bytes: in, out */ |
| 2633 | "<td>%s</td><td>%s</td>" |
| 2634 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2635 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2636 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2637 | 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] | 2638 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2639 | chunk_appendf(&trash, |
| 2640 | /* denied: req, resp */ |
| 2641 | "<td>%s</td><td>%s</td>" |
| 2642 | /* errors: request, connect, response */ |
| 2643 | "<td>%s</td><td></td><td></td>" |
| 2644 | /* warnings: retries, redispatches */ |
| 2645 | "<td></td><td></td>" |
| 2646 | /* server status: reflect listener status */ |
| 2647 | "<td class=ac>%s</td>" |
| 2648 | /* rest of server: nothing */ |
| 2649 | "<td class=ac colspan=8></td></tr>" |
| 2650 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2651 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2652 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2653 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2654 | } |
| 2655 | else { /* CSV mode */ |
| 2656 | chunk_appendf(&trash, |
| 2657 | /* pxid, name, queue cur, queue max, */ |
| 2658 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2659 | /* sessions: current, max, limit, total */ |
| 2660 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2661 | /* bytes: in, out */ |
| 2662 | "%lld,%lld," |
| 2663 | /* denied: req, resp */ |
| 2664 | "%lld,%lld," |
| 2665 | /* errors: request, connect, response */ |
| 2666 | "%lld,,," |
| 2667 | /* warnings: retries, redispatches */ |
| 2668 | ",," |
| 2669 | /* server status: reflect listener status */ |
| 2670 | "%s," |
| 2671 | /* rest of server: nothing */ |
| 2672 | ",,,,,,,," |
| 2673 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2674 | "%d,%d,%d,,,,%d," |
| 2675 | /* rate, rate_lim, rate_max */ |
| 2676 | ",,," |
| 2677 | /* check_status, check_code, check_duration */ |
| 2678 | ",,," |
| 2679 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2680 | ",,,,,," |
| 2681 | /* failed health analyses */ |
| 2682 | "," |
| 2683 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2684 | ",,," |
| 2685 | /* errors: cli_aborts, srv_aborts */ |
| 2686 | ",," |
| 2687 | /* compression: in, out, bypassed, comp_rsp */ |
| 2688 | ",,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2689 | /* lastsess */ |
| 2690 | "," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2691 | "\n", |
| 2692 | px->id, l->name, |
| 2693 | l->nbconn, l->counters->conn_max, |
| 2694 | l->maxconn, l->counters->cum_conn, |
| 2695 | l->counters->bytes_in, l->counters->bytes_out, |
| 2696 | l->counters->denied_req, l->counters->denied_resp, |
| 2697 | l->counters->failed_req, |
| 2698 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2699 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2700 | } |
| 2701 | return 1; |
| 2702 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2703 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2704 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2705 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2706 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2707 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2708 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2709 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2710 | */ |
| 2711 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2712 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2713 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2714 | struct server *ref = sv->track ? sv->track : sv; |
| 2715 | char str[INET6_ADDRSTRLEN]; |
| 2716 | struct chunk src; |
| 2717 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2718 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2719 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2720 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2721 | "DOWN", |
| 2722 | "DN %d/%d ↑", |
| 2723 | "UP %d/%d ↓", |
| 2724 | "UP", |
| 2725 | "NOLB %d/%d ↓", |
| 2726 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2727 | "DRAIN %d/%d ↓", |
| 2728 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2729 | "<i>no check</i>" |
| 2730 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2731 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2732 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2733 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2734 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2735 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2736 | "<tr class=\"%s%d\">", |
| 2737 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2738 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2739 | 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] | 2740 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2741 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2742 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2743 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2744 | chunk_appendf(&trash, |
| 2745 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2746 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2747 | "", |
| 2748 | px->id, sv->id, |
| 2749 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2750 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2751 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2752 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2753 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2754 | |
| 2755 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2756 | case AF_INET: |
| 2757 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2758 | break; |
| 2759 | case AF_INET6: |
| 2760 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2761 | break; |
| 2762 | case AF_UNIX: |
| 2763 | chunk_appendf(&trash, "unix, "); |
| 2764 | break; |
| 2765 | case -1: |
| 2766 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2767 | break; |
| 2768 | default: /* address family not supported */ |
| 2769 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2770 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2771 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2772 | /* id */ |
| 2773 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2774 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2775 | /* cookie */ |
| 2776 | if (sv->cookie) { |
| 2777 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2778 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2779 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2780 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2781 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2782 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2783 | } |
| 2784 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2785 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2786 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2787 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2788 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2789 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2790 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2791 | /* sessions rate : current, max, limit */ |
| 2792 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2793 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2794 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2795 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2796 | 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] | 2797 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2798 | |
| 2799 | chunk_appendf(&trash, |
| 2800 | /* sessions: current, max, limit, total */ |
| 2801 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2802 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2803 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2804 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2805 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2806 | U2H(sv->counters.cum_sess), |
| 2807 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2808 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2809 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2810 | if (px->mode == PR_MODE_HTTP) { |
| 2811 | unsigned long long tot; |
| 2812 | for (tot = i = 0; i < 6; i++) |
| 2813 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2814 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2815 | chunk_appendf(&trash, |
| 2816 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2817 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2818 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2819 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2820 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2821 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2822 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2823 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2824 | U2H(tot), |
| 2825 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2826 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2827 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2828 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2829 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2830 | 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] | 2831 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2832 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2833 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2834 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2835 | /* sessions: lbtot, last */ |
| 2836 | "<td>%s</td><td>%s</td>", |
| 2837 | U2H(sv->counters.cum_lbconn), |
| 2838 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2839 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2840 | chunk_appendf(&trash, |
| 2841 | /* bytes : in, out */ |
| 2842 | "<td>%s</td><td>%s</td>" |
| 2843 | /* denied: req, resp */ |
| 2844 | "<td></td><td>%s</td>" |
| 2845 | /* errors : request, connect */ |
| 2846 | "<td></td><td>%s</td>" |
| 2847 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2848 | "<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] | 2849 | /* warnings: retries, redispatches */ |
| 2850 | "<td>%lld</td><td>%lld</td>" |
| 2851 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2852 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2853 | U2H(sv->counters.failed_secu), |
| 2854 | U2H(sv->counters.failed_conns), |
| 2855 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2856 | sv->counters.cli_aborts, |
| 2857 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2858 | sv->counters.retries, sv->counters.redispatches); |
| 2859 | |
| 2860 | /* status, lest check */ |
| 2861 | chunk_appendf(&trash, "<td class=ac>"); |
| 2862 | |
| 2863 | if (sv->state & SRV_MAINTAIN) { |
| 2864 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2865 | chunk_appendf(&trash, "MAINT"); |
| 2866 | } |
| 2867 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2868 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2869 | chunk_appendf(&trash, "MAINT(via)"); |
| 2870 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2871 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2872 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2873 | chunk_appendf(&trash, |
| 2874 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2875 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2876 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2877 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2878 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2879 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2880 | chunk_appendf(&trash, |
| 2881 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 2882 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2883 | get_check_status_info(sv->check.status)); |
| 2884 | |
| 2885 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2886 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2887 | |
| 2888 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2889 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2890 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2891 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2892 | get_check_status_description(sv->check.status)); |
| 2893 | if (*sv->check.desc) { |
| 2894 | chunk_appendf(&trash, ": "); |
| 2895 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2896 | chunk_htmlencode(&trash, &src); |
| 2897 | } |
| 2898 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2899 | } |
| 2900 | else |
| 2901 | chunk_appendf(&trash, "</td><td>"); |
| 2902 | |
| 2903 | chunk_appendf(&trash, |
| 2904 | /* weight */ |
| 2905 | "</td><td class=ac>%d</td>" |
| 2906 | /* act, bck */ |
| 2907 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2908 | "", |
| 2909 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2910 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2911 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2912 | |
| 2913 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2914 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2915 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2916 | |
| 2917 | if (ref->observe) |
| 2918 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2919 | |
| 2920 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2921 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2922 | "<td>%lld</td><td>%s</td>" |
| 2923 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2924 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2925 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2926 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2927 | else if (sv != ref) { |
| 2928 | if (sv->state & SRV_MAINTAIN) |
| 2929 | chunk_appendf(&trash, |
| 2930 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2931 | ref->proxy->id, ref->id); |
| 2932 | else |
| 2933 | chunk_appendf(&trash, |
| 2934 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2935 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2936 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2937 | else |
| 2938 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2939 | |
| 2940 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2941 | if (sv->state & SRV_WARMINGUP) |
| 2942 | 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] | 2943 | else |
| 2944 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2945 | } |
| 2946 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2947 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2948 | "DOWN,", |
| 2949 | "DOWN %d/%d,", |
| 2950 | "UP %d/%d,", |
| 2951 | "UP,", |
| 2952 | "NOLB %d/%d,", |
| 2953 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2954 | "DRAIN %d/%d,", |
| 2955 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2956 | "no check," |
| 2957 | }; |
| 2958 | |
| 2959 | chunk_appendf(&trash, |
| 2960 | /* pxid, name */ |
| 2961 | "%s,%s," |
| 2962 | /* queue : current, max */ |
| 2963 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2964 | /* sessions : current, max, limit, total */ |
| 2965 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2966 | /* bytes : in, out */ |
| 2967 | "%lld,%lld," |
| 2968 | /* denied: req, resp */ |
| 2969 | ",%lld," |
| 2970 | /* errors : request, connect, response */ |
| 2971 | ",%lld,%lld," |
| 2972 | /* warnings: retries, redispatches */ |
| 2973 | "%lld,%lld," |
| 2974 | "", |
| 2975 | px->id, sv->id, |
| 2976 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2977 | 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] | 2978 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2979 | sv->counters.failed_secu, |
| 2980 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2981 | sv->counters.retries, sv->counters.redispatches); |
| 2982 | |
| 2983 | /* status */ |
| 2984 | if (sv->state & SRV_MAINTAIN) |
| 2985 | chunk_appendf(&trash, "MAINT,"); |
| 2986 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2987 | chunk_appendf(&trash, "MAINT(via),"); |
| 2988 | else |
| 2989 | chunk_appendf(&trash, |
| 2990 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2991 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2992 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2993 | |
| 2994 | chunk_appendf(&trash, |
| 2995 | /* weight, active, backup */ |
| 2996 | "%d,%d,%d," |
| 2997 | "", |
| 2998 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2999 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 3000 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 3001 | |
| 3002 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3003 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3004 | chunk_appendf(&trash, |
| 3005 | "%lld,%lld,%d,%d,", |
| 3006 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3007 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3008 | else |
| 3009 | chunk_appendf(&trash, ",,,,"); |
| 3010 | |
| 3011 | /* queue limit, pid, iid, sid, */ |
| 3012 | chunk_appendf(&trash, |
| 3013 | "%s," |
| 3014 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3015 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3016 | relative_pid, px->uuid, sv->puid); |
| 3017 | |
| 3018 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3019 | if (sv->state & SRV_WARMINGUP) |
| 3020 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3021 | |
| 3022 | /* sessions: lbtot */ |
| 3023 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3024 | |
| 3025 | /* tracked */ |
| 3026 | if (sv->track) |
| 3027 | chunk_appendf(&trash, "%s/%s,", |
| 3028 | sv->track->proxy->id, sv->track->id); |
| 3029 | else |
| 3030 | chunk_appendf(&trash, ","); |
| 3031 | |
| 3032 | /* type */ |
| 3033 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3034 | |
| 3035 | /* rate */ |
| 3036 | chunk_appendf(&trash, "%u,,%u,", |
| 3037 | read_freq_ctr(&sv->sess_per_sec), |
| 3038 | sv->counters.sps_max); |
| 3039 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3040 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3041 | /* check_status */ |
| 3042 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3043 | |
| 3044 | /* check_code */ |
| 3045 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3046 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3047 | else |
| 3048 | chunk_appendf(&trash, ","); |
| 3049 | |
| 3050 | /* check_duration */ |
| 3051 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3052 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3053 | else |
| 3054 | chunk_appendf(&trash, ","); |
| 3055 | |
| 3056 | } |
| 3057 | else |
| 3058 | chunk_appendf(&trash, ",,,"); |
| 3059 | |
| 3060 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3061 | if (px->mode == PR_MODE_HTTP) { |
| 3062 | for (i=1; i<6; i++) |
| 3063 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3064 | |
| 3065 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3066 | } |
| 3067 | else |
| 3068 | chunk_appendf(&trash, ",,,,,,"); |
| 3069 | |
| 3070 | /* failed health analyses */ |
| 3071 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3072 | |
| 3073 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3074 | chunk_appendf(&trash, ",,,"); |
| 3075 | |
| 3076 | /* errors: cli_aborts, srv_aborts */ |
| 3077 | chunk_appendf(&trash, "%lld,%lld,", |
| 3078 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3079 | |
| 3080 | /* compression: in, out, bypassed, comp_rsp */ |
| 3081 | chunk_appendf(&trash, ",,,,"); |
| 3082 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3083 | /* lastsess */ |
| 3084 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3085 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3086 | /* finish with EOL */ |
| 3087 | chunk_appendf(&trash, "\n"); |
| 3088 | } |
| 3089 | return 1; |
| 3090 | } |
| 3091 | |
| 3092 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3093 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3094 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3095 | */ |
| 3096 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3097 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3098 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3099 | struct chunk src; |
| 3100 | int i; |
| 3101 | |
| 3102 | if (!(px->cap & PR_CAP_BE)) |
| 3103 | return 0; |
| 3104 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3105 | 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] | 3106 | return 0; |
| 3107 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3108 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3109 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3110 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3111 | /* Column sub-heading for Enable or Disable server */ |
| 3112 | chunk_appendf(&trash, "<td></td>"); |
| 3113 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3114 | chunk_appendf(&trash, |
| 3115 | "<td class=ac>" |
| 3116 | /* name */ |
| 3117 | "%s<a name=\"%s/Backend\"></a>" |
| 3118 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3119 | "", |
| 3120 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3121 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3122 | |
| 3123 | if (flags & ST_SHLGNDS) { |
| 3124 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3125 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3126 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3127 | |
| 3128 | /* cookie */ |
| 3129 | if (px->cookie_name) { |
| 3130 | chunk_appendf(&trash, ", cookie: '"); |
| 3131 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3132 | chunk_htmlencode(&trash, &src); |
| 3133 | chunk_appendf(&trash, "'"); |
| 3134 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3135 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3139 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3140 | /* queue : current, max */ |
| 3141 | "<td>%s</td><td>%s</td><td></td>" |
| 3142 | /* sessions rate : current, max, limit */ |
| 3143 | "<td>%s</td><td>%s</td><td></td>" |
| 3144 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3145 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3146 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3147 | 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] | 3148 | |
| 3149 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3150 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3151 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3152 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3153 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3154 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3155 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3156 | U2H(px->be_counters.cum_conn), |
| 3157 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3158 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3159 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3160 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3161 | chunk_appendf(&trash, |
| 3162 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3163 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3164 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3165 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3166 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3167 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3168 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3169 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3170 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3171 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3172 | U2H(px->be_counters.p.http.cum_req), |
| 3173 | U2H(px->be_counters.p.http.rsp[1]), |
| 3174 | U2H(px->be_counters.p.http.rsp[2]), |
| 3175 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3176 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3177 | (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] | 3178 | U2H(px->be_counters.p.http.rsp[3]), |
| 3179 | U2H(px->be_counters.p.http.rsp[4]), |
| 3180 | U2H(px->be_counters.p.http.rsp[5]), |
| 3181 | U2H(px->be_counters.p.http.rsp[0]), |
| 3182 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3186 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3187 | /* sessions: lbtot, last */ |
| 3188 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3189 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3190 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3191 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3192 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3193 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3194 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3195 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3196 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3197 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3198 | "<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] | 3199 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3200 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3201 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3202 | px->be_counters.comp_in ? |
| 3203 | (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] | 3204 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3205 | |
| 3206 | chunk_appendf(&trash, |
| 3207 | /* denied: req, resp */ |
| 3208 | "<td>%s</td><td>%s</td>" |
| 3209 | /* errors : request, connect */ |
| 3210 | "<td></td><td>%s</td>" |
| 3211 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3212 | "<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] | 3213 | /* warnings: retries, redispatches */ |
| 3214 | "<td>%lld</td><td>%lld</td>" |
| 3215 | /* backend status: reflect backend status (up/down): we display UP |
| 3216 | * if the backend has known working servers or if it has no server at |
| 3217 | * all (eg: for stats). Then we display the total weight, number of |
| 3218 | * active and backups. */ |
| 3219 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3220 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3221 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3222 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3223 | U2H(px->be_counters.failed_conns), |
| 3224 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3225 | px->be_counters.cli_aborts, |
| 3226 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3227 | px->be_counters.retries, px->be_counters.redispatches, |
| 3228 | human_time(now.tv_sec - px->last_change, 1), |
| 3229 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3230 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3231 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3232 | px->srv_act, px->srv_bck); |
| 3233 | |
| 3234 | chunk_appendf(&trash, |
| 3235 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3236 | "<td class=ac> </td><td>%d</td>" |
| 3237 | "<td>%s</td>" |
| 3238 | "<td></td>" |
| 3239 | "</tr>", |
| 3240 | px->down_trans, |
| 3241 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3242 | } |
| 3243 | else { /* CSV mode */ |
| 3244 | chunk_appendf(&trash, |
| 3245 | /* pxid, name */ |
| 3246 | "%s,BACKEND," |
| 3247 | /* queue : current, max */ |
| 3248 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3249 | /* sessions : current, max, limit, total */ |
| 3250 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3251 | /* bytes : in, out */ |
| 3252 | "%lld,%lld," |
| 3253 | /* denied: req, resp */ |
| 3254 | "%lld,%lld," |
| 3255 | /* errors : request, connect, response */ |
| 3256 | ",%lld,%lld," |
| 3257 | /* warnings: retries, redispatches */ |
| 3258 | "%lld,%lld," |
| 3259 | /* backend status: reflect backend status (up/down): we display UP |
| 3260 | * if the backend has known working servers or if it has no server at |
| 3261 | * all (eg: for stats). Then we display the total weight, number of |
| 3262 | * active and backups. */ |
| 3263 | "%s," |
| 3264 | "%d,%d,%d," |
| 3265 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3266 | ",%d,%d,%d,," |
| 3267 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3268 | "%d,%d,0,,%lld,,%d," |
| 3269 | /* rate, rate_lim, rate_max, */ |
| 3270 | "%u,,%u," |
| 3271 | /* check_status, check_code, check_duration */ |
| 3272 | ",,,", |
| 3273 | px->id, |
| 3274 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3275 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3276 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3277 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3278 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3279 | px->be_counters.retries, px->be_counters.redispatches, |
| 3280 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3281 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3282 | px->srv_act, px->srv_bck, |
| 3283 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3284 | px->srv?be_downtime(px):0, |
| 3285 | relative_pid, px->uuid, |
| 3286 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3287 | read_freq_ctr(&px->be_sess_per_sec), |
| 3288 | px->be_counters.sps_max); |
| 3289 | |
| 3290 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3291 | if (px->mode == PR_MODE_HTTP) { |
| 3292 | for (i=1; i<6; i++) |
| 3293 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3294 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3295 | } |
| 3296 | else |
| 3297 | chunk_appendf(&trash, ",,,,,,"); |
| 3298 | |
| 3299 | /* failed health analyses */ |
| 3300 | chunk_appendf(&trash, ","); |
| 3301 | |
| 3302 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3303 | chunk_appendf(&trash, ",,,"); |
| 3304 | |
| 3305 | /* errors: cli_aborts, srv_aborts */ |
| 3306 | chunk_appendf(&trash, "%lld,%lld,", |
| 3307 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3308 | |
| 3309 | /* compression: in, out, bypassed */ |
| 3310 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3311 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3312 | |
| 3313 | /* compression: comp_rsp */ |
| 3314 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3315 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3316 | /* lastsess */ |
| 3317 | chunk_appendf(&trash, "%d,", be_lastsession(px)); |
| 3318 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3319 | /* finish with EOL */ |
| 3320 | chunk_appendf(&trash, "\n"); |
| 3321 | } |
| 3322 | return 1; |
| 3323 | } |
| 3324 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3325 | /* 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] | 3326 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3327 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3328 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3329 | 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] | 3330 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3331 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3332 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3333 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3334 | 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] | 3335 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3336 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3337 | /* 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] | 3338 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3339 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3340 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3341 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3342 | 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] | 3343 | } |
| 3344 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3345 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3346 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3347 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3348 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3349 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3350 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | /* print a new table */ |
| 3354 | chunk_appendf(&trash, |
| 3355 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3356 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3357 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3358 | |
| 3359 | chunk_appendf(&trash, |
| 3360 | "<a name=\"%s\"></a>%s" |
| 3361 | "<a class=px href=\"#%s\">%s</a>", |
| 3362 | px->id, |
| 3363 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3364 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3365 | |
| 3366 | if (uri->flags & ST_SHLGNDS) { |
| 3367 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3368 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3369 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3370 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3371 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3375 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3376 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3377 | "</tr>\n" |
| 3378 | "</table>\n" |
| 3379 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3380 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3381 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3382 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3383 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3384 | 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] | 3385 | /* Column heading for Enable or Disable server */ |
| 3386 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3387 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3388 | |
| 3389 | chunk_appendf(&trash, |
| 3390 | "<th rowspan=2></th>" |
| 3391 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3392 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3393 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3394 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3395 | "<th colspan=9>Server</th>" |
| 3396 | "</tr>\n" |
| 3397 | "<tr class=\"titre\">" |
| 3398 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3399 | "<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] | 3400 | "<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] | 3401 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3402 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3403 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3404 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3405 | "<th>Thrtle</th>\n" |
| 3406 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3407 | } |
| 3408 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3409 | /* 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] | 3410 | * 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] | 3411 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3412 | 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] | 3413 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3414 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3415 | chunk_appendf(&trash, "</table>"); |
| 3416 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3417 | 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] | 3418 | /* close the form used to enable/disable this proxy servers */ |
| 3419 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3420 | "Choose the action to perform on the checked servers : " |
| 3421 | "<select name=action>" |
| 3422 | "<option value=\"\"></option>" |
| 3423 | "<option value=\"disable\">Disable</option>" |
| 3424 | "<option value=\"enable\">Enable</option>" |
| 3425 | "<option value=\"stop\">Soft Stop</option>" |
| 3426 | "<option value=\"start\">Soft Start</option>" |
| 3427 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3428 | "</select>" |
| 3429 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3430 | " <input type=\"submit\" value=\"Apply\">" |
| 3431 | "</form>", |
| 3432 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3436 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3437 | |
| 3438 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3439 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3440 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3441 | * buffer space, or non-zero if everything completed. This function is used |
| 3442 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3443 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3444 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3445 | 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] | 3446 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3447 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3448 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3449 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3450 | 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] | 3451 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3452 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3453 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3454 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3455 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3456 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3457 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3458 | if (uri && uri->scope) { |
| 3459 | /* we have a limited scope, we have to check the proxy name */ |
| 3460 | struct stat_scope *scope; |
| 3461 | int len; |
| 3462 | |
| 3463 | len = strlen(px->id); |
| 3464 | scope = uri->scope; |
| 3465 | |
| 3466 | while (scope) { |
| 3467 | /* match exact proxy name */ |
| 3468 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3469 | break; |
| 3470 | |
| 3471 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3472 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3473 | break; |
| 3474 | scope = scope->next; |
| 3475 | } |
| 3476 | |
| 3477 | /* proxy name not found : don't dump anything */ |
| 3478 | if (scope == NULL) |
| 3479 | return 1; |
| 3480 | } |
| 3481 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3482 | /* if the user has requested a limited output and the proxy |
| 3483 | * name does not match, skip it. |
| 3484 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3485 | if (appctx->ctx.stats.scope_len && |
| 3486 | 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] | 3487 | return 1; |
| 3488 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3489 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3490 | (appctx->ctx.stats.iid != -1) && |
| 3491 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3492 | return 1; |
| 3493 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3494 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3495 | /* fall through */ |
| 3496 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3497 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3498 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3499 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3500 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3501 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3502 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3503 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3504 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3505 | /* fall through */ |
| 3506 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3507 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3508 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3509 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3510 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3511 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3512 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3513 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3514 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3515 | /* fall through */ |
| 3516 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3517 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3518 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3519 | 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] | 3520 | if (buffer_almost_full(rep->buf)) { |
| 3521 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3522 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3523 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3524 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3525 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3526 | if (!l->counters) |
| 3527 | continue; |
| 3528 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3529 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3530 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3531 | break; |
| 3532 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3533 | 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] | 3534 | continue; |
| 3535 | } |
| 3536 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3537 | /* print the frontend */ |
| 3538 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3539 | if (bi_putchk(rep, &trash) == -1) |
| 3540 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3541 | } |
| 3542 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3543 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3544 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3545 | /* fall through */ |
| 3546 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3547 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3548 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3549 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3550 | 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] | 3551 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3552 | if (buffer_almost_full(rep->buf)) { |
| 3553 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3554 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3555 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3556 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3557 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3558 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3559 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3560 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3561 | break; |
| 3562 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3563 | 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] | 3564 | continue; |
| 3565 | } |
| 3566 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3567 | if (sv->track) |
| 3568 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3569 | else |
| 3570 | svs = sv; |
| 3571 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3572 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3573 | if (!(svs->check.state & CHK_ST_ENABLED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3574 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3575 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 3576 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3577 | sv_state = 3; /* UP */ |
| 3578 | else |
| 3579 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3580 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3581 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3582 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3583 | else if (svs->state & SRV_GOINGDOWN) |
| 3584 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3585 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3586 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 3587 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3588 | sv_state = 1; /* going up */ |
| 3589 | else |
| 3590 | sv_state = 0; /* DOWN */ |
| 3591 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3592 | 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] | 3593 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3594 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3595 | continue; |
| 3596 | } |
| 3597 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3598 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3599 | if (bi_putchk(rep, &trash) == -1) |
| 3600 | return 0; |
| 3601 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3602 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3603 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3604 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3605 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3606 | case STAT_PX_ST_BE: |
| 3607 | /* print the backend */ |
| 3608 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3609 | if (bi_putchk(rep, &trash) == -1) |
| 3610 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3611 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3612 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3613 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3614 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3615 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3616 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3617 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3618 | if (bi_putchk(rep, &trash) == -1) |
| 3619 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3620 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3621 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3622 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3623 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3624 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3625 | case STAT_PX_ST_FIN: |
| 3626 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3627 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3628 | default: |
| 3629 | /* unknown state, we should put an abort() here ! */ |
| 3630 | return 1; |
| 3631 | } |
| 3632 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3633 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3634 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3635 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3636 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3637 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3638 | { |
| 3639 | /* WARNING! This must fit in the first buffer !!! */ |
| 3640 | chunk_appendf(&trash, |
| 3641 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3642 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3643 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3644 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3645 | "<style type=\"text/css\"><!--\n" |
| 3646 | "body {" |
| 3647 | " font-family: arial, helvetica, sans-serif;" |
| 3648 | " font-size: 12px;" |
| 3649 | " font-weight: normal;" |
| 3650 | " color: black;" |
| 3651 | " background: white;" |
| 3652 | "}\n" |
| 3653 | "th,td {" |
| 3654 | " font-size: 10px;" |
| 3655 | "}\n" |
| 3656 | "h1 {" |
| 3657 | " font-size: x-large;" |
| 3658 | " margin-bottom: 0.5em;" |
| 3659 | "}\n" |
| 3660 | "h2 {" |
| 3661 | " font-family: helvetica, arial;" |
| 3662 | " font-size: x-large;" |
| 3663 | " font-weight: bold;" |
| 3664 | " font-style: italic;" |
| 3665 | " color: #6020a0;" |
| 3666 | " margin-top: 0em;" |
| 3667 | " margin-bottom: 0em;" |
| 3668 | "}\n" |
| 3669 | "h3 {" |
| 3670 | " font-family: helvetica, arial;" |
| 3671 | " font-size: 16px;" |
| 3672 | " font-weight: bold;" |
| 3673 | " color: #b00040;" |
| 3674 | " background: #e8e8d0;" |
| 3675 | " margin-top: 0em;" |
| 3676 | " margin-bottom: 0em;" |
| 3677 | "}\n" |
| 3678 | "li {" |
| 3679 | " margin-top: 0.25em;" |
| 3680 | " margin-right: 2em;" |
| 3681 | "}\n" |
| 3682 | ".hr {margin-top: 0.25em;" |
| 3683 | " border-color: black;" |
| 3684 | " border-bottom-style: solid;" |
| 3685 | "}\n" |
| 3686 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3687 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3688 | ".frontend {background: #e8e8d0;}\n" |
| 3689 | ".socket {background: #d0d0d0;}\n" |
| 3690 | ".backend {background: #e8e8d0;}\n" |
| 3691 | ".active0 {background: #ff9090;}\n" |
| 3692 | ".active1 {background: #ffd020;}\n" |
| 3693 | ".active2 {background: #ffffa0;}\n" |
| 3694 | ".active3 {background: #c0ffc0;}\n" |
| 3695 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3696 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3697 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3698 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3699 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3700 | ".backup0 {background: #ff9090;}\n" |
| 3701 | ".backup1 {background: #ff80ff;}\n" |
| 3702 | ".backup2 {background: #c060ff;}\n" |
| 3703 | ".backup3 {background: #b0d0ff;}\n" |
| 3704 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3705 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3706 | ".backup6 {background: #c060ff;}\n" |
| 3707 | ".backup7 {background: #cc9900;}\n" |
| 3708 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3709 | ".maintain {background: #c07820;}\n" |
| 3710 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3711 | "\n" |
| 3712 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3713 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3714 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3715 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3716 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3717 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3718 | "\n" |
| 3719 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3720 | "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" |
| 3721 | "table.tbl td.ac { text-align: center;}\n" |
| 3722 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3723 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3724 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3725 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3726 | "\n" |
| 3727 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3728 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3729 | "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] | 3730 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3731 | "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] | 3732 | "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] | 3733 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3734 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3735 | " display:block;\n" |
| 3736 | " visibility:hidden;\n" |
| 3737 | " z-index:2147483647;\n" |
| 3738 | " position:absolute;\n" |
| 3739 | " padding:2px 4px 3px;\n" |
| 3740 | " background:#f0f060; color:#000000;\n" |
| 3741 | " border:1px solid #7040c0;\n" |
| 3742 | " white-space:nowrap;\n" |
| 3743 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3744 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3745 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3746 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3747 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3748 | "-->\n" |
| 3749 | "</style></head>\n", |
| 3750 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3751 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3752 | ); |
| 3753 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3754 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3755 | /* 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] | 3756 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3757 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3758 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3759 | 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] | 3760 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3761 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3762 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3763 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3764 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3765 | /* WARNING! this has to fit the first packet too. |
| 3766 | * We are around 3.5 kB, add adding entries will |
| 3767 | * become tricky if we want to support 4kB buffers ! |
| 3768 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3769 | chunk_appendf(&trash, |
| 3770 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3771 | PRODUCT_NAME "%s</a></h1>\n" |
| 3772 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3773 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3774 | "<h3>> General process information</h3>\n" |
| 3775 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3776 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3777 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3778 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3779 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3780 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3781 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3782 | "</td><td align=\"center\" nowrap>\n" |
| 3783 | "<table class=\"lgd\"><tr>\n" |
| 3784 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3785 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3786 | "</tr><tr>\n" |
| 3787 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3788 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3789 | "</tr><tr>\n" |
| 3790 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3791 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3792 | "</tr><tr>\n" |
| 3793 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3794 | "</tr><tr>\n" |
| 3795 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3796 | "</tr><tr>\n" |
| 3797 | "<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] | 3798 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3799 | "<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] | 3800 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3801 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3802 | "</td>" |
| 3803 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3804 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3805 | "", |
| 3806 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3807 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3808 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3809 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3810 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3811 | pid, relative_pid, global.nbproc, |
| 3812 | up / 86400, (up % 86400) / 3600, |
| 3813 | (up % 3600) / 60, (up % 60), |
| 3814 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3815 | global.rlimit_memmax ? " MB" : "", |
| 3816 | global.rlimit_nofile, |
| 3817 | global.maxsock, global.maxconn, global.maxpipes, |
| 3818 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3819 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3820 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3821 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3822 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3823 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3824 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3825 | |
| 3826 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3827 | "<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] | 3828 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3829 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3830 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3831 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3832 | STAT_SCOPE_TXT_MAXLEN); |
| 3833 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3834 | /* 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] | 3835 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3836 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3837 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3838 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3839 | 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] | 3840 | } |
| 3841 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3842 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3843 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3844 | "<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] | 3845 | uri->uri_prefix, |
| 3846 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3847 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3848 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3849 | else |
| 3850 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3851 | "<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] | 3852 | uri->uri_prefix, |
| 3853 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3854 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3855 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3856 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3857 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3858 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
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\">Enable refresh</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" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3863 | "", |
| 3864 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3865 | else |
| 3866 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3867 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3868 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3869 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3870 | ";norefresh", |
| 3871 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3872 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3873 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3874 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3875 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3876 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3877 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3878 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3879 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3880 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3881 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3882 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3883 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3884 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3885 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3886 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3887 | chunk_appendf(&trash, |
| 3888 | "</ul></td>" |
| 3889 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3890 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3891 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3892 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3893 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3894 | "</ul>" |
| 3895 | "</td>" |
| 3896 | "</tr></table>\n" |
| 3897 | "" |
| 3898 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3899 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3900 | if (appctx->ctx.stats.st_code) { |
| 3901 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3902 | case STAT_STATUS_DONE: |
| 3903 | chunk_appendf(&trash, |
| 3904 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3905 | "<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] | 3906 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3907 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3908 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3909 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3910 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3911 | break; |
| 3912 | case STAT_STATUS_NONE: |
| 3913 | chunk_appendf(&trash, |
| 3914 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3915 | "<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] | 3916 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3917 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3918 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3919 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3920 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3921 | break; |
| 3922 | case STAT_STATUS_PART: |
| 3923 | chunk_appendf(&trash, |
| 3924 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3925 | "<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] | 3926 | "Action partially processed.<br>" |
| 3927 | "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] | 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_ERRP: |
| 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 | "Action not processed because of invalid parameters." |
| 3938 | "<ul>" |
| 3939 | "<li>The action is maybe unknown.</li>" |
| 3940 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3941 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3942 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3943 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3944 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3945 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3946 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3947 | break; |
| 3948 | case STAT_STATUS_EXCD: |
| 3949 | chunk_appendf(&trash, |
| 3950 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3951 | "<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] | 3952 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3953 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3954 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3955 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3956 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3957 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3958 | break; |
| 3959 | case STAT_STATUS_DENY: |
| 3960 | chunk_appendf(&trash, |
| 3961 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3962 | "<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] | 3963 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3964 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3965 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3966 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3967 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3968 | break; |
| 3969 | default: |
| 3970 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3971 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3972 | "<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] | 3973 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3974 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3975 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3976 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3977 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3978 | } |
| 3979 | chunk_appendf(&trash, "<p>\n"); |
| 3980 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3981 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3982 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3983 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3984 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3985 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3986 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3987 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3988 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3989 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3990 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3991 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3992 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3993 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3994 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3995 | * and the session must be closed, or -1 in case of any error. This function is |
| 3996 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3997 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3998 | 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] | 3999 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4000 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4001 | struct channel *rep = si->ib; |
| 4002 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4003 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4004 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4005 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4006 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4007 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4008 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4009 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4010 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4011 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4012 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4013 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4014 | else |
| 4015 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4016 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4017 | if (bi_putchk(rep, &trash) == -1) |
| 4018 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4019 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4020 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4021 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4022 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4023 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4024 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4025 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4026 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4027 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4028 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4029 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4030 | appctx->ctx.stats.px = proxy; |
| 4031 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4032 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4033 | /* fall through */ |
| 4034 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4035 | case STAT_ST_LIST: |
| 4036 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4037 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4038 | if (buffer_almost_full(rep->buf)) { |
| 4039 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4040 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4041 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4042 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4043 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4044 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4045 | 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] | 4046 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4047 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4048 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4049 | appctx->ctx.stats.px = px->next; |
| 4050 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4051 | } |
| 4052 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4053 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4054 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4055 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4056 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4057 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4058 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4059 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4060 | if (bi_putchk(rep, &trash) == -1) |
| 4061 | return 0; |
| 4062 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4063 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4064 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4065 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4066 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4067 | case STAT_ST_FIN: |
| 4068 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4069 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4070 | default: |
| 4071 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4072 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4073 | return -1; |
| 4074 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4075 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4076 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4077 | /* We reached the stats page through a POST request. The appctx is |
| 4078 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4079 | * Parse the posted data and enable/disable servers if necessary. |
| 4080 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4081 | */ |
| 4082 | static int stats_process_http_post(struct stream_interface *si) |
| 4083 | { |
| 4084 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4085 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4086 | |
| 4087 | struct proxy *px = NULL; |
| 4088 | struct server *sv = NULL; |
| 4089 | |
| 4090 | char key[LINESIZE]; |
| 4091 | int action = ST_ADM_ACTION_NONE; |
| 4092 | int reprocess = 0; |
| 4093 | |
| 4094 | int total_servers = 0; |
| 4095 | int altered_servers = 0; |
| 4096 | |
| 4097 | char *first_param, *cur_param, *next_param, *end_params; |
| 4098 | char *st_cur_param = NULL; |
| 4099 | char *st_next_param = NULL; |
| 4100 | |
| 4101 | struct chunk *temp; |
| 4102 | int reql; |
| 4103 | |
| 4104 | temp = get_trash_chunk(); |
| 4105 | if (temp->size < s->txn.req.body_len) { |
| 4106 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4107 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4108 | goto out; |
| 4109 | } |
| 4110 | |
| 4111 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 4112 | if (reql <= 0) { |
| 4113 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4114 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4115 | return 0; |
| 4116 | } |
| 4117 | |
| 4118 | first_param = temp->str; |
| 4119 | end_params = temp->str + reql; |
| 4120 | cur_param = next_param = end_params; |
| 4121 | *end_params = '\0'; |
| 4122 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4123 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4124 | |
| 4125 | /* |
| 4126 | * Parse the parameters in reverse order to only store the last value. |
| 4127 | * From the html form, the backend and the action are at the end. |
| 4128 | */ |
| 4129 | while (cur_param > first_param) { |
| 4130 | char *value; |
| 4131 | int poffset, plen; |
| 4132 | |
| 4133 | cur_param--; |
| 4134 | |
| 4135 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4136 | reprocess_servers: |
| 4137 | /* Parse the key */ |
| 4138 | poffset = (cur_param != first_param ? 1 : 0); |
| 4139 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4140 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4141 | strncpy(key, cur_param + poffset, plen); |
| 4142 | key[plen - 1] = '\0'; |
| 4143 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4144 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4145 | goto out; |
| 4146 | } |
| 4147 | |
| 4148 | /* Parse the value */ |
| 4149 | value = key; |
| 4150 | while (*value != '\0' && *value != '=') { |
| 4151 | value++; |
| 4152 | } |
| 4153 | if (*value == '=') { |
| 4154 | /* Ok, a value is found, we can mark the end of the key */ |
| 4155 | *value++ = '\0'; |
| 4156 | } |
| 4157 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4158 | break; |
| 4159 | |
| 4160 | /* Now we can check the key to see what to do */ |
| 4161 | if (!px && (strcmp(key, "b") == 0)) { |
| 4162 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4163 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4164 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4165 | goto out; |
| 4166 | } |
| 4167 | } |
| 4168 | else if (!action && (strcmp(key, "action") == 0)) { |
| 4169 | if (strcmp(value, "disable") == 0) { |
| 4170 | action = ST_ADM_ACTION_DISABLE; |
| 4171 | } |
| 4172 | else if (strcmp(value, "enable") == 0) { |
| 4173 | action = ST_ADM_ACTION_ENABLE; |
| 4174 | } |
| 4175 | else if (strcmp(value, "stop") == 0) { |
| 4176 | action = ST_ADM_ACTION_STOP; |
| 4177 | } |
| 4178 | else if (strcmp(value, "start") == 0) { |
| 4179 | action = ST_ADM_ACTION_START; |
| 4180 | } |
| 4181 | else if (strcmp(value, "shutdown") == 0) { |
| 4182 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4183 | } |
| 4184 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4185 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4186 | goto out; |
| 4187 | } |
| 4188 | } |
| 4189 | else if (strcmp(key, "s") == 0) { |
| 4190 | if (!(px && action)) { |
| 4191 | /* |
| 4192 | * Indicates that we'll need to reprocess the parameters |
| 4193 | * as soon as backend and action are known |
| 4194 | */ |
| 4195 | if (!reprocess) { |
| 4196 | st_cur_param = cur_param; |
| 4197 | st_next_param = next_param; |
| 4198 | } |
| 4199 | reprocess = 1; |
| 4200 | } |
| 4201 | else if ((sv = findserver(px, value)) != NULL) { |
| 4202 | switch (action) { |
| 4203 | case ST_ADM_ACTION_DISABLE: |
| 4204 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 4205 | /* Not already in maintenance, we can change the server state */ |
| 4206 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 4207 | sv->check.state |= CHK_ST_PAUSED; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4208 | set_server_down(&sv->check); |
| 4209 | altered_servers++; |
| 4210 | total_servers++; |
| 4211 | } |
| 4212 | break; |
| 4213 | case ST_ADM_ACTION_ENABLE: |
| 4214 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
Willy Tarreau | a3ae932 | 2013-12-28 21:28:49 +0100 | [diff] [blame] | 4215 | /* Already in maintenance, we can change the server state. |
| 4216 | * If this server tracks the status of another one, |
| 4217 | * we must restore the good status. |
| 4218 | */ |
| 4219 | if (!sv->track || (sv->track->state & SRV_RUNNING)) { |
| 4220 | set_server_up(&sv->check); |
| 4221 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 4222 | } |
| 4223 | else { |
| 4224 | sv->state &= ~SRV_MAINTAIN; |
| 4225 | sv->check.state &= ~CHK_ST_PAUSED; |
| 4226 | set_server_down(&sv->check); |
| 4227 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4228 | altered_servers++; |
| 4229 | total_servers++; |
| 4230 | } |
| 4231 | break; |
| 4232 | case ST_ADM_ACTION_STOP: |
| 4233 | case ST_ADM_ACTION_START: |
| 4234 | if (action == ST_ADM_ACTION_START) |
| 4235 | sv->uweight = sv->iweight; |
| 4236 | else |
| 4237 | sv->uweight = 0; |
| 4238 | |
| 4239 | server_recalc_eweight(sv); |
| 4240 | set_server_drain_state(sv); |
| 4241 | |
| 4242 | altered_servers++; |
| 4243 | total_servers++; |
| 4244 | break; |
| 4245 | case ST_ADM_ACTION_SHUTDOWN: |
| 4246 | if (px->state != PR_STSTOPPED) { |
| 4247 | struct session *sess, *sess_bck; |
| 4248 | |
| 4249 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4250 | if (sess->srv_conn == sv) |
| 4251 | session_shutdown(sess, SN_ERR_KILLED); |
| 4252 | |
| 4253 | altered_servers++; |
| 4254 | total_servers++; |
| 4255 | } |
| 4256 | break; |
| 4257 | } |
| 4258 | } else { |
| 4259 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4260 | total_servers++; |
| 4261 | } |
| 4262 | } |
| 4263 | if (reprocess && px && action) { |
| 4264 | /* Now, we know the backend and the action chosen by the user. |
| 4265 | * We can safely restart from the first server parameter |
| 4266 | * to reprocess them |
| 4267 | */ |
| 4268 | cur_param = st_cur_param; |
| 4269 | next_param = st_next_param; |
| 4270 | reprocess = 0; |
| 4271 | goto reprocess_servers; |
| 4272 | } |
| 4273 | |
| 4274 | next_param = cur_param; |
| 4275 | } |
| 4276 | } |
| 4277 | |
| 4278 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4279 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4280 | } |
| 4281 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4282 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4283 | } |
| 4284 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4285 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4286 | } |
| 4287 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4288 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4289 | } |
| 4290 | out: |
| 4291 | return 1; |
| 4292 | } |
| 4293 | |
| 4294 | |
| 4295 | static int stats_send_http_headers(struct stream_interface *si) |
| 4296 | { |
| 4297 | struct session *s = session_from_task(si->owner); |
| 4298 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4299 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4300 | |
| 4301 | chunk_printf(&trash, |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4302 | "HTTP/1.0 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4303 | "Cache-Control: no-cache\r\n" |
| 4304 | "Connection: close\r\n" |
| 4305 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4306 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4307 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4308 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4309 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4310 | uri->refresh); |
| 4311 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4312 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4313 | |
| 4314 | s->txn.status = 200; |
| 4315 | s->logs.tv_request = now; |
| 4316 | |
| 4317 | if (bi_putchk(si->ib, &trash) == -1) |
| 4318 | return 0; |
| 4319 | |
| 4320 | return 1; |
| 4321 | } |
| 4322 | |
| 4323 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4324 | { |
| 4325 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4326 | struct session *s = session_from_task(si->owner); |
| 4327 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4328 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4329 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4330 | /* 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] | 4331 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4332 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4333 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4334 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4335 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | /* We don't want to land on the posted stats page because a refresh will |
| 4339 | * repost the data. We don't want this to happen on accident so we redirect |
| 4340 | * the browse to the stats page with a GET. |
| 4341 | */ |
| 4342 | chunk_printf(&trash, |
| 4343 | "HTTP/1.1 303 See Other\r\n" |
| 4344 | "Cache-Control: no-cache\r\n" |
| 4345 | "Content-Type: text/plain\r\n" |
| 4346 | "Connection: close\r\n" |
| 4347 | "Location: %s;st=%s%s%s%s\r\n" |
| 4348 | "\r\n", |
| 4349 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4350 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4351 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4352 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4353 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4354 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4355 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4356 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4357 | scope_txt); |
| 4358 | |
| 4359 | s->txn.status = 303; |
| 4360 | s->logs.tv_request = now; |
| 4361 | |
| 4362 | if (bi_putchk(si->ib, &trash) == -1) |
| 4363 | return 0; |
| 4364 | |
| 4365 | return 1; |
| 4366 | } |
| 4367 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4368 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4369 | * 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] | 4370 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4371 | * automatically unregisters itself once transfer is complete. |
| 4372 | */ |
| 4373 | static void http_stats_io_handler(struct stream_interface *si) |
| 4374 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4375 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4376 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4377 | struct channel *req = si->ob; |
| 4378 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4379 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4380 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4381 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4382 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4383 | /* check that the output is not closed */ |
| 4384 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4385 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4386 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4387 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4388 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4389 | if (stats_send_http_headers(si)) { |
| 4390 | if (s->txn.meth == HTTP_METH_HEAD) |
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 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4393 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4394 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4395 | } |
| 4396 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4397 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4398 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4399 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4400 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4401 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4402 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4403 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4404 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4405 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4406 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4407 | } |
| 4408 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4409 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4410 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4411 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4412 | } |
| 4413 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4414 | if (appctx->st0 == STAT_HTTP_DONE) |
| 4415 | si_shutw(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4416 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4417 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4418 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4419 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4420 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4421 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4422 | si_shutr(si); |
| 4423 | res->flags |= CF_READ_NULL; |
| 4424 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4425 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4426 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4427 | /* update all other flags and resync with the other side */ |
| 4428 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4429 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4430 | /* we don't want to expire timeouts while we're processing requests */ |
| 4431 | si->ib->rex = TICK_ETERNITY; |
| 4432 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4433 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4434 | out: |
| 4435 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4436 | /* check that we have released everything then unregister */ |
| 4437 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4438 | } |
| 4439 | } |
| 4440 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4441 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4442 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4443 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4444 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4445 | return "NONE"; |
| 4446 | return conn->ctrl->name; |
| 4447 | } |
| 4448 | |
| 4449 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4450 | { |
| 4451 | static char ptr[17]; |
| 4452 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4453 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4454 | return "NONE"; |
| 4455 | |
| 4456 | if (conn->xprt == &raw_sock) |
| 4457 | return "RAW"; |
| 4458 | |
| 4459 | #ifdef USE_OPENSSL |
| 4460 | if (conn->xprt == &ssl_sock) |
| 4461 | return "SSL"; |
| 4462 | #endif |
| 4463 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4464 | return ptr; |
| 4465 | } |
| 4466 | |
| 4467 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4468 | { |
| 4469 | static char ptr[17]; |
| 4470 | |
| 4471 | if (!conn->data) |
| 4472 | return "NONE"; |
| 4473 | |
| 4474 | if (conn->data == &sess_conn_cb) |
| 4475 | return "SESS"; |
| 4476 | |
| 4477 | if (conn->data == &si_conn_cb) |
| 4478 | return "STRM"; |
| 4479 | |
| 4480 | if (conn->data == &check_conn_cb) |
| 4481 | return "CHCK"; |
| 4482 | |
| 4483 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4484 | return ptr; |
| 4485 | } |
| 4486 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4487 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4488 | * 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] | 4489 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4490 | * 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] | 4491 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4492 | 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] | 4493 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4494 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4495 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4496 | extern const char *monthname[12]; |
| 4497 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4498 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4499 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4500 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4501 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4502 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4503 | 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] | 4504 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4505 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4506 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4507 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4508 | appctx->ctx.sess.uid = 0; |
| 4509 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4510 | return 1; |
| 4511 | } |
| 4512 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4513 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4514 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4515 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4516 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4517 | /* fall through */ |
| 4518 | |
| 4519 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4520 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4521 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4522 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4523 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4524 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4525 | 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] | 4526 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 4527 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4528 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4529 | conn = objt_conn(sess->si[0].end); |
| 4530 | 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] | 4531 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4532 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4533 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4534 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4535 | break; |
| 4536 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4537 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4538 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4539 | default: |
| 4540 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4541 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4542 | break; |
| 4543 | } |
| 4544 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4545 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4546 | " 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] | 4547 | 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] | 4548 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4549 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4550 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4551 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 4552 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 4553 | sess->listener ? sess->listener->luid : 0); |
| 4554 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4555 | if (conn) |
| 4556 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4557 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4558 | 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] | 4559 | case AF_INET: |
| 4560 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4561 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4562 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4563 | break; |
| 4564 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4565 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4566 | break; |
| 4567 | default: |
| 4568 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4569 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4570 | break; |
| 4571 | } |
| 4572 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4573 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4574 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4575 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4576 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4577 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 4578 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4579 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4580 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4581 | conn = objt_conn(sess->si[1].end); |
| 4582 | if (conn) |
| 4583 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4584 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4585 | 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] | 4586 | case AF_INET: |
| 4587 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4588 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4589 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4590 | break; |
| 4591 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4592 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4593 | break; |
| 4594 | default: |
| 4595 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4596 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4597 | break; |
| 4598 | } |
| 4599 | |
| 4600 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4601 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4602 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4603 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 4604 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4605 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4606 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4607 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4608 | if (conn) |
| 4609 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4610 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4611 | 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] | 4612 | case AF_INET: |
| 4613 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4614 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4615 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4616 | break; |
| 4617 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4618 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4619 | break; |
| 4620 | default: |
| 4621 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4622 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4623 | break; |
| 4624 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 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 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4628 | sess->task, |
| 4629 | sess->task->state, |
| 4630 | sess->task->nice, sess->task->calls, |
| 4631 | sess->task->expire ? |
| 4632 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4633 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4634 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4635 | task_in_rq(sess->task) ? ", running" : ""); |
| 4636 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4637 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4638 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4639 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4640 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4641 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4642 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4643 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4644 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4645 | |
| 4646 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4647 | " 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] | 4648 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4649 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4650 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4651 | obj_type_name(sess->si[0].end), |
| 4652 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4653 | sess->si[0].exp ? |
| 4654 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4655 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4656 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4657 | sess->si[0].err_type); |
| 4658 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4659 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4660 | " 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] | 4661 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4662 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4663 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4664 | obj_type_name(sess->si[1].end), |
| 4665 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4666 | sess->si[1].exp ? |
| 4667 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4668 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4669 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4670 | sess->si[1].err_type); |
| 4671 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4672 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4673 | chunk_appendf(&trash, |
| 4674 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4675 | conn, |
| 4676 | get_conn_ctrl_name(conn), |
| 4677 | get_conn_xprt_name(conn), |
| 4678 | get_conn_data_name(conn), |
| 4679 | obj_type_name(conn->target), |
| 4680 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4681 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4682 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 4683 | " 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] | 4684 | conn->flags, |
| 4685 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4686 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4687 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4688 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4689 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4690 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 4691 | chunk_appendf(&trash, |
| 4692 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4693 | tmpctx, |
| 4694 | tmpctx->st0, |
| 4695 | tmpctx->st1, |
| 4696 | tmpctx->st2, |
| 4697 | tmpctx->applet->name); |
| 4698 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4699 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4700 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4701 | chunk_appendf(&trash, |
| 4702 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4703 | conn, |
| 4704 | get_conn_ctrl_name(conn), |
| 4705 | get_conn_xprt_name(conn), |
| 4706 | get_conn_data_name(conn), |
| 4707 | obj_type_name(conn->target), |
| 4708 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4709 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4710 | chunk_appendf(&trash, |
| 4711 | " 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] | 4712 | conn->flags, |
| 4713 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4714 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4715 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4716 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4717 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4718 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 4719 | chunk_appendf(&trash, |
| 4720 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4721 | tmpctx, |
| 4722 | tmpctx->st0, |
| 4723 | tmpctx->st1, |
| 4724 | tmpctx->st2, |
| 4725 | tmpctx->applet->name); |
| 4726 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4727 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4728 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4729 | " 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] | 4730 | " an_exp=%s", |
| 4731 | sess->req, |
| 4732 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4733 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4734 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4735 | sess->req->analyse_exp ? |
| 4736 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4737 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4738 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4739 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4740 | " rex=%s", |
| 4741 | sess->req->rex ? |
| 4742 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4743 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4744 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4745 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4746 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4747 | " 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] | 4748 | sess->req->wex ? |
| 4749 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4750 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4751 | sess->req->buf, |
| 4752 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4753 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4754 | sess->txn.req.next, sess->req->buf->i, |
| 4755 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4756 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4757 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4758 | " 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] | 4759 | " an_exp=%s", |
| 4760 | sess->rep, |
| 4761 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4762 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4763 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4764 | sess->rep->analyse_exp ? |
| 4765 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4766 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4767 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4768 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4769 | " rex=%s", |
| 4770 | sess->rep->rex ? |
| 4771 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4772 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4773 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4774 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4775 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4776 | " 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] | 4777 | sess->rep->wex ? |
| 4778 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4779 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4780 | sess->rep->buf, |
| 4781 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4782 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4783 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4784 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4785 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4786 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4787 | return 0; |
| 4788 | |
| 4789 | /* use other states to dump the contents */ |
| 4790 | } |
| 4791 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4792 | appctx->ctx.sess.uid = 0; |
| 4793 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4794 | return 1; |
| 4795 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4796 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4797 | static int stats_maps_list(struct stream_interface *si) |
| 4798 | { |
| 4799 | struct appctx *appctx = __objt_appctx(si->end); |
| 4800 | |
| 4801 | switch (appctx->st2) { |
| 4802 | case STAT_ST_INIT: |
| 4803 | /* Init to the first entry. The list cannot be change */ |
| 4804 | appctx->ctx.map.ref = LIST_NEXT(&maps, struct map_reference *, list); |
| 4805 | appctx->st2 = STAT_ST_LIST; |
| 4806 | /* fall through */ |
| 4807 | |
| 4808 | case STAT_ST_LIST: |
| 4809 | while (appctx->ctx.map.ref) { |
| 4810 | |
| 4811 | chunk_reset(&trash); |
| 4812 | |
| 4813 | /* build messages */ |
| 4814 | chunk_appendf(&trash, "%s\n", appctx->ctx.map.ref->reference); |
| 4815 | |
| 4816 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4817 | /* let's try again later from this session. We add ourselves into |
| 4818 | * this session's users so that it can remove us upon termination. |
| 4819 | */ |
| 4820 | return 0; |
| 4821 | } |
| 4822 | |
| 4823 | /* get next list entry and check the end of the list */ |
| 4824 | appctx->ctx.map.ref = LIST_NEXT(&appctx->ctx.map.ref->list, |
| 4825 | struct map_reference *, list); |
| 4826 | if (&appctx->ctx.map.ref->list == &maps) |
| 4827 | break; |
| 4828 | } |
| 4829 | |
| 4830 | appctx->st2 = STAT_ST_FIN; |
| 4831 | /* fall through */ |
| 4832 | |
| 4833 | default: |
| 4834 | appctx->st2 = STAT_ST_FIN; |
| 4835 | return 1; |
| 4836 | } |
| 4837 | } |
| 4838 | |
| 4839 | static const char *smp_to_type[SMP_TYPES] = { |
| 4840 | [SMP_T_BOOL] = "bool", |
| 4841 | [SMP_T_UINT] = "uint", |
| 4842 | [SMP_T_SINT] = "sint", |
| 4843 | [SMP_T_ADDR] = "addr", |
| 4844 | [SMP_T_IPV4] = "ipv4", |
| 4845 | [SMP_T_IPV6] = "ipv6", |
| 4846 | [SMP_T_STR] = "str", |
| 4847 | [SMP_T_BIN] = "bin", |
| 4848 | [SMP_T_CSTR] = "cstr", |
| 4849 | [SMP_T_CBIN] = "cbin", |
| 4850 | }; |
| 4851 | |
| 4852 | static int stats_map_lookup(struct stream_interface *si) |
| 4853 | { |
| 4854 | struct appctx *appctx = __objt_appctx(si->end); |
| 4855 | struct sample_storage *smp; |
| 4856 | struct sample sample; |
| 4857 | struct pattern *pat; |
| 4858 | struct pat_idx_elt *elt; |
| 4859 | enum pat_match_res res; |
| 4860 | struct sockaddr_in addr; |
Willy Tarreau | b908bef | 2013-12-16 01:42:03 +0100 | [diff] [blame] | 4861 | char addr_str[INET_ADDRSTRLEN]; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4862 | |
| 4863 | switch (appctx->st2) { |
| 4864 | case STAT_ST_INIT: |
| 4865 | appctx->ctx.map.desc = NULL; |
| 4866 | stats_map_lookup_next(si); |
| 4867 | appctx->st2 = STAT_ST_LIST; |
| 4868 | /* fall through */ |
| 4869 | |
| 4870 | case STAT_ST_LIST: |
| 4871 | /* for each lookup type */ |
| 4872 | while (appctx->ctx.map.desc) { |
| 4873 | /* initialise chunk to build new message */ |
| 4874 | chunk_reset(&trash); |
| 4875 | |
| 4876 | /* execute pattern matching */ |
| 4877 | sample.type = SMP_T_CSTR; |
| 4878 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 4879 | sample.data.str.str = appctx->ctx.map.chunk.str; |
| 4880 | pat = NULL; |
| 4881 | elt = NULL; |
| 4882 | res = pattern_exec_match(appctx->ctx.map.desc->pat, &sample, &smp, &pat, &elt); |
| 4883 | |
| 4884 | /* build return message: set type of match */ |
| 4885 | /**/ if (appctx->ctx.map.desc->pat->match == NULL) |
| 4886 | chunk_appendf(&trash, "found, "); |
| 4887 | else if (appctx->ctx.map.desc->pat->match == pat_match_nothing) |
| 4888 | chunk_appendf(&trash, "bool, "); |
| 4889 | else if (appctx->ctx.map.desc->pat->match == pat_match_int) |
| 4890 | chunk_appendf(&trash, "int, "); |
| 4891 | else if (appctx->ctx.map.desc->pat->match == pat_match_ip) |
| 4892 | chunk_appendf(&trash, "ip, "); |
| 4893 | else if (appctx->ctx.map.desc->pat->match == pat_match_bin) |
| 4894 | chunk_appendf(&trash, "bin, "); |
| 4895 | else if (appctx->ctx.map.desc->pat->match == pat_match_len) |
| 4896 | chunk_appendf(&trash, "len, "); |
| 4897 | else if (appctx->ctx.map.desc->pat->match == pat_match_str) |
| 4898 | chunk_appendf(&trash, "str, "); |
| 4899 | else if (appctx->ctx.map.desc->pat->match == pat_match_beg) |
| 4900 | chunk_appendf(&trash, "beg, "); |
| 4901 | else if (appctx->ctx.map.desc->pat->match == pat_match_sub) |
| 4902 | chunk_appendf(&trash, "sub, "); |
| 4903 | else if (appctx->ctx.map.desc->pat->match == pat_match_dir) |
| 4904 | chunk_appendf(&trash, "dir, "); |
| 4905 | else if (appctx->ctx.map.desc->pat->match == pat_match_dom) |
| 4906 | chunk_appendf(&trash, "dom, "); |
| 4907 | else if (appctx->ctx.map.desc->pat->match == pat_match_end) |
| 4908 | chunk_appendf(&trash, "end, "); |
| 4909 | else if (appctx->ctx.map.desc->pat->match == pat_match_reg) |
| 4910 | chunk_appendf(&trash, "reg, "); |
| 4911 | else /* The never appens case */ |
| 4912 | chunk_appendf(&trash, "unknown(%p), ", appctx->ctx.map.desc->pat->match); |
| 4913 | |
| 4914 | /* Display no match, and set default value */ |
| 4915 | if (res == PAT_NOMATCH) { |
| 4916 | chunk_appendf(&trash, "no-match, "); |
| 4917 | smp = appctx->ctx.map.desc->def; |
| 4918 | } |
| 4919 | |
| 4920 | /* Display match and match info */ |
| 4921 | else { |
| 4922 | /* display match */ |
| 4923 | chunk_appendf(&trash, "match, "); |
| 4924 | |
| 4925 | /* display search mode */ |
| 4926 | if (elt) |
| 4927 | chunk_appendf(&trash, "tree, "); |
| 4928 | else |
| 4929 | chunk_appendf(&trash, "list, "); |
| 4930 | |
| 4931 | /* display search options */ |
| 4932 | if (pat) { |
| 4933 | /* case sensitive */ |
| 4934 | if (pat->flags & PAT_F_IGNORE_CASE) |
| 4935 | chunk_appendf(&trash, "case-insensitive, "); |
| 4936 | else |
| 4937 | chunk_appendf(&trash, "case-sensitive, "); |
| 4938 | |
| 4939 | /* display source */ |
| 4940 | if (pat->flags & PAT_F_FROM_FILE) |
| 4941 | chunk_appendf(&trash, "from-file, "); |
| 4942 | } |
| 4943 | |
| 4944 | /* display match expresion */ |
| 4945 | if (elt) { |
| 4946 | if (appctx->ctx.map.desc->pat->match == pat_match_str) { |
| 4947 | chunk_appendf(&trash, "match=\"%s\", ", elt->node.key); |
| 4948 | } |
| 4949 | /* only IPv4 */ |
| 4950 | else if (appctx->ctx.map.desc->pat->match == pat_match_ip) { |
| 4951 | /* convert ip */ |
| 4952 | memcpy(&addr.sin_addr, elt->node.key, 4); |
| 4953 | addr.sin_family = AF_INET; |
Willy Tarreau | b908bef | 2013-12-16 01:42:03 +0100 | [diff] [blame] | 4954 | if (addr_to_str((struct sockaddr_storage *)&addr, addr_str, INET_ADDRSTRLEN)) |
| 4955 | chunk_appendf(&trash, "match=\"%s/%d\", ", addr_str, elt->node.node.pfx); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4956 | } |
| 4957 | } |
| 4958 | } |
| 4959 | |
| 4960 | /* display return value */ |
| 4961 | if (!smp) { |
| 4962 | chunk_appendf(&trash, "return=nothing\n"); |
| 4963 | } |
| 4964 | else { |
| 4965 | memcpy(&sample.data, &smp->data, sizeof(sample.data)); |
| 4966 | sample.type = smp->type; |
| 4967 | if (sample_casts[sample.type][SMP_T_CSTR] && |
| 4968 | sample_casts[sample.type][SMP_T_CSTR](&sample)) |
| 4969 | chunk_appendf(&trash, "return=\"%s\", type=\"%s\"\n", |
| 4970 | sample.data.str.str, smp_to_type[smp->type]); |
| 4971 | else |
| 4972 | chunk_appendf(&trash, "return=cannot-display, type=\"%s\"\n", |
| 4973 | smp_to_type[smp->type]); |
| 4974 | } |
| 4975 | |
| 4976 | /* display response */ |
| 4977 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4978 | /* let's try again later from this session. We add ourselves into |
| 4979 | * this session's users so that it can remove us upon termination. |
| 4980 | */ |
| 4981 | return 0; |
| 4982 | } |
| 4983 | |
| 4984 | /* get next entry */ |
| 4985 | stats_map_lookup_next(si); |
| 4986 | } |
| 4987 | |
| 4988 | appctx->st2 = STAT_ST_FIN; |
| 4989 | /* fall through */ |
| 4990 | |
| 4991 | default: |
| 4992 | appctx->st2 = STAT_ST_FIN; |
| 4993 | free(appctx->ctx.map.chunk.str); |
| 4994 | return 1; |
| 4995 | } |
| 4996 | } |
| 4997 | |
| 4998 | static int stats_map_list(struct stream_interface *si) |
| 4999 | { |
| 5000 | struct appctx *appctx = __objt_appctx(si->end); |
| 5001 | |
| 5002 | switch (appctx->st2) { |
| 5003 | |
| 5004 | case STAT_ST_INIT: |
| 5005 | /* Init to the first entry. The list cannot be change */ |
| 5006 | appctx->ctx.map.ent = LIST_NEXT(&appctx->ctx.map.ref->entries, |
| 5007 | struct map_entry *, list); |
| 5008 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) |
| 5009 | appctx->ctx.map.ent = NULL; |
| 5010 | appctx->st2 = STAT_ST_LIST; |
| 5011 | /* fall through */ |
| 5012 | |
| 5013 | case STAT_ST_LIST: |
| 5014 | while (appctx->ctx.map.ent) { |
| 5015 | chunk_reset(&trash); |
| 5016 | |
| 5017 | /* build messages */ |
| 5018 | chunk_appendf(&trash, "%s %s\n", appctx->ctx.map.ent->key, appctx->ctx.map.ent->value); |
| 5019 | |
| 5020 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5021 | /* let's try again later from this session. We add ourselves into |
| 5022 | * this session's users so that it can remove us upon termination. |
| 5023 | */ |
| 5024 | return 0; |
| 5025 | } |
| 5026 | |
| 5027 | /* get next list entry and check the end of the list */ |
| 5028 | appctx->ctx.map.ent = LIST_NEXT(&appctx->ctx.map.ent->list, |
| 5029 | struct map_entry *, list); |
| 5030 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) |
| 5031 | break; |
| 5032 | } |
| 5033 | |
| 5034 | appctx->st2 = STAT_ST_FIN; |
| 5035 | /* fall through */ |
| 5036 | |
| 5037 | default: |
| 5038 | appctx->st2 = STAT_ST_FIN; |
| 5039 | return 1; |
| 5040 | } |
| 5041 | } |
| 5042 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5043 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5044 | * 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] | 5045 | * to be called again, otherwise non-zero. It is designed to be called |
| 5046 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5047 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5048 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5049 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5050 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5051 | struct connection *conn; |
| 5052 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5053 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5054 | /* If we're forced to shut down, we might have to remove our |
| 5055 | * reference to the last session being dumped. |
| 5056 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5057 | if (appctx->st2 == STAT_ST_LIST) { |
| 5058 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5059 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5060 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5061 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5062 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5063 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5064 | } |
| 5065 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5066 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5067 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5068 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5069 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5070 | /* the function had not been called yet, let's prepare the |
| 5071 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5072 | * pointer to the first in the global list. When a target |
| 5073 | * session is being destroyed, it is responsible for updating |
| 5074 | * this pointer. We know we have reached the end when this |
| 5075 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5076 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5077 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5078 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5079 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5080 | /* fall through */ |
| 5081 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5082 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5083 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5084 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5085 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5086 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5087 | } |
| 5088 | |
| 5089 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5090 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5091 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5092 | struct session *curr_sess; |
| 5093 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5094 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5095 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5096 | if (appctx->ctx.sess.target) { |
| 5097 | 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] | 5098 | goto next_sess; |
| 5099 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5100 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5101 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5102 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5103 | return 0; |
| 5104 | |
| 5105 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5106 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5107 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5108 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5109 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5110 | break; |
| 5111 | } |
| 5112 | else |
| 5113 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5114 | } |
| 5115 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5116 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5117 | "%p: proto=%s", |
| 5118 | curr_sess, |
| 5119 | curr_sess->listener->proto->name); |
| 5120 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5121 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5122 | conn = objt_conn(curr_sess->si[0].end); |
| 5123 | 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] | 5124 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5125 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5126 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5127 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5128 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5129 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5130 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5131 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5132 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5133 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5134 | break; |
| 5135 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5136 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5137 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5138 | curr_sess->listener->luid, |
| 5139 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5140 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5141 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5142 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5143 | break; |
| 5144 | } |
| 5145 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5146 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5147 | " ts=%02x age=%s calls=%d", |
| 5148 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5149 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5150 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5151 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5152 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5153 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5154 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5155 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5156 | curr_sess->req->analysers, |
| 5157 | curr_sess->req->rex ? |
| 5158 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 5159 | TICKS_TO_MS(1000)) : ""); |
| 5160 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5161 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5162 | ",wx=%s", |
| 5163 | curr_sess->req->wex ? |
| 5164 | human_time(TICKS_TO_MS(curr_sess->req->wex - 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 | ",ax=%s]", |
| 5169 | curr_sess->req->analyse_exp ? |
| 5170 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - 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 | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5174 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5175 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5176 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5177 | curr_sess->rep->analysers, |
| 5178 | curr_sess->rep->rex ? |
| 5179 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5180 | TICKS_TO_MS(1000)) : ""); |
| 5181 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5182 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5183 | ",wx=%s", |
| 5184 | curr_sess->rep->wex ? |
| 5185 | human_time(TICKS_TO_MS(curr_sess->rep->wex - 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 | ",ax=%s]", |
| 5190 | curr_sess->rep->analyse_exp ? |
| 5191 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5192 | TICKS_TO_MS(1000)) : ""); |
| 5193 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5194 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5195 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5196 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5197 | curr_sess->si[0].state, |
| 5198 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5199 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5200 | curr_sess->si[0].exp ? |
| 5201 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5202 | TICKS_TO_MS(1000)) : ""); |
| 5203 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5204 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5205 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5206 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5207 | curr_sess->si[1].state, |
| 5208 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5209 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5210 | curr_sess->si[1].exp ? |
| 5211 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5212 | TICKS_TO_MS(1000)) : ""); |
| 5213 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5214 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5215 | " exp=%s", |
| 5216 | curr_sess->task->expire ? |
| 5217 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5218 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5219 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5220 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5221 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5222 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5223 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5224 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5225 | /* let's try again later from this session. We add ourselves into |
| 5226 | * this session's users so that it can remove us upon termination. |
| 5227 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5228 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5229 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5230 | } |
| 5231 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5232 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5233 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5234 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5235 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5236 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5237 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5238 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5239 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5240 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5241 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5242 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5243 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5244 | return 0; |
| 5245 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5246 | appctx->ctx.sess.target = NULL; |
| 5247 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5248 | return 1; |
| 5249 | } |
| 5250 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5251 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5252 | /* fall through */ |
| 5253 | |
| 5254 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5255 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5256 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5257 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5258 | } |
| 5259 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5260 | /* This is called when the stream interface is closed. For instance, upon an |
| 5261 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5262 | * remove back references to the session currently being dumped. |
| 5263 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5264 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5265 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5266 | struct appctx *appctx = __objt_appctx(si->end); |
| 5267 | |
| 5268 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5269 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5270 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5271 | } |
| 5272 | } |
| 5273 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5274 | /* This function is used to either dump tables states (when action is set |
| 5275 | * 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] | 5276 | * It returns 0 if the output buffer is full and it needs to be called |
| 5277 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5278 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5279 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5280 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5281 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5282 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5283 | struct ebmb_node *eb; |
| 5284 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5285 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5286 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5287 | |
| 5288 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5289 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5290 | * - STAT_ST_INIT : the first call |
| 5291 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5292 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5293 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5294 | * and the entry pointer points to the next entry to be dumped, |
| 5295 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5296 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5297 | * data though. |
| 5298 | */ |
| 5299 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5300 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5301 | /* 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] | 5302 | if (appctx->st2 == STAT_ST_LIST) { |
| 5303 | appctx->ctx.table.entry->ref_cnt--; |
| 5304 | 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] | 5305 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5306 | return 1; |
| 5307 | } |
| 5308 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5309 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5310 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5311 | while (appctx->st2 != STAT_ST_FIN) { |
| 5312 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5313 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5314 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5315 | if (!appctx->ctx.table.proxy) |
| 5316 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5317 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5318 | appctx->ctx.table.entry = NULL; |
| 5319 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5320 | break; |
| 5321 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5322 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5323 | if (!appctx->ctx.table.proxy || |
| 5324 | (appctx->ctx.table.target && |
| 5325 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5326 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5327 | break; |
| 5328 | } |
| 5329 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5330 | if (appctx->ctx.table.proxy->table.size) { |
| 5331 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5332 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5333 | return 0; |
| 5334 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5335 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5336 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5337 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5338 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5339 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5340 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5341 | appctx->ctx.table.entry->ref_cnt++; |
| 5342 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5343 | break; |
| 5344 | } |
| 5345 | } |
| 5346 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5347 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5348 | break; |
| 5349 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5350 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5351 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5352 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5353 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5354 | /* we're filtering on some data contents */ |
| 5355 | void *ptr; |
| 5356 | long long data; |
| 5357 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5358 | dt = appctx->ctx.table.data_type; |
| 5359 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5360 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5361 | dt); |
| 5362 | |
| 5363 | data = 0; |
| 5364 | switch (stktable_data_types[dt].std_type) { |
| 5365 | case STD_T_SINT: |
| 5366 | data = stktable_data_cast(ptr, std_t_sint); |
| 5367 | break; |
| 5368 | case STD_T_UINT: |
| 5369 | data = stktable_data_cast(ptr, std_t_uint); |
| 5370 | break; |
| 5371 | case STD_T_ULL: |
| 5372 | data = stktable_data_cast(ptr, std_t_ull); |
| 5373 | break; |
| 5374 | case STD_T_FRQP: |
| 5375 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5376 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5377 | break; |
| 5378 | } |
| 5379 | |
| 5380 | /* 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] | 5381 | if ((data < appctx->ctx.table.value && |
| 5382 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5383 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5384 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5385 | (data == appctx->ctx.table.value && |
| 5386 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5387 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5388 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5389 | (data > appctx->ctx.table.value && |
| 5390 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5391 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5392 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5393 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5394 | } |
| 5395 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5396 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5397 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5398 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5399 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5400 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5401 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5402 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5403 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5404 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5405 | struct stksess *old = appctx->ctx.table.entry; |
| 5406 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5407 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5408 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5409 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5410 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5411 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5412 | break; |
| 5413 | } |
| 5414 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5415 | |
| 5416 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5417 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5418 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5419 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5420 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5421 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5422 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5423 | break; |
| 5424 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5425 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5426 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5427 | break; |
| 5428 | } |
| 5429 | } |
| 5430 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5431 | } |
| 5432 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5433 | /* 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] | 5434 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5435 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5436 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5437 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5438 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5439 | * after the offset. The new pointer is returned. |
| 5440 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5441 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5442 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5443 | { |
| 5444 | int end; |
| 5445 | unsigned char c; |
| 5446 | |
| 5447 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5448 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5449 | return ptr; |
| 5450 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5451 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5452 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5453 | while (ptr < len && ptr < bsize) { |
| 5454 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5455 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5456 | if (out->len > end - 2) |
| 5457 | break; |
| 5458 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5459 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5460 | if (out->len > end - 3) |
| 5461 | break; |
| 5462 | out->str[out->len++] = '\\'; |
| 5463 | switch (c) { |
| 5464 | case '\t': c = 't'; break; |
| 5465 | case '\n': c = 'n'; break; |
| 5466 | case '\r': c = 'r'; break; |
| 5467 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5468 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5469 | } |
| 5470 | out->str[out->len++] = c; |
| 5471 | } else { |
| 5472 | if (out->len > end - 5) |
| 5473 | break; |
| 5474 | out->str[out->len++] = '\\'; |
| 5475 | out->str[out->len++] = 'x'; |
| 5476 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5477 | out->str[out->len++] = hextab[c & 0xF]; |
| 5478 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5479 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5480 | /* we had a line break, let's return now */ |
| 5481 | out->str[out->len++] = '\n'; |
| 5482 | *line = ptr; |
| 5483 | return ptr; |
| 5484 | } |
| 5485 | } |
| 5486 | /* we have an incomplete line, we return it as-is */ |
| 5487 | out->str[out->len++] = '\n'; |
| 5488 | return ptr; |
| 5489 | } |
| 5490 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5491 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5492 | * 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] | 5493 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5494 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5495 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5496 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5497 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5498 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5499 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5500 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5501 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5502 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5503 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5504 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5505 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5506 | /* the function had not been called yet, let's prepare the |
| 5507 | * buffer for a response. |
| 5508 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5509 | struct tm tm; |
| 5510 | |
| 5511 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5512 | 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] | 5513 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5514 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5515 | error_snapshot_id); |
| 5516 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5517 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5518 | /* Socket buffer full. Let's try again later from the same point */ |
| 5519 | return 0; |
| 5520 | } |
| 5521 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5522 | appctx->ctx.errors.px = proxy; |
| 5523 | appctx->ctx.errors.buf = 0; |
| 5524 | appctx->ctx.errors.bol = 0; |
| 5525 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5526 | } |
| 5527 | |
| 5528 | /* we have two inner loops here, one for the proxy, the other one for |
| 5529 | * the buffer. |
| 5530 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5531 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5532 | struct error_snapshot *es; |
| 5533 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5534 | if (appctx->ctx.errors.buf == 0) |
| 5535 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5536 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5537 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5538 | |
| 5539 | if (!es->when.tv_sec) |
| 5540 | goto next; |
| 5541 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5542 | if (appctx->ctx.errors.iid >= 0 && |
| 5543 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 5544 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5545 | goto next; |
| 5546 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5547 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5548 | /* just print headers now */ |
| 5549 | |
| 5550 | char pn[INET6_ADDRSTRLEN]; |
| 5551 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5552 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5553 | |
| 5554 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5555 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5556 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5557 | 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] | 5558 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5559 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 5560 | case AF_INET: |
| 5561 | case AF_INET6: |
| 5562 | port = get_host_port(&es->src); |
| 5563 | break; |
| 5564 | default: |
| 5565 | port = 0; |
| 5566 | } |
| 5567 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5568 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5569 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5570 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5571 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5572 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5573 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5574 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 5575 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5576 | break; |
| 5577 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5578 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5579 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5580 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5581 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5582 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5583 | break; |
| 5584 | } |
| 5585 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5586 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5587 | ", server %s (#%d), event #%u\n" |
| 5588 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 5589 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 5590 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 5591 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 5592 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 5593 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 5594 | es->ev_id, |
| 5595 | pn, port, es->sid, es->s_flags, |
| 5596 | es->state, es->m_flags, es->t_flags, |
| 5597 | es->m_clen, es->m_blen, |
| 5598 | es->b_flags, es->b_out, es->b_tot, |
| 5599 | es->len, es->b_wrap, es->pos); |
| 5600 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5601 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5602 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5603 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5604 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5605 | appctx->ctx.errors.ptr = 0; |
| 5606 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5607 | } |
| 5608 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5609 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5610 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5611 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5612 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5613 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5614 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5615 | goto next; |
| 5616 | } |
| 5617 | |
| 5618 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5619 | 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] | 5620 | int newptr; |
| 5621 | int newline; |
| 5622 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5623 | newline = appctx->ctx.errors.bol; |
| 5624 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 5625 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5626 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5627 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5628 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5629 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5630 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5631 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5632 | appctx->ctx.errors.ptr = newptr; |
| 5633 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5634 | }; |
| 5635 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5636 | appctx->ctx.errors.bol = 0; |
| 5637 | appctx->ctx.errors.ptr = -1; |
| 5638 | appctx->ctx.errors.buf++; |
| 5639 | if (appctx->ctx.errors.buf > 1) { |
| 5640 | appctx->ctx.errors.buf = 0; |
| 5641 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5642 | } |
| 5643 | } |
| 5644 | |
| 5645 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5646 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5647 | } |
| 5648 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5649 | /* parse the "level" argument on the bind lines */ |
| 5650 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 5651 | { |
| 5652 | if (!*args[cur_arg + 1]) { |
| 5653 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 5654 | return ERR_ALERT | ERR_FATAL; |
| 5655 | } |
| 5656 | |
| 5657 | if (!strcmp(args[cur_arg+1], "user")) |
| 5658 | conf->level = ACCESS_LVL_USER; |
| 5659 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 5660 | conf->level = ACCESS_LVL_OPER; |
| 5661 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 5662 | conf->level = ACCESS_LVL_ADMIN; |
| 5663 | else { |
| 5664 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 5665 | args[cur_arg], args[cur_arg+1]); |
| 5666 | return ERR_ALERT | ERR_FATAL; |
| 5667 | } |
| 5668 | |
| 5669 | return 0; |
| 5670 | } |
| 5671 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5672 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5673 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5674 | .name = "<STATS>", /* used for logging */ |
| 5675 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 5676 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5677 | }; |
| 5678 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5679 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5680 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5681 | .name = "<CLI>", /* used for logging */ |
| 5682 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5683 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5684 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5685 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 5686 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5687 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 5688 | { 0, NULL, NULL }, |
| 5689 | }}; |
| 5690 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5691 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 5692 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 5693 | { NULL, NULL, 0 }, |
| 5694 | }}; |
| 5695 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5696 | __attribute__((constructor)) |
| 5697 | static void __dumpstats_module_init(void) |
| 5698 | { |
| 5699 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5700 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5701 | } |
| 5702 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5703 | /* |
| 5704 | * Local variables: |
| 5705 | * c-indent-level: 8 |
| 5706 | * c-basic-offset: 8 |
| 5707 | * End: |
| 5708 | */ |