Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 2 | * Functions dedicated to statistics output and the stats socket |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 27 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/debug.h> |
| 31 | #include <common/memory.h> |
| 32 | #include <common/mini-clist.h> |
| 33 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 34 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 35 | #include <common/time.h> |
| 36 | #include <common/uri_auth.h> |
| 37 | #include <common/version.h> |
| 38 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | |
| 41 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 42 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 43 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 44 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 45 | #include <proto/dumpstats.h> |
| 46 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 47 | #include <proto/freq_ctr.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 48 | #include <proto/log.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 49 | #include <proto/pattern.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 50 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 51 | #include <proto/listener.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 52 | #include <proto/map.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 53 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 54 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 55 | #include <proto/proxy.h> |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 56 | #include <proto/sample.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 57 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 58 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 59 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 60 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 61 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 62 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 63 | #ifdef USE_OPENSSL |
| 64 | #include <proto/ssl_sock.h> |
| 65 | #endif |
| 66 | |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 67 | /* stats socket states */ |
| 68 | enum { |
| 69 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 70 | STAT_CLI_END, /* final state, let's close */ |
| 71 | STAT_CLI_GETREQ, /* wait for a request */ |
| 72 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 73 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 74 | STAT_CLI_PRINT, /* display message in cli->msg */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 75 | STAT_CLI_PRINT_FREE, /* display message in cli->msg. After the display, free the pointer */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 76 | STAT_CLI_O_INFO, /* dump info */ |
| 77 | STAT_CLI_O_SESS, /* dump sessions */ |
| 78 | STAT_CLI_O_ERR, /* dump errors */ |
| 79 | STAT_CLI_O_TAB, /* dump tables */ |
| 80 | STAT_CLI_O_CLR, /* clear tables */ |
| 81 | STAT_CLI_O_SET, /* set entries in tables */ |
| 82 | STAT_CLI_O_STAT, /* dump stats */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 83 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 84 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 85 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 86 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 89 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 90 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 91 | 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] | 92 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 93 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 94 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 95 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 96 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 97 | static int stats_pats_list(struct stream_interface *si); |
| 98 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 99 | static int stats_map_lookup(struct stream_interface *si); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 100 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 101 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 102 | * cli_io_handler() |
| 103 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 104 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 105 | * -> stats_dump_info_to_buffer() // "show info" |
| 106 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 107 | * -> stats_dump_csv_header() |
| 108 | * -> stats_dump_proxy_to_buffer() |
| 109 | * -> stats_dump_fe_stats() |
| 110 | * -> stats_dump_li_stats() |
| 111 | * -> stats_dump_sv_stats() |
| 112 | * -> stats_dump_be_stats() |
| 113 | * |
| 114 | * http_stats_io_handler() |
| 115 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 116 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 117 | * -> stats_dump_html_head() // emits the HTML headers |
| 118 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 119 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 120 | * -> stats_dump_html_px_hdr() |
| 121 | * -> stats_dump_fe_stats() |
| 122 | * -> stats_dump_li_stats() |
| 123 | * -> stats_dump_sv_stats() |
| 124 | * -> stats_dump_be_stats() |
| 125 | * -> stats_dump_html_px_end() |
| 126 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 127 | */ |
| 128 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 129 | static struct si_applet cli_applet; |
| 130 | |
| 131 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 132 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 133 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 134 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 135 | " help : this message\n" |
| 136 | " prompt : toggle interactive mode with prompt\n" |
| 137 | " quit : disconnect\n" |
| 138 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 139 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 140 | " show stat : report counters for each proxy and server\n" |
| 141 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 142 | " 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] | 143 | " show table [id]: report table usage stats or dump this table's contents\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 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" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 150 | " disable : put a server or frontend in maintenance mode\n" |
| 151 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 152 | " shutdown : kill a session or a frontend (eg:to release listening ports)\n" |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 153 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 154 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 155 | " add acl : add acl entry\n" |
| 156 | " del acl : delete acl entry\n" |
| 157 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 158 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 159 | " get map : reports the keys and values matching a sample for a map\n" |
| 160 | " set map : modify map entry\n" |
| 161 | " add map : add map entry\n" |
| 162 | " del map : delete map entry\n" |
| 163 | " clear map <id> : clear the content of this map\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 164 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 165 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 166 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 167 | "Permission denied\n" |
| 168 | ""; |
| 169 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 170 | /* data transmission states for the stats responses */ |
| 171 | enum { |
| 172 | STAT_ST_INIT = 0, |
| 173 | STAT_ST_HEAD, |
| 174 | STAT_ST_INFO, |
| 175 | STAT_ST_LIST, |
| 176 | STAT_ST_END, |
| 177 | STAT_ST_FIN, |
| 178 | }; |
| 179 | |
| 180 | /* data transmission states for the stats responses inside a proxy */ |
| 181 | enum { |
| 182 | STAT_PX_ST_INIT = 0, |
| 183 | STAT_PX_ST_TH, |
| 184 | STAT_PX_ST_FE, |
| 185 | STAT_PX_ST_LI, |
| 186 | STAT_PX_ST_SV, |
| 187 | STAT_PX_ST_BE, |
| 188 | STAT_PX_ST_END, |
| 189 | STAT_PX_ST_FIN, |
| 190 | }; |
| 191 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 192 | extern const char *stat_status_codes[]; |
| 193 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 194 | /* 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] | 195 | * 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] | 196 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 197 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 198 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 199 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 200 | s->target = &cli_applet.obj_type; |
Willy Tarreau | 4171e9e | 2013-12-01 12:32:30 +0100 | [diff] [blame] | 201 | /* 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] | 202 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 203 | tv_zero(&s->logs.tv_request); |
| 204 | s->logs.t_queue = 0; |
| 205 | s->logs.t_connect = 0; |
| 206 | s->logs.t_data = 0; |
| 207 | s->logs.t_close = 0; |
| 208 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 209 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 210 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 211 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 212 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 213 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 214 | if (s->listener->timeout) { |
| 215 | s->req->rto = *s->listener->timeout; |
| 216 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 217 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 218 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 221 | /* allocate a new stats frontend named <name>, and return it |
| 222 | * (or NULL in case of lack of memory). |
| 223 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 224 | 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] | 225 | { |
| 226 | struct proxy *fe; |
| 227 | |
| 228 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 229 | if (!fe) |
| 230 | return NULL; |
| 231 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 232 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 233 | fe->next = proxy; |
| 234 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 235 | fe->last_change = now.tv_sec; |
| 236 | fe->id = strdup("GLOBAL"); |
| 237 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 238 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 239 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 240 | fe->conf.file = strdup(file); |
| 241 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 242 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 243 | |
| 244 | /* the stats frontend is the only one able to assign ID #0 */ |
| 245 | fe->conf.id.key = fe->uuid = 0; |
| 246 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 247 | return fe; |
| 248 | } |
| 249 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 250 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 251 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 252 | * error message into the <err> buffer which will be preallocated. The trailing |
| 253 | * '\n' must not be written. The function must be called with <args> pointing to |
| 254 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 255 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 256 | 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] | 257 | struct proxy *defpx, const char *file, int line, |
| 258 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 259 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 260 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 261 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 262 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 263 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 264 | int cur_arg; |
| 265 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 266 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 267 | 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] | 268 | return -1; |
| 269 | } |
| 270 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 271 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 272 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 273 | 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] | 274 | return -1; |
| 275 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 276 | } |
| 277 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 278 | 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] | 279 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 280 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 281 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 282 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 283 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 284 | return -1; |
| 285 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 286 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 287 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 288 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 289 | static int bind_dumped; |
| 290 | struct bind_kw *kw; |
| 291 | |
| 292 | kw = bind_find_kw(args[cur_arg]); |
| 293 | if (kw) { |
| 294 | if (!kw->parse) { |
| 295 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 296 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 297 | return -1; |
| 298 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 299 | |
| 300 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 301 | if (err && *err) |
| 302 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 303 | else |
| 304 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 305 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 306 | return -1; |
| 307 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 308 | |
| 309 | cur_arg += 1 + kw->skip; |
| 310 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 311 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 312 | |
| 313 | if (!bind_dumped) { |
| 314 | bind_dump_kws(err); |
| 315 | indent_msg(err, 4); |
| 316 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 317 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 318 | |
| 319 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 320 | args[0], args[1], args[cur_arg], |
| 321 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 322 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 323 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 324 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 325 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 326 | l->maxconn = global.stats_fe->maxconn; |
| 327 | l->backlog = global.stats_fe->backlog; |
| 328 | l->timeout = &global.stats_fe->timeout.client; |
| 329 | l->accept = session_accept; |
| 330 | l->handler = process_session; |
| 331 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 332 | l->nice = -64; /* we want to boost priority for local stats */ |
| 333 | global.maxsock += l->maxconn; |
| 334 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 335 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 336 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 337 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 338 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 339 | |
| 340 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 341 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 342 | return -1; |
| 343 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 344 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 345 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 346 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 347 | return -1; |
| 348 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 349 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 350 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 351 | 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] | 352 | return -1; |
| 353 | } |
| 354 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 355 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 356 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 357 | else if (!strcmp(args[1], "maxconn")) { |
| 358 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 359 | |
| 360 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 361 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 362 | return -1; |
| 363 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 364 | |
| 365 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 366 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 367 | 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] | 368 | return -1; |
| 369 | } |
| 370 | } |
| 371 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 372 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 373 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 374 | int cur_arg = 2; |
| 375 | unsigned int set = 0; |
| 376 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 377 | if (!global.stats_fe) { |
| 378 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 379 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 380 | return -1; |
| 381 | } |
| 382 | } |
| 383 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 384 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 385 | unsigned int low, high; |
| 386 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 387 | if (strcmp(args[cur_arg], "all") == 0) { |
| 388 | set = 0; |
| 389 | break; |
| 390 | } |
| 391 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 392 | set |= 0x55555555; |
| 393 | } |
| 394 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 395 | set |= 0xAAAAAAAA; |
| 396 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 397 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 398 | char *dash = strchr(args[cur_arg], '-'); |
| 399 | |
| 400 | low = high = str2uic(args[cur_arg]); |
| 401 | if (dash) |
| 402 | high = str2uic(dash + 1); |
| 403 | |
| 404 | if (high < low) { |
| 405 | unsigned int swap = low; |
| 406 | low = high; |
| 407 | high = swap; |
| 408 | } |
| 409 | |
| 410 | if (low < 1 || high > 32) { |
| 411 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 412 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 413 | return -1; |
| 414 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 415 | |
| 416 | while (low <= high) |
| 417 | set |= 1 << (low++ - 1); |
| 418 | } |
| 419 | else { |
| 420 | memprintf(err, |
| 421 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 422 | args[0], args[1]); |
| 423 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 424 | } |
| 425 | cur_arg++; |
| 426 | } |
| 427 | global.stats_fe->bind_proc = set; |
| 428 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 429 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 430 | 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] | 431 | return -1; |
| 432 | } |
| 433 | return 0; |
| 434 | } |
| 435 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 436 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 437 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 438 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 439 | * so please only append new fields at the end, never in the middle. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 440 | */ |
| 441 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 442 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 443 | chunk_appendf(&trash, |
| 444 | "# pxname,svname," |
| 445 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 446 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 447 | "bin,bout," |
| 448 | "dreq,dresp," |
| 449 | "ereq,econ,eresp," |
| 450 | "wretr,wredis," |
| 451 | "status,weight,act,bck," |
| 452 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 453 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 454 | "rate,rate_lim,rate_max," |
| 455 | "check_status,check_code,check_duration," |
| 456 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 457 | "req_rate,req_rate_max,req_tot," |
| 458 | "cli_abrt,srv_abrt," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 459 | "comp_in,comp_out,comp_byp,comp_rsp,lastsess," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 460 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 461 | } |
| 462 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 463 | /* print a string of text buffer to <out>. The format is : |
| 464 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 465 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 466 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 467 | */ |
| 468 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 469 | { |
| 470 | unsigned char c; |
| 471 | int ptr = 0; |
| 472 | |
| 473 | while (buf[ptr] && ptr < bsize) { |
| 474 | c = buf[ptr]; |
| 475 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 476 | if (out->len > out->size - 1) |
| 477 | break; |
| 478 | out->str[out->len++] = c; |
| 479 | } |
| 480 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 481 | if (out->len > out->size - 2) |
| 482 | break; |
| 483 | out->str[out->len++] = '\\'; |
| 484 | switch (c) { |
| 485 | case ' ': c = ' '; break; |
| 486 | case '\t': c = 't'; break; |
| 487 | case '\n': c = 'n'; break; |
| 488 | case '\r': c = 'r'; break; |
| 489 | case '\e': c = 'e'; break; |
| 490 | case '\\': c = '\\'; break; |
| 491 | } |
| 492 | out->str[out->len++] = c; |
| 493 | } |
| 494 | else { |
| 495 | if (out->len > out->size - 4) |
| 496 | break; |
| 497 | out->str[out->len++] = '\\'; |
| 498 | out->str[out->len++] = 'x'; |
| 499 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 500 | out->str[out->len++] = hextab[c & 0xF]; |
| 501 | } |
| 502 | ptr++; |
| 503 | } |
| 504 | |
| 505 | return ptr; |
| 506 | } |
| 507 | |
| 508 | /* print a buffer in hexa. |
| 509 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 510 | */ |
| 511 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 512 | { |
| 513 | unsigned char c; |
| 514 | int ptr = 0; |
| 515 | |
| 516 | while (ptr < bsize) { |
| 517 | c = buf[ptr]; |
| 518 | |
| 519 | if (out->len > out->size - 2) |
| 520 | break; |
| 521 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 522 | out->str[out->len++] = hextab[c & 0xF]; |
| 523 | |
| 524 | ptr++; |
| 525 | } |
| 526 | return ptr; |
| 527 | } |
| 528 | |
| 529 | /* Dump the status of a table to a stream interface's |
| 530 | * read buffer. It returns 0 if the output buffer is full |
| 531 | * and needs to be called again, otherwise non-zero. |
| 532 | */ |
| 533 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 534 | struct proxy *proxy, struct proxy *target) |
| 535 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 536 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 537 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 538 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 539 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 540 | |
| 541 | /* any other information should be dumped here */ |
| 542 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 543 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 544 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 545 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 546 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 547 | return 0; |
| 548 | |
| 549 | return 1; |
| 550 | } |
| 551 | |
| 552 | /* Dump the a table entry to a stream interface's |
| 553 | * read buffer. It returns 0 if the output buffer is full |
| 554 | * and needs to be called again, otherwise non-zero. |
| 555 | */ |
| 556 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 557 | struct proxy *proxy, struct stksess *entry) |
| 558 | { |
| 559 | int dt; |
| 560 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 561 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 562 | |
| 563 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 564 | char addr[INET_ADDRSTRLEN]; |
| 565 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 566 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 567 | } |
| 568 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 569 | char addr[INET6_ADDRSTRLEN]; |
| 570 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 571 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 572 | } |
| 573 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 574 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 575 | } |
| 576 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 577 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 578 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 579 | } |
| 580 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 581 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 582 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 583 | } |
| 584 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 585 | 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] | 586 | |
| 587 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 588 | void *ptr; |
| 589 | |
| 590 | if (proxy->table.data_ofs[dt] == 0) |
| 591 | continue; |
| 592 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 593 | 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] | 594 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 595 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 596 | |
| 597 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 598 | switch (stktable_data_types[dt].std_type) { |
| 599 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 600 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 601 | break; |
| 602 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 603 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 604 | break; |
| 605 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 606 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 607 | break; |
| 608 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 609 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 610 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 611 | proxy->table.data_arg[dt].u)); |
| 612 | break; |
| 613 | } |
| 614 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 615 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 616 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 617 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 618 | return 0; |
| 619 | |
| 620 | return 1; |
| 621 | } |
| 622 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 623 | 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] | 624 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 625 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 626 | struct appctx *appctx = __objt_appctx(si->end); |
| 627 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 628 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 629 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 630 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 631 | long long value; |
| 632 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 633 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 634 | void *ptr; |
| 635 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 636 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 637 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 638 | |
| 639 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 640 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 641 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 642 | return; |
| 643 | } |
| 644 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 645 | switch (px->table.type) { |
| 646 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 647 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 648 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 649 | break; |
| 650 | case STKTABLE_TYPE_IPV6: |
| 651 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 652 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 653 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 654 | case STKTABLE_TYPE_INTEGER: |
| 655 | { |
| 656 | char *endptr; |
| 657 | unsigned long val; |
| 658 | errno = 0; |
| 659 | val = strtoul(args[4], &endptr, 10); |
| 660 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 661 | (errno != 0 && val == 0) || endptr == args[4] || |
| 662 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 663 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 664 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 665 | return; |
| 666 | } |
| 667 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 668 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 669 | break; |
| 670 | } |
| 671 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 672 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 673 | static_table_key->key = args[4]; |
| 674 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 675 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 676 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 677 | switch (action) { |
| 678 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 679 | 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] | 680 | break; |
| 681 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 682 | 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] | 683 | break; |
| 684 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 685 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 686 | break; |
| 687 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 688 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 689 | return; |
| 690 | } |
| 691 | |
| 692 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 693 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 694 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 695 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 696 | return; |
| 697 | } |
| 698 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 699 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 700 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 701 | switch (action) { |
| 702 | case STAT_CLI_O_TAB: |
| 703 | if (!ts) |
| 704 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 705 | chunk_reset(&trash); |
| 706 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 707 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 708 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 709 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 710 | |
| 711 | case STAT_CLI_O_CLR: |
| 712 | if (!ts) |
| 713 | return; |
| 714 | if (ts->ref_cnt) { |
| 715 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 716 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 717 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 718 | return; |
| 719 | } |
| 720 | stksess_kill(&px->table, ts); |
| 721 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 722 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 723 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 724 | if (ts) |
| 725 | stktable_touch(&px->table, ts, 1); |
| 726 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 727 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 728 | if (!ts) { |
| 729 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 730 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 731 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 732 | return; |
| 733 | } |
| 734 | stktable_store(&px->table, ts, 1); |
| 735 | } |
| 736 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 737 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 738 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 739 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 740 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 741 | return; |
| 742 | } |
| 743 | |
| 744 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 745 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 746 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 747 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 748 | return; |
| 749 | } |
| 750 | |
| 751 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 752 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 753 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 754 | return; |
| 755 | } |
| 756 | |
| 757 | 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] | 758 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 759 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 760 | return; |
| 761 | } |
| 762 | |
| 763 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 764 | |
| 765 | switch (stktable_data_types[data_type].std_type) { |
| 766 | case STD_T_SINT: |
| 767 | stktable_data_cast(ptr, std_t_sint) = value; |
| 768 | break; |
| 769 | case STD_T_UINT: |
| 770 | stktable_data_cast(ptr, std_t_uint) = value; |
| 771 | break; |
| 772 | case STD_T_ULL: |
| 773 | stktable_data_cast(ptr, std_t_ull) = value; |
| 774 | break; |
| 775 | case STD_T_FRQP: |
| 776 | /* We set both the current and previous values. That way |
| 777 | * the reported frequency is stable during all the period |
| 778 | * then slowly fades out. This allows external tools to |
| 779 | * push measures without having to update them too often. |
| 780 | */ |
| 781 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 782 | frqp->curr_tick = now_ms; |
| 783 | frqp->prev_ctr = 0; |
| 784 | frqp->curr_ctr = value; |
| 785 | break; |
| 786 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 787 | } |
| 788 | break; |
| 789 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 790 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 791 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 792 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 793 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 794 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 795 | } |
| 796 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 797 | 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] | 798 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 799 | struct appctx *appctx = __objt_appctx(si->end); |
| 800 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 801 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 802 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 803 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 804 | return; |
| 805 | } |
| 806 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 807 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 808 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 809 | if (appctx->ctx.table.data_type < 0) { |
| 810 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 811 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 812 | return; |
| 813 | } |
| 814 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 815 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 816 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 817 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 818 | return; |
| 819 | } |
| 820 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 821 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 822 | if (appctx->ctx.table.data_op < 0) { |
| 823 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 824 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 825 | return; |
| 826 | } |
| 827 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 828 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 829 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 830 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 831 | return; |
| 832 | } |
| 833 | } |
| 834 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 835 | 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] | 836 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 837 | struct appctx *appctx = __objt_appctx(si->end); |
| 838 | |
| 839 | appctx->ctx.table.data_type = -1; |
| 840 | appctx->st2 = STAT_ST_INIT; |
| 841 | appctx->ctx.table.target = NULL; |
| 842 | appctx->ctx.table.proxy = NULL; |
| 843 | appctx->ctx.table.entry = NULL; |
| 844 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 845 | |
| 846 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 847 | appctx->ctx.table.target = find_stktable(args[2]); |
| 848 | if (!appctx->ctx.table.target) { |
| 849 | appctx->ctx.cli.msg = "No such table\n"; |
| 850 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 851 | return; |
| 852 | } |
| 853 | } |
| 854 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 855 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 856 | goto err_args; |
| 857 | return; |
| 858 | } |
| 859 | |
| 860 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 861 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 862 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 863 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 864 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 865 | goto err_args; |
| 866 | |
| 867 | return; |
| 868 | |
| 869 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 870 | switch (action) { |
| 871 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 872 | 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] | 873 | break; |
| 874 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 875 | 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] | 876 | break; |
| 877 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 878 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 879 | break; |
| 880 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 881 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 882 | } |
| 883 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 884 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 885 | * adequate error messages and returns NULL. This function also expects the session |
| 886 | * level to be admin. |
| 887 | */ |
| 888 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 889 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 890 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 891 | struct proxy *px; |
| 892 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 893 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 894 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 895 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 896 | return NULL; |
| 897 | } |
| 898 | |
| 899 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 900 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 901 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 902 | return NULL; |
| 903 | } |
| 904 | |
| 905 | px = findproxy(arg, PR_CAP_FE); |
| 906 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 907 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 908 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 909 | return NULL; |
| 910 | } |
| 911 | return px; |
| 912 | } |
| 913 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 914 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 915 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 916 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 917 | * the <arg> is modified to remove the '/'. |
| 918 | */ |
| 919 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 920 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 921 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 922 | struct proxy *px; |
| 923 | struct server *sv; |
| 924 | char *line; |
| 925 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 926 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 927 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 928 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 929 | return NULL; |
| 930 | } |
| 931 | |
| 932 | /* split "backend/server" and make <line> point to server */ |
| 933 | for (line = arg; *line; line++) |
| 934 | if (*line == '/') { |
| 935 | *line++ = '\0'; |
| 936 | break; |
| 937 | } |
| 938 | |
| 939 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 940 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 941 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 942 | return NULL; |
| 943 | } |
| 944 | |
| 945 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 946 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 947 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 948 | return NULL; |
| 949 | } |
| 950 | |
| 951 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 952 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 953 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 954 | return NULL; |
| 955 | } |
| 956 | |
| 957 | return sv; |
| 958 | } |
| 959 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 960 | /* This function is used with map and acl management. It permits to browse |
| 961 | * each reference. The variable <getnext> must contain the current node, |
| 962 | * <end> point to the root node and the <flags> permit to filter required |
| 963 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 964 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 965 | static inline |
| 966 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 967 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 968 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 969 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 970 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 971 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 972 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 973 | /* Get next list entry. */ |
| 974 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 975 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 976 | /* If the entry is the last of the list, return NULL. */ |
| 977 | if (&ref->list == end) |
| 978 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 979 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 980 | /* If the entry match the flag, return it. */ |
| 981 | if (ref->flags & flags) |
| 982 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 986 | static inline |
| 987 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 988 | { |
| 989 | int id; |
| 990 | char *error; |
| 991 | |
| 992 | /* If the reference starts by a '#', this is numeric id. */ |
| 993 | if (reference[0] == '#') { |
| 994 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 995 | id = strtol(reference + 1, &error, 10); |
| 996 | if (*error != '\0') |
| 997 | return NULL; |
| 998 | |
| 999 | /* Perform the unique id lookup. */ |
| 1000 | return pat_ref_lookupid(id); |
| 1001 | } |
| 1002 | |
| 1003 | /* Perform the string lookup. */ |
| 1004 | return pat_ref_lookup(reference); |
| 1005 | } |
| 1006 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1007 | /* This function is used with map and acl management. It permits to browse |
| 1008 | * each reference. |
| 1009 | */ |
| 1010 | static inline |
| 1011 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1012 | { |
| 1013 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1014 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1015 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1016 | return NULL; |
| 1017 | return expr; |
| 1018 | } |
| 1019 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1020 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1021 | * 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] | 1022 | * 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] | 1023 | * designating the function which will have to process the request, which can |
| 1024 | * 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] | 1025 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1026 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1027 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 1028 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1029 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1030 | char *args[MAX_STATS_ARGS + 1]; |
| 1031 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1032 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1033 | |
| 1034 | while (isspace((unsigned char)*line)) |
| 1035 | line++; |
| 1036 | |
| 1037 | arg = 0; |
| 1038 | args[arg] = line; |
| 1039 | |
| 1040 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1041 | if (*line == '\\') { |
| 1042 | line++; |
| 1043 | if (*line == '\0') |
| 1044 | break; |
| 1045 | } |
| 1046 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1047 | *line++ = '\0'; |
| 1048 | |
| 1049 | while (isspace((unsigned char)*line)) |
| 1050 | line++; |
| 1051 | |
| 1052 | args[++arg] = line; |
| 1053 | continue; |
| 1054 | } |
| 1055 | |
| 1056 | line++; |
| 1057 | } |
| 1058 | |
| 1059 | while (++arg <= MAX_STATS_ARGS) |
| 1060 | args[arg] = line; |
| 1061 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1062 | /* remove \ */ |
| 1063 | arg = 0; |
| 1064 | while (*args[arg] != '\0') { |
| 1065 | j = 0; |
| 1066 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1067 | if (args[arg][i] == '\\') |
| 1068 | continue; |
| 1069 | args[arg][j] = args[arg][i]; |
| 1070 | j++; |
| 1071 | } |
| 1072 | args[arg][j] = '\0'; |
| 1073 | arg++; |
| 1074 | } |
| 1075 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1076 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1077 | if (strcmp(args[0], "show") == 0) { |
| 1078 | if (strcmp(args[1], "stat") == 0) { |
| 1079 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1080 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1081 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1082 | appctx->ctx.stats.type = atoi(args[3]); |
| 1083 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1084 | } |
| 1085 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1086 | appctx->st2 = STAT_ST_INIT; |
| 1087 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1088 | } |
| 1089 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1090 | appctx->st2 = STAT_ST_INIT; |
| 1091 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1092 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1093 | else if (strcmp(args[1], "pools") == 0) { |
| 1094 | appctx->st2 = STAT_ST_INIT; |
| 1095 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1096 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1097 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1098 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1099 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1100 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1101 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1102 | return 1; |
| 1103 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1104 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1105 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1106 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1107 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1108 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1109 | appctx->ctx.sess.target = NULL; |
| 1110 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1111 | appctx->ctx.sess.pos = 0; |
| 1112 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1113 | } |
| 1114 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1115 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1116 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1117 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1118 | return 1; |
| 1119 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1120 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1121 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1122 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1123 | appctx->ctx.errors.iid = -1; |
| 1124 | appctx->ctx.errors.px = NULL; |
| 1125 | appctx->st2 = STAT_ST_INIT; |
| 1126 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1127 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1128 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1129 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1130 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1131 | else if (strcmp(args[1], "map") == 0 || |
| 1132 | strcmp(args[1], "acl") == 0) { |
| 1133 | |
| 1134 | /* Set ACL or MAP flags. */ |
| 1135 | if (args[1][0] == 'm') |
| 1136 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1137 | else |
| 1138 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1139 | |
| 1140 | /* no parameter: display all map avalaible */ |
| 1141 | if (!*args[2]) { |
| 1142 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1143 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1144 | return 1; |
| 1145 | } |
| 1146 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1147 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1148 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1149 | if (!appctx->ctx.map.ref || |
| 1150 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1151 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1152 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1153 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1154 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1155 | appctx->st0 = STAT_CLI_PRINT; |
| 1156 | return 1; |
| 1157 | } |
| 1158 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1159 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1160 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1161 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1162 | return 0; |
| 1163 | } |
| 1164 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1165 | else if (strcmp(args[0], "clear") == 0) { |
| 1166 | if (strcmp(args[1], "counters") == 0) { |
| 1167 | struct proxy *px; |
| 1168 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1169 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1170 | int clrall = 0; |
| 1171 | |
| 1172 | if (strcmp(args[2], "all") == 0) |
| 1173 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1174 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1175 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1176 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1177 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1178 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1179 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1180 | return 1; |
| 1181 | } |
| 1182 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1183 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1184 | if (clrall) { |
| 1185 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1186 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1187 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1188 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1189 | px->be_counters.conn_max = 0; |
| 1190 | px->be_counters.p.http.rps_max = 0; |
| 1191 | px->be_counters.sps_max = 0; |
| 1192 | px->be_counters.cps_max = 0; |
| 1193 | px->be_counters.nbpend_max = 0; |
| 1194 | |
| 1195 | px->fe_counters.conn_max = 0; |
| 1196 | px->fe_counters.p.http.rps_max = 0; |
| 1197 | px->fe_counters.sps_max = 0; |
| 1198 | px->fe_counters.cps_max = 0; |
| 1199 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1200 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1201 | |
| 1202 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1203 | if (clrall) |
| 1204 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1205 | else { |
| 1206 | sv->counters.cur_sess_max = 0; |
| 1207 | sv->counters.nbpend_max = 0; |
| 1208 | sv->counters.sps_max = 0; |
| 1209 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1210 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1211 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1212 | if (li->counters) { |
| 1213 | if (clrall) |
| 1214 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1215 | else |
| 1216 | li->counters->conn_max = 0; |
| 1217 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1218 | } |
| 1219 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1220 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1221 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1222 | return 1; |
| 1223 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1224 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1225 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1226 | /* end of processing */ |
| 1227 | return 1; |
| 1228 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1229 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1230 | /* Set ACL or MAP flags. */ |
| 1231 | if (args[1][0] == 'm') |
| 1232 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1233 | else |
| 1234 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1235 | |
| 1236 | /* no parameter */ |
| 1237 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1238 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1239 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1240 | else |
| 1241 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1242 | appctx->st0 = STAT_CLI_PRINT; |
| 1243 | return 1; |
| 1244 | } |
| 1245 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1246 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1247 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1248 | if (!appctx->ctx.map.ref || |
| 1249 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1250 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1251 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1252 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1253 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1254 | appctx->st0 = STAT_CLI_PRINT; |
| 1255 | return 1; |
| 1256 | } |
| 1257 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1258 | /* Clear all. */ |
| 1259 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1260 | |
| 1261 | /* return response */ |
| 1262 | appctx->ctx.cli.msg = "Done.\n"; |
| 1263 | appctx->st0 = STAT_CLI_PRINT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1264 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1265 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1266 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1267 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1268 | return 0; |
| 1269 | } |
| 1270 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1271 | else if (strcmp(args[0], "get") == 0) { |
| 1272 | if (strcmp(args[1], "weight") == 0) { |
| 1273 | struct proxy *px; |
| 1274 | struct server *sv; |
| 1275 | |
| 1276 | /* split "backend/server" and make <line> point to server */ |
| 1277 | for (line = args[2]; *line; line++) |
| 1278 | if (*line == '/') { |
| 1279 | *line++ = '\0'; |
| 1280 | break; |
| 1281 | } |
| 1282 | |
| 1283 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1284 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1285 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1286 | return 1; |
| 1287 | } |
| 1288 | |
| 1289 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1290 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1291 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1292 | return 1; |
| 1293 | } |
| 1294 | |
| 1295 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1296 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1297 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1298 | return 1; |
| 1299 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1300 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1301 | /* Set flags. */ |
| 1302 | if (args[1][0] == 'm') |
| 1303 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1304 | else |
| 1305 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1306 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1307 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1308 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1309 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1310 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1311 | else |
| 1312 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1313 | appctx->st0 = STAT_CLI_PRINT; |
| 1314 | return 1; |
| 1315 | } |
| 1316 | |
| 1317 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1318 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1319 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1320 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1321 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1322 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1323 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1324 | appctx->st0 = STAT_CLI_PRINT; |
| 1325 | return 1; |
| 1326 | } |
| 1327 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1328 | /* copy input string. The string must be allocated because |
| 1329 | * it may be used over multiple iterations. It's released |
| 1330 | * at the end and upon abort anyway. |
| 1331 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1332 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1333 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1334 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1335 | if (!appctx->ctx.map.chunk.str) { |
| 1336 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1337 | appctx->st0 = STAT_CLI_PRINT; |
| 1338 | return 1; |
| 1339 | } |
| 1340 | |
| 1341 | /* prepare response */ |
| 1342 | appctx->st2 = STAT_ST_INIT; |
| 1343 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1344 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1345 | else { /* not "get weight" */ |
| 1346 | return 0; |
| 1347 | } |
| 1348 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1349 | else if (strcmp(args[0], "set") == 0) { |
| 1350 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1351 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1352 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1353 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1354 | sv = expect_server_admin(s, si, args[2]); |
| 1355 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1356 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1357 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1358 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1359 | /* |
| 1360 | * The user-weight may now be zero and thus |
| 1361 | * the server considered to be draining. |
| 1362 | * Update the server's drain state as necessary. |
| 1363 | */ |
| 1364 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1365 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1366 | appctx->ctx.cli.msg = warning; |
| 1367 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1368 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1369 | return 1; |
| 1370 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1371 | else if (strcmp(args[1], "timeout") == 0) { |
| 1372 | if (strcmp(args[2], "cli") == 0) { |
| 1373 | unsigned timeout; |
| 1374 | const char *res; |
| 1375 | |
| 1376 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1377 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1378 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1379 | return 1; |
| 1380 | } |
| 1381 | |
| 1382 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1383 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1384 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1385 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1386 | return 1; |
| 1387 | } |
| 1388 | |
| 1389 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1390 | return 1; |
| 1391 | } |
| 1392 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1393 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1394 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1395 | return 1; |
| 1396 | } |
| 1397 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1398 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1399 | if (strcmp(args[2], "frontend") == 0) { |
| 1400 | struct proxy *px; |
| 1401 | struct listener *l; |
| 1402 | int v; |
| 1403 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1404 | px = expect_frontend_admin(s, si, args[3]); |
| 1405 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1406 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1407 | |
| 1408 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1409 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1410 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1411 | return 1; |
| 1412 | } |
| 1413 | |
| 1414 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1415 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1416 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1417 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1418 | return 1; |
| 1419 | } |
| 1420 | |
| 1421 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1422 | * its listeners. The blocked ones will be dequeued. |
| 1423 | */ |
| 1424 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1425 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1426 | l->maxconn = v; |
| 1427 | if (l->state == LI_FULL) |
| 1428 | resume_listener(l); |
| 1429 | } |
| 1430 | |
| 1431 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1432 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1433 | |
| 1434 | return 1; |
| 1435 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1436 | else if (strcmp(args[2], "global") == 0) { |
| 1437 | int v; |
| 1438 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1439 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1440 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1441 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1442 | return 1; |
| 1443 | } |
| 1444 | |
| 1445 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1446 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1447 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1448 | return 1; |
| 1449 | } |
| 1450 | |
| 1451 | v = atoi(args[3]); |
| 1452 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1453 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1454 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1455 | return 1; |
| 1456 | } |
| 1457 | |
| 1458 | /* check for unlimited values */ |
| 1459 | if (v <= 0) |
| 1460 | v = global.hardmaxconn; |
| 1461 | |
| 1462 | global.maxconn = v; |
| 1463 | |
| 1464 | /* Dequeues all of the listeners waiting for a resource */ |
| 1465 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1466 | dequeue_all_listeners(&global_listener_queue); |
| 1467 | |
| 1468 | return 1; |
| 1469 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1470 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1471 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1472 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1473 | return 1; |
| 1474 | } |
| 1475 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1476 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1477 | if (strcmp(args[2], "connections") == 0) { |
| 1478 | if (strcmp(args[3], "global") == 0) { |
| 1479 | int v; |
| 1480 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1481 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1482 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1483 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1484 | return 1; |
| 1485 | } |
| 1486 | |
| 1487 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1488 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1489 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1490 | return 1; |
| 1491 | } |
| 1492 | |
| 1493 | v = atoi(args[4]); |
| 1494 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1495 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1496 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1497 | return 1; |
| 1498 | } |
| 1499 | |
| 1500 | global.cps_lim = v; |
| 1501 | |
| 1502 | /* Dequeues all of the listeners waiting for a resource */ |
| 1503 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1504 | dequeue_all_listeners(&global_listener_queue); |
| 1505 | |
| 1506 | return 1; |
| 1507 | } |
| 1508 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1509 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1510 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1511 | return 1; |
| 1512 | } |
| 1513 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1514 | else if (strcmp(args[2], "sessions") == 0) { |
| 1515 | if (strcmp(args[3], "global") == 0) { |
| 1516 | int v; |
| 1517 | |
| 1518 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1519 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1520 | appctx->st0 = STAT_CLI_PRINT; |
| 1521 | return 1; |
| 1522 | } |
| 1523 | |
| 1524 | if (!*args[4]) { |
| 1525 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1526 | appctx->st0 = STAT_CLI_PRINT; |
| 1527 | return 1; |
| 1528 | } |
| 1529 | |
| 1530 | v = atoi(args[4]); |
| 1531 | if (v < 0) { |
| 1532 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1533 | appctx->st0 = STAT_CLI_PRINT; |
| 1534 | return 1; |
| 1535 | } |
| 1536 | |
| 1537 | global.sps_lim = v; |
| 1538 | |
| 1539 | /* Dequeues all of the listeners waiting for a resource */ |
| 1540 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1541 | dequeue_all_listeners(&global_listener_queue); |
| 1542 | |
| 1543 | return 1; |
| 1544 | } |
| 1545 | else { |
| 1546 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1547 | appctx->st0 = STAT_CLI_PRINT; |
| 1548 | return 1; |
| 1549 | } |
| 1550 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1551 | #ifdef USE_OPENSSL |
| 1552 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1553 | if (strcmp(args[3], "global") == 0) { |
| 1554 | int v; |
| 1555 | |
| 1556 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1557 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1558 | appctx->st0 = STAT_CLI_PRINT; |
| 1559 | return 1; |
| 1560 | } |
| 1561 | |
| 1562 | if (!*args[4]) { |
| 1563 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1564 | appctx->st0 = STAT_CLI_PRINT; |
| 1565 | return 1; |
| 1566 | } |
| 1567 | |
| 1568 | v = atoi(args[4]); |
| 1569 | if (v < 0) { |
| 1570 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1571 | appctx->st0 = STAT_CLI_PRINT; |
| 1572 | return 1; |
| 1573 | } |
| 1574 | |
| 1575 | global.ssl_lim = v; |
| 1576 | |
| 1577 | /* Dequeues all of the listeners waiting for a resource */ |
| 1578 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1579 | dequeue_all_listeners(&global_listener_queue); |
| 1580 | |
| 1581 | return 1; |
| 1582 | } |
| 1583 | else { |
| 1584 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1585 | appctx->st0 = STAT_CLI_PRINT; |
| 1586 | return 1; |
| 1587 | } |
| 1588 | } |
| 1589 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1590 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1591 | if (strcmp(args[3], "global") == 0) { |
| 1592 | int v; |
| 1593 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1594 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1595 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1596 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1597 | return 1; |
| 1598 | } |
| 1599 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1600 | v = atoi(args[4]); |
| 1601 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1602 | } |
| 1603 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1604 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1605 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1606 | return 1; |
| 1607 | } |
| 1608 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1609 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1610 | 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] | 1611 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1612 | return 1; |
| 1613 | } |
| 1614 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1615 | else if (strcmp(args[1], "table") == 0) { |
| 1616 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1617 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1618 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1619 | char *err; |
| 1620 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1621 | /* Set flags. */ |
| 1622 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1623 | |
| 1624 | /* Expect three parameters: map name, key and new value. */ |
| 1625 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1626 | appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1627 | appctx->st0 = STAT_CLI_PRINT; |
| 1628 | return 1; |
| 1629 | } |
| 1630 | |
| 1631 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1632 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1633 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1634 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1635 | appctx->st0 = STAT_CLI_PRINT; |
| 1636 | return 1; |
| 1637 | } |
| 1638 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1639 | /* If the entry identifier start with a '#', it is considered as |
| 1640 | * pointer id |
| 1641 | */ |
| 1642 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1643 | struct pat_ref_elt *ref; |
| 1644 | long long int conv; |
| 1645 | char *error; |
| 1646 | |
| 1647 | /* Convert argument to integer value. */ |
| 1648 | conv = strtoll(&args[3][1], &error, 16); |
| 1649 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1650 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1651 | appctx->st0 = STAT_CLI_PRINT; |
| 1652 | return 1; |
| 1653 | } |
| 1654 | |
| 1655 | /* Convert and check integer to pointer. */ |
| 1656 | ref = (struct pat_ref_elt *)(long)conv; |
| 1657 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1658 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1659 | appctx->st0 = STAT_CLI_PRINT; |
| 1660 | return 1; |
| 1661 | } |
| 1662 | |
| 1663 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1664 | err = NULL; |
| 1665 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1666 | if (err) |
| 1667 | memprintf(&err, "%s.\n", err); |
| 1668 | appctx->ctx.cli.err = err; |
| 1669 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1670 | return 1; |
| 1671 | } |
| 1672 | } |
| 1673 | else { |
| 1674 | /* Else, use the entry identifier as pattern |
| 1675 | * string, and update the value. |
| 1676 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1677 | err = NULL; |
| 1678 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1679 | if (err) |
| 1680 | memprintf(&err, "%s.\n", err); |
| 1681 | appctx->ctx.cli.err = err; |
| 1682 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1683 | return 1; |
| 1684 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1685 | } |
| 1686 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1687 | /* The set is done, send message. */ |
| 1688 | appctx->ctx.cli.msg = "Done.\n"; |
| 1689 | appctx->st0 = STAT_CLI_PRINT; |
| 1690 | return 1; |
| 1691 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1692 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1693 | return 0; |
| 1694 | } |
| 1695 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1696 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1697 | if (strcmp(args[1], "agent") == 0) { |
| 1698 | struct server *sv; |
| 1699 | |
| 1700 | sv = expect_server_admin(s, si, args[2]); |
| 1701 | if (!sv) |
| 1702 | return 1; |
| 1703 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1704 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1705 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1706 | appctx->st0 = STAT_CLI_PRINT; |
| 1707 | return 1; |
| 1708 | } |
| 1709 | |
| 1710 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1711 | return 1; |
| 1712 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1713 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1714 | struct server *sv; |
| 1715 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1716 | sv = expect_server_admin(s, si, args[2]); |
| 1717 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1718 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1719 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1720 | if (sv->state & SRV_MAINTAIN) { |
| 1721 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1722 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1723 | /* If this server tracks the status of another one, |
| 1724 | * we must restore the good status. |
| 1725 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1726 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1727 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1728 | 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] | 1729 | } else { |
| 1730 | sv->state &= ~SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1731 | sv->check.state &= ~CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1732 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1733 | } |
| 1734 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1735 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1736 | 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] | 1737 | } |
| 1738 | } |
| 1739 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1740 | return 1; |
| 1741 | } |
| 1742 | else if (strcmp(args[1], "frontend") == 0) { |
| 1743 | struct proxy *px; |
| 1744 | |
| 1745 | px = expect_frontend_admin(s, si, args[2]); |
| 1746 | if (!px) |
| 1747 | return 1; |
| 1748 | |
| 1749 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1750 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1751 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1752 | return 1; |
| 1753 | } |
| 1754 | |
| 1755 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1756 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1757 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1758 | return 1; |
| 1759 | } |
| 1760 | |
| 1761 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1762 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1763 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1764 | return 1; |
| 1765 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1766 | return 1; |
| 1767 | } |
| 1768 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1769 | appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1770 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1771 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1775 | if (strcmp(args[1], "agent") == 0) { |
| 1776 | struct server *sv; |
| 1777 | |
| 1778 | sv = expect_server_admin(s, si, args[2]); |
| 1779 | if (!sv) |
| 1780 | return 1; |
| 1781 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1782 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1783 | return 1; |
| 1784 | } |
| 1785 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1786 | struct server *sv; |
| 1787 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1788 | sv = expect_server_admin(s, si, args[2]); |
| 1789 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1790 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1791 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1792 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1793 | /* Not already in maintenance, we can change the server state */ |
| 1794 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1795 | sv->check.state |= CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1796 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1797 | } |
| 1798 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1799 | return 1; |
| 1800 | } |
| 1801 | else if (strcmp(args[1], "frontend") == 0) { |
| 1802 | struct proxy *px; |
| 1803 | |
| 1804 | px = expect_frontend_admin(s, si, args[2]); |
| 1805 | if (!px) |
| 1806 | return 1; |
| 1807 | |
| 1808 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1809 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1810 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1811 | return 1; |
| 1812 | } |
| 1813 | |
| 1814 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1815 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1816 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1817 | return 1; |
| 1818 | } |
| 1819 | |
| 1820 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1821 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1822 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1823 | return 1; |
| 1824 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1825 | return 1; |
| 1826 | } |
| 1827 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1828 | appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1829 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1830 | return 1; |
| 1831 | } |
| 1832 | } |
| 1833 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1834 | if (strcmp(args[1], "frontend") == 0) { |
| 1835 | struct proxy *px; |
| 1836 | |
| 1837 | px = expect_frontend_admin(s, si, args[2]); |
| 1838 | if (!px) |
| 1839 | return 1; |
| 1840 | |
| 1841 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1842 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1843 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1844 | return 1; |
| 1845 | } |
| 1846 | |
| 1847 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1848 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1849 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1850 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1851 | stop_proxy(px); |
| 1852 | return 1; |
| 1853 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1854 | else if (strcmp(args[1], "session") == 0) { |
| 1855 | struct session *sess, *ptr; |
| 1856 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1857 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1858 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1859 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1860 | return 1; |
| 1861 | } |
| 1862 | |
| 1863 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1864 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1865 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1866 | return 1; |
| 1867 | } |
| 1868 | |
| 1869 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1870 | |
| 1871 | /* first, look for the requested session in the session table */ |
| 1872 | list_for_each_entry(sess, &sessions, list) { |
| 1873 | if (sess == ptr) |
| 1874 | break; |
| 1875 | } |
| 1876 | |
| 1877 | /* do we have the session ? */ |
| 1878 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1879 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1880 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1881 | return 1; |
| 1882 | } |
| 1883 | |
| 1884 | session_shutdown(sess, SN_ERR_KILLED); |
| 1885 | return 1; |
| 1886 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1887 | else if (strcmp(args[1], "sessions") == 0) { |
| 1888 | if (strcmp(args[2], "server") == 0) { |
| 1889 | struct server *sv; |
| 1890 | struct session *sess, *sess_bck; |
| 1891 | |
| 1892 | sv = expect_server_admin(s, si, args[3]); |
| 1893 | if (!sv) |
| 1894 | return 1; |
| 1895 | |
| 1896 | /* kill all the session that are on this server */ |
| 1897 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1898 | if (sess->srv_conn == sv) |
| 1899 | session_shutdown(sess, SN_ERR_KILLED); |
| 1900 | |
| 1901 | return 1; |
| 1902 | } |
| 1903 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1904 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1905 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1906 | return 1; |
| 1907 | } |
| 1908 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1909 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1910 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1911 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1912 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1913 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1914 | } |
| 1915 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1916 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1917 | if (args[1][0] == 'm') |
| 1918 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1919 | else |
| 1920 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1921 | |
| 1922 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1923 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 1924 | if (!*args[2] || !*args[3]) { |
| 1925 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 1926 | appctx->st0 = STAT_CLI_PRINT; |
| 1927 | return 1; |
| 1928 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1929 | } |
| 1930 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1931 | else { |
| 1932 | if (!*args[2] || !*args[3]) { |
| 1933 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 1934 | appctx->st0 = STAT_CLI_PRINT; |
| 1935 | return 1; |
| 1936 | } |
| 1937 | } |
| 1938 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1939 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1940 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1941 | if (!appctx->ctx.map.ref || |
| 1942 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1943 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1944 | appctx->st0 = STAT_CLI_PRINT; |
| 1945 | return 1; |
| 1946 | } |
| 1947 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1948 | /* If the entry identifier start with a '#', it is considered as |
| 1949 | * pointer id |
| 1950 | */ |
| 1951 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1952 | struct pat_ref_elt *ref; |
| 1953 | long long int conv; |
| 1954 | char *error; |
| 1955 | |
| 1956 | /* Convert argument to integer value. */ |
| 1957 | conv = strtoll(&args[3][1], &error, 16); |
| 1958 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1959 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1960 | appctx->st0 = STAT_CLI_PRINT; |
| 1961 | return 1; |
| 1962 | } |
| 1963 | |
| 1964 | /* Convert and check integer to pointer. */ |
| 1965 | ref = (struct pat_ref_elt *)(long)conv; |
| 1966 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1967 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1968 | appctx->st0 = STAT_CLI_PRINT; |
| 1969 | return 1; |
| 1970 | } |
| 1971 | |
| 1972 | /* Try to delete the entry. */ |
| 1973 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 1974 | /* The entry is not found, send message. */ |
| 1975 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 1976 | appctx->st0 = STAT_CLI_PRINT; |
| 1977 | return 1; |
| 1978 | } |
| 1979 | } |
| 1980 | else { |
| 1981 | /* Else, use the entry identifier as pattern |
| 1982 | * string and try to delete the entry. |
| 1983 | */ |
| 1984 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 1985 | /* The entry is not found, send message. */ |
| 1986 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 1987 | appctx->st0 = STAT_CLI_PRINT; |
| 1988 | return 1; |
| 1989 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1990 | } |
| 1991 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1992 | /* The deletion is done, send message. */ |
| 1993 | appctx->ctx.cli.msg = "Done.\n"; |
| 1994 | appctx->st0 = STAT_CLI_PRINT; |
| 1995 | return 1; |
| 1996 | } |
| 1997 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1998 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1999 | appctx->st0 = STAT_CLI_PRINT; |
| 2000 | return 1; |
| 2001 | } |
| 2002 | } |
| 2003 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2004 | if (strcmp(args[1], "map") == 0 || |
| 2005 | strcmp(args[1], "acl") == 0) { |
| 2006 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2007 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2008 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2009 | /* Set flags. */ |
| 2010 | if (args[1][0] == 'm') |
| 2011 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2012 | else |
| 2013 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2014 | |
| 2015 | /* If the keywork is "map", we expect three parameters, if it |
| 2016 | * is "acl", we expect only two parameters |
| 2017 | */ |
| 2018 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2019 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2020 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2021 | appctx->st0 = STAT_CLI_PRINT; |
| 2022 | return 1; |
| 2023 | } |
| 2024 | } |
| 2025 | else { |
| 2026 | if (!*args[2] || !*args[3]) { |
| 2027 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2028 | appctx->st0 = STAT_CLI_PRINT; |
| 2029 | return 1; |
| 2030 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2031 | } |
| 2032 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2033 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2034 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2035 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2036 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2037 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2038 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2039 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2040 | appctx->st0 = STAT_CLI_PRINT; |
| 2041 | return 1; |
| 2042 | } |
| 2043 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2044 | /* The command "add acl" is prohibited if the reference |
| 2045 | * use samples. |
| 2046 | */ |
| 2047 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2048 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2049 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2050 | "You must use the command 'add map' to add values.\n"; |
| 2051 | appctx->st0 = STAT_CLI_PRINT; |
| 2052 | return 1; |
| 2053 | } |
| 2054 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2055 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2056 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2057 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2058 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2059 | else |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2060 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2061 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2062 | if (err) |
| 2063 | memprintf(&err, "%s.\n", err); |
| 2064 | appctx->ctx.cli.err = err; |
| 2065 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2066 | return 1; |
| 2067 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2068 | |
| 2069 | /* The add is done, send message. */ |
| 2070 | appctx->ctx.cli.msg = "Done.\n"; |
| 2071 | appctx->st0 = STAT_CLI_PRINT; |
| 2072 | return 1; |
| 2073 | } |
| 2074 | else { /* unknown "del" parameter */ |
| 2075 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2076 | appctx->st0 = STAT_CLI_PRINT; |
| 2077 | return 1; |
| 2078 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2079 | } |
| 2080 | 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] | 2081 | return 0; |
| 2082 | } |
| 2083 | return 1; |
| 2084 | } |
| 2085 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2086 | /* 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] | 2087 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2088 | * state machine handling requests and various responses. We read a request, |
| 2089 | * 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] | 2090 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2091 | * 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] | 2092 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2093 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2094 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2095 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2096 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2097 | struct channel *req = si->ob; |
| 2098 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2099 | int reql; |
| 2100 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2101 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2102 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2103 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2104 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2105 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2106 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2107 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2108 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2109 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2110 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2111 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2112 | /* Let's close for real now. We just close the request |
| 2113 | * side, the conditions below will complete if needed. |
| 2114 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2115 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2116 | break; |
| 2117 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2118 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2119 | /* ensure we have some output room left in the event we |
| 2120 | * would want to return some info right after parsing. |
| 2121 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2122 | if (buffer_almost_full(si->ib->buf)) { |
| 2123 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2124 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2125 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2126 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2127 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2128 | if (reql <= 0) { /* closed or EOL not found */ |
| 2129 | if (reql == 0) |
| 2130 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2131 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2132 | continue; |
| 2133 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2134 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2135 | /* seek for a possible semi-colon. If we find one, we |
| 2136 | * replace it with an LF and skip only this part. |
| 2137 | */ |
| 2138 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2139 | if (trash.str[len] == ';') { |
| 2140 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2141 | reql = len + 1; |
| 2142 | break; |
| 2143 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2144 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2145 | /* now it is time to check that we have a full line, |
| 2146 | * remove the trailing \n and possibly \r, then cut the |
| 2147 | * line. |
| 2148 | */ |
| 2149 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2150 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2151 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2152 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2153 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2154 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2155 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2156 | len--; |
| 2157 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2158 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2159 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2160 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2161 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2162 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2163 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2164 | continue; |
| 2165 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2166 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2167 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2168 | else if (strcmp(trash.str, "help") == 0 || |
| 2169 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2170 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2171 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2172 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2173 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2174 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2175 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2176 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2177 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2178 | /* if prompt is disabled, print help on empty lines, |
| 2179 | * so that the user at least knows how to enable |
| 2180 | * prompt and find help. |
| 2181 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2182 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2183 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2187 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2188 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2189 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2190 | 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] | 2191 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2192 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2193 | continue; |
| 2194 | } |
| 2195 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2196 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2197 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2198 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2199 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2200 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2201 | case STAT_CLI_PRINT_FREE: |
| 2202 | if (bi_putstr(si->ib, appctx->ctx.cli.err) != -1) { |
| 2203 | free(appctx->ctx.cli.err); |
| 2204 | appctx->st0 = STAT_CLI_PROMPT; |
| 2205 | } |
| 2206 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2207 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2208 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2209 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2210 | break; |
| 2211 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2212 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2213 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2214 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2215 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2216 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2217 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2218 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2219 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2220 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2221 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2222 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2223 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2224 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2225 | if (stats_table_request(si, appctx->st0)) |
| 2226 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2227 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2228 | case STAT_CLI_O_PATS: |
| 2229 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2230 | appctx->st0 = STAT_CLI_PROMPT; |
| 2231 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2232 | case STAT_CLI_O_PAT: |
| 2233 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2234 | appctx->st0 = STAT_CLI_PROMPT; |
| 2235 | break; |
| 2236 | case STAT_CLI_O_MLOOK: |
| 2237 | if (stats_map_lookup(si)) |
| 2238 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2239 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2240 | case STAT_CLI_O_POOLS: |
| 2241 | if (stats_dump_pools_to_buffer(si)) |
| 2242 | appctx->st0 = STAT_CLI_PROMPT; |
| 2243 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2244 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2245 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2246 | break; |
| 2247 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2248 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2249 | /* 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] | 2250 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2251 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2252 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2253 | } |
| 2254 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2255 | /* 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] | 2256 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2257 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2258 | |
| 2259 | /* Now we close the output if one of the writers did so, |
| 2260 | * or if we're not in interactive mode and the request |
| 2261 | * buffer is empty. This still allows pipelined requests |
| 2262 | * to be sent in non-interactive mode. |
| 2263 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2264 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2265 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2266 | continue; |
| 2267 | } |
| 2268 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2269 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2270 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2271 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2272 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2273 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2274 | 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] | 2275 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2276 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2277 | /* 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] | 2278 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2279 | * we forward the close to the request side so that it flows upstream to |
| 2280 | * the client. |
| 2281 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2282 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2283 | } |
| 2284 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2285 | 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] | 2286 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2287 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2288 | /* We have no more processing to do, and nothing more to send, and |
| 2289 | * the client side has closed. So we'll forward this state downstream |
| 2290 | * on the response buffer. |
| 2291 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2292 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2293 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2297 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2298 | |
| 2299 | /* we don't want to expire timeouts while we're processing requests */ |
| 2300 | si->ib->rex = TICK_ETERNITY; |
| 2301 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2302 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2303 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2304 | 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] | 2305 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2306 | 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] | 2307 | |
| 2308 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2309 | /* check that we have released everything then unregister */ |
| 2310 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2311 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2312 | } |
| 2313 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2314 | /* This function dumps information onto the stream interface's read buffer. |
| 2315 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2316 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2317 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2318 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2319 | { |
| 2320 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2321 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2322 | chunk_printf(&trash, |
| 2323 | "Name: " PRODUCT_NAME "\n" |
| 2324 | "Version: " HAPROXY_VERSION "\n" |
| 2325 | "Release_date: " HAPROXY_DATE "\n" |
| 2326 | "Nbproc: %d\n" |
| 2327 | "Process_num: %d\n" |
| 2328 | "Pid: %d\n" |
| 2329 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2330 | "Uptime_sec: %d\n" |
| 2331 | "Memmax_MB: %d\n" |
| 2332 | "Ulimit-n: %d\n" |
| 2333 | "Maxsock: %d\n" |
| 2334 | "Maxconn: %d\n" |
| 2335 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2336 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2337 | "CumConns: %d\n" |
| 2338 | "CumReq: %d\n" |
| 2339 | #ifdef USE_OPENSSL |
| 2340 | "MaxSslConns: %d\n" |
| 2341 | "CurrSslConns: %d\n" |
| 2342 | "CumSslConns: %d\n" |
| 2343 | #endif |
| 2344 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2345 | "PipesUsed: %d\n" |
| 2346 | "PipesFree: %d\n" |
| 2347 | "ConnRate: %d\n" |
| 2348 | "ConnRateLimit: %d\n" |
| 2349 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2350 | "SessRate: %d\n" |
| 2351 | "SessRateLimit: %d\n" |
| 2352 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2353 | #ifdef USE_OPENSSL |
| 2354 | "SslRate: %d\n" |
| 2355 | "SslRateLimit: %d\n" |
| 2356 | "MaxSslRate: %d\n" |
| 2357 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2358 | "CompressBpsIn: %u\n" |
| 2359 | "CompressBpsOut: %u\n" |
| 2360 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2361 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2362 | "ZlibMemUsage: %ld\n" |
| 2363 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2364 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2365 | "Tasks: %d\n" |
| 2366 | "Run_queue: %d\n" |
| 2367 | "Idle_pct: %d\n" |
| 2368 | "node: %s\n" |
| 2369 | "description: %s\n" |
| 2370 | "", |
| 2371 | global.nbproc, |
| 2372 | relative_pid, |
| 2373 | pid, |
| 2374 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2375 | up, |
| 2376 | global.rlimit_memmax, |
| 2377 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2378 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2379 | actconn, totalconn, global.req_count, |
| 2380 | #ifdef USE_OPENSSL |
| 2381 | global.maxsslconn, sslconns, totalsslconns, |
| 2382 | #endif |
| 2383 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2384 | 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] | 2385 | 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] | 2386 | #ifdef USE_OPENSSL |
| 2387 | read_freq_ctr(&global.ssl_per_sec), global.ssl_lim, global.ssl_max, |
| 2388 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2389 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2390 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2391 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2392 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2393 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2394 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2395 | global.node, global.desc ? global.desc : "" |
| 2396 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2397 | |
| 2398 | if (bi_putchk(si->ib, &trash) == -1) |
| 2399 | return 0; |
| 2400 | |
| 2401 | return 1; |
| 2402 | } |
| 2403 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2404 | /* This function dumps memory usage information onto the stream interface's |
| 2405 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2406 | * completion. No state is used. |
| 2407 | */ |
| 2408 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2409 | { |
| 2410 | dump_pools_to_trash(); |
| 2411 | if (bi_putchk(si->ib, &trash) == -1) |
| 2412 | return 0; |
| 2413 | return 1; |
| 2414 | } |
| 2415 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2416 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2417 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2418 | * 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] | 2419 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2420 | 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] | 2421 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2422 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2423 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2424 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2425 | if (!(px->cap & PR_CAP_FE)) |
| 2426 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2427 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2428 | 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] | 2429 | return 0; |
| 2430 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2431 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2432 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2433 | /* name, queue */ |
| 2434 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2435 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2436 | 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] | 2437 | /* Column sub-heading for Enable or Disable server */ |
| 2438 | chunk_appendf(&trash, "<td></td>"); |
| 2439 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2440 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2441 | chunk_appendf(&trash, |
| 2442 | "<td class=ac>" |
| 2443 | "<a name=\"%s/Frontend\"></a>" |
| 2444 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2445 | "<td colspan=3></td>" |
| 2446 | "", |
| 2447 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2448 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2449 | chunk_appendf(&trash, |
| 2450 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2451 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2452 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2453 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2454 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2455 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2456 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2457 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2458 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2459 | if (px->mode == PR_MODE_HTTP) |
| 2460 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2461 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2462 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2463 | |
| 2464 | chunk_appendf(&trash, |
| 2465 | "</table></div></u></td>" |
| 2466 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2467 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2468 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2469 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2470 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2471 | U2H(px->fe_counters.sps_max), |
| 2472 | U2H(px->fe_counters.cps_max), |
| 2473 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2474 | |
| 2475 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2476 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2477 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2478 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2479 | |
| 2480 | chunk_appendf(&trash, |
| 2481 | "</table></div></u></td>" |
| 2482 | /* sessions rate : limit */ |
| 2483 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2484 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2485 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2486 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2487 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2488 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2489 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2490 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2491 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2492 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2493 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2494 | U2H(px->fe_counters.cum_sess), |
| 2495 | U2H(px->fe_counters.cum_conn), |
| 2496 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2497 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2498 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2499 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2500 | chunk_appendf(&trash, |
| 2501 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2502 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2503 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2504 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2505 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2506 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2507 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2508 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2509 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2510 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2511 | U2H(px->fe_counters.p.http.cum_req), |
| 2512 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2513 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2514 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2515 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2516 | (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] | 2517 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2518 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2519 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2520 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2521 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2522 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2523 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2524 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2525 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2526 | /* sessions: lbtot, lastsess */ |
| 2527 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2528 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2529 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2530 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2531 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2532 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2533 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2534 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2535 | "<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] | 2536 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2537 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2538 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2539 | px->fe_counters.comp_in ? |
| 2540 | (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] | 2541 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2542 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2543 | chunk_appendf(&trash, |
| 2544 | /* denied: req, resp */ |
| 2545 | "<td>%s</td><td>%s</td>" |
| 2546 | /* errors : request, connect, response */ |
| 2547 | "<td>%s</td><td></td><td></td>" |
| 2548 | /* warnings: retries, redispatches */ |
| 2549 | "<td></td><td></td>" |
| 2550 | /* server status : reflect frontend status */ |
| 2551 | "<td class=ac>%s</td>" |
| 2552 | /* rest of server: nothing */ |
| 2553 | "<td class=ac colspan=8></td></tr>" |
| 2554 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2555 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2556 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2557 | px->state == PR_STREADY ? "OPEN" : |
| 2558 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2559 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2560 | else { /* CSV mode */ |
| 2561 | chunk_appendf(&trash, |
| 2562 | /* pxid, name, queue cur, queue max, */ |
| 2563 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2564 | /* sessions : current, max, limit, total */ |
| 2565 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2566 | /* bytes : in, out */ |
| 2567 | "%lld,%lld," |
| 2568 | /* denied: req, resp */ |
| 2569 | "%lld,%lld," |
| 2570 | /* errors : request, connect, response */ |
| 2571 | "%lld,,," |
| 2572 | /* warnings: retries, redispatches */ |
| 2573 | ",," |
| 2574 | /* server status : reflect frontend status */ |
| 2575 | "%s," |
| 2576 | /* rest of server: nothing */ |
| 2577 | ",,,,,,,," |
| 2578 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2579 | "%d,%d,0,,,,%d," |
| 2580 | /* rate, rate_lim, rate_max */ |
| 2581 | "%u,%u,%u," |
| 2582 | /* check_status, check_code, check_duration */ |
| 2583 | ",,,", |
| 2584 | px->id, |
| 2585 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2586 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2587 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2588 | px->fe_counters.failed_req, |
| 2589 | px->state == PR_STREADY ? "OPEN" : |
| 2590 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2591 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2592 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2593 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2594 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2595 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2596 | if (px->mode == PR_MODE_HTTP) { |
| 2597 | for (i=1; i<6; i++) |
| 2598 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2599 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2600 | } |
| 2601 | else |
| 2602 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2603 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2604 | /* failed health analyses */ |
| 2605 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2606 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2607 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2608 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2609 | read_freq_ctr(&px->fe_req_per_sec), |
| 2610 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2611 | |
| 2612 | /* errors: cli_aborts, srv_aborts */ |
| 2613 | chunk_appendf(&trash, ",,"); |
| 2614 | |
| 2615 | /* compression: in, out, bypassed */ |
| 2616 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2617 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2618 | |
| 2619 | /* compression: comp_rsp */ |
| 2620 | chunk_appendf(&trash, "%lld,", |
| 2621 | px->fe_counters.p.http.comp_rsp); |
| 2622 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2623 | /* lastsess */ |
| 2624 | chunk_appendf(&trash, ","); |
| 2625 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2626 | /* finish with EOL */ |
| 2627 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2628 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2629 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2630 | } |
| 2631 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2632 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2633 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2634 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2635 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2636 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2637 | 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] | 2638 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2639 | struct appctx *appctx = __objt_appctx(si->end); |
| 2640 | |
| 2641 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2642 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2643 | 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] | 2644 | /* Column sub-heading for Enable or Disable server */ |
| 2645 | chunk_appendf(&trash, "<td></td>"); |
| 2646 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2647 | chunk_appendf(&trash, |
| 2648 | /* frontend name, listener name */ |
| 2649 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2650 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2651 | "", |
| 2652 | px->id, l->name, |
| 2653 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2654 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2655 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2656 | if (flags & ST_SHLGNDS) { |
| 2657 | char str[INET6_ADDRSTRLEN]; |
| 2658 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2659 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2660 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2661 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2662 | port = get_host_port(&l->addr); |
| 2663 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2664 | case AF_INET: |
| 2665 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2666 | break; |
| 2667 | case AF_INET6: |
| 2668 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2669 | break; |
| 2670 | case AF_UNIX: |
| 2671 | chunk_appendf(&trash, "unix, "); |
| 2672 | break; |
| 2673 | case -1: |
| 2674 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2675 | break; |
| 2676 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2677 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2678 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2679 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2680 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2681 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2682 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2683 | /* queue */ |
| 2684 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2685 | /* sessions rate: current, max, limit */ |
| 2686 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2687 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2688 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2689 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2690 | /* bytes: in, out */ |
| 2691 | "<td>%s</td><td>%s</td>" |
| 2692 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2693 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2694 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2695 | 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] | 2696 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2697 | chunk_appendf(&trash, |
| 2698 | /* denied: req, resp */ |
| 2699 | "<td>%s</td><td>%s</td>" |
| 2700 | /* errors: request, connect, response */ |
| 2701 | "<td>%s</td><td></td><td></td>" |
| 2702 | /* warnings: retries, redispatches */ |
| 2703 | "<td></td><td></td>" |
| 2704 | /* server status: reflect listener status */ |
| 2705 | "<td class=ac>%s</td>" |
| 2706 | /* rest of server: nothing */ |
| 2707 | "<td class=ac colspan=8></td></tr>" |
| 2708 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2709 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2710 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2711 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2712 | } |
| 2713 | else { /* CSV mode */ |
| 2714 | chunk_appendf(&trash, |
| 2715 | /* pxid, name, queue cur, queue max, */ |
| 2716 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2717 | /* sessions: current, max, limit, total */ |
| 2718 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2719 | /* bytes: in, out */ |
| 2720 | "%lld,%lld," |
| 2721 | /* denied: req, resp */ |
| 2722 | "%lld,%lld," |
| 2723 | /* errors: request, connect, response */ |
| 2724 | "%lld,,," |
| 2725 | /* warnings: retries, redispatches */ |
| 2726 | ",," |
| 2727 | /* server status: reflect listener status */ |
| 2728 | "%s," |
| 2729 | /* rest of server: nothing */ |
| 2730 | ",,,,,,,," |
| 2731 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2732 | "%d,%d,%d,,,,%d," |
| 2733 | /* rate, rate_lim, rate_max */ |
| 2734 | ",,," |
| 2735 | /* check_status, check_code, check_duration */ |
| 2736 | ",,," |
| 2737 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2738 | ",,,,,," |
| 2739 | /* failed health analyses */ |
| 2740 | "," |
| 2741 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2742 | ",,," |
| 2743 | /* errors: cli_aborts, srv_aborts */ |
| 2744 | ",," |
| 2745 | /* compression: in, out, bypassed, comp_rsp */ |
| 2746 | ",,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2747 | /* lastsess */ |
| 2748 | "," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2749 | "\n", |
| 2750 | px->id, l->name, |
| 2751 | l->nbconn, l->counters->conn_max, |
| 2752 | l->maxconn, l->counters->cum_conn, |
| 2753 | l->counters->bytes_in, l->counters->bytes_out, |
| 2754 | l->counters->denied_req, l->counters->denied_resp, |
| 2755 | l->counters->failed_req, |
| 2756 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2757 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2758 | } |
| 2759 | return 1; |
| 2760 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2761 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2762 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2763 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2764 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2765 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2766 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2767 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2768 | */ |
| 2769 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2770 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2771 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2772 | struct server *ref = sv->track ? sv->track : sv; |
| 2773 | char str[INET6_ADDRSTRLEN]; |
| 2774 | struct chunk src; |
| 2775 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2776 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2777 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2778 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2779 | "DOWN", |
| 2780 | "DN %d/%d ↑", |
| 2781 | "UP %d/%d ↓", |
| 2782 | "UP", |
| 2783 | "NOLB %d/%d ↓", |
| 2784 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2785 | "DRAIN %d/%d ↓", |
| 2786 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2787 | "<i>no check</i>" |
| 2788 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2789 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2790 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2791 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2792 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2793 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2794 | "<tr class=\"%s%d\">", |
| 2795 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2796 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2797 | 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] | 2798 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2799 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2800 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2801 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2802 | chunk_appendf(&trash, |
| 2803 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2804 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2805 | "", |
| 2806 | px->id, sv->id, |
| 2807 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2808 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2809 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2810 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2811 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2812 | |
| 2813 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2814 | case AF_INET: |
| 2815 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2816 | break; |
| 2817 | case AF_INET6: |
| 2818 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2819 | break; |
| 2820 | case AF_UNIX: |
| 2821 | chunk_appendf(&trash, "unix, "); |
| 2822 | break; |
| 2823 | case -1: |
| 2824 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2825 | break; |
| 2826 | default: /* address family not supported */ |
| 2827 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +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 | /* id */ |
| 2831 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2832 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2833 | /* cookie */ |
| 2834 | if (sv->cookie) { |
| 2835 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2836 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2837 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2838 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2839 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2840 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2841 | } |
| 2842 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2843 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2844 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2845 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2846 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2847 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2848 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2849 | /* sessions rate : current, max, limit */ |
| 2850 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2851 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2852 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2853 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2854 | 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] | 2855 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2856 | |
| 2857 | chunk_appendf(&trash, |
| 2858 | /* sessions: current, max, limit, total */ |
| 2859 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2860 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2861 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2862 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2863 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2864 | U2H(sv->counters.cum_sess), |
| 2865 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2866 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2867 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2868 | if (px->mode == PR_MODE_HTTP) { |
| 2869 | unsigned long long tot; |
| 2870 | for (tot = i = 0; i < 6; i++) |
| 2871 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2872 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2873 | chunk_appendf(&trash, |
| 2874 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2875 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2876 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2877 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2878 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2879 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2880 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2881 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2882 | U2H(tot), |
| 2883 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2884 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2885 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2886 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2887 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2888 | 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] | 2889 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2890 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2891 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2892 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2893 | /* sessions: lbtot, last */ |
| 2894 | "<td>%s</td><td>%s</td>", |
| 2895 | U2H(sv->counters.cum_lbconn), |
| 2896 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2897 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2898 | chunk_appendf(&trash, |
| 2899 | /* bytes : in, out */ |
| 2900 | "<td>%s</td><td>%s</td>" |
| 2901 | /* denied: req, resp */ |
| 2902 | "<td></td><td>%s</td>" |
| 2903 | /* errors : request, connect */ |
| 2904 | "<td></td><td>%s</td>" |
| 2905 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2906 | "<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] | 2907 | /* warnings: retries, redispatches */ |
| 2908 | "<td>%lld</td><td>%lld</td>" |
| 2909 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2910 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2911 | U2H(sv->counters.failed_secu), |
| 2912 | U2H(sv->counters.failed_conns), |
| 2913 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2914 | sv->counters.cli_aborts, |
| 2915 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2916 | sv->counters.retries, sv->counters.redispatches); |
| 2917 | |
| 2918 | /* status, lest check */ |
| 2919 | chunk_appendf(&trash, "<td class=ac>"); |
| 2920 | |
| 2921 | if (sv->state & SRV_MAINTAIN) { |
| 2922 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2923 | chunk_appendf(&trash, "MAINT"); |
| 2924 | } |
| 2925 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2926 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2927 | chunk_appendf(&trash, "MAINT(via)"); |
| 2928 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2929 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2930 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2931 | chunk_appendf(&trash, |
| 2932 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2933 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2934 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2935 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2936 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2937 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2938 | chunk_appendf(&trash, |
| 2939 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 2940 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2941 | get_check_status_info(sv->check.status)); |
| 2942 | |
| 2943 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2944 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2945 | |
| 2946 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2947 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2948 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2949 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2950 | get_check_status_description(sv->check.status)); |
| 2951 | if (*sv->check.desc) { |
| 2952 | chunk_appendf(&trash, ": "); |
| 2953 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2954 | chunk_htmlencode(&trash, &src); |
| 2955 | } |
| 2956 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2957 | } |
| 2958 | else |
| 2959 | chunk_appendf(&trash, "</td><td>"); |
| 2960 | |
| 2961 | chunk_appendf(&trash, |
| 2962 | /* weight */ |
| 2963 | "</td><td class=ac>%d</td>" |
| 2964 | /* act, bck */ |
| 2965 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2966 | "", |
| 2967 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2968 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2969 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2970 | |
| 2971 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2972 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2973 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2974 | |
| 2975 | if (ref->observe) |
| 2976 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2977 | |
| 2978 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2979 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2980 | "<td>%lld</td><td>%s</td>" |
| 2981 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2982 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2983 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2984 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2985 | else if (sv != ref) { |
| 2986 | if (sv->state & SRV_MAINTAIN) |
| 2987 | chunk_appendf(&trash, |
| 2988 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2989 | ref->proxy->id, ref->id); |
| 2990 | else |
| 2991 | chunk_appendf(&trash, |
| 2992 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2993 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2994 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2995 | else |
| 2996 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2997 | |
| 2998 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2999 | if (sv->state & SRV_WARMINGUP) |
| 3000 | 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] | 3001 | else |
| 3002 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3003 | } |
| 3004 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3005 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3006 | "DOWN,", |
| 3007 | "DOWN %d/%d,", |
| 3008 | "UP %d/%d,", |
| 3009 | "UP,", |
| 3010 | "NOLB %d/%d,", |
| 3011 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3012 | "DRAIN %d/%d,", |
| 3013 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3014 | "no check," |
| 3015 | }; |
| 3016 | |
| 3017 | chunk_appendf(&trash, |
| 3018 | /* pxid, name */ |
| 3019 | "%s,%s," |
| 3020 | /* queue : current, max */ |
| 3021 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3022 | /* sessions : current, max, limit, total */ |
| 3023 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3024 | /* bytes : in, out */ |
| 3025 | "%lld,%lld," |
| 3026 | /* denied: req, resp */ |
| 3027 | ",%lld," |
| 3028 | /* errors : request, connect, response */ |
| 3029 | ",%lld,%lld," |
| 3030 | /* warnings: retries, redispatches */ |
| 3031 | "%lld,%lld," |
| 3032 | "", |
| 3033 | px->id, sv->id, |
| 3034 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3035 | 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] | 3036 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3037 | sv->counters.failed_secu, |
| 3038 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3039 | sv->counters.retries, sv->counters.redispatches); |
| 3040 | |
| 3041 | /* status */ |
| 3042 | if (sv->state & SRV_MAINTAIN) |
| 3043 | chunk_appendf(&trash, "MAINT,"); |
| 3044 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 3045 | chunk_appendf(&trash, "MAINT(via),"); |
| 3046 | else |
| 3047 | chunk_appendf(&trash, |
| 3048 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 3049 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3050 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3051 | |
| 3052 | chunk_appendf(&trash, |
| 3053 | /* weight, active, backup */ |
| 3054 | "%d,%d,%d," |
| 3055 | "", |
| 3056 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3057 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 3058 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 3059 | |
| 3060 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3061 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3062 | chunk_appendf(&trash, |
| 3063 | "%lld,%lld,%d,%d,", |
| 3064 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3065 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3066 | else |
| 3067 | chunk_appendf(&trash, ",,,,"); |
| 3068 | |
| 3069 | /* queue limit, pid, iid, sid, */ |
| 3070 | chunk_appendf(&trash, |
| 3071 | "%s," |
| 3072 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3073 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3074 | relative_pid, px->uuid, sv->puid); |
| 3075 | |
| 3076 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3077 | if (sv->state & SRV_WARMINGUP) |
| 3078 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3079 | |
| 3080 | /* sessions: lbtot */ |
| 3081 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3082 | |
| 3083 | /* tracked */ |
| 3084 | if (sv->track) |
| 3085 | chunk_appendf(&trash, "%s/%s,", |
| 3086 | sv->track->proxy->id, sv->track->id); |
| 3087 | else |
| 3088 | chunk_appendf(&trash, ","); |
| 3089 | |
| 3090 | /* type */ |
| 3091 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3092 | |
| 3093 | /* rate */ |
| 3094 | chunk_appendf(&trash, "%u,,%u,", |
| 3095 | read_freq_ctr(&sv->sess_per_sec), |
| 3096 | sv->counters.sps_max); |
| 3097 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3098 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3099 | /* check_status */ |
| 3100 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3101 | |
| 3102 | /* check_code */ |
| 3103 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3104 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3105 | else |
| 3106 | chunk_appendf(&trash, ","); |
| 3107 | |
| 3108 | /* check_duration */ |
| 3109 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3110 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3111 | else |
| 3112 | chunk_appendf(&trash, ","); |
| 3113 | |
| 3114 | } |
| 3115 | else |
| 3116 | chunk_appendf(&trash, ",,,"); |
| 3117 | |
| 3118 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3119 | if (px->mode == PR_MODE_HTTP) { |
| 3120 | for (i=1; i<6; i++) |
| 3121 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3122 | |
| 3123 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3124 | } |
| 3125 | else |
| 3126 | chunk_appendf(&trash, ",,,,,,"); |
| 3127 | |
| 3128 | /* failed health analyses */ |
| 3129 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3130 | |
| 3131 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3132 | chunk_appendf(&trash, ",,,"); |
| 3133 | |
| 3134 | /* errors: cli_aborts, srv_aborts */ |
| 3135 | chunk_appendf(&trash, "%lld,%lld,", |
| 3136 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3137 | |
| 3138 | /* compression: in, out, bypassed, comp_rsp */ |
| 3139 | chunk_appendf(&trash, ",,,,"); |
| 3140 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3141 | /* lastsess */ |
| 3142 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3143 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3144 | /* finish with EOL */ |
| 3145 | chunk_appendf(&trash, "\n"); |
| 3146 | } |
| 3147 | return 1; |
| 3148 | } |
| 3149 | |
| 3150 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3151 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3152 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3153 | */ |
| 3154 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3155 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3156 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3157 | struct chunk src; |
| 3158 | int i; |
| 3159 | |
| 3160 | if (!(px->cap & PR_CAP_BE)) |
| 3161 | return 0; |
| 3162 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3163 | 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] | 3164 | return 0; |
| 3165 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3166 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3167 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3168 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3169 | /* Column sub-heading for Enable or Disable server */ |
| 3170 | chunk_appendf(&trash, "<td></td>"); |
| 3171 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3172 | chunk_appendf(&trash, |
| 3173 | "<td class=ac>" |
| 3174 | /* name */ |
| 3175 | "%s<a name=\"%s/Backend\"></a>" |
| 3176 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3177 | "", |
| 3178 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3179 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3180 | |
| 3181 | if (flags & ST_SHLGNDS) { |
| 3182 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3183 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3184 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3185 | |
| 3186 | /* cookie */ |
| 3187 | if (px->cookie_name) { |
| 3188 | chunk_appendf(&trash, ", cookie: '"); |
| 3189 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3190 | chunk_htmlencode(&trash, &src); |
| 3191 | chunk_appendf(&trash, "'"); |
| 3192 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3193 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3197 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3198 | /* queue : current, max */ |
| 3199 | "<td>%s</td><td>%s</td><td></td>" |
| 3200 | /* sessions rate : current, max, limit */ |
| 3201 | "<td>%s</td><td>%s</td><td></td>" |
| 3202 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3203 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3204 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3205 | 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] | 3206 | |
| 3207 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3208 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3209 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3210 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3211 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3212 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3213 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3214 | U2H(px->be_counters.cum_conn), |
| 3215 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3216 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3217 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3218 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3219 | chunk_appendf(&trash, |
| 3220 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3221 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3222 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3223 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3224 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3225 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3226 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3227 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3228 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3229 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3230 | U2H(px->be_counters.p.http.cum_req), |
| 3231 | U2H(px->be_counters.p.http.rsp[1]), |
| 3232 | U2H(px->be_counters.p.http.rsp[2]), |
| 3233 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3234 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3235 | (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] | 3236 | U2H(px->be_counters.p.http.rsp[3]), |
| 3237 | U2H(px->be_counters.p.http.rsp[4]), |
| 3238 | U2H(px->be_counters.p.http.rsp[5]), |
| 3239 | U2H(px->be_counters.p.http.rsp[0]), |
| 3240 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3241 | } |
| 3242 | |
| 3243 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3244 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3245 | /* sessions: lbtot, last */ |
| 3246 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3247 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3248 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3249 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3250 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3251 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3252 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3253 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3254 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3255 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3256 | "<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] | 3257 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3258 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3259 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3260 | px->be_counters.comp_in ? |
| 3261 | (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] | 3262 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3263 | |
| 3264 | chunk_appendf(&trash, |
| 3265 | /* denied: req, resp */ |
| 3266 | "<td>%s</td><td>%s</td>" |
| 3267 | /* errors : request, connect */ |
| 3268 | "<td></td><td>%s</td>" |
| 3269 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3270 | "<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] | 3271 | /* warnings: retries, redispatches */ |
| 3272 | "<td>%lld</td><td>%lld</td>" |
| 3273 | /* backend status: reflect backend status (up/down): we display UP |
| 3274 | * if the backend has known working servers or if it has no server at |
| 3275 | * all (eg: for stats). Then we display the total weight, number of |
| 3276 | * active and backups. */ |
| 3277 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3278 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3279 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3280 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3281 | U2H(px->be_counters.failed_conns), |
| 3282 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3283 | px->be_counters.cli_aborts, |
| 3284 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3285 | px->be_counters.retries, px->be_counters.redispatches, |
| 3286 | human_time(now.tv_sec - px->last_change, 1), |
| 3287 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3288 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3289 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3290 | px->srv_act, px->srv_bck); |
| 3291 | |
| 3292 | chunk_appendf(&trash, |
| 3293 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3294 | "<td class=ac> </td><td>%d</td>" |
| 3295 | "<td>%s</td>" |
| 3296 | "<td></td>" |
| 3297 | "</tr>", |
| 3298 | px->down_trans, |
| 3299 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3300 | } |
| 3301 | else { /* CSV mode */ |
| 3302 | chunk_appendf(&trash, |
| 3303 | /* pxid, name */ |
| 3304 | "%s,BACKEND," |
| 3305 | /* queue : current, max */ |
| 3306 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3307 | /* sessions : current, max, limit, total */ |
| 3308 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3309 | /* bytes : in, out */ |
| 3310 | "%lld,%lld," |
| 3311 | /* denied: req, resp */ |
| 3312 | "%lld,%lld," |
| 3313 | /* errors : request, connect, response */ |
| 3314 | ",%lld,%lld," |
| 3315 | /* warnings: retries, redispatches */ |
| 3316 | "%lld,%lld," |
| 3317 | /* backend status: reflect backend status (up/down): we display UP |
| 3318 | * if the backend has known working servers or if it has no server at |
| 3319 | * all (eg: for stats). Then we display the total weight, number of |
| 3320 | * active and backups. */ |
| 3321 | "%s," |
| 3322 | "%d,%d,%d," |
| 3323 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3324 | ",%d,%d,%d,," |
| 3325 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3326 | "%d,%d,0,,%lld,,%d," |
| 3327 | /* rate, rate_lim, rate_max, */ |
| 3328 | "%u,,%u," |
| 3329 | /* check_status, check_code, check_duration */ |
| 3330 | ",,,", |
| 3331 | px->id, |
| 3332 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3333 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3334 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3335 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3336 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3337 | px->be_counters.retries, px->be_counters.redispatches, |
| 3338 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3339 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3340 | px->srv_act, px->srv_bck, |
| 3341 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3342 | px->srv?be_downtime(px):0, |
| 3343 | relative_pid, px->uuid, |
| 3344 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3345 | read_freq_ctr(&px->be_sess_per_sec), |
| 3346 | px->be_counters.sps_max); |
| 3347 | |
| 3348 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3349 | if (px->mode == PR_MODE_HTTP) { |
| 3350 | for (i=1; i<6; i++) |
| 3351 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3352 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3353 | } |
| 3354 | else |
| 3355 | chunk_appendf(&trash, ",,,,,,"); |
| 3356 | |
| 3357 | /* failed health analyses */ |
| 3358 | chunk_appendf(&trash, ","); |
| 3359 | |
| 3360 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3361 | chunk_appendf(&trash, ",,,"); |
| 3362 | |
| 3363 | /* errors: cli_aborts, srv_aborts */ |
| 3364 | chunk_appendf(&trash, "%lld,%lld,", |
| 3365 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3366 | |
| 3367 | /* compression: in, out, bypassed */ |
| 3368 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3369 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3370 | |
| 3371 | /* compression: comp_rsp */ |
| 3372 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3373 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3374 | /* lastsess */ |
| 3375 | chunk_appendf(&trash, "%d,", be_lastsession(px)); |
| 3376 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3377 | /* finish with EOL */ |
| 3378 | chunk_appendf(&trash, "\n"); |
| 3379 | } |
| 3380 | return 1; |
| 3381 | } |
| 3382 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3383 | /* 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] | 3384 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3385 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3386 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3387 | 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] | 3388 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3389 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3390 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3391 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3392 | 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] | 3393 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3394 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3395 | /* 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] | 3396 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3397 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3398 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3399 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3400 | 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] | 3401 | } |
| 3402 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3403 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3404 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3405 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3406 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3407 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3408 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | /* print a new table */ |
| 3412 | chunk_appendf(&trash, |
| 3413 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3414 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3415 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3416 | |
| 3417 | chunk_appendf(&trash, |
| 3418 | "<a name=\"%s\"></a>%s" |
| 3419 | "<a class=px href=\"#%s\">%s</a>", |
| 3420 | px->id, |
| 3421 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3422 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3423 | |
| 3424 | if (uri->flags & ST_SHLGNDS) { |
| 3425 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3426 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3427 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3428 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3429 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3433 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3434 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3435 | "</tr>\n" |
| 3436 | "</table>\n" |
| 3437 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3438 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3439 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3440 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3441 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3442 | 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] | 3443 | /* Column heading for Enable or Disable server */ |
| 3444 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3445 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3446 | |
| 3447 | chunk_appendf(&trash, |
| 3448 | "<th rowspan=2></th>" |
| 3449 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3450 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3451 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3452 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3453 | "<th colspan=9>Server</th>" |
| 3454 | "</tr>\n" |
| 3455 | "<tr class=\"titre\">" |
| 3456 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3457 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3458 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3459 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3460 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3461 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3462 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3463 | "<th>Thrtle</th>\n" |
| 3464 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3465 | } |
| 3466 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3467 | /* 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] | 3468 | * 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] | 3469 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3470 | 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] | 3471 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3472 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3473 | chunk_appendf(&trash, "</table>"); |
| 3474 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3475 | 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] | 3476 | /* close the form used to enable/disable this proxy servers */ |
| 3477 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3478 | "Choose the action to perform on the checked servers : " |
| 3479 | "<select name=action>" |
| 3480 | "<option value=\"\"></option>" |
| 3481 | "<option value=\"disable\">Disable</option>" |
| 3482 | "<option value=\"enable\">Enable</option>" |
| 3483 | "<option value=\"stop\">Soft Stop</option>" |
| 3484 | "<option value=\"start\">Soft Start</option>" |
| 3485 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3486 | "</select>" |
| 3487 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3488 | " <input type=\"submit\" value=\"Apply\">" |
| 3489 | "</form>", |
| 3490 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3494 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3495 | |
| 3496 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3497 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3498 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3499 | * buffer space, or non-zero if everything completed. This function is used |
| 3500 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3501 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3502 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3503 | 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] | 3504 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3505 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3506 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3507 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3508 | 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] | 3509 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3510 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3511 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3512 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3513 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3514 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3515 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3516 | if (uri && uri->scope) { |
| 3517 | /* we have a limited scope, we have to check the proxy name */ |
| 3518 | struct stat_scope *scope; |
| 3519 | int len; |
| 3520 | |
| 3521 | len = strlen(px->id); |
| 3522 | scope = uri->scope; |
| 3523 | |
| 3524 | while (scope) { |
| 3525 | /* match exact proxy name */ |
| 3526 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3527 | break; |
| 3528 | |
| 3529 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3530 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3531 | break; |
| 3532 | scope = scope->next; |
| 3533 | } |
| 3534 | |
| 3535 | /* proxy name not found : don't dump anything */ |
| 3536 | if (scope == NULL) |
| 3537 | return 1; |
| 3538 | } |
| 3539 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3540 | /* if the user has requested a limited output and the proxy |
| 3541 | * name does not match, skip it. |
| 3542 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3543 | if (appctx->ctx.stats.scope_len && |
| 3544 | 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] | 3545 | return 1; |
| 3546 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3547 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3548 | (appctx->ctx.stats.iid != -1) && |
| 3549 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3550 | return 1; |
| 3551 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3552 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3553 | /* fall through */ |
| 3554 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3555 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3556 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3557 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3558 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3559 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3560 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3561 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3562 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3563 | /* fall through */ |
| 3564 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3565 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3566 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3567 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3568 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3569 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3570 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3571 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3572 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3573 | /* fall through */ |
| 3574 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3575 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3576 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3577 | 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] | 3578 | if (buffer_almost_full(rep->buf)) { |
| 3579 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3580 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3581 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3582 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3583 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3584 | if (!l->counters) |
| 3585 | continue; |
| 3586 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3587 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3588 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3589 | break; |
| 3590 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3591 | 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] | 3592 | continue; |
| 3593 | } |
| 3594 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3595 | /* print the frontend */ |
| 3596 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3597 | if (bi_putchk(rep, &trash) == -1) |
| 3598 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3599 | } |
| 3600 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3601 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3602 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3603 | /* fall through */ |
| 3604 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3605 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3606 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3607 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3608 | 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] | 3609 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3610 | if (buffer_almost_full(rep->buf)) { |
| 3611 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3612 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3613 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3614 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3615 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3616 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3617 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3618 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3619 | break; |
| 3620 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3621 | 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] | 3622 | continue; |
| 3623 | } |
| 3624 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3625 | if (sv->track) |
| 3626 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3627 | else |
| 3628 | svs = sv; |
| 3629 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3630 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3631 | if (!(svs->check.state & CHK_ST_ENABLED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3632 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3633 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 3634 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3635 | sv_state = 3; /* UP */ |
| 3636 | else |
| 3637 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3638 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3639 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3640 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3641 | else if (svs->state & SRV_GOINGDOWN) |
| 3642 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3643 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3644 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 3645 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3646 | sv_state = 1; /* going up */ |
| 3647 | else |
| 3648 | sv_state = 0; /* DOWN */ |
| 3649 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3650 | 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] | 3651 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3652 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3653 | continue; |
| 3654 | } |
| 3655 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3656 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3657 | if (bi_putchk(rep, &trash) == -1) |
| 3658 | return 0; |
| 3659 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3660 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3661 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3662 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3663 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3664 | case STAT_PX_ST_BE: |
| 3665 | /* print the backend */ |
| 3666 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3667 | if (bi_putchk(rep, &trash) == -1) |
| 3668 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3669 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3670 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3671 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3672 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3673 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3674 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3675 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3676 | if (bi_putchk(rep, &trash) == -1) |
| 3677 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3678 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3679 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3680 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3681 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3682 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3683 | case STAT_PX_ST_FIN: |
| 3684 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3685 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3686 | default: |
| 3687 | /* unknown state, we should put an abort() here ! */ |
| 3688 | return 1; |
| 3689 | } |
| 3690 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3691 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3692 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3693 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3694 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3695 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3696 | { |
| 3697 | /* WARNING! This must fit in the first buffer !!! */ |
| 3698 | chunk_appendf(&trash, |
| 3699 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3700 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3701 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3702 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3703 | "<style type=\"text/css\"><!--\n" |
| 3704 | "body {" |
| 3705 | " font-family: arial, helvetica, sans-serif;" |
| 3706 | " font-size: 12px;" |
| 3707 | " font-weight: normal;" |
| 3708 | " color: black;" |
| 3709 | " background: white;" |
| 3710 | "}\n" |
| 3711 | "th,td {" |
| 3712 | " font-size: 10px;" |
| 3713 | "}\n" |
| 3714 | "h1 {" |
| 3715 | " font-size: x-large;" |
| 3716 | " margin-bottom: 0.5em;" |
| 3717 | "}\n" |
| 3718 | "h2 {" |
| 3719 | " font-family: helvetica, arial;" |
| 3720 | " font-size: x-large;" |
| 3721 | " font-weight: bold;" |
| 3722 | " font-style: italic;" |
| 3723 | " color: #6020a0;" |
| 3724 | " margin-top: 0em;" |
| 3725 | " margin-bottom: 0em;" |
| 3726 | "}\n" |
| 3727 | "h3 {" |
| 3728 | " font-family: helvetica, arial;" |
| 3729 | " font-size: 16px;" |
| 3730 | " font-weight: bold;" |
| 3731 | " color: #b00040;" |
| 3732 | " background: #e8e8d0;" |
| 3733 | " margin-top: 0em;" |
| 3734 | " margin-bottom: 0em;" |
| 3735 | "}\n" |
| 3736 | "li {" |
| 3737 | " margin-top: 0.25em;" |
| 3738 | " margin-right: 2em;" |
| 3739 | "}\n" |
| 3740 | ".hr {margin-top: 0.25em;" |
| 3741 | " border-color: black;" |
| 3742 | " border-bottom-style: solid;" |
| 3743 | "}\n" |
| 3744 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3745 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3746 | ".frontend {background: #e8e8d0;}\n" |
| 3747 | ".socket {background: #d0d0d0;}\n" |
| 3748 | ".backend {background: #e8e8d0;}\n" |
| 3749 | ".active0 {background: #ff9090;}\n" |
| 3750 | ".active1 {background: #ffd020;}\n" |
| 3751 | ".active2 {background: #ffffa0;}\n" |
| 3752 | ".active3 {background: #c0ffc0;}\n" |
| 3753 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3754 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3755 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3756 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3757 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3758 | ".backup0 {background: #ff9090;}\n" |
| 3759 | ".backup1 {background: #ff80ff;}\n" |
| 3760 | ".backup2 {background: #c060ff;}\n" |
| 3761 | ".backup3 {background: #b0d0ff;}\n" |
| 3762 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3763 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3764 | ".backup6 {background: #c060ff;}\n" |
| 3765 | ".backup7 {background: #cc9900;}\n" |
| 3766 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3767 | ".maintain {background: #c07820;}\n" |
| 3768 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3769 | "\n" |
| 3770 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3771 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3772 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3773 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3774 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3775 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3776 | "\n" |
| 3777 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3778 | "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" |
| 3779 | "table.tbl td.ac { text-align: center;}\n" |
| 3780 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3781 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3782 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3783 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3784 | "\n" |
| 3785 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3786 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3787 | "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] | 3788 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3789 | "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] | 3790 | "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] | 3791 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3792 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3793 | " display:block;\n" |
| 3794 | " visibility:hidden;\n" |
| 3795 | " z-index:2147483647;\n" |
| 3796 | " position:absolute;\n" |
| 3797 | " padding:2px 4px 3px;\n" |
| 3798 | " background:#f0f060; color:#000000;\n" |
| 3799 | " border:1px solid #7040c0;\n" |
| 3800 | " white-space:nowrap;\n" |
| 3801 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3802 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3803 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3804 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3805 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3806 | "-->\n" |
| 3807 | "</style></head>\n", |
| 3808 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3809 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3810 | ); |
| 3811 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3812 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3813 | /* 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] | 3814 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3815 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3816 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3817 | 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] | 3818 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3819 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3820 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3821 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3822 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3823 | /* WARNING! this has to fit the first packet too. |
| 3824 | * We are around 3.5 kB, add adding entries will |
| 3825 | * become tricky if we want to support 4kB buffers ! |
| 3826 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3827 | chunk_appendf(&trash, |
| 3828 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3829 | PRODUCT_NAME "%s</a></h1>\n" |
| 3830 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3831 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3832 | "<h3>> General process information</h3>\n" |
| 3833 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3834 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3835 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3836 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3837 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3838 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3839 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3840 | "</td><td align=\"center\" nowrap>\n" |
| 3841 | "<table class=\"lgd\"><tr>\n" |
| 3842 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3843 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3844 | "</tr><tr>\n" |
| 3845 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3846 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3847 | "</tr><tr>\n" |
| 3848 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3849 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3850 | "</tr><tr>\n" |
| 3851 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3852 | "</tr><tr>\n" |
| 3853 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3854 | "</tr><tr>\n" |
| 3855 | "<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] | 3856 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3857 | "<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] | 3858 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3859 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3860 | "</td>" |
| 3861 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3862 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3863 | "", |
| 3864 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3865 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3866 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3867 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3868 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3869 | pid, relative_pid, global.nbproc, |
| 3870 | up / 86400, (up % 86400) / 3600, |
| 3871 | (up % 3600) / 60, (up % 60), |
| 3872 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3873 | global.rlimit_memmax ? " MB" : "", |
| 3874 | global.rlimit_nofile, |
| 3875 | global.maxsock, global.maxconn, global.maxpipes, |
| 3876 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3877 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3878 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3879 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3880 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3881 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3882 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3883 | |
| 3884 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3885 | "<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] | 3886 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3887 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3888 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3889 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3890 | STAT_SCOPE_TXT_MAXLEN); |
| 3891 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3892 | /* 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] | 3893 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3894 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3895 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3896 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3897 | 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] | 3898 | } |
| 3899 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3900 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3901 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3902 | "<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] | 3903 | uri->uri_prefix, |
| 3904 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3905 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3906 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3907 | else |
| 3908 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3909 | "<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] | 3910 | uri->uri_prefix, |
| 3911 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3912 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3913 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3914 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3915 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3916 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3917 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3918 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3919 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3920 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3921 | "", |
| 3922 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3923 | else |
| 3924 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3925 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3926 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3927 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3928 | ";norefresh", |
| 3929 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3930 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3931 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3932 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3933 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3934 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3935 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3936 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3937 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3938 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3939 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3940 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3941 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3942 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3943 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3944 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3945 | chunk_appendf(&trash, |
| 3946 | "</ul></td>" |
| 3947 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3948 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3949 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3950 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3951 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3952 | "</ul>" |
| 3953 | "</td>" |
| 3954 | "</tr></table>\n" |
| 3955 | "" |
| 3956 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3957 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3958 | if (appctx->ctx.stats.st_code) { |
| 3959 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3960 | case STAT_STATUS_DONE: |
| 3961 | chunk_appendf(&trash, |
| 3962 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3963 | "<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] | 3964 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3965 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3966 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3967 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3968 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3969 | break; |
| 3970 | case STAT_STATUS_NONE: |
| 3971 | chunk_appendf(&trash, |
| 3972 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3973 | "<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] | 3974 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3975 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3976 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3977 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3978 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3979 | break; |
| 3980 | case STAT_STATUS_PART: |
| 3981 | chunk_appendf(&trash, |
| 3982 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3983 | "<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] | 3984 | "Action partially processed.<br>" |
| 3985 | "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] | 3986 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3987 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3988 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3989 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3990 | break; |
| 3991 | case STAT_STATUS_ERRP: |
| 3992 | chunk_appendf(&trash, |
| 3993 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3994 | "<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] | 3995 | "Action not processed because of invalid parameters." |
| 3996 | "<ul>" |
| 3997 | "<li>The action is maybe unknown.</li>" |
| 3998 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3999 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4000 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4001 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4002 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4003 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4004 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4005 | break; |
| 4006 | case STAT_STATUS_EXCD: |
| 4007 | chunk_appendf(&trash, |
| 4008 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4009 | "<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] | 4010 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4011 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4012 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4013 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4014 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4015 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4016 | break; |
| 4017 | case STAT_STATUS_DENY: |
| 4018 | chunk_appendf(&trash, |
| 4019 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4020 | "<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] | 4021 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4022 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4023 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4024 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4025 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4026 | break; |
| 4027 | default: |
| 4028 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 4029 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4030 | "<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] | 4031 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4032 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4033 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4034 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4035 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4036 | } |
| 4037 | chunk_appendf(&trash, "<p>\n"); |
| 4038 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4039 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4040 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4041 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4042 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4043 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4044 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4045 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4046 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4047 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4048 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4049 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4050 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4051 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4052 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 4053 | * and the session must be closed, or -1 in case of any error. This function is |
| 4054 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4055 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4056 | 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] | 4057 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4058 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4059 | struct channel *rep = si->ib; |
| 4060 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4061 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4062 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4063 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4064 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4065 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4066 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4067 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4068 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4069 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4070 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4071 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4072 | else |
| 4073 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4074 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4075 | if (bi_putchk(rep, &trash) == -1) |
| 4076 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4077 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4078 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4079 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4080 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4081 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4082 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4083 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4084 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4085 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4086 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4087 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4088 | appctx->ctx.stats.px = proxy; |
| 4089 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4090 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4091 | /* fall through */ |
| 4092 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4093 | case STAT_ST_LIST: |
| 4094 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4095 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4096 | if (buffer_almost_full(rep->buf)) { |
| 4097 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4098 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4099 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4100 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4101 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4102 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4103 | 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] | 4104 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4105 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4106 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4107 | appctx->ctx.stats.px = px->next; |
| 4108 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4109 | } |
| 4110 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4111 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4112 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4113 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4114 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4115 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4116 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4117 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4118 | if (bi_putchk(rep, &trash) == -1) |
| 4119 | return 0; |
| 4120 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4121 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4122 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4123 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4124 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4125 | case STAT_ST_FIN: |
| 4126 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4127 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4128 | default: |
| 4129 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4130 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4131 | return -1; |
| 4132 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4133 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4134 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4135 | /* We reached the stats page through a POST request. The appctx is |
| 4136 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4137 | * Parse the posted data and enable/disable servers if necessary. |
| 4138 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4139 | */ |
| 4140 | static int stats_process_http_post(struct stream_interface *si) |
| 4141 | { |
| 4142 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4143 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4144 | |
| 4145 | struct proxy *px = NULL; |
| 4146 | struct server *sv = NULL; |
| 4147 | |
| 4148 | char key[LINESIZE]; |
| 4149 | int action = ST_ADM_ACTION_NONE; |
| 4150 | int reprocess = 0; |
| 4151 | |
| 4152 | int total_servers = 0; |
| 4153 | int altered_servers = 0; |
| 4154 | |
| 4155 | char *first_param, *cur_param, *next_param, *end_params; |
| 4156 | char *st_cur_param = NULL; |
| 4157 | char *st_next_param = NULL; |
| 4158 | |
| 4159 | struct chunk *temp; |
| 4160 | int reql; |
| 4161 | |
| 4162 | temp = get_trash_chunk(); |
| 4163 | if (temp->size < s->txn.req.body_len) { |
| 4164 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4165 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4166 | goto out; |
| 4167 | } |
| 4168 | |
| 4169 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 4170 | if (reql <= 0) { |
| 4171 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4172 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4173 | return 0; |
| 4174 | } |
| 4175 | |
| 4176 | first_param = temp->str; |
| 4177 | end_params = temp->str + reql; |
| 4178 | cur_param = next_param = end_params; |
| 4179 | *end_params = '\0'; |
| 4180 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4181 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4182 | |
| 4183 | /* |
| 4184 | * Parse the parameters in reverse order to only store the last value. |
| 4185 | * From the html form, the backend and the action are at the end. |
| 4186 | */ |
| 4187 | while (cur_param > first_param) { |
| 4188 | char *value; |
| 4189 | int poffset, plen; |
| 4190 | |
| 4191 | cur_param--; |
| 4192 | |
| 4193 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4194 | reprocess_servers: |
| 4195 | /* Parse the key */ |
| 4196 | poffset = (cur_param != first_param ? 1 : 0); |
| 4197 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4198 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4199 | strncpy(key, cur_param + poffset, plen); |
| 4200 | key[plen - 1] = '\0'; |
| 4201 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4202 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4203 | goto out; |
| 4204 | } |
| 4205 | |
| 4206 | /* Parse the value */ |
| 4207 | value = key; |
| 4208 | while (*value != '\0' && *value != '=') { |
| 4209 | value++; |
| 4210 | } |
| 4211 | if (*value == '=') { |
| 4212 | /* Ok, a value is found, we can mark the end of the key */ |
| 4213 | *value++ = '\0'; |
| 4214 | } |
| 4215 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4216 | break; |
| 4217 | |
| 4218 | /* Now we can check the key to see what to do */ |
| 4219 | if (!px && (strcmp(key, "b") == 0)) { |
| 4220 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4221 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4222 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4223 | goto out; |
| 4224 | } |
| 4225 | } |
| 4226 | else if (!action && (strcmp(key, "action") == 0)) { |
| 4227 | if (strcmp(value, "disable") == 0) { |
| 4228 | action = ST_ADM_ACTION_DISABLE; |
| 4229 | } |
| 4230 | else if (strcmp(value, "enable") == 0) { |
| 4231 | action = ST_ADM_ACTION_ENABLE; |
| 4232 | } |
| 4233 | else if (strcmp(value, "stop") == 0) { |
| 4234 | action = ST_ADM_ACTION_STOP; |
| 4235 | } |
| 4236 | else if (strcmp(value, "start") == 0) { |
| 4237 | action = ST_ADM_ACTION_START; |
| 4238 | } |
| 4239 | else if (strcmp(value, "shutdown") == 0) { |
| 4240 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4241 | } |
| 4242 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4243 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4244 | goto out; |
| 4245 | } |
| 4246 | } |
| 4247 | else if (strcmp(key, "s") == 0) { |
| 4248 | if (!(px && action)) { |
| 4249 | /* |
| 4250 | * Indicates that we'll need to reprocess the parameters |
| 4251 | * as soon as backend and action are known |
| 4252 | */ |
| 4253 | if (!reprocess) { |
| 4254 | st_cur_param = cur_param; |
| 4255 | st_next_param = next_param; |
| 4256 | } |
| 4257 | reprocess = 1; |
| 4258 | } |
| 4259 | else if ((sv = findserver(px, value)) != NULL) { |
| 4260 | switch (action) { |
| 4261 | case ST_ADM_ACTION_DISABLE: |
| 4262 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 4263 | /* Not already in maintenance, we can change the server state */ |
| 4264 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 4265 | sv->check.state |= CHK_ST_PAUSED; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4266 | set_server_down(&sv->check); |
| 4267 | altered_servers++; |
| 4268 | total_servers++; |
| 4269 | } |
| 4270 | break; |
| 4271 | case ST_ADM_ACTION_ENABLE: |
| 4272 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
Willy Tarreau | a3ae932 | 2013-12-28 21:28:49 +0100 | [diff] [blame] | 4273 | /* Already in maintenance, we can change the server state. |
| 4274 | * If this server tracks the status of another one, |
| 4275 | * we must restore the good status. |
| 4276 | */ |
| 4277 | if (!sv->track || (sv->track->state & SRV_RUNNING)) { |
| 4278 | set_server_up(&sv->check); |
| 4279 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 4280 | } |
| 4281 | else { |
| 4282 | sv->state &= ~SRV_MAINTAIN; |
| 4283 | sv->check.state &= ~CHK_ST_PAUSED; |
| 4284 | set_server_down(&sv->check); |
| 4285 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4286 | altered_servers++; |
| 4287 | total_servers++; |
| 4288 | } |
| 4289 | break; |
| 4290 | case ST_ADM_ACTION_STOP: |
| 4291 | case ST_ADM_ACTION_START: |
| 4292 | if (action == ST_ADM_ACTION_START) |
| 4293 | sv->uweight = sv->iweight; |
| 4294 | else |
| 4295 | sv->uweight = 0; |
| 4296 | |
| 4297 | server_recalc_eweight(sv); |
| 4298 | set_server_drain_state(sv); |
| 4299 | |
| 4300 | altered_servers++; |
| 4301 | total_servers++; |
| 4302 | break; |
| 4303 | case ST_ADM_ACTION_SHUTDOWN: |
| 4304 | if (px->state != PR_STSTOPPED) { |
| 4305 | struct session *sess, *sess_bck; |
| 4306 | |
| 4307 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4308 | if (sess->srv_conn == sv) |
| 4309 | session_shutdown(sess, SN_ERR_KILLED); |
| 4310 | |
| 4311 | altered_servers++; |
| 4312 | total_servers++; |
| 4313 | } |
| 4314 | break; |
| 4315 | } |
| 4316 | } else { |
| 4317 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4318 | total_servers++; |
| 4319 | } |
| 4320 | } |
| 4321 | if (reprocess && px && action) { |
| 4322 | /* Now, we know the backend and the action chosen by the user. |
| 4323 | * We can safely restart from the first server parameter |
| 4324 | * to reprocess them |
| 4325 | */ |
| 4326 | cur_param = st_cur_param; |
| 4327 | next_param = st_next_param; |
| 4328 | reprocess = 0; |
| 4329 | goto reprocess_servers; |
| 4330 | } |
| 4331 | |
| 4332 | next_param = cur_param; |
| 4333 | } |
| 4334 | } |
| 4335 | |
| 4336 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4337 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4338 | } |
| 4339 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4340 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4341 | } |
| 4342 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4343 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4344 | } |
| 4345 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4346 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4347 | } |
| 4348 | out: |
| 4349 | return 1; |
| 4350 | } |
| 4351 | |
| 4352 | |
| 4353 | static int stats_send_http_headers(struct stream_interface *si) |
| 4354 | { |
| 4355 | struct session *s = session_from_task(si->owner); |
| 4356 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4357 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4358 | |
| 4359 | chunk_printf(&trash, |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4360 | "HTTP/1.0 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4361 | "Cache-Control: no-cache\r\n" |
| 4362 | "Connection: close\r\n" |
| 4363 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4364 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4365 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4366 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4367 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4368 | uri->refresh); |
| 4369 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4370 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4371 | |
| 4372 | s->txn.status = 200; |
| 4373 | s->logs.tv_request = now; |
| 4374 | |
| 4375 | if (bi_putchk(si->ib, &trash) == -1) |
| 4376 | return 0; |
| 4377 | |
| 4378 | return 1; |
| 4379 | } |
| 4380 | |
| 4381 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4382 | { |
| 4383 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4384 | struct session *s = session_from_task(si->owner); |
| 4385 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4386 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4387 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4388 | /* 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] | 4389 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4390 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4391 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4392 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4393 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | /* We don't want to land on the posted stats page because a refresh will |
| 4397 | * repost the data. We don't want this to happen on accident so we redirect |
| 4398 | * the browse to the stats page with a GET. |
| 4399 | */ |
| 4400 | chunk_printf(&trash, |
| 4401 | "HTTP/1.1 303 See Other\r\n" |
| 4402 | "Cache-Control: no-cache\r\n" |
| 4403 | "Content-Type: text/plain\r\n" |
| 4404 | "Connection: close\r\n" |
| 4405 | "Location: %s;st=%s%s%s%s\r\n" |
| 4406 | "\r\n", |
| 4407 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4408 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4409 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4410 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4411 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4412 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4413 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4414 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4415 | scope_txt); |
| 4416 | |
| 4417 | s->txn.status = 303; |
| 4418 | s->logs.tv_request = now; |
| 4419 | |
| 4420 | if (bi_putchk(si->ib, &trash) == -1) |
| 4421 | return 0; |
| 4422 | |
| 4423 | return 1; |
| 4424 | } |
| 4425 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4426 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4427 | * 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] | 4428 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4429 | * automatically unregisters itself once transfer is complete. |
| 4430 | */ |
| 4431 | static void http_stats_io_handler(struct stream_interface *si) |
| 4432 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4433 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4434 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4435 | struct channel *req = si->ob; |
| 4436 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4437 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4438 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4439 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4440 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4441 | /* check that the output is not closed */ |
| 4442 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4443 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4444 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4445 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4446 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4447 | if (stats_send_http_headers(si)) { |
| 4448 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4449 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4450 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4451 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4452 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4453 | } |
| 4454 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4455 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4456 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4457 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4458 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4459 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4460 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4461 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4462 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4463 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4464 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4465 | } |
| 4466 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4467 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4468 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4469 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4470 | } |
| 4471 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4472 | if (appctx->st0 == STAT_HTTP_DONE) |
| 4473 | si_shutw(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4474 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4475 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4476 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4477 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4478 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4479 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4480 | si_shutr(si); |
| 4481 | res->flags |= CF_READ_NULL; |
| 4482 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4483 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4484 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4485 | /* update all other flags and resync with the other side */ |
| 4486 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4487 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4488 | /* we don't want to expire timeouts while we're processing requests */ |
| 4489 | si->ib->rex = TICK_ETERNITY; |
| 4490 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4491 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4492 | out: |
| 4493 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4494 | /* check that we have released everything then unregister */ |
| 4495 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4496 | } |
| 4497 | } |
| 4498 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4499 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4500 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4501 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4502 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4503 | return "NONE"; |
| 4504 | return conn->ctrl->name; |
| 4505 | } |
| 4506 | |
| 4507 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4508 | { |
| 4509 | static char ptr[17]; |
| 4510 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4511 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4512 | return "NONE"; |
| 4513 | |
| 4514 | if (conn->xprt == &raw_sock) |
| 4515 | return "RAW"; |
| 4516 | |
| 4517 | #ifdef USE_OPENSSL |
| 4518 | if (conn->xprt == &ssl_sock) |
| 4519 | return "SSL"; |
| 4520 | #endif |
| 4521 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4522 | return ptr; |
| 4523 | } |
| 4524 | |
| 4525 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4526 | { |
| 4527 | static char ptr[17]; |
| 4528 | |
| 4529 | if (!conn->data) |
| 4530 | return "NONE"; |
| 4531 | |
| 4532 | if (conn->data == &sess_conn_cb) |
| 4533 | return "SESS"; |
| 4534 | |
| 4535 | if (conn->data == &si_conn_cb) |
| 4536 | return "STRM"; |
| 4537 | |
| 4538 | if (conn->data == &check_conn_cb) |
| 4539 | return "CHCK"; |
| 4540 | |
| 4541 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4542 | return ptr; |
| 4543 | } |
| 4544 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4545 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4546 | * 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] | 4547 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4548 | * 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] | 4549 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4550 | 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] | 4551 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4552 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4553 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4554 | extern const char *monthname[12]; |
| 4555 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4556 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4557 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4558 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4559 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4560 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4561 | 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] | 4562 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4563 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4564 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4565 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4566 | appctx->ctx.sess.uid = 0; |
| 4567 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4568 | return 1; |
| 4569 | } |
| 4570 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4571 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4572 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4573 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4574 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4575 | /* fall through */ |
| 4576 | |
| 4577 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4578 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4579 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4580 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4581 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4582 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4583 | 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] | 4584 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 4585 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4586 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4587 | conn = objt_conn(sess->si[0].end); |
| 4588 | 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] | 4589 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4590 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4591 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4592 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4593 | break; |
| 4594 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4595 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4596 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4597 | default: |
| 4598 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4599 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4600 | break; |
| 4601 | } |
| 4602 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4603 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4604 | " 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] | 4605 | 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] | 4606 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4607 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4608 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4609 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 4610 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 4611 | sess->listener ? sess->listener->luid : 0); |
| 4612 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4613 | if (conn) |
| 4614 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4615 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4616 | 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] | 4617 | case AF_INET: |
| 4618 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4619 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4620 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4621 | break; |
| 4622 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4623 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4624 | break; |
| 4625 | default: |
| 4626 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4627 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4628 | break; |
| 4629 | } |
| 4630 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4631 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4632 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4633 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4634 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4635 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 4636 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4637 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4638 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4639 | conn = objt_conn(sess->si[1].end); |
| 4640 | if (conn) |
| 4641 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4642 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4643 | 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] | 4644 | case AF_INET: |
| 4645 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4646 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4647 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4648 | break; |
| 4649 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4650 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4651 | break; |
| 4652 | default: |
| 4653 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4654 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4655 | break; |
| 4656 | } |
| 4657 | |
| 4658 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4659 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4660 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4661 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 4662 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4663 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4664 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4665 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4666 | if (conn) |
| 4667 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4668 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4669 | 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] | 4670 | case AF_INET: |
| 4671 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4672 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4673 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4674 | break; |
| 4675 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4676 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4677 | break; |
| 4678 | default: |
| 4679 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4680 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4681 | break; |
| 4682 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4683 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4684 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4685 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4686 | sess->task, |
| 4687 | sess->task->state, |
| 4688 | sess->task->nice, sess->task->calls, |
| 4689 | sess->task->expire ? |
| 4690 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4691 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4692 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4693 | task_in_rq(sess->task) ? ", running" : ""); |
| 4694 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4695 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4696 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4697 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4698 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4699 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4700 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4701 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4702 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4703 | |
| 4704 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4705 | " 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] | 4706 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4707 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4708 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4709 | obj_type_name(sess->si[0].end), |
| 4710 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4711 | sess->si[0].exp ? |
| 4712 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4713 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4714 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4715 | sess->si[0].err_type); |
| 4716 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4717 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4718 | " 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] | 4719 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4720 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4721 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4722 | obj_type_name(sess->si[1].end), |
| 4723 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4724 | sess->si[1].exp ? |
| 4725 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4726 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4727 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4728 | sess->si[1].err_type); |
| 4729 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4730 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4731 | chunk_appendf(&trash, |
| 4732 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4733 | conn, |
| 4734 | get_conn_ctrl_name(conn), |
| 4735 | get_conn_xprt_name(conn), |
| 4736 | get_conn_data_name(conn), |
| 4737 | obj_type_name(conn->target), |
| 4738 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4739 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4740 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 4741 | " 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] | 4742 | conn->flags, |
| 4743 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4744 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4745 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4746 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4747 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4748 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 4749 | chunk_appendf(&trash, |
| 4750 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4751 | tmpctx, |
| 4752 | tmpctx->st0, |
| 4753 | tmpctx->st1, |
| 4754 | tmpctx->st2, |
| 4755 | tmpctx->applet->name); |
| 4756 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4757 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4758 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4759 | chunk_appendf(&trash, |
| 4760 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4761 | conn, |
| 4762 | get_conn_ctrl_name(conn), |
| 4763 | get_conn_xprt_name(conn), |
| 4764 | get_conn_data_name(conn), |
| 4765 | obj_type_name(conn->target), |
| 4766 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4767 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4768 | chunk_appendf(&trash, |
| 4769 | " 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] | 4770 | conn->flags, |
| 4771 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 4772 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 4773 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4774 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4775 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4776 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 4777 | chunk_appendf(&trash, |
| 4778 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4779 | tmpctx, |
| 4780 | tmpctx->st0, |
| 4781 | tmpctx->st1, |
| 4782 | tmpctx->st2, |
| 4783 | tmpctx->applet->name); |
| 4784 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4785 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4786 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4787 | " 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] | 4788 | " an_exp=%s", |
| 4789 | sess->req, |
| 4790 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4791 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4792 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4793 | sess->req->analyse_exp ? |
| 4794 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4795 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4796 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4797 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4798 | " rex=%s", |
| 4799 | sess->req->rex ? |
| 4800 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4801 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4802 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4803 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4804 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4805 | " 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] | 4806 | sess->req->wex ? |
| 4807 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4808 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4809 | sess->req->buf, |
| 4810 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4811 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4812 | sess->txn.req.next, sess->req->buf->i, |
| 4813 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4814 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4815 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4816 | " 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] | 4817 | " an_exp=%s", |
| 4818 | sess->rep, |
| 4819 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4820 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4821 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4822 | sess->rep->analyse_exp ? |
| 4823 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4824 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4825 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4826 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4827 | " rex=%s", |
| 4828 | sess->rep->rex ? |
| 4829 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4830 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4831 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4832 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4833 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4834 | " 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] | 4835 | sess->rep->wex ? |
| 4836 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4837 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4838 | sess->rep->buf, |
| 4839 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4840 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4841 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4842 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4843 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4844 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4845 | return 0; |
| 4846 | |
| 4847 | /* use other states to dump the contents */ |
| 4848 | } |
| 4849 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4850 | appctx->ctx.sess.uid = 0; |
| 4851 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4852 | return 1; |
| 4853 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4854 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4855 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4856 | { |
| 4857 | struct appctx *appctx = __objt_appctx(si->end); |
| 4858 | |
| 4859 | switch (appctx->st2) { |
| 4860 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4861 | /* Display the column headers. If the message cannot be sent, |
| 4862 | * quit the fucntion with returning 0. The function is called |
| 4863 | * later and restart at the state "STAT_ST_INIT". |
| 4864 | */ |
| 4865 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 4866 | chunk_appendf(&trash, "# id (file) description\n"); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4867 | if (bi_putchk(si->ib, &trash) == -1) |
| 4868 | return 0; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4869 | |
| 4870 | /* Now, we start the browsing of the references lists. |
| 4871 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 4872 | * avalaible field of this pointer is <list>. It is used with the function |
| 4873 | * pat_list_get_next() for retruning the first avalaible entry |
| 4874 | */ |
| 4875 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 4876 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 4877 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4878 | appctx->st2 = STAT_ST_LIST; |
| 4879 | /* fall through */ |
| 4880 | |
| 4881 | case STAT_ST_LIST: |
| 4882 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4883 | chunk_reset(&trash); |
| 4884 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4885 | /* Build messages. If the reference is used by another category than |
| 4886 | * the listed categorie, display the information in the massage. |
| 4887 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 4888 | chunk_appendf(&trash, "%d (%s) %s\n", appctx->ctx.map.ref->unique_id, |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 4889 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 4890 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 4891 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4892 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4893 | /* let's try again later from this session. We add ourselves into |
| 4894 | * this session's users so that it can remove us upon termination. |
| 4895 | */ |
| 4896 | return 0; |
| 4897 | } |
| 4898 | |
| 4899 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4900 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 4901 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4902 | } |
| 4903 | |
| 4904 | appctx->st2 = STAT_ST_FIN; |
| 4905 | /* fall through */ |
| 4906 | |
| 4907 | default: |
| 4908 | appctx->st2 = STAT_ST_FIN; |
| 4909 | return 1; |
| 4910 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4911 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4912 | } |
| 4913 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4914 | static int stats_map_lookup(struct stream_interface *si) |
| 4915 | { |
| 4916 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4917 | struct sample sample; |
| 4918 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4919 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4920 | |
| 4921 | switch (appctx->st2) { |
| 4922 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4923 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 4924 | appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4925 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4926 | appctx->st2 = STAT_ST_LIST; |
| 4927 | /* fall through */ |
| 4928 | |
| 4929 | case STAT_ST_LIST: |
| 4930 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4931 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4932 | /* initialise chunk to build new message */ |
| 4933 | chunk_reset(&trash); |
| 4934 | |
| 4935 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 4936 | sample.type = SMP_T_STR; |
| 4937 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4938 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 4939 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 4940 | if (appctx->ctx.map.expr->pat_head->match && |
| 4941 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4942 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 4943 | else |
| 4944 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4945 | |
| 4946 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4947 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 4948 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 4949 | break; |
| 4950 | if (match_method >= PAT_MATCH_NUM) |
| 4951 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 4952 | else |
| 4953 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4954 | |
| 4955 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4956 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4957 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 4958 | chunk_appendf(&trash, ", found=no"); |
| 4959 | else |
| 4960 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | /* Display match and match info */ |
| 4964 | else { |
| 4965 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4966 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 4967 | chunk_appendf(&trash, ", found=yes"); |
| 4968 | else |
| 4969 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4970 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4971 | /* display index mode */ |
| 4972 | if (pat->flags & PAT_F_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4973 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4974 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4975 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4976 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4977 | /* case sensitive */ |
| 4978 | if (pat->flags & PAT_F_IGNORE_CASE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4979 | chunk_appendf(&trash, ", case=insensitive"); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 4980 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 4981 | chunk_appendf(&trash, ", case=sensitive"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4982 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 4983 | /* display pattern */ |
| 4984 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 4985 | if (pat->ref && pat->ref->pattern) |
| 4986 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 4987 | else |
| 4988 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 4989 | } |
| 4990 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 4991 | if (pat->ref && pat->ref->pattern) |
| 4992 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 4993 | else |
| 4994 | chunk_appendf(&trash, ", pattern=unknown"); |
| 4995 | } |
| 4996 | |
| 4997 | /* display return value */ |
| 4998 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 4999 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5000 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5001 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5002 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5003 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5004 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5005 | } |
| 5006 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5007 | chunk_appendf(&trash, "\n"); |
| 5008 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5009 | /* display response */ |
| 5010 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5011 | /* let's try again later from this session. We add ourselves into |
| 5012 | * this session's users so that it can remove us upon termination. |
| 5013 | */ |
| 5014 | return 0; |
| 5015 | } |
| 5016 | |
| 5017 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5018 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5019 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | appctx->st2 = STAT_ST_FIN; |
| 5023 | /* fall through */ |
| 5024 | |
| 5025 | default: |
| 5026 | appctx->st2 = STAT_ST_FIN; |
| 5027 | free(appctx->ctx.map.chunk.str); |
| 5028 | return 1; |
| 5029 | } |
| 5030 | } |
| 5031 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5032 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5033 | { |
| 5034 | struct appctx *appctx = __objt_appctx(si->end); |
| 5035 | |
| 5036 | switch (appctx->st2) { |
| 5037 | |
| 5038 | case STAT_ST_INIT: |
| 5039 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5040 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5041 | struct pat_ref_elt *, list); |
| 5042 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5043 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5044 | appctx->st2 = STAT_ST_LIST; |
| 5045 | /* fall through */ |
| 5046 | |
| 5047 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5048 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5049 | chunk_reset(&trash); |
| 5050 | |
| 5051 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5052 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5053 | chunk_appendf(&trash, "%p %s %s\n", |
| 5054 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5055 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5056 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5057 | chunk_appendf(&trash, "%p %s\n", |
| 5058 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5059 | |
| 5060 | if (bi_putchk(si->ib, &trash) == -1) { |
| 5061 | /* let's try again later from this session. We add ourselves into |
| 5062 | * this session's users so that it can remove us upon termination. |
| 5063 | */ |
| 5064 | return 0; |
| 5065 | } |
| 5066 | |
| 5067 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5068 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5069 | struct pat_ref_elt *, list); |
| 5070 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5071 | break; |
| 5072 | } |
| 5073 | |
| 5074 | appctx->st2 = STAT_ST_FIN; |
| 5075 | /* fall through */ |
| 5076 | |
| 5077 | default: |
| 5078 | appctx->st2 = STAT_ST_FIN; |
| 5079 | return 1; |
| 5080 | } |
| 5081 | } |
| 5082 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5083 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5084 | * 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] | 5085 | * to be called again, otherwise non-zero. It is designed to be called |
| 5086 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5087 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5088 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5089 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5090 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5091 | struct connection *conn; |
| 5092 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5093 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5094 | /* If we're forced to shut down, we might have to remove our |
| 5095 | * reference to the last session being dumped. |
| 5096 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5097 | if (appctx->st2 == STAT_ST_LIST) { |
| 5098 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5099 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5100 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5101 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5102 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5103 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5104 | } |
| 5105 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5106 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5107 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5108 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5109 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5110 | /* the function had not been called yet, let's prepare the |
| 5111 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5112 | * pointer to the first in the global list. When a target |
| 5113 | * session is being destroyed, it is responsible for updating |
| 5114 | * this pointer. We know we have reached the end when this |
| 5115 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5116 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5117 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5118 | appctx->ctx.sess.bref.ref = sessions.n; |
| 5119 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5120 | /* fall through */ |
| 5121 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5122 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5123 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5124 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5125 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5126 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5127 | } |
| 5128 | |
| 5129 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5130 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5131 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5132 | struct session *curr_sess; |
| 5133 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5134 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5135 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5136 | if (appctx->ctx.sess.target) { |
| 5137 | 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] | 5138 | goto next_sess; |
| 5139 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5140 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5141 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5142 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5143 | return 0; |
| 5144 | |
| 5145 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5146 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5147 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5148 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5149 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5150 | break; |
| 5151 | } |
| 5152 | else |
| 5153 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5154 | } |
| 5155 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5156 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5157 | "%p: proto=%s", |
| 5158 | curr_sess, |
| 5159 | curr_sess->listener->proto->name); |
| 5160 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5161 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5162 | conn = objt_conn(curr_sess->si[0].end); |
| 5163 | 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] | 5164 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5165 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5166 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5167 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5168 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5169 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5170 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5171 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5172 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5173 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5174 | break; |
| 5175 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5176 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5177 | " src=unix:%d fe=%s be=%s srv=%s", |
| 5178 | curr_sess->listener->luid, |
| 5179 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5180 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5181 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5182 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5183 | break; |
| 5184 | } |
| 5185 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5186 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5187 | " ts=%02x age=%s calls=%d", |
| 5188 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5189 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5190 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5191 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5192 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5193 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5194 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5195 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5196 | curr_sess->req->analysers, |
| 5197 | curr_sess->req->rex ? |
| 5198 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 5199 | TICKS_TO_MS(1000)) : ""); |
| 5200 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5201 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5202 | ",wx=%s", |
| 5203 | curr_sess->req->wex ? |
| 5204 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 5205 | TICKS_TO_MS(1000)) : ""); |
| 5206 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5207 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5208 | ",ax=%s]", |
| 5209 | curr_sess->req->analyse_exp ? |
| 5210 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 5211 | TICKS_TO_MS(1000)) : ""); |
| 5212 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5213 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5214 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5215 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5216 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5217 | curr_sess->rep->analysers, |
| 5218 | curr_sess->rep->rex ? |
| 5219 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5220 | TICKS_TO_MS(1000)) : ""); |
| 5221 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5222 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5223 | ",wx=%s", |
| 5224 | curr_sess->rep->wex ? |
| 5225 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 5226 | TICKS_TO_MS(1000)) : ""); |
| 5227 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5228 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5229 | ",ax=%s]", |
| 5230 | curr_sess->rep->analyse_exp ? |
| 5231 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5232 | TICKS_TO_MS(1000)) : ""); |
| 5233 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5234 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5235 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5236 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5237 | curr_sess->si[0].state, |
| 5238 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5239 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5240 | curr_sess->si[0].exp ? |
| 5241 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5242 | TICKS_TO_MS(1000)) : ""); |
| 5243 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5244 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5245 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5246 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5247 | curr_sess->si[1].state, |
| 5248 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5249 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5250 | curr_sess->si[1].exp ? |
| 5251 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5252 | TICKS_TO_MS(1000)) : ""); |
| 5253 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5254 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5255 | " exp=%s", |
| 5256 | curr_sess->task->expire ? |
| 5257 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5258 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5259 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5260 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5261 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5262 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5263 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5264 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5265 | /* let's try again later from this session. We add ourselves into |
| 5266 | * this session's users so that it can remove us upon termination. |
| 5267 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5268 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5269 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5270 | } |
| 5271 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5272 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5273 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5274 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5275 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5276 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5277 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5278 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5279 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5280 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5281 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5282 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5283 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5284 | return 0; |
| 5285 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5286 | appctx->ctx.sess.target = NULL; |
| 5287 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5288 | return 1; |
| 5289 | } |
| 5290 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5291 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5292 | /* fall through */ |
| 5293 | |
| 5294 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5295 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5296 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5297 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5298 | } |
| 5299 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5300 | /* This is called when the stream interface is closed. For instance, upon an |
| 5301 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5302 | * remove back references to the session currently being dumped. |
| 5303 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5304 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5305 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5306 | struct appctx *appctx = __objt_appctx(si->end); |
| 5307 | |
| 5308 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5309 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5310 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5311 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5312 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5313 | free(appctx->ctx.cli.err); |
| 5314 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5315 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5316 | free(appctx->ctx.map.chunk.str); |
| 5317 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5318 | } |
| 5319 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5320 | /* This function is used to either dump tables states (when action is set |
| 5321 | * 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] | 5322 | * It returns 0 if the output buffer is full and it needs to be called |
| 5323 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5324 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5325 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5326 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5327 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5328 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5329 | struct ebmb_node *eb; |
| 5330 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5331 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5332 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5333 | |
| 5334 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5335 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5336 | * - STAT_ST_INIT : the first call |
| 5337 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5338 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5339 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5340 | * and the entry pointer points to the next entry to be dumped, |
| 5341 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5342 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5343 | * data though. |
| 5344 | */ |
| 5345 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5346 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5347 | /* 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] | 5348 | if (appctx->st2 == STAT_ST_LIST) { |
| 5349 | appctx->ctx.table.entry->ref_cnt--; |
| 5350 | 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] | 5351 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5352 | return 1; |
| 5353 | } |
| 5354 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5355 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5356 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5357 | while (appctx->st2 != STAT_ST_FIN) { |
| 5358 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5359 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5360 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5361 | if (!appctx->ctx.table.proxy) |
| 5362 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5363 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5364 | appctx->ctx.table.entry = NULL; |
| 5365 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5366 | break; |
| 5367 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5368 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5369 | if (!appctx->ctx.table.proxy || |
| 5370 | (appctx->ctx.table.target && |
| 5371 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5372 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5373 | break; |
| 5374 | } |
| 5375 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5376 | if (appctx->ctx.table.proxy->table.size) { |
| 5377 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5378 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5379 | return 0; |
| 5380 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5381 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5382 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5383 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5384 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5385 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5386 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5387 | appctx->ctx.table.entry->ref_cnt++; |
| 5388 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5389 | break; |
| 5390 | } |
| 5391 | } |
| 5392 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5393 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5394 | break; |
| 5395 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5396 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5397 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5398 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5399 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5400 | /* we're filtering on some data contents */ |
| 5401 | void *ptr; |
| 5402 | long long data; |
| 5403 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5404 | dt = appctx->ctx.table.data_type; |
| 5405 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5406 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5407 | dt); |
| 5408 | |
| 5409 | data = 0; |
| 5410 | switch (stktable_data_types[dt].std_type) { |
| 5411 | case STD_T_SINT: |
| 5412 | data = stktable_data_cast(ptr, std_t_sint); |
| 5413 | break; |
| 5414 | case STD_T_UINT: |
| 5415 | data = stktable_data_cast(ptr, std_t_uint); |
| 5416 | break; |
| 5417 | case STD_T_ULL: |
| 5418 | data = stktable_data_cast(ptr, std_t_ull); |
| 5419 | break; |
| 5420 | case STD_T_FRQP: |
| 5421 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5422 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5423 | break; |
| 5424 | } |
| 5425 | |
| 5426 | /* 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] | 5427 | if ((data < appctx->ctx.table.value && |
| 5428 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5429 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5430 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5431 | (data == appctx->ctx.table.value && |
| 5432 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5433 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5434 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5435 | (data > appctx->ctx.table.value && |
| 5436 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5437 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5438 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5439 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5440 | } |
| 5441 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5442 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5443 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5444 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5445 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5446 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5447 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5448 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5449 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5450 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5451 | struct stksess *old = appctx->ctx.table.entry; |
| 5452 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5453 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5454 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5455 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5456 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5457 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5458 | break; |
| 5459 | } |
| 5460 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5461 | |
| 5462 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5463 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5464 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5465 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5466 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5467 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5468 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5469 | break; |
| 5470 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5471 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5472 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5473 | break; |
| 5474 | } |
| 5475 | } |
| 5476 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5477 | } |
| 5478 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5479 | /* 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] | 5480 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5481 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5482 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5483 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5484 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5485 | * after the offset. The new pointer is returned. |
| 5486 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5487 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5488 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5489 | { |
| 5490 | int end; |
| 5491 | unsigned char c; |
| 5492 | |
| 5493 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5494 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5495 | return ptr; |
| 5496 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5497 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5498 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5499 | while (ptr < len && ptr < bsize) { |
| 5500 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5501 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5502 | if (out->len > end - 2) |
| 5503 | break; |
| 5504 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5505 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5506 | if (out->len > end - 3) |
| 5507 | break; |
| 5508 | out->str[out->len++] = '\\'; |
| 5509 | switch (c) { |
| 5510 | case '\t': c = 't'; break; |
| 5511 | case '\n': c = 'n'; break; |
| 5512 | case '\r': c = 'r'; break; |
| 5513 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5514 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5515 | } |
| 5516 | out->str[out->len++] = c; |
| 5517 | } else { |
| 5518 | if (out->len > end - 5) |
| 5519 | break; |
| 5520 | out->str[out->len++] = '\\'; |
| 5521 | out->str[out->len++] = 'x'; |
| 5522 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5523 | out->str[out->len++] = hextab[c & 0xF]; |
| 5524 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5525 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5526 | /* we had a line break, let's return now */ |
| 5527 | out->str[out->len++] = '\n'; |
| 5528 | *line = ptr; |
| 5529 | return ptr; |
| 5530 | } |
| 5531 | } |
| 5532 | /* we have an incomplete line, we return it as-is */ |
| 5533 | out->str[out->len++] = '\n'; |
| 5534 | return ptr; |
| 5535 | } |
| 5536 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5537 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5538 | * 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] | 5539 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5540 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5541 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5542 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5543 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5544 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5545 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5546 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5547 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5548 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5549 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5550 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5551 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5552 | /* the function had not been called yet, let's prepare the |
| 5553 | * buffer for a response. |
| 5554 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5555 | struct tm tm; |
| 5556 | |
| 5557 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5558 | 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] | 5559 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5560 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5561 | error_snapshot_id); |
| 5562 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5563 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5564 | /* Socket buffer full. Let's try again later from the same point */ |
| 5565 | return 0; |
| 5566 | } |
| 5567 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5568 | appctx->ctx.errors.px = proxy; |
| 5569 | appctx->ctx.errors.buf = 0; |
| 5570 | appctx->ctx.errors.bol = 0; |
| 5571 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | /* we have two inner loops here, one for the proxy, the other one for |
| 5575 | * the buffer. |
| 5576 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5577 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5578 | struct error_snapshot *es; |
| 5579 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5580 | if (appctx->ctx.errors.buf == 0) |
| 5581 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5582 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5583 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5584 | |
| 5585 | if (!es->when.tv_sec) |
| 5586 | goto next; |
| 5587 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5588 | if (appctx->ctx.errors.iid >= 0 && |
| 5589 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 5590 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5591 | goto next; |
| 5592 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5593 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5594 | /* just print headers now */ |
| 5595 | |
| 5596 | char pn[INET6_ADDRSTRLEN]; |
| 5597 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5598 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5599 | |
| 5600 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5601 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5602 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5603 | 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] | 5604 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5605 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 5606 | case AF_INET: |
| 5607 | case AF_INET6: |
| 5608 | port = get_host_port(&es->src); |
| 5609 | break; |
| 5610 | default: |
| 5611 | port = 0; |
| 5612 | } |
| 5613 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5614 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5615 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5616 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5617 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5618 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5619 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5620 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 5621 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5622 | break; |
| 5623 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5624 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5625 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5626 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5627 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5628 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5629 | break; |
| 5630 | } |
| 5631 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5632 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5633 | ", server %s (#%d), event #%u\n" |
| 5634 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 5635 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 5636 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 5637 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 5638 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 5639 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 5640 | es->ev_id, |
| 5641 | pn, port, es->sid, es->s_flags, |
| 5642 | es->state, es->m_flags, es->t_flags, |
| 5643 | es->m_clen, es->m_blen, |
| 5644 | es->b_flags, es->b_out, es->b_tot, |
| 5645 | es->len, es->b_wrap, es->pos); |
| 5646 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5647 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5648 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5649 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5650 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5651 | appctx->ctx.errors.ptr = 0; |
| 5652 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5653 | } |
| 5654 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5655 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5656 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5657 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5658 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5659 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5660 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5661 | goto next; |
| 5662 | } |
| 5663 | |
| 5664 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5665 | 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] | 5666 | int newptr; |
| 5667 | int newline; |
| 5668 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5669 | newline = appctx->ctx.errors.bol; |
| 5670 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 5671 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5672 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5673 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5674 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5675 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5676 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5677 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5678 | appctx->ctx.errors.ptr = newptr; |
| 5679 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5680 | }; |
| 5681 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5682 | appctx->ctx.errors.bol = 0; |
| 5683 | appctx->ctx.errors.ptr = -1; |
| 5684 | appctx->ctx.errors.buf++; |
| 5685 | if (appctx->ctx.errors.buf > 1) { |
| 5686 | appctx->ctx.errors.buf = 0; |
| 5687 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5688 | } |
| 5689 | } |
| 5690 | |
| 5691 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5692 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5693 | } |
| 5694 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5695 | /* parse the "level" argument on the bind lines */ |
| 5696 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 5697 | { |
| 5698 | if (!*args[cur_arg + 1]) { |
| 5699 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 5700 | return ERR_ALERT | ERR_FATAL; |
| 5701 | } |
| 5702 | |
| 5703 | if (!strcmp(args[cur_arg+1], "user")) |
| 5704 | conf->level = ACCESS_LVL_USER; |
| 5705 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 5706 | conf->level = ACCESS_LVL_OPER; |
| 5707 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 5708 | conf->level = ACCESS_LVL_ADMIN; |
| 5709 | else { |
| 5710 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 5711 | args[cur_arg], args[cur_arg+1]); |
| 5712 | return ERR_ALERT | ERR_FATAL; |
| 5713 | } |
| 5714 | |
| 5715 | return 0; |
| 5716 | } |
| 5717 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5718 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5719 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5720 | .name = "<STATS>", /* used for logging */ |
| 5721 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 5722 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5723 | }; |
| 5724 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5725 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5726 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5727 | .name = "<CLI>", /* used for logging */ |
| 5728 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5729 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5730 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5731 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 5732 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5733 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 5734 | { 0, NULL, NULL }, |
| 5735 | }}; |
| 5736 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5737 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 5738 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 5739 | { NULL, NULL, 0 }, |
| 5740 | }}; |
| 5741 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5742 | __attribute__((constructor)) |
| 5743 | static void __dumpstats_module_init(void) |
| 5744 | { |
| 5745 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5746 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5747 | } |
| 5748 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5749 | /* |
| 5750 | * Local variables: |
| 5751 | * c-indent-level: 8 |
| 5752 | * c-basic-offset: 8 |
| 5753 | * End: |
| 5754 | */ |