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. |
| 430 | */ |
| 431 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 432 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 433 | chunk_appendf(&trash, |
| 434 | "# pxname,svname," |
| 435 | "qcur,qmax," |
| 436 | "scur,smax,slim,stot," |
| 437 | "bin,bout," |
| 438 | "dreq,dresp," |
| 439 | "ereq,econ,eresp," |
| 440 | "wretr,wredis," |
| 441 | "status,weight,act,bck," |
| 442 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 443 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 444 | "rate,rate_lim,rate_max," |
| 445 | "check_status,check_code,check_duration," |
| 446 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 447 | "req_rate,req_rate_max,req_tot," |
| 448 | "cli_abrt,srv_abrt," |
| 449 | "comp_in,comp_out,comp_byp,comp_rsp," |
| 450 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 451 | } |
| 452 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 453 | /* print a string of text buffer to <out>. The format is : |
| 454 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 455 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 456 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 457 | */ |
| 458 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 459 | { |
| 460 | unsigned char c; |
| 461 | int ptr = 0; |
| 462 | |
| 463 | while (buf[ptr] && ptr < bsize) { |
| 464 | c = buf[ptr]; |
| 465 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 466 | if (out->len > out->size - 1) |
| 467 | break; |
| 468 | out->str[out->len++] = c; |
| 469 | } |
| 470 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 471 | if (out->len > out->size - 2) |
| 472 | break; |
| 473 | out->str[out->len++] = '\\'; |
| 474 | switch (c) { |
| 475 | case ' ': c = ' '; break; |
| 476 | case '\t': c = 't'; break; |
| 477 | case '\n': c = 'n'; break; |
| 478 | case '\r': c = 'r'; break; |
| 479 | case '\e': c = 'e'; break; |
| 480 | case '\\': c = '\\'; break; |
| 481 | } |
| 482 | out->str[out->len++] = c; |
| 483 | } |
| 484 | else { |
| 485 | if (out->len > out->size - 4) |
| 486 | break; |
| 487 | out->str[out->len++] = '\\'; |
| 488 | out->str[out->len++] = 'x'; |
| 489 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 490 | out->str[out->len++] = hextab[c & 0xF]; |
| 491 | } |
| 492 | ptr++; |
| 493 | } |
| 494 | |
| 495 | return ptr; |
| 496 | } |
| 497 | |
| 498 | /* print a buffer in hexa. |
| 499 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 500 | */ |
| 501 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 502 | { |
| 503 | unsigned char c; |
| 504 | int ptr = 0; |
| 505 | |
| 506 | while (ptr < bsize) { |
| 507 | c = buf[ptr]; |
| 508 | |
| 509 | if (out->len > out->size - 2) |
| 510 | break; |
| 511 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 512 | out->str[out->len++] = hextab[c & 0xF]; |
| 513 | |
| 514 | ptr++; |
| 515 | } |
| 516 | return ptr; |
| 517 | } |
| 518 | |
| 519 | /* Dump the status of a table to a stream interface's |
| 520 | * read buffer. It returns 0 if the output buffer is full |
| 521 | * and needs to be called again, otherwise non-zero. |
| 522 | */ |
| 523 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 524 | struct proxy *proxy, struct proxy *target) |
| 525 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 526 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 527 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 528 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 529 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 530 | |
| 531 | /* any other information should be dumped here */ |
| 532 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 533 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 534 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 535 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 536 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 537 | return 0; |
| 538 | |
| 539 | return 1; |
| 540 | } |
| 541 | |
| 542 | /* Dump the a table entry to a stream interface's |
| 543 | * read buffer. It returns 0 if the output buffer is full |
| 544 | * and needs to be called again, otherwise non-zero. |
| 545 | */ |
| 546 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 547 | struct proxy *proxy, struct stksess *entry) |
| 548 | { |
| 549 | int dt; |
| 550 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 551 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 552 | |
| 553 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 554 | char addr[INET_ADDRSTRLEN]; |
| 555 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 556 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 557 | } |
| 558 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 559 | char addr[INET6_ADDRSTRLEN]; |
| 560 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 561 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 562 | } |
| 563 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 564 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 565 | } |
| 566 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 567 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 568 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 569 | } |
| 570 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 571 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 572 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 573 | } |
| 574 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 575 | 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] | 576 | |
| 577 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 578 | void *ptr; |
| 579 | |
| 580 | if (proxy->table.data_ofs[dt] == 0) |
| 581 | continue; |
| 582 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 583 | 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] | 584 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 585 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 586 | |
| 587 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 588 | switch (stktable_data_types[dt].std_type) { |
| 589 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 590 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 591 | break; |
| 592 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 593 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 594 | break; |
| 595 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 596 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 597 | break; |
| 598 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 599 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 600 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 601 | proxy->table.data_arg[dt].u)); |
| 602 | break; |
| 603 | } |
| 604 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 605 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 606 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 607 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 608 | return 0; |
| 609 | |
| 610 | return 1; |
| 611 | } |
| 612 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 613 | 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] | 614 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 615 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 616 | struct appctx *appctx = __objt_appctx(si->end); |
| 617 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 618 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 619 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 620 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 621 | long long value; |
| 622 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 623 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 624 | void *ptr; |
| 625 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 626 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 627 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 628 | |
| 629 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 630 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 631 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 632 | return; |
| 633 | } |
| 634 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 635 | switch (px->table.type) { |
| 636 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 637 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 638 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 639 | break; |
| 640 | case STKTABLE_TYPE_IPV6: |
| 641 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 642 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 643 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 644 | case STKTABLE_TYPE_INTEGER: |
| 645 | { |
| 646 | char *endptr; |
| 647 | unsigned long val; |
| 648 | errno = 0; |
| 649 | val = strtoul(args[4], &endptr, 10); |
| 650 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 651 | (errno != 0 && val == 0) || endptr == args[4] || |
| 652 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 653 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 654 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 655 | return; |
| 656 | } |
| 657 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 658 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 659 | break; |
| 660 | } |
| 661 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 662 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 663 | static_table_key->key = args[4]; |
| 664 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 665 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 666 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 667 | switch (action) { |
| 668 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 669 | 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] | 670 | break; |
| 671 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 672 | 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] | 673 | break; |
| 674 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 675 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 676 | break; |
| 677 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 678 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 679 | return; |
| 680 | } |
| 681 | |
| 682 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 683 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 684 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 685 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 686 | return; |
| 687 | } |
| 688 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 689 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 690 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 691 | switch (action) { |
| 692 | case STAT_CLI_O_TAB: |
| 693 | if (!ts) |
| 694 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 695 | chunk_reset(&trash); |
| 696 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 697 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 698 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 699 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 700 | |
| 701 | case STAT_CLI_O_CLR: |
| 702 | if (!ts) |
| 703 | return; |
| 704 | if (ts->ref_cnt) { |
| 705 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 706 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 707 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 708 | return; |
| 709 | } |
| 710 | stksess_kill(&px->table, ts); |
| 711 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 712 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 713 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 714 | if (ts) |
| 715 | stktable_touch(&px->table, ts, 1); |
| 716 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 717 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 718 | if (!ts) { |
| 719 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 720 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 721 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 722 | return; |
| 723 | } |
| 724 | stktable_store(&px->table, ts, 1); |
| 725 | } |
| 726 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 727 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 728 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 729 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 730 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 731 | return; |
| 732 | } |
| 733 | |
| 734 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 735 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 736 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 737 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 738 | return; |
| 739 | } |
| 740 | |
| 741 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 742 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 743 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 744 | return; |
| 745 | } |
| 746 | |
| 747 | 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] | 748 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 749 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 750 | return; |
| 751 | } |
| 752 | |
| 753 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 754 | |
| 755 | switch (stktable_data_types[data_type].std_type) { |
| 756 | case STD_T_SINT: |
| 757 | stktable_data_cast(ptr, std_t_sint) = value; |
| 758 | break; |
| 759 | case STD_T_UINT: |
| 760 | stktable_data_cast(ptr, std_t_uint) = value; |
| 761 | break; |
| 762 | case STD_T_ULL: |
| 763 | stktable_data_cast(ptr, std_t_ull) = value; |
| 764 | break; |
| 765 | case STD_T_FRQP: |
| 766 | /* We set both the current and previous values. That way |
| 767 | * the reported frequency is stable during all the period |
| 768 | * then slowly fades out. This allows external tools to |
| 769 | * push measures without having to update them too often. |
| 770 | */ |
| 771 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 772 | frqp->curr_tick = now_ms; |
| 773 | frqp->prev_ctr = 0; |
| 774 | frqp->curr_ctr = value; |
| 775 | break; |
| 776 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 777 | } |
| 778 | break; |
| 779 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 780 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 781 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 782 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 783 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 784 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 785 | } |
| 786 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 787 | 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] | 788 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 789 | struct appctx *appctx = __objt_appctx(si->end); |
| 790 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 791 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 792 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 793 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 794 | return; |
| 795 | } |
| 796 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 797 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 798 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 799 | if (appctx->ctx.table.data_type < 0) { |
| 800 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 801 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 802 | return; |
| 803 | } |
| 804 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 805 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 806 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 807 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 808 | return; |
| 809 | } |
| 810 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 811 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 812 | if (appctx->ctx.table.data_op < 0) { |
| 813 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 814 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 815 | return; |
| 816 | } |
| 817 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 818 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 819 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 820 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 821 | return; |
| 822 | } |
| 823 | } |
| 824 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 825 | 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] | 826 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 827 | struct appctx *appctx = __objt_appctx(si->end); |
| 828 | |
| 829 | appctx->ctx.table.data_type = -1; |
| 830 | appctx->st2 = STAT_ST_INIT; |
| 831 | appctx->ctx.table.target = NULL; |
| 832 | appctx->ctx.table.proxy = NULL; |
| 833 | appctx->ctx.table.entry = NULL; |
| 834 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 835 | |
| 836 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 837 | appctx->ctx.table.target = find_stktable(args[2]); |
| 838 | if (!appctx->ctx.table.target) { |
| 839 | appctx->ctx.cli.msg = "No such table\n"; |
| 840 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 841 | return; |
| 842 | } |
| 843 | } |
| 844 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 845 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 846 | goto err_args; |
| 847 | return; |
| 848 | } |
| 849 | |
| 850 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 851 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 852 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 853 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 854 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 855 | goto err_args; |
| 856 | |
| 857 | return; |
| 858 | |
| 859 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 860 | switch (action) { |
| 861 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 862 | 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] | 863 | break; |
| 864 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 865 | 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] | 866 | break; |
| 867 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 868 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 869 | break; |
| 870 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 871 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 872 | } |
| 873 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 874 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 875 | * adequate error messages and returns NULL. This function also expects the session |
| 876 | * level to be admin. |
| 877 | */ |
| 878 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 879 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 880 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 881 | struct proxy *px; |
| 882 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 883 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 884 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 885 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 886 | return NULL; |
| 887 | } |
| 888 | |
| 889 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 890 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 891 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 892 | return NULL; |
| 893 | } |
| 894 | |
| 895 | px = findproxy(arg, PR_CAP_FE); |
| 896 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 897 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 898 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 899 | return NULL; |
| 900 | } |
| 901 | return px; |
| 902 | } |
| 903 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 904 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 905 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 906 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 907 | * the <arg> is modified to remove the '/'. |
| 908 | */ |
| 909 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 910 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 911 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 912 | struct proxy *px; |
| 913 | struct server *sv; |
| 914 | char *line; |
| 915 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 916 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 917 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 918 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 919 | return NULL; |
| 920 | } |
| 921 | |
| 922 | /* split "backend/server" and make <line> point to server */ |
| 923 | for (line = arg; *line; line++) |
| 924 | if (*line == '/') { |
| 925 | *line++ = '\0'; |
| 926 | break; |
| 927 | } |
| 928 | |
| 929 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 930 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 931 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 932 | return NULL; |
| 933 | } |
| 934 | |
| 935 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 936 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 937 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 938 | return NULL; |
| 939 | } |
| 940 | |
| 941 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 942 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 943 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 944 | return NULL; |
| 945 | } |
| 946 | |
| 947 | return sv; |
| 948 | } |
| 949 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 950 | /* This function is used with map management. It permits to browse each |
| 951 | * really allocated descriptors of one map reference. The variable |
| 952 | * <appctx->ctx.map.ref> must contain the map reference to browse. |
| 953 | * The variable <appctx->ctx.map.desc> contain the descriptor of the |
| 954 | * current allocated map descriptor. This variable must be initialized |
| 955 | * to NULL. |
| 956 | */ |
| 957 | static inline void stats_map_lookup_next(struct stream_interface *si) |
| 958 | { |
| 959 | struct appctx *appctx = __objt_appctx(si->end); |
| 960 | |
| 961 | /* search the next allocated map */ |
| 962 | while (1) { |
| 963 | /* get next descriptor */ |
| 964 | if (!appctx->ctx.map.desc) |
| 965 | appctx->ctx.map.desc = LIST_NEXT(&appctx->ctx.map.ref->maps, |
| 966 | struct map_descriptor *, list); |
| 967 | else |
| 968 | appctx->ctx.map.desc = LIST_NEXT(&appctx->ctx.map.desc->list, |
| 969 | struct map_descriptor *, list); |
| 970 | |
| 971 | /* detect end of list */ |
| 972 | if (&appctx->ctx.map.desc->list == &appctx->ctx.map.ref->maps) { |
| 973 | appctx->ctx.map.desc = NULL; |
| 974 | return; |
| 975 | } |
| 976 | |
| 977 | /* do not lookup this entry */ |
| 978 | if (!appctx->ctx.map.desc->do_free) |
| 979 | continue; |
| 980 | |
| 981 | /* avalaible descriptor */ |
| 982 | return; |
| 983 | } |
| 984 | } |
| 985 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 986 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 987 | * 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] | 988 | * 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] | 989 | * designating the function which will have to process the request, which can |
| 990 | * 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] | 991 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 992 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 993 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 994 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 995 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 996 | char *args[MAX_STATS_ARGS + 1]; |
| 997 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 998 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 999 | |
| 1000 | while (isspace((unsigned char)*line)) |
| 1001 | line++; |
| 1002 | |
| 1003 | arg = 0; |
| 1004 | args[arg] = line; |
| 1005 | |
| 1006 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1007 | if (*line == '\\') { |
| 1008 | line++; |
| 1009 | if (*line == '\0') |
| 1010 | break; |
| 1011 | } |
| 1012 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1013 | *line++ = '\0'; |
| 1014 | |
| 1015 | while (isspace((unsigned char)*line)) |
| 1016 | line++; |
| 1017 | |
| 1018 | args[++arg] = line; |
| 1019 | continue; |
| 1020 | } |
| 1021 | |
| 1022 | line++; |
| 1023 | } |
| 1024 | |
| 1025 | while (++arg <= MAX_STATS_ARGS) |
| 1026 | args[arg] = line; |
| 1027 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1028 | /* remove \ */ |
| 1029 | arg = 0; |
| 1030 | while (*args[arg] != '\0') { |
| 1031 | j = 0; |
| 1032 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1033 | if (args[arg][i] == '\\') |
| 1034 | continue; |
| 1035 | args[arg][j] = args[arg][i]; |
| 1036 | j++; |
| 1037 | } |
| 1038 | args[arg][j] = '\0'; |
| 1039 | arg++; |
| 1040 | } |
| 1041 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1042 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1043 | if (strcmp(args[0], "show") == 0) { |
| 1044 | if (strcmp(args[1], "stat") == 0) { |
| 1045 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1046 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1047 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1048 | appctx->ctx.stats.type = atoi(args[3]); |
| 1049 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1050 | } |
| 1051 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1052 | appctx->st2 = STAT_ST_INIT; |
| 1053 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1054 | } |
| 1055 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1056 | appctx->st2 = STAT_ST_INIT; |
| 1057 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1058 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1059 | else if (strcmp(args[1], "pools") == 0) { |
| 1060 | appctx->st2 = STAT_ST_INIT; |
| 1061 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1062 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1063 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1064 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1065 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1066 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1067 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1068 | return 1; |
| 1069 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1070 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1071 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1072 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1073 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1074 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1075 | appctx->ctx.sess.target = NULL; |
| 1076 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1077 | appctx->ctx.sess.pos = 0; |
| 1078 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1079 | } |
| 1080 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1081 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1082 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1083 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1084 | return 1; |
| 1085 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1086 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1087 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1088 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1089 | appctx->ctx.errors.iid = -1; |
| 1090 | appctx->ctx.errors.px = NULL; |
| 1091 | appctx->st2 = STAT_ST_INIT; |
| 1092 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1093 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1094 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1095 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1096 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1097 | else if (strcmp(args[1], "map") == 0) { |
| 1098 | |
| 1099 | /* no parameter: display all map avalaible */ |
| 1100 | if (!*args[2]) { |
| 1101 | appctx->st2 = STAT_ST_INIT; |
| 1102 | appctx->st0 = STAT_CLI_O_MAPS; |
| 1103 | return 1; |
| 1104 | } |
| 1105 | |
| 1106 | /* lookup into the maps */ |
| 1107 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1108 | if (!appctx->ctx.map.ref) { |
| 1109 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1110 | appctx->st0 = STAT_CLI_PRINT; |
| 1111 | return 1; |
| 1112 | } |
| 1113 | appctx->st2 = STAT_ST_INIT; |
| 1114 | appctx->st0 = STAT_CLI_O_MAP; |
| 1115 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1116 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1117 | return 0; |
| 1118 | } |
| 1119 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1120 | else if (strcmp(args[0], "clear") == 0) { |
| 1121 | if (strcmp(args[1], "counters") == 0) { |
| 1122 | struct proxy *px; |
| 1123 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1124 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1125 | int clrall = 0; |
| 1126 | |
| 1127 | if (strcmp(args[2], "all") == 0) |
| 1128 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1129 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1130 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1131 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1132 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1133 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1134 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1135 | return 1; |
| 1136 | } |
| 1137 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1138 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1139 | if (clrall) { |
| 1140 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1141 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1142 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1143 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1144 | px->be_counters.conn_max = 0; |
| 1145 | px->be_counters.p.http.rps_max = 0; |
| 1146 | px->be_counters.sps_max = 0; |
| 1147 | px->be_counters.cps_max = 0; |
| 1148 | px->be_counters.nbpend_max = 0; |
| 1149 | |
| 1150 | px->fe_counters.conn_max = 0; |
| 1151 | px->fe_counters.p.http.rps_max = 0; |
| 1152 | px->fe_counters.sps_max = 0; |
| 1153 | px->fe_counters.cps_max = 0; |
| 1154 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1155 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1156 | |
| 1157 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1158 | if (clrall) |
| 1159 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1160 | else { |
| 1161 | sv->counters.cur_sess_max = 0; |
| 1162 | sv->counters.nbpend_max = 0; |
| 1163 | sv->counters.sps_max = 0; |
| 1164 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1165 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1166 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1167 | if (li->counters) { |
| 1168 | if (clrall) |
| 1169 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1170 | else |
| 1171 | li->counters->conn_max = 0; |
| 1172 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1173 | } |
| 1174 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1175 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1176 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1177 | return 1; |
| 1178 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1179 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1180 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1181 | /* end of processing */ |
| 1182 | return 1; |
| 1183 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1184 | else if (strcmp(args[1], "map") == 0) { |
| 1185 | struct map_reference *mref; |
| 1186 | struct map_descriptor *mdesc; |
| 1187 | struct map_entry *ent, *nent; |
| 1188 | |
| 1189 | /* no parameter */ |
| 1190 | if (!*args[2]) { |
| 1191 | appctx->ctx.cli.msg = "Expect map reference.\n"; |
| 1192 | appctx->st0 = STAT_CLI_PRINT; |
| 1193 | return 1; |
| 1194 | } |
| 1195 | |
| 1196 | /* lookup into the maps */ |
| 1197 | mref = map_get_reference(args[2]); |
| 1198 | if (!mref) { |
| 1199 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1200 | appctx->st0 = STAT_CLI_PRINT; |
| 1201 | return 1; |
| 1202 | } |
| 1203 | |
| 1204 | /* clear all maps */ |
| 1205 | list_for_each_entry(mdesc, &mref->maps, list) |
| 1206 | if (mdesc->do_free) |
| 1207 | pattern_prune_expr(mdesc->pat); |
| 1208 | |
| 1209 | /* clear map reference */ |
| 1210 | list_for_each_entry_safe(ent, nent, &mref->entries, list) { |
| 1211 | LIST_DEL(&ent->list); |
| 1212 | free(ent->key); |
| 1213 | free(ent->value); |
| 1214 | free(ent); |
| 1215 | } |
| 1216 | |
| 1217 | /* return response */ |
| 1218 | appctx->ctx.cli.msg = "Done.\n"; |
| 1219 | appctx->st0 = STAT_CLI_PRINT; |
| 1220 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1221 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1222 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1223 | return 0; |
| 1224 | } |
| 1225 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1226 | else if (strcmp(args[0], "get") == 0) { |
| 1227 | if (strcmp(args[1], "weight") == 0) { |
| 1228 | struct proxy *px; |
| 1229 | struct server *sv; |
| 1230 | |
| 1231 | /* split "backend/server" and make <line> point to server */ |
| 1232 | for (line = args[2]; *line; line++) |
| 1233 | if (*line == '/') { |
| 1234 | *line++ = '\0'; |
| 1235 | break; |
| 1236 | } |
| 1237 | |
| 1238 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1239 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1240 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1241 | return 1; |
| 1242 | } |
| 1243 | |
| 1244 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1245 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1246 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1247 | return 1; |
| 1248 | } |
| 1249 | |
| 1250 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1251 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1252 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1253 | return 1; |
| 1254 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1255 | else if (strcmp(args[1], "map") == 0) { |
| 1256 | |
| 1257 | /* no parameter */ |
| 1258 | if (!*args[2] || !*args[3]) { |
| 1259 | appctx->ctx.cli.msg = "Expect map reference and required key.\n"; |
| 1260 | appctx->st0 = STAT_CLI_PRINT; |
| 1261 | return 1; |
| 1262 | } |
| 1263 | |
| 1264 | /* lookup into the maps */ |
| 1265 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1266 | if (!appctx->ctx.map.ref) { |
| 1267 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1268 | appctx->st0 = STAT_CLI_PRINT; |
| 1269 | return 1; |
| 1270 | } |
| 1271 | |
| 1272 | /* copy input string */ |
| 1273 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1274 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1275 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1276 | if (!appctx->ctx.map.chunk.str) { |
| 1277 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1278 | appctx->st0 = STAT_CLI_PRINT; |
| 1279 | return 1; |
| 1280 | } |
| 1281 | |
| 1282 | /* prepare response */ |
| 1283 | appctx->st2 = STAT_ST_INIT; |
| 1284 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1285 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1286 | else { /* not "get weight" */ |
| 1287 | return 0; |
| 1288 | } |
| 1289 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1290 | else if (strcmp(args[0], "set") == 0) { |
| 1291 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1292 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1293 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1294 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1295 | sv = expect_server_admin(s, si, args[2]); |
| 1296 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1297 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1298 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1299 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1300 | /* |
| 1301 | * The user-weight may now be zero and thus |
| 1302 | * the server considered to be draining. |
| 1303 | * Update the server's drain state as necessary. |
| 1304 | */ |
| 1305 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1306 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1307 | appctx->ctx.cli.msg = warning; |
| 1308 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1309 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1310 | return 1; |
| 1311 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1312 | else if (strcmp(args[1], "timeout") == 0) { |
| 1313 | if (strcmp(args[2], "cli") == 0) { |
| 1314 | unsigned timeout; |
| 1315 | const char *res; |
| 1316 | |
| 1317 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1318 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1319 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1320 | return 1; |
| 1321 | } |
| 1322 | |
| 1323 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1324 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1325 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1326 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1327 | return 1; |
| 1328 | } |
| 1329 | |
| 1330 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1331 | return 1; |
| 1332 | } |
| 1333 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1334 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1335 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1336 | return 1; |
| 1337 | } |
| 1338 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1339 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1340 | if (strcmp(args[2], "frontend") == 0) { |
| 1341 | struct proxy *px; |
| 1342 | struct listener *l; |
| 1343 | int v; |
| 1344 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1345 | px = expect_frontend_admin(s, si, args[3]); |
| 1346 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1347 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1348 | |
| 1349 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1350 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1351 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1352 | return 1; |
| 1353 | } |
| 1354 | |
| 1355 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1356 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1357 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1358 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1359 | return 1; |
| 1360 | } |
| 1361 | |
| 1362 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1363 | * its listeners. The blocked ones will be dequeued. |
| 1364 | */ |
| 1365 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1366 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1367 | l->maxconn = v; |
| 1368 | if (l->state == LI_FULL) |
| 1369 | resume_listener(l); |
| 1370 | } |
| 1371 | |
| 1372 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1373 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1374 | |
| 1375 | return 1; |
| 1376 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1377 | else if (strcmp(args[2], "global") == 0) { |
| 1378 | int v; |
| 1379 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1380 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1381 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1382 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1383 | return 1; |
| 1384 | } |
| 1385 | |
| 1386 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1387 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1388 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1389 | return 1; |
| 1390 | } |
| 1391 | |
| 1392 | v = atoi(args[3]); |
| 1393 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1394 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1395 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1396 | return 1; |
| 1397 | } |
| 1398 | |
| 1399 | /* check for unlimited values */ |
| 1400 | if (v <= 0) |
| 1401 | v = global.hardmaxconn; |
| 1402 | |
| 1403 | global.maxconn = v; |
| 1404 | |
| 1405 | /* Dequeues all of the listeners waiting for a resource */ |
| 1406 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1407 | dequeue_all_listeners(&global_listener_queue); |
| 1408 | |
| 1409 | return 1; |
| 1410 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1411 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1412 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1413 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1414 | return 1; |
| 1415 | } |
| 1416 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1417 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1418 | if (strcmp(args[2], "connections") == 0) { |
| 1419 | if (strcmp(args[3], "global") == 0) { |
| 1420 | int v; |
| 1421 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1422 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1423 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1424 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1425 | return 1; |
| 1426 | } |
| 1427 | |
| 1428 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1429 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1430 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1431 | return 1; |
| 1432 | } |
| 1433 | |
| 1434 | v = atoi(args[4]); |
| 1435 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1436 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1437 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1438 | return 1; |
| 1439 | } |
| 1440 | |
| 1441 | global.cps_lim = v; |
| 1442 | |
| 1443 | /* Dequeues all of the listeners waiting for a resource */ |
| 1444 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1445 | dequeue_all_listeners(&global_listener_queue); |
| 1446 | |
| 1447 | return 1; |
| 1448 | } |
| 1449 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1450 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1451 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1452 | return 1; |
| 1453 | } |
| 1454 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1455 | else if (strcmp(args[2], "sessions") == 0) { |
| 1456 | if (strcmp(args[3], "global") == 0) { |
| 1457 | int v; |
| 1458 | |
| 1459 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1460 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1461 | appctx->st0 = STAT_CLI_PRINT; |
| 1462 | return 1; |
| 1463 | } |
| 1464 | |
| 1465 | if (!*args[4]) { |
| 1466 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1467 | appctx->st0 = STAT_CLI_PRINT; |
| 1468 | return 1; |
| 1469 | } |
| 1470 | |
| 1471 | v = atoi(args[4]); |
| 1472 | if (v < 0) { |
| 1473 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1474 | appctx->st0 = STAT_CLI_PRINT; |
| 1475 | return 1; |
| 1476 | } |
| 1477 | |
| 1478 | global.sps_lim = v; |
| 1479 | |
| 1480 | /* Dequeues all of the listeners waiting for a resource */ |
| 1481 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1482 | dequeue_all_listeners(&global_listener_queue); |
| 1483 | |
| 1484 | return 1; |
| 1485 | } |
| 1486 | else { |
| 1487 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1488 | appctx->st0 = STAT_CLI_PRINT; |
| 1489 | return 1; |
| 1490 | } |
| 1491 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1492 | #ifdef USE_OPENSSL |
| 1493 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1494 | if (strcmp(args[3], "global") == 0) { |
| 1495 | int v; |
| 1496 | |
| 1497 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1498 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1499 | appctx->st0 = STAT_CLI_PRINT; |
| 1500 | return 1; |
| 1501 | } |
| 1502 | |
| 1503 | if (!*args[4]) { |
| 1504 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1505 | appctx->st0 = STAT_CLI_PRINT; |
| 1506 | return 1; |
| 1507 | } |
| 1508 | |
| 1509 | v = atoi(args[4]); |
| 1510 | if (v < 0) { |
| 1511 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1512 | appctx->st0 = STAT_CLI_PRINT; |
| 1513 | return 1; |
| 1514 | } |
| 1515 | |
| 1516 | global.ssl_lim = v; |
| 1517 | |
| 1518 | /* Dequeues all of the listeners waiting for a resource */ |
| 1519 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1520 | dequeue_all_listeners(&global_listener_queue); |
| 1521 | |
| 1522 | return 1; |
| 1523 | } |
| 1524 | else { |
| 1525 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1526 | appctx->st0 = STAT_CLI_PRINT; |
| 1527 | return 1; |
| 1528 | } |
| 1529 | } |
| 1530 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1531 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1532 | if (strcmp(args[3], "global") == 0) { |
| 1533 | int v; |
| 1534 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1535 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1536 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1537 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1538 | return 1; |
| 1539 | } |
| 1540 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1541 | v = atoi(args[4]); |
| 1542 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1543 | } |
| 1544 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1545 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1546 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1547 | return 1; |
| 1548 | } |
| 1549 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1550 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1551 | 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] | 1552 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1553 | return 1; |
| 1554 | } |
| 1555 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1556 | else if (strcmp(args[1], "table") == 0) { |
| 1557 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1558 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1559 | else if (strcmp(args[1], "map") == 0) { |
| 1560 | struct pattern *pat_elt; |
| 1561 | struct pat_idx_elt *idx_elt; |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1562 | char *value = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1563 | |
| 1564 | /* Expect three parameters: map name, key and new value. */ |
| 1565 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 1566 | appctx->ctx.cli.msg = "'set map' expect three parameters: map name, key and value.\n"; |
| 1567 | appctx->st0 = STAT_CLI_PRINT; |
| 1568 | return 1; |
| 1569 | } |
| 1570 | |
| 1571 | /* Lookup the reference in the maps. */ |
| 1572 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1573 | if (!appctx->ctx.map.ref) { |
| 1574 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1575 | appctx->st0 = STAT_CLI_PRINT; |
| 1576 | return 1; |
| 1577 | } |
| 1578 | |
| 1579 | /* Lookup the entry in the reference values. */ |
| 1580 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) |
| 1581 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) |
| 1582 | break; |
| 1583 | |
| 1584 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) { |
| 1585 | appctx->ctx.cli.msg = "Entry not found.\n"; |
| 1586 | appctx->st0 = STAT_CLI_PRINT; |
| 1587 | return 1; |
| 1588 | } |
| 1589 | |
| 1590 | /* Update each reference entries. */ |
| 1591 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) { |
| 1592 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) { |
| 1593 | value = strdup(args[4]); |
| 1594 | if (!value) { |
| 1595 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1596 | appctx->st0 = STAT_CLI_PRINT; |
| 1597 | return 1; |
| 1598 | } |
| 1599 | free(appctx->ctx.map.ent->value); |
| 1600 | appctx->ctx.map.ent->value = value; |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | /* Change the sample. The lookup juste return the first entry, other |
| 1605 | * entries are not changed, but are never matched. |
| 1606 | */ |
| 1607 | appctx->ctx.map.desc = NULL; |
| 1608 | for (stats_map_lookup_next(si); |
| 1609 | appctx->ctx.map.desc; |
| 1610 | stats_map_lookup_next(si)) { |
| 1611 | pattern_lookup(args[3], appctx->ctx.map.desc->pat, &pat_elt, &idx_elt, NULL); |
| 1612 | if (pat_elt != NULL) |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1613 | appctx->ctx.map.desc->parse(value, pat_elt->smp); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1614 | if (idx_elt != NULL) |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1615 | appctx->ctx.map.desc->parse(value, idx_elt->smp); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | /* The set is done, send message. */ |
| 1619 | appctx->ctx.cli.msg = "Done.\n"; |
| 1620 | appctx->st0 = STAT_CLI_PRINT; |
| 1621 | return 1; |
| 1622 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1623 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1624 | return 0; |
| 1625 | } |
| 1626 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1627 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1628 | if (strcmp(args[1], "agent") == 0) { |
| 1629 | struct server *sv; |
| 1630 | |
| 1631 | sv = expect_server_admin(s, si, args[2]); |
| 1632 | if (!sv) |
| 1633 | return 1; |
| 1634 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1635 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1636 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1637 | appctx->st0 = STAT_CLI_PRINT; |
| 1638 | return 1; |
| 1639 | } |
| 1640 | |
| 1641 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1642 | return 1; |
| 1643 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1644 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1645 | struct server *sv; |
| 1646 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1647 | sv = expect_server_admin(s, si, args[2]); |
| 1648 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1649 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1650 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1651 | if (sv->state & SRV_MAINTAIN) { |
| 1652 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1653 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1654 | /* If this server tracks the status of another one, |
| 1655 | * we must restore the good status. |
| 1656 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1657 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1658 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1659 | 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] | 1660 | } else { |
| 1661 | sv->state &= ~SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1662 | sv->check.state &= ~CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1663 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1664 | } |
| 1665 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1666 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1667 | 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] | 1668 | } |
| 1669 | } |
| 1670 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1671 | return 1; |
| 1672 | } |
| 1673 | else if (strcmp(args[1], "frontend") == 0) { |
| 1674 | struct proxy *px; |
| 1675 | |
| 1676 | px = expect_frontend_admin(s, si, args[2]); |
| 1677 | if (!px) |
| 1678 | return 1; |
| 1679 | |
| 1680 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1681 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1682 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1683 | return 1; |
| 1684 | } |
| 1685 | |
| 1686 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1687 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1688 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1689 | return 1; |
| 1690 | } |
| 1691 | |
| 1692 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1693 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1694 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1695 | return 1; |
| 1696 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1697 | return 1; |
| 1698 | } |
| 1699 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1700 | appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1701 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1702 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1703 | } |
| 1704 | } |
| 1705 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1706 | if (strcmp(args[1], "agent") == 0) { |
| 1707 | struct server *sv; |
| 1708 | |
| 1709 | sv = expect_server_admin(s, si, args[2]); |
| 1710 | if (!sv) |
| 1711 | return 1; |
| 1712 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1713 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1714 | return 1; |
| 1715 | } |
| 1716 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1717 | struct server *sv; |
| 1718 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1719 | sv = expect_server_admin(s, si, args[2]); |
| 1720 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1721 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1722 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1723 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1724 | /* Not already in maintenance, we can change the server state */ |
| 1725 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1726 | sv->check.state |= CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1727 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1728 | } |
| 1729 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1730 | return 1; |
| 1731 | } |
| 1732 | else if (strcmp(args[1], "frontend") == 0) { |
| 1733 | struct proxy *px; |
| 1734 | |
| 1735 | px = expect_frontend_admin(s, si, args[2]); |
| 1736 | if (!px) |
| 1737 | return 1; |
| 1738 | |
| 1739 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1740 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1741 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1742 | return 1; |
| 1743 | } |
| 1744 | |
| 1745 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1746 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1747 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1748 | return 1; |
| 1749 | } |
| 1750 | |
| 1751 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1752 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1753 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1754 | return 1; |
| 1755 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1756 | return 1; |
| 1757 | } |
| 1758 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1759 | appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1760 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1761 | return 1; |
| 1762 | } |
| 1763 | } |
| 1764 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1765 | if (strcmp(args[1], "frontend") == 0) { |
| 1766 | struct proxy *px; |
| 1767 | |
| 1768 | px = expect_frontend_admin(s, si, args[2]); |
| 1769 | if (!px) |
| 1770 | return 1; |
| 1771 | |
| 1772 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1773 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1774 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1775 | return 1; |
| 1776 | } |
| 1777 | |
| 1778 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1779 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1780 | send_log(px, LOG_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 | stop_proxy(px); |
| 1783 | return 1; |
| 1784 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1785 | else if (strcmp(args[1], "session") == 0) { |
| 1786 | struct session *sess, *ptr; |
| 1787 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1788 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1789 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1790 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1791 | return 1; |
| 1792 | } |
| 1793 | |
| 1794 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1795 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1796 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1797 | return 1; |
| 1798 | } |
| 1799 | |
| 1800 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1801 | |
| 1802 | /* first, look for the requested session in the session table */ |
| 1803 | list_for_each_entry(sess, &sessions, list) { |
| 1804 | if (sess == ptr) |
| 1805 | break; |
| 1806 | } |
| 1807 | |
| 1808 | /* do we have the session ? */ |
| 1809 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1810 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1811 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1812 | return 1; |
| 1813 | } |
| 1814 | |
| 1815 | session_shutdown(sess, SN_ERR_KILLED); |
| 1816 | return 1; |
| 1817 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1818 | else if (strcmp(args[1], "sessions") == 0) { |
| 1819 | if (strcmp(args[2], "server") == 0) { |
| 1820 | struct server *sv; |
| 1821 | struct session *sess, *sess_bck; |
| 1822 | |
| 1823 | sv = expect_server_admin(s, si, args[3]); |
| 1824 | if (!sv) |
| 1825 | return 1; |
| 1826 | |
| 1827 | /* kill all the session that are on this server */ |
| 1828 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1829 | if (sess->srv_conn == sv) |
| 1830 | session_shutdown(sess, SN_ERR_KILLED); |
| 1831 | |
| 1832 | return 1; |
| 1833 | } |
| 1834 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1835 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1836 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1837 | return 1; |
| 1838 | } |
| 1839 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1840 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1841 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1842 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1843 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1844 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1845 | } |
| 1846 | else if (strcmp(args[0], "del") == 0) { |
| 1847 | if (strcmp(args[1], "map") == 0) { |
| 1848 | struct pattern *pat_elt; |
| 1849 | struct pat_idx_elt *idx_elt; |
| 1850 | struct map_entry *ent; |
| 1851 | |
| 1852 | /* Expect two parameters: map name and key. */ |
| 1853 | if (!*args[2] || !*args[3]) { |
| 1854 | appctx->ctx.cli.msg = "'del map' expect two parameters: map name and key.\n"; |
| 1855 | appctx->st0 = STAT_CLI_PRINT; |
| 1856 | return 1; |
| 1857 | } |
| 1858 | |
| 1859 | /* Lookup the reference in the maps. */ |
| 1860 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1861 | if (!appctx->ctx.map.ref) { |
| 1862 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1863 | appctx->st0 = STAT_CLI_PRINT; |
| 1864 | return 1; |
| 1865 | } |
| 1866 | |
| 1867 | /* Lookup the entry in the reference values. |
| 1868 | * If the entry is not found in the reference, return error message. |
| 1869 | */ |
| 1870 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) |
| 1871 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) |
| 1872 | break; |
| 1873 | |
| 1874 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) { |
| 1875 | appctx->ctx.cli.msg = "Entry not found.\n"; |
| 1876 | appctx->st0 = STAT_CLI_PRINT; |
| 1877 | return 1; |
| 1878 | } |
| 1879 | |
| 1880 | /* Delete each enties from reference. */ |
| 1881 | list_for_each_entry_safe(appctx->ctx.map.ent, ent, &appctx->ctx.map.ref->entries, list) { |
| 1882 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) { |
| 1883 | LIST_DEL(&appctx->ctx.map.ent->list); |
| 1884 | free(appctx->ctx.map.ent->key); |
| 1885 | free(appctx->ctx.map.ent->value); |
| 1886 | free(appctx->ctx.map.ent); |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | /* Delete all matching entries for each map descritor. */ |
| 1891 | appctx->ctx.map.desc = NULL; |
| 1892 | stats_map_lookup_next(si); |
| 1893 | while (appctx->ctx.map.desc) { |
| 1894 | while (pattern_lookup(args[3], appctx->ctx.map.desc->pat, &pat_elt, &idx_elt, NULL)) { |
| 1895 | if (pat_elt != NULL) { |
| 1896 | LIST_DEL(&pat_elt->list); |
| 1897 | pattern_free(pat_elt); |
| 1898 | } |
| 1899 | if (idx_elt != NULL) { |
| 1900 | ebmb_delete(&idx_elt->node); |
| 1901 | free(idx_elt); |
| 1902 | } |
| 1903 | } |
| 1904 | stats_map_lookup_next(si); |
| 1905 | } |
| 1906 | |
| 1907 | /* The deletion is done, send message. */ |
| 1908 | appctx->ctx.cli.msg = "Done.\n"; |
| 1909 | appctx->st0 = STAT_CLI_PRINT; |
| 1910 | return 1; |
| 1911 | } |
| 1912 | else { /* unknown "del" parameter */ |
| 1913 | appctx->ctx.cli.msg = "'del' only supports 'map'.\n"; |
| 1914 | appctx->st0 = STAT_CLI_PRINT; |
| 1915 | return 1; |
| 1916 | } |
| 1917 | } |
| 1918 | else if (strcmp(args[0], "add") == 0) { |
| 1919 | if (strcmp(args[1], "map") == 0) { |
| 1920 | const char *params[2]; |
| 1921 | struct pattern *pat; |
| 1922 | struct map_entry *ent; |
| 1923 | struct sample_storage *smp; |
| 1924 | |
| 1925 | /* Expect three parameters: map name, key and new value. */ |
| 1926 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 1927 | appctx->ctx.cli.msg = "'add map' expect three parameters: map name, key and value.\n"; |
| 1928 | appctx->st0 = STAT_CLI_PRINT; |
| 1929 | return 1; |
| 1930 | } |
| 1931 | |
| 1932 | params[0] = args[3]; |
| 1933 | params[1] = ""; |
| 1934 | |
| 1935 | /* Lookup the reference in the maps. */ |
| 1936 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1937 | if (!appctx->ctx.map.ref) { |
| 1938 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1939 | appctx->st0 = STAT_CLI_PRINT; |
| 1940 | return 1; |
| 1941 | } |
| 1942 | |
| 1943 | /* Prepare and link the new map_entry element. If out of memory |
| 1944 | * error the action is cancelled and the descriptor are left |
| 1945 | * coherents. |
| 1946 | */ |
| 1947 | ent = malloc(sizeof(*ent)); |
| 1948 | if (!ent) { |
| 1949 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1950 | appctx->st0 = STAT_CLI_PRINT; |
| 1951 | return 1; |
| 1952 | } |
| 1953 | ent->key = strdup(args[3]); |
| 1954 | if (!ent->key) { |
| 1955 | free(ent); |
| 1956 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1957 | appctx->st0 = STAT_CLI_PRINT; |
| 1958 | return 1; |
| 1959 | } |
| 1960 | ent->value = strdup(args[4]); |
| 1961 | if (!ent->value) { |
| 1962 | free(ent->key); |
| 1963 | free(ent); |
| 1964 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1965 | appctx->st0 = STAT_CLI_PRINT; |
| 1966 | return 1; |
| 1967 | } |
| 1968 | LIST_ADDQ(&appctx->ctx.map.ref->entries, &ent->list); |
| 1969 | |
| 1970 | /* Browse each map descritor and try to insert this new value. */ |
| 1971 | appctx->ctx.map.desc = NULL; |
| 1972 | for (stats_map_lookup_next(si); |
| 1973 | appctx->ctx.map.desc; |
| 1974 | stats_map_lookup_next(si)) { |
| 1975 | |
| 1976 | /* Create new sample. Return out of memory error |
| 1977 | * if the memory cannot be allocated. The 'add' process |
| 1978 | * is aborted, but the already inserted entries are not |
| 1979 | * deleted. |
| 1980 | */ |
| 1981 | smp = calloc(1, sizeof(*smp)); |
| 1982 | if (!smp) { |
| 1983 | appctx->ctx.cli.msg = "Out of memory error. The value is not added in all maps.\n"; |
| 1984 | appctx->st0 = STAT_CLI_PRINT; |
| 1985 | return 1; |
| 1986 | } |
| 1987 | |
| 1988 | /* Create sample. If this function fails, the insertion |
| 1989 | * is canceled for this 'descriptor', but continue, for |
| 1990 | * the other descriptors. |
| 1991 | */ |
| 1992 | if (!appctx->ctx.map.desc->parse(ent->value, smp)) { |
| 1993 | free(smp); |
| 1994 | continue; |
| 1995 | } |
| 1996 | |
| 1997 | /* If the value can be indexed, get the first pattern. If |
| 1998 | * the return entry is not the indexed entry, new 'pattern' is |
| 1999 | * created by the function pattern_register(). If the 'pattern' |
| 2000 | * is NULL, new entry is created. This is ugly because the |
| 2001 | * following code interfers with the own code of the function |
| 2002 | * pattern_register(). |
| 2003 | */ |
| 2004 | if (appctx->ctx.map.desc->pat->match == pat_match_str || |
| 2005 | appctx->ctx.map.desc->pat->match == pat_match_ip) { |
| 2006 | pat = LIST_NEXT(&appctx->ctx.map.desc->pat->patterns, struct pattern *, list); |
| 2007 | if (&pat->list == &appctx->ctx.map.desc->pat->patterns) |
| 2008 | pat = NULL; |
| 2009 | } |
| 2010 | else |
| 2011 | pat = NULL; |
| 2012 | |
| 2013 | if (!pattern_register(appctx->ctx.map.desc->pat, params, smp, &pat, 0, NULL)) { |
| 2014 | free(smp); |
| 2015 | continue; |
| 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | /* The add is done, send message. */ |
| 2020 | appctx->ctx.cli.msg = "Done.\n"; |
| 2021 | appctx->st0 = STAT_CLI_PRINT; |
| 2022 | return 1; |
| 2023 | } |
| 2024 | else { /* unknown "del" parameter */ |
| 2025 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2026 | appctx->st0 = STAT_CLI_PRINT; |
| 2027 | return 1; |
| 2028 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2029 | } |
| 2030 | 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] | 2031 | return 0; |
| 2032 | } |
| 2033 | return 1; |
| 2034 | } |
| 2035 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2036 | /* 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] | 2037 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2038 | * state machine handling requests and various responses. We read a request, |
| 2039 | * 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] | 2040 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2041 | * 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] | 2042 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2043 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2044 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2045 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2046 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2047 | struct channel *req = si->ob; |
| 2048 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2049 | int reql; |
| 2050 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2051 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2052 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2053 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2054 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2055 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2056 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2057 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2058 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2059 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2060 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2061 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2062 | /* Let's close for real now. We just close the request |
| 2063 | * side, the conditions below will complete if needed. |
| 2064 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2065 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2066 | break; |
| 2067 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2068 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2069 | /* ensure we have some output room left in the event we |
| 2070 | * would want to return some info right after parsing. |
| 2071 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2072 | if (buffer_almost_full(si->ib->buf)) { |
| 2073 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2074 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2075 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2076 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2077 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2078 | if (reql <= 0) { /* closed or EOL not found */ |
| 2079 | if (reql == 0) |
| 2080 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2081 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2082 | continue; |
| 2083 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2084 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2085 | /* seek for a possible semi-colon. If we find one, we |
| 2086 | * replace it with an LF and skip only this part. |
| 2087 | */ |
| 2088 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2089 | if (trash.str[len] == ';') { |
| 2090 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2091 | reql = len + 1; |
| 2092 | break; |
| 2093 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2094 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2095 | /* now it is time to check that we have a full line, |
| 2096 | * remove the trailing \n and possibly \r, then cut the |
| 2097 | * line. |
| 2098 | */ |
| 2099 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2100 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2101 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2102 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2103 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2104 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2105 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2106 | len--; |
| 2107 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2108 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2109 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2110 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2111 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2112 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2113 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2114 | continue; |
| 2115 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2116 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2117 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2118 | else if (strcmp(trash.str, "help") == 0 || |
| 2119 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2120 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2121 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2122 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2123 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2124 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2125 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2126 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2127 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2128 | /* if prompt is disabled, print help on empty lines, |
| 2129 | * so that the user at least knows how to enable |
| 2130 | * prompt and find help. |
| 2131 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2132 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2133 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2137 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2138 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2139 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2140 | 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] | 2141 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2142 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2143 | continue; |
| 2144 | } |
| 2145 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2146 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2147 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2148 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2149 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2150 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2151 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2152 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2153 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2154 | break; |
| 2155 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2156 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2157 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2158 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2159 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2160 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2161 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2162 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2163 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2164 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2165 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2166 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2167 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2168 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2169 | if (stats_table_request(si, appctx->st0)) |
| 2170 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2171 | break; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2172 | case STAT_CLI_O_MAPS: |
| 2173 | if (stats_maps_list(si)) |
| 2174 | appctx->st0 = STAT_CLI_PROMPT; |
| 2175 | break; |
| 2176 | case STAT_CLI_O_MAP: |
| 2177 | if (stats_map_list(si)) |
| 2178 | appctx->st0 = STAT_CLI_PROMPT; |
| 2179 | break; |
| 2180 | case STAT_CLI_O_MLOOK: |
| 2181 | if (stats_map_lookup(si)) |
| 2182 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2183 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2184 | case STAT_CLI_O_POOLS: |
| 2185 | if (stats_dump_pools_to_buffer(si)) |
| 2186 | appctx->st0 = STAT_CLI_PROMPT; |
| 2187 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2188 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2189 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2190 | break; |
| 2191 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2192 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2193 | /* 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] | 2194 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2195 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2196 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2197 | } |
| 2198 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2199 | /* 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] | 2200 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2201 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2202 | |
| 2203 | /* Now we close the output if one of the writers did so, |
| 2204 | * or if we're not in interactive mode and the request |
| 2205 | * buffer is empty. This still allows pipelined requests |
| 2206 | * to be sent in non-interactive mode. |
| 2207 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2208 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2209 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2210 | continue; |
| 2211 | } |
| 2212 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2213 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2214 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2215 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2216 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2217 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2218 | 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] | 2219 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2220 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2221 | /* 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] | 2222 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2223 | * we forward the close to the request side so that it flows upstream to |
| 2224 | * the client. |
| 2225 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2226 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2227 | } |
| 2228 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2229 | 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] | 2230 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2231 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2232 | /* We have no more processing to do, and nothing more to send, and |
| 2233 | * the client side has closed. So we'll forward this state downstream |
| 2234 | * on the response buffer. |
| 2235 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2236 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2237 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2241 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2242 | |
| 2243 | /* we don't want to expire timeouts while we're processing requests */ |
| 2244 | si->ib->rex = TICK_ETERNITY; |
| 2245 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2246 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2247 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2248 | 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] | 2249 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2250 | 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] | 2251 | |
| 2252 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2253 | /* check that we have released everything then unregister */ |
| 2254 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2255 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2256 | } |
| 2257 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2258 | /* This function dumps information onto the stream interface's read buffer. |
| 2259 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2260 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2261 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2262 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2263 | { |
| 2264 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2265 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2266 | chunk_printf(&trash, |
| 2267 | "Name: " PRODUCT_NAME "\n" |
| 2268 | "Version: " HAPROXY_VERSION "\n" |
| 2269 | "Release_date: " HAPROXY_DATE "\n" |
| 2270 | "Nbproc: %d\n" |
| 2271 | "Process_num: %d\n" |
| 2272 | "Pid: %d\n" |
| 2273 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2274 | "Uptime_sec: %d\n" |
| 2275 | "Memmax_MB: %d\n" |
| 2276 | "Ulimit-n: %d\n" |
| 2277 | "Maxsock: %d\n" |
| 2278 | "Maxconn: %d\n" |
| 2279 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2280 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2281 | "CumConns: %d\n" |
| 2282 | "CumReq: %d\n" |
| 2283 | #ifdef USE_OPENSSL |
| 2284 | "MaxSslConns: %d\n" |
| 2285 | "CurrSslConns: %d\n" |
| 2286 | "CumSslConns: %d\n" |
| 2287 | #endif |
| 2288 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2289 | "PipesUsed: %d\n" |
| 2290 | "PipesFree: %d\n" |
| 2291 | "ConnRate: %d\n" |
| 2292 | "ConnRateLimit: %d\n" |
| 2293 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2294 | "SessRate: %d\n" |
| 2295 | "SessRateLimit: %d\n" |
| 2296 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2297 | #ifdef USE_OPENSSL |
| 2298 | "SslRate: %d\n" |
| 2299 | "SslRateLimit: %d\n" |
| 2300 | "MaxSslRate: %d\n" |
| 2301 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2302 | "CompressBpsIn: %u\n" |
| 2303 | "CompressBpsOut: %u\n" |
| 2304 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2305 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2306 | "ZlibMemUsage: %ld\n" |
| 2307 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2308 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2309 | "Tasks: %d\n" |
| 2310 | "Run_queue: %d\n" |
| 2311 | "Idle_pct: %d\n" |
| 2312 | "node: %s\n" |
| 2313 | "description: %s\n" |
| 2314 | "", |
| 2315 | global.nbproc, |
| 2316 | relative_pid, |
| 2317 | pid, |
| 2318 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2319 | up, |
| 2320 | global.rlimit_memmax, |
| 2321 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2322 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2323 | actconn, totalconn, global.req_count, |
| 2324 | #ifdef USE_OPENSSL |
| 2325 | global.maxsslconn, sslconns, totalsslconns, |
| 2326 | #endif |
| 2327 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2328 | 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] | 2329 | 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] | 2330 | #ifdef USE_OPENSSL |
| 2331 | read_freq_ctr(&global.ssl_per_sec), global.ssl_lim, global.ssl_max, |
| 2332 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2333 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2334 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2335 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2336 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2337 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2338 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2339 | global.node, global.desc ? global.desc : "" |
| 2340 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2341 | |
| 2342 | if (bi_putchk(si->ib, &trash) == -1) |
| 2343 | return 0; |
| 2344 | |
| 2345 | return 1; |
| 2346 | } |
| 2347 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2348 | /* This function dumps memory usage information onto the stream interface's |
| 2349 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2350 | * completion. No state is used. |
| 2351 | */ |
| 2352 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2353 | { |
| 2354 | dump_pools_to_trash(); |
| 2355 | if (bi_putchk(si->ib, &trash) == -1) |
| 2356 | return 0; |
| 2357 | return 1; |
| 2358 | } |
| 2359 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2360 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2361 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2362 | * 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] | 2363 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2364 | 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] | 2365 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2366 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2367 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2368 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2369 | if (!(px->cap & PR_CAP_FE)) |
| 2370 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2371 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2372 | 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] | 2373 | return 0; |
| 2374 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2375 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2376 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2377 | /* name, queue */ |
| 2378 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2379 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2380 | 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] | 2381 | /* Column sub-heading for Enable or Disable server */ |
| 2382 | chunk_appendf(&trash, "<td></td>"); |
| 2383 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2384 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2385 | chunk_appendf(&trash, |
| 2386 | "<td class=ac>" |
| 2387 | "<a name=\"%s/Frontend\"></a>" |
| 2388 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2389 | "<td colspan=3></td>" |
| 2390 | "", |
| 2391 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2392 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2393 | chunk_appendf(&trash, |
| 2394 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2395 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2396 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2397 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2398 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2399 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2400 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2401 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2402 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2403 | if (px->mode == PR_MODE_HTTP) |
| 2404 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2405 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2406 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2407 | |
| 2408 | chunk_appendf(&trash, |
| 2409 | "</table></div></u></td>" |
| 2410 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2411 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2412 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2413 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2414 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2415 | U2H(px->fe_counters.sps_max), |
| 2416 | U2H(px->fe_counters.cps_max), |
| 2417 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2418 | |
| 2419 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2420 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2421 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2422 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2423 | |
| 2424 | chunk_appendf(&trash, |
| 2425 | "</table></div></u></td>" |
| 2426 | /* sessions rate : limit */ |
| 2427 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2428 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2429 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2430 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2431 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2432 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2433 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2434 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2435 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2436 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2437 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2438 | U2H(px->fe_counters.cum_sess), |
| 2439 | U2H(px->fe_counters.cum_conn), |
| 2440 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2441 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2442 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2443 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2444 | chunk_appendf(&trash, |
| 2445 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2446 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2447 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2448 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2449 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2450 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2451 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2452 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2453 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2454 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2455 | U2H(px->fe_counters.p.http.cum_req), |
| 2456 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2457 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2458 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2459 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2460 | (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] | 2461 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2462 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2463 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2464 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2465 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2466 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2467 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2468 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2469 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2470 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2471 | "<td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2472 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2473 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2474 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2475 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2476 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2477 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2478 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2479 | "<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] | 2480 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2481 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2482 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2483 | px->fe_counters.comp_in ? |
| 2484 | (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] | 2485 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2486 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2487 | chunk_appendf(&trash, |
| 2488 | /* denied: req, resp */ |
| 2489 | "<td>%s</td><td>%s</td>" |
| 2490 | /* errors : request, connect, response */ |
| 2491 | "<td>%s</td><td></td><td></td>" |
| 2492 | /* warnings: retries, redispatches */ |
| 2493 | "<td></td><td></td>" |
| 2494 | /* server status : reflect frontend status */ |
| 2495 | "<td class=ac>%s</td>" |
| 2496 | /* rest of server: nothing */ |
| 2497 | "<td class=ac colspan=8></td></tr>" |
| 2498 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2499 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2500 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2501 | px->state == PR_STREADY ? "OPEN" : |
| 2502 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2503 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2504 | else { /* CSV mode */ |
| 2505 | chunk_appendf(&trash, |
| 2506 | /* pxid, name, queue cur, queue max, */ |
| 2507 | "%s,FRONTEND,,," |
| 2508 | /* sessions : current, max, limit, total */ |
| 2509 | "%d,%d,%d,%lld," |
| 2510 | /* bytes : in, out */ |
| 2511 | "%lld,%lld," |
| 2512 | /* denied: req, resp */ |
| 2513 | "%lld,%lld," |
| 2514 | /* errors : request, connect, response */ |
| 2515 | "%lld,,," |
| 2516 | /* warnings: retries, redispatches */ |
| 2517 | ",," |
| 2518 | /* server status : reflect frontend status */ |
| 2519 | "%s," |
| 2520 | /* rest of server: nothing */ |
| 2521 | ",,,,,,,," |
| 2522 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2523 | "%d,%d,0,,,,%d," |
| 2524 | /* rate, rate_lim, rate_max */ |
| 2525 | "%u,%u,%u," |
| 2526 | /* check_status, check_code, check_duration */ |
| 2527 | ",,,", |
| 2528 | px->id, |
| 2529 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2530 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2531 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2532 | px->fe_counters.failed_req, |
| 2533 | px->state == PR_STREADY ? "OPEN" : |
| 2534 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2535 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2536 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2537 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2538 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2539 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2540 | if (px->mode == PR_MODE_HTTP) { |
| 2541 | for (i=1; i<6; i++) |
| 2542 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2543 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2544 | } |
| 2545 | else |
| 2546 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2547 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2548 | /* failed health analyses */ |
| 2549 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2550 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2551 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2552 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2553 | read_freq_ctr(&px->fe_req_per_sec), |
| 2554 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2555 | |
| 2556 | /* errors: cli_aborts, srv_aborts */ |
| 2557 | chunk_appendf(&trash, ",,"); |
| 2558 | |
| 2559 | /* compression: in, out, bypassed */ |
| 2560 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2561 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2562 | |
| 2563 | /* compression: comp_rsp */ |
| 2564 | chunk_appendf(&trash, "%lld,", |
| 2565 | px->fe_counters.p.http.comp_rsp); |
| 2566 | |
| 2567 | /* finish with EOL */ |
| 2568 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2569 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2570 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2571 | } |
| 2572 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2573 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2574 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2575 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2576 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2577 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2578 | 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] | 2579 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2580 | struct appctx *appctx = __objt_appctx(si->end); |
| 2581 | |
| 2582 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2583 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2584 | 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] | 2585 | /* Column sub-heading for Enable or Disable server */ |
| 2586 | chunk_appendf(&trash, "<td></td>"); |
| 2587 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2588 | chunk_appendf(&trash, |
| 2589 | /* frontend name, listener name */ |
| 2590 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2591 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2592 | "", |
| 2593 | px->id, l->name, |
| 2594 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2595 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2596 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2597 | if (flags & ST_SHLGNDS) { |
| 2598 | char str[INET6_ADDRSTRLEN]; |
| 2599 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2600 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2601 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2602 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2603 | port = get_host_port(&l->addr); |
| 2604 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2605 | case AF_INET: |
| 2606 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2607 | break; |
| 2608 | case AF_INET6: |
| 2609 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2610 | break; |
| 2611 | case AF_UNIX: |
| 2612 | chunk_appendf(&trash, "unix, "); |
| 2613 | break; |
| 2614 | case -1: |
| 2615 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2616 | break; |
| 2617 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2618 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2619 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2620 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2621 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2622 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2623 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2624 | /* queue */ |
| 2625 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2626 | /* sessions rate: current, max, limit */ |
| 2627 | "<td colspan=3> </td>" |
| 2628 | /* sessions: current, max, limit, total, lbtot */ |
| 2629 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2630 | "<td>%s</td><td> </td>" |
| 2631 | /* bytes: in, out */ |
| 2632 | "<td>%s</td><td>%s</td>" |
| 2633 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2634 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2635 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2636 | 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] | 2637 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2638 | chunk_appendf(&trash, |
| 2639 | /* denied: req, resp */ |
| 2640 | "<td>%s</td><td>%s</td>" |
| 2641 | /* errors: request, connect, response */ |
| 2642 | "<td>%s</td><td></td><td></td>" |
| 2643 | /* warnings: retries, redispatches */ |
| 2644 | "<td></td><td></td>" |
| 2645 | /* server status: reflect listener status */ |
| 2646 | "<td class=ac>%s</td>" |
| 2647 | /* rest of server: nothing */ |
| 2648 | "<td class=ac colspan=8></td></tr>" |
| 2649 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2650 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2651 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2652 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2653 | } |
| 2654 | else { /* CSV mode */ |
| 2655 | chunk_appendf(&trash, |
| 2656 | /* pxid, name, queue cur, queue max, */ |
| 2657 | "%s,%s,,," |
| 2658 | /* sessions: current, max, limit, total */ |
| 2659 | "%d,%d,%d,%lld," |
| 2660 | /* bytes: in, out */ |
| 2661 | "%lld,%lld," |
| 2662 | /* denied: req, resp */ |
| 2663 | "%lld,%lld," |
| 2664 | /* errors: request, connect, response */ |
| 2665 | "%lld,,," |
| 2666 | /* warnings: retries, redispatches */ |
| 2667 | ",," |
| 2668 | /* server status: reflect listener status */ |
| 2669 | "%s," |
| 2670 | /* rest of server: nothing */ |
| 2671 | ",,,,,,,," |
| 2672 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2673 | "%d,%d,%d,,,,%d," |
| 2674 | /* rate, rate_lim, rate_max */ |
| 2675 | ",,," |
| 2676 | /* check_status, check_code, check_duration */ |
| 2677 | ",,," |
| 2678 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2679 | ",,,,,," |
| 2680 | /* failed health analyses */ |
| 2681 | "," |
| 2682 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2683 | ",,," |
| 2684 | /* errors: cli_aborts, srv_aborts */ |
| 2685 | ",," |
| 2686 | /* compression: in, out, bypassed, comp_rsp */ |
| 2687 | ",,,," |
| 2688 | "\n", |
| 2689 | px->id, l->name, |
| 2690 | l->nbconn, l->counters->conn_max, |
| 2691 | l->maxconn, l->counters->cum_conn, |
| 2692 | l->counters->bytes_in, l->counters->bytes_out, |
| 2693 | l->counters->denied_req, l->counters->denied_resp, |
| 2694 | l->counters->failed_req, |
| 2695 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2696 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2697 | } |
| 2698 | return 1; |
| 2699 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2700 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2701 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2702 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2703 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2704 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2705 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2706 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2707 | */ |
| 2708 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2709 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2710 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2711 | struct server *ref = sv->track ? sv->track : sv; |
| 2712 | char str[INET6_ADDRSTRLEN]; |
| 2713 | struct chunk src; |
| 2714 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2715 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2716 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2717 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2718 | "DOWN", |
| 2719 | "DN %d/%d ↑", |
| 2720 | "UP %d/%d ↓", |
| 2721 | "UP", |
| 2722 | "NOLB %d/%d ↓", |
| 2723 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2724 | "DRAIN %d/%d ↓", |
| 2725 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2726 | "<i>no check</i>" |
| 2727 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2728 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2729 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2730 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2731 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2732 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2733 | "<tr class=\"%s%d\">", |
| 2734 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2735 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2736 | 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] | 2737 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2738 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2739 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2740 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2741 | chunk_appendf(&trash, |
| 2742 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2743 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2744 | "", |
| 2745 | px->id, sv->id, |
| 2746 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2747 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2748 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2749 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2750 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2751 | |
| 2752 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2753 | case AF_INET: |
| 2754 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2755 | break; |
| 2756 | case AF_INET6: |
| 2757 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2758 | break; |
| 2759 | case AF_UNIX: |
| 2760 | chunk_appendf(&trash, "unix, "); |
| 2761 | break; |
| 2762 | case -1: |
| 2763 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2764 | break; |
| 2765 | default: /* address family not supported */ |
| 2766 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2767 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2768 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2769 | /* id */ |
| 2770 | chunk_appendf(&trash, "id: %d", sv->puid); |
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 | /* cookie */ |
| 2773 | if (sv->cookie) { |
| 2774 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2775 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2776 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2777 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2778 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2779 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2780 | } |
| 2781 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2782 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2783 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2784 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2785 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2786 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2787 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2788 | /* sessions rate : current, max, limit */ |
| 2789 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2790 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2791 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2792 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2793 | 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] | 2794 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2795 | |
| 2796 | chunk_appendf(&trash, |
| 2797 | /* sessions: current, max, limit, total */ |
| 2798 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2799 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2800 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2801 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2802 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2803 | U2H(sv->counters.cum_sess), |
| 2804 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2805 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2806 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2807 | if (px->mode == PR_MODE_HTTP) { |
| 2808 | unsigned long long tot; |
| 2809 | for (tot = i = 0; i < 6; i++) |
| 2810 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2811 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2812 | chunk_appendf(&trash, |
| 2813 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2814 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2815 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2816 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2817 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2818 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2819 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2820 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2821 | U2H(tot), |
| 2822 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2823 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2824 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2825 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2826 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2827 | 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] | 2828 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2829 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2830 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2831 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2832 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2833 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2834 | U2H(sv->counters.cum_lbconn)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2835 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2836 | chunk_appendf(&trash, |
| 2837 | /* bytes : in, out */ |
| 2838 | "<td>%s</td><td>%s</td>" |
| 2839 | /* denied: req, resp */ |
| 2840 | "<td></td><td>%s</td>" |
| 2841 | /* errors : request, connect */ |
| 2842 | "<td></td><td>%s</td>" |
| 2843 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2844 | "<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] | 2845 | /* warnings: retries, redispatches */ |
| 2846 | "<td>%lld</td><td>%lld</td>" |
| 2847 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2848 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2849 | U2H(sv->counters.failed_secu), |
| 2850 | U2H(sv->counters.failed_conns), |
| 2851 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2852 | sv->counters.cli_aborts, |
| 2853 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2854 | sv->counters.retries, sv->counters.redispatches); |
| 2855 | |
| 2856 | /* status, lest check */ |
| 2857 | chunk_appendf(&trash, "<td class=ac>"); |
| 2858 | |
| 2859 | if (sv->state & SRV_MAINTAIN) { |
| 2860 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2861 | chunk_appendf(&trash, "MAINT"); |
| 2862 | } |
| 2863 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2864 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2865 | chunk_appendf(&trash, "MAINT(via)"); |
| 2866 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2867 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2868 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2869 | chunk_appendf(&trash, |
| 2870 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2871 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2872 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2873 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2874 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2875 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2876 | chunk_appendf(&trash, |
| 2877 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 2878 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2879 | get_check_status_info(sv->check.status)); |
| 2880 | |
| 2881 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2882 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2883 | |
| 2884 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2885 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2886 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2887 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2888 | get_check_status_description(sv->check.status)); |
| 2889 | if (*sv->check.desc) { |
| 2890 | chunk_appendf(&trash, ": "); |
| 2891 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2892 | chunk_htmlencode(&trash, &src); |
| 2893 | } |
| 2894 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2895 | } |
| 2896 | else |
| 2897 | chunk_appendf(&trash, "</td><td>"); |
| 2898 | |
| 2899 | chunk_appendf(&trash, |
| 2900 | /* weight */ |
| 2901 | "</td><td class=ac>%d</td>" |
| 2902 | /* act, bck */ |
| 2903 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2904 | "", |
| 2905 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2906 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2907 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2908 | |
| 2909 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2910 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2911 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2912 | |
| 2913 | if (ref->observe) |
| 2914 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2915 | |
| 2916 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2917 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2918 | "<td>%lld</td><td>%s</td>" |
| 2919 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2920 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2921 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2922 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2923 | else if (sv != ref) { |
| 2924 | if (sv->state & SRV_MAINTAIN) |
| 2925 | chunk_appendf(&trash, |
| 2926 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2927 | ref->proxy->id, ref->id); |
| 2928 | else |
| 2929 | chunk_appendf(&trash, |
| 2930 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2931 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2932 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2933 | else |
| 2934 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2935 | |
| 2936 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2937 | if (sv->state & SRV_WARMINGUP) |
| 2938 | 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] | 2939 | else |
| 2940 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2941 | } |
| 2942 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2943 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2944 | "DOWN,", |
| 2945 | "DOWN %d/%d,", |
| 2946 | "UP %d/%d,", |
| 2947 | "UP,", |
| 2948 | "NOLB %d/%d,", |
| 2949 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2950 | "DRAIN %d/%d,", |
| 2951 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2952 | "no check," |
| 2953 | }; |
| 2954 | |
| 2955 | chunk_appendf(&trash, |
| 2956 | /* pxid, name */ |
| 2957 | "%s,%s," |
| 2958 | /* queue : current, max */ |
| 2959 | "%d,%d," |
| 2960 | /* sessions : current, max, limit, total */ |
| 2961 | "%d,%d,%s,%lld," |
| 2962 | /* bytes : in, out */ |
| 2963 | "%lld,%lld," |
| 2964 | /* denied: req, resp */ |
| 2965 | ",%lld," |
| 2966 | /* errors : request, connect, response */ |
| 2967 | ",%lld,%lld," |
| 2968 | /* warnings: retries, redispatches */ |
| 2969 | "%lld,%lld," |
| 2970 | "", |
| 2971 | px->id, sv->id, |
| 2972 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2973 | 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] | 2974 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2975 | sv->counters.failed_secu, |
| 2976 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2977 | sv->counters.retries, sv->counters.redispatches); |
| 2978 | |
| 2979 | /* status */ |
| 2980 | if (sv->state & SRV_MAINTAIN) |
| 2981 | chunk_appendf(&trash, "MAINT,"); |
| 2982 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2983 | chunk_appendf(&trash, "MAINT(via),"); |
| 2984 | else |
| 2985 | chunk_appendf(&trash, |
| 2986 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2987 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2988 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2989 | |
| 2990 | chunk_appendf(&trash, |
| 2991 | /* weight, active, backup */ |
| 2992 | "%d,%d,%d," |
| 2993 | "", |
| 2994 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2995 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2996 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2997 | |
| 2998 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2999 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3000 | chunk_appendf(&trash, |
| 3001 | "%lld,%lld,%d,%d,", |
| 3002 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3003 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3004 | else |
| 3005 | chunk_appendf(&trash, ",,,,"); |
| 3006 | |
| 3007 | /* queue limit, pid, iid, sid, */ |
| 3008 | chunk_appendf(&trash, |
| 3009 | "%s," |
| 3010 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3011 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3012 | relative_pid, px->uuid, sv->puid); |
| 3013 | |
| 3014 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3015 | if (sv->state & SRV_WARMINGUP) |
| 3016 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3017 | |
| 3018 | /* sessions: lbtot */ |
| 3019 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3020 | |
| 3021 | /* tracked */ |
| 3022 | if (sv->track) |
| 3023 | chunk_appendf(&trash, "%s/%s,", |
| 3024 | sv->track->proxy->id, sv->track->id); |
| 3025 | else |
| 3026 | chunk_appendf(&trash, ","); |
| 3027 | |
| 3028 | /* type */ |
| 3029 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3030 | |
| 3031 | /* rate */ |
| 3032 | chunk_appendf(&trash, "%u,,%u,", |
| 3033 | read_freq_ctr(&sv->sess_per_sec), |
| 3034 | sv->counters.sps_max); |
| 3035 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3036 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3037 | /* check_status */ |
| 3038 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3039 | |
| 3040 | /* check_code */ |
| 3041 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3042 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3043 | else |
| 3044 | chunk_appendf(&trash, ","); |
| 3045 | |
| 3046 | /* check_duration */ |
| 3047 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3048 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3049 | else |
| 3050 | chunk_appendf(&trash, ","); |
| 3051 | |
| 3052 | } |
| 3053 | else |
| 3054 | chunk_appendf(&trash, ",,,"); |
| 3055 | |
| 3056 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3057 | if (px->mode == PR_MODE_HTTP) { |
| 3058 | for (i=1; i<6; i++) |
| 3059 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3060 | |
| 3061 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3062 | } |
| 3063 | else |
| 3064 | chunk_appendf(&trash, ",,,,,,"); |
| 3065 | |
| 3066 | /* failed health analyses */ |
| 3067 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3068 | |
| 3069 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3070 | chunk_appendf(&trash, ",,,"); |
| 3071 | |
| 3072 | /* errors: cli_aborts, srv_aborts */ |
| 3073 | chunk_appendf(&trash, "%lld,%lld,", |
| 3074 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3075 | |
| 3076 | /* compression: in, out, bypassed, comp_rsp */ |
| 3077 | chunk_appendf(&trash, ",,,,"); |
| 3078 | |
| 3079 | /* finish with EOL */ |
| 3080 | chunk_appendf(&trash, "\n"); |
| 3081 | } |
| 3082 | return 1; |
| 3083 | } |
| 3084 | |
| 3085 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3086 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3087 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3088 | */ |
| 3089 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3090 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3091 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3092 | struct chunk src; |
| 3093 | int i; |
| 3094 | |
| 3095 | if (!(px->cap & PR_CAP_BE)) |
| 3096 | return 0; |
| 3097 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3098 | 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] | 3099 | return 0; |
| 3100 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3101 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3102 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3103 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3104 | /* Column sub-heading for Enable or Disable server */ |
| 3105 | chunk_appendf(&trash, "<td></td>"); |
| 3106 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3107 | chunk_appendf(&trash, |
| 3108 | "<td class=ac>" |
| 3109 | /* name */ |
| 3110 | "%s<a name=\"%s/Backend\"></a>" |
| 3111 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3112 | "", |
| 3113 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3114 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3115 | |
| 3116 | if (flags & ST_SHLGNDS) { |
| 3117 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3118 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3119 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3120 | |
| 3121 | /* cookie */ |
| 3122 | if (px->cookie_name) { |
| 3123 | chunk_appendf(&trash, ", cookie: '"); |
| 3124 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3125 | chunk_htmlencode(&trash, &src); |
| 3126 | chunk_appendf(&trash, "'"); |
| 3127 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3128 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3132 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3133 | /* queue : current, max */ |
| 3134 | "<td>%s</td><td>%s</td><td></td>" |
| 3135 | /* sessions rate : current, max, limit */ |
| 3136 | "<td>%s</td><td>%s</td><td></td>" |
| 3137 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3138 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3139 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3140 | 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] | 3141 | |
| 3142 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3143 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3144 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3145 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3146 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3147 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3148 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3149 | U2H(px->be_counters.cum_conn), |
| 3150 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3151 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3152 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3153 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3154 | chunk_appendf(&trash, |
| 3155 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3156 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3157 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3158 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3159 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3160 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3161 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3162 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3163 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3164 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3165 | U2H(px->be_counters.p.http.cum_req), |
| 3166 | U2H(px->be_counters.p.http.rsp[1]), |
| 3167 | U2H(px->be_counters.p.http.rsp[2]), |
| 3168 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3169 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3170 | (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] | 3171 | U2H(px->be_counters.p.http.rsp[3]), |
| 3172 | U2H(px->be_counters.p.http.rsp[4]), |
| 3173 | U2H(px->be_counters.p.http.rsp[5]), |
| 3174 | U2H(px->be_counters.p.http.rsp[0]), |
| 3175 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3179 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3180 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3181 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3182 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3183 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3184 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3185 | U2H(px->be_counters.cum_lbconn), |
| 3186 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3187 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3188 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3189 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3190 | "<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] | 3191 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3192 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3193 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3194 | px->be_counters.comp_in ? |
| 3195 | (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] | 3196 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3197 | |
| 3198 | chunk_appendf(&trash, |
| 3199 | /* denied: req, resp */ |
| 3200 | "<td>%s</td><td>%s</td>" |
| 3201 | /* errors : request, connect */ |
| 3202 | "<td></td><td>%s</td>" |
| 3203 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3204 | "<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] | 3205 | /* warnings: retries, redispatches */ |
| 3206 | "<td>%lld</td><td>%lld</td>" |
| 3207 | /* backend status: reflect backend status (up/down): we display UP |
| 3208 | * if the backend has known working servers or if it has no server at |
| 3209 | * all (eg: for stats). Then we display the total weight, number of |
| 3210 | * active and backups. */ |
| 3211 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3212 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3213 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3214 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3215 | U2H(px->be_counters.failed_conns), |
| 3216 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3217 | px->be_counters.cli_aborts, |
| 3218 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3219 | px->be_counters.retries, px->be_counters.redispatches, |
| 3220 | human_time(now.tv_sec - px->last_change, 1), |
| 3221 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3222 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3223 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3224 | px->srv_act, px->srv_bck); |
| 3225 | |
| 3226 | chunk_appendf(&trash, |
| 3227 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3228 | "<td class=ac> </td><td>%d</td>" |
| 3229 | "<td>%s</td>" |
| 3230 | "<td></td>" |
| 3231 | "</tr>", |
| 3232 | px->down_trans, |
| 3233 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3234 | } |
| 3235 | else { /* CSV mode */ |
| 3236 | chunk_appendf(&trash, |
| 3237 | /* pxid, name */ |
| 3238 | "%s,BACKEND," |
| 3239 | /* queue : current, max */ |
| 3240 | "%d,%d," |
| 3241 | /* sessions : current, max, limit, total */ |
| 3242 | "%d,%d,%d,%lld," |
| 3243 | /* bytes : in, out */ |
| 3244 | "%lld,%lld," |
| 3245 | /* denied: req, resp */ |
| 3246 | "%lld,%lld," |
| 3247 | /* errors : request, connect, response */ |
| 3248 | ",%lld,%lld," |
| 3249 | /* warnings: retries, redispatches */ |
| 3250 | "%lld,%lld," |
| 3251 | /* backend status: reflect backend status (up/down): we display UP |
| 3252 | * if the backend has known working servers or if it has no server at |
| 3253 | * all (eg: for stats). Then we display the total weight, number of |
| 3254 | * active and backups. */ |
| 3255 | "%s," |
| 3256 | "%d,%d,%d," |
| 3257 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3258 | ",%d,%d,%d,," |
| 3259 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3260 | "%d,%d,0,,%lld,,%d," |
| 3261 | /* rate, rate_lim, rate_max, */ |
| 3262 | "%u,,%u," |
| 3263 | /* check_status, check_code, check_duration */ |
| 3264 | ",,,", |
| 3265 | px->id, |
| 3266 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3267 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3268 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3269 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3270 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3271 | px->be_counters.retries, px->be_counters.redispatches, |
| 3272 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3273 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3274 | px->srv_act, px->srv_bck, |
| 3275 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3276 | px->srv?be_downtime(px):0, |
| 3277 | relative_pid, px->uuid, |
| 3278 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3279 | read_freq_ctr(&px->be_sess_per_sec), |
| 3280 | px->be_counters.sps_max); |
| 3281 | |
| 3282 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3283 | if (px->mode == PR_MODE_HTTP) { |
| 3284 | for (i=1; i<6; i++) |
| 3285 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3286 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3287 | } |
| 3288 | else |
| 3289 | chunk_appendf(&trash, ",,,,,,"); |
| 3290 | |
| 3291 | /* failed health analyses */ |
| 3292 | chunk_appendf(&trash, ","); |
| 3293 | |
| 3294 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3295 | chunk_appendf(&trash, ",,,"); |
| 3296 | |
| 3297 | /* errors: cli_aborts, srv_aborts */ |
| 3298 | chunk_appendf(&trash, "%lld,%lld,", |
| 3299 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3300 | |
| 3301 | /* compression: in, out, bypassed */ |
| 3302 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3303 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3304 | |
| 3305 | /* compression: comp_rsp */ |
| 3306 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3307 | |
| 3308 | /* finish with EOL */ |
| 3309 | chunk_appendf(&trash, "\n"); |
| 3310 | } |
| 3311 | return 1; |
| 3312 | } |
| 3313 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3314 | /* 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] | 3315 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3316 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3317 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3318 | 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] | 3319 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3320 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3321 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3322 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3323 | 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] | 3324 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3325 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3326 | /* 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] | 3327 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3328 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3329 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3330 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3331 | 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] | 3332 | } |
| 3333 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3334 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3335 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3336 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3337 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3338 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3339 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | /* print a new table */ |
| 3343 | chunk_appendf(&trash, |
| 3344 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3345 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3346 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3347 | |
| 3348 | chunk_appendf(&trash, |
| 3349 | "<a name=\"%s\"></a>%s" |
| 3350 | "<a class=px href=\"#%s\">%s</a>", |
| 3351 | px->id, |
| 3352 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3353 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3354 | |
| 3355 | if (uri->flags & ST_SHLGNDS) { |
| 3356 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3357 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3358 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3359 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3360 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3364 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3365 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3366 | "</tr>\n" |
| 3367 | "</table>\n" |
| 3368 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3369 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3370 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3371 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3372 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3373 | 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] | 3374 | /* Column heading for Enable or Disable server */ |
| 3375 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3376 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3377 | |
| 3378 | chunk_appendf(&trash, |
| 3379 | "<th rowspan=2></th>" |
| 3380 | "<th colspan=3>Queue</th>" |
| 3381 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
| 3382 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3383 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3384 | "<th colspan=9>Server</th>" |
| 3385 | "</tr>\n" |
| 3386 | "<tr class=\"titre\">" |
| 3387 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3388 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 3389 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
| 3390 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3391 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3392 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3393 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3394 | "<th>Thrtle</th>\n" |
| 3395 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3396 | } |
| 3397 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3398 | /* 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] | 3399 | * 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] | 3400 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3401 | 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] | 3402 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3403 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3404 | chunk_appendf(&trash, "</table>"); |
| 3405 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3406 | 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] | 3407 | /* close the form used to enable/disable this proxy servers */ |
| 3408 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3409 | "Choose the action to perform on the checked servers : " |
| 3410 | "<select name=action>" |
| 3411 | "<option value=\"\"></option>" |
| 3412 | "<option value=\"disable\">Disable</option>" |
| 3413 | "<option value=\"enable\">Enable</option>" |
| 3414 | "<option value=\"stop\">Soft Stop</option>" |
| 3415 | "<option value=\"start\">Soft Start</option>" |
| 3416 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3417 | "</select>" |
| 3418 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3419 | " <input type=\"submit\" value=\"Apply\">" |
| 3420 | "</form>", |
| 3421 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3425 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3426 | |
| 3427 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3428 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3429 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3430 | * buffer space, or non-zero if everything completed. This function is used |
| 3431 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3432 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3433 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3434 | 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] | 3435 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3436 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3437 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3438 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3439 | 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] | 3440 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3441 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3442 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3443 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3444 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3445 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3446 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3447 | if (uri && uri->scope) { |
| 3448 | /* we have a limited scope, we have to check the proxy name */ |
| 3449 | struct stat_scope *scope; |
| 3450 | int len; |
| 3451 | |
| 3452 | len = strlen(px->id); |
| 3453 | scope = uri->scope; |
| 3454 | |
| 3455 | while (scope) { |
| 3456 | /* match exact proxy name */ |
| 3457 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3458 | break; |
| 3459 | |
| 3460 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3461 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3462 | break; |
| 3463 | scope = scope->next; |
| 3464 | } |
| 3465 | |
| 3466 | /* proxy name not found : don't dump anything */ |
| 3467 | if (scope == NULL) |
| 3468 | return 1; |
| 3469 | } |
| 3470 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3471 | /* if the user has requested a limited output and the proxy |
| 3472 | * name does not match, skip it. |
| 3473 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3474 | if (appctx->ctx.stats.scope_len && |
| 3475 | 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] | 3476 | return 1; |
| 3477 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3478 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3479 | (appctx->ctx.stats.iid != -1) && |
| 3480 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3481 | return 1; |
| 3482 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3483 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3484 | /* fall through */ |
| 3485 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3486 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3487 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3488 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3489 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3490 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3491 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3492 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3493 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3494 | /* fall through */ |
| 3495 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3496 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3497 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3498 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3499 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3500 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3501 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3502 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3503 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3504 | /* fall through */ |
| 3505 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3506 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3507 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3508 | 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] | 3509 | if (buffer_almost_full(rep->buf)) { |
| 3510 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3511 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3512 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3513 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3514 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3515 | if (!l->counters) |
| 3516 | continue; |
| 3517 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3518 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3519 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3520 | break; |
| 3521 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3522 | 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] | 3523 | continue; |
| 3524 | } |
| 3525 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3526 | /* print the frontend */ |
| 3527 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3528 | if (bi_putchk(rep, &trash) == -1) |
| 3529 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3530 | } |
| 3531 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3532 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3533 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3534 | /* fall through */ |
| 3535 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3536 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3537 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3538 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3539 | 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] | 3540 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3541 | if (buffer_almost_full(rep->buf)) { |
| 3542 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3543 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3544 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3545 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3546 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3547 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3548 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3549 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3550 | break; |
| 3551 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3552 | 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] | 3553 | continue; |
| 3554 | } |
| 3555 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3556 | if (sv->track) |
| 3557 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3558 | else |
| 3559 | svs = sv; |
| 3560 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3561 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3562 | if (!(svs->check.state & CHK_ST_ENABLED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3563 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3564 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 3565 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3566 | sv_state = 3; /* UP */ |
| 3567 | else |
| 3568 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3569 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3570 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3571 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3572 | else if (svs->state & SRV_GOINGDOWN) |
| 3573 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3574 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3575 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 3576 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3577 | sv_state = 1; /* going up */ |
| 3578 | else |
| 3579 | sv_state = 0; /* DOWN */ |
| 3580 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3581 | 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] | 3582 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3583 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3584 | continue; |
| 3585 | } |
| 3586 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3587 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3588 | if (bi_putchk(rep, &trash) == -1) |
| 3589 | return 0; |
| 3590 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3591 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3592 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3593 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3594 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3595 | case STAT_PX_ST_BE: |
| 3596 | /* print the backend */ |
| 3597 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3598 | if (bi_putchk(rep, &trash) == -1) |
| 3599 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3600 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3601 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3602 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3603 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3604 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3605 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3606 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3607 | if (bi_putchk(rep, &trash) == -1) |
| 3608 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3609 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3610 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3611 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3612 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3613 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3614 | case STAT_PX_ST_FIN: |
| 3615 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3616 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3617 | default: |
| 3618 | /* unknown state, we should put an abort() here ! */ |
| 3619 | return 1; |
| 3620 | } |
| 3621 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3622 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3623 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3624 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3625 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3626 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3627 | { |
| 3628 | /* WARNING! This must fit in the first buffer !!! */ |
| 3629 | chunk_appendf(&trash, |
| 3630 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3631 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3632 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3633 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3634 | "<style type=\"text/css\"><!--\n" |
| 3635 | "body {" |
| 3636 | " font-family: arial, helvetica, sans-serif;" |
| 3637 | " font-size: 12px;" |
| 3638 | " font-weight: normal;" |
| 3639 | " color: black;" |
| 3640 | " background: white;" |
| 3641 | "}\n" |
| 3642 | "th,td {" |
| 3643 | " font-size: 10px;" |
| 3644 | "}\n" |
| 3645 | "h1 {" |
| 3646 | " font-size: x-large;" |
| 3647 | " margin-bottom: 0.5em;" |
| 3648 | "}\n" |
| 3649 | "h2 {" |
| 3650 | " font-family: helvetica, arial;" |
| 3651 | " font-size: x-large;" |
| 3652 | " font-weight: bold;" |
| 3653 | " font-style: italic;" |
| 3654 | " color: #6020a0;" |
| 3655 | " margin-top: 0em;" |
| 3656 | " margin-bottom: 0em;" |
| 3657 | "}\n" |
| 3658 | "h3 {" |
| 3659 | " font-family: helvetica, arial;" |
| 3660 | " font-size: 16px;" |
| 3661 | " font-weight: bold;" |
| 3662 | " color: #b00040;" |
| 3663 | " background: #e8e8d0;" |
| 3664 | " margin-top: 0em;" |
| 3665 | " margin-bottom: 0em;" |
| 3666 | "}\n" |
| 3667 | "li {" |
| 3668 | " margin-top: 0.25em;" |
| 3669 | " margin-right: 2em;" |
| 3670 | "}\n" |
| 3671 | ".hr {margin-top: 0.25em;" |
| 3672 | " border-color: black;" |
| 3673 | " border-bottom-style: solid;" |
| 3674 | "}\n" |
| 3675 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3676 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3677 | ".frontend {background: #e8e8d0;}\n" |
| 3678 | ".socket {background: #d0d0d0;}\n" |
| 3679 | ".backend {background: #e8e8d0;}\n" |
| 3680 | ".active0 {background: #ff9090;}\n" |
| 3681 | ".active1 {background: #ffd020;}\n" |
| 3682 | ".active2 {background: #ffffa0;}\n" |
| 3683 | ".active3 {background: #c0ffc0;}\n" |
| 3684 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3685 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3686 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3687 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3688 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3689 | ".backup0 {background: #ff9090;}\n" |
| 3690 | ".backup1 {background: #ff80ff;}\n" |
| 3691 | ".backup2 {background: #c060ff;}\n" |
| 3692 | ".backup3 {background: #b0d0ff;}\n" |
| 3693 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3694 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3695 | ".backup6 {background: #c060ff;}\n" |
| 3696 | ".backup7 {background: #cc9900;}\n" |
| 3697 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3698 | ".maintain {background: #c07820;}\n" |
| 3699 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3700 | "\n" |
| 3701 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3702 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3703 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3704 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3705 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3706 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3707 | "\n" |
| 3708 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3709 | "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" |
| 3710 | "table.tbl td.ac { text-align: center;}\n" |
| 3711 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3712 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3713 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3714 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3715 | "\n" |
| 3716 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3717 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3718 | "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] | 3719 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3720 | "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] | 3721 | "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] | 3722 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3723 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3724 | " display:block;\n" |
| 3725 | " visibility:hidden;\n" |
| 3726 | " z-index:2147483647;\n" |
| 3727 | " position:absolute;\n" |
| 3728 | " padding:2px 4px 3px;\n" |
| 3729 | " background:#f0f060; color:#000000;\n" |
| 3730 | " border:1px solid #7040c0;\n" |
| 3731 | " white-space:nowrap;\n" |
| 3732 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3733 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3734 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3735 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3736 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3737 | "-->\n" |
| 3738 | "</style></head>\n", |
| 3739 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3740 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3741 | ); |
| 3742 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3743 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3744 | /* 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] | 3745 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3746 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3747 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3748 | 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] | 3749 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3750 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3751 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3752 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3753 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3754 | /* WARNING! this has to fit the first packet too. |
| 3755 | * We are around 3.5 kB, add adding entries will |
| 3756 | * become tricky if we want to support 4kB buffers ! |
| 3757 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3758 | chunk_appendf(&trash, |
| 3759 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3760 | PRODUCT_NAME "%s</a></h1>\n" |
| 3761 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3762 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3763 | "<h3>> General process information</h3>\n" |
| 3764 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3765 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3766 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3767 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3768 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3769 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3770 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3771 | "</td><td align=\"center\" nowrap>\n" |
| 3772 | "<table class=\"lgd\"><tr>\n" |
| 3773 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3774 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3775 | "</tr><tr>\n" |
| 3776 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3777 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3778 | "</tr><tr>\n" |
| 3779 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3780 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3781 | "</tr><tr>\n" |
| 3782 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3783 | "</tr><tr>\n" |
| 3784 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3785 | "</tr><tr>\n" |
| 3786 | "<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] | 3787 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3788 | "<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] | 3789 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3790 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3791 | "</td>" |
| 3792 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3793 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3794 | "", |
| 3795 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3796 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3797 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3798 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3799 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3800 | pid, relative_pid, global.nbproc, |
| 3801 | up / 86400, (up % 86400) / 3600, |
| 3802 | (up % 3600) / 60, (up % 60), |
| 3803 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3804 | global.rlimit_memmax ? " MB" : "", |
| 3805 | global.rlimit_nofile, |
| 3806 | global.maxsock, global.maxconn, global.maxpipes, |
| 3807 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3808 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3809 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3810 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3811 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3812 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3813 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3814 | |
| 3815 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3816 | "<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] | 3817 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3818 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3819 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3820 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3821 | STAT_SCOPE_TXT_MAXLEN); |
| 3822 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3823 | /* 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] | 3824 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3825 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3826 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3827 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3828 | 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] | 3829 | } |
| 3830 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3831 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3832 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3833 | "<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] | 3834 | uri->uri_prefix, |
| 3835 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3836 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3837 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3838 | else |
| 3839 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3840 | "<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] | 3841 | uri->uri_prefix, |
| 3842 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3843 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3844 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3845 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3846 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3847 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3848 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3849 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3850 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3851 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3852 | "", |
| 3853 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3854 | else |
| 3855 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3856 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3857 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3858 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3859 | ";norefresh", |
| 3860 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3861 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3862 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3863 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3864 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3865 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3866 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3867 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3868 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3869 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3870 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3871 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3872 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3873 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3874 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3875 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3876 | chunk_appendf(&trash, |
| 3877 | "</ul></td>" |
| 3878 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3879 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3880 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3881 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3882 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3883 | "</ul>" |
| 3884 | "</td>" |
| 3885 | "</tr></table>\n" |
| 3886 | "" |
| 3887 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3888 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3889 | if (appctx->ctx.stats.st_code) { |
| 3890 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3891 | case STAT_STATUS_DONE: |
| 3892 | chunk_appendf(&trash, |
| 3893 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3894 | "<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] | 3895 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3896 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3897 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3898 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3899 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3900 | break; |
| 3901 | case STAT_STATUS_NONE: |
| 3902 | chunk_appendf(&trash, |
| 3903 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3904 | "<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] | 3905 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3906 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3907 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3908 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3909 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3910 | break; |
| 3911 | case STAT_STATUS_PART: |
| 3912 | chunk_appendf(&trash, |
| 3913 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3914 | "<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] | 3915 | "Action partially processed.<br>" |
| 3916 | "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] | 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_ERRP: |
| 3923 | chunk_appendf(&trash, |
| 3924 | "<p><div class=active0>" |
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 not processed because of invalid parameters." |
| 3927 | "<ul>" |
| 3928 | "<li>The action is maybe unknown.</li>" |
| 3929 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3930 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3931 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3932 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3933 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3934 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3935 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3936 | break; |
| 3937 | case STAT_STATUS_EXCD: |
| 3938 | chunk_appendf(&trash, |
| 3939 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3940 | "<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] | 3941 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3942 | "You should retry with less servers at a time.</b>" |
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_DENY: |
| 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 denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3953 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3954 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3955 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3956 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3957 | break; |
| 3958 | default: |
| 3959 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3960 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3961 | "<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] | 3962 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3963 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3964 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3965 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3966 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3967 | } |
| 3968 | chunk_appendf(&trash, "<p>\n"); |
| 3969 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3970 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3971 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3972 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3973 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3974 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3975 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3976 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3977 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3978 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3979 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3980 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3981 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3982 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3983 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3984 | * and the session must be closed, or -1 in case of any error. This function is |
| 3985 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3986 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3987 | 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] | 3988 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3989 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3990 | struct channel *rep = si->ib; |
| 3991 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3992 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3993 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3994 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3995 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3996 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3997 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3998 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3999 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4000 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4001 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4002 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4003 | else |
| 4004 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4005 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4006 | if (bi_putchk(rep, &trash) == -1) |
| 4007 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4008 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4009 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4010 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4011 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4012 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4013 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4014 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4015 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4016 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4017 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4018 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4019 | appctx->ctx.stats.px = proxy; |
| 4020 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4021 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4022 | /* fall through */ |
| 4023 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4024 | case STAT_ST_LIST: |
| 4025 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4026 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4027 | if (buffer_almost_full(rep->buf)) { |
| 4028 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4029 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4030 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4031 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4032 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4033 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4034 | 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] | 4035 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4036 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4037 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4038 | appctx->ctx.stats.px = px->next; |
| 4039 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4040 | } |
| 4041 | /* here, we just have reached the last proxy */ |
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 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4044 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4045 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4046 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4047 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4048 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4049 | if (bi_putchk(rep, &trash) == -1) |
| 4050 | return 0; |
| 4051 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4052 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4053 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4054 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4055 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4056 | case STAT_ST_FIN: |
| 4057 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4058 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4059 | default: |
| 4060 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4061 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4062 | return -1; |
| 4063 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4064 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4065 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4066 | /* We reached the stats page through a POST request. The appctx is |
| 4067 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4068 | * Parse the posted data and enable/disable servers if necessary. |
| 4069 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4070 | */ |
| 4071 | static int stats_process_http_post(struct stream_interface *si) |
| 4072 | { |
| 4073 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4074 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4075 | |
| 4076 | struct proxy *px = NULL; |
| 4077 | struct server *sv = NULL; |
| 4078 | |
| 4079 | char key[LINESIZE]; |
| 4080 | int action = ST_ADM_ACTION_NONE; |
| 4081 | int reprocess = 0; |
| 4082 | |
| 4083 | int total_servers = 0; |
| 4084 | int altered_servers = 0; |
| 4085 | |
| 4086 | char *first_param, *cur_param, *next_param, *end_params; |
| 4087 | char *st_cur_param = NULL; |
| 4088 | char *st_next_param = NULL; |
| 4089 | |
| 4090 | struct chunk *temp; |
| 4091 | int reql; |
| 4092 | |
| 4093 | temp = get_trash_chunk(); |
| 4094 | if (temp->size < s->txn.req.body_len) { |
| 4095 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4096 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4097 | goto out; |
| 4098 | } |
| 4099 | |
| 4100 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 4101 | if (reql <= 0) { |
| 4102 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4103 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4104 | return 0; |
| 4105 | } |
| 4106 | |
| 4107 | first_param = temp->str; |
| 4108 | end_params = temp->str + reql; |
| 4109 | cur_param = next_param = end_params; |
| 4110 | *end_params = '\0'; |
| 4111 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4112 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4113 | |
| 4114 | /* |
| 4115 | * Parse the parameters in reverse order to only store the last value. |
| 4116 | * From the html form, the backend and the action are at the end. |
| 4117 | */ |
| 4118 | while (cur_param > first_param) { |
| 4119 | char *value; |
| 4120 | int poffset, plen; |
| 4121 | |
| 4122 | cur_param--; |
| 4123 | |
| 4124 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4125 | reprocess_servers: |
| 4126 | /* Parse the key */ |
| 4127 | poffset = (cur_param != first_param ? 1 : 0); |
| 4128 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4129 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4130 | strncpy(key, cur_param + poffset, plen); |
| 4131 | key[plen - 1] = '\0'; |
| 4132 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4133 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4134 | goto out; |
| 4135 | } |
| 4136 | |
| 4137 | /* Parse the value */ |
| 4138 | value = key; |
| 4139 | while (*value != '\0' && *value != '=') { |
| 4140 | value++; |
| 4141 | } |
| 4142 | if (*value == '=') { |
| 4143 | /* Ok, a value is found, we can mark the end of the key */ |
| 4144 | *value++ = '\0'; |
| 4145 | } |
| 4146 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4147 | break; |
| 4148 | |
| 4149 | /* Now we can check the key to see what to do */ |
| 4150 | if (!px && (strcmp(key, "b") == 0)) { |
| 4151 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4152 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4153 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4154 | goto out; |
| 4155 | } |
| 4156 | } |
| 4157 | else if (!action && (strcmp(key, "action") == 0)) { |
| 4158 | if (strcmp(value, "disable") == 0) { |
| 4159 | action = ST_ADM_ACTION_DISABLE; |
| 4160 | } |
| 4161 | else if (strcmp(value, "enable") == 0) { |
| 4162 | action = ST_ADM_ACTION_ENABLE; |
| 4163 | } |
| 4164 | else if (strcmp(value, "stop") == 0) { |
| 4165 | action = ST_ADM_ACTION_STOP; |
| 4166 | } |
| 4167 | else if (strcmp(value, "start") == 0) { |
| 4168 | action = ST_ADM_ACTION_START; |
| 4169 | } |
| 4170 | else if (strcmp(value, "shutdown") == 0) { |
| 4171 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4172 | } |
| 4173 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4174 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4175 | goto out; |
| 4176 | } |
| 4177 | } |
| 4178 | else if (strcmp(key, "s") == 0) { |
| 4179 | if (!(px && action)) { |
| 4180 | /* |
| 4181 | * Indicates that we'll need to reprocess the parameters |
| 4182 | * as soon as backend and action are known |
| 4183 | */ |
| 4184 | if (!reprocess) { |
| 4185 | st_cur_param = cur_param; |
| 4186 | st_next_param = next_param; |
| 4187 | } |
| 4188 | reprocess = 1; |
| 4189 | } |
| 4190 | else if ((sv = findserver(px, value)) != NULL) { |
| 4191 | switch (action) { |
| 4192 | case ST_ADM_ACTION_DISABLE: |
| 4193 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 4194 | /* Not already in maintenance, we can change the server state */ |
| 4195 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 4196 | sv->check.state |= CHK_ST_PAUSED; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4197 | set_server_down(&sv->check); |
| 4198 | altered_servers++; |
| 4199 | total_servers++; |
| 4200 | } |
| 4201 | break; |
| 4202 | case ST_ADM_ACTION_ENABLE: |
| 4203 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
Willy Tarreau | a3ae932 | 2013-12-28 21:28:49 +0100 | [diff] [blame] | 4204 | /* Already in maintenance, we can change the server state. |
| 4205 | * If this server tracks the status of another one, |
| 4206 | * we must restore the good status. |
| 4207 | */ |
| 4208 | if (!sv->track || (sv->track->state & SRV_RUNNING)) { |
| 4209 | set_server_up(&sv->check); |
| 4210 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 4211 | } |
| 4212 | else { |
| 4213 | sv->state &= ~SRV_MAINTAIN; |
| 4214 | sv->check.state &= ~CHK_ST_PAUSED; |
| 4215 | set_server_down(&sv->check); |
| 4216 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4217 | altered_servers++; |
| 4218 | total_servers++; |
| 4219 | } |
| 4220 | break; |
| 4221 | case ST_ADM_ACTION_STOP: |
| 4222 | case ST_ADM_ACTION_START: |
| 4223 | if (action == ST_ADM_ACTION_START) |
| 4224 | sv->uweight = sv->iweight; |
| 4225 | else |
| 4226 | sv->uweight = 0; |
| 4227 | |
| 4228 | server_recalc_eweight(sv); |
| 4229 | set_server_drain_state(sv); |
| 4230 | |
| 4231 | altered_servers++; |
| 4232 | total_servers++; |
| 4233 | break; |
| 4234 | case ST_ADM_ACTION_SHUTDOWN: |
| 4235 | if (px->state != PR_STSTOPPED) { |
| 4236 | struct session *sess, *sess_bck; |
| 4237 | |
| 4238 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4239 | if (sess->srv_conn == sv) |
| 4240 | session_shutdown(sess, SN_ERR_KILLED); |
| 4241 | |
| 4242 | altered_servers++; |
| 4243 | total_servers++; |
| 4244 | } |
| 4245 | break; |
| 4246 | } |
| 4247 | } else { |
| 4248 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4249 | total_servers++; |
| 4250 | } |
| 4251 | } |
| 4252 | if (reprocess && px && action) { |
| 4253 | /* Now, we know the backend and the action chosen by the user. |
| 4254 | * We can safely restart from the first server parameter |
| 4255 | * to reprocess them |
| 4256 | */ |
| 4257 | cur_param = st_cur_param; |
| 4258 | next_param = st_next_param; |
| 4259 | reprocess = 0; |
| 4260 | goto reprocess_servers; |
| 4261 | } |
| 4262 | |
| 4263 | next_param = cur_param; |
| 4264 | } |
| 4265 | } |
| 4266 | |
| 4267 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4268 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4269 | } |
| 4270 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4271 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4272 | } |
| 4273 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4274 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4275 | } |
| 4276 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4277 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4278 | } |
| 4279 | out: |
| 4280 | return 1; |
| 4281 | } |
| 4282 | |
| 4283 | |
| 4284 | static int stats_send_http_headers(struct stream_interface *si) |
| 4285 | { |
| 4286 | struct session *s = session_from_task(si->owner); |
| 4287 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4288 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4289 | |
| 4290 | chunk_printf(&trash, |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4291 | "HTTP/1.0 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4292 | "Cache-Control: no-cache\r\n" |
| 4293 | "Connection: close\r\n" |
| 4294 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4295 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4296 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4297 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4298 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4299 | uri->refresh); |
| 4300 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4301 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4302 | |
| 4303 | s->txn.status = 200; |
| 4304 | s->logs.tv_request = now; |
| 4305 | |
| 4306 | if (bi_putchk(si->ib, &trash) == -1) |
| 4307 | return 0; |
| 4308 | |
| 4309 | return 1; |
| 4310 | } |
| 4311 | |
| 4312 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4313 | { |
| 4314 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4315 | struct session *s = session_from_task(si->owner); |
| 4316 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4317 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4318 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4319 | /* 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] | 4320 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4321 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4322 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4323 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4324 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | /* We don't want to land on the posted stats page because a refresh will |
| 4328 | * repost the data. We don't want this to happen on accident so we redirect |
| 4329 | * the browse to the stats page with a GET. |
| 4330 | */ |
| 4331 | chunk_printf(&trash, |
| 4332 | "HTTP/1.1 303 See Other\r\n" |
| 4333 | "Cache-Control: no-cache\r\n" |
| 4334 | "Content-Type: text/plain\r\n" |
| 4335 | "Connection: close\r\n" |
| 4336 | "Location: %s;st=%s%s%s%s\r\n" |
| 4337 | "\r\n", |
| 4338 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4339 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4340 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4341 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4342 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4343 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4344 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4345 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4346 | scope_txt); |
| 4347 | |
| 4348 | s->txn.status = 303; |
| 4349 | s->logs.tv_request = now; |
| 4350 | |
| 4351 | if (bi_putchk(si->ib, &trash) == -1) |
| 4352 | return 0; |
| 4353 | |
| 4354 | return 1; |
| 4355 | } |
| 4356 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4357 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4358 | * 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] | 4359 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4360 | * automatically unregisters itself once transfer is complete. |
| 4361 | */ |
| 4362 | static void http_stats_io_handler(struct stream_interface *si) |
| 4363 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4364 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4365 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4366 | struct channel *req = si->ob; |
| 4367 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4368 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4369 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4370 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4371 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4372 | /* check that the output is not closed */ |
| 4373 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4374 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4375 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4376 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4377 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4378 | if (stats_send_http_headers(si)) { |
| 4379 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4380 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4381 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4382 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4383 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4384 | } |
| 4385 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4386 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4387 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4388 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4389 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4390 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4391 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4392 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4393 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4394 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4395 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4396 | } |
| 4397 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4398 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4399 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4400 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4401 | } |
| 4402 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4403 | if (appctx->st0 == STAT_HTTP_DONE) |
| 4404 | si_shutw(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4405 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4406 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4407 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4408 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4409 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4410 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4411 | si_shutr(si); |
| 4412 | res->flags |= CF_READ_NULL; |
| 4413 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4414 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4415 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4416 | /* update all other flags and resync with the other side */ |
| 4417 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4418 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4419 | /* we don't want to expire timeouts while we're processing requests */ |
| 4420 | si->ib->rex = TICK_ETERNITY; |
| 4421 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4422 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4423 | out: |
| 4424 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4425 | /* check that we have released everything then unregister */ |
| 4426 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4427 | } |
| 4428 | } |
| 4429 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4430 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4431 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4432 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4433 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4434 | return "NONE"; |
| 4435 | return conn->ctrl->name; |
| 4436 | } |
| 4437 | |
| 4438 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4439 | { |
| 4440 | static char ptr[17]; |
| 4441 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4442 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4443 | return "NONE"; |
| 4444 | |
| 4445 | if (conn->xprt == &raw_sock) |
| 4446 | return "RAW"; |
| 4447 | |
| 4448 | #ifdef USE_OPENSSL |
| 4449 | if (conn->xprt == &ssl_sock) |
| 4450 | return "SSL"; |
| 4451 | #endif |
| 4452 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4453 | return ptr; |
| 4454 | } |
| 4455 | |
| 4456 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4457 | { |
| 4458 | static char ptr[17]; |
| 4459 | |
| 4460 | if (!conn->data) |
| 4461 | return "NONE"; |
| 4462 | |
| 4463 | if (conn->data == &sess_conn_cb) |
| 4464 | return "SESS"; |
| 4465 | |
| 4466 | if (conn->data == &si_conn_cb) |
| 4467 | return "STRM"; |
| 4468 | |
| 4469 | if (conn->data == &check_conn_cb) |
| 4470 | return "CHCK"; |
| 4471 | |
| 4472 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4473 | return ptr; |
| 4474 | } |
| 4475 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4476 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4477 | * 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] | 4478 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4479 | * 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] | 4480 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4481 | 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] | 4482 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4483 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4484 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4485 | extern const char *monthname[12]; |
| 4486 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4487 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4488 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4489 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4490 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4491 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4492 | 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] | 4493 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4494 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4495 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4496 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4497 | appctx->ctx.sess.uid = 0; |
| 4498 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4499 | return 1; |
| 4500 | } |
| 4501 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4502 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4503 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4504 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4505 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4506 | /* fall through */ |
| 4507 | |
| 4508 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4509 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4510 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4511 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4512 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4513 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4514 | 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] | 4515 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 4516 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4517 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4518 | conn = objt_conn(sess->si[0].end); |
| 4519 | 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] | 4520 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4521 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4522 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4523 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4524 | break; |
| 4525 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4526 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4527 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4528 | default: |
| 4529 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4530 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4531 | break; |
| 4532 | } |
| 4533 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4534 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4535 | " 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] | 4536 | 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] | 4537 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4538 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4539 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4540 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 4541 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 4542 | sess->listener ? sess->listener->luid : 0); |
| 4543 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4544 | if (conn) |
| 4545 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4546 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4547 | switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4548 | case AF_INET: |
| 4549 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4550 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4551 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4552 | break; |
| 4553 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4554 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4555 | break; |
| 4556 | default: |
| 4557 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4558 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4559 | break; |
| 4560 | } |
| 4561 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4562 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4563 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4564 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4565 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4566 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 4567 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4568 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4569 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4570 | conn = objt_conn(sess->si[1].end); |
| 4571 | if (conn) |
| 4572 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4573 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4574 | 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] | 4575 | case AF_INET: |
| 4576 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4577 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4578 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4579 | break; |
| 4580 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4581 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4582 | break; |
| 4583 | default: |
| 4584 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4585 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4586 | break; |
| 4587 | } |
| 4588 | |
| 4589 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4590 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4591 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4592 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 4593 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4594 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4595 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4596 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4597 | if (conn) |
| 4598 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4599 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4600 | 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] | 4601 | case AF_INET: |
| 4602 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4603 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4604 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4605 | break; |
| 4606 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4607 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4608 | break; |
| 4609 | default: |
| 4610 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4611 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4612 | break; |
| 4613 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4614 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4615 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4616 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4617 | sess->task, |
| 4618 | sess->task->state, |
| 4619 | sess->task->nice, sess->task->calls, |
| 4620 | sess->task->expire ? |
| 4621 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4622 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4623 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4624 | task_in_rq(sess->task) ? ", running" : ""); |
| 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 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4628 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4629 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4630 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4631 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4632 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4633 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4634 | |
| 4635 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4636 | " 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] | 4637 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4638 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4639 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4640 | obj_type_name(sess->si[0].end), |
| 4641 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4642 | sess->si[0].exp ? |
| 4643 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4644 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4645 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4646 | sess->si[0].err_type); |
| 4647 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4648 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4649 | " 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] | 4650 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4651 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4652 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4653 | obj_type_name(sess->si[1].end), |
| 4654 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4655 | sess->si[1].exp ? |
| 4656 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4657 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4658 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4659 | sess->si[1].err_type); |
| 4660 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4661 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4662 | chunk_appendf(&trash, |
| 4663 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4664 | conn, |
| 4665 | get_conn_ctrl_name(conn), |
| 4666 | get_conn_xprt_name(conn), |
| 4667 | get_conn_data_name(conn), |
| 4668 | obj_type_name(conn->target), |
| 4669 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4670 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4671 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 4672 | " 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] | 4673 | conn->flags, |
| 4674 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4675 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4676 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4677 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4678 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4679 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 4680 | chunk_appendf(&trash, |
| 4681 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4682 | tmpctx, |
| 4683 | tmpctx->st0, |
| 4684 | tmpctx->st1, |
| 4685 | tmpctx->st2, |
| 4686 | tmpctx->applet->name); |
| 4687 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4688 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4689 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4690 | chunk_appendf(&trash, |
| 4691 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4692 | conn, |
| 4693 | get_conn_ctrl_name(conn), |
| 4694 | get_conn_xprt_name(conn), |
| 4695 | get_conn_data_name(conn), |
| 4696 | obj_type_name(conn->target), |
| 4697 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4698 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4699 | chunk_appendf(&trash, |
| 4700 | " 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] | 4701 | conn->flags, |
| 4702 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4703 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4704 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4705 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4706 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4707 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 4708 | chunk_appendf(&trash, |
| 4709 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4710 | tmpctx, |
| 4711 | tmpctx->st0, |
| 4712 | tmpctx->st1, |
| 4713 | tmpctx->st2, |
| 4714 | tmpctx->applet->name); |
| 4715 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4716 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4717 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4718 | " 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] | 4719 | " an_exp=%s", |
| 4720 | sess->req, |
| 4721 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4722 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4723 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4724 | sess->req->analyse_exp ? |
| 4725 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4726 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4727 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4728 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4729 | " rex=%s", |
| 4730 | sess->req->rex ? |
| 4731 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4732 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4733 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4734 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4735 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4736 | " 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] | 4737 | sess->req->wex ? |
| 4738 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4739 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4740 | sess->req->buf, |
| 4741 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4742 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4743 | sess->txn.req.next, sess->req->buf->i, |
| 4744 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4745 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4746 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4747 | " 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] | 4748 | " an_exp=%s", |
| 4749 | sess->rep, |
| 4750 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4751 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4752 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4753 | sess->rep->analyse_exp ? |
| 4754 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4755 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4756 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4757 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4758 | " rex=%s", |
| 4759 | sess->rep->rex ? |
| 4760 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4761 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4762 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4763 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4764 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4765 | " 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] | 4766 | sess->rep->wex ? |
| 4767 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4768 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4769 | sess->rep->buf, |
| 4770 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4771 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4772 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4773 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4774 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4775 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4776 | return 0; |
| 4777 | |
| 4778 | /* use other states to dump the contents */ |
| 4779 | } |
| 4780 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4781 | appctx->ctx.sess.uid = 0; |
| 4782 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4783 | return 1; |
| 4784 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4785 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4786 | static int stats_maps_list(struct stream_interface *si) |
| 4787 | { |
| 4788 | struct appctx *appctx = __objt_appctx(si->end); |
| 4789 | |
| 4790 | switch (appctx->st2) { |
| 4791 | case STAT_ST_INIT: |
| 4792 | /* Init to the first entry. The list cannot be change */ |
| 4793 | appctx->ctx.map.ref = LIST_NEXT(&maps, struct map_reference *, list); |
| 4794 | appctx->st2 = STAT_ST_LIST; |
| 4795 | /* fall through */ |
| 4796 | |
| 4797 | case STAT_ST_LIST: |
| 4798 | while (appctx->ctx.map.ref) { |
| 4799 | |
| 4800 | chunk_reset(&trash); |
| 4801 | |
| 4802 | /* build messages */ |
| 4803 | chunk_appendf(&trash, "%s\n", appctx->ctx.map.ref->reference); |
| 4804 | |
| 4805 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4806 | /* let's try again later from this session. We add ourselves into |
| 4807 | * this session's users so that it can remove us upon termination. |
| 4808 | */ |
| 4809 | return 0; |
| 4810 | } |
| 4811 | |
| 4812 | /* get next list entry and check the end of the list */ |
| 4813 | appctx->ctx.map.ref = LIST_NEXT(&appctx->ctx.map.ref->list, |
| 4814 | struct map_reference *, list); |
| 4815 | if (&appctx->ctx.map.ref->list == &maps) |
| 4816 | break; |
| 4817 | } |
| 4818 | |
| 4819 | appctx->st2 = STAT_ST_FIN; |
| 4820 | /* fall through */ |
| 4821 | |
| 4822 | default: |
| 4823 | appctx->st2 = STAT_ST_FIN; |
| 4824 | return 1; |
| 4825 | } |
| 4826 | } |
| 4827 | |
| 4828 | static const char *smp_to_type[SMP_TYPES] = { |
| 4829 | [SMP_T_BOOL] = "bool", |
| 4830 | [SMP_T_UINT] = "uint", |
| 4831 | [SMP_T_SINT] = "sint", |
| 4832 | [SMP_T_ADDR] = "addr", |
| 4833 | [SMP_T_IPV4] = "ipv4", |
| 4834 | [SMP_T_IPV6] = "ipv6", |
| 4835 | [SMP_T_STR] = "str", |
| 4836 | [SMP_T_BIN] = "bin", |
| 4837 | [SMP_T_CSTR] = "cstr", |
| 4838 | [SMP_T_CBIN] = "cbin", |
| 4839 | }; |
| 4840 | |
| 4841 | static int stats_map_lookup(struct stream_interface *si) |
| 4842 | { |
| 4843 | struct appctx *appctx = __objt_appctx(si->end); |
| 4844 | struct sample_storage *smp; |
| 4845 | struct sample sample; |
| 4846 | struct pattern *pat; |
| 4847 | struct pat_idx_elt *elt; |
| 4848 | enum pat_match_res res; |
| 4849 | struct sockaddr_in addr; |
Willy Tarreau | b908bef | 2013-12-16 01:42:03 +0100 | [diff] [blame] | 4850 | char addr_str[INET_ADDRSTRLEN]; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4851 | |
| 4852 | switch (appctx->st2) { |
| 4853 | case STAT_ST_INIT: |
| 4854 | appctx->ctx.map.desc = NULL; |
| 4855 | stats_map_lookup_next(si); |
| 4856 | appctx->st2 = STAT_ST_LIST; |
| 4857 | /* fall through */ |
| 4858 | |
| 4859 | case STAT_ST_LIST: |
| 4860 | /* for each lookup type */ |
| 4861 | while (appctx->ctx.map.desc) { |
| 4862 | /* initialise chunk to build new message */ |
| 4863 | chunk_reset(&trash); |
| 4864 | |
| 4865 | /* execute pattern matching */ |
| 4866 | sample.type = SMP_T_CSTR; |
| 4867 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 4868 | sample.data.str.str = appctx->ctx.map.chunk.str; |
| 4869 | pat = NULL; |
| 4870 | elt = NULL; |
| 4871 | res = pattern_exec_match(appctx->ctx.map.desc->pat, &sample, &smp, &pat, &elt); |
| 4872 | |
| 4873 | /* build return message: set type of match */ |
| 4874 | /**/ if (appctx->ctx.map.desc->pat->match == NULL) |
| 4875 | chunk_appendf(&trash, "found, "); |
| 4876 | else if (appctx->ctx.map.desc->pat->match == pat_match_nothing) |
| 4877 | chunk_appendf(&trash, "bool, "); |
| 4878 | else if (appctx->ctx.map.desc->pat->match == pat_match_int) |
| 4879 | chunk_appendf(&trash, "int, "); |
| 4880 | else if (appctx->ctx.map.desc->pat->match == pat_match_ip) |
| 4881 | chunk_appendf(&trash, "ip, "); |
| 4882 | else if (appctx->ctx.map.desc->pat->match == pat_match_bin) |
| 4883 | chunk_appendf(&trash, "bin, "); |
| 4884 | else if (appctx->ctx.map.desc->pat->match == pat_match_len) |
| 4885 | chunk_appendf(&trash, "len, "); |
| 4886 | else if (appctx->ctx.map.desc->pat->match == pat_match_str) |
| 4887 | chunk_appendf(&trash, "str, "); |
| 4888 | else if (appctx->ctx.map.desc->pat->match == pat_match_beg) |
| 4889 | chunk_appendf(&trash, "beg, "); |
| 4890 | else if (appctx->ctx.map.desc->pat->match == pat_match_sub) |
| 4891 | chunk_appendf(&trash, "sub, "); |
| 4892 | else if (appctx->ctx.map.desc->pat->match == pat_match_dir) |
| 4893 | chunk_appendf(&trash, "dir, "); |
| 4894 | else if (appctx->ctx.map.desc->pat->match == pat_match_dom) |
| 4895 | chunk_appendf(&trash, "dom, "); |
| 4896 | else if (appctx->ctx.map.desc->pat->match == pat_match_end) |
| 4897 | chunk_appendf(&trash, "end, "); |
| 4898 | else if (appctx->ctx.map.desc->pat->match == pat_match_reg) |
| 4899 | chunk_appendf(&trash, "reg, "); |
| 4900 | else /* The never appens case */ |
| 4901 | chunk_appendf(&trash, "unknown(%p), ", appctx->ctx.map.desc->pat->match); |
| 4902 | |
| 4903 | /* Display no match, and set default value */ |
| 4904 | if (res == PAT_NOMATCH) { |
| 4905 | chunk_appendf(&trash, "no-match, "); |
| 4906 | smp = appctx->ctx.map.desc->def; |
| 4907 | } |
| 4908 | |
| 4909 | /* Display match and match info */ |
| 4910 | else { |
| 4911 | /* display match */ |
| 4912 | chunk_appendf(&trash, "match, "); |
| 4913 | |
| 4914 | /* display search mode */ |
| 4915 | if (elt) |
| 4916 | chunk_appendf(&trash, "tree, "); |
| 4917 | else |
| 4918 | chunk_appendf(&trash, "list, "); |
| 4919 | |
| 4920 | /* display search options */ |
| 4921 | if (pat) { |
| 4922 | /* case sensitive */ |
| 4923 | if (pat->flags & PAT_F_IGNORE_CASE) |
| 4924 | chunk_appendf(&trash, "case-insensitive, "); |
| 4925 | else |
| 4926 | chunk_appendf(&trash, "case-sensitive, "); |
| 4927 | |
| 4928 | /* display source */ |
| 4929 | if (pat->flags & PAT_F_FROM_FILE) |
| 4930 | chunk_appendf(&trash, "from-file, "); |
| 4931 | } |
| 4932 | |
| 4933 | /* display match expresion */ |
| 4934 | if (elt) { |
| 4935 | if (appctx->ctx.map.desc->pat->match == pat_match_str) { |
| 4936 | chunk_appendf(&trash, "match=\"%s\", ", elt->node.key); |
| 4937 | } |
| 4938 | /* only IPv4 */ |
| 4939 | else if (appctx->ctx.map.desc->pat->match == pat_match_ip) { |
| 4940 | /* convert ip */ |
| 4941 | memcpy(&addr.sin_addr, elt->node.key, 4); |
| 4942 | addr.sin_family = AF_INET; |
Willy Tarreau | b908bef | 2013-12-16 01:42:03 +0100 | [diff] [blame] | 4943 | if (addr_to_str((struct sockaddr_storage *)&addr, addr_str, INET_ADDRSTRLEN)) |
| 4944 | chunk_appendf(&trash, "match=\"%s/%d\", ", addr_str, elt->node.node.pfx); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4945 | } |
| 4946 | } |
| 4947 | } |
| 4948 | |
| 4949 | /* display return value */ |
| 4950 | if (!smp) { |
| 4951 | chunk_appendf(&trash, "return=nothing\n"); |
| 4952 | } |
| 4953 | else { |
| 4954 | memcpy(&sample.data, &smp->data, sizeof(sample.data)); |
| 4955 | sample.type = smp->type; |
| 4956 | if (sample_casts[sample.type][SMP_T_CSTR] && |
| 4957 | sample_casts[sample.type][SMP_T_CSTR](&sample)) |
| 4958 | chunk_appendf(&trash, "return=\"%s\", type=\"%s\"\n", |
| 4959 | sample.data.str.str, smp_to_type[smp->type]); |
| 4960 | else |
| 4961 | chunk_appendf(&trash, "return=cannot-display, type=\"%s\"\n", |
| 4962 | smp_to_type[smp->type]); |
| 4963 | } |
| 4964 | |
| 4965 | /* display response */ |
| 4966 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4967 | /* let's try again later from this session. We add ourselves into |
| 4968 | * this session's users so that it can remove us upon termination. |
| 4969 | */ |
| 4970 | return 0; |
| 4971 | } |
| 4972 | |
| 4973 | /* get next entry */ |
| 4974 | stats_map_lookup_next(si); |
| 4975 | } |
| 4976 | |
| 4977 | appctx->st2 = STAT_ST_FIN; |
| 4978 | /* fall through */ |
| 4979 | |
| 4980 | default: |
| 4981 | appctx->st2 = STAT_ST_FIN; |
| 4982 | free(appctx->ctx.map.chunk.str); |
| 4983 | return 1; |
| 4984 | } |
| 4985 | } |
| 4986 | |
| 4987 | static int stats_map_list(struct stream_interface *si) |
| 4988 | { |
| 4989 | struct appctx *appctx = __objt_appctx(si->end); |
| 4990 | |
| 4991 | switch (appctx->st2) { |
| 4992 | |
| 4993 | case STAT_ST_INIT: |
| 4994 | /* Init to the first entry. The list cannot be change */ |
| 4995 | appctx->ctx.map.ent = LIST_NEXT(&appctx->ctx.map.ref->entries, |
| 4996 | struct map_entry *, list); |
| 4997 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) |
| 4998 | appctx->ctx.map.ent = NULL; |
| 4999 | appctx->st2 = STAT_ST_LIST; |
| 5000 | /* fall through */ |
| 5001 | |
| 5002 | case STAT_ST_LIST: |
| 5003 | while (appctx->ctx.map.ent) { |
| 5004 | chunk_reset(&trash); |
| 5005 | |
| 5006 | /* build messages */ |
| 5007 | chunk_appendf(&trash, "%s %s\n", appctx->ctx.map.ent->key, appctx->ctx.map.ent->value); |
| 5008 | |
| 5009 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5010 | /* let's try again later from this session. We add ourselves into |
| 5011 | * this session's users so that it can remove us upon termination. |
| 5012 | */ |
| 5013 | return 0; |
| 5014 | } |
| 5015 | |
| 5016 | /* get next list entry and check the end of the list */ |
| 5017 | appctx->ctx.map.ent = LIST_NEXT(&appctx->ctx.map.ent->list, |
| 5018 | struct map_entry *, list); |
| 5019 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) |
| 5020 | break; |
| 5021 | } |
| 5022 | |
| 5023 | appctx->st2 = STAT_ST_FIN; |
| 5024 | /* fall through */ |
| 5025 | |
| 5026 | default: |
| 5027 | appctx->st2 = STAT_ST_FIN; |
| 5028 | return 1; |
| 5029 | } |
| 5030 | } |
| 5031 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5032 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5033 | * 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] | 5034 | * to be called again, otherwise non-zero. It is designed to be called |
| 5035 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5036 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5037 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5038 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5039 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5040 | struct connection *conn; |
| 5041 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5042 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5043 | /* If we're forced to shut down, we might have to remove our |
| 5044 | * reference to the last session being dumped. |
| 5045 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5046 | if (appctx->st2 == STAT_ST_LIST) { |
| 5047 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5048 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5049 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5050 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5051 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5052 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5053 | } |
| 5054 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5055 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5056 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5057 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5058 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5059 | /* the function had not been called yet, let's prepare the |
| 5060 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5061 | * pointer to the first in the global list. When a target |
| 5062 | * session is being destroyed, it is responsible for updating |
| 5063 | * this pointer. We know we have reached the end when this |
| 5064 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5065 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5066 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5067 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5068 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5069 | /* fall through */ |
| 5070 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5071 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5072 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5073 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5074 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5075 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5079 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5080 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5081 | struct session *curr_sess; |
| 5082 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5083 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5084 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5085 | if (appctx->ctx.sess.target) { |
| 5086 | 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] | 5087 | goto next_sess; |
| 5088 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5089 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5090 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5091 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5092 | return 0; |
| 5093 | |
| 5094 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5095 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5096 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5097 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5098 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5099 | break; |
| 5100 | } |
| 5101 | else |
| 5102 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5103 | } |
| 5104 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5105 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5106 | "%p: proto=%s", |
| 5107 | curr_sess, |
| 5108 | curr_sess->listener->proto->name); |
| 5109 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5110 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5111 | conn = objt_conn(curr_sess->si[0].end); |
| 5112 | 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] | 5113 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5114 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5115 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5116 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5117 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5118 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5119 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5120 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5121 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5122 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5123 | break; |
| 5124 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5125 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5126 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5127 | curr_sess->listener->luid, |
| 5128 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5129 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5130 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5131 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5132 | break; |
| 5133 | } |
| 5134 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5135 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5136 | " ts=%02x age=%s calls=%d", |
| 5137 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5138 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5139 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5140 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5141 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5142 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5143 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5144 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5145 | curr_sess->req->analysers, |
| 5146 | curr_sess->req->rex ? |
| 5147 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 5148 | TICKS_TO_MS(1000)) : ""); |
| 5149 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5150 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5151 | ",wx=%s", |
| 5152 | curr_sess->req->wex ? |
| 5153 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 5154 | TICKS_TO_MS(1000)) : ""); |
| 5155 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5156 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5157 | ",ax=%s]", |
| 5158 | curr_sess->req->analyse_exp ? |
| 5159 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 5160 | TICKS_TO_MS(1000)) : ""); |
| 5161 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5162 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5163 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5164 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5165 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5166 | curr_sess->rep->analysers, |
| 5167 | curr_sess->rep->rex ? |
| 5168 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5169 | TICKS_TO_MS(1000)) : ""); |
| 5170 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5171 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5172 | ",wx=%s", |
| 5173 | curr_sess->rep->wex ? |
| 5174 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 5175 | TICKS_TO_MS(1000)) : ""); |
| 5176 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5177 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5178 | ",ax=%s]", |
| 5179 | curr_sess->rep->analyse_exp ? |
| 5180 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5181 | TICKS_TO_MS(1000)) : ""); |
| 5182 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5183 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5184 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5185 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5186 | curr_sess->si[0].state, |
| 5187 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5188 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5189 | curr_sess->si[0].exp ? |
| 5190 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5191 | TICKS_TO_MS(1000)) : ""); |
| 5192 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5193 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5194 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5195 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5196 | curr_sess->si[1].state, |
| 5197 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5198 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5199 | curr_sess->si[1].exp ? |
| 5200 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5201 | TICKS_TO_MS(1000)) : ""); |
| 5202 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5203 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5204 | " exp=%s", |
| 5205 | curr_sess->task->expire ? |
| 5206 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5207 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5208 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5209 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5210 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5211 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5212 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5213 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5214 | /* let's try again later from this session. We add ourselves into |
| 5215 | * this session's users so that it can remove us upon termination. |
| 5216 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5217 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5218 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5219 | } |
| 5220 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5221 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5222 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5223 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5224 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5225 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5226 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5227 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5228 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5229 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5230 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5231 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5232 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5233 | return 0; |
| 5234 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5235 | appctx->ctx.sess.target = NULL; |
| 5236 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5237 | return 1; |
| 5238 | } |
| 5239 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5240 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5241 | /* fall through */ |
| 5242 | |
| 5243 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5244 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5245 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5246 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5247 | } |
| 5248 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5249 | /* This is called when the stream interface is closed. For instance, upon an |
| 5250 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5251 | * remove back references to the session currently being dumped. |
| 5252 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5253 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5254 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5255 | struct appctx *appctx = __objt_appctx(si->end); |
| 5256 | |
| 5257 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5258 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5259 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5260 | } |
| 5261 | } |
| 5262 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5263 | /* This function is used to either dump tables states (when action is set |
| 5264 | * 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] | 5265 | * It returns 0 if the output buffer is full and it needs to be called |
| 5266 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5267 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5268 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5269 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5270 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5271 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5272 | struct ebmb_node *eb; |
| 5273 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5274 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5275 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5276 | |
| 5277 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5278 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5279 | * - STAT_ST_INIT : the first call |
| 5280 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5281 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5282 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5283 | * and the entry pointer points to the next entry to be dumped, |
| 5284 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5285 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5286 | * data though. |
| 5287 | */ |
| 5288 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5289 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5290 | /* 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] | 5291 | if (appctx->st2 == STAT_ST_LIST) { |
| 5292 | appctx->ctx.table.entry->ref_cnt--; |
| 5293 | 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] | 5294 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5295 | return 1; |
| 5296 | } |
| 5297 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5298 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5299 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5300 | while (appctx->st2 != STAT_ST_FIN) { |
| 5301 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5302 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5303 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5304 | if (!appctx->ctx.table.proxy) |
| 5305 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5306 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5307 | appctx->ctx.table.entry = NULL; |
| 5308 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5309 | break; |
| 5310 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5311 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5312 | if (!appctx->ctx.table.proxy || |
| 5313 | (appctx->ctx.table.target && |
| 5314 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5315 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5316 | break; |
| 5317 | } |
| 5318 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5319 | if (appctx->ctx.table.proxy->table.size) { |
| 5320 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5321 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5322 | return 0; |
| 5323 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5324 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5325 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5326 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5327 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5328 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5329 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5330 | appctx->ctx.table.entry->ref_cnt++; |
| 5331 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5332 | break; |
| 5333 | } |
| 5334 | } |
| 5335 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5336 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5337 | break; |
| 5338 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5339 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5340 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5341 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5342 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5343 | /* we're filtering on some data contents */ |
| 5344 | void *ptr; |
| 5345 | long long data; |
| 5346 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5347 | dt = appctx->ctx.table.data_type; |
| 5348 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5349 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5350 | dt); |
| 5351 | |
| 5352 | data = 0; |
| 5353 | switch (stktable_data_types[dt].std_type) { |
| 5354 | case STD_T_SINT: |
| 5355 | data = stktable_data_cast(ptr, std_t_sint); |
| 5356 | break; |
| 5357 | case STD_T_UINT: |
| 5358 | data = stktable_data_cast(ptr, std_t_uint); |
| 5359 | break; |
| 5360 | case STD_T_ULL: |
| 5361 | data = stktable_data_cast(ptr, std_t_ull); |
| 5362 | break; |
| 5363 | case STD_T_FRQP: |
| 5364 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5365 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5366 | break; |
| 5367 | } |
| 5368 | |
| 5369 | /* 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] | 5370 | if ((data < appctx->ctx.table.value && |
| 5371 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5372 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5373 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5374 | (data == appctx->ctx.table.value && |
| 5375 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5376 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5377 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5378 | (data > appctx->ctx.table.value && |
| 5379 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5380 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5381 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5382 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5383 | } |
| 5384 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5385 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5386 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5387 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5388 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5389 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5390 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5391 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5392 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5393 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5394 | struct stksess *old = appctx->ctx.table.entry; |
| 5395 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5396 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5397 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5398 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5399 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5400 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5401 | break; |
| 5402 | } |
| 5403 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5404 | |
| 5405 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5406 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5407 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5408 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5409 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5410 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5411 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5412 | break; |
| 5413 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5414 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5415 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5416 | break; |
| 5417 | } |
| 5418 | } |
| 5419 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5420 | } |
| 5421 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5422 | /* 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] | 5423 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5424 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5425 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5426 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5427 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5428 | * after the offset. The new pointer is returned. |
| 5429 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5430 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5431 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5432 | { |
| 5433 | int end; |
| 5434 | unsigned char c; |
| 5435 | |
| 5436 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5437 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5438 | return ptr; |
| 5439 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5440 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5441 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5442 | while (ptr < len && ptr < bsize) { |
| 5443 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5444 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5445 | if (out->len > end - 2) |
| 5446 | break; |
| 5447 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5448 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5449 | if (out->len > end - 3) |
| 5450 | break; |
| 5451 | out->str[out->len++] = '\\'; |
| 5452 | switch (c) { |
| 5453 | case '\t': c = 't'; break; |
| 5454 | case '\n': c = 'n'; break; |
| 5455 | case '\r': c = 'r'; break; |
| 5456 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5457 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5458 | } |
| 5459 | out->str[out->len++] = c; |
| 5460 | } else { |
| 5461 | if (out->len > end - 5) |
| 5462 | break; |
| 5463 | out->str[out->len++] = '\\'; |
| 5464 | out->str[out->len++] = 'x'; |
| 5465 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5466 | out->str[out->len++] = hextab[c & 0xF]; |
| 5467 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5468 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5469 | /* we had a line break, let's return now */ |
| 5470 | out->str[out->len++] = '\n'; |
| 5471 | *line = ptr; |
| 5472 | return ptr; |
| 5473 | } |
| 5474 | } |
| 5475 | /* we have an incomplete line, we return it as-is */ |
| 5476 | out->str[out->len++] = '\n'; |
| 5477 | return ptr; |
| 5478 | } |
| 5479 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5480 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5481 | * 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] | 5482 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5483 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5484 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5485 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5486 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5487 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5488 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5489 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5490 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5491 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5492 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5493 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5494 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5495 | /* the function had not been called yet, let's prepare the |
| 5496 | * buffer for a response. |
| 5497 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5498 | struct tm tm; |
| 5499 | |
| 5500 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5501 | 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] | 5502 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5503 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5504 | error_snapshot_id); |
| 5505 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5506 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5507 | /* Socket buffer full. Let's try again later from the same point */ |
| 5508 | return 0; |
| 5509 | } |
| 5510 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5511 | appctx->ctx.errors.px = proxy; |
| 5512 | appctx->ctx.errors.buf = 0; |
| 5513 | appctx->ctx.errors.bol = 0; |
| 5514 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | /* we have two inner loops here, one for the proxy, the other one for |
| 5518 | * the buffer. |
| 5519 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5520 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5521 | struct error_snapshot *es; |
| 5522 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5523 | if (appctx->ctx.errors.buf == 0) |
| 5524 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5525 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5526 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5527 | |
| 5528 | if (!es->when.tv_sec) |
| 5529 | goto next; |
| 5530 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5531 | if (appctx->ctx.errors.iid >= 0 && |
| 5532 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 5533 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5534 | goto next; |
| 5535 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5536 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5537 | /* just print headers now */ |
| 5538 | |
| 5539 | char pn[INET6_ADDRSTRLEN]; |
| 5540 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5541 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5542 | |
| 5543 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5544 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5545 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5546 | 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] | 5547 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5548 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 5549 | case AF_INET: |
| 5550 | case AF_INET6: |
| 5551 | port = get_host_port(&es->src); |
| 5552 | break; |
| 5553 | default: |
| 5554 | port = 0; |
| 5555 | } |
| 5556 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5557 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5558 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5559 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5560 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5561 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5562 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5563 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 5564 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5565 | break; |
| 5566 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5567 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5568 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5569 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5570 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5571 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5572 | break; |
| 5573 | } |
| 5574 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5575 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5576 | ", server %s (#%d), event #%u\n" |
| 5577 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 5578 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 5579 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 5580 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 5581 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 5582 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 5583 | es->ev_id, |
| 5584 | pn, port, es->sid, es->s_flags, |
| 5585 | es->state, es->m_flags, es->t_flags, |
| 5586 | es->m_clen, es->m_blen, |
| 5587 | es->b_flags, es->b_out, es->b_tot, |
| 5588 | es->len, es->b_wrap, es->pos); |
| 5589 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5590 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5591 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5592 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5593 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5594 | appctx->ctx.errors.ptr = 0; |
| 5595 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5596 | } |
| 5597 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5598 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5599 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5600 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5601 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5602 | if (bi_putchk(si->ib, &trash) == -1) |
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 | goto next; |
| 5605 | } |
| 5606 | |
| 5607 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5608 | 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] | 5609 | int newptr; |
| 5610 | int newline; |
| 5611 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5612 | newline = appctx->ctx.errors.bol; |
| 5613 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 5614 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5615 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5616 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5617 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5618 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5619 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5620 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5621 | appctx->ctx.errors.ptr = newptr; |
| 5622 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5623 | }; |
| 5624 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5625 | appctx->ctx.errors.bol = 0; |
| 5626 | appctx->ctx.errors.ptr = -1; |
| 5627 | appctx->ctx.errors.buf++; |
| 5628 | if (appctx->ctx.errors.buf > 1) { |
| 5629 | appctx->ctx.errors.buf = 0; |
| 5630 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5631 | } |
| 5632 | } |
| 5633 | |
| 5634 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5635 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5636 | } |
| 5637 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5638 | /* parse the "level" argument on the bind lines */ |
| 5639 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 5640 | { |
| 5641 | if (!*args[cur_arg + 1]) { |
| 5642 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 5643 | return ERR_ALERT | ERR_FATAL; |
| 5644 | } |
| 5645 | |
| 5646 | if (!strcmp(args[cur_arg+1], "user")) |
| 5647 | conf->level = ACCESS_LVL_USER; |
| 5648 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 5649 | conf->level = ACCESS_LVL_OPER; |
| 5650 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 5651 | conf->level = ACCESS_LVL_ADMIN; |
| 5652 | else { |
| 5653 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 5654 | args[cur_arg], args[cur_arg+1]); |
| 5655 | return ERR_ALERT | ERR_FATAL; |
| 5656 | } |
| 5657 | |
| 5658 | return 0; |
| 5659 | } |
| 5660 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5661 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5662 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5663 | .name = "<STATS>", /* used for logging */ |
| 5664 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 5665 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5666 | }; |
| 5667 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5668 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5669 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5670 | .name = "<CLI>", /* used for logging */ |
| 5671 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5672 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5673 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5674 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 5675 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5676 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 5677 | { 0, NULL, NULL }, |
| 5678 | }}; |
| 5679 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5680 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 5681 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 5682 | { NULL, NULL, 0 }, |
| 5683 | }}; |
| 5684 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5685 | __attribute__((constructor)) |
| 5686 | static void __dumpstats_module_init(void) |
| 5687 | { |
| 5688 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5689 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5690 | } |
| 5691 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5692 | /* |
| 5693 | * Local variables: |
| 5694 | * c-indent-level: 8 |
| 5695 | * c-basic-offset: 8 |
| 5696 | * End: |
| 5697 | */ |