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 | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 59 | #include <proto/session.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 60 | #include <proto/stream.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 61 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 62 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 63 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 64 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 65 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 66 | #ifdef USE_OPENSSL |
| 67 | #include <proto/ssl_sock.h> |
| 68 | #endif |
| 69 | |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 70 | /* stats socket states */ |
| 71 | enum { |
| 72 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 73 | STAT_CLI_END, /* final state, let's close */ |
| 74 | STAT_CLI_GETREQ, /* wait for a request */ |
| 75 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 76 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 77 | STAT_CLI_PRINT, /* display message in cli->msg */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 78 | 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] | 79 | STAT_CLI_O_INFO, /* dump info */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 80 | STAT_CLI_O_SESS, /* dump streams */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 81 | STAT_CLI_O_ERR, /* dump errors */ |
| 82 | STAT_CLI_O_TAB, /* dump tables */ |
| 83 | STAT_CLI_O_CLR, /* clear tables */ |
| 84 | STAT_CLI_O_SET, /* set entries in tables */ |
| 85 | STAT_CLI_O_STAT, /* dump stats */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 86 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 87 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 88 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 89 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 90 | }; |
| 91 | |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 92 | /* Actions available for the stats admin forms */ |
| 93 | enum { |
| 94 | ST_ADM_ACTION_NONE = 0, |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 95 | |
| 96 | /* enable/disable health checks */ |
| 97 | ST_ADM_ACTION_DHLTH, |
| 98 | ST_ADM_ACTION_EHLTH, |
| 99 | |
| 100 | /* force health check status */ |
| 101 | ST_ADM_ACTION_HRUNN, |
| 102 | ST_ADM_ACTION_HNOLB, |
| 103 | ST_ADM_ACTION_HDOWN, |
| 104 | |
| 105 | /* enable/disable agent checks */ |
| 106 | ST_ADM_ACTION_DAGENT, |
| 107 | ST_ADM_ACTION_EAGENT, |
| 108 | |
| 109 | /* force agent check status */ |
| 110 | ST_ADM_ACTION_ARUNN, |
| 111 | ST_ADM_ACTION_ADOWN, |
| 112 | |
| 113 | /* set admin state */ |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 114 | ST_ADM_ACTION_READY, |
| 115 | ST_ADM_ACTION_DRAIN, |
| 116 | ST_ADM_ACTION_MAINT, |
| 117 | ST_ADM_ACTION_SHUTDOWN, |
| 118 | /* these are the ancient actions, still available for compatibility */ |
| 119 | ST_ADM_ACTION_DISABLE, |
| 120 | ST_ADM_ACTION_ENABLE, |
| 121 | ST_ADM_ACTION_STOP, |
| 122 | ST_ADM_ACTION_START, |
| 123 | }; |
| 124 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 125 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 126 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 127 | 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] | 128 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 129 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 130 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 131 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 132 | 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] | 133 | static int stats_pats_list(struct stream_interface *si); |
| 134 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 135 | static int stats_map_lookup(struct stream_interface *si); |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 136 | static void cli_release_handler(struct stream_interface *si); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 137 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 138 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 139 | * cli_io_handler() |
| 140 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 141 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 142 | * -> stats_dump_info_to_buffer() // "show info" |
| 143 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 144 | * -> stats_dump_csv_header() |
| 145 | * -> stats_dump_proxy_to_buffer() |
| 146 | * -> stats_dump_fe_stats() |
| 147 | * -> stats_dump_li_stats() |
| 148 | * -> stats_dump_sv_stats() |
| 149 | * -> stats_dump_be_stats() |
| 150 | * |
| 151 | * http_stats_io_handler() |
| 152 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 153 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 154 | * -> stats_dump_html_head() // emits the HTML headers |
| 155 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 156 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 157 | * -> stats_dump_html_px_hdr() |
| 158 | * -> stats_dump_fe_stats() |
| 159 | * -> stats_dump_li_stats() |
| 160 | * -> stats_dump_sv_stats() |
| 161 | * -> stats_dump_be_stats() |
| 162 | * -> stats_dump_html_px_end() |
| 163 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 164 | */ |
| 165 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 166 | static struct si_applet cli_applet; |
| 167 | |
| 168 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 169 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 170 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 171 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 172 | " help : this message\n" |
| 173 | " prompt : toggle interactive mode with prompt\n" |
| 174 | " quit : disconnect\n" |
| 175 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 176 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 177 | " show stat : report counters for each proxy and server\n" |
| 178 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 179 | " 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] | 180 | " 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] | 181 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 182 | " set weight : change a server's weight\n" |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 183 | " set server : change a server's state or weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 184 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 185 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 186 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 187 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 188 | " disable : put a server or frontend in maintenance mode\n" |
| 189 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 190 | " 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] | 191 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 192 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 193 | " add acl : add acl entry\n" |
| 194 | " del acl : delete acl entry\n" |
| 195 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 196 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 197 | " get map : reports the keys and values matching a sample for a map\n" |
| 198 | " set map : modify map entry\n" |
| 199 | " add map : add map entry\n" |
| 200 | " del map : delete map entry\n" |
| 201 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 202 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 203 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 204 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 205 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 206 | "Permission denied\n" |
| 207 | ""; |
| 208 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 209 | /* data transmission states for the stats responses */ |
| 210 | enum { |
| 211 | STAT_ST_INIT = 0, |
| 212 | STAT_ST_HEAD, |
| 213 | STAT_ST_INFO, |
| 214 | STAT_ST_LIST, |
| 215 | STAT_ST_END, |
| 216 | STAT_ST_FIN, |
| 217 | }; |
| 218 | |
| 219 | /* data transmission states for the stats responses inside a proxy */ |
| 220 | enum { |
| 221 | STAT_PX_ST_INIT = 0, |
| 222 | STAT_PX_ST_TH, |
| 223 | STAT_PX_ST_FE, |
| 224 | STAT_PX_ST_LI, |
| 225 | STAT_PX_ST_SV, |
| 226 | STAT_PX_ST_BE, |
| 227 | STAT_PX_ST_END, |
| 228 | STAT_PX_ST_FIN, |
| 229 | }; |
| 230 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 231 | extern const char *stat_status_codes[]; |
| 232 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 233 | /* allocate a new stats frontend named <name>, and return it |
| 234 | * (or NULL in case of lack of memory). |
| 235 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 236 | 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] | 237 | { |
| 238 | struct proxy *fe; |
| 239 | |
| 240 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 241 | if (!fe) |
| 242 | return NULL; |
| 243 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 244 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 245 | fe->next = proxy; |
| 246 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 247 | fe->last_change = now.tv_sec; |
| 248 | fe->id = strdup("GLOBAL"); |
| 249 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 250 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 251 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 252 | fe->conf.file = strdup(file); |
| 253 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 254 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 255 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 256 | |
| 257 | /* the stats frontend is the only one able to assign ID #0 */ |
| 258 | fe->conf.id.key = fe->uuid = 0; |
| 259 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 260 | return fe; |
| 261 | } |
| 262 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 263 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 264 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 265 | * error message into the <err> buffer which will be preallocated. The trailing |
| 266 | * '\n' must not be written. The function must be called with <args> pointing to |
| 267 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 268 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 269 | 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] | 270 | struct proxy *defpx, const char *file, int line, |
| 271 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 272 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 273 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 274 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 275 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 276 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 277 | int cur_arg; |
| 278 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 279 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 280 | 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] | 281 | return -1; |
| 282 | } |
| 283 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 284 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 285 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 286 | 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] | 287 | return -1; |
| 288 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 291 | 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] | 292 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 293 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 294 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 295 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 296 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 297 | return -1; |
| 298 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 299 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 300 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 301 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 302 | static int bind_dumped; |
| 303 | struct bind_kw *kw; |
| 304 | |
| 305 | kw = bind_find_kw(args[cur_arg]); |
| 306 | if (kw) { |
| 307 | if (!kw->parse) { |
| 308 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 309 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 310 | return -1; |
| 311 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 312 | |
| 313 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 314 | if (err && *err) |
| 315 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 316 | else |
| 317 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 318 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 319 | return -1; |
| 320 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 321 | |
| 322 | cur_arg += 1 + kw->skip; |
| 323 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 324 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 325 | |
| 326 | if (!bind_dumped) { |
| 327 | bind_dump_kws(err); |
| 328 | indent_msg(err, 4); |
| 329 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 330 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 331 | |
| 332 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 333 | args[0], args[1], args[cur_arg], |
| 334 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 335 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 336 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 337 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 338 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 339 | l->maxconn = global.stats_fe->maxconn; |
| 340 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 341 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 342 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 343 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 344 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 345 | l->nice = -64; /* we want to boost priority for local stats */ |
| 346 | global.maxsock += l->maxconn; |
| 347 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 348 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 349 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 350 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 351 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 352 | |
| 353 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 354 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 355 | return -1; |
| 356 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 357 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 358 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 359 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 360 | return -1; |
| 361 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 362 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 363 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 364 | 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] | 365 | return -1; |
| 366 | } |
| 367 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 368 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 369 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 370 | else if (!strcmp(args[1], "maxconn")) { |
| 371 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 372 | |
| 373 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 374 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 375 | return -1; |
| 376 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 377 | |
| 378 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 379 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 380 | 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] | 381 | return -1; |
| 382 | } |
| 383 | } |
| 384 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 385 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 386 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 387 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 388 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 389 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 390 | if (!global.stats_fe) { |
| 391 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 392 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 393 | return -1; |
| 394 | } |
| 395 | } |
| 396 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 397 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 398 | unsigned int low, high; |
| 399 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 400 | if (strcmp(args[cur_arg], "all") == 0) { |
| 401 | set = 0; |
| 402 | break; |
| 403 | } |
| 404 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 405 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 406 | } |
| 407 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 408 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 409 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 410 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 411 | char *dash = strchr(args[cur_arg], '-'); |
| 412 | |
| 413 | low = high = str2uic(args[cur_arg]); |
| 414 | if (dash) |
| 415 | high = str2uic(dash + 1); |
| 416 | |
| 417 | if (high < low) { |
| 418 | unsigned int swap = low; |
| 419 | low = high; |
| 420 | high = swap; |
| 421 | } |
| 422 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 423 | if (low < 1 || high > LONGBITS) { |
| 424 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 425 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 426 | return -1; |
| 427 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 428 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 429 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 430 | } |
| 431 | else { |
| 432 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 433 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 434 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 435 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 436 | } |
| 437 | cur_arg++; |
| 438 | } |
| 439 | global.stats_fe->bind_proc = set; |
| 440 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 441 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 442 | 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] | 443 | return -1; |
| 444 | } |
| 445 | return 0; |
| 446 | } |
| 447 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 448 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 449 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 450 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 451 | * 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] | 452 | */ |
| 453 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 454 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 455 | chunk_appendf(&trash, |
| 456 | "# pxname,svname," |
| 457 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 458 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 459 | "bin,bout," |
| 460 | "dreq,dresp," |
| 461 | "ereq,econ,eresp," |
| 462 | "wretr,wredis," |
| 463 | "status,weight,act,bck," |
| 464 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 465 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 466 | "rate,rate_lim,rate_max," |
| 467 | "check_status,check_code,check_duration," |
| 468 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 469 | "req_rate,req_rate_max,req_tot," |
| 470 | "cli_abrt,srv_abrt," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 471 | "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] | 472 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 473 | } |
| 474 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 475 | /* print a string of text buffer to <out>. The format is : |
| 476 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 477 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 478 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 479 | */ |
| 480 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 481 | { |
| 482 | unsigned char c; |
| 483 | int ptr = 0; |
| 484 | |
| 485 | while (buf[ptr] && ptr < bsize) { |
| 486 | c = buf[ptr]; |
| 487 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 488 | if (out->len > out->size - 1) |
| 489 | break; |
| 490 | out->str[out->len++] = c; |
| 491 | } |
| 492 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 493 | if (out->len > out->size - 2) |
| 494 | break; |
| 495 | out->str[out->len++] = '\\'; |
| 496 | switch (c) { |
| 497 | case ' ': c = ' '; break; |
| 498 | case '\t': c = 't'; break; |
| 499 | case '\n': c = 'n'; break; |
| 500 | case '\r': c = 'r'; break; |
| 501 | case '\e': c = 'e'; break; |
| 502 | case '\\': c = '\\'; break; |
| 503 | } |
| 504 | out->str[out->len++] = c; |
| 505 | } |
| 506 | else { |
| 507 | if (out->len > out->size - 4) |
| 508 | break; |
| 509 | out->str[out->len++] = '\\'; |
| 510 | out->str[out->len++] = 'x'; |
| 511 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 512 | out->str[out->len++] = hextab[c & 0xF]; |
| 513 | } |
| 514 | ptr++; |
| 515 | } |
| 516 | |
| 517 | return ptr; |
| 518 | } |
| 519 | |
| 520 | /* print a buffer in hexa. |
| 521 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 522 | */ |
| 523 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 524 | { |
| 525 | unsigned char c; |
| 526 | int ptr = 0; |
| 527 | |
| 528 | while (ptr < bsize) { |
| 529 | c = buf[ptr]; |
| 530 | |
| 531 | if (out->len > out->size - 2) |
| 532 | break; |
| 533 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 534 | out->str[out->len++] = hextab[c & 0xF]; |
| 535 | |
| 536 | ptr++; |
| 537 | } |
| 538 | return ptr; |
| 539 | } |
| 540 | |
| 541 | /* Dump the status of a table to a stream interface's |
| 542 | * read buffer. It returns 0 if the output buffer is full |
| 543 | * and needs to be called again, otherwise non-zero. |
| 544 | */ |
| 545 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 546 | struct proxy *proxy, struct proxy *target) |
| 547 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 548 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 549 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 550 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 551 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 552 | |
| 553 | /* any other information should be dumped here */ |
| 554 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 555 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 556 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 557 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 558 | if (bi_putchk(si_ic(si), msg) == -1) { |
| 559 | si->flags |= SI_FL_WAIT_ROOM; |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 560 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 561 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 562 | |
| 563 | return 1; |
| 564 | } |
| 565 | |
| 566 | /* Dump the a table entry to a stream interface's |
| 567 | * read buffer. It returns 0 if the output buffer is full |
| 568 | * and needs to be called again, otherwise non-zero. |
| 569 | */ |
| 570 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 571 | struct proxy *proxy, struct stksess *entry) |
| 572 | { |
| 573 | int dt; |
| 574 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 575 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 576 | |
| 577 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 578 | char addr[INET_ADDRSTRLEN]; |
| 579 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 580 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 581 | } |
| 582 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 583 | char addr[INET6_ADDRSTRLEN]; |
| 584 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 585 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 586 | } |
| 587 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 588 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 589 | } |
| 590 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 591 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 592 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 593 | } |
| 594 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 595 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 596 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 597 | } |
| 598 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 599 | 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] | 600 | |
| 601 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 602 | void *ptr; |
| 603 | |
| 604 | if (proxy->table.data_ofs[dt] == 0) |
| 605 | continue; |
| 606 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 607 | 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] | 608 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 609 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 610 | |
| 611 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 612 | switch (stktable_data_types[dt].std_type) { |
| 613 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 614 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 615 | break; |
| 616 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 617 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 618 | break; |
| 619 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 620 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 621 | break; |
| 622 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 623 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 624 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 625 | proxy->table.data_arg[dt].u)); |
| 626 | break; |
| 627 | } |
| 628 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 629 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 630 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 631 | if (bi_putchk(si_ic(si), msg) == -1) { |
| 632 | si->flags |= SI_FL_WAIT_ROOM; |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 633 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 634 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 635 | |
| 636 | return 1; |
| 637 | } |
| 638 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 639 | 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] | 640 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 641 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 642 | struct appctx *appctx = __objt_appctx(si->end); |
| 643 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 644 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 645 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 646 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 647 | long long value; |
| 648 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 649 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 650 | void *ptr; |
| 651 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 652 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 653 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 654 | |
| 655 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 656 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 657 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 658 | return; |
| 659 | } |
| 660 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 661 | switch (px->table.type) { |
| 662 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 663 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 664 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 665 | break; |
| 666 | case STKTABLE_TYPE_IPV6: |
| 667 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 668 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 669 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 670 | case STKTABLE_TYPE_INTEGER: |
| 671 | { |
| 672 | char *endptr; |
| 673 | unsigned long val; |
| 674 | errno = 0; |
| 675 | val = strtoul(args[4], &endptr, 10); |
| 676 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 677 | (errno != 0 && val == 0) || endptr == args[4] || |
| 678 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 679 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 680 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 681 | return; |
| 682 | } |
| 683 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 684 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 685 | break; |
| 686 | } |
| 687 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 688 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 689 | static_table_key->key = args[4]; |
| 690 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 691 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 692 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 693 | switch (action) { |
| 694 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 695 | 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] | 696 | break; |
| 697 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 698 | 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] | 699 | break; |
| 700 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 701 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 702 | break; |
| 703 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 704 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 705 | return; |
| 706 | } |
| 707 | |
| 708 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 709 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 710 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 711 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 715 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 716 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 717 | switch (action) { |
| 718 | case STAT_CLI_O_TAB: |
| 719 | if (!ts) |
| 720 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 721 | chunk_reset(&trash); |
| 722 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 723 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 724 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 725 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 726 | |
| 727 | case STAT_CLI_O_CLR: |
| 728 | if (!ts) |
| 729 | return; |
| 730 | if (ts->ref_cnt) { |
| 731 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 732 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 733 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 734 | return; |
| 735 | } |
| 736 | stksess_kill(&px->table, ts); |
| 737 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 738 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 739 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 740 | if (ts) |
| 741 | stktable_touch(&px->table, ts, 1); |
| 742 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 743 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 744 | if (!ts) { |
| 745 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 746 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 747 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 748 | return; |
| 749 | } |
| 750 | stktable_store(&px->table, ts, 1); |
| 751 | } |
| 752 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 753 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 754 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 755 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 756 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 757 | return; |
| 758 | } |
| 759 | |
| 760 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 761 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 762 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 763 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 764 | return; |
| 765 | } |
| 766 | |
| 767 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 768 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 769 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 770 | return; |
| 771 | } |
| 772 | |
| 773 | 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] | 774 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 775 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 776 | return; |
| 777 | } |
| 778 | |
| 779 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 780 | |
| 781 | switch (stktable_data_types[data_type].std_type) { |
| 782 | case STD_T_SINT: |
| 783 | stktable_data_cast(ptr, std_t_sint) = value; |
| 784 | break; |
| 785 | case STD_T_UINT: |
| 786 | stktable_data_cast(ptr, std_t_uint) = value; |
| 787 | break; |
| 788 | case STD_T_ULL: |
| 789 | stktable_data_cast(ptr, std_t_ull) = value; |
| 790 | break; |
| 791 | case STD_T_FRQP: |
| 792 | /* We set both the current and previous values. That way |
| 793 | * the reported frequency is stable during all the period |
| 794 | * then slowly fades out. This allows external tools to |
| 795 | * push measures without having to update them too often. |
| 796 | */ |
| 797 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 798 | frqp->curr_tick = now_ms; |
| 799 | frqp->prev_ctr = 0; |
| 800 | frqp->curr_ctr = value; |
| 801 | break; |
| 802 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 803 | } |
| 804 | break; |
| 805 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 806 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 807 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 808 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 809 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 810 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 811 | } |
| 812 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 813 | 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] | 814 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 815 | struct appctx *appctx = __objt_appctx(si->end); |
| 816 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 817 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 818 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 819 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 820 | return; |
| 821 | } |
| 822 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 823 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 824 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 825 | if (appctx->ctx.table.data_type < 0) { |
| 826 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 827 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 828 | return; |
| 829 | } |
| 830 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 831 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 832 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 833 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 834 | return; |
| 835 | } |
| 836 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 837 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 838 | if (appctx->ctx.table.data_op < 0) { |
| 839 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 840 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 841 | return; |
| 842 | } |
| 843 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 844 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 845 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 846 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 847 | return; |
| 848 | } |
| 849 | } |
| 850 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 851 | 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] | 852 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 853 | struct appctx *appctx = __objt_appctx(si->end); |
| 854 | |
| 855 | appctx->ctx.table.data_type = -1; |
| 856 | appctx->st2 = STAT_ST_INIT; |
| 857 | appctx->ctx.table.target = NULL; |
| 858 | appctx->ctx.table.proxy = NULL; |
| 859 | appctx->ctx.table.entry = NULL; |
| 860 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 861 | |
| 862 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 863 | appctx->ctx.table.target = find_stktable(args[2]); |
| 864 | if (!appctx->ctx.table.target) { |
| 865 | appctx->ctx.cli.msg = "No such table\n"; |
| 866 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 867 | return; |
| 868 | } |
| 869 | } |
| 870 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 871 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 872 | goto err_args; |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 877 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 878 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 879 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 880 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 881 | goto err_args; |
| 882 | |
| 883 | return; |
| 884 | |
| 885 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 886 | switch (action) { |
| 887 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 888 | 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] | 889 | break; |
| 890 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 891 | 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] | 892 | break; |
| 893 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 894 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 895 | break; |
| 896 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 897 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 898 | } |
| 899 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 900 | /* 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] | 901 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 902 | * level to be admin. |
| 903 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 904 | 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] | 905 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 906 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 907 | struct proxy *px; |
| 908 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 909 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 910 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 911 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 912 | return NULL; |
| 913 | } |
| 914 | |
| 915 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 916 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 917 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 918 | return NULL; |
| 919 | } |
| 920 | |
| 921 | px = findproxy(arg, PR_CAP_FE); |
| 922 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 923 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 924 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 925 | return NULL; |
| 926 | } |
| 927 | return px; |
| 928 | } |
| 929 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 930 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 931 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 932 | * 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] | 933 | * the <arg> is modified to remove the '/'. |
| 934 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 935 | 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] | 936 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 937 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 938 | struct proxy *px; |
| 939 | struct server *sv; |
| 940 | char *line; |
| 941 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 942 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 943 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 944 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 945 | return NULL; |
| 946 | } |
| 947 | |
| 948 | /* split "backend/server" and make <line> point to server */ |
| 949 | for (line = arg; *line; line++) |
| 950 | if (*line == '/') { |
| 951 | *line++ = '\0'; |
| 952 | break; |
| 953 | } |
| 954 | |
| 955 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 956 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 957 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 958 | return NULL; |
| 959 | } |
| 960 | |
| 961 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 962 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 963 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 964 | return NULL; |
| 965 | } |
| 966 | |
| 967 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 968 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 969 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 970 | return NULL; |
| 971 | } |
| 972 | |
| 973 | return sv; |
| 974 | } |
| 975 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 976 | /* This function is used with map and acl management. It permits to browse |
| 977 | * each reference. The variable <getnext> must contain the current node, |
| 978 | * <end> point to the root node and the <flags> permit to filter required |
| 979 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 980 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 981 | static inline |
| 982 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 983 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 984 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 985 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 986 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 987 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 988 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 989 | /* Get next list entry. */ |
| 990 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 991 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 992 | /* If the entry is the last of the list, return NULL. */ |
| 993 | if (&ref->list == end) |
| 994 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 995 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 996 | /* If the entry match the flag, return it. */ |
| 997 | if (ref->flags & flags) |
| 998 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1002 | static inline |
| 1003 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1004 | { |
| 1005 | int id; |
| 1006 | char *error; |
| 1007 | |
| 1008 | /* If the reference starts by a '#', this is numeric id. */ |
| 1009 | if (reference[0] == '#') { |
| 1010 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1011 | id = strtol(reference + 1, &error, 10); |
| 1012 | if (*error != '\0') |
| 1013 | return NULL; |
| 1014 | |
| 1015 | /* Perform the unique id lookup. */ |
| 1016 | return pat_ref_lookupid(id); |
| 1017 | } |
| 1018 | |
| 1019 | /* Perform the string lookup. */ |
| 1020 | return pat_ref_lookup(reference); |
| 1021 | } |
| 1022 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1023 | /* This function is used with map and acl management. It permits to browse |
| 1024 | * each reference. |
| 1025 | */ |
| 1026 | static inline |
| 1027 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1028 | { |
| 1029 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1030 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1031 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1032 | return NULL; |
| 1033 | return expr; |
| 1034 | } |
| 1035 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1036 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1037 | * 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] | 1038 | * 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] | 1039 | * designating the function which will have to process the request, which can |
| 1040 | * 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] | 1041 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1042 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1043 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1044 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1045 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1046 | char *args[MAX_STATS_ARGS + 1]; |
| 1047 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1048 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1049 | |
| 1050 | while (isspace((unsigned char)*line)) |
| 1051 | line++; |
| 1052 | |
| 1053 | arg = 0; |
| 1054 | args[arg] = line; |
| 1055 | |
| 1056 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1057 | if (*line == '\\') { |
| 1058 | line++; |
| 1059 | if (*line == '\0') |
| 1060 | break; |
| 1061 | } |
| 1062 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1063 | *line++ = '\0'; |
| 1064 | |
| 1065 | while (isspace((unsigned char)*line)) |
| 1066 | line++; |
| 1067 | |
| 1068 | args[++arg] = line; |
| 1069 | continue; |
| 1070 | } |
| 1071 | |
| 1072 | line++; |
| 1073 | } |
| 1074 | |
| 1075 | while (++arg <= MAX_STATS_ARGS) |
| 1076 | args[arg] = line; |
| 1077 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1078 | /* remove \ */ |
| 1079 | arg = 0; |
| 1080 | while (*args[arg] != '\0') { |
| 1081 | j = 0; |
| 1082 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1083 | if (args[arg][i] == '\\') |
| 1084 | continue; |
| 1085 | args[arg][j] = args[arg][i]; |
| 1086 | j++; |
| 1087 | } |
| 1088 | args[arg][j] = '\0'; |
| 1089 | arg++; |
| 1090 | } |
| 1091 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1092 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1093 | if (strcmp(args[0], "show") == 0) { |
| 1094 | if (strcmp(args[1], "stat") == 0) { |
| 1095 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1096 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1097 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1098 | appctx->ctx.stats.type = atoi(args[3]); |
| 1099 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1100 | } |
| 1101 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1102 | appctx->st2 = STAT_ST_INIT; |
| 1103 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1104 | } |
| 1105 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1106 | appctx->st2 = STAT_ST_INIT; |
| 1107 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1108 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1109 | else if (strcmp(args[1], "pools") == 0) { |
| 1110 | appctx->st2 = STAT_ST_INIT; |
| 1111 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1112 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1113 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1114 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1115 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1116 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1117 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1118 | return 1; |
| 1119 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1120 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1121 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1122 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1123 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1124 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1125 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1126 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1127 | appctx->ctx.sess.pos = 0; |
| 1128 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1129 | } |
| 1130 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1131 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1132 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1133 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1134 | return 1; |
| 1135 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1136 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1137 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1138 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1139 | appctx->ctx.errors.iid = -1; |
| 1140 | appctx->ctx.errors.px = NULL; |
| 1141 | appctx->st2 = STAT_ST_INIT; |
| 1142 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1143 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1144 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1145 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1146 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1147 | else if (strcmp(args[1], "map") == 0 || |
| 1148 | strcmp(args[1], "acl") == 0) { |
| 1149 | |
| 1150 | /* Set ACL or MAP flags. */ |
| 1151 | if (args[1][0] == 'm') |
| 1152 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1153 | else |
| 1154 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1155 | |
| 1156 | /* no parameter: display all map avalaible */ |
| 1157 | if (!*args[2]) { |
| 1158 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1159 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1160 | return 1; |
| 1161 | } |
| 1162 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1163 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1164 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1165 | if (!appctx->ctx.map.ref || |
| 1166 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1167 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1168 | 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] | 1169 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1170 | 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] | 1171 | appctx->st0 = STAT_CLI_PRINT; |
| 1172 | return 1; |
| 1173 | } |
| 1174 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1175 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1176 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1177 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1178 | return 0; |
| 1179 | } |
| 1180 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1181 | else if (strcmp(args[0], "clear") == 0) { |
| 1182 | if (strcmp(args[1], "counters") == 0) { |
| 1183 | struct proxy *px; |
| 1184 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1185 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1186 | int clrall = 0; |
| 1187 | |
| 1188 | if (strcmp(args[2], "all") == 0) |
| 1189 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1190 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1191 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1192 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1193 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1194 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1195 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1196 | return 1; |
| 1197 | } |
| 1198 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1199 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1200 | if (clrall) { |
| 1201 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1202 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1203 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1204 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1205 | px->be_counters.conn_max = 0; |
| 1206 | px->be_counters.p.http.rps_max = 0; |
| 1207 | px->be_counters.sps_max = 0; |
| 1208 | px->be_counters.cps_max = 0; |
| 1209 | px->be_counters.nbpend_max = 0; |
| 1210 | |
| 1211 | px->fe_counters.conn_max = 0; |
| 1212 | px->fe_counters.p.http.rps_max = 0; |
| 1213 | px->fe_counters.sps_max = 0; |
| 1214 | px->fe_counters.cps_max = 0; |
| 1215 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1216 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1217 | |
| 1218 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1219 | if (clrall) |
| 1220 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1221 | else { |
| 1222 | sv->counters.cur_sess_max = 0; |
| 1223 | sv->counters.nbpend_max = 0; |
| 1224 | sv->counters.sps_max = 0; |
| 1225 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1226 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1227 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1228 | if (li->counters) { |
| 1229 | if (clrall) |
| 1230 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1231 | else |
| 1232 | li->counters->conn_max = 0; |
| 1233 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1234 | } |
| 1235 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1236 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1237 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1238 | return 1; |
| 1239 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1240 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1241 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1242 | /* end of processing */ |
| 1243 | return 1; |
| 1244 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1245 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1246 | /* Set ACL or MAP flags. */ |
| 1247 | if (args[1][0] == 'm') |
| 1248 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1249 | else |
| 1250 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1251 | |
| 1252 | /* no parameter */ |
| 1253 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1254 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1255 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1256 | else |
| 1257 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1258 | appctx->st0 = STAT_CLI_PRINT; |
| 1259 | return 1; |
| 1260 | } |
| 1261 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1262 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1263 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1264 | if (!appctx->ctx.map.ref || |
| 1265 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1266 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1267 | 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] | 1268 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1269 | 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] | 1270 | appctx->st0 = STAT_CLI_PRINT; |
| 1271 | return 1; |
| 1272 | } |
| 1273 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1274 | /* Clear all. */ |
| 1275 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1276 | |
| 1277 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1278 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1279 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1280 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1281 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1282 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1283 | return 0; |
| 1284 | } |
| 1285 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1286 | else if (strcmp(args[0], "get") == 0) { |
| 1287 | if (strcmp(args[1], "weight") == 0) { |
| 1288 | struct proxy *px; |
| 1289 | struct server *sv; |
| 1290 | |
| 1291 | /* split "backend/server" and make <line> point to server */ |
| 1292 | for (line = args[2]; *line; line++) |
| 1293 | if (*line == '/') { |
| 1294 | *line++ = '\0'; |
| 1295 | break; |
| 1296 | } |
| 1297 | |
| 1298 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1299 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1300 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1301 | return 1; |
| 1302 | } |
| 1303 | |
| 1304 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1305 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1306 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1307 | return 1; |
| 1308 | } |
| 1309 | |
| 1310 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1311 | 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] | 1312 | if (bi_putstr(si_ic(si), trash.str) == -1) |
| 1313 | si->flags |= SI_FL_WAIT_ROOM; |
| 1314 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1315 | return 1; |
| 1316 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1317 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1318 | /* Set flags. */ |
| 1319 | if (args[1][0] == 'm') |
| 1320 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1321 | else |
| 1322 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1323 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1324 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1325 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1326 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1327 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1328 | else |
| 1329 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1330 | appctx->st0 = STAT_CLI_PRINT; |
| 1331 | return 1; |
| 1332 | } |
| 1333 | |
| 1334 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1335 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1336 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1337 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1338 | 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] | 1339 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1340 | 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] | 1341 | appctx->st0 = STAT_CLI_PRINT; |
| 1342 | return 1; |
| 1343 | } |
| 1344 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1345 | /* copy input string. The string must be allocated because |
| 1346 | * it may be used over multiple iterations. It's released |
| 1347 | * at the end and upon abort anyway. |
| 1348 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1349 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1350 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1351 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1352 | if (!appctx->ctx.map.chunk.str) { |
| 1353 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1354 | appctx->st0 = STAT_CLI_PRINT; |
| 1355 | return 1; |
| 1356 | } |
| 1357 | |
| 1358 | /* prepare response */ |
| 1359 | appctx->st2 = STAT_ST_INIT; |
| 1360 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1361 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1362 | else { /* not "get weight" */ |
| 1363 | return 0; |
| 1364 | } |
| 1365 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1366 | else if (strcmp(args[0], "set") == 0) { |
| 1367 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1368 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1369 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1370 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1371 | sv = expect_server_admin(s, si, args[2]); |
| 1372 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1373 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1374 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1375 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1376 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1377 | appctx->ctx.cli.msg = warning; |
| 1378 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1379 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1380 | return 1; |
| 1381 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1382 | else if (strcmp(args[1], "server") == 0) { |
| 1383 | struct server *sv; |
| 1384 | const char *warning; |
| 1385 | |
| 1386 | sv = expect_server_admin(s, si, args[2]); |
| 1387 | if (!sv) |
| 1388 | return 1; |
| 1389 | |
| 1390 | if (strcmp(args[3], "weight") == 0) { |
| 1391 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1392 | if (warning) { |
| 1393 | appctx->ctx.cli.msg = warning; |
| 1394 | appctx->st0 = STAT_CLI_PRINT; |
| 1395 | } |
| 1396 | } |
| 1397 | else if (strcmp(args[3], "state") == 0) { |
| 1398 | if (strcmp(args[4], "ready") == 0) |
| 1399 | srv_adm_set_ready(sv); |
| 1400 | else if (strcmp(args[4], "drain") == 0) |
| 1401 | srv_adm_set_drain(sv); |
| 1402 | else if (strcmp(args[4], "maint") == 0) |
| 1403 | srv_adm_set_maint(sv); |
| 1404 | else { |
| 1405 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1406 | appctx->st0 = STAT_CLI_PRINT; |
| 1407 | } |
| 1408 | } |
| 1409 | else if (strcmp(args[3], "health") == 0) { |
| 1410 | if (sv->track) { |
| 1411 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1412 | appctx->st0 = STAT_CLI_PRINT; |
| 1413 | } |
| 1414 | else if (strcmp(args[4], "up") == 0) { |
| 1415 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1416 | srv_set_running(sv, "changed from CLI"); |
| 1417 | } |
| 1418 | else if (strcmp(args[4], "stopping") == 0) { |
| 1419 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1420 | srv_set_stopping(sv, "changed from CLI"); |
| 1421 | } |
| 1422 | else if (strcmp(args[4], "down") == 0) { |
| 1423 | sv->check.health = 0; |
| 1424 | srv_set_stopped(sv, "changed from CLI"); |
| 1425 | } |
| 1426 | else { |
| 1427 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1428 | appctx->st0 = STAT_CLI_PRINT; |
| 1429 | } |
| 1430 | } |
| 1431 | else if (strcmp(args[3], "agent") == 0) { |
| 1432 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1433 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1434 | appctx->st0 = STAT_CLI_PRINT; |
| 1435 | } |
| 1436 | else if (strcmp(args[4], "up") == 0) { |
| 1437 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1438 | srv_set_running(sv, "changed from CLI"); |
| 1439 | } |
| 1440 | else if (strcmp(args[4], "down") == 0) { |
| 1441 | sv->agent.health = 0; |
| 1442 | srv_set_stopped(sv, "changed from CLI"); |
| 1443 | } |
| 1444 | else { |
| 1445 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1446 | appctx->st0 = STAT_CLI_PRINT; |
| 1447 | } |
| 1448 | } |
| 1449 | else { |
| 1450 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state' and 'weight'.\n"; |
| 1451 | appctx->st0 = STAT_CLI_PRINT; |
| 1452 | } |
| 1453 | return 1; |
| 1454 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1455 | else if (strcmp(args[1], "timeout") == 0) { |
| 1456 | if (strcmp(args[2], "cli") == 0) { |
| 1457 | unsigned timeout; |
| 1458 | const char *res; |
| 1459 | |
| 1460 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1461 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1462 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1463 | return 1; |
| 1464 | } |
| 1465 | |
| 1466 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1467 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1468 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1469 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1470 | return 1; |
| 1471 | } |
| 1472 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1473 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1474 | return 1; |
| 1475 | } |
| 1476 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1477 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1478 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1479 | return 1; |
| 1480 | } |
| 1481 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1482 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1483 | if (strcmp(args[2], "frontend") == 0) { |
| 1484 | struct proxy *px; |
| 1485 | struct listener *l; |
| 1486 | int v; |
| 1487 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1488 | px = expect_frontend_admin(s, si, args[3]); |
| 1489 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1490 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1491 | |
| 1492 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1493 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1494 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1495 | return 1; |
| 1496 | } |
| 1497 | |
| 1498 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1499 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1500 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1501 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1502 | return 1; |
| 1503 | } |
| 1504 | |
| 1505 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1506 | * its listeners. The blocked ones will be dequeued. |
| 1507 | */ |
| 1508 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1509 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1510 | l->maxconn = v; |
| 1511 | if (l->state == LI_FULL) |
| 1512 | resume_listener(l); |
| 1513 | } |
| 1514 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1515 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1516 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1517 | |
| 1518 | return 1; |
| 1519 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1520 | else if (strcmp(args[2], "global") == 0) { |
| 1521 | int v; |
| 1522 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1523 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1524 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1525 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1526 | return 1; |
| 1527 | } |
| 1528 | |
| 1529 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1530 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1531 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1532 | return 1; |
| 1533 | } |
| 1534 | |
| 1535 | v = atoi(args[3]); |
| 1536 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1537 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1538 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1539 | return 1; |
| 1540 | } |
| 1541 | |
| 1542 | /* check for unlimited values */ |
| 1543 | if (v <= 0) |
| 1544 | v = global.hardmaxconn; |
| 1545 | |
| 1546 | global.maxconn = v; |
| 1547 | |
| 1548 | /* Dequeues all of the listeners waiting for a resource */ |
| 1549 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1550 | dequeue_all_listeners(&global_listener_queue); |
| 1551 | |
| 1552 | return 1; |
| 1553 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1554 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1555 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1556 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1557 | return 1; |
| 1558 | } |
| 1559 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1560 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1561 | if (strcmp(args[2], "connections") == 0) { |
| 1562 | if (strcmp(args[3], "global") == 0) { |
| 1563 | int v; |
| 1564 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1565 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1566 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1567 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1568 | return 1; |
| 1569 | } |
| 1570 | |
| 1571 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1572 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1573 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1574 | return 1; |
| 1575 | } |
| 1576 | |
| 1577 | v = atoi(args[4]); |
| 1578 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1579 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1580 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1581 | return 1; |
| 1582 | } |
| 1583 | |
| 1584 | global.cps_lim = v; |
| 1585 | |
| 1586 | /* Dequeues all of the listeners waiting for a resource */ |
| 1587 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1588 | dequeue_all_listeners(&global_listener_queue); |
| 1589 | |
| 1590 | return 1; |
| 1591 | } |
| 1592 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1593 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1594 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1595 | return 1; |
| 1596 | } |
| 1597 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1598 | else if (strcmp(args[2], "sessions") == 0) { |
| 1599 | if (strcmp(args[3], "global") == 0) { |
| 1600 | int v; |
| 1601 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1602 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1603 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1604 | appctx->st0 = STAT_CLI_PRINT; |
| 1605 | return 1; |
| 1606 | } |
| 1607 | |
| 1608 | if (!*args[4]) { |
| 1609 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1610 | appctx->st0 = STAT_CLI_PRINT; |
| 1611 | return 1; |
| 1612 | } |
| 1613 | |
| 1614 | v = atoi(args[4]); |
| 1615 | if (v < 0) { |
| 1616 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1617 | appctx->st0 = STAT_CLI_PRINT; |
| 1618 | return 1; |
| 1619 | } |
| 1620 | |
| 1621 | global.sps_lim = v; |
| 1622 | |
| 1623 | /* Dequeues all of the listeners waiting for a resource */ |
| 1624 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1625 | dequeue_all_listeners(&global_listener_queue); |
| 1626 | |
| 1627 | return 1; |
| 1628 | } |
| 1629 | else { |
| 1630 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1631 | appctx->st0 = STAT_CLI_PRINT; |
| 1632 | return 1; |
| 1633 | } |
| 1634 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1635 | #ifdef USE_OPENSSL |
| 1636 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1637 | if (strcmp(args[3], "global") == 0) { |
| 1638 | int v; |
| 1639 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1640 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1641 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1642 | appctx->st0 = STAT_CLI_PRINT; |
| 1643 | return 1; |
| 1644 | } |
| 1645 | |
| 1646 | if (!*args[4]) { |
| 1647 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1648 | appctx->st0 = STAT_CLI_PRINT; |
| 1649 | return 1; |
| 1650 | } |
| 1651 | |
| 1652 | v = atoi(args[4]); |
| 1653 | if (v < 0) { |
| 1654 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1655 | appctx->st0 = STAT_CLI_PRINT; |
| 1656 | return 1; |
| 1657 | } |
| 1658 | |
| 1659 | global.ssl_lim = v; |
| 1660 | |
| 1661 | /* Dequeues all of the listeners waiting for a resource */ |
| 1662 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1663 | dequeue_all_listeners(&global_listener_queue); |
| 1664 | |
| 1665 | return 1; |
| 1666 | } |
| 1667 | else { |
| 1668 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1669 | appctx->st0 = STAT_CLI_PRINT; |
| 1670 | return 1; |
| 1671 | } |
| 1672 | } |
| 1673 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1674 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1675 | if (strcmp(args[3], "global") == 0) { |
| 1676 | int v; |
| 1677 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1678 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1679 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1680 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1681 | return 1; |
| 1682 | } |
| 1683 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1684 | v = atoi(args[4]); |
| 1685 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1686 | } |
| 1687 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1688 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1689 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1690 | return 1; |
| 1691 | } |
| 1692 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1693 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1694 | 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] | 1695 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1696 | return 1; |
| 1697 | } |
| 1698 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1699 | else if (strcmp(args[1], "table") == 0) { |
| 1700 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1701 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1702 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1703 | char *err; |
| 1704 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1705 | /* Set flags. */ |
| 1706 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1707 | |
| 1708 | /* Expect three parameters: map name, key and new value. */ |
| 1709 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1710 | 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] | 1711 | appctx->st0 = STAT_CLI_PRINT; |
| 1712 | return 1; |
| 1713 | } |
| 1714 | |
| 1715 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1716 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1717 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1718 | 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] | 1719 | appctx->st0 = STAT_CLI_PRINT; |
| 1720 | return 1; |
| 1721 | } |
| 1722 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1723 | /* If the entry identifier start with a '#', it is considered as |
| 1724 | * pointer id |
| 1725 | */ |
| 1726 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1727 | struct pat_ref_elt *ref; |
| 1728 | long long int conv; |
| 1729 | char *error; |
| 1730 | |
| 1731 | /* Convert argument to integer value. */ |
| 1732 | conv = strtoll(&args[3][1], &error, 16); |
| 1733 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1734 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1735 | appctx->st0 = STAT_CLI_PRINT; |
| 1736 | return 1; |
| 1737 | } |
| 1738 | |
| 1739 | /* Convert and check integer to pointer. */ |
| 1740 | ref = (struct pat_ref_elt *)(long)conv; |
| 1741 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1742 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1743 | appctx->st0 = STAT_CLI_PRINT; |
| 1744 | return 1; |
| 1745 | } |
| 1746 | |
| 1747 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1748 | err = NULL; |
| 1749 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1750 | if (err) |
| 1751 | memprintf(&err, "%s.\n", err); |
| 1752 | appctx->ctx.cli.err = err; |
| 1753 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1754 | return 1; |
| 1755 | } |
| 1756 | } |
| 1757 | else { |
| 1758 | /* Else, use the entry identifier as pattern |
| 1759 | * string, and update the value. |
| 1760 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1761 | err = NULL; |
| 1762 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1763 | if (err) |
| 1764 | memprintf(&err, "%s.\n", err); |
| 1765 | appctx->ctx.cli.err = err; |
| 1766 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1767 | return 1; |
| 1768 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1769 | } |
| 1770 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1771 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1772 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1773 | return 1; |
| 1774 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1775 | #ifdef USE_OPENSSL |
| 1776 | else if (strcmp(args[1], "ssl") == 0) { |
| 1777 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 1778 | #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] | 1779 | char *err = NULL; |
| 1780 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 1781 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1782 | if (!*args[3]) { |
| 1783 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 1784 | appctx->st0 = STAT_CLI_PRINT; |
| 1785 | return 1; |
| 1786 | } |
| 1787 | |
| 1788 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 1789 | if (trash.len < 0) { |
| 1790 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 1791 | appctx->st0 = STAT_CLI_PRINT; |
| 1792 | return 1; |
| 1793 | } |
| 1794 | |
| 1795 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 1796 | if (err) { |
| 1797 | memprintf(&err, "%s.\n", err); |
| 1798 | appctx->ctx.cli.err = err; |
| 1799 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 1800 | } |
| 1801 | return 1; |
| 1802 | } |
| 1803 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 1804 | appctx->st0 = STAT_CLI_PRINT; |
| 1805 | return 1; |
| 1806 | #else |
| 1807 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 1808 | appctx->st0 = STAT_CLI_PRINT; |
| 1809 | return 1; |
| 1810 | #endif |
| 1811 | } |
| 1812 | else { |
| 1813 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 1814 | appctx->st0 = STAT_CLI_PRINT; |
| 1815 | return 1; |
| 1816 | } |
| 1817 | } |
| 1818 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1819 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1820 | return 0; |
| 1821 | } |
| 1822 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1823 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1824 | if (strcmp(args[1], "agent") == 0) { |
| 1825 | struct server *sv; |
| 1826 | |
| 1827 | sv = expect_server_admin(s, si, args[2]); |
| 1828 | if (!sv) |
| 1829 | return 1; |
| 1830 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1831 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1832 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1833 | appctx->st0 = STAT_CLI_PRINT; |
| 1834 | return 1; |
| 1835 | } |
| 1836 | |
| 1837 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1838 | return 1; |
| 1839 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1840 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1841 | struct server *sv; |
| 1842 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1843 | sv = expect_server_admin(s, si, args[2]); |
| 1844 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1845 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1846 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1847 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 1848 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 1849 | appctx->st0 = STAT_CLI_PRINT; |
| 1850 | return 1; |
| 1851 | } |
| 1852 | |
| 1853 | sv->check.state |= CHK_ST_ENABLED; |
| 1854 | return 1; |
| 1855 | } |
| 1856 | else if (strcmp(args[1], "server") == 0) { |
| 1857 | struct server *sv; |
| 1858 | |
| 1859 | sv = expect_server_admin(s, si, args[2]); |
| 1860 | if (!sv) |
| 1861 | return 1; |
| 1862 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1863 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1864 | return 1; |
| 1865 | } |
| 1866 | else if (strcmp(args[1], "frontend") == 0) { |
| 1867 | struct proxy *px; |
| 1868 | |
| 1869 | px = expect_frontend_admin(s, si, args[2]); |
| 1870 | if (!px) |
| 1871 | return 1; |
| 1872 | |
| 1873 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1874 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1875 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1876 | return 1; |
| 1877 | } |
| 1878 | |
| 1879 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1880 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1881 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1882 | return 1; |
| 1883 | } |
| 1884 | |
| 1885 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1886 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1887 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1888 | return 1; |
| 1889 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1890 | return 1; |
| 1891 | } |
| 1892 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1893 | 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] | 1894 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1895 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1896 | } |
| 1897 | } |
| 1898 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1899 | if (strcmp(args[1], "agent") == 0) { |
| 1900 | struct server *sv; |
| 1901 | |
| 1902 | sv = expect_server_admin(s, si, args[2]); |
| 1903 | if (!sv) |
| 1904 | return 1; |
| 1905 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1906 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1907 | return 1; |
| 1908 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1909 | else if (strcmp(args[1], "health") == 0) { |
| 1910 | struct server *sv; |
| 1911 | |
| 1912 | sv = expect_server_admin(s, si, args[2]); |
| 1913 | if (!sv) |
| 1914 | return 1; |
| 1915 | |
| 1916 | sv->check.state &= ~CHK_ST_ENABLED; |
| 1917 | return 1; |
| 1918 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1919 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1920 | struct server *sv; |
| 1921 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1922 | sv = expect_server_admin(s, si, args[2]); |
| 1923 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1924 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1925 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1926 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1927 | return 1; |
| 1928 | } |
| 1929 | else if (strcmp(args[1], "frontend") == 0) { |
| 1930 | struct proxy *px; |
| 1931 | |
| 1932 | px = expect_frontend_admin(s, si, args[2]); |
| 1933 | if (!px) |
| 1934 | return 1; |
| 1935 | |
| 1936 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1937 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1938 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1939 | return 1; |
| 1940 | } |
| 1941 | |
| 1942 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1943 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1944 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1945 | return 1; |
| 1946 | } |
| 1947 | |
| 1948 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1949 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1950 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1951 | return 1; |
| 1952 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1953 | return 1; |
| 1954 | } |
| 1955 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1956 | 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] | 1957 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1958 | return 1; |
| 1959 | } |
| 1960 | } |
| 1961 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1962 | if (strcmp(args[1], "frontend") == 0) { |
| 1963 | struct proxy *px; |
| 1964 | |
| 1965 | px = expect_frontend_admin(s, si, args[2]); |
| 1966 | if (!px) |
| 1967 | return 1; |
| 1968 | |
| 1969 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1970 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1971 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1972 | return 1; |
| 1973 | } |
| 1974 | |
| 1975 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1976 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1977 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1978 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1979 | stop_proxy(px); |
| 1980 | return 1; |
| 1981 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1982 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1983 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1984 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1985 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1986 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1987 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1988 | return 1; |
| 1989 | } |
| 1990 | |
| 1991 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1992 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1993 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1994 | return 1; |
| 1995 | } |
| 1996 | |
| 1997 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1998 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1999 | /* first, look for the requested stream in the stream table */ |
| 2000 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2001 | if (sess == ptr) |
| 2002 | break; |
| 2003 | } |
| 2004 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2005 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2006 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2007 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2008 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2009 | return 1; |
| 2010 | } |
| 2011 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2012 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2013 | return 1; |
| 2014 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2015 | else if (strcmp(args[1], "sessions") == 0) { |
| 2016 | if (strcmp(args[2], "server") == 0) { |
| 2017 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2018 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2019 | |
| 2020 | sv = expect_server_admin(s, si, args[3]); |
| 2021 | if (!sv) |
| 2022 | return 1; |
| 2023 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2024 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2025 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2026 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2027 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2028 | |
| 2029 | return 1; |
| 2030 | } |
| 2031 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2032 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2033 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2034 | return 1; |
| 2035 | } |
| 2036 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2037 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2038 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2039 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2040 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2041 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2042 | } |
| 2043 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2044 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2045 | if (args[1][0] == 'm') |
| 2046 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2047 | else |
| 2048 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2049 | |
| 2050 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2051 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2052 | if (!*args[2] || !*args[3]) { |
| 2053 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2054 | appctx->st0 = STAT_CLI_PRINT; |
| 2055 | return 1; |
| 2056 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2057 | } |
| 2058 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2059 | else { |
| 2060 | if (!*args[2] || !*args[3]) { |
| 2061 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2062 | appctx->st0 = STAT_CLI_PRINT; |
| 2063 | return 1; |
| 2064 | } |
| 2065 | } |
| 2066 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2067 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2068 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2069 | if (!appctx->ctx.map.ref || |
| 2070 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2071 | 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] | 2072 | appctx->st0 = STAT_CLI_PRINT; |
| 2073 | return 1; |
| 2074 | } |
| 2075 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2076 | /* If the entry identifier start with a '#', it is considered as |
| 2077 | * pointer id |
| 2078 | */ |
| 2079 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2080 | struct pat_ref_elt *ref; |
| 2081 | long long int conv; |
| 2082 | char *error; |
| 2083 | |
| 2084 | /* Convert argument to integer value. */ |
| 2085 | conv = strtoll(&args[3][1], &error, 16); |
| 2086 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2087 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2088 | appctx->st0 = STAT_CLI_PRINT; |
| 2089 | return 1; |
| 2090 | } |
| 2091 | |
| 2092 | /* Convert and check integer to pointer. */ |
| 2093 | ref = (struct pat_ref_elt *)(long)conv; |
| 2094 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2095 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2096 | appctx->st0 = STAT_CLI_PRINT; |
| 2097 | return 1; |
| 2098 | } |
| 2099 | |
| 2100 | /* Try to delete the entry. */ |
| 2101 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2102 | /* The entry is not found, send message. */ |
| 2103 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2104 | appctx->st0 = STAT_CLI_PRINT; |
| 2105 | return 1; |
| 2106 | } |
| 2107 | } |
| 2108 | else { |
| 2109 | /* Else, use the entry identifier as pattern |
| 2110 | * string and try to delete the entry. |
| 2111 | */ |
| 2112 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2113 | /* The entry is not found, send message. */ |
| 2114 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2115 | appctx->st0 = STAT_CLI_PRINT; |
| 2116 | return 1; |
| 2117 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2118 | } |
| 2119 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2120 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2121 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2122 | return 1; |
| 2123 | } |
| 2124 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2125 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2126 | appctx->st0 = STAT_CLI_PRINT; |
| 2127 | return 1; |
| 2128 | } |
| 2129 | } |
| 2130 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2131 | if (strcmp(args[1], "map") == 0 || |
| 2132 | strcmp(args[1], "acl") == 0) { |
| 2133 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2134 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2135 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2136 | /* Set flags. */ |
| 2137 | if (args[1][0] == 'm') |
| 2138 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2139 | else |
| 2140 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2141 | |
| 2142 | /* If the keywork is "map", we expect three parameters, if it |
| 2143 | * is "acl", we expect only two parameters |
| 2144 | */ |
| 2145 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2146 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2147 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2148 | appctx->st0 = STAT_CLI_PRINT; |
| 2149 | return 1; |
| 2150 | } |
| 2151 | } |
| 2152 | else { |
| 2153 | if (!*args[2] || !*args[3]) { |
| 2154 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2155 | appctx->st0 = STAT_CLI_PRINT; |
| 2156 | return 1; |
| 2157 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2158 | } |
| 2159 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2160 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2161 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2162 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2163 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2164 | 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] | 2165 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2166 | 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] | 2167 | appctx->st0 = STAT_CLI_PRINT; |
| 2168 | return 1; |
| 2169 | } |
| 2170 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2171 | /* The command "add acl" is prohibited if the reference |
| 2172 | * use samples. |
| 2173 | */ |
| 2174 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2175 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2176 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2177 | "You must use the command 'add map' to add values.\n"; |
| 2178 | appctx->st0 = STAT_CLI_PRINT; |
| 2179 | return 1; |
| 2180 | } |
| 2181 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2182 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2183 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2184 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2185 | 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] | 2186 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2187 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2188 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2189 | if (err) |
| 2190 | memprintf(&err, "%s.\n", err); |
| 2191 | appctx->ctx.cli.err = err; |
| 2192 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2193 | return 1; |
| 2194 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2195 | |
| 2196 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2197 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2198 | return 1; |
| 2199 | } |
| 2200 | else { /* unknown "del" parameter */ |
| 2201 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2202 | appctx->st0 = STAT_CLI_PRINT; |
| 2203 | return 1; |
| 2204 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2205 | } |
| 2206 | 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] | 2207 | return 0; |
| 2208 | } |
| 2209 | return 1; |
| 2210 | } |
| 2211 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2212 | /* 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] | 2213 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2214 | * state machine handling requests and various responses. We read a request, |
| 2215 | * 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] | 2216 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2217 | * 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] | 2218 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2219 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2220 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2221 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2222 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2223 | struct channel *req = si_oc(si); |
| 2224 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2225 | int reql; |
| 2226 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2227 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2228 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2229 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2230 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2231 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2232 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2233 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2234 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2235 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2236 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2237 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2238 | /* Let's close for real now. We just close the request |
| 2239 | * side, the conditions below will complete if needed. |
| 2240 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2241 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2242 | break; |
| 2243 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2244 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2245 | /* ensure we have some output room left in the event we |
| 2246 | * would want to return some info right after parsing. |
| 2247 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2248 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2249 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2250 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2251 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2252 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2253 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2254 | if (reql <= 0) { /* closed or EOL not found */ |
| 2255 | if (reql == 0) |
| 2256 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2257 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2258 | continue; |
| 2259 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2260 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2261 | /* seek for a possible semi-colon. If we find one, we |
| 2262 | * replace it with an LF and skip only this part. |
| 2263 | */ |
| 2264 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2265 | if (trash.str[len] == ';') { |
| 2266 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2267 | reql = len + 1; |
| 2268 | break; |
| 2269 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2270 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2271 | /* now it is time to check that we have a full line, |
| 2272 | * remove the trailing \n and possibly \r, then cut the |
| 2273 | * line. |
| 2274 | */ |
| 2275 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2276 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2277 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2278 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2279 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2280 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2281 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2282 | len--; |
| 2283 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2284 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2285 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2286 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2287 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2288 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2289 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2290 | continue; |
| 2291 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2292 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2293 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2294 | else if (strcmp(trash.str, "help") == 0 || |
| 2295 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2296 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2297 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2298 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2299 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2300 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2301 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2302 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2303 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2304 | /* if prompt is disabled, print help on empty lines, |
| 2305 | * so that the user at least knows how to enable |
| 2306 | * prompt and find help. |
| 2307 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2308 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2309 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2313 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2314 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2315 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2316 | 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] | 2317 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 2318 | cli_release_handler(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2319 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2320 | continue; |
| 2321 | } |
| 2322 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2323 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2324 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2325 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2326 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2327 | else |
| 2328 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2329 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2330 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2331 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2332 | free(appctx->ctx.cli.err); |
| 2333 | appctx->st0 = STAT_CLI_PROMPT; |
| 2334 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2335 | else |
| 2336 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2337 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2338 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2339 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2340 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2341 | break; |
| 2342 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2343 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2344 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2345 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2346 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2347 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2348 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2349 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2350 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2351 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2352 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2353 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2354 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2355 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2356 | if (stats_table_request(si, appctx->st0)) |
| 2357 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2358 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2359 | case STAT_CLI_O_PATS: |
| 2360 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2361 | appctx->st0 = STAT_CLI_PROMPT; |
| 2362 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2363 | case STAT_CLI_O_PAT: |
| 2364 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2365 | appctx->st0 = STAT_CLI_PROMPT; |
| 2366 | break; |
| 2367 | case STAT_CLI_O_MLOOK: |
| 2368 | if (stats_map_lookup(si)) |
| 2369 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2370 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2371 | case STAT_CLI_O_POOLS: |
| 2372 | if (stats_dump_pools_to_buffer(si)) |
| 2373 | appctx->st0 = STAT_CLI_PROMPT; |
| 2374 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2375 | default: /* abnormal state */ |
Willy Tarreau | 44cf545 | 2014-10-22 19:06:31 +0200 | [diff] [blame] | 2376 | cli_release_handler(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2377 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2378 | break; |
| 2379 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2380 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2381 | /* 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] | 2382 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2383 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2384 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2385 | else |
| 2386 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2387 | } |
| 2388 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2389 | /* 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] | 2390 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2391 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2392 | |
| 2393 | /* Now we close the output if one of the writers did so, |
| 2394 | * or if we're not in interactive mode and the request |
| 2395 | * buffer is empty. This still allows pipelined requests |
| 2396 | * to be sent in non-interactive mode. |
| 2397 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2398 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2399 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2400 | continue; |
| 2401 | } |
| 2402 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2403 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2404 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2405 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2406 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2407 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2408 | 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] | 2409 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2410 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2411 | /* 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] | 2412 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2413 | * we forward the close to the request side so that it flows upstream to |
| 2414 | * the client. |
| 2415 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2416 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2417 | } |
| 2418 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2419 | 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] | 2420 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2421 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2422 | /* We have no more processing to do, and nothing more to send, and |
| 2423 | * the client side has closed. So we'll forward this state downstream |
| 2424 | * on the response buffer. |
| 2425 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2426 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2427 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2431 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2432 | |
| 2433 | /* we don't want to expire timeouts while we're processing requests */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2434 | si_ic(si)->rex = TICK_ETERNITY; |
| 2435 | si_oc(si)->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2436 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2437 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2438 | 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] | 2439 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2440 | 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] | 2441 | |
| 2442 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2443 | /* check that we have released everything then unregister */ |
| 2444 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2445 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2446 | } |
| 2447 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2448 | /* This function dumps information onto the stream interface's read buffer. |
| 2449 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2450 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2451 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2452 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2453 | { |
| 2454 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2455 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2456 | #ifdef USE_OPENSSL |
| 2457 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2458 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2459 | int ssl_reuse = 0; |
| 2460 | |
| 2461 | if (ssl_key_rate < ssl_sess_rate) { |
| 2462 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2463 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2464 | } |
| 2465 | #endif |
| 2466 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2467 | chunk_printf(&trash, |
| 2468 | "Name: " PRODUCT_NAME "\n" |
| 2469 | "Version: " HAPROXY_VERSION "\n" |
| 2470 | "Release_date: " HAPROXY_DATE "\n" |
| 2471 | "Nbproc: %d\n" |
| 2472 | "Process_num: %d\n" |
| 2473 | "Pid: %d\n" |
| 2474 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2475 | "Uptime_sec: %d\n" |
| 2476 | "Memmax_MB: %d\n" |
| 2477 | "Ulimit-n: %d\n" |
| 2478 | "Maxsock: %d\n" |
| 2479 | "Maxconn: %d\n" |
| 2480 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2481 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2482 | "CumConns: %d\n" |
Warren Turkal | b197d7f | 2015-01-27 15:04:16 -0800 | [diff] [blame] | 2483 | "CumReq: %u\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2484 | #ifdef USE_OPENSSL |
| 2485 | "MaxSslConns: %d\n" |
| 2486 | "CurrSslConns: %d\n" |
| 2487 | "CumSslConns: %d\n" |
| 2488 | #endif |
| 2489 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2490 | "PipesUsed: %d\n" |
| 2491 | "PipesFree: %d\n" |
| 2492 | "ConnRate: %d\n" |
| 2493 | "ConnRateLimit: %d\n" |
| 2494 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2495 | "SessRate: %d\n" |
| 2496 | "SessRateLimit: %d\n" |
| 2497 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2498 | #ifdef USE_OPENSSL |
| 2499 | "SslRate: %d\n" |
| 2500 | "SslRateLimit: %d\n" |
| 2501 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2502 | "SslFrontendKeyRate: %d\n" |
| 2503 | "SslFrontendMaxKeyRate: %d\n" |
| 2504 | "SslFrontendSessionReuse_pct: %d\n" |
| 2505 | "SslBackendKeyRate: %d\n" |
| 2506 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2507 | "SslCacheLookups: %u\n" |
| 2508 | "SslCacheMisses: %u\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2509 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2510 | "CompressBpsIn: %u\n" |
| 2511 | "CompressBpsOut: %u\n" |
| 2512 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2513 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2514 | "ZlibMemUsage: %ld\n" |
| 2515 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2516 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2517 | "Tasks: %d\n" |
| 2518 | "Run_queue: %d\n" |
| 2519 | "Idle_pct: %d\n" |
| 2520 | "node: %s\n" |
| 2521 | "description: %s\n" |
| 2522 | "", |
| 2523 | global.nbproc, |
| 2524 | relative_pid, |
| 2525 | pid, |
| 2526 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2527 | up, |
| 2528 | global.rlimit_memmax, |
| 2529 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2530 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2531 | actconn, totalconn, global.req_count, |
| 2532 | #ifdef USE_OPENSSL |
| 2533 | global.maxsslconn, sslconns, totalsslconns, |
| 2534 | #endif |
| 2535 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2536 | 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] | 2537 | 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] | 2538 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2539 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2540 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2541 | ssl_reuse, |
| 2542 | 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] | 2543 | global.shctx_lookups, global.shctx_misses, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2544 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2545 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2546 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2547 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2548 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2549 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2550 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2551 | global.node, global.desc ? global.desc : "" |
| 2552 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2553 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2554 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 2555 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2556 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2557 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2558 | |
| 2559 | return 1; |
| 2560 | } |
| 2561 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2562 | /* This function dumps memory usage information onto the stream interface's |
| 2563 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2564 | * completion. No state is used. |
| 2565 | */ |
| 2566 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2567 | { |
| 2568 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2569 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 2570 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2571 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2572 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2573 | return 1; |
| 2574 | } |
| 2575 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2576 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2577 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2578 | * 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] | 2579 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2580 | 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] | 2581 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2582 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2583 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2584 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2585 | if (!(px->cap & PR_CAP_FE)) |
| 2586 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2587 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2588 | 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] | 2589 | return 0; |
| 2590 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2591 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2592 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2593 | /* name, queue */ |
| 2594 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2595 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2596 | 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] | 2597 | /* Column sub-heading for Enable or Disable server */ |
| 2598 | chunk_appendf(&trash, "<td></td>"); |
| 2599 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2600 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2601 | chunk_appendf(&trash, |
| 2602 | "<td class=ac>" |
| 2603 | "<a name=\"%s/Frontend\"></a>" |
| 2604 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2605 | "<td colspan=3></td>" |
| 2606 | "", |
| 2607 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2608 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2609 | chunk_appendf(&trash, |
| 2610 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2611 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2612 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2613 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2614 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2615 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2616 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2617 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2618 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2619 | if (px->mode == PR_MODE_HTTP) |
| 2620 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2621 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2622 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2623 | |
| 2624 | chunk_appendf(&trash, |
| 2625 | "</table></div></u></td>" |
| 2626 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2627 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2628 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2629 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2630 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2631 | U2H(px->fe_counters.sps_max), |
| 2632 | U2H(px->fe_counters.cps_max), |
| 2633 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2634 | |
| 2635 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2636 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2637 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2638 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2639 | |
| 2640 | chunk_appendf(&trash, |
| 2641 | "</table></div></u></td>" |
| 2642 | /* sessions rate : limit */ |
| 2643 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2644 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2645 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2646 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2647 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2648 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2649 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2650 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2651 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2652 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2653 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2654 | U2H(px->fe_counters.cum_sess), |
| 2655 | U2H(px->fe_counters.cum_conn), |
| 2656 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2657 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2658 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2659 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2660 | chunk_appendf(&trash, |
| 2661 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2662 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2663 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2664 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2665 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2666 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2667 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2668 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2669 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2670 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2671 | U2H(px->fe_counters.p.http.cum_req), |
| 2672 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2673 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2674 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2675 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2676 | (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] | 2677 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2678 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2679 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2680 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2681 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2682 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2683 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2684 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2685 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2686 | /* sessions: lbtot, lastsess */ |
| 2687 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2688 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2689 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2690 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2691 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2692 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2693 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2694 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2695 | "<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] | 2696 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2697 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2698 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2699 | px->fe_counters.comp_in ? |
| 2700 | (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] | 2701 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2702 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2703 | chunk_appendf(&trash, |
| 2704 | /* denied: req, resp */ |
| 2705 | "<td>%s</td><td>%s</td>" |
| 2706 | /* errors : request, connect, response */ |
| 2707 | "<td>%s</td><td></td><td></td>" |
| 2708 | /* warnings: retries, redispatches */ |
| 2709 | "<td></td><td></td>" |
| 2710 | /* server status : reflect frontend status */ |
| 2711 | "<td class=ac>%s</td>" |
| 2712 | /* rest of server: nothing */ |
| 2713 | "<td class=ac colspan=8></td></tr>" |
| 2714 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2715 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2716 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2717 | px->state == PR_STREADY ? "OPEN" : |
| 2718 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2719 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2720 | else { /* CSV mode */ |
| 2721 | chunk_appendf(&trash, |
| 2722 | /* pxid, name, queue cur, queue max, */ |
| 2723 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2724 | /* sessions : current, max, limit, total */ |
| 2725 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2726 | /* bytes : in, out */ |
| 2727 | "%lld,%lld," |
| 2728 | /* denied: req, resp */ |
| 2729 | "%lld,%lld," |
| 2730 | /* errors : request, connect, response */ |
| 2731 | "%lld,,," |
| 2732 | /* warnings: retries, redispatches */ |
| 2733 | ",," |
| 2734 | /* server status : reflect frontend status */ |
| 2735 | "%s," |
| 2736 | /* rest of server: nothing */ |
| 2737 | ",,,,,,,," |
| 2738 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2739 | "%d,%d,0,,,,%d," |
| 2740 | /* rate, rate_lim, rate_max */ |
| 2741 | "%u,%u,%u," |
| 2742 | /* check_status, check_code, check_duration */ |
| 2743 | ",,,", |
| 2744 | px->id, |
| 2745 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2746 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2747 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2748 | px->fe_counters.failed_req, |
| 2749 | px->state == PR_STREADY ? "OPEN" : |
| 2750 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2751 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2752 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2753 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2754 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2755 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2756 | if (px->mode == PR_MODE_HTTP) { |
| 2757 | for (i=1; i<6; i++) |
| 2758 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2759 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2760 | } |
| 2761 | else |
| 2762 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2763 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2764 | /* failed health analyses */ |
| 2765 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2766 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2767 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2768 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2769 | read_freq_ctr(&px->fe_req_per_sec), |
| 2770 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2771 | |
| 2772 | /* errors: cli_aborts, srv_aborts */ |
| 2773 | chunk_appendf(&trash, ",,"); |
| 2774 | |
| 2775 | /* compression: in, out, bypassed */ |
| 2776 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2777 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2778 | |
| 2779 | /* compression: comp_rsp */ |
| 2780 | chunk_appendf(&trash, "%lld,", |
| 2781 | px->fe_counters.p.http.comp_rsp); |
| 2782 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2783 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2784 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2785 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2786 | /* finish with EOL */ |
| 2787 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2788 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2789 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2790 | } |
| 2791 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2792 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2793 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2794 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2795 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2796 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2797 | 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] | 2798 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2799 | struct appctx *appctx = __objt_appctx(si->end); |
| 2800 | |
| 2801 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2802 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2803 | 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] | 2804 | /* Column sub-heading for Enable or Disable server */ |
| 2805 | chunk_appendf(&trash, "<td></td>"); |
| 2806 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2807 | chunk_appendf(&trash, |
| 2808 | /* frontend name, listener name */ |
| 2809 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2810 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2811 | "", |
| 2812 | px->id, l->name, |
| 2813 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2814 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2815 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2816 | if (flags & ST_SHLGNDS) { |
| 2817 | char str[INET6_ADDRSTRLEN]; |
| 2818 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2819 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2820 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2821 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2822 | port = get_host_port(&l->addr); |
| 2823 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2824 | case AF_INET: |
| 2825 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2826 | break; |
| 2827 | case AF_INET6: |
| 2828 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2829 | break; |
| 2830 | case AF_UNIX: |
| 2831 | chunk_appendf(&trash, "unix, "); |
| 2832 | break; |
| 2833 | case -1: |
| 2834 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2835 | break; |
| 2836 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2837 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2838 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2839 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2840 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2841 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2842 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2843 | /* queue */ |
| 2844 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2845 | /* sessions rate: current, max, limit */ |
| 2846 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2847 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2848 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2849 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2850 | /* bytes: in, out */ |
| 2851 | "<td>%s</td><td>%s</td>" |
| 2852 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2853 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2854 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2855 | 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] | 2856 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2857 | chunk_appendf(&trash, |
| 2858 | /* denied: req, resp */ |
| 2859 | "<td>%s</td><td>%s</td>" |
| 2860 | /* errors: request, connect, response */ |
| 2861 | "<td>%s</td><td></td><td></td>" |
| 2862 | /* warnings: retries, redispatches */ |
| 2863 | "<td></td><td></td>" |
| 2864 | /* server status: reflect listener status */ |
| 2865 | "<td class=ac>%s</td>" |
| 2866 | /* rest of server: nothing */ |
| 2867 | "<td class=ac colspan=8></td></tr>" |
| 2868 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2869 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2870 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2871 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2872 | } |
| 2873 | else { /* CSV mode */ |
| 2874 | chunk_appendf(&trash, |
| 2875 | /* pxid, name, queue cur, queue max, */ |
| 2876 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2877 | /* sessions: current, max, limit, total */ |
| 2878 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2879 | /* bytes: in, out */ |
| 2880 | "%lld,%lld," |
| 2881 | /* denied: req, resp */ |
| 2882 | "%lld,%lld," |
| 2883 | /* errors: request, connect, response */ |
| 2884 | "%lld,,," |
| 2885 | /* warnings: retries, redispatches */ |
| 2886 | ",," |
| 2887 | /* server status: reflect listener status */ |
| 2888 | "%s," |
| 2889 | /* rest of server: nothing */ |
| 2890 | ",,,,,,,," |
| 2891 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2892 | "%d,%d,%d,,,,%d," |
| 2893 | /* rate, rate_lim, rate_max */ |
| 2894 | ",,," |
| 2895 | /* check_status, check_code, check_duration */ |
| 2896 | ",,," |
| 2897 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2898 | ",,,,,," |
| 2899 | /* failed health analyses */ |
| 2900 | "," |
| 2901 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2902 | ",,," |
| 2903 | /* errors: cli_aborts, srv_aborts */ |
| 2904 | ",," |
| 2905 | /* compression: in, out, bypassed, comp_rsp */ |
| 2906 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2907 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2908 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2909 | "\n", |
| 2910 | px->id, l->name, |
| 2911 | l->nbconn, l->counters->conn_max, |
| 2912 | l->maxconn, l->counters->cum_conn, |
| 2913 | l->counters->bytes_in, l->counters->bytes_out, |
| 2914 | l->counters->denied_req, l->counters->denied_resp, |
| 2915 | l->counters->failed_req, |
| 2916 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2917 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2918 | } |
| 2919 | return 1; |
| 2920 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2921 | |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 2922 | enum srv_stats_state { |
| 2923 | SRV_STATS_STATE_DOWN = 0, |
| 2924 | SRV_STATS_STATE_DOWN_AGENT, |
| 2925 | SRV_STATS_STATE_GOING_UP, |
| 2926 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 2927 | SRV_STATS_STATE_UP, |
| 2928 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 2929 | SRV_STATS_STATE_NOLB, |
| 2930 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 2931 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame^] | 2932 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 2933 | SRV_STATS_STATE_NO_CHECK, |
| 2934 | |
| 2935 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 2936 | }; |
| 2937 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 2938 | enum srv_stats_colour { |
| 2939 | SRV_STATS_COLOUR_DOWN = 0, |
| 2940 | SRV_STATS_COLOUR_GOING_UP, |
| 2941 | SRV_STATS_COLOUR_GOING_DOWN, |
| 2942 | SRV_STATS_COLOUR_UP, |
| 2943 | SRV_STATS_COLOUR_NOLB, |
| 2944 | SRV_STATS_COLOUR_DRAINING, |
| 2945 | SRV_STATS_COLOUR_NO_CHECK, |
| 2946 | |
| 2947 | SRV_STATS_COLOUR_COUNT, /* Must be last */ |
| 2948 | }; |
| 2949 | |
| 2950 | static const char *srv_stats_colour_st[SRV_STATS_COLOUR_COUNT] = { |
| 2951 | [SRV_STATS_COLOUR_DOWN] = "down", |
| 2952 | [SRV_STATS_COLOUR_GOING_UP] = "going_up", |
| 2953 | [SRV_STATS_COLOUR_GOING_DOWN] = "going_down", |
| 2954 | [SRV_STATS_COLOUR_UP] = "up", |
| 2955 | [SRV_STATS_COLOUR_NOLB] = "nolb", |
| 2956 | [SRV_STATS_COLOUR_DRAINING] = "draining", |
| 2957 | [SRV_STATS_COLOUR_NO_CHECK] = "no_check", |
| 2958 | }; |
| 2959 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2960 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2961 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2962 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 2963 | * if it emits anything, zero otherwise. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2964 | */ |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 2965 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 2966 | enum srv_stats_state state, enum srv_stats_colour colour) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2967 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2968 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2969 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2970 | char str[INET6_ADDRSTRLEN]; |
| 2971 | struct chunk src; |
| 2972 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2973 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 2974 | /* we have "via" which is the tracked server as described in the configuration, |
| 2975 | * and "ref" which is the checked server and the end of the chain. |
| 2976 | */ |
| 2977 | via = sv->track ? sv->track : sv; |
| 2978 | ref = via; |
| 2979 | while (ref->track) |
| 2980 | ref = ref->track; |
| 2981 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2982 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 2983 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 2984 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 2985 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 2986 | [SRV_STATS_STATE_GOING_UP] = "DN %d/%d ↑", |
| 2987 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d ↓", |
| 2988 | [SRV_STATS_STATE_UP] = "UP", |
| 2989 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d ↓", |
| 2990 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 2991 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d ↓", |
| 2992 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame^] | 2993 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 2994 | [SRV_STATS_STATE_NO_CHECK] = "<i>no check</i>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2995 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2996 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 2997 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2998 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2999 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3000 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3001 | "<tr class=\"%s_%s\">", |
| 3002 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", srv_stats_colour_st[colour]); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3003 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3004 | 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] | 3005 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3006 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3007 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3008 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3009 | chunk_appendf(&trash, |
| 3010 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3011 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3012 | "", |
| 3013 | px->id, sv->id, |
| 3014 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3015 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3016 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3017 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3018 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3019 | |
| 3020 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 3021 | case AF_INET: |
| 3022 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 3023 | break; |
| 3024 | case AF_INET6: |
| 3025 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 3026 | break; |
| 3027 | case AF_UNIX: |
| 3028 | chunk_appendf(&trash, "unix, "); |
| 3029 | break; |
| 3030 | case -1: |
| 3031 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3032 | break; |
| 3033 | default: /* address family not supported */ |
| 3034 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3035 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3036 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3037 | /* id */ |
| 3038 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3039 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3040 | /* cookie */ |
| 3041 | if (sv->cookie) { |
| 3042 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3043 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3044 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3045 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3046 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3047 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3048 | } |
| 3049 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3050 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3051 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3052 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3053 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3054 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3055 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3056 | /* sessions rate : current, max, limit */ |
| 3057 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3058 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3059 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3060 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3061 | 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] | 3062 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3063 | |
| 3064 | chunk_appendf(&trash, |
| 3065 | /* sessions: current, max, limit, total */ |
| 3066 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3067 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3068 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3069 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3070 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3071 | U2H(sv->counters.cum_sess), |
| 3072 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3073 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3074 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3075 | if (px->mode == PR_MODE_HTTP) { |
| 3076 | unsigned long long tot; |
| 3077 | for (tot = i = 0; i < 6; i++) |
| 3078 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3079 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3080 | chunk_appendf(&trash, |
| 3081 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3082 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3083 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3084 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3085 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3086 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3087 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3088 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3089 | U2H(tot), |
| 3090 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3091 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3092 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3093 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3094 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3095 | 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] | 3096 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3097 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3098 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3099 | 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))); |
| 3100 | 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))); |
| 3101 | if (px->mode == PR_MODE_HTTP) |
| 3102 | 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))); |
| 3103 | 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))); |
| 3104 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3105 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3106 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3107 | /* sessions: lbtot, last */ |
| 3108 | "<td>%s</td><td>%s</td>", |
| 3109 | U2H(sv->counters.cum_lbconn), |
| 3110 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3111 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3112 | chunk_appendf(&trash, |
| 3113 | /* bytes : in, out */ |
| 3114 | "<td>%s</td><td>%s</td>" |
| 3115 | /* denied: req, resp */ |
| 3116 | "<td></td><td>%s</td>" |
| 3117 | /* errors : request, connect */ |
| 3118 | "<td></td><td>%s</td>" |
| 3119 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3120 | "<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] | 3121 | /* warnings: retries, redispatches */ |
| 3122 | "<td>%lld</td><td>%lld</td>" |
| 3123 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3124 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3125 | U2H(sv->counters.failed_secu), |
| 3126 | U2H(sv->counters.failed_conns), |
| 3127 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3128 | sv->counters.cli_aborts, |
| 3129 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3130 | sv->counters.retries, sv->counters.redispatches); |
| 3131 | |
| 3132 | /* status, lest check */ |
| 3133 | chunk_appendf(&trash, "<td class=ac>"); |
| 3134 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3135 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3136 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3137 | chunk_appendf(&trash, "MAINT"); |
| 3138 | } |
Simon Horman | 0766e44 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3139 | 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] | 3140 | 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] | 3141 | /* DOWN (agent) */ |
| 3142 | 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] | 3143 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3144 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3145 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3146 | chunk_appendf(&trash, |
| 3147 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3148 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3149 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3150 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3151 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3152 | if ((sv->state == SRV_ST_STOPPED) && |
| 3153 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3154 | chunk_appendf(&trash, |
| 3155 | "</td><td class=ac><u> %s%s", |
| 3156 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3157 | get_check_status_info(sv->agent.status)); |
| 3158 | |
| 3159 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3160 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3161 | |
| 3162 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3163 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3164 | |
| 3165 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3166 | get_check_status_description(sv->agent.status)); |
| 3167 | if (*sv->agent.desc) { |
| 3168 | chunk_appendf(&trash, ": "); |
| 3169 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3170 | chunk_htmlencode(&trash, &src); |
| 3171 | } |
| 3172 | chunk_appendf(&trash, "</div></u>"); |
| 3173 | } |
| 3174 | 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] | 3175 | chunk_appendf(&trash, |
| 3176 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3177 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3178 | get_check_status_info(sv->check.status)); |
| 3179 | |
| 3180 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3181 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3182 | |
| 3183 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3184 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3185 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3186 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3187 | get_check_status_description(sv->check.status)); |
| 3188 | if (*sv->check.desc) { |
| 3189 | chunk_appendf(&trash, ": "); |
| 3190 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3191 | chunk_htmlencode(&trash, &src); |
| 3192 | } |
| 3193 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3194 | } |
| 3195 | else |
| 3196 | chunk_appendf(&trash, "</td><td>"); |
| 3197 | |
| 3198 | chunk_appendf(&trash, |
| 3199 | /* weight */ |
| 3200 | "</td><td class=ac>%d</td>" |
| 3201 | /* act, bck */ |
| 3202 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3203 | "", |
| 3204 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3205 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3206 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3207 | |
| 3208 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3209 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3210 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3211 | |
| 3212 | if (ref->observe) |
| 3213 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3214 | |
| 3215 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3216 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3217 | "<td>%lld</td><td>%s</td>" |
| 3218 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3219 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3220 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3221 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3222 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3223 | /* tracking a server */ |
| 3224 | chunk_appendf(&trash, |
| 3225 | "<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] | 3226 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3227 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3228 | else |
| 3229 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3230 | |
| 3231 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3232 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3233 | 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] | 3234 | else |
| 3235 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3236 | } |
| 3237 | else { /* CSV mode */ |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3238 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3239 | [SRV_STATS_STATE_DOWN] = "DOWN,", |
| 3240 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent),", |
| 3241 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d,", |
| 3242 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d,", |
| 3243 | [SRV_STATS_STATE_UP] = "UP,", |
| 3244 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d,", |
| 3245 | [SRV_STATS_STATE_NOLB] = "NOLB,", |
| 3246 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d,", |
| 3247 | [SRV_STATS_STATE_DRAIN] = "DRAIN,", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame^] | 3248 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3249 | [SRV_STATS_STATE_NO_CHECK] = "no check," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3250 | }; |
| 3251 | |
| 3252 | chunk_appendf(&trash, |
| 3253 | /* pxid, name */ |
| 3254 | "%s,%s," |
| 3255 | /* queue : current, max */ |
| 3256 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3257 | /* sessions : current, max, limit, total */ |
| 3258 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3259 | /* bytes : in, out */ |
| 3260 | "%lld,%lld," |
| 3261 | /* denied: req, resp */ |
| 3262 | ",%lld," |
| 3263 | /* errors : request, connect, response */ |
| 3264 | ",%lld,%lld," |
| 3265 | /* warnings: retries, redispatches */ |
| 3266 | "%lld,%lld," |
| 3267 | "", |
| 3268 | px->id, sv->id, |
| 3269 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3270 | 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] | 3271 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3272 | sv->counters.failed_secu, |
| 3273 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3274 | sv->counters.retries, sv->counters.redispatches); |
| 3275 | |
| 3276 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3277 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3278 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3279 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3280 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3281 | else |
| 3282 | chunk_appendf(&trash, |
| 3283 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3284 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3285 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3286 | |
| 3287 | chunk_appendf(&trash, |
| 3288 | /* weight, active, backup */ |
| 3289 | "%d,%d,%d," |
| 3290 | "", |
| 3291 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3292 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3293 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3294 | |
| 3295 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3296 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3297 | chunk_appendf(&trash, |
| 3298 | "%lld,%lld,%d,%d,", |
| 3299 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3300 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3301 | else |
| 3302 | chunk_appendf(&trash, ",,,,"); |
| 3303 | |
| 3304 | /* queue limit, pid, iid, sid, */ |
| 3305 | chunk_appendf(&trash, |
| 3306 | "%s," |
| 3307 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3308 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3309 | relative_pid, px->uuid, sv->puid); |
| 3310 | |
| 3311 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3312 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3313 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3314 | |
| 3315 | /* sessions: lbtot */ |
| 3316 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3317 | |
| 3318 | /* tracked */ |
| 3319 | if (sv->track) |
| 3320 | chunk_appendf(&trash, "%s/%s,", |
| 3321 | sv->track->proxy->id, sv->track->id); |
| 3322 | else |
| 3323 | chunk_appendf(&trash, ","); |
| 3324 | |
| 3325 | /* type */ |
| 3326 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3327 | |
| 3328 | /* rate */ |
| 3329 | chunk_appendf(&trash, "%u,,%u,", |
| 3330 | read_freq_ctr(&sv->sess_per_sec), |
| 3331 | sv->counters.sps_max); |
| 3332 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3333 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3334 | /* check_status */ |
| 3335 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3336 | |
| 3337 | /* check_code */ |
| 3338 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3339 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3340 | else |
| 3341 | chunk_appendf(&trash, ","); |
| 3342 | |
| 3343 | /* check_duration */ |
| 3344 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3345 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3346 | else |
| 3347 | chunk_appendf(&trash, ","); |
| 3348 | |
| 3349 | } |
| 3350 | else |
| 3351 | chunk_appendf(&trash, ",,,"); |
| 3352 | |
| 3353 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3354 | if (px->mode == PR_MODE_HTTP) { |
| 3355 | for (i=1; i<6; i++) |
| 3356 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3357 | |
| 3358 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3359 | } |
| 3360 | else |
| 3361 | chunk_appendf(&trash, ",,,,,,"); |
| 3362 | |
| 3363 | /* failed health analyses */ |
| 3364 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3365 | |
| 3366 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3367 | chunk_appendf(&trash, ",,,"); |
| 3368 | |
| 3369 | /* errors: cli_aborts, srv_aborts */ |
| 3370 | chunk_appendf(&trash, "%lld,%lld,", |
| 3371 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3372 | |
| 3373 | /* compression: in, out, bypassed, comp_rsp */ |
| 3374 | chunk_appendf(&trash, ",,,,"); |
| 3375 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3376 | /* lastsess */ |
| 3377 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3378 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3379 | /* capture of last check and agent statuses */ |
| 3380 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->check.desc) : ""); |
| 3381 | chunk_appendf(&trash, "%s,", ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->agent.desc) : ""); |
| 3382 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3383 | /* qtime, ctime, rtime, ttime, */ |
| 3384 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3385 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3386 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3387 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3388 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3389 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3390 | /* finish with EOL */ |
| 3391 | chunk_appendf(&trash, "\n"); |
| 3392 | } |
| 3393 | return 1; |
| 3394 | } |
| 3395 | |
| 3396 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3397 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3398 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3399 | */ |
| 3400 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3401 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3402 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3403 | struct chunk src; |
| 3404 | int i; |
| 3405 | |
| 3406 | if (!(px->cap & PR_CAP_BE)) |
| 3407 | return 0; |
| 3408 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3409 | 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] | 3410 | return 0; |
| 3411 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3412 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3413 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3414 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3415 | /* Column sub-heading for Enable or Disable server */ |
| 3416 | chunk_appendf(&trash, "<td></td>"); |
| 3417 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3418 | chunk_appendf(&trash, |
| 3419 | "<td class=ac>" |
| 3420 | /* name */ |
| 3421 | "%s<a name=\"%s/Backend\"></a>" |
| 3422 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3423 | "", |
| 3424 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3425 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3426 | |
| 3427 | if (flags & ST_SHLGNDS) { |
| 3428 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3429 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3430 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3431 | |
| 3432 | /* cookie */ |
| 3433 | if (px->cookie_name) { |
| 3434 | chunk_appendf(&trash, ", cookie: '"); |
| 3435 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3436 | chunk_htmlencode(&trash, &src); |
| 3437 | chunk_appendf(&trash, "'"); |
| 3438 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3439 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3443 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3444 | /* queue : current, max */ |
| 3445 | "<td>%s</td><td>%s</td><td></td>" |
| 3446 | /* sessions rate : current, max, limit */ |
| 3447 | "<td>%s</td><td>%s</td><td></td>" |
| 3448 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3449 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3450 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3451 | 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] | 3452 | |
| 3453 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3454 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3455 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3456 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3457 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3458 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3459 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3460 | U2H(px->be_counters.cum_conn), |
| 3461 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3462 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3463 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3464 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3465 | chunk_appendf(&trash, |
| 3466 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3467 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3468 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3469 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3470 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3471 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3472 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3473 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3474 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3475 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3476 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3477 | U2H(px->be_counters.p.http.cum_req), |
| 3478 | U2H(px->be_counters.p.http.rsp[1]), |
| 3479 | U2H(px->be_counters.p.http.rsp[2]), |
| 3480 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3481 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3482 | (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] | 3483 | U2H(px->be_counters.p.http.rsp[3]), |
| 3484 | U2H(px->be_counters.p.http.rsp[4]), |
| 3485 | U2H(px->be_counters.p.http.rsp[5]), |
| 3486 | U2H(px->be_counters.p.http.rsp[0]), |
| 3487 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3488 | } |
| 3489 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3490 | 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))); |
| 3491 | 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))); |
| 3492 | if (px->mode == PR_MODE_HTTP) |
| 3493 | 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))); |
| 3494 | 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))); |
| 3495 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3496 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3497 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3498 | /* sessions: lbtot, last */ |
| 3499 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3500 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3501 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3502 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3503 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3504 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3505 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3506 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3507 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3508 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3509 | "<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] | 3510 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3511 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3512 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3513 | px->be_counters.comp_in ? |
| 3514 | (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] | 3515 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3516 | |
| 3517 | chunk_appendf(&trash, |
| 3518 | /* denied: req, resp */ |
| 3519 | "<td>%s</td><td>%s</td>" |
| 3520 | /* errors : request, connect */ |
| 3521 | "<td></td><td>%s</td>" |
| 3522 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3523 | "<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] | 3524 | /* warnings: retries, redispatches */ |
| 3525 | "<td>%lld</td><td>%lld</td>" |
| 3526 | /* backend status: reflect backend status (up/down): we display UP |
| 3527 | * if the backend has known working servers or if it has no server at |
| 3528 | * all (eg: for stats). Then we display the total weight, number of |
| 3529 | * active and backups. */ |
| 3530 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3531 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3532 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3533 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3534 | U2H(px->be_counters.failed_conns), |
| 3535 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3536 | px->be_counters.cli_aborts, |
| 3537 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3538 | px->be_counters.retries, px->be_counters.redispatches, |
| 3539 | human_time(now.tv_sec - px->last_change, 1), |
| 3540 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3541 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3542 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3543 | px->srv_act, px->srv_bck); |
| 3544 | |
| 3545 | chunk_appendf(&trash, |
| 3546 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3547 | "<td class=ac> </td><td>%d</td>" |
| 3548 | "<td>%s</td>" |
| 3549 | "<td></td>" |
| 3550 | "</tr>", |
| 3551 | px->down_trans, |
| 3552 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3553 | } |
| 3554 | else { /* CSV mode */ |
| 3555 | chunk_appendf(&trash, |
| 3556 | /* pxid, name */ |
| 3557 | "%s,BACKEND," |
| 3558 | /* queue : current, max */ |
| 3559 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3560 | /* sessions : current, max, limit, total */ |
| 3561 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3562 | /* bytes : in, out */ |
| 3563 | "%lld,%lld," |
| 3564 | /* denied: req, resp */ |
| 3565 | "%lld,%lld," |
| 3566 | /* errors : request, connect, response */ |
| 3567 | ",%lld,%lld," |
| 3568 | /* warnings: retries, redispatches */ |
| 3569 | "%lld,%lld," |
| 3570 | /* backend status: reflect backend status (up/down): we display UP |
| 3571 | * if the backend has known working servers or if it has no server at |
| 3572 | * all (eg: for stats). Then we display the total weight, number of |
| 3573 | * active and backups. */ |
| 3574 | "%s," |
| 3575 | "%d,%d,%d," |
| 3576 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3577 | ",%d,%d,%d,," |
| 3578 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3579 | "%d,%d,0,,%lld,,%d," |
| 3580 | /* rate, rate_lim, rate_max, */ |
| 3581 | "%u,,%u," |
| 3582 | /* check_status, check_code, check_duration */ |
| 3583 | ",,,", |
| 3584 | px->id, |
| 3585 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3586 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3587 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3588 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3589 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3590 | px->be_counters.retries, px->be_counters.redispatches, |
| 3591 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3592 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3593 | px->srv_act, px->srv_bck, |
| 3594 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3595 | px->srv?be_downtime(px):0, |
| 3596 | relative_pid, px->uuid, |
| 3597 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3598 | read_freq_ctr(&px->be_sess_per_sec), |
| 3599 | px->be_counters.sps_max); |
| 3600 | |
| 3601 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3602 | if (px->mode == PR_MODE_HTTP) { |
| 3603 | for (i=1; i<6; i++) |
| 3604 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3605 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3606 | } |
| 3607 | else |
| 3608 | chunk_appendf(&trash, ",,,,,,"); |
| 3609 | |
| 3610 | /* failed health analyses */ |
| 3611 | chunk_appendf(&trash, ","); |
| 3612 | |
| 3613 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3614 | chunk_appendf(&trash, ",,,"); |
| 3615 | |
| 3616 | /* errors: cli_aborts, srv_aborts */ |
| 3617 | chunk_appendf(&trash, "%lld,%lld,", |
| 3618 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3619 | |
| 3620 | /* compression: in, out, bypassed */ |
| 3621 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3622 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3623 | |
| 3624 | /* compression: comp_rsp */ |
| 3625 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3626 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3627 | /* lastsess, last_chk, last_agt, */ |
| 3628 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3629 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3630 | /* qtime, ctime, rtime, ttime, */ |
| 3631 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3632 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 3633 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 3634 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 3635 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 3636 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3637 | /* finish with EOL */ |
| 3638 | chunk_appendf(&trash, "\n"); |
| 3639 | } |
| 3640 | return 1; |
| 3641 | } |
| 3642 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3643 | /* 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] | 3644 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3645 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3646 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3647 | 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] | 3648 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3649 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3650 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3651 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3652 | 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] | 3653 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3654 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3655 | /* 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] | 3656 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3657 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3658 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3659 | 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] | 3660 | 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] | 3661 | } |
| 3662 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3663 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 3664 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | /* print a new table */ |
| 3668 | chunk_appendf(&trash, |
| 3669 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3670 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3671 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3672 | |
| 3673 | chunk_appendf(&trash, |
| 3674 | "<a name=\"%s\"></a>%s" |
| 3675 | "<a class=px href=\"#%s\">%s</a>", |
| 3676 | px->id, |
| 3677 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3678 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3679 | |
| 3680 | if (uri->flags & ST_SHLGNDS) { |
| 3681 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3682 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3683 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3684 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3685 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3689 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3690 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3691 | "</tr>\n" |
| 3692 | "</table>\n" |
| 3693 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3694 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3695 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3696 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3697 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3698 | 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] | 3699 | /* Column heading for Enable or Disable server */ |
| 3700 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3701 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3702 | |
| 3703 | chunk_appendf(&trash, |
| 3704 | "<th rowspan=2></th>" |
| 3705 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3706 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3707 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3708 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3709 | "<th colspan=9>Server</th>" |
| 3710 | "</tr>\n" |
| 3711 | "<tr class=\"titre\">" |
| 3712 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3713 | "<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] | 3714 | "<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] | 3715 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3716 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3717 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3718 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3719 | "<th>Thrtle</th>\n" |
| 3720 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3721 | } |
| 3722 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3723 | /* 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] | 3724 | * 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] | 3725 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3726 | 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] | 3727 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3728 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3729 | chunk_appendf(&trash, "</table>"); |
| 3730 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3731 | 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] | 3732 | /* close the form used to enable/disable this proxy servers */ |
| 3733 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3734 | "Choose the action to perform on the checked servers : " |
| 3735 | "<select name=action>" |
| 3736 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 3737 | "<option value=\"ready\">Set state to READY</option>" |
| 3738 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 3739 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 3740 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3741 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3742 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3743 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3744 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3745 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3746 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3747 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3748 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3749 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3750 | "</select>" |
| 3751 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3752 | " <input type=\"submit\" value=\"Apply\">" |
| 3753 | "</form>", |
| 3754 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3758 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3759 | |
| 3760 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3761 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3762 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3763 | * buffer space, or non-zero if everything completed. This function is used |
| 3764 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3765 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3766 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3767 | 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] | 3768 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3769 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3770 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 3771 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3772 | 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] | 3773 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3774 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3775 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3776 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3777 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3778 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3779 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3780 | if (uri && uri->scope) { |
| 3781 | /* we have a limited scope, we have to check the proxy name */ |
| 3782 | struct stat_scope *scope; |
| 3783 | int len; |
| 3784 | |
| 3785 | len = strlen(px->id); |
| 3786 | scope = uri->scope; |
| 3787 | |
| 3788 | while (scope) { |
| 3789 | /* match exact proxy name */ |
| 3790 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3791 | break; |
| 3792 | |
| 3793 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3794 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3795 | break; |
| 3796 | scope = scope->next; |
| 3797 | } |
| 3798 | |
| 3799 | /* proxy name not found : don't dump anything */ |
| 3800 | if (scope == NULL) |
| 3801 | return 1; |
| 3802 | } |
| 3803 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3804 | /* if the user has requested a limited output and the proxy |
| 3805 | * name does not match, skip it. |
| 3806 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3807 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3808 | 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] | 3809 | return 1; |
| 3810 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3811 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3812 | (appctx->ctx.stats.iid != -1) && |
| 3813 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3814 | return 1; |
| 3815 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3816 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3817 | /* fall through */ |
| 3818 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3819 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3820 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3821 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3822 | if (bi_putchk(rep, &trash) == -1) { |
| 3823 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3824 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3825 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3826 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3827 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3828 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3829 | /* fall through */ |
| 3830 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3831 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3832 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3833 | if (stats_dump_fe_stats(si, px)) { |
| 3834 | if (bi_putchk(rep, &trash) == -1) { |
| 3835 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3836 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3837 | } |
| 3838 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3839 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3840 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3841 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3842 | /* fall through */ |
| 3843 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3844 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3845 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3846 | 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] | 3847 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3848 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3849 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3850 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3851 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3852 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3853 | if (!l->counters) |
| 3854 | continue; |
| 3855 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3856 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3857 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3858 | break; |
| 3859 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3860 | 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] | 3861 | continue; |
| 3862 | } |
| 3863 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3864 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3865 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) { |
| 3866 | if (bi_putchk(rep, &trash) == -1) { |
| 3867 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3868 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3869 | } |
| 3870 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3871 | } |
| 3872 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3873 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3874 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3875 | /* fall through */ |
| 3876 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3877 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3878 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3879 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3880 | enum srv_stats_state sv_state; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3881 | enum srv_stats_colour sv_colour; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3882 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3883 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3884 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3885 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3886 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3887 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3888 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3889 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3890 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3891 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3892 | break; |
| 3893 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3894 | 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] | 3895 | continue; |
| 3896 | } |
| 3897 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3898 | svs = sv; |
| 3899 | while (svs->track) |
| 3900 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3901 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3902 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3903 | if ((svs->check.state & CHK_ST_ENABLED) && |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3904 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3905 | sv_state = SRV_STATS_STATE_UP_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3906 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 3907 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3908 | sv_state = SRV_STATS_STATE_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3909 | sv_colour = SRV_STATS_COLOUR_UP; |
| 3910 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3911 | |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 3912 | if (sv_state == SRV_STATS_STATE_UP && !svs->uweight) |
| 3913 | sv_colour = SRV_STATS_COLOUR_DRAINING; |
| 3914 | |
| 3915 | if (sv->admin & SRV_ADMF_DRAIN) { |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame^] | 3916 | if (svs->agent.state & CHK_ST_ENABLED) |
| 3917 | sv_state = SRV_STATS_STATE_DRAIN_AGENT; |
| 3918 | else if (sv_state == SRV_STATS_STATE_UP_GOING_DOWN) |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3919 | sv_state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 3920 | else |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3921 | sv_state = SRV_STATS_STATE_DRAIN; |
| 3922 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3923 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3924 | if (sv_state == SRV_STATS_STATE_UP && !(svs->check.state & CHK_ST_ENABLED)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3925 | sv_state = SRV_STATS_STATE_NO_CHECK; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3926 | sv_colour = SRV_STATS_COLOUR_NO_CHECK; |
| 3927 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3928 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3929 | else if (sv->state == SRV_ST_STOPPING) { |
| 3930 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3931 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3932 | sv_state = SRV_STATS_STATE_NOLB; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3933 | sv_colour = SRV_STATS_COLOUR_NOLB; |
| 3934 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3935 | sv_state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3936 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 3937 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3938 | } |
| 3939 | else { /* stopped */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3940 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3941 | sv_state = SRV_STATS_STATE_DOWN_AGENT; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3942 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 3943 | } else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3944 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3945 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 3946 | } else if ((svs->agent.state & CHK_ST_ENABLED) || (svs->check.state & CHK_ST_ENABLED)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3947 | sv_state = SRV_STATS_STATE_GOING_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3948 | sv_colour = SRV_STATS_COLOUR_GOING_UP; |
| 3949 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3950 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3951 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 3952 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3953 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3954 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 3955 | 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] | 3956 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3957 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3958 | continue; |
| 3959 | } |
| 3960 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3961 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state, sv_colour)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3962 | if (bi_putchk(rep, &trash) == -1) { |
| 3963 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3964 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3965 | } |
| 3966 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3967 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3968 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3969 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3970 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3971 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3972 | case STAT_PX_ST_BE: |
| 3973 | /* print the backend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3974 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) { |
| 3975 | if (bi_putchk(rep, &trash) == -1) { |
| 3976 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3977 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3978 | } |
| 3979 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3980 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3981 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3982 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3983 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3984 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3985 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3986 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3987 | if (bi_putchk(rep, &trash) == -1) { |
| 3988 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3989 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3990 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3991 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3992 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3993 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3994 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3995 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3996 | case STAT_PX_ST_FIN: |
| 3997 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3998 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3999 | default: |
| 4000 | /* unknown state, we should put an abort() here ! */ |
| 4001 | return 1; |
| 4002 | } |
| 4003 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4004 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4005 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4006 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4007 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4008 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4009 | { |
| 4010 | /* WARNING! This must fit in the first buffer !!! */ |
| 4011 | chunk_appendf(&trash, |
| 4012 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4013 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4014 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4015 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4016 | "<style type=\"text/css\"><!--\n" |
| 4017 | "body {" |
| 4018 | " font-family: arial, helvetica, sans-serif;" |
| 4019 | " font-size: 12px;" |
| 4020 | " font-weight: normal;" |
| 4021 | " color: black;" |
| 4022 | " background: white;" |
| 4023 | "}\n" |
| 4024 | "th,td {" |
| 4025 | " font-size: 10px;" |
| 4026 | "}\n" |
| 4027 | "h1 {" |
| 4028 | " font-size: x-large;" |
| 4029 | " margin-bottom: 0.5em;" |
| 4030 | "}\n" |
| 4031 | "h2 {" |
| 4032 | " font-family: helvetica, arial;" |
| 4033 | " font-size: x-large;" |
| 4034 | " font-weight: bold;" |
| 4035 | " font-style: italic;" |
| 4036 | " color: #6020a0;" |
| 4037 | " margin-top: 0em;" |
| 4038 | " margin-bottom: 0em;" |
| 4039 | "}\n" |
| 4040 | "h3 {" |
| 4041 | " font-family: helvetica, arial;" |
| 4042 | " font-size: 16px;" |
| 4043 | " font-weight: bold;" |
| 4044 | " color: #b00040;" |
| 4045 | " background: #e8e8d0;" |
| 4046 | " margin-top: 0em;" |
| 4047 | " margin-bottom: 0em;" |
| 4048 | "}\n" |
| 4049 | "li {" |
| 4050 | " margin-top: 0.25em;" |
| 4051 | " margin-right: 2em;" |
| 4052 | "}\n" |
| 4053 | ".hr {margin-top: 0.25em;" |
| 4054 | " border-color: black;" |
| 4055 | " border-bottom-style: solid;" |
| 4056 | "}\n" |
| 4057 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4058 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4059 | ".frontend {background: #e8e8d0;}\n" |
| 4060 | ".socket {background: #d0d0d0;}\n" |
| 4061 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4062 | ".active_down {background: #ff9090;}\n" |
| 4063 | ".active_going_up {background: #ffd020;}\n" |
| 4064 | ".active_going_down {background: #ffffa0;}\n" |
| 4065 | ".active_up {background: #c0ffc0;}\n" |
| 4066 | ".active_nolb {background: #20a0ff;}\n" |
| 4067 | ".active_draining {background: #20a0FF;}\n" |
| 4068 | ".active_no_check {background: #e0e0e0;}\n" |
| 4069 | ".backup_down {background: #ff9090;}\n" |
| 4070 | ".backup_going_up {background: #ff80ff;}\n" |
| 4071 | ".backup_going_down {background: #c060ff;}\n" |
| 4072 | ".backup_up {background: #b0d0ff;}\n" |
| 4073 | ".backup_nolb {background: #90b0e0;}\n" |
| 4074 | ".backup_draining {background: #cc9900;}\n" |
| 4075 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4076 | ".maintain {background: #c07820;}\n" |
| 4077 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4078 | "\n" |
| 4079 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4080 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4081 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4082 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4083 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4084 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4085 | "\n" |
| 4086 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4087 | "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" |
| 4088 | "table.tbl td.ac { text-align: center;}\n" |
| 4089 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4090 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4091 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4092 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4093 | "\n" |
| 4094 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4095 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4096 | "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] | 4097 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4098 | "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] | 4099 | "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] | 4100 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4101 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4102 | " display:block;\n" |
| 4103 | " visibility:hidden;\n" |
| 4104 | " z-index:2147483647;\n" |
| 4105 | " position:absolute;\n" |
| 4106 | " padding:2px 4px 3px;\n" |
| 4107 | " background:#f0f060; color:#000000;\n" |
| 4108 | " border:1px solid #7040c0;\n" |
| 4109 | " white-space:nowrap;\n" |
| 4110 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4111 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4112 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4113 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4114 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4115 | "-->\n" |
| 4116 | "</style></head>\n", |
| 4117 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4118 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4119 | ); |
| 4120 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4121 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4122 | /* 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] | 4123 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4124 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4125 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4126 | 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] | 4127 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4128 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4129 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4130 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4131 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4132 | /* WARNING! this has to fit the first packet too. |
| 4133 | * We are around 3.5 kB, add adding entries will |
| 4134 | * become tricky if we want to support 4kB buffers ! |
| 4135 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4136 | chunk_appendf(&trash, |
| 4137 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4138 | PRODUCT_NAME "%s</a></h1>\n" |
| 4139 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4140 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4141 | "<h3>> General process information</h3>\n" |
| 4142 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4143 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4144 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4145 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4146 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4147 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4148 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4149 | "</td><td align=\"center\" nowrap>\n" |
| 4150 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4151 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4152 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4153 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4154 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4155 | "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4156 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4157 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4158 | "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4159 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4160 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4161 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4162 | "</tr><tr>\n" |
| 4163 | "<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] | 4164 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4165 | "<td class=\"active_draining\"></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] | 4166 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4167 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4168 | "</td>" |
| 4169 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4170 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4171 | "", |
| 4172 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4173 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4174 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4175 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4176 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4177 | pid, relative_pid, global.nbproc, |
| 4178 | up / 86400, (up % 86400) / 3600, |
| 4179 | (up % 3600) / 60, (up % 60), |
| 4180 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4181 | global.rlimit_memmax ? " MB" : "", |
| 4182 | global.rlimit_nofile, |
| 4183 | global.maxsock, global.maxconn, global.maxpipes, |
| 4184 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4185 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4186 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4187 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4188 | /* 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] | 4189 | 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] | 4190 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4191 | |
| 4192 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4193 | "<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] | 4194 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4195 | STAT_SCOPE_TXT_MAXLEN); |
| 4196 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4197 | /* 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] | 4198 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4199 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4200 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4201 | 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] | 4202 | 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] | 4203 | } |
| 4204 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4205 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4206 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4207 | "<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] | 4208 | uri->uri_prefix, |
| 4209 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4210 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4211 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4212 | else |
| 4213 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4214 | "<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] | 4215 | uri->uri_prefix, |
| 4216 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4217 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4218 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4219 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4220 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4221 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4222 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4223 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4224 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4225 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4226 | "", |
| 4227 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4228 | else |
| 4229 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4230 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4231 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4232 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4233 | ";norefresh", |
| 4234 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4235 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4236 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4237 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4238 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4239 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4240 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4241 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4242 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4243 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4244 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4245 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4246 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4247 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4248 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4249 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4250 | chunk_appendf(&trash, |
| 4251 | "</ul></td>" |
| 4252 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4253 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4254 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4255 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4256 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4257 | "</ul>" |
| 4258 | "</td>" |
| 4259 | "</tr></table>\n" |
| 4260 | "" |
| 4261 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4262 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4263 | if (appctx->ctx.stats.st_code) { |
| 4264 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4265 | case STAT_STATUS_DONE: |
| 4266 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4267 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4268 | "<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] | 4269 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4270 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4271 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4272 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4273 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4274 | break; |
| 4275 | case STAT_STATUS_NONE: |
| 4276 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4277 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4278 | "<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] | 4279 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4280 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4281 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4282 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4283 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4284 | break; |
| 4285 | case STAT_STATUS_PART: |
| 4286 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4287 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4288 | "<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] | 4289 | "Action partially processed.<br>" |
| 4290 | "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] | 4291 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4292 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4293 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4294 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4295 | break; |
| 4296 | case STAT_STATUS_ERRP: |
| 4297 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4298 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4299 | "<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] | 4300 | "Action not processed because of invalid parameters." |
| 4301 | "<ul>" |
| 4302 | "<li>The action is maybe unknown.</li>" |
| 4303 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4304 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4305 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4306 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4307 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4308 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4309 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4310 | break; |
| 4311 | case STAT_STATUS_EXCD: |
| 4312 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4313 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4314 | "<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] | 4315 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4316 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4317 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4318 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4319 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4320 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4321 | break; |
| 4322 | case STAT_STATUS_DENY: |
| 4323 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4324 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4325 | "<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] | 4326 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4327 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4328 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4329 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4330 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4331 | break; |
| 4332 | default: |
| 4333 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4334 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4335 | "<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] | 4336 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4337 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4338 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4339 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4340 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4341 | } |
| 4342 | chunk_appendf(&trash, "<p>\n"); |
| 4343 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4344 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4345 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4346 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4347 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4348 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4349 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4350 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4351 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4352 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4353 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4354 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4355 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4356 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4357 | * 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] | 4358 | * 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] | 4359 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4360 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4361 | 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] | 4362 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4363 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4364 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4365 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4366 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4367 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4368 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4369 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4370 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4371 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4372 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4373 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4374 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4375 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4376 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4377 | else |
| 4378 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4379 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4380 | if (bi_putchk(rep, &trash) == -1) { |
| 4381 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4382 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4383 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4384 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4385 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4386 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4387 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4388 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4389 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4390 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4391 | if (bi_putchk(rep, &trash) == -1) { |
| 4392 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4393 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4394 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4395 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4396 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4397 | appctx->ctx.stats.px = proxy; |
| 4398 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4399 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4400 | /* fall through */ |
| 4401 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4402 | case STAT_ST_LIST: |
| 4403 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4404 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4405 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4406 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4407 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4408 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4409 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4410 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4411 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4412 | 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] | 4413 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4414 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4415 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4416 | appctx->ctx.stats.px = px->next; |
| 4417 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4418 | } |
| 4419 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4420 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4421 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4422 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4423 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4424 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4425 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4426 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4427 | if (bi_putchk(rep, &trash) == -1) { |
| 4428 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4429 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4430 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4431 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4432 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4433 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4434 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4435 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4436 | case STAT_ST_FIN: |
| 4437 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4438 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4439 | default: |
| 4440 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4441 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4442 | return -1; |
| 4443 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4444 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4445 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4446 | /* We reached the stats page through a POST request. The appctx is |
| 4447 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4448 | * Parse the posted data and enable/disable servers if necessary. |
| 4449 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4450 | */ |
| 4451 | static int stats_process_http_post(struct stream_interface *si) |
| 4452 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4453 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4454 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4455 | |
| 4456 | struct proxy *px = NULL; |
| 4457 | struct server *sv = NULL; |
| 4458 | |
| 4459 | char key[LINESIZE]; |
| 4460 | int action = ST_ADM_ACTION_NONE; |
| 4461 | int reprocess = 0; |
| 4462 | |
| 4463 | int total_servers = 0; |
| 4464 | int altered_servers = 0; |
| 4465 | |
| 4466 | char *first_param, *cur_param, *next_param, *end_params; |
| 4467 | char *st_cur_param = NULL; |
| 4468 | char *st_next_param = NULL; |
| 4469 | |
| 4470 | struct chunk *temp; |
| 4471 | int reql; |
| 4472 | |
| 4473 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4474 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4475 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4476 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4477 | goto out; |
| 4478 | } |
| 4479 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4480 | 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] | 4481 | if (reql <= 0) { |
| 4482 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4483 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4484 | return 0; |
| 4485 | } |
| 4486 | |
| 4487 | first_param = temp->str; |
| 4488 | end_params = temp->str + reql; |
| 4489 | cur_param = next_param = end_params; |
| 4490 | *end_params = '\0'; |
| 4491 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4492 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4493 | |
| 4494 | /* |
| 4495 | * Parse the parameters in reverse order to only store the last value. |
| 4496 | * From the html form, the backend and the action are at the end. |
| 4497 | */ |
| 4498 | while (cur_param > first_param) { |
| 4499 | char *value; |
| 4500 | int poffset, plen; |
| 4501 | |
| 4502 | cur_param--; |
| 4503 | |
| 4504 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4505 | reprocess_servers: |
| 4506 | /* Parse the key */ |
| 4507 | poffset = (cur_param != first_param ? 1 : 0); |
| 4508 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4509 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4510 | strncpy(key, cur_param + poffset, plen); |
| 4511 | key[plen - 1] = '\0'; |
| 4512 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4513 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4514 | goto out; |
| 4515 | } |
| 4516 | |
| 4517 | /* Parse the value */ |
| 4518 | value = key; |
| 4519 | while (*value != '\0' && *value != '=') { |
| 4520 | value++; |
| 4521 | } |
| 4522 | if (*value == '=') { |
| 4523 | /* Ok, a value is found, we can mark the end of the key */ |
| 4524 | *value++ = '\0'; |
| 4525 | } |
| 4526 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4527 | break; |
| 4528 | |
| 4529 | /* Now we can check the key to see what to do */ |
| 4530 | if (!px && (strcmp(key, "b") == 0)) { |
| 4531 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4532 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4533 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4534 | goto out; |
| 4535 | } |
| 4536 | } |
| 4537 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4538 | if (strcmp(value, "ready") == 0) { |
| 4539 | action = ST_ADM_ACTION_READY; |
| 4540 | } |
| 4541 | else if (strcmp(value, "drain") == 0) { |
| 4542 | action = ST_ADM_ACTION_DRAIN; |
| 4543 | } |
| 4544 | else if (strcmp(value, "maint") == 0) { |
| 4545 | action = ST_ADM_ACTION_MAINT; |
| 4546 | } |
| 4547 | else if (strcmp(value, "shutdown") == 0) { |
| 4548 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4549 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4550 | else if (strcmp(value, "dhlth") == 0) { |
| 4551 | action = ST_ADM_ACTION_DHLTH; |
| 4552 | } |
| 4553 | else if (strcmp(value, "ehlth") == 0) { |
| 4554 | action = ST_ADM_ACTION_EHLTH; |
| 4555 | } |
| 4556 | else if (strcmp(value, "hrunn") == 0) { |
| 4557 | action = ST_ADM_ACTION_HRUNN; |
| 4558 | } |
| 4559 | else if (strcmp(value, "hnolb") == 0) { |
| 4560 | action = ST_ADM_ACTION_HNOLB; |
| 4561 | } |
| 4562 | else if (strcmp(value, "hdown") == 0) { |
| 4563 | action = ST_ADM_ACTION_HDOWN; |
| 4564 | } |
| 4565 | else if (strcmp(value, "dagent") == 0) { |
| 4566 | action = ST_ADM_ACTION_DAGENT; |
| 4567 | } |
| 4568 | else if (strcmp(value, "eagent") == 0) { |
| 4569 | action = ST_ADM_ACTION_EAGENT; |
| 4570 | } |
| 4571 | else if (strcmp(value, "arunn") == 0) { |
| 4572 | action = ST_ADM_ACTION_ARUNN; |
| 4573 | } |
| 4574 | else if (strcmp(value, "adown") == 0) { |
| 4575 | action = ST_ADM_ACTION_ADOWN; |
| 4576 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4577 | /* else these are the old supported methods */ |
| 4578 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4579 | action = ST_ADM_ACTION_DISABLE; |
| 4580 | } |
| 4581 | else if (strcmp(value, "enable") == 0) { |
| 4582 | action = ST_ADM_ACTION_ENABLE; |
| 4583 | } |
| 4584 | else if (strcmp(value, "stop") == 0) { |
| 4585 | action = ST_ADM_ACTION_STOP; |
| 4586 | } |
| 4587 | else if (strcmp(value, "start") == 0) { |
| 4588 | action = ST_ADM_ACTION_START; |
| 4589 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4590 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4591 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4592 | goto out; |
| 4593 | } |
| 4594 | } |
| 4595 | else if (strcmp(key, "s") == 0) { |
| 4596 | if (!(px && action)) { |
| 4597 | /* |
| 4598 | * Indicates that we'll need to reprocess the parameters |
| 4599 | * as soon as backend and action are known |
| 4600 | */ |
| 4601 | if (!reprocess) { |
| 4602 | st_cur_param = cur_param; |
| 4603 | st_next_param = next_param; |
| 4604 | } |
| 4605 | reprocess = 1; |
| 4606 | } |
| 4607 | else if ((sv = findserver(px, value)) != NULL) { |
| 4608 | switch (action) { |
| 4609 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4610 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4611 | altered_servers++; |
| 4612 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4613 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4614 | } |
| 4615 | break; |
| 4616 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4617 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4618 | altered_servers++; |
| 4619 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4620 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4621 | } |
| 4622 | break; |
| 4623 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4624 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 4625 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4626 | altered_servers++; |
| 4627 | total_servers++; |
| 4628 | } |
| 4629 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4630 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4631 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 4632 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4633 | altered_servers++; |
| 4634 | total_servers++; |
| 4635 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4636 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4637 | case ST_ADM_ACTION_DHLTH: |
| 4638 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4639 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4640 | altered_servers++; |
| 4641 | total_servers++; |
| 4642 | } |
| 4643 | break; |
| 4644 | case ST_ADM_ACTION_EHLTH: |
| 4645 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4646 | sv->check.state |= CHK_ST_ENABLED; |
| 4647 | altered_servers++; |
| 4648 | total_servers++; |
| 4649 | } |
| 4650 | break; |
| 4651 | case ST_ADM_ACTION_HRUNN: |
| 4652 | if (!(sv->track)) { |
| 4653 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4654 | srv_set_running(sv, "changed from Web interface"); |
| 4655 | altered_servers++; |
| 4656 | total_servers++; |
| 4657 | } |
| 4658 | break; |
| 4659 | case ST_ADM_ACTION_HNOLB: |
| 4660 | if (!(sv->track)) { |
| 4661 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4662 | srv_set_stopping(sv, "changed from Web interface"); |
| 4663 | altered_servers++; |
| 4664 | total_servers++; |
| 4665 | } |
| 4666 | break; |
| 4667 | case ST_ADM_ACTION_HDOWN: |
| 4668 | if (!(sv->track)) { |
| 4669 | sv->check.health = 0; |
| 4670 | srv_set_stopped(sv, "changed from Web interface"); |
| 4671 | altered_servers++; |
| 4672 | total_servers++; |
| 4673 | } |
| 4674 | break; |
| 4675 | case ST_ADM_ACTION_DAGENT: |
| 4676 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4677 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4678 | altered_servers++; |
| 4679 | total_servers++; |
| 4680 | } |
| 4681 | break; |
| 4682 | case ST_ADM_ACTION_EAGENT: |
| 4683 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4684 | sv->agent.state |= CHK_ST_ENABLED; |
| 4685 | altered_servers++; |
| 4686 | total_servers++; |
| 4687 | } |
| 4688 | break; |
| 4689 | case ST_ADM_ACTION_ARUNN: |
| 4690 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4691 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 4692 | srv_set_running(sv, "changed from Web interface"); |
| 4693 | altered_servers++; |
| 4694 | total_servers++; |
| 4695 | } |
| 4696 | break; |
| 4697 | case ST_ADM_ACTION_ADOWN: |
| 4698 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4699 | sv->agent.health = 0; |
| 4700 | srv_set_stopped(sv, "changed from Web interface"); |
| 4701 | altered_servers++; |
| 4702 | total_servers++; |
| 4703 | } |
| 4704 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4705 | case ST_ADM_ACTION_READY: |
| 4706 | srv_adm_set_ready(sv); |
| 4707 | altered_servers++; |
| 4708 | total_servers++; |
| 4709 | break; |
| 4710 | case ST_ADM_ACTION_DRAIN: |
| 4711 | srv_adm_set_drain(sv); |
| 4712 | altered_servers++; |
| 4713 | total_servers++; |
| 4714 | break; |
| 4715 | case ST_ADM_ACTION_MAINT: |
| 4716 | srv_adm_set_maint(sv); |
| 4717 | altered_servers++; |
| 4718 | total_servers++; |
| 4719 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4720 | case ST_ADM_ACTION_SHUTDOWN: |
| 4721 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4722 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4723 | |
| 4724 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4725 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 4726 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4727 | |
| 4728 | altered_servers++; |
| 4729 | total_servers++; |
| 4730 | } |
| 4731 | break; |
| 4732 | } |
| 4733 | } else { |
| 4734 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4735 | total_servers++; |
| 4736 | } |
| 4737 | } |
| 4738 | if (reprocess && px && action) { |
| 4739 | /* Now, we know the backend and the action chosen by the user. |
| 4740 | * We can safely restart from the first server parameter |
| 4741 | * to reprocess them |
| 4742 | */ |
| 4743 | cur_param = st_cur_param; |
| 4744 | next_param = st_next_param; |
| 4745 | reprocess = 0; |
| 4746 | goto reprocess_servers; |
| 4747 | } |
| 4748 | |
| 4749 | next_param = cur_param; |
| 4750 | } |
| 4751 | } |
| 4752 | |
| 4753 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4754 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4755 | } |
| 4756 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4757 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4758 | } |
| 4759 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4760 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4761 | } |
| 4762 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4763 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4764 | } |
| 4765 | out: |
| 4766 | return 1; |
| 4767 | } |
| 4768 | |
| 4769 | |
| 4770 | static int stats_send_http_headers(struct stream_interface *si) |
| 4771 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4772 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4773 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4774 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4775 | |
| 4776 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4777 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4778 | "Cache-Control: no-cache\r\n" |
| 4779 | "Connection: close\r\n" |
| 4780 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4781 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4782 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4783 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4784 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4785 | uri->refresh); |
| 4786 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4787 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4788 | |
| 4789 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4790 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4791 | else |
| 4792 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4793 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4794 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4795 | s->logs.tv_request = now; |
| 4796 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4797 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 4798 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4799 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4800 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4801 | |
| 4802 | return 1; |
| 4803 | } |
| 4804 | |
| 4805 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4806 | { |
| 4807 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4808 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4809 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4810 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4811 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4812 | /* 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] | 4813 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4814 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4815 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4816 | 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] | 4817 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | /* We don't want to land on the posted stats page because a refresh will |
| 4821 | * repost the data. We don't want this to happen on accident so we redirect |
| 4822 | * the browse to the stats page with a GET. |
| 4823 | */ |
| 4824 | chunk_printf(&trash, |
| 4825 | "HTTP/1.1 303 See Other\r\n" |
| 4826 | "Cache-Control: no-cache\r\n" |
| 4827 | "Content-Type: text/plain\r\n" |
| 4828 | "Connection: close\r\n" |
| 4829 | "Location: %s;st=%s%s%s%s\r\n" |
| 4830 | "\r\n", |
| 4831 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4832 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4833 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4834 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4835 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4836 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4837 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4838 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4839 | scope_txt); |
| 4840 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4841 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4842 | s->logs.tv_request = now; |
| 4843 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4844 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 4845 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4846 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4847 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4848 | |
| 4849 | return 1; |
| 4850 | } |
| 4851 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4852 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4853 | * 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] | 4854 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4855 | * automatically unregisters itself once transfer is complete. |
| 4856 | */ |
| 4857 | static void http_stats_io_handler(struct stream_interface *si) |
| 4858 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4859 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4860 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4861 | struct channel *req = si_oc(si); |
| 4862 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4863 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4864 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4865 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4866 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4867 | /* check that the output is not closed */ |
| 4868 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4869 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4870 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4871 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4872 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4873 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4874 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4875 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4876 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4877 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4878 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4879 | } |
| 4880 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4881 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4882 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4883 | unsigned int data_len; |
| 4884 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 4885 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4886 | |
| 4887 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4888 | /* One difficulty we're facing is that we must prevent |
| 4889 | * the input data from being automatically forwarded to |
| 4890 | * the output area. For this, we temporarily disable |
| 4891 | * forwarding on the channel. |
| 4892 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4893 | last_fwd = si_ic(si)->to_forward; |
| 4894 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4895 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4896 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4897 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4898 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4899 | goto fail; |
| 4900 | } |
| 4901 | } |
| 4902 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4903 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4904 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4905 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4906 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4907 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4908 | |
| 4909 | /* Now we must either adjust or remove the chunk size. This is |
| 4910 | * not easy because the chunk size might wrap at the end of the |
| 4911 | * buffer, so we pretend we have nothing in the buffer, we write |
| 4912 | * the size, then restore the buffer's contents. Note that we can |
| 4913 | * only do that because no forwarding is scheduled on the stats |
| 4914 | * applet. |
| 4915 | */ |
| 4916 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4917 | si_ic(si)->total -= (last_len - prev_len); |
| 4918 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4919 | |
| 4920 | if (last_len != data_len) { |
| 4921 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4922 | if (bi_putchk(si_ic(si), &trash) == -1) |
| 4923 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4924 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4925 | si_ic(si)->total += (last_len - data_len); |
| 4926 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4927 | } |
| 4928 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4929 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4930 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4931 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4932 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4933 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4934 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4935 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4936 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4937 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4938 | } |
| 4939 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4940 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4941 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4942 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4943 | } |
| 4944 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4945 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 4946 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4947 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4948 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 4949 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4950 | goto fail; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4951 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4952 | } |
| 4953 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4954 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4955 | res->flags |= CF_READ_NULL; |
| 4956 | si_shutr(si); |
| 4957 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4958 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4959 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4960 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4961 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4962 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4963 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4964 | si_shutr(si); |
| 4965 | res->flags |= CF_READ_NULL; |
| 4966 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4967 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4968 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4969 | fail: |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4970 | /* update all other flags and resync with the other side */ |
| 4971 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4972 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4973 | /* we don't want to expire timeouts while we're processing requests */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4974 | si_ic(si)->rex = TICK_ETERNITY; |
| 4975 | si_oc(si)->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4976 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4977 | out: |
| 4978 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4979 | /* check that we have released everything then unregister */ |
| 4980 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4981 | } |
| 4982 | } |
| 4983 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4984 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4985 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4986 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 4987 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4988 | return "NONE"; |
| 4989 | return conn->ctrl->name; |
| 4990 | } |
| 4991 | |
| 4992 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4993 | { |
| 4994 | static char ptr[17]; |
| 4995 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 4996 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4997 | return "NONE"; |
| 4998 | |
| 4999 | if (conn->xprt == &raw_sock) |
| 5000 | return "RAW"; |
| 5001 | |
| 5002 | #ifdef USE_OPENSSL |
| 5003 | if (conn->xprt == &ssl_sock) |
| 5004 | return "SSL"; |
| 5005 | #endif |
| 5006 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5007 | return ptr; |
| 5008 | } |
| 5009 | |
| 5010 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5011 | { |
| 5012 | static char ptr[17]; |
| 5013 | |
| 5014 | if (!conn->data) |
| 5015 | return "NONE"; |
| 5016 | |
| 5017 | if (conn->data == &sess_conn_cb) |
| 5018 | return "SESS"; |
| 5019 | |
| 5020 | if (conn->data == &si_conn_cb) |
| 5021 | return "STRM"; |
| 5022 | |
| 5023 | if (conn->data == &check_conn_cb) |
| 5024 | return "CHCK"; |
| 5025 | |
| 5026 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5027 | return ptr; |
| 5028 | } |
| 5029 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5030 | /* This function dumps a complete stream state onto the stream interface's |
| 5031 | * 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] | 5032 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5033 | * 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] | 5034 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5035 | 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] | 5036 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5037 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5038 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5039 | extern const char *monthname[12]; |
| 5040 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5041 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5042 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5043 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5044 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5045 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5046 | 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] | 5047 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5048 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5049 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5050 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5051 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5052 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5053 | appctx->ctx.sess.uid = 0; |
| 5054 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5055 | return 1; |
| 5056 | } |
| 5057 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5058 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5059 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5060 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5061 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5062 | /* fall through */ |
| 5063 | |
| 5064 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5065 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5066 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5067 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5068 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5069 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5070 | 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] | 5071 | sess->uniq_id, |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5072 | 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] | 5073 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5074 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5075 | 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] | 5076 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5077 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5078 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5079 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5080 | break; |
| 5081 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5082 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5083 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5084 | default: |
| 5085 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5086 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5087 | break; |
| 5088 | } |
| 5089 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5090 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5091 | " 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] | 5092 | 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] | 5093 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5094 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5095 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5096 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5097 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5098 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5099 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5100 | if (conn) |
| 5101 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5102 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5103 | 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] | 5104 | case AF_INET: |
| 5105 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5106 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5107 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5108 | break; |
| 5109 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5110 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5111 | break; |
| 5112 | default: |
| 5113 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5114 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5115 | break; |
| 5116 | } |
| 5117 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5118 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5119 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5120 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5121 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5122 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5123 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5124 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5125 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5126 | conn = objt_conn(sess->si[1].end); |
| 5127 | if (conn) |
| 5128 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5129 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5130 | 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] | 5131 | case AF_INET: |
| 5132 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5133 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5134 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5135 | break; |
| 5136 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5137 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5138 | break; |
| 5139 | default: |
| 5140 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5141 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5142 | break; |
| 5143 | } |
| 5144 | |
| 5145 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5146 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5147 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5148 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5149 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5150 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5151 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5152 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5153 | if (conn) |
| 5154 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5155 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5156 | 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] | 5157 | case AF_INET: |
| 5158 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5159 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5160 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5161 | break; |
| 5162 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5163 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5164 | break; |
| 5165 | default: |
| 5166 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5167 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5168 | break; |
| 5169 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5170 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5171 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5172 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5173 | sess->task, |
| 5174 | sess->task->state, |
| 5175 | sess->task->nice, sess->task->calls, |
| 5176 | sess->task->expire ? |
| 5177 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5178 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5179 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5180 | task_in_rq(sess->task) ? ", running" : ""); |
| 5181 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5182 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5183 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5184 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5185 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5186 | if (sess->txn) |
| 5187 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5188 | " 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] | 5189 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5190 | 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] | 5191 | |
| 5192 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5193 | " 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] | 5194 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5195 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5196 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5197 | obj_type_name(sess->si[0].end), |
| 5198 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5199 | sess->si[0].exp ? |
| 5200 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5201 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5202 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5203 | sess->si[0].err_type); |
| 5204 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5205 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5206 | " 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] | 5207 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5208 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5209 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5210 | obj_type_name(sess->si[1].end), |
| 5211 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5212 | sess->si[1].exp ? |
| 5213 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5214 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5215 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5216 | sess->si[1].err_type); |
| 5217 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5218 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5219 | chunk_appendf(&trash, |
| 5220 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5221 | conn, |
| 5222 | get_conn_ctrl_name(conn), |
| 5223 | get_conn_xprt_name(conn), |
| 5224 | get_conn_data_name(conn), |
| 5225 | obj_type_name(conn->target), |
| 5226 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5227 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5228 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5229 | " 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] | 5230 | conn->flags, |
| 5231 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5232 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5233 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5234 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5235 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5236 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5237 | chunk_appendf(&trash, |
| 5238 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5239 | tmpctx, |
| 5240 | tmpctx->st0, |
| 5241 | tmpctx->st1, |
| 5242 | tmpctx->st2, |
| 5243 | tmpctx->applet->name); |
| 5244 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5245 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5246 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5247 | chunk_appendf(&trash, |
| 5248 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5249 | conn, |
| 5250 | get_conn_ctrl_name(conn), |
| 5251 | get_conn_xprt_name(conn), |
| 5252 | get_conn_data_name(conn), |
| 5253 | obj_type_name(conn->target), |
| 5254 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5255 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5256 | chunk_appendf(&trash, |
| 5257 | " 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] | 5258 | conn->flags, |
| 5259 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5260 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5261 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5262 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5263 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5264 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5265 | chunk_appendf(&trash, |
| 5266 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5267 | tmpctx, |
| 5268 | tmpctx->st0, |
| 5269 | tmpctx->st1, |
| 5270 | tmpctx->st2, |
| 5271 | tmpctx->applet->name); |
| 5272 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5273 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5274 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5275 | " 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] | 5276 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5277 | &sess->req, |
| 5278 | sess->req.flags, sess->req.analysers, |
| 5279 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5280 | sess->req.to_forward, sess->req.total, |
| 5281 | sess->req.analyse_exp ? |
| 5282 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5283 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5284 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5285 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5286 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5287 | sess->req.rex ? |
| 5288 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5289 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5290 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5291 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5292 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5293 | " 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] | 5294 | sess->req.wex ? |
| 5295 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5296 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5297 | sess->req.buf, |
| 5298 | sess->req.buf->data, sess->req.buf->o, |
| 5299 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5300 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5301 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5302 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5303 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5304 | " 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] | 5305 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5306 | &sess->res, |
| 5307 | sess->res.flags, sess->res.analysers, |
| 5308 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5309 | sess->res.to_forward, sess->res.total, |
| 5310 | sess->res.analyse_exp ? |
| 5311 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5312 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5313 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5314 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5315 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5316 | sess->res.rex ? |
| 5317 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5318 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5319 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5320 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5321 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5322 | " 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] | 5323 | sess->res.wex ? |
| 5324 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5325 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5326 | sess->res.buf, |
| 5327 | sess->res.buf->data, sess->res.buf->o, |
| 5328 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5329 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5330 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5331 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5332 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5333 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5334 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5335 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5336 | |
| 5337 | /* use other states to dump the contents */ |
| 5338 | } |
| 5339 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5340 | appctx->ctx.sess.uid = 0; |
| 5341 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5342 | return 1; |
| 5343 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5344 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5345 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5346 | { |
| 5347 | struct appctx *appctx = __objt_appctx(si->end); |
| 5348 | |
| 5349 | switch (appctx->st2) { |
| 5350 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5351 | /* Display the column headers. If the message cannot be sent, |
| 5352 | * quit the fucntion with returning 0. The function is called |
| 5353 | * later and restart at the state "STAT_ST_INIT". |
| 5354 | */ |
| 5355 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5356 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5357 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5358 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5359 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5360 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5361 | |
| 5362 | /* Now, we start the browsing of the references lists. |
| 5363 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5364 | * avalaible field of this pointer is <list>. It is used with the function |
| 5365 | * pat_list_get_next() for retruning the first avalaible entry |
| 5366 | */ |
| 5367 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5368 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5369 | appctx->ctx.map.display_flags); |
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 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5375 | chunk_reset(&trash); |
| 5376 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5377 | /* Build messages. If the reference is used by another category than |
| 5378 | * the listed categorie, display the information in the massage. |
| 5379 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5380 | 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] | 5381 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5382 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5383 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5384 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5385 | /* let's try again later from this stream. We add ourselves into |
| 5386 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5387 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5388 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5389 | return 0; |
| 5390 | } |
| 5391 | |
| 5392 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5393 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5394 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5395 | } |
| 5396 | |
| 5397 | appctx->st2 = STAT_ST_FIN; |
| 5398 | /* fall through */ |
| 5399 | |
| 5400 | default: |
| 5401 | appctx->st2 = STAT_ST_FIN; |
| 5402 | return 1; |
| 5403 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5404 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5405 | } |
| 5406 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5407 | static int stats_map_lookup(struct stream_interface *si) |
| 5408 | { |
| 5409 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5410 | struct sample sample; |
| 5411 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5412 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5413 | |
| 5414 | switch (appctx->st2) { |
| 5415 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5416 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5417 | 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] | 5418 | 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] | 5419 | appctx->st2 = STAT_ST_LIST; |
| 5420 | /* fall through */ |
| 5421 | |
| 5422 | case STAT_ST_LIST: |
| 5423 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5424 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5425 | /* initialise chunk to build new message */ |
| 5426 | chunk_reset(&trash); |
| 5427 | |
| 5428 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 5429 | sample.type = SMP_T_STR; |
| 5430 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5431 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 5432 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5433 | if (appctx->ctx.map.expr->pat_head->match && |
| 5434 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5435 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5436 | else |
| 5437 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5438 | |
| 5439 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5440 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5441 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5442 | break; |
| 5443 | if (match_method >= PAT_MATCH_NUM) |
| 5444 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5445 | else |
| 5446 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5447 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5448 | /* case sensitive */ |
| 5449 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5450 | chunk_appendf(&trash, ", case=insensitive"); |
| 5451 | else |
| 5452 | chunk_appendf(&trash, ", case=sensitive"); |
| 5453 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5454 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5455 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5456 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5457 | chunk_appendf(&trash, ", found=no"); |
| 5458 | else |
| 5459 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | /* Display match and match info */ |
| 5463 | else { |
| 5464 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5465 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5466 | chunk_appendf(&trash, ", found=yes"); |
| 5467 | else |
| 5468 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5469 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5470 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5471 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5472 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5473 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5474 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5475 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5476 | /* display pattern */ |
| 5477 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5478 | if (pat->ref && pat->ref->pattern) |
| 5479 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5480 | else |
| 5481 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5482 | } |
| 5483 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5484 | if (pat->ref && pat->ref->pattern) |
| 5485 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5486 | else |
| 5487 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5488 | } |
| 5489 | |
| 5490 | /* display return value */ |
| 5491 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5492 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5493 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5494 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5495 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5496 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5497 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5498 | } |
| 5499 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5500 | chunk_appendf(&trash, "\n"); |
| 5501 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5502 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5503 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5504 | /* let's try again later from this stream. We add ourselves into |
| 5505 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5506 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5507 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5508 | return 0; |
| 5509 | } |
| 5510 | |
| 5511 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5512 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5513 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | appctx->st2 = STAT_ST_FIN; |
| 5517 | /* fall through */ |
| 5518 | |
| 5519 | default: |
| 5520 | appctx->st2 = STAT_ST_FIN; |
| 5521 | free(appctx->ctx.map.chunk.str); |
| 5522 | return 1; |
| 5523 | } |
| 5524 | } |
| 5525 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5526 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5527 | { |
| 5528 | struct appctx *appctx = __objt_appctx(si->end); |
| 5529 | |
| 5530 | switch (appctx->st2) { |
| 5531 | |
| 5532 | case STAT_ST_INIT: |
| 5533 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5534 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5535 | struct pat_ref_elt *, list); |
| 5536 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5537 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5538 | appctx->st2 = STAT_ST_LIST; |
| 5539 | /* fall through */ |
| 5540 | |
| 5541 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5542 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5543 | chunk_reset(&trash); |
| 5544 | |
| 5545 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5546 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5547 | chunk_appendf(&trash, "%p %s %s\n", |
| 5548 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5549 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5550 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5551 | chunk_appendf(&trash, "%p %s\n", |
| 5552 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5553 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5554 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5555 | /* let's try again later from this stream. We add ourselves into |
| 5556 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5557 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5558 | si->flags |= SI_FL_WAIT_ROOM; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5559 | return 0; |
| 5560 | } |
| 5561 | |
| 5562 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5563 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5564 | struct pat_ref_elt *, list); |
| 5565 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5566 | break; |
| 5567 | } |
| 5568 | |
| 5569 | appctx->st2 = STAT_ST_FIN; |
| 5570 | /* fall through */ |
| 5571 | |
| 5572 | default: |
| 5573 | appctx->st2 = STAT_ST_FIN; |
| 5574 | return 1; |
| 5575 | } |
| 5576 | } |
| 5577 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5578 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5579 | * 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] | 5580 | * to be called again, otherwise non-zero. It is designed to be called |
| 5581 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5582 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5583 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5584 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5585 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5586 | struct connection *conn; |
| 5587 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5588 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5589 | /* 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] | 5590 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5591 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5592 | if (appctx->st2 == STAT_ST_LIST) { |
| 5593 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5594 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5595 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5596 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5597 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5598 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5599 | } |
| 5600 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5601 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5602 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5603 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5604 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5605 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5606 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5607 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5608 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5609 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5610 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5611 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5612 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5613 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5614 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5615 | /* fall through */ |
| 5616 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5617 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5618 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5619 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5620 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5621 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5622 | } |
| 5623 | |
| 5624 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5625 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5626 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5627 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5628 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5629 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5630 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5631 | if (appctx->ctx.sess.target) { |
| 5632 | 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] | 5633 | goto next_sess; |
| 5634 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5635 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5636 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5637 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5638 | return 0; |
| 5639 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5640 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5641 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5642 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5643 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5644 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5645 | break; |
| 5646 | } |
| 5647 | else |
| 5648 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5649 | } |
| 5650 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5651 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5652 | "%p: proto=%s", |
| 5653 | curr_sess, |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5654 | strm_li(curr_sess)->proto->name); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5655 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5656 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5657 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5658 | 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] | 5659 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5660 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5661 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5662 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5663 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5664 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5665 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5666 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5667 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5668 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5669 | break; |
| 5670 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5671 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5672 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5673 | strm_li(curr_sess)->luid, |
| 5674 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5675 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5676 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5677 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5678 | break; |
| 5679 | } |
| 5680 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5681 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5682 | " ts=%02x age=%s calls=%d", |
| 5683 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5684 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5685 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5686 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5687 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5688 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5689 | curr_sess->req.flags, |
| 5690 | curr_sess->req.buf->i, |
| 5691 | curr_sess->req.analysers, |
| 5692 | curr_sess->req.rex ? |
| 5693 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5694 | TICKS_TO_MS(1000)) : ""); |
| 5695 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5696 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5697 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5698 | curr_sess->req.wex ? |
| 5699 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5700 | TICKS_TO_MS(1000)) : ""); |
| 5701 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5702 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5703 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5704 | curr_sess->req.analyse_exp ? |
| 5705 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5706 | TICKS_TO_MS(1000)) : ""); |
| 5707 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5708 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5709 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5710 | curr_sess->res.flags, |
| 5711 | curr_sess->res.buf->i, |
| 5712 | curr_sess->res.analysers, |
| 5713 | curr_sess->res.rex ? |
| 5714 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5715 | TICKS_TO_MS(1000)) : ""); |
| 5716 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5717 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5718 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5719 | curr_sess->res.wex ? |
| 5720 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5721 | TICKS_TO_MS(1000)) : ""); |
| 5722 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5723 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5724 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5725 | curr_sess->res.analyse_exp ? |
| 5726 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5727 | TICKS_TO_MS(1000)) : ""); |
| 5728 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5729 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5730 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5731 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5732 | curr_sess->si[0].state, |
| 5733 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5734 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5735 | curr_sess->si[0].exp ? |
| 5736 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5737 | TICKS_TO_MS(1000)) : ""); |
| 5738 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5739 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5740 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5741 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5742 | curr_sess->si[1].state, |
| 5743 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5744 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5745 | curr_sess->si[1].exp ? |
| 5746 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5747 | TICKS_TO_MS(1000)) : ""); |
| 5748 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5749 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5750 | " exp=%s", |
| 5751 | curr_sess->task->expire ? |
| 5752 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5753 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5754 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5755 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5756 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5757 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5758 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5759 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5760 | /* let's try again later from this stream. We add ourselves into |
| 5761 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5762 | */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5763 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5764 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5765 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5766 | } |
| 5767 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5768 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5769 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5770 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5771 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5772 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5773 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5774 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5775 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5776 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5777 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5778 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5779 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5780 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5781 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5782 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5783 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5784 | appctx->ctx.sess.target = NULL; |
| 5785 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5786 | return 1; |
| 5787 | } |
| 5788 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5789 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5790 | /* fall through */ |
| 5791 | |
| 5792 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5793 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5794 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5795 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5796 | } |
| 5797 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5798 | /* This is called when the stream interface is closed. For instance, upon an |
| 5799 | * 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] | 5800 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5801 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5802 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5803 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5804 | struct appctx *appctx = __objt_appctx(si->end); |
| 5805 | |
| 5806 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5807 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5808 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5809 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5810 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5811 | free(appctx->ctx.cli.err); |
| 5812 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5813 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5814 | free(appctx->ctx.map.chunk.str); |
| 5815 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5816 | } |
| 5817 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5818 | /* This function is used to either dump tables states (when action is set |
| 5819 | * 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] | 5820 | * It returns 0 if the output buffer is full and it needs to be called |
| 5821 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5822 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5823 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5824 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5825 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5826 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5827 | struct ebmb_node *eb; |
| 5828 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5829 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5830 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5831 | |
| 5832 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5833 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5834 | * - STAT_ST_INIT : the first call |
| 5835 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5836 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5837 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5838 | * and the entry pointer points to the next entry to be dumped, |
| 5839 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5840 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5841 | * data though. |
| 5842 | */ |
| 5843 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5844 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5845 | /* 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] | 5846 | if (appctx->st2 == STAT_ST_LIST) { |
| 5847 | appctx->ctx.table.entry->ref_cnt--; |
| 5848 | 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] | 5849 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5850 | return 1; |
| 5851 | } |
| 5852 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5853 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5854 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5855 | while (appctx->st2 != STAT_ST_FIN) { |
| 5856 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5857 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5858 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5859 | if (!appctx->ctx.table.proxy) |
| 5860 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5861 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5862 | appctx->ctx.table.entry = NULL; |
| 5863 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5864 | break; |
| 5865 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5866 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5867 | if (!appctx->ctx.table.proxy || |
| 5868 | (appctx->ctx.table.target && |
| 5869 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5870 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5871 | break; |
| 5872 | } |
| 5873 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5874 | if (appctx->ctx.table.proxy->table.size) { |
| 5875 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5876 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5877 | return 0; |
| 5878 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5879 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5880 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5881 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5882 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5883 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5884 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5885 | appctx->ctx.table.entry->ref_cnt++; |
| 5886 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5887 | break; |
| 5888 | } |
| 5889 | } |
| 5890 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5891 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5892 | break; |
| 5893 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5894 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5895 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5896 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5897 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5898 | /* we're filtering on some data contents */ |
| 5899 | void *ptr; |
| 5900 | long long data; |
| 5901 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5902 | dt = appctx->ctx.table.data_type; |
| 5903 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5904 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5905 | dt); |
| 5906 | |
| 5907 | data = 0; |
| 5908 | switch (stktable_data_types[dt].std_type) { |
| 5909 | case STD_T_SINT: |
| 5910 | data = stktable_data_cast(ptr, std_t_sint); |
| 5911 | break; |
| 5912 | case STD_T_UINT: |
| 5913 | data = stktable_data_cast(ptr, std_t_uint); |
| 5914 | break; |
| 5915 | case STD_T_ULL: |
| 5916 | data = stktable_data_cast(ptr, std_t_ull); |
| 5917 | break; |
| 5918 | case STD_T_FRQP: |
| 5919 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5920 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5921 | break; |
| 5922 | } |
| 5923 | |
| 5924 | /* 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] | 5925 | if ((data < appctx->ctx.table.value && |
| 5926 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5927 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5928 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5929 | (data == appctx->ctx.table.value && |
| 5930 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5931 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5932 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5933 | (data > appctx->ctx.table.value && |
| 5934 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5935 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5936 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5937 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5938 | } |
| 5939 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5940 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5941 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5942 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5943 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5944 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5945 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5946 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5947 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5948 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5949 | struct stksess *old = appctx->ctx.table.entry; |
| 5950 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5951 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5952 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5953 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5954 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5955 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5956 | break; |
| 5957 | } |
| 5958 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5959 | |
| 5960 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5961 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5962 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5963 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5964 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5965 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5966 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5967 | break; |
| 5968 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5969 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5970 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5971 | break; |
| 5972 | } |
| 5973 | } |
| 5974 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5975 | } |
| 5976 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5977 | /* 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] | 5978 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5979 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5980 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5981 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5982 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5983 | * after the offset. The new pointer is returned. |
| 5984 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5985 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5986 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5987 | { |
| 5988 | int end; |
| 5989 | unsigned char c; |
| 5990 | |
| 5991 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5992 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5993 | return ptr; |
| 5994 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5995 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5996 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5997 | while (ptr < len && ptr < bsize) { |
| 5998 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5999 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6000 | if (out->len > end - 2) |
| 6001 | break; |
| 6002 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6003 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6004 | if (out->len > end - 3) |
| 6005 | break; |
| 6006 | out->str[out->len++] = '\\'; |
| 6007 | switch (c) { |
| 6008 | case '\t': c = 't'; break; |
| 6009 | case '\n': c = 'n'; break; |
| 6010 | case '\r': c = 'r'; break; |
| 6011 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6012 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6013 | } |
| 6014 | out->str[out->len++] = c; |
| 6015 | } else { |
| 6016 | if (out->len > end - 5) |
| 6017 | break; |
| 6018 | out->str[out->len++] = '\\'; |
| 6019 | out->str[out->len++] = 'x'; |
| 6020 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6021 | out->str[out->len++] = hextab[c & 0xF]; |
| 6022 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6023 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6024 | /* we had a line break, let's return now */ |
| 6025 | out->str[out->len++] = '\n'; |
| 6026 | *line = ptr; |
| 6027 | return ptr; |
| 6028 | } |
| 6029 | } |
| 6030 | /* we have an incomplete line, we return it as-is */ |
| 6031 | out->str[out->len++] = '\n'; |
| 6032 | return ptr; |
| 6033 | } |
| 6034 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6035 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6036 | * 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] | 6037 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6038 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6039 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6040 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6041 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6042 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6043 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6044 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6045 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6046 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6047 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6048 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6049 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6050 | /* the function had not been called yet, let's prepare the |
| 6051 | * buffer for a response. |
| 6052 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6053 | struct tm tm; |
| 6054 | |
| 6055 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6056 | 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] | 6057 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6058 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6059 | error_snapshot_id); |
| 6060 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6061 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6062 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6063 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6064 | return 0; |
| 6065 | } |
| 6066 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6067 | appctx->ctx.errors.px = proxy; |
| 6068 | appctx->ctx.errors.buf = 0; |
| 6069 | appctx->ctx.errors.bol = 0; |
| 6070 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6071 | } |
| 6072 | |
| 6073 | /* we have two inner loops here, one for the proxy, the other one for |
| 6074 | * the buffer. |
| 6075 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6076 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6077 | struct error_snapshot *es; |
| 6078 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6079 | if (appctx->ctx.errors.buf == 0) |
| 6080 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6081 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6082 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6083 | |
| 6084 | if (!es->when.tv_sec) |
| 6085 | goto next; |
| 6086 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6087 | if (appctx->ctx.errors.iid >= 0 && |
| 6088 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6089 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6090 | goto next; |
| 6091 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6092 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6093 | /* just print headers now */ |
| 6094 | |
| 6095 | char pn[INET6_ADDRSTRLEN]; |
| 6096 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6097 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6098 | |
| 6099 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6100 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6101 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6102 | 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] | 6103 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6104 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6105 | case AF_INET: |
| 6106 | case AF_INET6: |
| 6107 | port = get_host_port(&es->src); |
| 6108 | break; |
| 6109 | default: |
| 6110 | port = 0; |
| 6111 | } |
| 6112 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6113 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6114 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6115 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6116 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6117 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6118 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6119 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6120 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6121 | break; |
| 6122 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6123 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6124 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6125 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6126 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6127 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6128 | break; |
| 6129 | } |
| 6130 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6131 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6132 | ", server %s (#%d), event #%u\n" |
| 6133 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6134 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6135 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6136 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6137 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6138 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6139 | es->ev_id, |
| 6140 | pn, port, es->sid, es->s_flags, |
| 6141 | es->state, es->m_flags, es->t_flags, |
| 6142 | es->m_clen, es->m_blen, |
| 6143 | es->b_flags, es->b_out, es->b_tot, |
| 6144 | es->len, es->b_wrap, es->pos); |
| 6145 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6146 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6147 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6148 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6149 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6150 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6151 | appctx->ctx.errors.ptr = 0; |
| 6152 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6153 | } |
| 6154 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6155 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6156 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6157 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6158 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6159 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6160 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6161 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6162 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6163 | goto next; |
| 6164 | } |
| 6165 | |
| 6166 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6167 | 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] | 6168 | int newptr; |
| 6169 | int newline; |
| 6170 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6171 | newline = appctx->ctx.errors.bol; |
| 6172 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6173 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6174 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6175 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6176 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6177 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6178 | si->flags |= SI_FL_WAIT_ROOM; |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6179 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6180 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6181 | appctx->ctx.errors.ptr = newptr; |
| 6182 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6183 | }; |
| 6184 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6185 | appctx->ctx.errors.bol = 0; |
| 6186 | appctx->ctx.errors.ptr = -1; |
| 6187 | appctx->ctx.errors.buf++; |
| 6188 | if (appctx->ctx.errors.buf > 1) { |
| 6189 | appctx->ctx.errors.buf = 0; |
| 6190 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6195 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6196 | } |
| 6197 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6198 | /* parse the "level" argument on the bind lines */ |
| 6199 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6200 | { |
| 6201 | if (!*args[cur_arg + 1]) { |
| 6202 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6203 | return ERR_ALERT | ERR_FATAL; |
| 6204 | } |
| 6205 | |
| 6206 | if (!strcmp(args[cur_arg+1], "user")) |
| 6207 | conf->level = ACCESS_LVL_USER; |
| 6208 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6209 | conf->level = ACCESS_LVL_OPER; |
| 6210 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6211 | conf->level = ACCESS_LVL_ADMIN; |
| 6212 | else { |
| 6213 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6214 | args[cur_arg], args[cur_arg+1]); |
| 6215 | return ERR_ALERT | ERR_FATAL; |
| 6216 | } |
| 6217 | |
| 6218 | return 0; |
| 6219 | } |
| 6220 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6221 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6222 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6223 | .name = "<STATS>", /* used for logging */ |
| 6224 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6225 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6226 | }; |
| 6227 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6228 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6229 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6230 | .name = "<CLI>", /* used for logging */ |
| 6231 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6232 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6233 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6234 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6235 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6236 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6237 | { 0, NULL, NULL }, |
| 6238 | }}; |
| 6239 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6240 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6241 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6242 | { NULL, NULL, 0 }, |
| 6243 | }}; |
| 6244 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6245 | __attribute__((constructor)) |
| 6246 | static void __dumpstats_module_init(void) |
| 6247 | { |
| 6248 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6249 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6250 | } |
| 6251 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6252 | /* |
| 6253 | * Local variables: |
| 6254 | * c-indent-level: 8 |
| 6255 | * c-basic-offset: 8 |
| 6256 | * End: |
| 6257 | */ |