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> |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 38 | #include <common/base64.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 41 | |
| 42 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 43 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 44 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 45 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 46 | #include <proto/dumpstats.h> |
| 47 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 48 | #include <proto/freq_ctr.h> |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 49 | #include <proto/frontend.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 50 | #include <proto/log.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 51 | #include <proto/pattern.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 52 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 53 | #include <proto/listener.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 54 | #include <proto/map.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 55 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 56 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 57 | #include <proto/proxy.h> |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 58 | #include <proto/sample.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 59 | #include <proto/stream.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 60 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 61 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 62 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 63 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 64 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 65 | #ifdef USE_OPENSSL |
| 66 | #include <proto/ssl_sock.h> |
| 67 | #endif |
| 68 | |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 69 | /* stats socket states */ |
| 70 | enum { |
| 71 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 72 | STAT_CLI_END, /* final state, let's close */ |
| 73 | STAT_CLI_GETREQ, /* wait for a request */ |
| 74 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 75 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 76 | STAT_CLI_PRINT, /* display message in cli->msg */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 77 | 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] | 78 | STAT_CLI_O_INFO, /* dump info */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 79 | STAT_CLI_O_SESS, /* dump streams */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 80 | STAT_CLI_O_ERR, /* dump errors */ |
| 81 | STAT_CLI_O_TAB, /* dump tables */ |
| 82 | STAT_CLI_O_CLR, /* clear tables */ |
| 83 | STAT_CLI_O_SET, /* set entries in tables */ |
| 84 | STAT_CLI_O_STAT, /* dump stats */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 85 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 86 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 87 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 88 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 89 | }; |
| 90 | |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 91 | /* Actions available for the stats admin forms */ |
| 92 | enum { |
| 93 | ST_ADM_ACTION_NONE = 0, |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 94 | |
| 95 | /* enable/disable health checks */ |
| 96 | ST_ADM_ACTION_DHLTH, |
| 97 | ST_ADM_ACTION_EHLTH, |
| 98 | |
| 99 | /* force health check status */ |
| 100 | ST_ADM_ACTION_HRUNN, |
| 101 | ST_ADM_ACTION_HNOLB, |
| 102 | ST_ADM_ACTION_HDOWN, |
| 103 | |
| 104 | /* enable/disable agent checks */ |
| 105 | ST_ADM_ACTION_DAGENT, |
| 106 | ST_ADM_ACTION_EAGENT, |
| 107 | |
| 108 | /* force agent check status */ |
| 109 | ST_ADM_ACTION_ARUNN, |
| 110 | ST_ADM_ACTION_ADOWN, |
| 111 | |
| 112 | /* set admin state */ |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 113 | ST_ADM_ACTION_READY, |
| 114 | ST_ADM_ACTION_DRAIN, |
| 115 | ST_ADM_ACTION_MAINT, |
| 116 | ST_ADM_ACTION_SHUTDOWN, |
| 117 | /* these are the ancient actions, still available for compatibility */ |
| 118 | ST_ADM_ACTION_DISABLE, |
| 119 | ST_ADM_ACTION_ENABLE, |
| 120 | ST_ADM_ACTION_STOP, |
| 121 | ST_ADM_ACTION_START, |
| 122 | }; |
| 123 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 124 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 125 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 126 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct stream *sess); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 127 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 128 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 129 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 130 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 131 | 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] | 132 | static int stats_pats_list(struct stream_interface *si); |
| 133 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 134 | static int stats_map_lookup(struct stream_interface *si); |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 135 | static void cli_release_handler(struct stream_interface *si); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 136 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 137 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 138 | * cli_io_handler() |
| 139 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 140 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 141 | * -> stats_dump_info_to_buffer() // "show info" |
| 142 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 143 | * -> stats_dump_csv_header() |
| 144 | * -> stats_dump_proxy_to_buffer() |
| 145 | * -> stats_dump_fe_stats() |
| 146 | * -> stats_dump_li_stats() |
| 147 | * -> stats_dump_sv_stats() |
| 148 | * -> stats_dump_be_stats() |
| 149 | * |
| 150 | * http_stats_io_handler() |
| 151 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 152 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 153 | * -> stats_dump_html_head() // emits the HTML headers |
| 154 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 155 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 156 | * -> stats_dump_html_px_hdr() |
| 157 | * -> stats_dump_fe_stats() |
| 158 | * -> stats_dump_li_stats() |
| 159 | * -> stats_dump_sv_stats() |
| 160 | * -> stats_dump_be_stats() |
| 161 | * -> stats_dump_html_px_end() |
| 162 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 163 | */ |
| 164 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 165 | static struct si_applet cli_applet; |
| 166 | |
| 167 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 168 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 169 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 170 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 171 | " help : this message\n" |
| 172 | " prompt : toggle interactive mode with prompt\n" |
| 173 | " quit : disconnect\n" |
| 174 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 175 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 176 | " show stat : report counters for each proxy and server\n" |
| 177 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 178 | " 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] | 179 | " 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] | 180 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 181 | " set weight : change a server's weight\n" |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 182 | " set server : change a server's state or weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 183 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 184 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 185 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 186 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 187 | " disable : put a server or frontend in maintenance mode\n" |
| 188 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 189 | " 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] | 190 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 191 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 192 | " add acl : add acl entry\n" |
| 193 | " del acl : delete acl entry\n" |
| 194 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 195 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 196 | " get map : reports the keys and values matching a sample for a map\n" |
| 197 | " set map : modify map entry\n" |
| 198 | " add map : add map entry\n" |
| 199 | " del map : delete map entry\n" |
| 200 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 201 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 202 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 203 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 204 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 205 | "Permission denied\n" |
| 206 | ""; |
| 207 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 208 | /* data transmission states for the stats responses */ |
| 209 | enum { |
| 210 | STAT_ST_INIT = 0, |
| 211 | STAT_ST_HEAD, |
| 212 | STAT_ST_INFO, |
| 213 | STAT_ST_LIST, |
| 214 | STAT_ST_END, |
| 215 | STAT_ST_FIN, |
| 216 | }; |
| 217 | |
| 218 | /* data transmission states for the stats responses inside a proxy */ |
| 219 | enum { |
| 220 | STAT_PX_ST_INIT = 0, |
| 221 | STAT_PX_ST_TH, |
| 222 | STAT_PX_ST_FE, |
| 223 | STAT_PX_ST_LI, |
| 224 | STAT_PX_ST_SV, |
| 225 | STAT_PX_ST_BE, |
| 226 | STAT_PX_ST_END, |
| 227 | STAT_PX_ST_FIN, |
| 228 | }; |
| 229 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 230 | extern const char *stat_status_codes[]; |
| 231 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 232 | /* allocate a new stats frontend named <name>, and return it |
| 233 | * (or NULL in case of lack of memory). |
| 234 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 235 | 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] | 236 | { |
| 237 | struct proxy *fe; |
| 238 | |
| 239 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 240 | if (!fe) |
| 241 | return NULL; |
| 242 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 243 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 244 | fe->next = proxy; |
| 245 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 246 | fe->last_change = now.tv_sec; |
| 247 | fe->id = strdup("GLOBAL"); |
| 248 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 249 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 250 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 251 | fe->conf.file = strdup(file); |
| 252 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 253 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 254 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 255 | |
| 256 | /* the stats frontend is the only one able to assign ID #0 */ |
| 257 | fe->conf.id.key = fe->uuid = 0; |
| 258 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 259 | return fe; |
| 260 | } |
| 261 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 262 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 263 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 264 | * error message into the <err> buffer which will be preallocated. The trailing |
| 265 | * '\n' must not be written. The function must be called with <args> pointing to |
| 266 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 267 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 268 | 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] | 269 | struct proxy *defpx, const char *file, int line, |
| 270 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 271 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 272 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 273 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 274 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 275 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 276 | int cur_arg; |
| 277 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 278 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 279 | 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] | 280 | return -1; |
| 281 | } |
| 282 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 283 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 284 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 285 | 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] | 286 | return -1; |
| 287 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 288 | } |
| 289 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 290 | 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] | 291 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 292 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 293 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 294 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 295 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 296 | return -1; |
| 297 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 298 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 299 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 300 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 301 | static int bind_dumped; |
| 302 | struct bind_kw *kw; |
| 303 | |
| 304 | kw = bind_find_kw(args[cur_arg]); |
| 305 | if (kw) { |
| 306 | if (!kw->parse) { |
| 307 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 308 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 309 | return -1; |
| 310 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 311 | |
| 312 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 313 | if (err && *err) |
| 314 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 315 | else |
| 316 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 317 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 318 | return -1; |
| 319 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 320 | |
| 321 | cur_arg += 1 + kw->skip; |
| 322 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 323 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 324 | |
| 325 | if (!bind_dumped) { |
| 326 | bind_dump_kws(err); |
| 327 | indent_msg(err, 4); |
| 328 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 329 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 330 | |
| 331 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 332 | args[0], args[1], args[cur_arg], |
| 333 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 334 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 335 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 336 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 337 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 338 | l->maxconn = global.stats_fe->maxconn; |
| 339 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 340 | l->accept = stream_accept; |
| 341 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 342 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 343 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 344 | l->nice = -64; /* we want to boost priority for local stats */ |
| 345 | global.maxsock += l->maxconn; |
| 346 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 347 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 348 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 349 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 350 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 351 | |
| 352 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 353 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 354 | return -1; |
| 355 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 356 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 357 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 358 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 359 | return -1; |
| 360 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 361 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 362 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 363 | 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] | 364 | return -1; |
| 365 | } |
| 366 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 367 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 368 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 369 | else if (!strcmp(args[1], "maxconn")) { |
| 370 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 371 | |
| 372 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 373 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 374 | return -1; |
| 375 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 376 | |
| 377 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 378 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 379 | 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] | 380 | return -1; |
| 381 | } |
| 382 | } |
| 383 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 384 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 385 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 386 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 387 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 388 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 389 | if (!global.stats_fe) { |
| 390 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 391 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 392 | return -1; |
| 393 | } |
| 394 | } |
| 395 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 396 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 397 | unsigned int low, high; |
| 398 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 399 | if (strcmp(args[cur_arg], "all") == 0) { |
| 400 | set = 0; |
| 401 | break; |
| 402 | } |
| 403 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 404 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 405 | } |
| 406 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 407 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 408 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 409 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 410 | char *dash = strchr(args[cur_arg], '-'); |
| 411 | |
| 412 | low = high = str2uic(args[cur_arg]); |
| 413 | if (dash) |
| 414 | high = str2uic(dash + 1); |
| 415 | |
| 416 | if (high < low) { |
| 417 | unsigned int swap = low; |
| 418 | low = high; |
| 419 | high = swap; |
| 420 | } |
| 421 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 422 | if (low < 1 || high > LONGBITS) { |
| 423 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 424 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 425 | return -1; |
| 426 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 427 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 428 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 429 | } |
| 430 | else { |
| 431 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 432 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 433 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 434 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 435 | } |
| 436 | cur_arg++; |
| 437 | } |
| 438 | global.stats_fe->bind_proc = set; |
| 439 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 440 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 441 | 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] | 442 | return -1; |
| 443 | } |
| 444 | return 0; |
| 445 | } |
| 446 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 447 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 448 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 449 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 450 | * 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] | 451 | */ |
| 452 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 453 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 454 | chunk_appendf(&trash, |
| 455 | "# pxname,svname," |
| 456 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 457 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 458 | "bin,bout," |
| 459 | "dreq,dresp," |
| 460 | "ereq,econ,eresp," |
| 461 | "wretr,wredis," |
| 462 | "status,weight,act,bck," |
| 463 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 464 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 465 | "rate,rate_lim,rate_max," |
| 466 | "check_status,check_code,check_duration," |
| 467 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 468 | "req_rate,req_rate_max,req_tot," |
| 469 | "cli_abrt,srv_abrt," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 470 | "comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 471 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 472 | } |
| 473 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 474 | /* print a string of text buffer to <out>. The format is : |
| 475 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 476 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 477 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 478 | */ |
| 479 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 480 | { |
| 481 | unsigned char c; |
| 482 | int ptr = 0; |
| 483 | |
| 484 | while (buf[ptr] && ptr < bsize) { |
| 485 | c = buf[ptr]; |
| 486 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 487 | if (out->len > out->size - 1) |
| 488 | break; |
| 489 | out->str[out->len++] = c; |
| 490 | } |
| 491 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 492 | if (out->len > out->size - 2) |
| 493 | break; |
| 494 | out->str[out->len++] = '\\'; |
| 495 | switch (c) { |
| 496 | case ' ': c = ' '; break; |
| 497 | case '\t': c = 't'; break; |
| 498 | case '\n': c = 'n'; break; |
| 499 | case '\r': c = 'r'; break; |
| 500 | case '\e': c = 'e'; break; |
| 501 | case '\\': c = '\\'; break; |
| 502 | } |
| 503 | out->str[out->len++] = c; |
| 504 | } |
| 505 | else { |
| 506 | if (out->len > out->size - 4) |
| 507 | break; |
| 508 | out->str[out->len++] = '\\'; |
| 509 | out->str[out->len++] = 'x'; |
| 510 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 511 | out->str[out->len++] = hextab[c & 0xF]; |
| 512 | } |
| 513 | ptr++; |
| 514 | } |
| 515 | |
| 516 | return ptr; |
| 517 | } |
| 518 | |
| 519 | /* print a buffer in hexa. |
| 520 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 521 | */ |
| 522 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 523 | { |
| 524 | unsigned char c; |
| 525 | int ptr = 0; |
| 526 | |
| 527 | while (ptr < bsize) { |
| 528 | c = buf[ptr]; |
| 529 | |
| 530 | if (out->len > out->size - 2) |
| 531 | break; |
| 532 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 533 | out->str[out->len++] = hextab[c & 0xF]; |
| 534 | |
| 535 | ptr++; |
| 536 | } |
| 537 | return ptr; |
| 538 | } |
| 539 | |
| 540 | /* Dump the status of a table to a stream interface's |
| 541 | * read buffer. It returns 0 if the output buffer is full |
| 542 | * and needs to be called again, otherwise non-zero. |
| 543 | */ |
| 544 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 545 | struct proxy *proxy, struct proxy *target) |
| 546 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 547 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 548 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 549 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 550 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 551 | |
| 552 | /* any other information should be dumped here */ |
| 553 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 554 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 555 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 556 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 557 | if (bi_putchk(si_ic(si), msg) == -1) { |
| 558 | si->flags |= SI_FL_WAIT_ROOM; |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 559 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 560 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 561 | |
| 562 | return 1; |
| 563 | } |
| 564 | |
| 565 | /* Dump the a table entry to a stream interface's |
| 566 | * read buffer. It returns 0 if the output buffer is full |
| 567 | * and needs to be called again, otherwise non-zero. |
| 568 | */ |
| 569 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 570 | struct proxy *proxy, struct stksess *entry) |
| 571 | { |
| 572 | int dt; |
| 573 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 574 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 575 | |
| 576 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 577 | char addr[INET_ADDRSTRLEN]; |
| 578 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 579 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 580 | } |
| 581 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 582 | char addr[INET6_ADDRSTRLEN]; |
| 583 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 584 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 585 | } |
| 586 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 587 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 588 | } |
| 589 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 590 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 591 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 592 | } |
| 593 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 594 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 595 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 596 | } |
| 597 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 598 | 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] | 599 | |
| 600 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 601 | void *ptr; |
| 602 | |
| 603 | if (proxy->table.data_ofs[dt] == 0) |
| 604 | continue; |
| 605 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 606 | 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] | 607 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 608 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 609 | |
| 610 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 611 | switch (stktable_data_types[dt].std_type) { |
| 612 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 613 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 614 | break; |
| 615 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 616 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 617 | break; |
| 618 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 619 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 620 | break; |
| 621 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 622 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 623 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 624 | proxy->table.data_arg[dt].u)); |
| 625 | break; |
| 626 | } |
| 627 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 628 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 629 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 630 | if (bi_putchk(si_ic(si), msg) == -1) { |
| 631 | si->flags |= SI_FL_WAIT_ROOM; |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 632 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 633 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 634 | |
| 635 | return 1; |
| 636 | } |
| 637 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 638 | 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] | 639 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 640 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 641 | struct appctx *appctx = __objt_appctx(si->end); |
| 642 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 643 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 644 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 645 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 646 | long long value; |
| 647 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 648 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 649 | void *ptr; |
| 650 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 651 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 652 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 653 | |
| 654 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 655 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 656 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 657 | return; |
| 658 | } |
| 659 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 660 | switch (px->table.type) { |
| 661 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 662 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 663 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 664 | break; |
| 665 | case STKTABLE_TYPE_IPV6: |
| 666 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 667 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 668 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 669 | case STKTABLE_TYPE_INTEGER: |
| 670 | { |
| 671 | char *endptr; |
| 672 | unsigned long val; |
| 673 | errno = 0; |
| 674 | val = strtoul(args[4], &endptr, 10); |
| 675 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 676 | (errno != 0 && val == 0) || endptr == args[4] || |
| 677 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 678 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 679 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 680 | return; |
| 681 | } |
| 682 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 683 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 684 | break; |
| 685 | } |
| 686 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 687 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 688 | static_table_key->key = args[4]; |
| 689 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 690 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 691 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 692 | switch (action) { |
| 693 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 694 | 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] | 695 | break; |
| 696 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 697 | 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] | 698 | break; |
| 699 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 700 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 701 | break; |
| 702 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 703 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 704 | return; |
| 705 | } |
| 706 | |
| 707 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 708 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 709 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 710 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 711 | return; |
| 712 | } |
| 713 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 714 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 715 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 716 | switch (action) { |
| 717 | case STAT_CLI_O_TAB: |
| 718 | if (!ts) |
| 719 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 720 | chunk_reset(&trash); |
| 721 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 722 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 723 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 724 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 725 | |
| 726 | case STAT_CLI_O_CLR: |
| 727 | if (!ts) |
| 728 | return; |
| 729 | if (ts->ref_cnt) { |
| 730 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 731 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 732 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 733 | return; |
| 734 | } |
| 735 | stksess_kill(&px->table, ts); |
| 736 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 737 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 738 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 739 | if (ts) |
| 740 | stktable_touch(&px->table, ts, 1); |
| 741 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 742 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 743 | if (!ts) { |
| 744 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 745 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 746 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 747 | return; |
| 748 | } |
| 749 | stktable_store(&px->table, ts, 1); |
| 750 | } |
| 751 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 752 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 753 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 754 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 755 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 756 | return; |
| 757 | } |
| 758 | |
| 759 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 760 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 761 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 762 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 763 | return; |
| 764 | } |
| 765 | |
| 766 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 767 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 768 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 769 | return; |
| 770 | } |
| 771 | |
| 772 | 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] | 773 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 774 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 775 | return; |
| 776 | } |
| 777 | |
| 778 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 779 | |
| 780 | switch (stktable_data_types[data_type].std_type) { |
| 781 | case STD_T_SINT: |
| 782 | stktable_data_cast(ptr, std_t_sint) = value; |
| 783 | break; |
| 784 | case STD_T_UINT: |
| 785 | stktable_data_cast(ptr, std_t_uint) = value; |
| 786 | break; |
| 787 | case STD_T_ULL: |
| 788 | stktable_data_cast(ptr, std_t_ull) = value; |
| 789 | break; |
| 790 | case STD_T_FRQP: |
| 791 | /* We set both the current and previous values. That way |
| 792 | * the reported frequency is stable during all the period |
| 793 | * then slowly fades out. This allows external tools to |
| 794 | * push measures without having to update them too often. |
| 795 | */ |
| 796 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 797 | frqp->curr_tick = now_ms; |
| 798 | frqp->prev_ctr = 0; |
| 799 | frqp->curr_ctr = value; |
| 800 | break; |
| 801 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 802 | } |
| 803 | break; |
| 804 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 805 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 806 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 807 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 808 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 809 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 810 | } |
| 811 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 812 | 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] | 813 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 814 | struct appctx *appctx = __objt_appctx(si->end); |
| 815 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 816 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 817 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 818 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 819 | return; |
| 820 | } |
| 821 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 822 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 823 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 824 | if (appctx->ctx.table.data_type < 0) { |
| 825 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 826 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 827 | return; |
| 828 | } |
| 829 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 830 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 831 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 832 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 833 | return; |
| 834 | } |
| 835 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 836 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 837 | if (appctx->ctx.table.data_op < 0) { |
| 838 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 839 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 840 | return; |
| 841 | } |
| 842 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 843 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 844 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 845 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 846 | return; |
| 847 | } |
| 848 | } |
| 849 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 850 | 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] | 851 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 852 | struct appctx *appctx = __objt_appctx(si->end); |
| 853 | |
| 854 | appctx->ctx.table.data_type = -1; |
| 855 | appctx->st2 = STAT_ST_INIT; |
| 856 | appctx->ctx.table.target = NULL; |
| 857 | appctx->ctx.table.proxy = NULL; |
| 858 | appctx->ctx.table.entry = NULL; |
| 859 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 860 | |
| 861 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 862 | appctx->ctx.table.target = find_stktable(args[2]); |
| 863 | if (!appctx->ctx.table.target) { |
| 864 | appctx->ctx.cli.msg = "No such table\n"; |
| 865 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 866 | return; |
| 867 | } |
| 868 | } |
| 869 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 870 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 871 | goto err_args; |
| 872 | return; |
| 873 | } |
| 874 | |
| 875 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 876 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 877 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 878 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 879 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 880 | goto err_args; |
| 881 | |
| 882 | return; |
| 883 | |
| 884 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 885 | switch (action) { |
| 886 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 887 | 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] | 888 | break; |
| 889 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 890 | 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] | 891 | break; |
| 892 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 893 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 894 | break; |
| 895 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 896 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 897 | } |
| 898 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 899 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 900 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 901 | * level to be admin. |
| 902 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 903 | static struct proxy *expect_frontend_admin(struct stream *s, struct stream_interface *si, const char *arg) |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 904 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 905 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 906 | struct proxy *px; |
| 907 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 908 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 909 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 910 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 911 | return NULL; |
| 912 | } |
| 913 | |
| 914 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 915 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 916 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 917 | return NULL; |
| 918 | } |
| 919 | |
| 920 | px = findproxy(arg, PR_CAP_FE); |
| 921 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 922 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 923 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 924 | return NULL; |
| 925 | } |
| 926 | return px; |
| 927 | } |
| 928 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 929 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 930 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 931 | * and returns NULL. This function also expects the stream level to be admin. Note: |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 932 | * the <arg> is modified to remove the '/'. |
| 933 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 934 | static struct server *expect_server_admin(struct stream *s, struct stream_interface *si, char *arg) |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 935 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 936 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 937 | struct proxy *px; |
| 938 | struct server *sv; |
| 939 | char *line; |
| 940 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 941 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 942 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 943 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 944 | return NULL; |
| 945 | } |
| 946 | |
| 947 | /* split "backend/server" and make <line> point to server */ |
| 948 | for (line = arg; *line; line++) |
| 949 | if (*line == '/') { |
| 950 | *line++ = '\0'; |
| 951 | break; |
| 952 | } |
| 953 | |
| 954 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 955 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 956 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 957 | return NULL; |
| 958 | } |
| 959 | |
| 960 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 961 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 962 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 963 | return NULL; |
| 964 | } |
| 965 | |
| 966 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 967 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 968 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 969 | return NULL; |
| 970 | } |
| 971 | |
| 972 | return sv; |
| 973 | } |
| 974 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 975 | /* This function is used with map and acl management. It permits to browse |
| 976 | * each reference. The variable <getnext> must contain the current node, |
| 977 | * <end> point to the root node and the <flags> permit to filter required |
| 978 | * nodes. |
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 | static inline |
| 981 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 982 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 983 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 984 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 985 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 986 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 987 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 988 | /* Get next list entry. */ |
| 989 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 990 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 991 | /* If the entry is the last of the list, return NULL. */ |
| 992 | if (&ref->list == end) |
| 993 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 994 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 995 | /* If the entry match the flag, return it. */ |
| 996 | if (ref->flags & flags) |
| 997 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1001 | static inline |
| 1002 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1003 | { |
| 1004 | int id; |
| 1005 | char *error; |
| 1006 | |
| 1007 | /* If the reference starts by a '#', this is numeric id. */ |
| 1008 | if (reference[0] == '#') { |
| 1009 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1010 | id = strtol(reference + 1, &error, 10); |
| 1011 | if (*error != '\0') |
| 1012 | return NULL; |
| 1013 | |
| 1014 | /* Perform the unique id lookup. */ |
| 1015 | return pat_ref_lookupid(id); |
| 1016 | } |
| 1017 | |
| 1018 | /* Perform the string lookup. */ |
| 1019 | return pat_ref_lookup(reference); |
| 1020 | } |
| 1021 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1022 | /* This function is used with map and acl management. It permits to browse |
| 1023 | * each reference. |
| 1024 | */ |
| 1025 | static inline |
| 1026 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1027 | { |
| 1028 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1029 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1030 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1031 | return NULL; |
| 1032 | return expr; |
| 1033 | } |
| 1034 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1035 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1036 | * 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] | 1037 | * 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] | 1038 | * designating the function which will have to process the request, which can |
| 1039 | * 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] | 1040 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1041 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1042 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1043 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1044 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1045 | char *args[MAX_STATS_ARGS + 1]; |
| 1046 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1047 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1048 | |
| 1049 | while (isspace((unsigned char)*line)) |
| 1050 | line++; |
| 1051 | |
| 1052 | arg = 0; |
| 1053 | args[arg] = line; |
| 1054 | |
| 1055 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1056 | if (*line == '\\') { |
| 1057 | line++; |
| 1058 | if (*line == '\0') |
| 1059 | break; |
| 1060 | } |
| 1061 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1062 | *line++ = '\0'; |
| 1063 | |
| 1064 | while (isspace((unsigned char)*line)) |
| 1065 | line++; |
| 1066 | |
| 1067 | args[++arg] = line; |
| 1068 | continue; |
| 1069 | } |
| 1070 | |
| 1071 | line++; |
| 1072 | } |
| 1073 | |
| 1074 | while (++arg <= MAX_STATS_ARGS) |
| 1075 | args[arg] = line; |
| 1076 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1077 | /* remove \ */ |
| 1078 | arg = 0; |
| 1079 | while (*args[arg] != '\0') { |
| 1080 | j = 0; |
| 1081 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1082 | if (args[arg][i] == '\\') |
| 1083 | continue; |
| 1084 | args[arg][j] = args[arg][i]; |
| 1085 | j++; |
| 1086 | } |
| 1087 | args[arg][j] = '\0'; |
| 1088 | arg++; |
| 1089 | } |
| 1090 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1091 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1092 | if (strcmp(args[0], "show") == 0) { |
| 1093 | if (strcmp(args[1], "stat") == 0) { |
| 1094 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1095 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1096 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1097 | appctx->ctx.stats.type = atoi(args[3]); |
| 1098 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1099 | } |
| 1100 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1101 | appctx->st2 = STAT_ST_INIT; |
| 1102 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1103 | } |
| 1104 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1105 | appctx->st2 = STAT_ST_INIT; |
| 1106 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1107 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1108 | else if (strcmp(args[1], "pools") == 0) { |
| 1109 | appctx->st2 = STAT_ST_INIT; |
| 1110 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1111 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1112 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1113 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1114 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1115 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1116 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1117 | return 1; |
| 1118 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1119 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1120 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1121 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1122 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1123 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1124 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1125 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1126 | appctx->ctx.sess.pos = 0; |
| 1127 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1128 | } |
| 1129 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1130 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1131 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1132 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1133 | return 1; |
| 1134 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1135 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1136 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1137 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1138 | appctx->ctx.errors.iid = -1; |
| 1139 | appctx->ctx.errors.px = NULL; |
| 1140 | appctx->st2 = STAT_ST_INIT; |
| 1141 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1142 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1143 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1144 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1145 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1146 | else if (strcmp(args[1], "map") == 0 || |
| 1147 | strcmp(args[1], "acl") == 0) { |
| 1148 | |
| 1149 | /* Set ACL or MAP flags. */ |
| 1150 | if (args[1][0] == 'm') |
| 1151 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1152 | else |
| 1153 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1154 | |
| 1155 | /* no parameter: display all map avalaible */ |
| 1156 | if (!*args[2]) { |
| 1157 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1158 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1159 | return 1; |
| 1160 | } |
| 1161 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1162 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1163 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1164 | if (!appctx->ctx.map.ref || |
| 1165 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1166 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1167 | 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] | 1168 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1169 | 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] | 1170 | appctx->st0 = STAT_CLI_PRINT; |
| 1171 | return 1; |
| 1172 | } |
| 1173 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1174 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1175 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1176 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1177 | return 0; |
| 1178 | } |
| 1179 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1180 | else if (strcmp(args[0], "clear") == 0) { |
| 1181 | if (strcmp(args[1], "counters") == 0) { |
| 1182 | struct proxy *px; |
| 1183 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1184 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1185 | int clrall = 0; |
| 1186 | |
| 1187 | if (strcmp(args[2], "all") == 0) |
| 1188 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1189 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1190 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1191 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1192 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1193 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1194 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1195 | return 1; |
| 1196 | } |
| 1197 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1198 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1199 | if (clrall) { |
| 1200 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1201 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1202 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1203 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1204 | px->be_counters.conn_max = 0; |
| 1205 | px->be_counters.p.http.rps_max = 0; |
| 1206 | px->be_counters.sps_max = 0; |
| 1207 | px->be_counters.cps_max = 0; |
| 1208 | px->be_counters.nbpend_max = 0; |
| 1209 | |
| 1210 | px->fe_counters.conn_max = 0; |
| 1211 | px->fe_counters.p.http.rps_max = 0; |
| 1212 | px->fe_counters.sps_max = 0; |
| 1213 | px->fe_counters.cps_max = 0; |
| 1214 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1215 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1216 | |
| 1217 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1218 | if (clrall) |
| 1219 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1220 | else { |
| 1221 | sv->counters.cur_sess_max = 0; |
| 1222 | sv->counters.nbpend_max = 0; |
| 1223 | sv->counters.sps_max = 0; |
| 1224 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1225 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1226 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1227 | if (li->counters) { |
| 1228 | if (clrall) |
| 1229 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1230 | else |
| 1231 | li->counters->conn_max = 0; |
| 1232 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1233 | } |
| 1234 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1235 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1236 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1237 | return 1; |
| 1238 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1239 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1240 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1241 | /* end of processing */ |
| 1242 | return 1; |
| 1243 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1244 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1245 | /* Set ACL or MAP flags. */ |
| 1246 | if (args[1][0] == 'm') |
| 1247 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1248 | else |
| 1249 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1250 | |
| 1251 | /* no parameter */ |
| 1252 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1253 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1254 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1255 | else |
| 1256 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1257 | appctx->st0 = STAT_CLI_PRINT; |
| 1258 | return 1; |
| 1259 | } |
| 1260 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1261 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1262 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1263 | if (!appctx->ctx.map.ref || |
| 1264 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1265 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1266 | 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] | 1267 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1268 | 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] | 1269 | appctx->st0 = STAT_CLI_PRINT; |
| 1270 | return 1; |
| 1271 | } |
| 1272 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1273 | /* Clear all. */ |
| 1274 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1275 | |
| 1276 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1277 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1278 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1279 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1280 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1281 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1282 | return 0; |
| 1283 | } |
| 1284 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1285 | else if (strcmp(args[0], "get") == 0) { |
| 1286 | if (strcmp(args[1], "weight") == 0) { |
| 1287 | struct proxy *px; |
| 1288 | struct server *sv; |
| 1289 | |
| 1290 | /* split "backend/server" and make <line> point to server */ |
| 1291 | for (line = args[2]; *line; line++) |
| 1292 | if (*line == '/') { |
| 1293 | *line++ = '\0'; |
| 1294 | break; |
| 1295 | } |
| 1296 | |
| 1297 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1298 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1299 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1300 | return 1; |
| 1301 | } |
| 1302 | |
| 1303 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1304 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1305 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1306 | return 1; |
| 1307 | } |
| 1308 | |
| 1309 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1310 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1311 | if (bi_putstr(si_ic(si), trash.str) == -1) |
| 1312 | si->flags |= SI_FL_WAIT_ROOM; |
| 1313 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1314 | return 1; |
| 1315 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1316 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1317 | /* Set flags. */ |
| 1318 | if (args[1][0] == 'm') |
| 1319 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1320 | else |
| 1321 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1322 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1323 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1324 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1325 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1326 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1327 | else |
| 1328 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1329 | appctx->st0 = STAT_CLI_PRINT; |
| 1330 | return 1; |
| 1331 | } |
| 1332 | |
| 1333 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1334 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1335 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1336 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1337 | 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] | 1338 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1339 | 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] | 1340 | appctx->st0 = STAT_CLI_PRINT; |
| 1341 | return 1; |
| 1342 | } |
| 1343 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1344 | /* copy input string. The string must be allocated because |
| 1345 | * it may be used over multiple iterations. It's released |
| 1346 | * at the end and upon abort anyway. |
| 1347 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1348 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1349 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1350 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1351 | if (!appctx->ctx.map.chunk.str) { |
| 1352 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1353 | appctx->st0 = STAT_CLI_PRINT; |
| 1354 | return 1; |
| 1355 | } |
| 1356 | |
| 1357 | /* prepare response */ |
| 1358 | appctx->st2 = STAT_ST_INIT; |
| 1359 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1360 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1361 | else { /* not "get weight" */ |
| 1362 | return 0; |
| 1363 | } |
| 1364 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1365 | else if (strcmp(args[0], "set") == 0) { |
| 1366 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1367 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1368 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1369 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1370 | sv = expect_server_admin(s, si, args[2]); |
| 1371 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1372 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1373 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1374 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1375 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1376 | appctx->ctx.cli.msg = warning; |
| 1377 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1378 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1379 | return 1; |
| 1380 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1381 | else if (strcmp(args[1], "server") == 0) { |
| 1382 | struct server *sv; |
| 1383 | const char *warning; |
| 1384 | |
| 1385 | sv = expect_server_admin(s, si, args[2]); |
| 1386 | if (!sv) |
| 1387 | return 1; |
| 1388 | |
| 1389 | if (strcmp(args[3], "weight") == 0) { |
| 1390 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1391 | if (warning) { |
| 1392 | appctx->ctx.cli.msg = warning; |
| 1393 | appctx->st0 = STAT_CLI_PRINT; |
| 1394 | } |
| 1395 | } |
| 1396 | else if (strcmp(args[3], "state") == 0) { |
| 1397 | if (strcmp(args[4], "ready") == 0) |
| 1398 | srv_adm_set_ready(sv); |
| 1399 | else if (strcmp(args[4], "drain") == 0) |
| 1400 | srv_adm_set_drain(sv); |
| 1401 | else if (strcmp(args[4], "maint") == 0) |
| 1402 | srv_adm_set_maint(sv); |
| 1403 | else { |
| 1404 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1405 | appctx->st0 = STAT_CLI_PRINT; |
| 1406 | } |
| 1407 | } |
| 1408 | else if (strcmp(args[3], "health") == 0) { |
| 1409 | if (sv->track) { |
| 1410 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1411 | appctx->st0 = STAT_CLI_PRINT; |
| 1412 | } |
| 1413 | else if (strcmp(args[4], "up") == 0) { |
| 1414 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1415 | srv_set_running(sv, "changed from CLI"); |
| 1416 | } |
| 1417 | else if (strcmp(args[4], "stopping") == 0) { |
| 1418 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1419 | srv_set_stopping(sv, "changed from CLI"); |
| 1420 | } |
| 1421 | else if (strcmp(args[4], "down") == 0) { |
| 1422 | sv->check.health = 0; |
| 1423 | srv_set_stopped(sv, "changed from CLI"); |
| 1424 | } |
| 1425 | else { |
| 1426 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1427 | appctx->st0 = STAT_CLI_PRINT; |
| 1428 | } |
| 1429 | } |
| 1430 | else if (strcmp(args[3], "agent") == 0) { |
| 1431 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1432 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1433 | appctx->st0 = STAT_CLI_PRINT; |
| 1434 | } |
| 1435 | else if (strcmp(args[4], "up") == 0) { |
| 1436 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1437 | srv_set_running(sv, "changed from CLI"); |
| 1438 | } |
| 1439 | else if (strcmp(args[4], "down") == 0) { |
| 1440 | sv->agent.health = 0; |
| 1441 | srv_set_stopped(sv, "changed from CLI"); |
| 1442 | } |
| 1443 | else { |
| 1444 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1445 | appctx->st0 = STAT_CLI_PRINT; |
| 1446 | } |
| 1447 | } |
| 1448 | else { |
| 1449 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state' and 'weight'.\n"; |
| 1450 | appctx->st0 = STAT_CLI_PRINT; |
| 1451 | } |
| 1452 | return 1; |
| 1453 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1454 | else if (strcmp(args[1], "timeout") == 0) { |
| 1455 | if (strcmp(args[2], "cli") == 0) { |
| 1456 | unsigned timeout; |
| 1457 | const char *res; |
| 1458 | |
| 1459 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1460 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1461 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1462 | return 1; |
| 1463 | } |
| 1464 | |
| 1465 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1466 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1467 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1468 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1469 | return 1; |
| 1470 | } |
| 1471 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1472 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1473 | return 1; |
| 1474 | } |
| 1475 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1476 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1477 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1478 | return 1; |
| 1479 | } |
| 1480 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1481 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1482 | if (strcmp(args[2], "frontend") == 0) { |
| 1483 | struct proxy *px; |
| 1484 | struct listener *l; |
| 1485 | int v; |
| 1486 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1487 | px = expect_frontend_admin(s, si, args[3]); |
| 1488 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1489 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1490 | |
| 1491 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1492 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1493 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1494 | return 1; |
| 1495 | } |
| 1496 | |
| 1497 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1498 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1499 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1500 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1501 | return 1; |
| 1502 | } |
| 1503 | |
| 1504 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1505 | * its listeners. The blocked ones will be dequeued. |
| 1506 | */ |
| 1507 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1508 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1509 | l->maxconn = v; |
| 1510 | if (l->state == LI_FULL) |
| 1511 | resume_listener(l); |
| 1512 | } |
| 1513 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1514 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1515 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1516 | |
| 1517 | return 1; |
| 1518 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1519 | else if (strcmp(args[2], "global") == 0) { |
| 1520 | int v; |
| 1521 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1522 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1523 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1524 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1525 | return 1; |
| 1526 | } |
| 1527 | |
| 1528 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1529 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1530 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1531 | return 1; |
| 1532 | } |
| 1533 | |
| 1534 | v = atoi(args[3]); |
| 1535 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1536 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1537 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1538 | return 1; |
| 1539 | } |
| 1540 | |
| 1541 | /* check for unlimited values */ |
| 1542 | if (v <= 0) |
| 1543 | v = global.hardmaxconn; |
| 1544 | |
| 1545 | global.maxconn = v; |
| 1546 | |
| 1547 | /* Dequeues all of the listeners waiting for a resource */ |
| 1548 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1549 | dequeue_all_listeners(&global_listener_queue); |
| 1550 | |
| 1551 | return 1; |
| 1552 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1553 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1554 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1555 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1556 | return 1; |
| 1557 | } |
| 1558 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1559 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1560 | if (strcmp(args[2], "connections") == 0) { |
| 1561 | if (strcmp(args[3], "global") == 0) { |
| 1562 | int v; |
| 1563 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1564 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1565 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1566 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1567 | return 1; |
| 1568 | } |
| 1569 | |
| 1570 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1571 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1572 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1573 | return 1; |
| 1574 | } |
| 1575 | |
| 1576 | v = atoi(args[4]); |
| 1577 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1578 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1579 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1580 | return 1; |
| 1581 | } |
| 1582 | |
| 1583 | global.cps_lim = v; |
| 1584 | |
| 1585 | /* Dequeues all of the listeners waiting for a resource */ |
| 1586 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1587 | dequeue_all_listeners(&global_listener_queue); |
| 1588 | |
| 1589 | return 1; |
| 1590 | } |
| 1591 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1592 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1593 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1594 | return 1; |
| 1595 | } |
| 1596 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1597 | else if (strcmp(args[2], "sessions") == 0) { |
| 1598 | if (strcmp(args[3], "global") == 0) { |
| 1599 | int v; |
| 1600 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1601 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1602 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1603 | appctx->st0 = STAT_CLI_PRINT; |
| 1604 | return 1; |
| 1605 | } |
| 1606 | |
| 1607 | if (!*args[4]) { |
| 1608 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1609 | appctx->st0 = STAT_CLI_PRINT; |
| 1610 | return 1; |
| 1611 | } |
| 1612 | |
| 1613 | v = atoi(args[4]); |
| 1614 | if (v < 0) { |
| 1615 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1616 | appctx->st0 = STAT_CLI_PRINT; |
| 1617 | return 1; |
| 1618 | } |
| 1619 | |
| 1620 | global.sps_lim = v; |
| 1621 | |
| 1622 | /* Dequeues all of the listeners waiting for a resource */ |
| 1623 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1624 | dequeue_all_listeners(&global_listener_queue); |
| 1625 | |
| 1626 | return 1; |
| 1627 | } |
| 1628 | else { |
| 1629 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1630 | appctx->st0 = STAT_CLI_PRINT; |
| 1631 | return 1; |
| 1632 | } |
| 1633 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1634 | #ifdef USE_OPENSSL |
| 1635 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1636 | if (strcmp(args[3], "global") == 0) { |
| 1637 | int v; |
| 1638 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1639 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1640 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1641 | appctx->st0 = STAT_CLI_PRINT; |
| 1642 | return 1; |
| 1643 | } |
| 1644 | |
| 1645 | if (!*args[4]) { |
| 1646 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1647 | appctx->st0 = STAT_CLI_PRINT; |
| 1648 | return 1; |
| 1649 | } |
| 1650 | |
| 1651 | v = atoi(args[4]); |
| 1652 | if (v < 0) { |
| 1653 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1654 | appctx->st0 = STAT_CLI_PRINT; |
| 1655 | return 1; |
| 1656 | } |
| 1657 | |
| 1658 | global.ssl_lim = v; |
| 1659 | |
| 1660 | /* Dequeues all of the listeners waiting for a resource */ |
| 1661 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1662 | dequeue_all_listeners(&global_listener_queue); |
| 1663 | |
| 1664 | return 1; |
| 1665 | } |
| 1666 | else { |
| 1667 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1668 | appctx->st0 = STAT_CLI_PRINT; |
| 1669 | return 1; |
| 1670 | } |
| 1671 | } |
| 1672 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1673 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1674 | if (strcmp(args[3], "global") == 0) { |
| 1675 | int v; |
| 1676 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1677 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1678 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1679 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1680 | return 1; |
| 1681 | } |
| 1682 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1683 | v = atoi(args[4]); |
| 1684 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1685 | } |
| 1686 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1687 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1688 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1689 | return 1; |
| 1690 | } |
| 1691 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1692 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1693 | 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] | 1694 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1695 | return 1; |
| 1696 | } |
| 1697 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1698 | else if (strcmp(args[1], "table") == 0) { |
| 1699 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1700 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1701 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1702 | char *err; |
| 1703 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1704 | /* Set flags. */ |
| 1705 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1706 | |
| 1707 | /* Expect three parameters: map name, key and new value. */ |
| 1708 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1709 | 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] | 1710 | appctx->st0 = STAT_CLI_PRINT; |
| 1711 | return 1; |
| 1712 | } |
| 1713 | |
| 1714 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1715 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1716 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1717 | 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] | 1718 | appctx->st0 = STAT_CLI_PRINT; |
| 1719 | return 1; |
| 1720 | } |
| 1721 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1722 | /* If the entry identifier start with a '#', it is considered as |
| 1723 | * pointer id |
| 1724 | */ |
| 1725 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1726 | struct pat_ref_elt *ref; |
| 1727 | long long int conv; |
| 1728 | char *error; |
| 1729 | |
| 1730 | /* Convert argument to integer value. */ |
| 1731 | conv = strtoll(&args[3][1], &error, 16); |
| 1732 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1733 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1734 | appctx->st0 = STAT_CLI_PRINT; |
| 1735 | return 1; |
| 1736 | } |
| 1737 | |
| 1738 | /* Convert and check integer to pointer. */ |
| 1739 | ref = (struct pat_ref_elt *)(long)conv; |
| 1740 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1741 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1742 | appctx->st0 = STAT_CLI_PRINT; |
| 1743 | return 1; |
| 1744 | } |
| 1745 | |
| 1746 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1747 | err = NULL; |
| 1748 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1749 | if (err) |
| 1750 | memprintf(&err, "%s.\n", err); |
| 1751 | appctx->ctx.cli.err = err; |
| 1752 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1753 | return 1; |
| 1754 | } |
| 1755 | } |
| 1756 | else { |
| 1757 | /* Else, use the entry identifier as pattern |
| 1758 | * string, and update the value. |
| 1759 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1760 | err = NULL; |
| 1761 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1762 | if (err) |
| 1763 | memprintf(&err, "%s.\n", err); |
| 1764 | appctx->ctx.cli.err = err; |
| 1765 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1766 | return 1; |
| 1767 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1768 | } |
| 1769 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1770 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1771 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1772 | return 1; |
| 1773 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1774 | #ifdef USE_OPENSSL |
| 1775 | else if (strcmp(args[1], "ssl") == 0) { |
| 1776 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 1777 | #if (defined SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB && !defined OPENSSL_NO_OCSP) |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1778 | char *err = NULL; |
| 1779 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 1780 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1781 | if (!*args[3]) { |
| 1782 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 1783 | appctx->st0 = STAT_CLI_PRINT; |
| 1784 | return 1; |
| 1785 | } |
| 1786 | |
| 1787 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 1788 | if (trash.len < 0) { |
| 1789 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 1790 | appctx->st0 = STAT_CLI_PRINT; |
| 1791 | return 1; |
| 1792 | } |
| 1793 | |
| 1794 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 1795 | if (err) { |
| 1796 | memprintf(&err, "%s.\n", err); |
| 1797 | appctx->ctx.cli.err = err; |
| 1798 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 1799 | } |
| 1800 | return 1; |
| 1801 | } |
| 1802 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 1803 | appctx->st0 = STAT_CLI_PRINT; |
| 1804 | return 1; |
| 1805 | #else |
| 1806 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 1807 | appctx->st0 = STAT_CLI_PRINT; |
| 1808 | return 1; |
| 1809 | #endif |
| 1810 | } |
| 1811 | else { |
| 1812 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 1813 | appctx->st0 = STAT_CLI_PRINT; |
| 1814 | return 1; |
| 1815 | } |
| 1816 | } |
| 1817 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1818 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1819 | return 0; |
| 1820 | } |
| 1821 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1822 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1823 | if (strcmp(args[1], "agent") == 0) { |
| 1824 | struct server *sv; |
| 1825 | |
| 1826 | sv = expect_server_admin(s, si, args[2]); |
| 1827 | if (!sv) |
| 1828 | return 1; |
| 1829 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1830 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1831 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1832 | appctx->st0 = STAT_CLI_PRINT; |
| 1833 | return 1; |
| 1834 | } |
| 1835 | |
| 1836 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1837 | return 1; |
| 1838 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1839 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1840 | struct server *sv; |
| 1841 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1842 | sv = expect_server_admin(s, si, args[2]); |
| 1843 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1844 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1845 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1846 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 1847 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 1848 | appctx->st0 = STAT_CLI_PRINT; |
| 1849 | return 1; |
| 1850 | } |
| 1851 | |
| 1852 | sv->check.state |= CHK_ST_ENABLED; |
| 1853 | return 1; |
| 1854 | } |
| 1855 | else if (strcmp(args[1], "server") == 0) { |
| 1856 | struct server *sv; |
| 1857 | |
| 1858 | sv = expect_server_admin(s, si, args[2]); |
| 1859 | if (!sv) |
| 1860 | return 1; |
| 1861 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1862 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1863 | return 1; |
| 1864 | } |
| 1865 | else if (strcmp(args[1], "frontend") == 0) { |
| 1866 | struct proxy *px; |
| 1867 | |
| 1868 | px = expect_frontend_admin(s, si, args[2]); |
| 1869 | if (!px) |
| 1870 | return 1; |
| 1871 | |
| 1872 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1873 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1874 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1875 | return 1; |
| 1876 | } |
| 1877 | |
| 1878 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1879 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1880 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1881 | return 1; |
| 1882 | } |
| 1883 | |
| 1884 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1885 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1886 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1887 | return 1; |
| 1888 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1889 | return 1; |
| 1890 | } |
| 1891 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1892 | appctx->ctx.cli.msg = "'enable' only supports 'agent', 'frontend', 'health', and 'server'.\n"; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1893 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1894 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1895 | } |
| 1896 | } |
| 1897 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1898 | if (strcmp(args[1], "agent") == 0) { |
| 1899 | struct server *sv; |
| 1900 | |
| 1901 | sv = expect_server_admin(s, si, args[2]); |
| 1902 | if (!sv) |
| 1903 | return 1; |
| 1904 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1905 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1906 | return 1; |
| 1907 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1908 | else if (strcmp(args[1], "health") == 0) { |
| 1909 | struct server *sv; |
| 1910 | |
| 1911 | sv = expect_server_admin(s, si, args[2]); |
| 1912 | if (!sv) |
| 1913 | return 1; |
| 1914 | |
| 1915 | sv->check.state &= ~CHK_ST_ENABLED; |
| 1916 | return 1; |
| 1917 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1918 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1919 | struct server *sv; |
| 1920 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1921 | sv = expect_server_admin(s, si, args[2]); |
| 1922 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1923 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1924 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1925 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1926 | return 1; |
| 1927 | } |
| 1928 | else if (strcmp(args[1], "frontend") == 0) { |
| 1929 | struct proxy *px; |
| 1930 | |
| 1931 | px = expect_frontend_admin(s, si, args[2]); |
| 1932 | if (!px) |
| 1933 | return 1; |
| 1934 | |
| 1935 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1936 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1937 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1938 | return 1; |
| 1939 | } |
| 1940 | |
| 1941 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1942 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1943 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1944 | return 1; |
| 1945 | } |
| 1946 | |
| 1947 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1948 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1949 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1950 | return 1; |
| 1951 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1952 | return 1; |
| 1953 | } |
| 1954 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1955 | appctx->ctx.cli.msg = "'disable' only supports 'agent', 'frontend', 'health', and 'server'.\n"; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1956 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1957 | return 1; |
| 1958 | } |
| 1959 | } |
| 1960 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1961 | if (strcmp(args[1], "frontend") == 0) { |
| 1962 | struct proxy *px; |
| 1963 | |
| 1964 | px = expect_frontend_admin(s, si, args[2]); |
| 1965 | if (!px) |
| 1966 | return 1; |
| 1967 | |
| 1968 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1969 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1970 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1971 | return 1; |
| 1972 | } |
| 1973 | |
| 1974 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1975 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1976 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1977 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1978 | stop_proxy(px); |
| 1979 | return 1; |
| 1980 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1981 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1982 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1983 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1984 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1985 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1986 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1987 | return 1; |
| 1988 | } |
| 1989 | |
| 1990 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1991 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1992 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1993 | return 1; |
| 1994 | } |
| 1995 | |
| 1996 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1997 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1998 | /* first, look for the requested stream in the stream table */ |
| 1999 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2000 | if (sess == ptr) |
| 2001 | break; |
| 2002 | } |
| 2003 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2004 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2005 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2006 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2007 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2008 | return 1; |
| 2009 | } |
| 2010 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2011 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2012 | return 1; |
| 2013 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2014 | else if (strcmp(args[1], "sessions") == 0) { |
| 2015 | if (strcmp(args[2], "server") == 0) { |
| 2016 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2017 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2018 | |
| 2019 | sv = expect_server_admin(s, si, args[3]); |
| 2020 | if (!sv) |
| 2021 | return 1; |
| 2022 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2023 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2024 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2025 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2026 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2027 | |
| 2028 | return 1; |
| 2029 | } |
| 2030 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2031 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2032 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2033 | return 1; |
| 2034 | } |
| 2035 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2036 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2037 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2038 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2039 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2040 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2041 | } |
| 2042 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2043 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2044 | if (args[1][0] == 'm') |
| 2045 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2046 | else |
| 2047 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2048 | |
| 2049 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2050 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2051 | if (!*args[2] || !*args[3]) { |
| 2052 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2053 | appctx->st0 = STAT_CLI_PRINT; |
| 2054 | return 1; |
| 2055 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2056 | } |
| 2057 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2058 | else { |
| 2059 | if (!*args[2] || !*args[3]) { |
| 2060 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2061 | appctx->st0 = STAT_CLI_PRINT; |
| 2062 | return 1; |
| 2063 | } |
| 2064 | } |
| 2065 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2066 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2067 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2068 | if (!appctx->ctx.map.ref || |
| 2069 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2070 | 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] | 2071 | appctx->st0 = STAT_CLI_PRINT; |
| 2072 | return 1; |
| 2073 | } |
| 2074 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2075 | /* If the entry identifier start with a '#', it is considered as |
| 2076 | * pointer id |
| 2077 | */ |
| 2078 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2079 | struct pat_ref_elt *ref; |
| 2080 | long long int conv; |
| 2081 | char *error; |
| 2082 | |
| 2083 | /* Convert argument to integer value. */ |
| 2084 | conv = strtoll(&args[3][1], &error, 16); |
| 2085 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2086 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2087 | appctx->st0 = STAT_CLI_PRINT; |
| 2088 | return 1; |
| 2089 | } |
| 2090 | |
| 2091 | /* Convert and check integer to pointer. */ |
| 2092 | ref = (struct pat_ref_elt *)(long)conv; |
| 2093 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2094 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2095 | appctx->st0 = STAT_CLI_PRINT; |
| 2096 | return 1; |
| 2097 | } |
| 2098 | |
| 2099 | /* Try to delete the entry. */ |
| 2100 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2101 | /* The entry is not found, send message. */ |
| 2102 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2103 | appctx->st0 = STAT_CLI_PRINT; |
| 2104 | return 1; |
| 2105 | } |
| 2106 | } |
| 2107 | else { |
| 2108 | /* Else, use the entry identifier as pattern |
| 2109 | * string and try to delete the entry. |
| 2110 | */ |
| 2111 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2112 | /* The entry is not found, send message. */ |
| 2113 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2114 | appctx->st0 = STAT_CLI_PRINT; |
| 2115 | return 1; |
| 2116 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2117 | } |
| 2118 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2119 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2120 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2121 | return 1; |
| 2122 | } |
| 2123 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2124 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2125 | appctx->st0 = STAT_CLI_PRINT; |
| 2126 | return 1; |
| 2127 | } |
| 2128 | } |
| 2129 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2130 | if (strcmp(args[1], "map") == 0 || |
| 2131 | strcmp(args[1], "acl") == 0) { |
| 2132 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2133 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2134 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2135 | /* Set flags. */ |
| 2136 | if (args[1][0] == 'm') |
| 2137 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2138 | else |
| 2139 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2140 | |
| 2141 | /* If the keywork is "map", we expect three parameters, if it |
| 2142 | * is "acl", we expect only two parameters |
| 2143 | */ |
| 2144 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2145 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2146 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2147 | appctx->st0 = STAT_CLI_PRINT; |
| 2148 | return 1; |
| 2149 | } |
| 2150 | } |
| 2151 | else { |
| 2152 | if (!*args[2] || !*args[3]) { |
| 2153 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2154 | appctx->st0 = STAT_CLI_PRINT; |
| 2155 | return 1; |
| 2156 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2157 | } |
| 2158 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2159 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2160 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2161 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2162 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2163 | 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] | 2164 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2165 | 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] | 2166 | appctx->st0 = STAT_CLI_PRINT; |
| 2167 | return 1; |
| 2168 | } |
| 2169 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2170 | /* The command "add acl" is prohibited if the reference |
| 2171 | * use samples. |
| 2172 | */ |
| 2173 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2174 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2175 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2176 | "You must use the command 'add map' to add values.\n"; |
| 2177 | appctx->st0 = STAT_CLI_PRINT; |
| 2178 | return 1; |
| 2179 | } |
| 2180 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2181 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2182 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2183 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2184 | 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] | 2185 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2186 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2187 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2188 | if (err) |
| 2189 | memprintf(&err, "%s.\n", err); |
| 2190 | appctx->ctx.cli.err = err; |
| 2191 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2192 | return 1; |
| 2193 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2194 | |
| 2195 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2196 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2197 | return 1; |
| 2198 | } |
| 2199 | else { /* unknown "del" parameter */ |
| 2200 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2201 | appctx->st0 = STAT_CLI_PRINT; |
| 2202 | return 1; |
| 2203 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2204 | } |
| 2205 | 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] | 2206 | return 0; |
| 2207 | } |
| 2208 | return 1; |
| 2209 | } |
| 2210 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2211 | /* 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] | 2212 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2213 | * state machine handling requests and various responses. We read a request, |
| 2214 | * 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] | 2215 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2216 | * 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] | 2217 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2218 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2219 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2220 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2221 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2222 | struct channel *req = si_oc(si); |
| 2223 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2224 | int reql; |
| 2225 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2226 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2227 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2228 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2229 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2230 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2231 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2232 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2233 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2234 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2235 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2236 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2237 | /* Let's close for real now. We just close the request |
| 2238 | * side, the conditions below will complete if needed. |
| 2239 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2240 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2241 | break; |
| 2242 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2243 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2244 | /* ensure we have some output room left in the event we |
| 2245 | * would want to return some info right after parsing. |
| 2246 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2247 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2248 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2249 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2250 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2251 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2252 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2253 | if (reql <= 0) { /* closed or EOL not found */ |
| 2254 | if (reql == 0) |
| 2255 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2256 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2257 | continue; |
| 2258 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2259 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2260 | /* seek for a possible semi-colon. If we find one, we |
| 2261 | * replace it with an LF and skip only this part. |
| 2262 | */ |
| 2263 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2264 | if (trash.str[len] == ';') { |
| 2265 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2266 | reql = len + 1; |
| 2267 | break; |
| 2268 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2269 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2270 | /* now it is time to check that we have a full line, |
| 2271 | * remove the trailing \n and possibly \r, then cut the |
| 2272 | * line. |
| 2273 | */ |
| 2274 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2275 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2276 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2277 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2278 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2279 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2280 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2281 | len--; |
| 2282 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2283 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2284 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2285 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2286 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2287 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2288 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2289 | continue; |
| 2290 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2291 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2292 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2293 | else if (strcmp(trash.str, "help") == 0 || |
| 2294 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2295 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2296 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2297 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2298 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2299 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2300 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2301 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2302 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2303 | /* if prompt is disabled, print help on empty lines, |
| 2304 | * so that the user at least knows how to enable |
| 2305 | * prompt and find help. |
| 2306 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2307 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2308 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2312 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2313 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2314 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2315 | 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] | 2316 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 2317 | cli_release_handler(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2318 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2319 | continue; |
| 2320 | } |
| 2321 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2322 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2323 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2324 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2325 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2326 | else |
| 2327 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2328 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2329 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2330 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2331 | free(appctx->ctx.cli.err); |
| 2332 | appctx->st0 = STAT_CLI_PROMPT; |
| 2333 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2334 | else |
| 2335 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2336 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2337 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2338 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2339 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2340 | break; |
| 2341 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2342 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2343 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2344 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2345 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2346 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2347 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2348 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2349 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2350 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2351 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2352 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2353 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2354 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2355 | if (stats_table_request(si, appctx->st0)) |
| 2356 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2357 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2358 | case STAT_CLI_O_PATS: |
| 2359 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2360 | appctx->st0 = STAT_CLI_PROMPT; |
| 2361 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2362 | case STAT_CLI_O_PAT: |
| 2363 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2364 | appctx->st0 = STAT_CLI_PROMPT; |
| 2365 | break; |
| 2366 | case STAT_CLI_O_MLOOK: |
| 2367 | if (stats_map_lookup(si)) |
| 2368 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2369 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2370 | case STAT_CLI_O_POOLS: |
| 2371 | if (stats_dump_pools_to_buffer(si)) |
| 2372 | appctx->st0 = STAT_CLI_PROMPT; |
| 2373 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2374 | default: /* abnormal state */ |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 2375 | cli_release_handler(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2376 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2377 | break; |
| 2378 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2379 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2380 | /* 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] | 2381 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2382 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2383 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2384 | else |
| 2385 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2386 | } |
| 2387 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2388 | /* 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] | 2389 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2390 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2391 | |
| 2392 | /* Now we close the output if one of the writers did so, |
| 2393 | * or if we're not in interactive mode and the request |
| 2394 | * buffer is empty. This still allows pipelined requests |
| 2395 | * to be sent in non-interactive mode. |
| 2396 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2397 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2398 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2399 | continue; |
| 2400 | } |
| 2401 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2402 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2403 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2404 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2405 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2406 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2407 | 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] | 2408 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2409 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2410 | /* 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] | 2411 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2412 | * we forward the close to the request side so that it flows upstream to |
| 2413 | * the client. |
| 2414 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2415 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2416 | } |
| 2417 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2418 | 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] | 2419 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2420 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2421 | /* We have no more processing to do, and nothing more to send, and |
| 2422 | * the client side has closed. So we'll forward this state downstream |
| 2423 | * on the response buffer. |
| 2424 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2425 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2426 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2430 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2431 | |
| 2432 | /* we don't want to expire timeouts while we're processing requests */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2433 | si_ic(si)->rex = TICK_ETERNITY; |
| 2434 | si_oc(si)->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2435 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2436 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2437 | 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] | 2438 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2439 | 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] | 2440 | |
| 2441 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2442 | /* check that we have released everything then unregister */ |
| 2443 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2444 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2445 | } |
| 2446 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2447 | /* This function dumps information onto the stream interface's read buffer. |
| 2448 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2449 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2450 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2451 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2452 | { |
| 2453 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2454 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2455 | #ifdef USE_OPENSSL |
| 2456 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2457 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2458 | int ssl_reuse = 0; |
| 2459 | |
| 2460 | if (ssl_key_rate < ssl_sess_rate) { |
| 2461 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2462 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2463 | } |
| 2464 | #endif |
| 2465 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2466 | chunk_printf(&trash, |
| 2467 | "Name: " PRODUCT_NAME "\n" |
| 2468 | "Version: " HAPROXY_VERSION "\n" |
| 2469 | "Release_date: " HAPROXY_DATE "\n" |
| 2470 | "Nbproc: %d\n" |
| 2471 | "Process_num: %d\n" |
| 2472 | "Pid: %d\n" |
| 2473 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2474 | "Uptime_sec: %d\n" |
| 2475 | "Memmax_MB: %d\n" |
| 2476 | "Ulimit-n: %d\n" |
| 2477 | "Maxsock: %d\n" |
| 2478 | "Maxconn: %d\n" |
| 2479 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2480 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2481 | "CumConns: %d\n" |
Warren Turkal | b197d7f | 2015-01-27 15:04:16 -0800 | [diff] [blame] | 2482 | "CumReq: %u\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2483 | #ifdef USE_OPENSSL |
| 2484 | "MaxSslConns: %d\n" |
| 2485 | "CurrSslConns: %d\n" |
| 2486 | "CumSslConns: %d\n" |
| 2487 | #endif |
| 2488 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2489 | "PipesUsed: %d\n" |
| 2490 | "PipesFree: %d\n" |
| 2491 | "ConnRate: %d\n" |
| 2492 | "ConnRateLimit: %d\n" |
| 2493 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2494 | "SessRate: %d\n" |
| 2495 | "SessRateLimit: %d\n" |
| 2496 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2497 | #ifdef USE_OPENSSL |
| 2498 | "SslRate: %d\n" |
| 2499 | "SslRateLimit: %d\n" |
| 2500 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2501 | "SslFrontendKeyRate: %d\n" |
| 2502 | "SslFrontendMaxKeyRate: %d\n" |
| 2503 | "SslFrontendSessionReuse_pct: %d\n" |
| 2504 | "SslBackendKeyRate: %d\n" |
| 2505 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2506 | "SslCacheLookups: %u\n" |
| 2507 | "SslCacheMisses: %u\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2508 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2509 | "CompressBpsIn: %u\n" |
| 2510 | "CompressBpsOut: %u\n" |
| 2511 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2512 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2513 | "ZlibMemUsage: %ld\n" |
| 2514 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2515 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2516 | "Tasks: %d\n" |
| 2517 | "Run_queue: %d\n" |
| 2518 | "Idle_pct: %d\n" |
| 2519 | "node: %s\n" |
| 2520 | "description: %s\n" |
| 2521 | "", |
| 2522 | global.nbproc, |
| 2523 | relative_pid, |
| 2524 | pid, |
| 2525 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2526 | up, |
| 2527 | global.rlimit_memmax, |
| 2528 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2529 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2530 | actconn, totalconn, global.req_count, |
| 2531 | #ifdef USE_OPENSSL |
| 2532 | global.maxsslconn, sslconns, totalsslconns, |
| 2533 | #endif |
| 2534 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2535 | 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] | 2536 | 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] | 2537 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2538 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2539 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2540 | ssl_reuse, |
| 2541 | read_freq_ctr(&global.ssl_be_keys_per_sec), global.ssl_be_keys_max, |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2542 | global.shctx_lookups, global.shctx_misses, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2543 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2544 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2545 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2546 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2547 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2548 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2549 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2550 | global.node, global.desc ? global.desc : "" |
| 2551 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2552 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2553 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 2554 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2555 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2556 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2557 | |
| 2558 | return 1; |
| 2559 | } |
| 2560 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2561 | /* This function dumps memory usage information onto the stream interface's |
| 2562 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2563 | * completion. No state is used. |
| 2564 | */ |
| 2565 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2566 | { |
| 2567 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2568 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 2569 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2570 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2571 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2572 | return 1; |
| 2573 | } |
| 2574 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2575 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2576 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2577 | * 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] | 2578 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2579 | 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] | 2580 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2581 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2582 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2583 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2584 | if (!(px->cap & PR_CAP_FE)) |
| 2585 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2586 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2587 | 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] | 2588 | return 0; |
| 2589 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2590 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2591 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2592 | /* name, queue */ |
| 2593 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2594 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2595 | 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] | 2596 | /* Column sub-heading for Enable or Disable server */ |
| 2597 | chunk_appendf(&trash, "<td></td>"); |
| 2598 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2599 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2600 | chunk_appendf(&trash, |
| 2601 | "<td class=ac>" |
| 2602 | "<a name=\"%s/Frontend\"></a>" |
| 2603 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2604 | "<td colspan=3></td>" |
| 2605 | "", |
| 2606 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2607 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2608 | chunk_appendf(&trash, |
| 2609 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2610 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2611 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2612 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2613 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2614 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2615 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2616 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2617 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2618 | if (px->mode == PR_MODE_HTTP) |
| 2619 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2620 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2621 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2622 | |
| 2623 | chunk_appendf(&trash, |
| 2624 | "</table></div></u></td>" |
| 2625 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2626 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2627 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2628 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2629 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2630 | U2H(px->fe_counters.sps_max), |
| 2631 | U2H(px->fe_counters.cps_max), |
| 2632 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2633 | |
| 2634 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2635 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2636 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2637 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2638 | |
| 2639 | chunk_appendf(&trash, |
| 2640 | "</table></div></u></td>" |
| 2641 | /* sessions rate : limit */ |
| 2642 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2643 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2644 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2645 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2646 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2647 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2648 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2649 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2650 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2651 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2652 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2653 | U2H(px->fe_counters.cum_sess), |
| 2654 | U2H(px->fe_counters.cum_conn), |
| 2655 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2656 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2657 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2658 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2659 | chunk_appendf(&trash, |
| 2660 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2661 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2662 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2663 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2664 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2665 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2666 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2667 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2668 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2669 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2670 | U2H(px->fe_counters.p.http.cum_req), |
| 2671 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2672 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2673 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2674 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2675 | (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] | 2676 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2677 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2678 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2679 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2680 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2681 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2682 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2683 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2684 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2685 | /* sessions: lbtot, lastsess */ |
| 2686 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2687 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2688 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2689 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2690 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2691 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2692 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2693 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2694 | "<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] | 2695 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2696 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2697 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2698 | px->fe_counters.comp_in ? |
| 2699 | (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] | 2700 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2701 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2702 | chunk_appendf(&trash, |
| 2703 | /* denied: req, resp */ |
| 2704 | "<td>%s</td><td>%s</td>" |
| 2705 | /* errors : request, connect, response */ |
| 2706 | "<td>%s</td><td></td><td></td>" |
| 2707 | /* warnings: retries, redispatches */ |
| 2708 | "<td></td><td></td>" |
| 2709 | /* server status : reflect frontend status */ |
| 2710 | "<td class=ac>%s</td>" |
| 2711 | /* rest of server: nothing */ |
| 2712 | "<td class=ac colspan=8></td></tr>" |
| 2713 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2714 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2715 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2716 | px->state == PR_STREADY ? "OPEN" : |
| 2717 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2718 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2719 | else { /* CSV mode */ |
| 2720 | chunk_appendf(&trash, |
| 2721 | /* pxid, name, queue cur, queue max, */ |
| 2722 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2723 | /* sessions : current, max, limit, total */ |
| 2724 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2725 | /* bytes : in, out */ |
| 2726 | "%lld,%lld," |
| 2727 | /* denied: req, resp */ |
| 2728 | "%lld,%lld," |
| 2729 | /* errors : request, connect, response */ |
| 2730 | "%lld,,," |
| 2731 | /* warnings: retries, redispatches */ |
| 2732 | ",," |
| 2733 | /* server status : reflect frontend status */ |
| 2734 | "%s," |
| 2735 | /* rest of server: nothing */ |
| 2736 | ",,,,,,,," |
| 2737 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2738 | "%d,%d,0,,,,%d," |
| 2739 | /* rate, rate_lim, rate_max */ |
| 2740 | "%u,%u,%u," |
| 2741 | /* check_status, check_code, check_duration */ |
| 2742 | ",,,", |
| 2743 | px->id, |
| 2744 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2745 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2746 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2747 | px->fe_counters.failed_req, |
| 2748 | px->state == PR_STREADY ? "OPEN" : |
| 2749 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2750 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2751 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2752 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2753 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2754 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2755 | if (px->mode == PR_MODE_HTTP) { |
| 2756 | for (i=1; i<6; i++) |
| 2757 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2758 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2759 | } |
| 2760 | else |
| 2761 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2762 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2763 | /* failed health analyses */ |
| 2764 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2765 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2766 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2767 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2768 | read_freq_ctr(&px->fe_req_per_sec), |
| 2769 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2770 | |
| 2771 | /* errors: cli_aborts, srv_aborts */ |
| 2772 | chunk_appendf(&trash, ",,"); |
| 2773 | |
| 2774 | /* compression: in, out, bypassed */ |
| 2775 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2776 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2777 | |
| 2778 | /* compression: comp_rsp */ |
| 2779 | chunk_appendf(&trash, "%lld,", |
| 2780 | px->fe_counters.p.http.comp_rsp); |
| 2781 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2782 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2783 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2784 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2785 | /* finish with EOL */ |
| 2786 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2787 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2788 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2789 | } |
| 2790 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2791 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2792 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2793 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2794 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2795 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2796 | 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] | 2797 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2798 | struct appctx *appctx = __objt_appctx(si->end); |
| 2799 | |
| 2800 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2801 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2802 | 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] | 2803 | /* Column sub-heading for Enable or Disable server */ |
| 2804 | chunk_appendf(&trash, "<td></td>"); |
| 2805 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2806 | chunk_appendf(&trash, |
| 2807 | /* frontend name, listener name */ |
| 2808 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2809 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2810 | "", |
| 2811 | px->id, l->name, |
| 2812 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2813 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2814 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2815 | if (flags & ST_SHLGNDS) { |
| 2816 | char str[INET6_ADDRSTRLEN]; |
| 2817 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2818 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2819 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2820 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2821 | port = get_host_port(&l->addr); |
| 2822 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2823 | case AF_INET: |
| 2824 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2825 | break; |
| 2826 | case AF_INET6: |
| 2827 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2828 | break; |
| 2829 | case AF_UNIX: |
| 2830 | chunk_appendf(&trash, "unix, "); |
| 2831 | break; |
| 2832 | case -1: |
| 2833 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2834 | break; |
| 2835 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2836 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2837 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2838 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2839 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2840 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2841 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2842 | /* queue */ |
| 2843 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2844 | /* sessions rate: current, max, limit */ |
| 2845 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2846 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2847 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2848 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2849 | /* bytes: in, out */ |
| 2850 | "<td>%s</td><td>%s</td>" |
| 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(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2854 | 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] | 2855 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2856 | chunk_appendf(&trash, |
| 2857 | /* denied: req, resp */ |
| 2858 | "<td>%s</td><td>%s</td>" |
| 2859 | /* errors: request, connect, response */ |
| 2860 | "<td>%s</td><td></td><td></td>" |
| 2861 | /* warnings: retries, redispatches */ |
| 2862 | "<td></td><td></td>" |
| 2863 | /* server status: reflect listener status */ |
| 2864 | "<td class=ac>%s</td>" |
| 2865 | /* rest of server: nothing */ |
| 2866 | "<td class=ac colspan=8></td></tr>" |
| 2867 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2868 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2869 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2870 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2871 | } |
| 2872 | else { /* CSV mode */ |
| 2873 | chunk_appendf(&trash, |
| 2874 | /* pxid, name, queue cur, queue max, */ |
| 2875 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2876 | /* sessions: current, max, limit, total */ |
| 2877 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2878 | /* bytes: in, out */ |
| 2879 | "%lld,%lld," |
| 2880 | /* denied: req, resp */ |
| 2881 | "%lld,%lld," |
| 2882 | /* errors: request, connect, response */ |
| 2883 | "%lld,,," |
| 2884 | /* warnings: retries, redispatches */ |
| 2885 | ",," |
| 2886 | /* server status: reflect listener status */ |
| 2887 | "%s," |
| 2888 | /* rest of server: nothing */ |
| 2889 | ",,,,,,,," |
| 2890 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2891 | "%d,%d,%d,,,,%d," |
| 2892 | /* rate, rate_lim, rate_max */ |
| 2893 | ",,," |
| 2894 | /* check_status, check_code, check_duration */ |
| 2895 | ",,," |
| 2896 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2897 | ",,,,,," |
| 2898 | /* failed health analyses */ |
| 2899 | "," |
| 2900 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2901 | ",,," |
| 2902 | /* errors: cli_aborts, srv_aborts */ |
| 2903 | ",," |
| 2904 | /* compression: in, out, bypassed, comp_rsp */ |
| 2905 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2906 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2907 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2908 | "\n", |
| 2909 | px->id, l->name, |
| 2910 | l->nbconn, l->counters->conn_max, |
| 2911 | l->maxconn, l->counters->cum_conn, |
| 2912 | l->counters->bytes_in, l->counters->bytes_out, |
| 2913 | l->counters->denied_req, l->counters->denied_resp, |
| 2914 | l->counters->failed_req, |
| 2915 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2916 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2917 | } |
| 2918 | return 1; |
| 2919 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2920 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2921 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2922 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2923 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2924 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2925 | * following values : 0=DOWN, 1=DOWN(agent) 2=going up, 3=going down, 4=UP, 5,6=NOLB, |
| 2926 | * 7,8=DRAIN, 9=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2927 | */ |
| 2928 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2929 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2930 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2931 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2932 | char str[INET6_ADDRSTRLEN]; |
| 2933 | struct chunk src; |
| 2934 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2935 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2936 | /* we have "via" which is the tracked server as described in the configuration, |
| 2937 | * and "ref" which is the checked server and the end of the chain. |
| 2938 | */ |
| 2939 | via = sv->track ? sv->track : sv; |
| 2940 | ref = via; |
| 2941 | while (ref->track) |
| 2942 | ref = ref->track; |
| 2943 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2944 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2945 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2946 | "DOWN", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 2947 | "DOWN (agent)", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2948 | "DN %d/%d ↑", |
| 2949 | "UP %d/%d ↓", |
| 2950 | "UP", |
| 2951 | "NOLB %d/%d ↓", |
| 2952 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2953 | "DRAIN %d/%d ↓", |
| 2954 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2955 | "<i>no check</i>" |
| 2956 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2957 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 2958 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2959 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2960 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2961 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2962 | "<tr class=\"%s%d\">", |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 2963 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2964 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2965 | 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] | 2966 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2967 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2968 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2969 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2970 | chunk_appendf(&trash, |
| 2971 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2972 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2973 | "", |
| 2974 | px->id, sv->id, |
| 2975 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2976 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2977 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2978 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2979 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2980 | |
| 2981 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2982 | case AF_INET: |
| 2983 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2984 | break; |
| 2985 | case AF_INET6: |
| 2986 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2987 | break; |
| 2988 | case AF_UNIX: |
| 2989 | chunk_appendf(&trash, "unix, "); |
| 2990 | break; |
| 2991 | case -1: |
| 2992 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2993 | break; |
| 2994 | default: /* address family not supported */ |
| 2995 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2996 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2997 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2998 | /* id */ |
| 2999 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3000 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3001 | /* cookie */ |
| 3002 | if (sv->cookie) { |
| 3003 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3004 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3005 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3006 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3007 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3008 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3009 | } |
| 3010 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3011 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3012 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3013 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3014 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3015 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3016 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3017 | /* sessions rate : current, max, limit */ |
| 3018 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3019 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3020 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3021 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3022 | 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] | 3023 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3024 | |
| 3025 | chunk_appendf(&trash, |
| 3026 | /* sessions: current, max, limit, total */ |
| 3027 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3028 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3029 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3030 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3031 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3032 | U2H(sv->counters.cum_sess), |
| 3033 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3034 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3035 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3036 | if (px->mode == PR_MODE_HTTP) { |
| 3037 | unsigned long long tot; |
| 3038 | for (tot = i = 0; i < 6; i++) |
| 3039 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3040 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3041 | chunk_appendf(&trash, |
| 3042 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3043 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3044 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3045 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3046 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3047 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3048 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3049 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3050 | U2H(tot), |
| 3051 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3052 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3053 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3054 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3055 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3056 | 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] | 3057 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3058 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3059 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3060 | chunk_appendf(&trash, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES))); |
| 3061 | chunk_appendf(&trash, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES))); |
| 3062 | if (px->mode == PR_MODE_HTTP) |
| 3063 | chunk_appendf(&trash, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES))); |
| 3064 | chunk_appendf(&trash, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES))); |
| 3065 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3066 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3067 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3068 | /* sessions: lbtot, last */ |
| 3069 | "<td>%s</td><td>%s</td>", |
| 3070 | U2H(sv->counters.cum_lbconn), |
| 3071 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3072 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3073 | chunk_appendf(&trash, |
| 3074 | /* bytes : in, out */ |
| 3075 | "<td>%s</td><td>%s</td>" |
| 3076 | /* denied: req, resp */ |
| 3077 | "<td></td><td>%s</td>" |
| 3078 | /* errors : request, connect */ |
| 3079 | "<td></td><td>%s</td>" |
| 3080 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3081 | "<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] | 3082 | /* warnings: retries, redispatches */ |
| 3083 | "<td>%lld</td><td>%lld</td>" |
| 3084 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3085 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3086 | U2H(sv->counters.failed_secu), |
| 3087 | U2H(sv->counters.failed_conns), |
| 3088 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3089 | sv->counters.cli_aborts, |
| 3090 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3091 | sv->counters.retries, sv->counters.redispatches); |
| 3092 | |
| 3093 | /* status, lest check */ |
| 3094 | chunk_appendf(&trash, "<td class=ac>"); |
| 3095 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3096 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3097 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3098 | chunk_appendf(&trash, "MAINT"); |
| 3099 | } |
Simon Horman | 0766e44 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3100 | else if ((ref->agent.state & CHK_ST_ENABLED) && !(sv->agent.health) && (ref->state == SRV_ST_STOPPED)) { |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3101 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
Willy Tarreau | ac49707 | 2014-05-29 01:04:35 +0200 | [diff] [blame] | 3102 | /* DOWN (agent) */ |
| 3103 | chunk_appendf(&trash, srv_hlt_st[1], "GCC: your -Werror=format-security is bogus, annoying, and hides real bugs, I don't thank you, really!"); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3104 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3105 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3106 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3107 | chunk_appendf(&trash, |
| 3108 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3109 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3110 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3111 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3112 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3113 | if ((sv->state == SRV_ST_STOPPED) && |
| 3114 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3115 | chunk_appendf(&trash, |
| 3116 | "</td><td class=ac><u> %s%s", |
| 3117 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3118 | get_check_status_info(sv->agent.status)); |
| 3119 | |
| 3120 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3121 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3122 | |
| 3123 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3124 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3125 | |
| 3126 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3127 | get_check_status_description(sv->agent.status)); |
| 3128 | if (*sv->agent.desc) { |
| 3129 | chunk_appendf(&trash, ": "); |
| 3130 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3131 | chunk_htmlencode(&trash, &src); |
| 3132 | } |
| 3133 | chunk_appendf(&trash, "</div></u>"); |
| 3134 | } |
| 3135 | else if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3136 | chunk_appendf(&trash, |
| 3137 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3138 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3139 | get_check_status_info(sv->check.status)); |
| 3140 | |
| 3141 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3142 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3143 | |
| 3144 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3145 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3146 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3147 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3148 | get_check_status_description(sv->check.status)); |
| 3149 | if (*sv->check.desc) { |
| 3150 | chunk_appendf(&trash, ": "); |
| 3151 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3152 | chunk_htmlencode(&trash, &src); |
| 3153 | } |
| 3154 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3155 | } |
| 3156 | else |
| 3157 | chunk_appendf(&trash, "</td><td>"); |
| 3158 | |
| 3159 | chunk_appendf(&trash, |
| 3160 | /* weight */ |
| 3161 | "</td><td class=ac>%d</td>" |
| 3162 | /* act, bck */ |
| 3163 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3164 | "", |
| 3165 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3166 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3167 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3168 | |
| 3169 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3170 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3171 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3172 | |
| 3173 | if (ref->observe) |
| 3174 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3175 | |
| 3176 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3177 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3178 | "<td>%lld</td><td>%s</td>" |
| 3179 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3180 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3181 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3182 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3183 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3184 | /* tracking a server */ |
| 3185 | chunk_appendf(&trash, |
| 3186 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s</a></td>", |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3187 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3188 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3189 | else |
| 3190 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3191 | |
| 3192 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3193 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3194 | 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] | 3195 | else |
| 3196 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3197 | } |
| 3198 | else { /* CSV mode */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3199 | static char *srv_hlt_st[10] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3200 | "DOWN,", |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3201 | "DOWN (agent),", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3202 | "DOWN %d/%d,", |
| 3203 | "UP %d/%d,", |
| 3204 | "UP,", |
| 3205 | "NOLB %d/%d,", |
| 3206 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3207 | "DRAIN %d/%d,", |
| 3208 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3209 | "no check," |
| 3210 | }; |
| 3211 | |
| 3212 | chunk_appendf(&trash, |
| 3213 | /* pxid, name */ |
| 3214 | "%s,%s," |
| 3215 | /* queue : current, max */ |
| 3216 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3217 | /* sessions : current, max, limit, total */ |
| 3218 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3219 | /* bytes : in, out */ |
| 3220 | "%lld,%lld," |
| 3221 | /* denied: req, resp */ |
| 3222 | ",%lld," |
| 3223 | /* errors : request, connect, response */ |
| 3224 | ",%lld,%lld," |
| 3225 | /* warnings: retries, redispatches */ |
| 3226 | "%lld,%lld," |
| 3227 | "", |
| 3228 | px->id, sv->id, |
| 3229 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3230 | 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] | 3231 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3232 | sv->counters.failed_secu, |
| 3233 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3234 | sv->counters.retries, sv->counters.redispatches); |
| 3235 | |
| 3236 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3237 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3238 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3239 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3240 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3241 | else |
| 3242 | chunk_appendf(&trash, |
| 3243 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3244 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3245 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3246 | |
| 3247 | chunk_appendf(&trash, |
| 3248 | /* weight, active, backup */ |
| 3249 | "%d,%d,%d," |
| 3250 | "", |
| 3251 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3252 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3253 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3254 | |
| 3255 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3256 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3257 | chunk_appendf(&trash, |
| 3258 | "%lld,%lld,%d,%d,", |
| 3259 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3260 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3261 | else |
| 3262 | chunk_appendf(&trash, ",,,,"); |
| 3263 | |
| 3264 | /* queue limit, pid, iid, sid, */ |
| 3265 | chunk_appendf(&trash, |
| 3266 | "%s," |
| 3267 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3268 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3269 | relative_pid, px->uuid, sv->puid); |
| 3270 | |
| 3271 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3272 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3273 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3274 | |
| 3275 | /* sessions: lbtot */ |
| 3276 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3277 | |
| 3278 | /* tracked */ |
| 3279 | if (sv->track) |
| 3280 | chunk_appendf(&trash, "%s/%s,", |
| 3281 | sv->track->proxy->id, sv->track->id); |
| 3282 | else |
| 3283 | chunk_appendf(&trash, ","); |
| 3284 | |
| 3285 | /* type */ |
| 3286 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3287 | |
| 3288 | /* rate */ |
| 3289 | chunk_appendf(&trash, "%u,,%u,", |
| 3290 | read_freq_ctr(&sv->sess_per_sec), |
| 3291 | sv->counters.sps_max); |
| 3292 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3293 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3294 | /* check_status */ |
| 3295 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3296 | |
| 3297 | /* check_code */ |
| 3298 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3299 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3300 | else |
| 3301 | chunk_appendf(&trash, ","); |
| 3302 | |
| 3303 | /* check_duration */ |
| 3304 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3305 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3306 | else |
| 3307 | chunk_appendf(&trash, ","); |
| 3308 | |
| 3309 | } |
| 3310 | else |
| 3311 | chunk_appendf(&trash, ",,,"); |
| 3312 | |
| 3313 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3314 | if (px->mode == PR_MODE_HTTP) { |
| 3315 | for (i=1; i<6; i++) |
| 3316 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3317 | |
| 3318 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3319 | } |
| 3320 | else |
| 3321 | chunk_appendf(&trash, ",,,,,,"); |
| 3322 | |
| 3323 | /* failed health analyses */ |
| 3324 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3325 | |
| 3326 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3327 | chunk_appendf(&trash, ",,,"); |
| 3328 | |
| 3329 | /* errors: cli_aborts, srv_aborts */ |
| 3330 | chunk_appendf(&trash, "%lld,%lld,", |
| 3331 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3332 | |
| 3333 | /* compression: in, out, bypassed, comp_rsp */ |
| 3334 | chunk_appendf(&trash, ",,,,"); |
| 3335 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3336 | /* lastsess */ |
| 3337 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3338 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3339 | /* capture of last check and agent statuses */ |
| 3340 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->check.desc) : ""); |
| 3341 | chunk_appendf(&trash, "%s,", ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->agent.desc) : ""); |
| 3342 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3343 | /* qtime, ctime, rtime, ttime, */ |
| 3344 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3345 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3346 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3347 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3348 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3349 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3350 | /* finish with EOL */ |
| 3351 | chunk_appendf(&trash, "\n"); |
| 3352 | } |
| 3353 | return 1; |
| 3354 | } |
| 3355 | |
| 3356 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3357 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3358 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3359 | */ |
| 3360 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3361 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3362 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3363 | struct chunk src; |
| 3364 | int i; |
| 3365 | |
| 3366 | if (!(px->cap & PR_CAP_BE)) |
| 3367 | return 0; |
| 3368 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3369 | 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] | 3370 | return 0; |
| 3371 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3372 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3373 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3374 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3375 | /* Column sub-heading for Enable or Disable server */ |
| 3376 | chunk_appendf(&trash, "<td></td>"); |
| 3377 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3378 | chunk_appendf(&trash, |
| 3379 | "<td class=ac>" |
| 3380 | /* name */ |
| 3381 | "%s<a name=\"%s/Backend\"></a>" |
| 3382 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3383 | "", |
| 3384 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3385 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3386 | |
| 3387 | if (flags & ST_SHLGNDS) { |
| 3388 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3389 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3390 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3391 | |
| 3392 | /* cookie */ |
| 3393 | if (px->cookie_name) { |
| 3394 | chunk_appendf(&trash, ", cookie: '"); |
| 3395 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3396 | chunk_htmlencode(&trash, &src); |
| 3397 | chunk_appendf(&trash, "'"); |
| 3398 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3399 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3403 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3404 | /* queue : current, max */ |
| 3405 | "<td>%s</td><td>%s</td><td></td>" |
| 3406 | /* sessions rate : current, max, limit */ |
| 3407 | "<td>%s</td><td>%s</td><td></td>" |
| 3408 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3409 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3410 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3411 | 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] | 3412 | |
| 3413 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3414 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3415 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3416 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3417 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3418 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3419 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3420 | U2H(px->be_counters.cum_conn), |
| 3421 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3422 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3423 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3424 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3425 | chunk_appendf(&trash, |
| 3426 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3427 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3428 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3429 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3430 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3431 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3432 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3433 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3434 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3435 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3436 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3437 | U2H(px->be_counters.p.http.cum_req), |
| 3438 | U2H(px->be_counters.p.http.rsp[1]), |
| 3439 | U2H(px->be_counters.p.http.rsp[2]), |
| 3440 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3441 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3442 | (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] | 3443 | U2H(px->be_counters.p.http.rsp[3]), |
| 3444 | U2H(px->be_counters.p.http.rsp[4]), |
| 3445 | U2H(px->be_counters.p.http.rsp[5]), |
| 3446 | U2H(px->be_counters.p.http.rsp[0]), |
| 3447 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3448 | } |
| 3449 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3450 | chunk_appendf(&trash, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES))); |
| 3451 | chunk_appendf(&trash, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES))); |
| 3452 | if (px->mode == PR_MODE_HTTP) |
| 3453 | chunk_appendf(&trash, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES))); |
| 3454 | chunk_appendf(&trash, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES))); |
| 3455 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3456 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3457 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3458 | /* sessions: lbtot, last */ |
| 3459 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3460 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3461 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3462 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3463 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3464 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3465 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3466 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3467 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3468 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3469 | "<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] | 3470 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3471 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3472 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3473 | px->be_counters.comp_in ? |
| 3474 | (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] | 3475 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3476 | |
| 3477 | chunk_appendf(&trash, |
| 3478 | /* denied: req, resp */ |
| 3479 | "<td>%s</td><td>%s</td>" |
| 3480 | /* errors : request, connect */ |
| 3481 | "<td></td><td>%s</td>" |
| 3482 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3483 | "<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] | 3484 | /* warnings: retries, redispatches */ |
| 3485 | "<td>%lld</td><td>%lld</td>" |
| 3486 | /* backend status: reflect backend status (up/down): we display UP |
| 3487 | * if the backend has known working servers or if it has no server at |
| 3488 | * all (eg: for stats). Then we display the total weight, number of |
| 3489 | * active and backups. */ |
| 3490 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3491 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3492 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3493 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3494 | U2H(px->be_counters.failed_conns), |
| 3495 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3496 | px->be_counters.cli_aborts, |
| 3497 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3498 | px->be_counters.retries, px->be_counters.redispatches, |
| 3499 | human_time(now.tv_sec - px->last_change, 1), |
| 3500 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3501 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3502 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3503 | px->srv_act, px->srv_bck); |
| 3504 | |
| 3505 | chunk_appendf(&trash, |
| 3506 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3507 | "<td class=ac> </td><td>%d</td>" |
| 3508 | "<td>%s</td>" |
| 3509 | "<td></td>" |
| 3510 | "</tr>", |
| 3511 | px->down_trans, |
| 3512 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3513 | } |
| 3514 | else { /* CSV mode */ |
| 3515 | chunk_appendf(&trash, |
| 3516 | /* pxid, name */ |
| 3517 | "%s,BACKEND," |
| 3518 | /* queue : current, max */ |
| 3519 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3520 | /* sessions : current, max, limit, total */ |
| 3521 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3522 | /* bytes : in, out */ |
| 3523 | "%lld,%lld," |
| 3524 | /* denied: req, resp */ |
| 3525 | "%lld,%lld," |
| 3526 | /* errors : request, connect, response */ |
| 3527 | ",%lld,%lld," |
| 3528 | /* warnings: retries, redispatches */ |
| 3529 | "%lld,%lld," |
| 3530 | /* backend status: reflect backend status (up/down): we display UP |
| 3531 | * if the backend has known working servers or if it has no server at |
| 3532 | * all (eg: for stats). Then we display the total weight, number of |
| 3533 | * active and backups. */ |
| 3534 | "%s," |
| 3535 | "%d,%d,%d," |
| 3536 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3537 | ",%d,%d,%d,," |
| 3538 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3539 | "%d,%d,0,,%lld,,%d," |
| 3540 | /* rate, rate_lim, rate_max, */ |
| 3541 | "%u,,%u," |
| 3542 | /* check_status, check_code, check_duration */ |
| 3543 | ",,,", |
| 3544 | px->id, |
| 3545 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3546 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3547 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3548 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3549 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3550 | px->be_counters.retries, px->be_counters.redispatches, |
| 3551 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3552 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3553 | px->srv_act, px->srv_bck, |
| 3554 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3555 | px->srv?be_downtime(px):0, |
| 3556 | relative_pid, px->uuid, |
| 3557 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3558 | read_freq_ctr(&px->be_sess_per_sec), |
| 3559 | px->be_counters.sps_max); |
| 3560 | |
| 3561 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3562 | if (px->mode == PR_MODE_HTTP) { |
| 3563 | for (i=1; i<6; i++) |
| 3564 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3565 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3566 | } |
| 3567 | else |
| 3568 | chunk_appendf(&trash, ",,,,,,"); |
| 3569 | |
| 3570 | /* failed health analyses */ |
| 3571 | chunk_appendf(&trash, ","); |
| 3572 | |
| 3573 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3574 | chunk_appendf(&trash, ",,,"); |
| 3575 | |
| 3576 | /* errors: cli_aborts, srv_aborts */ |
| 3577 | chunk_appendf(&trash, "%lld,%lld,", |
| 3578 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3579 | |
| 3580 | /* compression: in, out, bypassed */ |
| 3581 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3582 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3583 | |
| 3584 | /* compression: comp_rsp */ |
| 3585 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3586 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3587 | /* lastsess, last_chk, last_agt, */ |
| 3588 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3589 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3590 | /* qtime, ctime, rtime, ttime, */ |
| 3591 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3592 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 3593 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 3594 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 3595 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 3596 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3597 | /* finish with EOL */ |
| 3598 | chunk_appendf(&trash, "\n"); |
| 3599 | } |
| 3600 | return 1; |
| 3601 | } |
| 3602 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3603 | /* 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] | 3604 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3605 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3606 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3607 | 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] | 3608 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3609 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3610 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3611 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3612 | 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] | 3613 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3614 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3615 | /* 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] | 3616 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3617 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3618 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3619 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3620 | 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] | 3621 | } |
| 3622 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3623 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 3624 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3625 | } |
| 3626 | |
| 3627 | /* print a new table */ |
| 3628 | chunk_appendf(&trash, |
| 3629 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3630 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3631 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3632 | |
| 3633 | chunk_appendf(&trash, |
| 3634 | "<a name=\"%s\"></a>%s" |
| 3635 | "<a class=px href=\"#%s\">%s</a>", |
| 3636 | px->id, |
| 3637 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3638 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3639 | |
| 3640 | if (uri->flags & ST_SHLGNDS) { |
| 3641 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3642 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3643 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3644 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3645 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3649 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3650 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3651 | "</tr>\n" |
| 3652 | "</table>\n" |
| 3653 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3654 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3655 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3656 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3657 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3658 | 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] | 3659 | /* Column heading for Enable or Disable server */ |
| 3660 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3661 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3662 | |
| 3663 | chunk_appendf(&trash, |
| 3664 | "<th rowspan=2></th>" |
| 3665 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3666 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3667 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3668 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3669 | "<th colspan=9>Server</th>" |
| 3670 | "</tr>\n" |
| 3671 | "<tr class=\"titre\">" |
| 3672 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3673 | "<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] | 3674 | "<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] | 3675 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3676 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3677 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3678 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3679 | "<th>Thrtle</th>\n" |
| 3680 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3681 | } |
| 3682 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3683 | /* 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] | 3684 | * 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] | 3685 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3686 | 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] | 3687 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3688 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3689 | chunk_appendf(&trash, "</table>"); |
| 3690 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3691 | 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] | 3692 | /* close the form used to enable/disable this proxy servers */ |
| 3693 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3694 | "Choose the action to perform on the checked servers : " |
| 3695 | "<select name=action>" |
| 3696 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 3697 | "<option value=\"ready\">Set state to READY</option>" |
| 3698 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 3699 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 3700 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3701 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3702 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3703 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3704 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3705 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3706 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3707 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3708 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3709 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3710 | "</select>" |
| 3711 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3712 | " <input type=\"submit\" value=\"Apply\">" |
| 3713 | "</form>", |
| 3714 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3718 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3719 | |
| 3720 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3721 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3722 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3723 | * buffer space, or non-zero if everything completed. This function is used |
| 3724 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3725 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3726 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3727 | 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] | 3728 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3729 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3730 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 3731 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3732 | 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] | 3733 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3734 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3735 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3736 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3737 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3738 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3739 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3740 | if (uri && uri->scope) { |
| 3741 | /* we have a limited scope, we have to check the proxy name */ |
| 3742 | struct stat_scope *scope; |
| 3743 | int len; |
| 3744 | |
| 3745 | len = strlen(px->id); |
| 3746 | scope = uri->scope; |
| 3747 | |
| 3748 | while (scope) { |
| 3749 | /* match exact proxy name */ |
| 3750 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3751 | break; |
| 3752 | |
| 3753 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3754 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3755 | break; |
| 3756 | scope = scope->next; |
| 3757 | } |
| 3758 | |
| 3759 | /* proxy name not found : don't dump anything */ |
| 3760 | if (scope == NULL) |
| 3761 | return 1; |
| 3762 | } |
| 3763 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3764 | /* if the user has requested a limited output and the proxy |
| 3765 | * name does not match, skip it. |
| 3766 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3767 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3768 | strnistr(px->id, strlen(px->id), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL) |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3769 | return 1; |
| 3770 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3771 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3772 | (appctx->ctx.stats.iid != -1) && |
| 3773 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3774 | return 1; |
| 3775 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3776 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3777 | /* fall through */ |
| 3778 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3779 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3780 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3781 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3782 | if (bi_putchk(rep, &trash) == -1) { |
| 3783 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3784 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3785 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3786 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3787 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3788 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3789 | /* fall through */ |
| 3790 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3791 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3792 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3793 | if (stats_dump_fe_stats(si, px)) { |
| 3794 | if (bi_putchk(rep, &trash) == -1) { |
| 3795 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3796 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3797 | } |
| 3798 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3799 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3800 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3801 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3802 | /* fall through */ |
| 3803 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3804 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3805 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3806 | 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] | 3807 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3808 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3809 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3810 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3811 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3812 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3813 | if (!l->counters) |
| 3814 | continue; |
| 3815 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3816 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3817 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3818 | break; |
| 3819 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3820 | 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] | 3821 | continue; |
| 3822 | } |
| 3823 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3824 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3825 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) { |
| 3826 | if (bi_putchk(rep, &trash) == -1) { |
| 3827 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3828 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3829 | } |
| 3830 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3831 | } |
| 3832 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3833 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3834 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3835 | /* fall through */ |
| 3836 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3837 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3838 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3839 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3840 | int sv_state; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3841 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3842 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3843 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3844 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3845 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3846 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3847 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3848 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3849 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3850 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3851 | break; |
| 3852 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3853 | 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] | 3854 | continue; |
| 3855 | } |
| 3856 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3857 | svs = sv; |
| 3858 | while (svs->track) |
| 3859 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3860 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3861 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 3862 | /* server is UP. The possibilities are : |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3863 | * - UP, draining, going down => state = 7 |
| 3864 | * - UP, going down => state = 3 |
| 3865 | * - UP, draining => state = 8 |
| 3866 | * - UP, checked => state = 4 |
| 3867 | * - UP, not checked nor tracked => state = 9 |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3868 | */ |
| 3869 | |
| 3870 | if ((svs->check.state & CHK_ST_ENABLED) && |
| 3871 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3872 | sv_state = 3; |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3873 | else |
| 3874 | sv_state = 4; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3875 | |
Willy Tarreau | efe2822 | 2014-05-21 17:13:13 +0200 | [diff] [blame] | 3876 | if (server_is_draining(sv)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3877 | sv_state += 4; |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3878 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3879 | if (sv_state == 4 && !(svs->check.state & CHK_ST_ENABLED)) |
| 3880 | sv_state = 9; /* unchecked UP */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3881 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3882 | else if (sv->state == SRV_ST_STOPPING) { |
| 3883 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 3884 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3885 | sv_state = 6; /* NOLB */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3886 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3887 | sv_state = 5; /* NOLB going down */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3888 | } |
| 3889 | else { /* stopped */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3890 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) |
| 3891 | sv_state = 1; /* DOWN (agent) */ |
| 3892 | else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3893 | sv_state = 0; /* DOWN */ |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3894 | else if ((svs->agent.state & CHK_ST_ENABLED) || (svs->check.state & CHK_ST_ENABLED)) |
| 3895 | sv_state = 2; /* going up */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3896 | else |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3897 | sv_state = 0; /* DOWN, unchecked */ |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3898 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3899 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3900 | if (((sv_state <= 1) || (sv->admin & SRV_ADMF_MAINT)) && (appctx->ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3901 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3902 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3903 | continue; |
| 3904 | } |
| 3905 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3906 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) { |
| 3907 | if (bi_putchk(rep, &trash) == -1) { |
| 3908 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3909 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3910 | } |
| 3911 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3912 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3913 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3914 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3915 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3916 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3917 | case STAT_PX_ST_BE: |
| 3918 | /* print the backend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3919 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) { |
| 3920 | if (bi_putchk(rep, &trash) == -1) { |
| 3921 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3922 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3923 | } |
| 3924 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3925 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3926 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3927 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3928 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3929 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3930 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3931 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3932 | if (bi_putchk(rep, &trash) == -1) { |
| 3933 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3934 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3935 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3936 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3937 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3938 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3939 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3940 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3941 | case STAT_PX_ST_FIN: |
| 3942 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3943 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3944 | default: |
| 3945 | /* unknown state, we should put an abort() here ! */ |
| 3946 | return 1; |
| 3947 | } |
| 3948 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3949 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3950 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3951 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3952 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3953 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3954 | { |
| 3955 | /* WARNING! This must fit in the first buffer !!! */ |
| 3956 | chunk_appendf(&trash, |
| 3957 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3958 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3959 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3960 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3961 | "<style type=\"text/css\"><!--\n" |
| 3962 | "body {" |
| 3963 | " font-family: arial, helvetica, sans-serif;" |
| 3964 | " font-size: 12px;" |
| 3965 | " font-weight: normal;" |
| 3966 | " color: black;" |
| 3967 | " background: white;" |
| 3968 | "}\n" |
| 3969 | "th,td {" |
| 3970 | " font-size: 10px;" |
| 3971 | "}\n" |
| 3972 | "h1 {" |
| 3973 | " font-size: x-large;" |
| 3974 | " margin-bottom: 0.5em;" |
| 3975 | "}\n" |
| 3976 | "h2 {" |
| 3977 | " font-family: helvetica, arial;" |
| 3978 | " font-size: x-large;" |
| 3979 | " font-weight: bold;" |
| 3980 | " font-style: italic;" |
| 3981 | " color: #6020a0;" |
| 3982 | " margin-top: 0em;" |
| 3983 | " margin-bottom: 0em;" |
| 3984 | "}\n" |
| 3985 | "h3 {" |
| 3986 | " font-family: helvetica, arial;" |
| 3987 | " font-size: 16px;" |
| 3988 | " font-weight: bold;" |
| 3989 | " color: #b00040;" |
| 3990 | " background: #e8e8d0;" |
| 3991 | " margin-top: 0em;" |
| 3992 | " margin-bottom: 0em;" |
| 3993 | "}\n" |
| 3994 | "li {" |
| 3995 | " margin-top: 0.25em;" |
| 3996 | " margin-right: 2em;" |
| 3997 | "}\n" |
| 3998 | ".hr {margin-top: 0.25em;" |
| 3999 | " border-color: black;" |
| 4000 | " border-bottom-style: solid;" |
| 4001 | "}\n" |
| 4002 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4003 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4004 | ".frontend {background: #e8e8d0;}\n" |
| 4005 | ".socket {background: #d0d0d0;}\n" |
| 4006 | ".backend {background: #e8e8d0;}\n" |
| 4007 | ".active0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4008 | ".active1 {background: #ff9090;}\n" |
| 4009 | ".active2 {background: #ffd020;}\n" |
| 4010 | ".active3 {background: #ffffa0;}\n" |
| 4011 | ".active4 {background: #c0ffc0;}\n" |
| 4012 | ".active5 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 4013 | ".active6 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 4014 | ".active7 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 4015 | ".active8 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
| 4016 | ".active9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4017 | ".backup0 {background: #ff9090;}\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4018 | ".backup1 {background: #ff9090;}\n" |
| 4019 | ".backup2 {background: #ff80ff;}\n" |
| 4020 | ".backup3 {background: #c060ff;}\n" |
| 4021 | ".backup4 {background: #b0d0ff;}\n" |
| 4022 | ".backup5 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 4023 | ".backup6 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 4024 | ".backup7 {background: #c060ff;}\n" |
| 4025 | ".backup8 {background: #cc9900;}\n" |
| 4026 | ".backup9 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4027 | ".maintain {background: #c07820;}\n" |
| 4028 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4029 | "\n" |
| 4030 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4031 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4032 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4033 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4034 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4035 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4036 | "\n" |
| 4037 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4038 | "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" |
| 4039 | "table.tbl td.ac { text-align: center;}\n" |
| 4040 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4041 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4042 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4043 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4044 | "\n" |
| 4045 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4046 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4047 | "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] | 4048 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4049 | "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] | 4050 | "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] | 4051 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4052 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4053 | " display:block;\n" |
| 4054 | " visibility:hidden;\n" |
| 4055 | " z-index:2147483647;\n" |
| 4056 | " position:absolute;\n" |
| 4057 | " padding:2px 4px 3px;\n" |
| 4058 | " background:#f0f060; color:#000000;\n" |
| 4059 | " border:1px solid #7040c0;\n" |
| 4060 | " white-space:nowrap;\n" |
| 4061 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4062 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4063 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4064 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4065 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4066 | "-->\n" |
| 4067 | "</style></head>\n", |
| 4068 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4069 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4070 | ); |
| 4071 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4072 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4073 | /* 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] | 4074 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4075 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4076 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4077 | 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] | 4078 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4079 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4080 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4081 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4082 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4083 | /* WARNING! this has to fit the first packet too. |
| 4084 | * We are around 3.5 kB, add adding entries will |
| 4085 | * become tricky if we want to support 4kB buffers ! |
| 4086 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4087 | chunk_appendf(&trash, |
| 4088 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4089 | PRODUCT_NAME "%s</a></h1>\n" |
| 4090 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4091 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4092 | "<h3>> General process information</h3>\n" |
| 4093 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4094 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4095 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4096 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4097 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4098 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4099 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4100 | "</td><td align=\"center\" nowrap>\n" |
| 4101 | "<table class=\"lgd\"><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4102 | "<td class=\"active4\"> </td><td class=\"noborder\">active UP </td>" |
| 4103 | "<td class=\"backup4\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4104 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4105 | "<td class=\"active3\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4106 | "<td class=\"backup3\"></td><td class=\"noborder\">backup UP, going down </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4107 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4108 | "<td class=\"active2\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4109 | "<td class=\"backup2\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4110 | "</tr><tr>\n" |
| 4111 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4112 | "<td class=\"active9\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4113 | "</tr><tr>\n" |
| 4114 | "<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] | 4115 | "</tr><tr>\n" |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4116 | "<td class=\"active8\"></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] | 4117 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4118 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4119 | "</td>" |
| 4120 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4121 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4122 | "", |
| 4123 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4124 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4125 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4126 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4127 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4128 | pid, relative_pid, global.nbproc, |
| 4129 | up / 86400, (up % 86400) / 3600, |
| 4130 | (up % 3600) / 60, (up % 60), |
| 4131 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4132 | global.rlimit_memmax ? " MB" : "", |
| 4133 | global.rlimit_nofile, |
| 4134 | global.maxsock, global.maxconn, global.maxpipes, |
| 4135 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4136 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4137 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4138 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4139 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4140 | memcpy(scope_txt, bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4141 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4142 | |
| 4143 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4144 | "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4145 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4146 | STAT_SCOPE_TXT_MAXLEN); |
| 4147 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4148 | /* 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] | 4149 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4150 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4151 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4152 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4153 | 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] | 4154 | } |
| 4155 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4156 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4157 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4158 | "<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] | 4159 | uri->uri_prefix, |
| 4160 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4161 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4162 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4163 | else |
| 4164 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4165 | "<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] | 4166 | uri->uri_prefix, |
| 4167 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4168 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4169 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4170 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4171 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4172 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4173 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4174 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4175 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4176 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4177 | "", |
| 4178 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4179 | else |
| 4180 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4181 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4182 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4183 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4184 | ";norefresh", |
| 4185 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4186 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4187 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4188 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4189 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4190 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4191 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4192 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4193 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4194 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4195 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4196 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4197 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4198 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4199 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4200 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4201 | chunk_appendf(&trash, |
| 4202 | "</ul></td>" |
| 4203 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4204 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4205 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4206 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4207 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4208 | "</ul>" |
| 4209 | "</td>" |
| 4210 | "</tr></table>\n" |
| 4211 | "" |
| 4212 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4213 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4214 | if (appctx->ctx.stats.st_code) { |
| 4215 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4216 | case STAT_STATUS_DONE: |
| 4217 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4218 | "<p><div class=active4>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4219 | "<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] | 4220 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4221 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4222 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4223 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4224 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4225 | break; |
| 4226 | case STAT_STATUS_NONE: |
| 4227 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4228 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4229 | "<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] | 4230 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4231 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4232 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4233 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4234 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4235 | break; |
| 4236 | case STAT_STATUS_PART: |
| 4237 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4238 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4239 | "<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] | 4240 | "Action partially processed.<br>" |
| 4241 | "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] | 4242 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4243 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4244 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4245 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4246 | break; |
| 4247 | case STAT_STATUS_ERRP: |
| 4248 | chunk_appendf(&trash, |
| 4249 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4250 | "<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] | 4251 | "Action not processed because of invalid parameters." |
| 4252 | "<ul>" |
| 4253 | "<li>The action is maybe unknown.</li>" |
| 4254 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4255 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4256 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4257 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4258 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4259 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4260 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4261 | break; |
| 4262 | case STAT_STATUS_EXCD: |
| 4263 | chunk_appendf(&trash, |
| 4264 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4265 | "<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] | 4266 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4267 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4268 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4269 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4270 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4271 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4272 | break; |
| 4273 | case STAT_STATUS_DENY: |
| 4274 | chunk_appendf(&trash, |
| 4275 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4276 | "<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] | 4277 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4278 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4279 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4280 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4281 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4282 | break; |
| 4283 | default: |
| 4284 | chunk_appendf(&trash, |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4285 | "<p><div class=active9>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4286 | "<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] | 4287 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4288 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4289 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4290 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4291 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4292 | } |
| 4293 | chunk_appendf(&trash, "<p>\n"); |
| 4294 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4295 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4296 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4297 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4298 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4299 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4300 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4301 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4302 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4303 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4304 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4305 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4306 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4307 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4308 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4309 | * and the stream must be closed, or -1 in case of any error. This function is |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4310 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4311 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4312 | 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] | 4313 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4314 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4315 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4316 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4317 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4318 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4319 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4320 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4321 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4322 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4323 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4324 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4325 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4326 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4327 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4328 | else |
| 4329 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4330 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4331 | if (bi_putchk(rep, &trash) == -1) { |
| 4332 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4333 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4334 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4335 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4336 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4337 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4338 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4339 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4340 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4341 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4342 | if (bi_putchk(rep, &trash) == -1) { |
| 4343 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4344 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4345 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4346 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4347 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4348 | appctx->ctx.stats.px = proxy; |
| 4349 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4350 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4351 | /* fall through */ |
| 4352 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4353 | case STAT_ST_LIST: |
| 4354 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4355 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4356 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4357 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4358 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4359 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4360 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4361 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4362 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4363 | 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] | 4364 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4365 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4366 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4367 | appctx->ctx.stats.px = px->next; |
| 4368 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4369 | } |
| 4370 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4371 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4372 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4373 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4374 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4375 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4376 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4377 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4378 | if (bi_putchk(rep, &trash) == -1) { |
| 4379 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4380 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4381 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4382 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4383 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4384 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4385 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4386 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4387 | case STAT_ST_FIN: |
| 4388 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4389 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4390 | default: |
| 4391 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4392 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4393 | return -1; |
| 4394 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4395 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4396 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4397 | /* We reached the stats page through a POST request. The appctx is |
| 4398 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4399 | * Parse the posted data and enable/disable servers if necessary. |
| 4400 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4401 | */ |
| 4402 | static int stats_process_http_post(struct stream_interface *si) |
| 4403 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4404 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4405 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4406 | |
| 4407 | struct proxy *px = NULL; |
| 4408 | struct server *sv = NULL; |
| 4409 | |
| 4410 | char key[LINESIZE]; |
| 4411 | int action = ST_ADM_ACTION_NONE; |
| 4412 | int reprocess = 0; |
| 4413 | |
| 4414 | int total_servers = 0; |
| 4415 | int altered_servers = 0; |
| 4416 | |
| 4417 | char *first_param, *cur_param, *next_param, *end_params; |
| 4418 | char *st_cur_param = NULL; |
| 4419 | char *st_next_param = NULL; |
| 4420 | |
| 4421 | struct chunk *temp; |
| 4422 | int reql; |
| 4423 | |
| 4424 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4425 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4426 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4427 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4428 | goto out; |
| 4429 | } |
| 4430 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4431 | reql = bo_getblk(si_oc(si), temp->str, s->txn->req.body_len, s->txn->req.eoh + 2); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4432 | if (reql <= 0) { |
| 4433 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4434 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4435 | return 0; |
| 4436 | } |
| 4437 | |
| 4438 | first_param = temp->str; |
| 4439 | end_params = temp->str + reql; |
| 4440 | cur_param = next_param = end_params; |
| 4441 | *end_params = '\0'; |
| 4442 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4443 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4444 | |
| 4445 | /* |
| 4446 | * Parse the parameters in reverse order to only store the last value. |
| 4447 | * From the html form, the backend and the action are at the end. |
| 4448 | */ |
| 4449 | while (cur_param > first_param) { |
| 4450 | char *value; |
| 4451 | int poffset, plen; |
| 4452 | |
| 4453 | cur_param--; |
| 4454 | |
| 4455 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4456 | reprocess_servers: |
| 4457 | /* Parse the key */ |
| 4458 | poffset = (cur_param != first_param ? 1 : 0); |
| 4459 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4460 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4461 | strncpy(key, cur_param + poffset, plen); |
| 4462 | key[plen - 1] = '\0'; |
| 4463 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4464 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4465 | goto out; |
| 4466 | } |
| 4467 | |
| 4468 | /* Parse the value */ |
| 4469 | value = key; |
| 4470 | while (*value != '\0' && *value != '=') { |
| 4471 | value++; |
| 4472 | } |
| 4473 | if (*value == '=') { |
| 4474 | /* Ok, a value is found, we can mark the end of the key */ |
| 4475 | *value++ = '\0'; |
| 4476 | } |
| 4477 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4478 | break; |
| 4479 | |
| 4480 | /* Now we can check the key to see what to do */ |
| 4481 | if (!px && (strcmp(key, "b") == 0)) { |
| 4482 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4483 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4484 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4485 | goto out; |
| 4486 | } |
| 4487 | } |
| 4488 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4489 | if (strcmp(value, "ready") == 0) { |
| 4490 | action = ST_ADM_ACTION_READY; |
| 4491 | } |
| 4492 | else if (strcmp(value, "drain") == 0) { |
| 4493 | action = ST_ADM_ACTION_DRAIN; |
| 4494 | } |
| 4495 | else if (strcmp(value, "maint") == 0) { |
| 4496 | action = ST_ADM_ACTION_MAINT; |
| 4497 | } |
| 4498 | else if (strcmp(value, "shutdown") == 0) { |
| 4499 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4500 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4501 | else if (strcmp(value, "dhlth") == 0) { |
| 4502 | action = ST_ADM_ACTION_DHLTH; |
| 4503 | } |
| 4504 | else if (strcmp(value, "ehlth") == 0) { |
| 4505 | action = ST_ADM_ACTION_EHLTH; |
| 4506 | } |
| 4507 | else if (strcmp(value, "hrunn") == 0) { |
| 4508 | action = ST_ADM_ACTION_HRUNN; |
| 4509 | } |
| 4510 | else if (strcmp(value, "hnolb") == 0) { |
| 4511 | action = ST_ADM_ACTION_HNOLB; |
| 4512 | } |
| 4513 | else if (strcmp(value, "hdown") == 0) { |
| 4514 | action = ST_ADM_ACTION_HDOWN; |
| 4515 | } |
| 4516 | else if (strcmp(value, "dagent") == 0) { |
| 4517 | action = ST_ADM_ACTION_DAGENT; |
| 4518 | } |
| 4519 | else if (strcmp(value, "eagent") == 0) { |
| 4520 | action = ST_ADM_ACTION_EAGENT; |
| 4521 | } |
| 4522 | else if (strcmp(value, "arunn") == 0) { |
| 4523 | action = ST_ADM_ACTION_ARUNN; |
| 4524 | } |
| 4525 | else if (strcmp(value, "adown") == 0) { |
| 4526 | action = ST_ADM_ACTION_ADOWN; |
| 4527 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4528 | /* else these are the old supported methods */ |
| 4529 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4530 | action = ST_ADM_ACTION_DISABLE; |
| 4531 | } |
| 4532 | else if (strcmp(value, "enable") == 0) { |
| 4533 | action = ST_ADM_ACTION_ENABLE; |
| 4534 | } |
| 4535 | else if (strcmp(value, "stop") == 0) { |
| 4536 | action = ST_ADM_ACTION_STOP; |
| 4537 | } |
| 4538 | else if (strcmp(value, "start") == 0) { |
| 4539 | action = ST_ADM_ACTION_START; |
| 4540 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4541 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4542 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4543 | goto out; |
| 4544 | } |
| 4545 | } |
| 4546 | else if (strcmp(key, "s") == 0) { |
| 4547 | if (!(px && action)) { |
| 4548 | /* |
| 4549 | * Indicates that we'll need to reprocess the parameters |
| 4550 | * as soon as backend and action are known |
| 4551 | */ |
| 4552 | if (!reprocess) { |
| 4553 | st_cur_param = cur_param; |
| 4554 | st_next_param = next_param; |
| 4555 | } |
| 4556 | reprocess = 1; |
| 4557 | } |
| 4558 | else if ((sv = findserver(px, value)) != NULL) { |
| 4559 | switch (action) { |
| 4560 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4561 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4562 | altered_servers++; |
| 4563 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4564 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4565 | } |
| 4566 | break; |
| 4567 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4568 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4569 | altered_servers++; |
| 4570 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4571 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4572 | } |
| 4573 | break; |
| 4574 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4575 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 4576 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4577 | altered_servers++; |
| 4578 | total_servers++; |
| 4579 | } |
| 4580 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4581 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4582 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 4583 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4584 | altered_servers++; |
| 4585 | total_servers++; |
| 4586 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4587 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4588 | case ST_ADM_ACTION_DHLTH: |
| 4589 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4590 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4591 | altered_servers++; |
| 4592 | total_servers++; |
| 4593 | } |
| 4594 | break; |
| 4595 | case ST_ADM_ACTION_EHLTH: |
| 4596 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4597 | sv->check.state |= CHK_ST_ENABLED; |
| 4598 | altered_servers++; |
| 4599 | total_servers++; |
| 4600 | } |
| 4601 | break; |
| 4602 | case ST_ADM_ACTION_HRUNN: |
| 4603 | if (!(sv->track)) { |
| 4604 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4605 | srv_set_running(sv, "changed from Web interface"); |
| 4606 | altered_servers++; |
| 4607 | total_servers++; |
| 4608 | } |
| 4609 | break; |
| 4610 | case ST_ADM_ACTION_HNOLB: |
| 4611 | if (!(sv->track)) { |
| 4612 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4613 | srv_set_stopping(sv, "changed from Web interface"); |
| 4614 | altered_servers++; |
| 4615 | total_servers++; |
| 4616 | } |
| 4617 | break; |
| 4618 | case ST_ADM_ACTION_HDOWN: |
| 4619 | if (!(sv->track)) { |
| 4620 | sv->check.health = 0; |
| 4621 | srv_set_stopped(sv, "changed from Web interface"); |
| 4622 | altered_servers++; |
| 4623 | total_servers++; |
| 4624 | } |
| 4625 | break; |
| 4626 | case ST_ADM_ACTION_DAGENT: |
| 4627 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4628 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4629 | altered_servers++; |
| 4630 | total_servers++; |
| 4631 | } |
| 4632 | break; |
| 4633 | case ST_ADM_ACTION_EAGENT: |
| 4634 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4635 | sv->agent.state |= CHK_ST_ENABLED; |
| 4636 | altered_servers++; |
| 4637 | total_servers++; |
| 4638 | } |
| 4639 | break; |
| 4640 | case ST_ADM_ACTION_ARUNN: |
| 4641 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4642 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 4643 | srv_set_running(sv, "changed from Web interface"); |
| 4644 | altered_servers++; |
| 4645 | total_servers++; |
| 4646 | } |
| 4647 | break; |
| 4648 | case ST_ADM_ACTION_ADOWN: |
| 4649 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4650 | sv->agent.health = 0; |
| 4651 | srv_set_stopped(sv, "changed from Web interface"); |
| 4652 | altered_servers++; |
| 4653 | total_servers++; |
| 4654 | } |
| 4655 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4656 | case ST_ADM_ACTION_READY: |
| 4657 | srv_adm_set_ready(sv); |
| 4658 | altered_servers++; |
| 4659 | total_servers++; |
| 4660 | break; |
| 4661 | case ST_ADM_ACTION_DRAIN: |
| 4662 | srv_adm_set_drain(sv); |
| 4663 | altered_servers++; |
| 4664 | total_servers++; |
| 4665 | break; |
| 4666 | case ST_ADM_ACTION_MAINT: |
| 4667 | srv_adm_set_maint(sv); |
| 4668 | altered_servers++; |
| 4669 | total_servers++; |
| 4670 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4671 | case ST_ADM_ACTION_SHUTDOWN: |
| 4672 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4673 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4674 | |
| 4675 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4676 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 4677 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4678 | |
| 4679 | altered_servers++; |
| 4680 | total_servers++; |
| 4681 | } |
| 4682 | break; |
| 4683 | } |
| 4684 | } else { |
| 4685 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4686 | total_servers++; |
| 4687 | } |
| 4688 | } |
| 4689 | if (reprocess && px && action) { |
| 4690 | /* Now, we know the backend and the action chosen by the user. |
| 4691 | * We can safely restart from the first server parameter |
| 4692 | * to reprocess them |
| 4693 | */ |
| 4694 | cur_param = st_cur_param; |
| 4695 | next_param = st_next_param; |
| 4696 | reprocess = 0; |
| 4697 | goto reprocess_servers; |
| 4698 | } |
| 4699 | |
| 4700 | next_param = cur_param; |
| 4701 | } |
| 4702 | } |
| 4703 | |
| 4704 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4705 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4706 | } |
| 4707 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4708 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4709 | } |
| 4710 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4711 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4712 | } |
| 4713 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4714 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4715 | } |
| 4716 | out: |
| 4717 | return 1; |
| 4718 | } |
| 4719 | |
| 4720 | |
| 4721 | static int stats_send_http_headers(struct stream_interface *si) |
| 4722 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4723 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4724 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4725 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4726 | |
| 4727 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4728 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4729 | "Cache-Control: no-cache\r\n" |
| 4730 | "Connection: close\r\n" |
| 4731 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4732 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4733 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4734 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4735 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4736 | uri->refresh); |
| 4737 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4738 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4739 | |
| 4740 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4741 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4742 | else |
| 4743 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4744 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4745 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4746 | s->logs.tv_request = now; |
| 4747 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4748 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 4749 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4750 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4751 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4752 | |
| 4753 | return 1; |
| 4754 | } |
| 4755 | |
| 4756 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4757 | { |
| 4758 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4759 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4760 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4761 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4762 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4763 | /* 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] | 4764 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4765 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4766 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4767 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4768 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | /* We don't want to land on the posted stats page because a refresh will |
| 4772 | * repost the data. We don't want this to happen on accident so we redirect |
| 4773 | * the browse to the stats page with a GET. |
| 4774 | */ |
| 4775 | chunk_printf(&trash, |
| 4776 | "HTTP/1.1 303 See Other\r\n" |
| 4777 | "Cache-Control: no-cache\r\n" |
| 4778 | "Content-Type: text/plain\r\n" |
| 4779 | "Connection: close\r\n" |
| 4780 | "Location: %s;st=%s%s%s%s\r\n" |
| 4781 | "\r\n", |
| 4782 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4783 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4784 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4785 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4786 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4787 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4788 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4789 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4790 | scope_txt); |
| 4791 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4792 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4793 | s->logs.tv_request = now; |
| 4794 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4795 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 4796 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4797 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4798 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4799 | |
| 4800 | return 1; |
| 4801 | } |
| 4802 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4803 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4804 | * 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] | 4805 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4806 | * automatically unregisters itself once transfer is complete. |
| 4807 | */ |
| 4808 | static void http_stats_io_handler(struct stream_interface *si) |
| 4809 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4810 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4811 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4812 | struct channel *req = si_oc(si); |
| 4813 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4814 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4815 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4816 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4817 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4818 | /* check that the output is not closed */ |
| 4819 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4820 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4821 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4822 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4823 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4824 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4825 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4826 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4827 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4828 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4829 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4830 | } |
| 4831 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4832 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4833 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4834 | unsigned int data_len; |
| 4835 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 4836 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4837 | |
| 4838 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4839 | /* One difficulty we're facing is that we must prevent |
| 4840 | * the input data from being automatically forwarded to |
| 4841 | * the output area. For this, we temporarily disable |
| 4842 | * forwarding on the channel. |
| 4843 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4844 | last_fwd = si_ic(si)->to_forward; |
| 4845 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4846 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4847 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4848 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4849 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4850 | goto fail; |
| 4851 | } |
| 4852 | } |
| 4853 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4854 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4855 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4856 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4857 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4858 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4859 | |
| 4860 | /* Now we must either adjust or remove the chunk size. This is |
| 4861 | * not easy because the chunk size might wrap at the end of the |
| 4862 | * buffer, so we pretend we have nothing in the buffer, we write |
| 4863 | * the size, then restore the buffer's contents. Note that we can |
| 4864 | * only do that because no forwarding is scheduled on the stats |
| 4865 | * applet. |
| 4866 | */ |
| 4867 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4868 | si_ic(si)->total -= (last_len - prev_len); |
| 4869 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4870 | |
| 4871 | if (last_len != data_len) { |
| 4872 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4873 | if (bi_putchk(si_ic(si), &trash) == -1) |
| 4874 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4875 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4876 | si_ic(si)->total += (last_len - data_len); |
| 4877 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4878 | } |
| 4879 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4880 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4881 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4882 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4883 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4884 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4885 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4886 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4887 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4888 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4889 | } |
| 4890 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4891 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4892 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4893 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4894 | } |
| 4895 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4896 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 4897 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4898 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4899 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 4900 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4901 | goto fail; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4902 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4903 | } |
| 4904 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4905 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4906 | res->flags |= CF_READ_NULL; |
| 4907 | si_shutr(si); |
| 4908 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4909 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4910 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4911 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4912 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4913 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4914 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4915 | si_shutr(si); |
| 4916 | res->flags |= CF_READ_NULL; |
| 4917 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4918 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4919 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4920 | fail: |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4921 | /* update all other flags and resync with the other side */ |
| 4922 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4923 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4924 | /* we don't want to expire timeouts while we're processing requests */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4925 | si_ic(si)->rex = TICK_ETERNITY; |
| 4926 | si_oc(si)->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4927 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4928 | out: |
| 4929 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4930 | /* check that we have released everything then unregister */ |
| 4931 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4932 | } |
| 4933 | } |
| 4934 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4935 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4936 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4937 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4938 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4939 | return "NONE"; |
| 4940 | return conn->ctrl->name; |
| 4941 | } |
| 4942 | |
| 4943 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4944 | { |
| 4945 | static char ptr[17]; |
| 4946 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4947 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4948 | return "NONE"; |
| 4949 | |
| 4950 | if (conn->xprt == &raw_sock) |
| 4951 | return "RAW"; |
| 4952 | |
| 4953 | #ifdef USE_OPENSSL |
| 4954 | if (conn->xprt == &ssl_sock) |
| 4955 | return "SSL"; |
| 4956 | #endif |
| 4957 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4958 | return ptr; |
| 4959 | } |
| 4960 | |
| 4961 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4962 | { |
| 4963 | static char ptr[17]; |
| 4964 | |
| 4965 | if (!conn->data) |
| 4966 | return "NONE"; |
| 4967 | |
| 4968 | if (conn->data == &sess_conn_cb) |
| 4969 | return "SESS"; |
| 4970 | |
| 4971 | if (conn->data == &si_conn_cb) |
| 4972 | return "STRM"; |
| 4973 | |
| 4974 | if (conn->data == &check_conn_cb) |
| 4975 | return "CHCK"; |
| 4976 | |
| 4977 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4978 | return ptr; |
| 4979 | } |
| 4980 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4981 | /* This function dumps a complete stream state onto the stream interface's |
| 4982 | * read buffer. The stream has to be set in sess->target. It returns |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 4983 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4984 | * 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] | 4985 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4986 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct stream *sess) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4987 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4988 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4989 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4990 | extern const char *monthname[12]; |
| 4991 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4992 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4993 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4994 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4995 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4996 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4997 | if (appctx->ctx.sess.section > 0 && appctx->ctx.sess.uid != sess->uniq_id) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4998 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4999 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5000 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5001 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5002 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5003 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5004 | appctx->ctx.sess.uid = 0; |
| 5005 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5006 | return 1; |
| 5007 | } |
| 5008 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5009 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5010 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5011 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5012 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5013 | /* fall through */ |
| 5014 | |
| 5015 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5016 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5017 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5018 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5019 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5020 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5021 | 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] | 5022 | sess->uniq_id, |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5023 | strm_li(sess) && strm_li(sess)->proto->name ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5024 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5025 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5026 | 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] | 5027 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5028 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5029 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5030 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5031 | break; |
| 5032 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5033 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5034 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5035 | default: |
| 5036 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5037 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5038 | break; |
| 5039 | } |
| 5040 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5041 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5042 | " 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] | 5043 | 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] | 5044 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5045 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5046 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5047 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5048 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5049 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5050 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5051 | if (conn) |
| 5052 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5053 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5054 | 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] | 5055 | case AF_INET: |
| 5056 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5057 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5058 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5059 | break; |
| 5060 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5061 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5062 | break; |
| 5063 | default: |
| 5064 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5065 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5066 | break; |
| 5067 | } |
| 5068 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5069 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5070 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5071 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5072 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5073 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5074 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5075 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5076 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5077 | conn = objt_conn(sess->si[1].end); |
| 5078 | if (conn) |
| 5079 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5080 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5081 | 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] | 5082 | case AF_INET: |
| 5083 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5084 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5085 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5086 | break; |
| 5087 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5088 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5089 | break; |
| 5090 | default: |
| 5091 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5092 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5093 | break; |
| 5094 | } |
| 5095 | |
| 5096 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5097 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5098 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5099 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5100 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5101 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5102 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5103 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5104 | if (conn) |
| 5105 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5106 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5107 | 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] | 5108 | case AF_INET: |
| 5109 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5110 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5111 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5112 | break; |
| 5113 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5114 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5115 | break; |
| 5116 | default: |
| 5117 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5118 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5119 | break; |
| 5120 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5121 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5122 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5123 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5124 | sess->task, |
| 5125 | sess->task->state, |
| 5126 | sess->task->nice, sess->task->calls, |
| 5127 | sess->task->expire ? |
| 5128 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5129 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5130 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5131 | task_in_rq(sess->task) ? ", running" : ""); |
| 5132 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5133 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5134 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5135 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5136 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5137 | if (sess->txn) |
| 5138 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5139 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s waiting=%d\n", |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5140 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5141 | http_msg_state_str(sess->txn->req.msg_state), http_msg_state_str(sess->txn->rsp.msg_state), !LIST_ISEMPTY(&sess->buffer_wait)); |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5142 | |
| 5143 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5144 | " 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] | 5145 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5146 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5147 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5148 | obj_type_name(sess->si[0].end), |
| 5149 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5150 | sess->si[0].exp ? |
| 5151 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5152 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5153 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5154 | sess->si[0].err_type); |
| 5155 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5156 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5157 | " 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] | 5158 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5159 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5160 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5161 | obj_type_name(sess->si[1].end), |
| 5162 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5163 | sess->si[1].exp ? |
| 5164 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5165 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5166 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5167 | sess->si[1].err_type); |
| 5168 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5169 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5170 | chunk_appendf(&trash, |
| 5171 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5172 | conn, |
| 5173 | get_conn_ctrl_name(conn), |
| 5174 | get_conn_xprt_name(conn), |
| 5175 | get_conn_data_name(conn), |
| 5176 | obj_type_name(conn->target), |
| 5177 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5178 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5179 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5180 | " 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] | 5181 | conn->flags, |
| 5182 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5183 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5184 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5185 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5186 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5187 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5188 | chunk_appendf(&trash, |
| 5189 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5190 | tmpctx, |
| 5191 | tmpctx->st0, |
| 5192 | tmpctx->st1, |
| 5193 | tmpctx->st2, |
| 5194 | tmpctx->applet->name); |
| 5195 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5196 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5197 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5198 | chunk_appendf(&trash, |
| 5199 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5200 | conn, |
| 5201 | get_conn_ctrl_name(conn), |
| 5202 | get_conn_xprt_name(conn), |
| 5203 | get_conn_data_name(conn), |
| 5204 | obj_type_name(conn->target), |
| 5205 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5206 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5207 | chunk_appendf(&trash, |
| 5208 | " 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] | 5209 | conn->flags, |
| 5210 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5211 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5212 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5213 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5214 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5215 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5216 | chunk_appendf(&trash, |
| 5217 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5218 | tmpctx, |
| 5219 | tmpctx->st0, |
| 5220 | tmpctx->st1, |
| 5221 | tmpctx->st2, |
| 5222 | tmpctx->applet->name); |
| 5223 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5224 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5225 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5226 | " 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] | 5227 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5228 | &sess->req, |
| 5229 | sess->req.flags, sess->req.analysers, |
| 5230 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5231 | sess->req.to_forward, sess->req.total, |
| 5232 | sess->req.analyse_exp ? |
| 5233 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5234 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5235 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5236 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5237 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5238 | sess->req.rex ? |
| 5239 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5240 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5241 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5242 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5243 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5244 | " buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d\n", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5245 | sess->req.wex ? |
| 5246 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5247 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5248 | sess->req.buf, |
| 5249 | sess->req.buf->data, sess->req.buf->o, |
| 5250 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5251 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5252 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5253 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5254 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5255 | " 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] | 5256 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5257 | &sess->res, |
| 5258 | sess->res.flags, sess->res.analysers, |
| 5259 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5260 | sess->res.to_forward, sess->res.total, |
| 5261 | sess->res.analyse_exp ? |
| 5262 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5263 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5264 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5265 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5266 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5267 | sess->res.rex ? |
| 5268 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5269 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5270 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5271 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5272 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5273 | " buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d\n", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5274 | sess->res.wex ? |
| 5275 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5276 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5277 | sess->res.buf, |
| 5278 | sess->res.buf->data, sess->res.buf->o, |
| 5279 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5280 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5281 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5282 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5283 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5284 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5285 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5286 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5287 | |
| 5288 | /* use other states to dump the contents */ |
| 5289 | } |
| 5290 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5291 | appctx->ctx.sess.uid = 0; |
| 5292 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5293 | return 1; |
| 5294 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5295 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5296 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5297 | { |
| 5298 | struct appctx *appctx = __objt_appctx(si->end); |
| 5299 | |
| 5300 | switch (appctx->st2) { |
| 5301 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5302 | /* Display the column headers. If the message cannot be sent, |
| 5303 | * quit the fucntion with returning 0. The function is called |
| 5304 | * later and restart at the state "STAT_ST_INIT". |
| 5305 | */ |
| 5306 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5307 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5308 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5309 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5310 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5311 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5312 | |
| 5313 | /* Now, we start the browsing of the references lists. |
| 5314 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5315 | * avalaible field of this pointer is <list>. It is used with the function |
| 5316 | * pat_list_get_next() for retruning the first avalaible entry |
| 5317 | */ |
| 5318 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5319 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5320 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5321 | appctx->st2 = STAT_ST_LIST; |
| 5322 | /* fall through */ |
| 5323 | |
| 5324 | case STAT_ST_LIST: |
| 5325 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5326 | chunk_reset(&trash); |
| 5327 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5328 | /* Build messages. If the reference is used by another category than |
| 5329 | * the listed categorie, display the information in the massage. |
| 5330 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5331 | 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] | 5332 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5333 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5334 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5335 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5336 | /* let's try again later from this stream. We add ourselves into |
| 5337 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5338 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5339 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5340 | return 0; |
| 5341 | } |
| 5342 | |
| 5343 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5344 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5345 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | appctx->st2 = STAT_ST_FIN; |
| 5349 | /* fall through */ |
| 5350 | |
| 5351 | default: |
| 5352 | appctx->st2 = STAT_ST_FIN; |
| 5353 | return 1; |
| 5354 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5355 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5356 | } |
| 5357 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5358 | static int stats_map_lookup(struct stream_interface *si) |
| 5359 | { |
| 5360 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5361 | struct sample sample; |
| 5362 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5363 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5364 | |
| 5365 | switch (appctx->st2) { |
| 5366 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5367 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5368 | 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] | 5369 | 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] | 5370 | appctx->st2 = STAT_ST_LIST; |
| 5371 | /* fall through */ |
| 5372 | |
| 5373 | case STAT_ST_LIST: |
| 5374 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5375 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5376 | /* initialise chunk to build new message */ |
| 5377 | chunk_reset(&trash); |
| 5378 | |
| 5379 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 5380 | sample.type = SMP_T_STR; |
| 5381 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5382 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 5383 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5384 | if (appctx->ctx.map.expr->pat_head->match && |
| 5385 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5386 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5387 | else |
| 5388 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5389 | |
| 5390 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5391 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5392 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5393 | break; |
| 5394 | if (match_method >= PAT_MATCH_NUM) |
| 5395 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5396 | else |
| 5397 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5398 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5399 | /* case sensitive */ |
| 5400 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5401 | chunk_appendf(&trash, ", case=insensitive"); |
| 5402 | else |
| 5403 | chunk_appendf(&trash, ", case=sensitive"); |
| 5404 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5405 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5406 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5407 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5408 | chunk_appendf(&trash, ", found=no"); |
| 5409 | else |
| 5410 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | /* Display match and match info */ |
| 5414 | else { |
| 5415 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5416 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5417 | chunk_appendf(&trash, ", found=yes"); |
| 5418 | else |
| 5419 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5420 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5421 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5422 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5423 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5424 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5425 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5426 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5427 | /* display pattern */ |
| 5428 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5429 | if (pat->ref && pat->ref->pattern) |
| 5430 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5431 | else |
| 5432 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5433 | } |
| 5434 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5435 | if (pat->ref && pat->ref->pattern) |
| 5436 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5437 | else |
| 5438 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5439 | } |
| 5440 | |
| 5441 | /* display return value */ |
| 5442 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5443 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5444 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5445 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5446 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5447 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5448 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5449 | } |
| 5450 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5451 | chunk_appendf(&trash, "\n"); |
| 5452 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5453 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5454 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5455 | /* let's try again later from this stream. We add ourselves into |
| 5456 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5457 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5458 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5459 | return 0; |
| 5460 | } |
| 5461 | |
| 5462 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5463 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5464 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5465 | } |
| 5466 | |
| 5467 | appctx->st2 = STAT_ST_FIN; |
| 5468 | /* fall through */ |
| 5469 | |
| 5470 | default: |
| 5471 | appctx->st2 = STAT_ST_FIN; |
| 5472 | free(appctx->ctx.map.chunk.str); |
| 5473 | return 1; |
| 5474 | } |
| 5475 | } |
| 5476 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5477 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5478 | { |
| 5479 | struct appctx *appctx = __objt_appctx(si->end); |
| 5480 | |
| 5481 | switch (appctx->st2) { |
| 5482 | |
| 5483 | case STAT_ST_INIT: |
| 5484 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5485 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5486 | struct pat_ref_elt *, list); |
| 5487 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5488 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5489 | appctx->st2 = STAT_ST_LIST; |
| 5490 | /* fall through */ |
| 5491 | |
| 5492 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5493 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5494 | chunk_reset(&trash); |
| 5495 | |
| 5496 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5497 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5498 | chunk_appendf(&trash, "%p %s %s\n", |
| 5499 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5500 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5501 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5502 | chunk_appendf(&trash, "%p %s\n", |
| 5503 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5504 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5505 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5506 | /* let's try again later from this stream. We add ourselves into |
| 5507 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5508 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5509 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5510 | return 0; |
| 5511 | } |
| 5512 | |
| 5513 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5514 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5515 | struct pat_ref_elt *, list); |
| 5516 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5517 | break; |
| 5518 | } |
| 5519 | |
| 5520 | appctx->st2 = STAT_ST_FIN; |
| 5521 | /* fall through */ |
| 5522 | |
| 5523 | default: |
| 5524 | appctx->st2 = STAT_ST_FIN; |
| 5525 | return 1; |
| 5526 | } |
| 5527 | } |
| 5528 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5529 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5530 | * 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] | 5531 | * to be called again, otherwise non-zero. It is designed to be called |
| 5532 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5533 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5534 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5535 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5536 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5537 | struct connection *conn; |
| 5538 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5539 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5540 | /* If we're forced to shut down, we might have to remove our |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5541 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5542 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5543 | if (appctx->st2 == STAT_ST_LIST) { |
| 5544 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5545 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5546 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5547 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5548 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5549 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5550 | } |
| 5551 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5552 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5553 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5554 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5555 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5556 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5557 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5558 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5559 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5560 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5561 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5562 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5563 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5564 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5565 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5566 | /* fall through */ |
| 5567 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5568 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5569 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5570 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5571 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5572 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5576 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5577 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5578 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5579 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5580 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5581 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5582 | if (appctx->ctx.sess.target) { |
| 5583 | 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] | 5584 | goto next_sess; |
| 5585 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5586 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5587 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5588 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5589 | return 0; |
| 5590 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5591 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5592 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5593 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5594 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5595 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5596 | break; |
| 5597 | } |
| 5598 | else |
| 5599 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5600 | } |
| 5601 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5602 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5603 | "%p: proto=%s", |
| 5604 | curr_sess, |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5605 | strm_li(curr_sess)->proto->name); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5606 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5607 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5608 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5609 | 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] | 5610 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5611 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5612 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5613 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5614 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5615 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5616 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5617 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5618 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5619 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5620 | break; |
| 5621 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5622 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5623 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5624 | strm_li(curr_sess)->luid, |
| 5625 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5626 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5627 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5628 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +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 | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5633 | " ts=%02x age=%s calls=%d", |
| 5634 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5635 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5636 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5637 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5638 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5639 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5640 | curr_sess->req.flags, |
| 5641 | curr_sess->req.buf->i, |
| 5642 | curr_sess->req.analysers, |
| 5643 | curr_sess->req.rex ? |
| 5644 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5645 | TICKS_TO_MS(1000)) : ""); |
| 5646 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5647 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5648 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5649 | curr_sess->req.wex ? |
| 5650 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5651 | TICKS_TO_MS(1000)) : ""); |
| 5652 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5653 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5654 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5655 | curr_sess->req.analyse_exp ? |
| 5656 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5657 | TICKS_TO_MS(1000)) : ""); |
| 5658 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5659 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5660 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5661 | curr_sess->res.flags, |
| 5662 | curr_sess->res.buf->i, |
| 5663 | curr_sess->res.analysers, |
| 5664 | curr_sess->res.rex ? |
| 5665 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5666 | TICKS_TO_MS(1000)) : ""); |
| 5667 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5668 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5669 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5670 | curr_sess->res.wex ? |
| 5671 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5672 | TICKS_TO_MS(1000)) : ""); |
| 5673 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5674 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5675 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5676 | curr_sess->res.analyse_exp ? |
| 5677 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5678 | TICKS_TO_MS(1000)) : ""); |
| 5679 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5680 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5681 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5682 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5683 | curr_sess->si[0].state, |
| 5684 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5685 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5686 | curr_sess->si[0].exp ? |
| 5687 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5688 | TICKS_TO_MS(1000)) : ""); |
| 5689 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5690 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5691 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5692 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5693 | curr_sess->si[1].state, |
| 5694 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5695 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5696 | curr_sess->si[1].exp ? |
| 5697 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5698 | TICKS_TO_MS(1000)) : ""); |
| 5699 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5700 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5701 | " exp=%s", |
| 5702 | curr_sess->task->expire ? |
| 5703 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5704 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5705 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5706 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5707 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5708 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5709 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5710 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5711 | /* let's try again later from this stream. We add ourselves into |
| 5712 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5713 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5714 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5715 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5716 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5717 | } |
| 5718 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5719 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5720 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5721 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5722 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5723 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5724 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5725 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5726 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5727 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5728 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5729 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5730 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5731 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5732 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5733 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5734 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5735 | appctx->ctx.sess.target = NULL; |
| 5736 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5737 | return 1; |
| 5738 | } |
| 5739 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5740 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5741 | /* fall through */ |
| 5742 | |
| 5743 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5744 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5745 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5746 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5747 | } |
| 5748 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5749 | /* This is called when the stream interface is closed. For instance, upon an |
| 5750 | * external abort, we won't call the i/o handler anymore so we may need to |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5751 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5752 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5753 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5754 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5755 | struct appctx *appctx = __objt_appctx(si->end); |
| 5756 | |
| 5757 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5758 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5759 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5760 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5761 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5762 | free(appctx->ctx.cli.err); |
| 5763 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5764 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5765 | free(appctx->ctx.map.chunk.str); |
| 5766 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5767 | } |
| 5768 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5769 | /* This function is used to either dump tables states (when action is set |
| 5770 | * 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] | 5771 | * It returns 0 if the output buffer is full and it needs to be called |
| 5772 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5773 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5774 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5775 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5776 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5777 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5778 | struct ebmb_node *eb; |
| 5779 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5780 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5781 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5782 | |
| 5783 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5784 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5785 | * - STAT_ST_INIT : the first call |
| 5786 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5787 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5788 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5789 | * and the entry pointer points to the next entry to be dumped, |
| 5790 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5791 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5792 | * data though. |
| 5793 | */ |
| 5794 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5795 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5796 | /* 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] | 5797 | if (appctx->st2 == STAT_ST_LIST) { |
| 5798 | appctx->ctx.table.entry->ref_cnt--; |
| 5799 | 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] | 5800 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5801 | return 1; |
| 5802 | } |
| 5803 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5804 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5805 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5806 | while (appctx->st2 != STAT_ST_FIN) { |
| 5807 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5808 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5809 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5810 | if (!appctx->ctx.table.proxy) |
| 5811 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5812 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5813 | appctx->ctx.table.entry = NULL; |
| 5814 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5815 | break; |
| 5816 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5817 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5818 | if (!appctx->ctx.table.proxy || |
| 5819 | (appctx->ctx.table.target && |
| 5820 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5821 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5822 | break; |
| 5823 | } |
| 5824 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5825 | if (appctx->ctx.table.proxy->table.size) { |
| 5826 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5827 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5828 | return 0; |
| 5829 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5830 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5831 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5832 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5833 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5834 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5835 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5836 | appctx->ctx.table.entry->ref_cnt++; |
| 5837 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5838 | break; |
| 5839 | } |
| 5840 | } |
| 5841 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5842 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5843 | break; |
| 5844 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5845 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5846 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5847 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5848 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5849 | /* we're filtering on some data contents */ |
| 5850 | void *ptr; |
| 5851 | long long data; |
| 5852 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5853 | dt = appctx->ctx.table.data_type; |
| 5854 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5855 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5856 | dt); |
| 5857 | |
| 5858 | data = 0; |
| 5859 | switch (stktable_data_types[dt].std_type) { |
| 5860 | case STD_T_SINT: |
| 5861 | data = stktable_data_cast(ptr, std_t_sint); |
| 5862 | break; |
| 5863 | case STD_T_UINT: |
| 5864 | data = stktable_data_cast(ptr, std_t_uint); |
| 5865 | break; |
| 5866 | case STD_T_ULL: |
| 5867 | data = stktable_data_cast(ptr, std_t_ull); |
| 5868 | break; |
| 5869 | case STD_T_FRQP: |
| 5870 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5871 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5872 | break; |
| 5873 | } |
| 5874 | |
| 5875 | /* 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] | 5876 | if ((data < appctx->ctx.table.value && |
| 5877 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5878 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5879 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5880 | (data == appctx->ctx.table.value && |
| 5881 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5882 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5883 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5884 | (data > appctx->ctx.table.value && |
| 5885 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5886 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5887 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5888 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5889 | } |
| 5890 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5891 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5892 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5893 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5894 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5895 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5896 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5897 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5898 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5899 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5900 | struct stksess *old = appctx->ctx.table.entry; |
| 5901 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5902 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5903 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5904 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5905 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5906 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5907 | break; |
| 5908 | } |
| 5909 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5910 | |
| 5911 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5912 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5913 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5914 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5915 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5916 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5917 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5918 | break; |
| 5919 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5920 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5921 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5922 | break; |
| 5923 | } |
| 5924 | } |
| 5925 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5926 | } |
| 5927 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5928 | /* 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] | 5929 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5930 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5931 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5932 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5933 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5934 | * after the offset. The new pointer is returned. |
| 5935 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5936 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5937 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5938 | { |
| 5939 | int end; |
| 5940 | unsigned char c; |
| 5941 | |
| 5942 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5943 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5944 | return ptr; |
| 5945 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5946 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5947 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5948 | while (ptr < len && ptr < bsize) { |
| 5949 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5950 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5951 | if (out->len > end - 2) |
| 5952 | break; |
| 5953 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5954 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5955 | if (out->len > end - 3) |
| 5956 | break; |
| 5957 | out->str[out->len++] = '\\'; |
| 5958 | switch (c) { |
| 5959 | case '\t': c = 't'; break; |
| 5960 | case '\n': c = 'n'; break; |
| 5961 | case '\r': c = 'r'; break; |
| 5962 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5963 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5964 | } |
| 5965 | out->str[out->len++] = c; |
| 5966 | } else { |
| 5967 | if (out->len > end - 5) |
| 5968 | break; |
| 5969 | out->str[out->len++] = '\\'; |
| 5970 | out->str[out->len++] = 'x'; |
| 5971 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5972 | out->str[out->len++] = hextab[c & 0xF]; |
| 5973 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5974 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5975 | /* we had a line break, let's return now */ |
| 5976 | out->str[out->len++] = '\n'; |
| 5977 | *line = ptr; |
| 5978 | return ptr; |
| 5979 | } |
| 5980 | } |
| 5981 | /* we have an incomplete line, we return it as-is */ |
| 5982 | out->str[out->len++] = '\n'; |
| 5983 | return ptr; |
| 5984 | } |
| 5985 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5986 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5987 | * 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] | 5988 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5989 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5990 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5991 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5992 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5993 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5994 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5995 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5996 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5997 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5998 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5999 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6000 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6001 | /* the function had not been called yet, let's prepare the |
| 6002 | * buffer for a response. |
| 6003 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6004 | struct tm tm; |
| 6005 | |
| 6006 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6007 | 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] | 6008 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6009 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6010 | error_snapshot_id); |
| 6011 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6012 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6013 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6014 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6015 | return 0; |
| 6016 | } |
| 6017 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6018 | appctx->ctx.errors.px = proxy; |
| 6019 | appctx->ctx.errors.buf = 0; |
| 6020 | appctx->ctx.errors.bol = 0; |
| 6021 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6022 | } |
| 6023 | |
| 6024 | /* we have two inner loops here, one for the proxy, the other one for |
| 6025 | * the buffer. |
| 6026 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6027 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6028 | struct error_snapshot *es; |
| 6029 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6030 | if (appctx->ctx.errors.buf == 0) |
| 6031 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6032 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6033 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6034 | |
| 6035 | if (!es->when.tv_sec) |
| 6036 | goto next; |
| 6037 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6038 | if (appctx->ctx.errors.iid >= 0 && |
| 6039 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6040 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6041 | goto next; |
| 6042 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6043 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6044 | /* just print headers now */ |
| 6045 | |
| 6046 | char pn[INET6_ADDRSTRLEN]; |
| 6047 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6048 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6049 | |
| 6050 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6051 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6052 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6053 | 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] | 6054 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6055 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6056 | case AF_INET: |
| 6057 | case AF_INET6: |
| 6058 | port = get_host_port(&es->src); |
| 6059 | break; |
| 6060 | default: |
| 6061 | port = 0; |
| 6062 | } |
| 6063 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6064 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6065 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6066 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6067 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6068 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6069 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6070 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6071 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6072 | break; |
| 6073 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6074 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6075 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6076 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6077 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6078 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6079 | break; |
| 6080 | } |
| 6081 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6082 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6083 | ", server %s (#%d), event #%u\n" |
| 6084 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6085 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6086 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6087 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6088 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6089 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6090 | es->ev_id, |
| 6091 | pn, port, es->sid, es->s_flags, |
| 6092 | es->state, es->m_flags, es->t_flags, |
| 6093 | es->m_clen, es->m_blen, |
| 6094 | es->b_flags, es->b_out, es->b_tot, |
| 6095 | es->len, es->b_wrap, es->pos); |
| 6096 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6097 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6098 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6099 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6100 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6101 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6102 | appctx->ctx.errors.ptr = 0; |
| 6103 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6104 | } |
| 6105 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6106 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6107 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6108 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6109 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6110 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6111 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6112 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6113 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6114 | goto next; |
| 6115 | } |
| 6116 | |
| 6117 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6118 | 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] | 6119 | int newptr; |
| 6120 | int newline; |
| 6121 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6122 | newline = appctx->ctx.errors.bol; |
| 6123 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6124 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6125 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6126 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6127 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6128 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6129 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6130 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6131 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6132 | appctx->ctx.errors.ptr = newptr; |
| 6133 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6134 | }; |
| 6135 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6136 | appctx->ctx.errors.bol = 0; |
| 6137 | appctx->ctx.errors.ptr = -1; |
| 6138 | appctx->ctx.errors.buf++; |
| 6139 | if (appctx->ctx.errors.buf > 1) { |
| 6140 | appctx->ctx.errors.buf = 0; |
| 6141 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6142 | } |
| 6143 | } |
| 6144 | |
| 6145 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6146 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6147 | } |
| 6148 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6149 | /* parse the "level" argument on the bind lines */ |
| 6150 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6151 | { |
| 6152 | if (!*args[cur_arg + 1]) { |
| 6153 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6154 | return ERR_ALERT | ERR_FATAL; |
| 6155 | } |
| 6156 | |
| 6157 | if (!strcmp(args[cur_arg+1], "user")) |
| 6158 | conf->level = ACCESS_LVL_USER; |
| 6159 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6160 | conf->level = ACCESS_LVL_OPER; |
| 6161 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6162 | conf->level = ACCESS_LVL_ADMIN; |
| 6163 | else { |
| 6164 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6165 | args[cur_arg], args[cur_arg+1]); |
| 6166 | return ERR_ALERT | ERR_FATAL; |
| 6167 | } |
| 6168 | |
| 6169 | return 0; |
| 6170 | } |
| 6171 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6172 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6173 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6174 | .name = "<STATS>", /* used for logging */ |
| 6175 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6176 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6177 | }; |
| 6178 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6179 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6180 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6181 | .name = "<CLI>", /* used for logging */ |
| 6182 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6183 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6184 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6185 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6186 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6187 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6188 | { 0, NULL, NULL }, |
| 6189 | }}; |
| 6190 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6191 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6192 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6193 | { NULL, NULL, 0 }, |
| 6194 | }}; |
| 6195 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6196 | __attribute__((constructor)) |
| 6197 | static void __dumpstats_module_init(void) |
| 6198 | { |
| 6199 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6200 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6201 | } |
| 6202 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6203 | /* |
| 6204 | * Local variables: |
| 6205 | * c-indent-level: 8 |
| 6206 | * c-basic-offset: 8 |
| 6207 | * End: |
| 6208 | */ |