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 | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 40 | #include <types/applet.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 41 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 42 | |
| 43 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 44 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 45 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 46 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 47 | #include <proto/dumpstats.h> |
| 48 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 49 | #include <proto/freq_ctr.h> |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 50 | #include <proto/frontend.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 51 | #include <proto/log.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 52 | #include <proto/pattern.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 53 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 54 | #include <proto/listener.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 55 | #include <proto/map.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 56 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 57 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 58 | #include <proto/proxy.h> |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 59 | #include <proto/sample.h> |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 60 | #include <proto/session.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 61 | #include <proto/stream.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 62 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 63 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 64 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 65 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 66 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 67 | #ifdef USE_OPENSSL |
| 68 | #include <proto/ssl_sock.h> |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 69 | #include <types/ssl_sock.h> |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 70 | #endif |
| 71 | |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 72 | /* stats socket states */ |
| 73 | enum { |
| 74 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 75 | STAT_CLI_END, /* final state, let's close */ |
| 76 | STAT_CLI_GETREQ, /* wait for a request */ |
| 77 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 78 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 79 | STAT_CLI_PRINT, /* display message in cli->msg */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 80 | 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] | 81 | STAT_CLI_O_INFO, /* dump info */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 82 | STAT_CLI_O_SESS, /* dump streams */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 83 | STAT_CLI_O_ERR, /* dump errors */ |
| 84 | STAT_CLI_O_TAB, /* dump tables */ |
| 85 | STAT_CLI_O_CLR, /* clear tables */ |
| 86 | STAT_CLI_O_SET, /* set entries in tables */ |
| 87 | STAT_CLI_O_STAT, /* dump stats */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 88 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 89 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 90 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 91 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 92 | STAT_CLI_O_TLSK, /* list all TLS ticket keys references */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 95 | /* Actions available for the stats admin forms */ |
| 96 | enum { |
| 97 | ST_ADM_ACTION_NONE = 0, |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 98 | |
| 99 | /* enable/disable health checks */ |
| 100 | ST_ADM_ACTION_DHLTH, |
| 101 | ST_ADM_ACTION_EHLTH, |
| 102 | |
| 103 | /* force health check status */ |
| 104 | ST_ADM_ACTION_HRUNN, |
| 105 | ST_ADM_ACTION_HNOLB, |
| 106 | ST_ADM_ACTION_HDOWN, |
| 107 | |
| 108 | /* enable/disable agent checks */ |
| 109 | ST_ADM_ACTION_DAGENT, |
| 110 | ST_ADM_ACTION_EAGENT, |
| 111 | |
| 112 | /* force agent check status */ |
| 113 | ST_ADM_ACTION_ARUNN, |
| 114 | ST_ADM_ACTION_ADOWN, |
| 115 | |
| 116 | /* set admin state */ |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 117 | ST_ADM_ACTION_READY, |
| 118 | ST_ADM_ACTION_DRAIN, |
| 119 | ST_ADM_ACTION_MAINT, |
| 120 | ST_ADM_ACTION_SHUTDOWN, |
| 121 | /* these are the ancient actions, still available for compatibility */ |
| 122 | ST_ADM_ACTION_DISABLE, |
| 123 | ST_ADM_ACTION_ENABLE, |
| 124 | ST_ADM_ACTION_STOP, |
| 125 | ST_ADM_ACTION_START, |
| 126 | }; |
| 127 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 128 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 129 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 130 | 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] | 131 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 132 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 133 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 134 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 135 | 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] | 136 | static int stats_pats_list(struct stream_interface *si); |
| 137 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 138 | static int stats_map_lookup(struct stream_interface *si); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 139 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 140 | static int stats_tlskeys_list(struct stream_interface *si); |
| 141 | #endif |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 142 | static void cli_release_handler(struct appctx *appctx); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 143 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 144 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 145 | * cli_io_handler() |
| 146 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 147 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 148 | * -> stats_dump_info_to_buffer() // "show info" |
| 149 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 150 | * -> stats_dump_csv_header() |
| 151 | * -> stats_dump_proxy_to_buffer() |
| 152 | * -> stats_dump_fe_stats() |
| 153 | * -> stats_dump_li_stats() |
| 154 | * -> stats_dump_sv_stats() |
| 155 | * -> stats_dump_be_stats() |
| 156 | * |
| 157 | * http_stats_io_handler() |
| 158 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 159 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 160 | * -> stats_dump_html_head() // emits the HTML headers |
| 161 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 162 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 163 | * -> stats_dump_html_px_hdr() |
| 164 | * -> stats_dump_fe_stats() |
| 165 | * -> stats_dump_li_stats() |
| 166 | * -> stats_dump_sv_stats() |
| 167 | * -> stats_dump_be_stats() |
| 168 | * -> stats_dump_html_px_end() |
| 169 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 170 | */ |
| 171 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 172 | static struct applet cli_applet; |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 173 | |
| 174 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 175 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 176 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 177 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 178 | " help : this message\n" |
| 179 | " prompt : toggle interactive mode with prompt\n" |
| 180 | " quit : disconnect\n" |
| 181 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 182 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 183 | " show stat : report counters for each proxy and server\n" |
| 184 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 185 | " 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] | 186 | " 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] | 187 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 188 | " set weight : change a server's weight\n" |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 189 | " set server : change a server's state or weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 190 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 191 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 192 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 193 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 194 | " disable : put a server or frontend in maintenance mode\n" |
| 195 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 196 | " 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] | 197 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 198 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 199 | " add acl : add acl entry\n" |
| 200 | " del acl : delete acl entry\n" |
| 201 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 202 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 203 | " get map : reports the keys and values matching a sample for a map\n" |
| 204 | " set map : modify map entry\n" |
| 205 | " add map : add map entry\n" |
| 206 | " del map : delete map entry\n" |
| 207 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 208 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 209 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 210 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 211 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 212 | "Permission denied\n" |
| 213 | ""; |
| 214 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 215 | /* data transmission states for the stats responses */ |
| 216 | enum { |
| 217 | STAT_ST_INIT = 0, |
| 218 | STAT_ST_HEAD, |
| 219 | STAT_ST_INFO, |
| 220 | STAT_ST_LIST, |
| 221 | STAT_ST_END, |
| 222 | STAT_ST_FIN, |
| 223 | }; |
| 224 | |
| 225 | /* data transmission states for the stats responses inside a proxy */ |
| 226 | enum { |
| 227 | STAT_PX_ST_INIT = 0, |
| 228 | STAT_PX_ST_TH, |
| 229 | STAT_PX_ST_FE, |
| 230 | STAT_PX_ST_LI, |
| 231 | STAT_PX_ST_SV, |
| 232 | STAT_PX_ST_BE, |
| 233 | STAT_PX_ST_END, |
| 234 | STAT_PX_ST_FIN, |
| 235 | }; |
| 236 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 237 | extern const char *stat_status_codes[]; |
| 238 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 239 | /* allocate a new stats frontend named <name>, and return it |
| 240 | * (or NULL in case of lack of memory). |
| 241 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 242 | 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] | 243 | { |
| 244 | struct proxy *fe; |
| 245 | |
| 246 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 247 | if (!fe) |
| 248 | return NULL; |
| 249 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 250 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 251 | fe->next = proxy; |
| 252 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 253 | fe->last_change = now.tv_sec; |
| 254 | fe->id = strdup("GLOBAL"); |
| 255 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 256 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 257 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 258 | fe->conf.file = strdup(file); |
| 259 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 260 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 261 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 262 | |
| 263 | /* the stats frontend is the only one able to assign ID #0 */ |
| 264 | fe->conf.id.key = fe->uuid = 0; |
| 265 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 266 | return fe; |
| 267 | } |
| 268 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 269 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 270 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 271 | * error message into the <err> buffer which will be preallocated. The trailing |
| 272 | * '\n' must not be written. The function must be called with <args> pointing to |
| 273 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 274 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 275 | 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] | 276 | struct proxy *defpx, const char *file, int line, |
| 277 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 278 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 279 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 280 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 281 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 282 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 283 | int cur_arg; |
| 284 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 285 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 286 | 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] | 287 | return -1; |
| 288 | } |
| 289 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 290 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 291 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 292 | 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] | 293 | return -1; |
| 294 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 297 | 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] | 298 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 299 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 300 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 301 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 302 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 303 | return -1; |
| 304 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 305 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 306 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 307 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 308 | static int bind_dumped; |
| 309 | struct bind_kw *kw; |
| 310 | |
| 311 | kw = bind_find_kw(args[cur_arg]); |
| 312 | if (kw) { |
| 313 | if (!kw->parse) { |
| 314 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 315 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 316 | return -1; |
| 317 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 318 | |
| 319 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 320 | if (err && *err) |
| 321 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 322 | else |
| 323 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 324 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 325 | return -1; |
| 326 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 327 | |
| 328 | cur_arg += 1 + kw->skip; |
| 329 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 330 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 331 | |
| 332 | if (!bind_dumped) { |
| 333 | bind_dump_kws(err); |
| 334 | indent_msg(err, 4); |
| 335 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 336 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 337 | |
| 338 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 339 | args[0], args[1], args[cur_arg], |
| 340 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 341 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 342 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 343 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 344 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 345 | l->maxconn = global.stats_fe->maxconn; |
| 346 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 347 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 348 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 349 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 350 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 351 | l->nice = -64; /* we want to boost priority for local stats */ |
| 352 | global.maxsock += l->maxconn; |
| 353 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 354 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 355 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 356 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 357 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 358 | |
| 359 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 360 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 361 | return -1; |
| 362 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 363 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 364 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 365 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 366 | return -1; |
| 367 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 368 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 369 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 370 | 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] | 371 | return -1; |
| 372 | } |
| 373 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 374 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 375 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 376 | else if (!strcmp(args[1], "maxconn")) { |
| 377 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 378 | |
| 379 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 380 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 381 | return -1; |
| 382 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 383 | |
| 384 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 385 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 386 | 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] | 387 | return -1; |
| 388 | } |
| 389 | } |
| 390 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 391 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 392 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 393 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 394 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 395 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 396 | if (!global.stats_fe) { |
| 397 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 398 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 399 | return -1; |
| 400 | } |
| 401 | } |
| 402 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 403 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 404 | unsigned int low, high; |
| 405 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 406 | if (strcmp(args[cur_arg], "all") == 0) { |
| 407 | set = 0; |
| 408 | break; |
| 409 | } |
| 410 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 411 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 412 | } |
| 413 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 414 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 415 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 416 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 417 | char *dash = strchr(args[cur_arg], '-'); |
| 418 | |
| 419 | low = high = str2uic(args[cur_arg]); |
| 420 | if (dash) |
| 421 | high = str2uic(dash + 1); |
| 422 | |
| 423 | if (high < low) { |
| 424 | unsigned int swap = low; |
| 425 | low = high; |
| 426 | high = swap; |
| 427 | } |
| 428 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 429 | if (low < 1 || high > LONGBITS) { |
| 430 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 431 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 432 | return -1; |
| 433 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 434 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 435 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 436 | } |
| 437 | else { |
| 438 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 439 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 440 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 441 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 442 | } |
| 443 | cur_arg++; |
| 444 | } |
| 445 | global.stats_fe->bind_proc = set; |
| 446 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 447 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 448 | 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] | 449 | return -1; |
| 450 | } |
| 451 | return 0; |
| 452 | } |
| 453 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 454 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 455 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 456 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 457 | * 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] | 458 | */ |
| 459 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 460 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 461 | chunk_appendf(&trash, |
| 462 | "# pxname,svname," |
| 463 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 464 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 465 | "bin,bout," |
| 466 | "dreq,dresp," |
| 467 | "ereq,econ,eresp," |
| 468 | "wretr,wredis," |
| 469 | "status,weight,act,bck," |
| 470 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 471 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 472 | "rate,rate_lim,rate_max," |
| 473 | "check_status,check_code,check_duration," |
| 474 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 475 | "req_rate,req_rate_max,req_tot," |
| 476 | "cli_abrt,srv_abrt," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 477 | "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] | 478 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 481 | /* print a string of text buffer to <out>. The format is : |
| 482 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 483 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 484 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 485 | */ |
| 486 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 487 | { |
| 488 | unsigned char c; |
| 489 | int ptr = 0; |
| 490 | |
| 491 | while (buf[ptr] && ptr < bsize) { |
| 492 | c = buf[ptr]; |
| 493 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 494 | if (out->len > out->size - 1) |
| 495 | break; |
| 496 | out->str[out->len++] = c; |
| 497 | } |
| 498 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 499 | if (out->len > out->size - 2) |
| 500 | break; |
| 501 | out->str[out->len++] = '\\'; |
| 502 | switch (c) { |
| 503 | case ' ': c = ' '; break; |
| 504 | case '\t': c = 't'; break; |
| 505 | case '\n': c = 'n'; break; |
| 506 | case '\r': c = 'r'; break; |
| 507 | case '\e': c = 'e'; break; |
| 508 | case '\\': c = '\\'; break; |
| 509 | } |
| 510 | out->str[out->len++] = c; |
| 511 | } |
| 512 | else { |
| 513 | if (out->len > out->size - 4) |
| 514 | break; |
| 515 | out->str[out->len++] = '\\'; |
| 516 | out->str[out->len++] = 'x'; |
| 517 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 518 | out->str[out->len++] = hextab[c & 0xF]; |
| 519 | } |
| 520 | ptr++; |
| 521 | } |
| 522 | |
| 523 | return ptr; |
| 524 | } |
| 525 | |
| 526 | /* print a buffer in hexa. |
| 527 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 528 | */ |
| 529 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 530 | { |
| 531 | unsigned char c; |
| 532 | int ptr = 0; |
| 533 | |
| 534 | while (ptr < bsize) { |
| 535 | c = buf[ptr]; |
| 536 | |
| 537 | if (out->len > out->size - 2) |
| 538 | break; |
| 539 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 540 | out->str[out->len++] = hextab[c & 0xF]; |
| 541 | |
| 542 | ptr++; |
| 543 | } |
| 544 | return ptr; |
| 545 | } |
| 546 | |
| 547 | /* Dump the status of a table to a stream interface's |
| 548 | * read buffer. It returns 0 if the output buffer is full |
| 549 | * and needs to be called again, otherwise non-zero. |
| 550 | */ |
| 551 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 552 | struct proxy *proxy, struct proxy *target) |
| 553 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 554 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 555 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 556 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 557 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 558 | |
| 559 | /* any other information should be dumped here */ |
| 560 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 561 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 562 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 563 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 564 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 565 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 566 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 567 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 568 | |
| 569 | return 1; |
| 570 | } |
| 571 | |
| 572 | /* Dump the a table entry to a stream interface's |
| 573 | * read buffer. It returns 0 if the output buffer is full |
| 574 | * and needs to be called again, otherwise non-zero. |
| 575 | */ |
| 576 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 577 | struct proxy *proxy, struct stksess *entry) |
| 578 | { |
| 579 | int dt; |
| 580 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 581 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 582 | |
| 583 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 584 | char addr[INET_ADDRSTRLEN]; |
| 585 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 586 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 587 | } |
| 588 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 589 | char addr[INET6_ADDRSTRLEN]; |
| 590 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 591 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 592 | } |
| 593 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 594 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 595 | } |
| 596 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 597 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 598 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 599 | } |
| 600 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 601 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 602 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 603 | } |
| 604 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 605 | 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] | 606 | |
| 607 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 608 | void *ptr; |
| 609 | |
| 610 | if (proxy->table.data_ofs[dt] == 0) |
| 611 | continue; |
| 612 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 613 | 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] | 614 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 615 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 616 | |
| 617 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 618 | switch (stktable_data_types[dt].std_type) { |
| 619 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 620 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 621 | break; |
| 622 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 623 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 624 | break; |
| 625 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 626 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 627 | break; |
| 628 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 629 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 630 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 631 | proxy->table.data_arg[dt].u)); |
| 632 | break; |
| 633 | } |
| 634 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 635 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 636 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 637 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 638 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 639 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 640 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 641 | |
| 642 | return 1; |
| 643 | } |
| 644 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 645 | 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] | 646 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 647 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 648 | struct appctx *appctx = __objt_appctx(si->end); |
| 649 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 650 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 651 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 652 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 653 | long long value; |
| 654 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 655 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 656 | void *ptr; |
| 657 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 658 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 659 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 660 | |
| 661 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 662 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 663 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 664 | return; |
| 665 | } |
| 666 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 667 | switch (px->table.type) { |
| 668 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 669 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 670 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 671 | break; |
| 672 | case STKTABLE_TYPE_IPV6: |
| 673 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 674 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 675 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 676 | case STKTABLE_TYPE_INTEGER: |
| 677 | { |
| 678 | char *endptr; |
| 679 | unsigned long val; |
| 680 | errno = 0; |
| 681 | val = strtoul(args[4], &endptr, 10); |
| 682 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 683 | (errno != 0 && val == 0) || endptr == args[4] || |
| 684 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 685 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 686 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 687 | return; |
| 688 | } |
| 689 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 690 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 691 | break; |
| 692 | } |
| 693 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 694 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 695 | static_table_key->key = args[4]; |
| 696 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 697 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 698 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 699 | switch (action) { |
| 700 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 701 | 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] | 702 | break; |
| 703 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 704 | 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] | 705 | break; |
| 706 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 707 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 708 | break; |
| 709 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 710 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 711 | return; |
| 712 | } |
| 713 | |
| 714 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 715 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 716 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 717 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 718 | return; |
| 719 | } |
| 720 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 721 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 722 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 723 | switch (action) { |
| 724 | case STAT_CLI_O_TAB: |
| 725 | if (!ts) |
| 726 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 727 | chunk_reset(&trash); |
| 728 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 729 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 730 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 731 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 732 | |
| 733 | case STAT_CLI_O_CLR: |
| 734 | if (!ts) |
| 735 | return; |
| 736 | if (ts->ref_cnt) { |
| 737 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 738 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 739 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 740 | return; |
| 741 | } |
| 742 | stksess_kill(&px->table, ts); |
| 743 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 744 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 745 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 746 | if (ts) |
| 747 | stktable_touch(&px->table, ts, 1); |
| 748 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 749 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 750 | if (!ts) { |
| 751 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 752 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 753 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 754 | return; |
| 755 | } |
| 756 | stktable_store(&px->table, ts, 1); |
| 757 | } |
| 758 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 759 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 760 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 761 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 762 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 763 | return; |
| 764 | } |
| 765 | |
| 766 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 767 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 768 | appctx->ctx.cli.msg = "Unknown data type\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 (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 774 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 775 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 776 | return; |
| 777 | } |
| 778 | |
| 779 | 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] | 780 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 781 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 782 | return; |
| 783 | } |
| 784 | |
| 785 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 786 | |
| 787 | switch (stktable_data_types[data_type].std_type) { |
| 788 | case STD_T_SINT: |
| 789 | stktable_data_cast(ptr, std_t_sint) = value; |
| 790 | break; |
| 791 | case STD_T_UINT: |
| 792 | stktable_data_cast(ptr, std_t_uint) = value; |
| 793 | break; |
| 794 | case STD_T_ULL: |
| 795 | stktable_data_cast(ptr, std_t_ull) = value; |
| 796 | break; |
| 797 | case STD_T_FRQP: |
| 798 | /* We set both the current and previous values. That way |
| 799 | * the reported frequency is stable during all the period |
| 800 | * then slowly fades out. This allows external tools to |
| 801 | * push measures without having to update them too often. |
| 802 | */ |
| 803 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 804 | frqp->curr_tick = now_ms; |
| 805 | frqp->prev_ctr = 0; |
| 806 | frqp->curr_ctr = value; |
| 807 | break; |
| 808 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 809 | } |
| 810 | break; |
| 811 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 812 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 813 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 814 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 815 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 816 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 817 | } |
| 818 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 819 | 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] | 820 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 821 | struct appctx *appctx = __objt_appctx(si->end); |
| 822 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 823 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 824 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 825 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 826 | return; |
| 827 | } |
| 828 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 829 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 830 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 831 | if (appctx->ctx.table.data_type < 0) { |
| 832 | appctx->ctx.cli.msg = "Unknown data type\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 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 838 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 839 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 840 | return; |
| 841 | } |
| 842 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 843 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 844 | if (appctx->ctx.table.data_op < 0) { |
| 845 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 846 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 847 | return; |
| 848 | } |
| 849 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 850 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 851 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 852 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 853 | return; |
| 854 | } |
| 855 | } |
| 856 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 857 | 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] | 858 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 859 | struct appctx *appctx = __objt_appctx(si->end); |
| 860 | |
| 861 | appctx->ctx.table.data_type = -1; |
| 862 | appctx->st2 = STAT_ST_INIT; |
| 863 | appctx->ctx.table.target = NULL; |
| 864 | appctx->ctx.table.proxy = NULL; |
| 865 | appctx->ctx.table.entry = NULL; |
| 866 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 867 | |
| 868 | if (*args[2]) { |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 869 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 870 | if (!appctx->ctx.table.target) { |
| 871 | appctx->ctx.cli.msg = "No such table\n"; |
| 872 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 873 | return; |
| 874 | } |
| 875 | } |
| 876 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 877 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 878 | goto err_args; |
| 879 | return; |
| 880 | } |
| 881 | |
| 882 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 883 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 884 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 885 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 886 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 887 | goto err_args; |
| 888 | |
| 889 | return; |
| 890 | |
| 891 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 892 | switch (action) { |
| 893 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 894 | 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] | 895 | break; |
| 896 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 897 | 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] | 898 | break; |
| 899 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 900 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 901 | break; |
| 902 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 903 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 904 | } |
| 905 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 906 | /* 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] | 907 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 908 | * level to be admin. |
| 909 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 910 | 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] | 911 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 912 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 913 | struct proxy *px; |
| 914 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 915 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 916 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 917 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 918 | return NULL; |
| 919 | } |
| 920 | |
| 921 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 922 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 923 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 924 | return NULL; |
| 925 | } |
| 926 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 927 | px = proxy_fe_by_name(arg); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 928 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 929 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 930 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 931 | return NULL; |
| 932 | } |
| 933 | return px; |
| 934 | } |
| 935 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 936 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 937 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 938 | * 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] | 939 | * the <arg> is modified to remove the '/'. |
| 940 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 941 | 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] | 942 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 943 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 944 | struct proxy *px; |
| 945 | struct server *sv; |
| 946 | char *line; |
| 947 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 948 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 949 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 950 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 951 | return NULL; |
| 952 | } |
| 953 | |
| 954 | /* split "backend/server" and make <line> point to server */ |
| 955 | for (line = arg; *line; line++) |
| 956 | if (*line == '/') { |
| 957 | *line++ = '\0'; |
| 958 | break; |
| 959 | } |
| 960 | |
| 961 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 962 | appctx->ctx.cli.msg = "Require 'backend/server'.\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 (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 968 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\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 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 974 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 975 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 976 | return NULL; |
| 977 | } |
| 978 | |
| 979 | return sv; |
| 980 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 981 | |
| 982 | /* This function is used with TLS ticket keys management. It permits to browse |
| 983 | * each reference. The variable <getnext> must contain the current node, |
| 984 | * <end> point to the root node. |
| 985 | */ |
| 986 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 987 | static inline |
| 988 | struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end) |
| 989 | { |
| 990 | struct tls_keys_ref *ref = getnext; |
| 991 | |
| 992 | while (1) { |
| 993 | |
| 994 | /* Get next list entry. */ |
| 995 | ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list); |
| 996 | |
| 997 | /* If the entry is the last of the list, return NULL. */ |
| 998 | if (&ref->list == end) |
| 999 | return NULL; |
| 1000 | |
| 1001 | return ref; |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | static inline |
| 1006 | struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference) |
| 1007 | { |
| 1008 | int id; |
| 1009 | char *error; |
| 1010 | |
| 1011 | /* If the reference starts by a '#', this is numeric id. */ |
| 1012 | if (reference[0] == '#') { |
| 1013 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1014 | id = strtol(reference + 1, &error, 10); |
| 1015 | if (*error != '\0') |
| 1016 | return NULL; |
| 1017 | |
| 1018 | /* Perform the unique id lookup. */ |
| 1019 | return tlskeys_ref_lookupid(id); |
| 1020 | } |
| 1021 | |
| 1022 | /* Perform the string lookup. */ |
| 1023 | return tlskeys_ref_lookup(reference); |
| 1024 | } |
| 1025 | #endif |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1026 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1027 | /* This function is used with map and acl management. It permits to browse |
| 1028 | * each reference. The variable <getnext> must contain the current node, |
| 1029 | * <end> point to the root node and the <flags> permit to filter required |
| 1030 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1031 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1032 | static inline |
| 1033 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1034 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1035 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1036 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1037 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1038 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1039 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1040 | /* Get next list entry. */ |
| 1041 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1042 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1043 | /* If the entry is the last of the list, return NULL. */ |
| 1044 | if (&ref->list == end) |
| 1045 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1046 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1047 | /* If the entry match the flag, return it. */ |
| 1048 | if (ref->flags & flags) |
| 1049 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1053 | static inline |
| 1054 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1055 | { |
| 1056 | int id; |
| 1057 | char *error; |
| 1058 | |
| 1059 | /* If the reference starts by a '#', this is numeric id. */ |
| 1060 | if (reference[0] == '#') { |
| 1061 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1062 | id = strtol(reference + 1, &error, 10); |
| 1063 | if (*error != '\0') |
| 1064 | return NULL; |
| 1065 | |
| 1066 | /* Perform the unique id lookup. */ |
| 1067 | return pat_ref_lookupid(id); |
| 1068 | } |
| 1069 | |
| 1070 | /* Perform the string lookup. */ |
| 1071 | return pat_ref_lookup(reference); |
| 1072 | } |
| 1073 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1074 | /* This function is used with map and acl management. It permits to browse |
| 1075 | * each reference. |
| 1076 | */ |
| 1077 | static inline |
| 1078 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1079 | { |
| 1080 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1081 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1082 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1083 | return NULL; |
| 1084 | return expr; |
| 1085 | } |
| 1086 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1087 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1088 | * 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] | 1089 | * 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] | 1090 | * designating the function which will have to process the request, which can |
| 1091 | * 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] | 1092 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1093 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1094 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1095 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1096 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1097 | char *args[MAX_STATS_ARGS + 1]; |
| 1098 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1099 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1100 | |
| 1101 | while (isspace((unsigned char)*line)) |
| 1102 | line++; |
| 1103 | |
| 1104 | arg = 0; |
| 1105 | args[arg] = line; |
| 1106 | |
| 1107 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1108 | if (*line == '\\') { |
| 1109 | line++; |
| 1110 | if (*line == '\0') |
| 1111 | break; |
| 1112 | } |
| 1113 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1114 | *line++ = '\0'; |
| 1115 | |
| 1116 | while (isspace((unsigned char)*line)) |
| 1117 | line++; |
| 1118 | |
| 1119 | args[++arg] = line; |
| 1120 | continue; |
| 1121 | } |
| 1122 | |
| 1123 | line++; |
| 1124 | } |
| 1125 | |
| 1126 | while (++arg <= MAX_STATS_ARGS) |
| 1127 | args[arg] = line; |
| 1128 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1129 | /* remove \ */ |
| 1130 | arg = 0; |
| 1131 | while (*args[arg] != '\0') { |
| 1132 | j = 0; |
| 1133 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1134 | if (args[arg][i] == '\\') |
| 1135 | continue; |
| 1136 | args[arg][j] = args[arg][i]; |
| 1137 | j++; |
| 1138 | } |
| 1139 | args[arg][j] = '\0'; |
| 1140 | arg++; |
| 1141 | } |
| 1142 | |
Willy Tarreau | 6bcb95d | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1143 | appctx->ctx.stats.scope_str = 0; |
| 1144 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1145 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1146 | if (strcmp(args[0], "show") == 0) { |
| 1147 | if (strcmp(args[1], "stat") == 0) { |
| 1148 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1149 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1150 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1151 | appctx->ctx.stats.type = atoi(args[3]); |
| 1152 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1153 | } |
| 1154 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1155 | appctx->st2 = STAT_ST_INIT; |
| 1156 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1157 | } |
| 1158 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1159 | appctx->st2 = STAT_ST_INIT; |
| 1160 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1161 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1162 | else if (strcmp(args[1], "pools") == 0) { |
| 1163 | appctx->st2 = STAT_ST_INIT; |
| 1164 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1165 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1166 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1167 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1168 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1169 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1170 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1171 | return 1; |
| 1172 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1173 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1174 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1175 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1176 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1177 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1178 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1179 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1180 | appctx->ctx.sess.pos = 0; |
| 1181 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1182 | } |
| 1183 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1184 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1185 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1186 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1187 | return 1; |
| 1188 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1189 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1190 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1191 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1192 | appctx->ctx.errors.iid = -1; |
| 1193 | appctx->ctx.errors.px = NULL; |
| 1194 | appctx->st2 = STAT_ST_INIT; |
| 1195 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1196 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1197 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1198 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1199 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1200 | else if (strcmp(args[1], "tls-keys") == 0) { |
| 1201 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1202 | appctx->st2 = STAT_ST_INIT; |
| 1203 | appctx->st0 = STAT_CLI_O_TLSK; |
| 1204 | #else |
| 1205 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1206 | "that doesn't support specifying TLS ticket keys\n"; |
| 1207 | appctx->st0 = STAT_CLI_PRINT; |
| 1208 | #endif |
| 1209 | return 1; |
| 1210 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1211 | else if (strcmp(args[1], "map") == 0 || |
| 1212 | strcmp(args[1], "acl") == 0) { |
| 1213 | |
| 1214 | /* Set ACL or MAP flags. */ |
| 1215 | if (args[1][0] == 'm') |
| 1216 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1217 | else |
| 1218 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1219 | |
| 1220 | /* no parameter: display all map avalaible */ |
| 1221 | if (!*args[2]) { |
| 1222 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1223 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1224 | return 1; |
| 1225 | } |
| 1226 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1227 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1228 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1229 | if (!appctx->ctx.map.ref || |
| 1230 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1231 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1232 | 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] | 1233 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1234 | 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] | 1235 | appctx->st0 = STAT_CLI_PRINT; |
| 1236 | return 1; |
| 1237 | } |
| 1238 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1239 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1240 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1241 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1242 | return 0; |
| 1243 | } |
| 1244 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1245 | else if (strcmp(args[0], "clear") == 0) { |
| 1246 | if (strcmp(args[1], "counters") == 0) { |
| 1247 | struct proxy *px; |
| 1248 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1249 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1250 | int clrall = 0; |
| 1251 | |
| 1252 | if (strcmp(args[2], "all") == 0) |
| 1253 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1254 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1255 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1256 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1257 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1258 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1259 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1260 | return 1; |
| 1261 | } |
| 1262 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1263 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1264 | if (clrall) { |
| 1265 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1266 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1267 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1268 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1269 | px->be_counters.conn_max = 0; |
| 1270 | px->be_counters.p.http.rps_max = 0; |
| 1271 | px->be_counters.sps_max = 0; |
| 1272 | px->be_counters.cps_max = 0; |
| 1273 | px->be_counters.nbpend_max = 0; |
| 1274 | |
| 1275 | px->fe_counters.conn_max = 0; |
| 1276 | px->fe_counters.p.http.rps_max = 0; |
| 1277 | px->fe_counters.sps_max = 0; |
| 1278 | px->fe_counters.cps_max = 0; |
| 1279 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1280 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1281 | |
| 1282 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1283 | if (clrall) |
| 1284 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1285 | else { |
| 1286 | sv->counters.cur_sess_max = 0; |
| 1287 | sv->counters.nbpend_max = 0; |
| 1288 | sv->counters.sps_max = 0; |
| 1289 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1290 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1291 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1292 | if (li->counters) { |
| 1293 | if (clrall) |
| 1294 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1295 | else |
| 1296 | li->counters->conn_max = 0; |
| 1297 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1298 | } |
| 1299 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1300 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1301 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1302 | return 1; |
| 1303 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1304 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1305 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1306 | /* end of processing */ |
| 1307 | return 1; |
| 1308 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1309 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1310 | /* Set ACL or MAP flags. */ |
| 1311 | if (args[1][0] == 'm') |
| 1312 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1313 | else |
| 1314 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1315 | |
| 1316 | /* no parameter */ |
| 1317 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1318 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1319 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1320 | else |
| 1321 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1322 | appctx->st0 = STAT_CLI_PRINT; |
| 1323 | return 1; |
| 1324 | } |
| 1325 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1326 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1327 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1328 | if (!appctx->ctx.map.ref || |
| 1329 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1330 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1331 | 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] | 1332 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1333 | 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] | 1334 | appctx->st0 = STAT_CLI_PRINT; |
| 1335 | return 1; |
| 1336 | } |
| 1337 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1338 | /* Clear all. */ |
| 1339 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1340 | |
| 1341 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1342 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1343 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1344 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1345 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1346 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1347 | return 0; |
| 1348 | } |
| 1349 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1350 | else if (strcmp(args[0], "get") == 0) { |
| 1351 | if (strcmp(args[1], "weight") == 0) { |
| 1352 | struct proxy *px; |
| 1353 | struct server *sv; |
| 1354 | |
| 1355 | /* split "backend/server" and make <line> point to server */ |
| 1356 | for (line = args[2]; *line; line++) |
| 1357 | if (*line == '/') { |
| 1358 | *line++ = '\0'; |
| 1359 | break; |
| 1360 | } |
| 1361 | |
| 1362 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1363 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1364 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1365 | return 1; |
| 1366 | } |
| 1367 | |
| 1368 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1369 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1370 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1371 | return 1; |
| 1372 | } |
| 1373 | |
| 1374 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1375 | 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] | 1376 | if (bi_putstr(si_ic(si), trash.str) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 1377 | si_applet_cant_put(si); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1378 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1379 | return 1; |
| 1380 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1381 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1382 | /* Set flags. */ |
| 1383 | if (args[1][0] == 'm') |
| 1384 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1385 | else |
| 1386 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1387 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1388 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1389 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1390 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1391 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1392 | else |
| 1393 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1394 | appctx->st0 = STAT_CLI_PRINT; |
| 1395 | return 1; |
| 1396 | } |
| 1397 | |
| 1398 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1399 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1400 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1401 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1402 | 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] | 1403 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1404 | 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] | 1405 | appctx->st0 = STAT_CLI_PRINT; |
| 1406 | return 1; |
| 1407 | } |
| 1408 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1409 | /* copy input string. The string must be allocated because |
| 1410 | * it may be used over multiple iterations. It's released |
| 1411 | * at the end and upon abort anyway. |
| 1412 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1413 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1414 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1415 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1416 | if (!appctx->ctx.map.chunk.str) { |
| 1417 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1418 | appctx->st0 = STAT_CLI_PRINT; |
| 1419 | return 1; |
| 1420 | } |
| 1421 | |
| 1422 | /* prepare response */ |
| 1423 | appctx->st2 = STAT_ST_INIT; |
| 1424 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1425 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1426 | else { /* not "get weight" */ |
| 1427 | return 0; |
| 1428 | } |
| 1429 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1430 | else if (strcmp(args[0], "set") == 0) { |
| 1431 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1432 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1433 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1434 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1435 | sv = expect_server_admin(s, si, args[2]); |
| 1436 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1437 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1438 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1439 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1440 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1441 | appctx->ctx.cli.msg = warning; |
| 1442 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1443 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1444 | return 1; |
| 1445 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1446 | else if (strcmp(args[1], "server") == 0) { |
| 1447 | struct server *sv; |
| 1448 | const char *warning; |
| 1449 | |
| 1450 | sv = expect_server_admin(s, si, args[2]); |
| 1451 | if (!sv) |
| 1452 | return 1; |
| 1453 | |
| 1454 | if (strcmp(args[3], "weight") == 0) { |
| 1455 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1456 | if (warning) { |
| 1457 | appctx->ctx.cli.msg = warning; |
| 1458 | appctx->st0 = STAT_CLI_PRINT; |
| 1459 | } |
| 1460 | } |
| 1461 | else if (strcmp(args[3], "state") == 0) { |
| 1462 | if (strcmp(args[4], "ready") == 0) |
| 1463 | srv_adm_set_ready(sv); |
| 1464 | else if (strcmp(args[4], "drain") == 0) |
| 1465 | srv_adm_set_drain(sv); |
| 1466 | else if (strcmp(args[4], "maint") == 0) |
| 1467 | srv_adm_set_maint(sv); |
| 1468 | else { |
| 1469 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1470 | appctx->st0 = STAT_CLI_PRINT; |
| 1471 | } |
| 1472 | } |
| 1473 | else if (strcmp(args[3], "health") == 0) { |
| 1474 | if (sv->track) { |
| 1475 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1476 | appctx->st0 = STAT_CLI_PRINT; |
| 1477 | } |
| 1478 | else if (strcmp(args[4], "up") == 0) { |
| 1479 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1480 | srv_set_running(sv, "changed from CLI"); |
| 1481 | } |
| 1482 | else if (strcmp(args[4], "stopping") == 0) { |
| 1483 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1484 | srv_set_stopping(sv, "changed from CLI"); |
| 1485 | } |
| 1486 | else if (strcmp(args[4], "down") == 0) { |
| 1487 | sv->check.health = 0; |
| 1488 | srv_set_stopped(sv, "changed from CLI"); |
| 1489 | } |
| 1490 | else { |
| 1491 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1492 | appctx->st0 = STAT_CLI_PRINT; |
| 1493 | } |
| 1494 | } |
| 1495 | else if (strcmp(args[3], "agent") == 0) { |
| 1496 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1497 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1498 | appctx->st0 = STAT_CLI_PRINT; |
| 1499 | } |
| 1500 | else if (strcmp(args[4], "up") == 0) { |
| 1501 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1502 | srv_set_running(sv, "changed from CLI"); |
| 1503 | } |
| 1504 | else if (strcmp(args[4], "down") == 0) { |
| 1505 | sv->agent.health = 0; |
| 1506 | srv_set_stopped(sv, "changed from CLI"); |
| 1507 | } |
| 1508 | else { |
| 1509 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1510 | appctx->st0 = STAT_CLI_PRINT; |
| 1511 | } |
| 1512 | } |
| 1513 | else { |
| 1514 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state' and 'weight'.\n"; |
| 1515 | appctx->st0 = STAT_CLI_PRINT; |
| 1516 | } |
| 1517 | return 1; |
| 1518 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1519 | else if (strcmp(args[1], "timeout") == 0) { |
| 1520 | if (strcmp(args[2], "cli") == 0) { |
| 1521 | unsigned timeout; |
| 1522 | const char *res; |
| 1523 | |
| 1524 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1525 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1526 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1527 | return 1; |
| 1528 | } |
| 1529 | |
| 1530 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1531 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1532 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1533 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1534 | return 1; |
| 1535 | } |
| 1536 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1537 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1538 | return 1; |
| 1539 | } |
| 1540 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1541 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1542 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1543 | return 1; |
| 1544 | } |
| 1545 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1546 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1547 | if (strcmp(args[2], "frontend") == 0) { |
| 1548 | struct proxy *px; |
| 1549 | struct listener *l; |
| 1550 | int v; |
| 1551 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1552 | px = expect_frontend_admin(s, si, args[3]); |
| 1553 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1554 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1555 | |
| 1556 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1557 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1558 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1559 | return 1; |
| 1560 | } |
| 1561 | |
| 1562 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1563 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1564 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1565 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1566 | return 1; |
| 1567 | } |
| 1568 | |
| 1569 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1570 | * its listeners. The blocked ones will be dequeued. |
| 1571 | */ |
| 1572 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1573 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1574 | l->maxconn = v; |
| 1575 | if (l->state == LI_FULL) |
| 1576 | resume_listener(l); |
| 1577 | } |
| 1578 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1579 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1580 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1581 | |
| 1582 | return 1; |
| 1583 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1584 | else if (strcmp(args[2], "global") == 0) { |
| 1585 | int v; |
| 1586 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1587 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1588 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1589 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1590 | return 1; |
| 1591 | } |
| 1592 | |
| 1593 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1594 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1595 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1596 | return 1; |
| 1597 | } |
| 1598 | |
| 1599 | v = atoi(args[3]); |
| 1600 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1601 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1602 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1603 | return 1; |
| 1604 | } |
| 1605 | |
| 1606 | /* check for unlimited values */ |
| 1607 | if (v <= 0) |
| 1608 | v = global.hardmaxconn; |
| 1609 | |
| 1610 | global.maxconn = v; |
| 1611 | |
| 1612 | /* Dequeues all of the listeners waiting for a resource */ |
| 1613 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1614 | dequeue_all_listeners(&global_listener_queue); |
| 1615 | |
| 1616 | return 1; |
| 1617 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1618 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1619 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1620 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1621 | return 1; |
| 1622 | } |
| 1623 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1624 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1625 | if (strcmp(args[2], "connections") == 0) { |
| 1626 | if (strcmp(args[3], "global") == 0) { |
| 1627 | int v; |
| 1628 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1629 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1630 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1631 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1632 | return 1; |
| 1633 | } |
| 1634 | |
| 1635 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1636 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1637 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1638 | return 1; |
| 1639 | } |
| 1640 | |
| 1641 | v = atoi(args[4]); |
| 1642 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1643 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1644 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1645 | return 1; |
| 1646 | } |
| 1647 | |
| 1648 | global.cps_lim = v; |
| 1649 | |
| 1650 | /* Dequeues all of the listeners waiting for a resource */ |
| 1651 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1652 | dequeue_all_listeners(&global_listener_queue); |
| 1653 | |
| 1654 | return 1; |
| 1655 | } |
| 1656 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1657 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1658 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1659 | return 1; |
| 1660 | } |
| 1661 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1662 | else if (strcmp(args[2], "sessions") == 0) { |
| 1663 | if (strcmp(args[3], "global") == 0) { |
| 1664 | int v; |
| 1665 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1666 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1667 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1668 | appctx->st0 = STAT_CLI_PRINT; |
| 1669 | return 1; |
| 1670 | } |
| 1671 | |
| 1672 | if (!*args[4]) { |
| 1673 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1674 | appctx->st0 = STAT_CLI_PRINT; |
| 1675 | return 1; |
| 1676 | } |
| 1677 | |
| 1678 | v = atoi(args[4]); |
| 1679 | if (v < 0) { |
| 1680 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1681 | appctx->st0 = STAT_CLI_PRINT; |
| 1682 | return 1; |
| 1683 | } |
| 1684 | |
| 1685 | global.sps_lim = v; |
| 1686 | |
| 1687 | /* Dequeues all of the listeners waiting for a resource */ |
| 1688 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1689 | dequeue_all_listeners(&global_listener_queue); |
| 1690 | |
| 1691 | return 1; |
| 1692 | } |
| 1693 | else { |
| 1694 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1695 | appctx->st0 = STAT_CLI_PRINT; |
| 1696 | return 1; |
| 1697 | } |
| 1698 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1699 | #ifdef USE_OPENSSL |
| 1700 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1701 | if (strcmp(args[3], "global") == 0) { |
| 1702 | int v; |
| 1703 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1704 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1705 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1706 | appctx->st0 = STAT_CLI_PRINT; |
| 1707 | return 1; |
| 1708 | } |
| 1709 | |
| 1710 | if (!*args[4]) { |
| 1711 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1712 | appctx->st0 = STAT_CLI_PRINT; |
| 1713 | return 1; |
| 1714 | } |
| 1715 | |
| 1716 | v = atoi(args[4]); |
| 1717 | if (v < 0) { |
| 1718 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1719 | appctx->st0 = STAT_CLI_PRINT; |
| 1720 | return 1; |
| 1721 | } |
| 1722 | |
| 1723 | global.ssl_lim = v; |
| 1724 | |
| 1725 | /* Dequeues all of the listeners waiting for a resource */ |
| 1726 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1727 | dequeue_all_listeners(&global_listener_queue); |
| 1728 | |
| 1729 | return 1; |
| 1730 | } |
| 1731 | else { |
| 1732 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1733 | appctx->st0 = STAT_CLI_PRINT; |
| 1734 | return 1; |
| 1735 | } |
| 1736 | } |
| 1737 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1738 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1739 | if (strcmp(args[3], "global") == 0) { |
| 1740 | int v; |
| 1741 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1742 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1743 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1744 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1745 | return 1; |
| 1746 | } |
| 1747 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1748 | v = atoi(args[4]); |
| 1749 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1750 | } |
| 1751 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1752 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1753 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1754 | return 1; |
| 1755 | } |
| 1756 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1757 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1758 | 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] | 1759 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1760 | return 1; |
| 1761 | } |
| 1762 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1763 | else if (strcmp(args[1], "table") == 0) { |
| 1764 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1765 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1766 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1767 | char *err; |
| 1768 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1769 | /* Set flags. */ |
| 1770 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1771 | |
| 1772 | /* Expect three parameters: map name, key and new value. */ |
| 1773 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1774 | 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] | 1775 | appctx->st0 = STAT_CLI_PRINT; |
| 1776 | return 1; |
| 1777 | } |
| 1778 | |
| 1779 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1780 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1781 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1782 | 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] | 1783 | appctx->st0 = STAT_CLI_PRINT; |
| 1784 | return 1; |
| 1785 | } |
| 1786 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1787 | /* If the entry identifier start with a '#', it is considered as |
| 1788 | * pointer id |
| 1789 | */ |
| 1790 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1791 | struct pat_ref_elt *ref; |
| 1792 | long long int conv; |
| 1793 | char *error; |
| 1794 | |
| 1795 | /* Convert argument to integer value. */ |
| 1796 | conv = strtoll(&args[3][1], &error, 16); |
| 1797 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1798 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1799 | appctx->st0 = STAT_CLI_PRINT; |
| 1800 | return 1; |
| 1801 | } |
| 1802 | |
| 1803 | /* Convert and check integer to pointer. */ |
| 1804 | ref = (struct pat_ref_elt *)(long)conv; |
| 1805 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1806 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1807 | appctx->st0 = STAT_CLI_PRINT; |
| 1808 | return 1; |
| 1809 | } |
| 1810 | |
| 1811 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1812 | err = NULL; |
| 1813 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1814 | if (err) |
| 1815 | memprintf(&err, "%s.\n", err); |
| 1816 | appctx->ctx.cli.err = err; |
| 1817 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1818 | return 1; |
| 1819 | } |
| 1820 | } |
| 1821 | else { |
| 1822 | /* Else, use the entry identifier as pattern |
| 1823 | * string, and update the value. |
| 1824 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1825 | err = NULL; |
| 1826 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1827 | if (err) |
| 1828 | memprintf(&err, "%s.\n", err); |
| 1829 | appctx->ctx.cli.err = err; |
| 1830 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1831 | return 1; |
| 1832 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1833 | } |
| 1834 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1835 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1836 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1837 | return 1; |
| 1838 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1839 | #ifdef USE_OPENSSL |
| 1840 | else if (strcmp(args[1], "ssl") == 0) { |
| 1841 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 1842 | #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] | 1843 | char *err = NULL; |
| 1844 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 1845 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1846 | if (!*args[3]) { |
| 1847 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 1848 | appctx->st0 = STAT_CLI_PRINT; |
| 1849 | return 1; |
| 1850 | } |
| 1851 | |
| 1852 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 1853 | if (trash.len < 0) { |
| 1854 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 1855 | appctx->st0 = STAT_CLI_PRINT; |
| 1856 | return 1; |
| 1857 | } |
| 1858 | |
| 1859 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 1860 | if (err) { |
| 1861 | memprintf(&err, "%s.\n", err); |
| 1862 | appctx->ctx.cli.err = err; |
| 1863 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 1864 | } |
| 1865 | return 1; |
| 1866 | } |
| 1867 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 1868 | appctx->st0 = STAT_CLI_PRINT; |
| 1869 | return 1; |
| 1870 | #else |
| 1871 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 1872 | appctx->st0 = STAT_CLI_PRINT; |
| 1873 | return 1; |
| 1874 | #endif |
| 1875 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1876 | else if (strcmp(args[2], "tls-key") == 0) { |
| 1877 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1878 | /* Expect two parameters: the filename and the new new TLS key in encoding */ |
| 1879 | if (!*args[3] || !*args[4]) { |
| 1880 | appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n"; |
| 1881 | appctx->st0 = STAT_CLI_PRINT; |
| 1882 | return 1; |
| 1883 | } |
| 1884 | |
| 1885 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]); |
| 1886 | if(!appctx->ctx.tlskeys.ref) { |
| 1887 | appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n"; |
| 1888 | appctx->st0 = STAT_CLI_PRINT; |
| 1889 | return 1; |
| 1890 | } |
| 1891 | |
| 1892 | trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size); |
| 1893 | if (trash.len != sizeof(struct tls_sess_key)) { |
| 1894 | appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n"; |
| 1895 | appctx->st0 = STAT_CLI_PRINT; |
| 1896 | return 1; |
| 1897 | } |
| 1898 | |
| 1899 | memcpy(appctx->ctx.tlskeys.ref->tlskeys + 2 % TLS_TICKETS_NO, trash.str, trash.len); |
| 1900 | appctx->ctx.tlskeys.ref->tls_ticket_enc_index = appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 1 % TLS_TICKETS_NO; |
| 1901 | |
| 1902 | appctx->ctx.cli.msg = "TLS ticket key updated!"; |
| 1903 | appctx->st0 = STAT_CLI_PRINT; |
| 1904 | return 1; |
| 1905 | #else |
| 1906 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1907 | "that doesn't support specifying TLS ticket keys\n"; |
| 1908 | appctx->st0 = STAT_CLI_PRINT; |
| 1909 | return 1; |
| 1910 | #endif |
| 1911 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1912 | else { |
| 1913 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 1914 | appctx->st0 = STAT_CLI_PRINT; |
| 1915 | return 1; |
| 1916 | } |
| 1917 | } |
| 1918 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1919 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1920 | return 0; |
| 1921 | } |
| 1922 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1923 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1924 | if (strcmp(args[1], "agent") == 0) { |
| 1925 | struct server *sv; |
| 1926 | |
| 1927 | sv = expect_server_admin(s, si, args[2]); |
| 1928 | if (!sv) |
| 1929 | return 1; |
| 1930 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1931 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1932 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1933 | appctx->st0 = STAT_CLI_PRINT; |
| 1934 | return 1; |
| 1935 | } |
| 1936 | |
| 1937 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1938 | return 1; |
| 1939 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1940 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1941 | struct server *sv; |
| 1942 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1943 | sv = expect_server_admin(s, si, args[2]); |
| 1944 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1945 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1946 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1947 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 1948 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 1949 | appctx->st0 = STAT_CLI_PRINT; |
| 1950 | return 1; |
| 1951 | } |
| 1952 | |
| 1953 | sv->check.state |= CHK_ST_ENABLED; |
| 1954 | return 1; |
| 1955 | } |
| 1956 | else if (strcmp(args[1], "server") == 0) { |
| 1957 | struct server *sv; |
| 1958 | |
| 1959 | sv = expect_server_admin(s, si, args[2]); |
| 1960 | if (!sv) |
| 1961 | return 1; |
| 1962 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 1963 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1964 | return 1; |
| 1965 | } |
| 1966 | else if (strcmp(args[1], "frontend") == 0) { |
| 1967 | struct proxy *px; |
| 1968 | |
| 1969 | px = expect_frontend_admin(s, si, args[2]); |
| 1970 | if (!px) |
| 1971 | return 1; |
| 1972 | |
| 1973 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1974 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1975 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1976 | return 1; |
| 1977 | } |
| 1978 | |
| 1979 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1980 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1981 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1982 | return 1; |
| 1983 | } |
| 1984 | |
| 1985 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1986 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1987 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1988 | return 1; |
| 1989 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1990 | return 1; |
| 1991 | } |
| 1992 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1993 | 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] | 1994 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1995 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1996 | } |
| 1997 | } |
| 1998 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1999 | if (strcmp(args[1], "agent") == 0) { |
| 2000 | struct server *sv; |
| 2001 | |
| 2002 | sv = expect_server_admin(s, si, args[2]); |
| 2003 | if (!sv) |
| 2004 | return 1; |
| 2005 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2006 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2007 | return 1; |
| 2008 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2009 | else if (strcmp(args[1], "health") == 0) { |
| 2010 | struct server *sv; |
| 2011 | |
| 2012 | sv = expect_server_admin(s, si, args[2]); |
| 2013 | if (!sv) |
| 2014 | return 1; |
| 2015 | |
| 2016 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2017 | return 1; |
| 2018 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2019 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2020 | struct server *sv; |
| 2021 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2022 | sv = expect_server_admin(s, si, args[2]); |
| 2023 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2024 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2025 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2026 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2027 | return 1; |
| 2028 | } |
| 2029 | else if (strcmp(args[1], "frontend") == 0) { |
| 2030 | struct proxy *px; |
| 2031 | |
| 2032 | px = expect_frontend_admin(s, si, args[2]); |
| 2033 | if (!px) |
| 2034 | return 1; |
| 2035 | |
| 2036 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2037 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 2038 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2039 | return 1; |
| 2040 | } |
| 2041 | |
| 2042 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2043 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 2044 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2045 | return 1; |
| 2046 | } |
| 2047 | |
| 2048 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2049 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 2050 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2051 | return 1; |
| 2052 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2053 | return 1; |
| 2054 | } |
| 2055 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2056 | 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] | 2057 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2058 | return 1; |
| 2059 | } |
| 2060 | } |
| 2061 | else if (strcmp(args[0], "shutdown") == 0) { |
| 2062 | if (strcmp(args[1], "frontend") == 0) { |
| 2063 | struct proxy *px; |
| 2064 | |
| 2065 | px = expect_frontend_admin(s, si, args[2]); |
| 2066 | if (!px) |
| 2067 | return 1; |
| 2068 | |
| 2069 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2070 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 2071 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2072 | return 1; |
| 2073 | } |
| 2074 | |
| 2075 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2076 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2077 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2078 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2079 | stop_proxy(px); |
| 2080 | return 1; |
| 2081 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2082 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2083 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2084 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2085 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2086 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2087 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2088 | return 1; |
| 2089 | } |
| 2090 | |
| 2091 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2092 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2093 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2094 | return 1; |
| 2095 | } |
| 2096 | |
| 2097 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2098 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2099 | /* first, look for the requested stream in the stream table */ |
| 2100 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2101 | if (sess == ptr) |
| 2102 | break; |
| 2103 | } |
| 2104 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2105 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2106 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2107 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2108 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2109 | return 1; |
| 2110 | } |
| 2111 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2112 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2113 | return 1; |
| 2114 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2115 | else if (strcmp(args[1], "sessions") == 0) { |
| 2116 | if (strcmp(args[2], "server") == 0) { |
| 2117 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2118 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2119 | |
| 2120 | sv = expect_server_admin(s, si, args[3]); |
| 2121 | if (!sv) |
| 2122 | return 1; |
| 2123 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2124 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2125 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2126 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2127 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2128 | |
| 2129 | return 1; |
| 2130 | } |
| 2131 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2132 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2133 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2134 | return 1; |
| 2135 | } |
| 2136 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2137 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2138 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2139 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2140 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2141 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2142 | } |
| 2143 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2144 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2145 | if (args[1][0] == 'm') |
| 2146 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2147 | else |
| 2148 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2149 | |
| 2150 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2151 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2152 | if (!*args[2] || !*args[3]) { |
| 2153 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2154 | appctx->st0 = STAT_CLI_PRINT; |
| 2155 | return 1; |
| 2156 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2157 | } |
| 2158 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2159 | else { |
| 2160 | if (!*args[2] || !*args[3]) { |
| 2161 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2162 | appctx->st0 = STAT_CLI_PRINT; |
| 2163 | return 1; |
| 2164 | } |
| 2165 | } |
| 2166 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2167 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2168 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2169 | if (!appctx->ctx.map.ref || |
| 2170 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2171 | 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] | 2172 | appctx->st0 = STAT_CLI_PRINT; |
| 2173 | return 1; |
| 2174 | } |
| 2175 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2176 | /* If the entry identifier start with a '#', it is considered as |
| 2177 | * pointer id |
| 2178 | */ |
| 2179 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2180 | struct pat_ref_elt *ref; |
| 2181 | long long int conv; |
| 2182 | char *error; |
| 2183 | |
| 2184 | /* Convert argument to integer value. */ |
| 2185 | conv = strtoll(&args[3][1], &error, 16); |
| 2186 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2187 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2188 | appctx->st0 = STAT_CLI_PRINT; |
| 2189 | return 1; |
| 2190 | } |
| 2191 | |
| 2192 | /* Convert and check integer to pointer. */ |
| 2193 | ref = (struct pat_ref_elt *)(long)conv; |
| 2194 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2195 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2196 | appctx->st0 = STAT_CLI_PRINT; |
| 2197 | return 1; |
| 2198 | } |
| 2199 | |
| 2200 | /* Try to delete the entry. */ |
| 2201 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2202 | /* The entry is not found, send message. */ |
| 2203 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2204 | appctx->st0 = STAT_CLI_PRINT; |
| 2205 | return 1; |
| 2206 | } |
| 2207 | } |
| 2208 | else { |
| 2209 | /* Else, use the entry identifier as pattern |
| 2210 | * string and try to delete the entry. |
| 2211 | */ |
| 2212 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2213 | /* The entry is not found, send message. */ |
| 2214 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2215 | appctx->st0 = STAT_CLI_PRINT; |
| 2216 | return 1; |
| 2217 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2218 | } |
| 2219 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2220 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2221 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2222 | return 1; |
| 2223 | } |
| 2224 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2225 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2226 | appctx->st0 = STAT_CLI_PRINT; |
| 2227 | return 1; |
| 2228 | } |
| 2229 | } |
| 2230 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2231 | if (strcmp(args[1], "map") == 0 || |
| 2232 | strcmp(args[1], "acl") == 0) { |
| 2233 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2234 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2235 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2236 | /* Set flags. */ |
| 2237 | if (args[1][0] == 'm') |
| 2238 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2239 | else |
| 2240 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2241 | |
| 2242 | /* If the keywork is "map", we expect three parameters, if it |
| 2243 | * is "acl", we expect only two parameters |
| 2244 | */ |
| 2245 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2246 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2247 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2248 | appctx->st0 = STAT_CLI_PRINT; |
| 2249 | return 1; |
| 2250 | } |
| 2251 | } |
| 2252 | else { |
| 2253 | if (!*args[2] || !*args[3]) { |
| 2254 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2255 | appctx->st0 = STAT_CLI_PRINT; |
| 2256 | return 1; |
| 2257 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2258 | } |
| 2259 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2260 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2261 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2262 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2263 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2264 | 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] | 2265 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2266 | 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] | 2267 | appctx->st0 = STAT_CLI_PRINT; |
| 2268 | return 1; |
| 2269 | } |
| 2270 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2271 | /* The command "add acl" is prohibited if the reference |
| 2272 | * use samples. |
| 2273 | */ |
| 2274 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2275 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2276 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2277 | "You must use the command 'add map' to add values.\n"; |
| 2278 | appctx->st0 = STAT_CLI_PRINT; |
| 2279 | return 1; |
| 2280 | } |
| 2281 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2282 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2283 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2284 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2285 | 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] | 2286 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2287 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2288 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2289 | if (err) |
| 2290 | memprintf(&err, "%s.\n", err); |
| 2291 | appctx->ctx.cli.err = err; |
| 2292 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2293 | return 1; |
| 2294 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2295 | |
| 2296 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2297 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2298 | return 1; |
| 2299 | } |
| 2300 | else { /* unknown "del" parameter */ |
| 2301 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2302 | appctx->st0 = STAT_CLI_PRINT; |
| 2303 | return 1; |
| 2304 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2305 | } |
| 2306 | 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] | 2307 | return 0; |
| 2308 | } |
| 2309 | return 1; |
| 2310 | } |
| 2311 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2312 | /* 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] | 2313 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2314 | * state machine handling requests and various responses. We read a request, |
| 2315 | * 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] | 2316 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2317 | * 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] | 2318 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2319 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2320 | static void cli_io_handler(struct appctx *appctx) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2321 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2322 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2323 | struct channel *req = si_oc(si); |
| 2324 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2325 | int reql; |
| 2326 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2327 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2328 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2329 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2330 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2331 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2332 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2333 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2334 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2335 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2336 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2337 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2338 | /* Let's close for real now. We just close the request |
| 2339 | * side, the conditions below will complete if needed. |
| 2340 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2341 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2342 | break; |
| 2343 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2344 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2345 | /* ensure we have some output room left in the event we |
| 2346 | * would want to return some info right after parsing. |
| 2347 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2348 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2349 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2350 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2351 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2352 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2353 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2354 | if (reql <= 0) { /* closed or EOL not found */ |
| 2355 | if (reql == 0) |
| 2356 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2357 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2358 | continue; |
| 2359 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2360 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2361 | /* seek for a possible semi-colon. If we find one, we |
| 2362 | * replace it with an LF and skip only this part. |
| 2363 | */ |
| 2364 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2365 | if (trash.str[len] == ';') { |
| 2366 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2367 | reql = len + 1; |
| 2368 | break; |
| 2369 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2370 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2371 | /* now it is time to check that we have a full line, |
| 2372 | * remove the trailing \n and possibly \r, then cut the |
| 2373 | * line. |
| 2374 | */ |
| 2375 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2376 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2377 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2378 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2379 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2380 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2381 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2382 | len--; |
| 2383 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2384 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2385 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2386 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2387 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2388 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2389 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2390 | continue; |
| 2391 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2392 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2393 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2394 | else if (strcmp(trash.str, "help") == 0 || |
| 2395 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2396 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2397 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2398 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2399 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2400 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2401 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2402 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2403 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2404 | /* if prompt is disabled, print help on empty lines, |
| 2405 | * so that the user at least knows how to enable |
| 2406 | * prompt and find help. |
| 2407 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2408 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2409 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2413 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2414 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2415 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2416 | 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] | 2417 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2418 | cli_release_handler(appctx); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2419 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2420 | continue; |
| 2421 | } |
| 2422 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2423 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2424 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2425 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2426 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2427 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2428 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2429 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2430 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2431 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2432 | free(appctx->ctx.cli.err); |
| 2433 | appctx->st0 = STAT_CLI_PROMPT; |
| 2434 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2435 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2436 | si_applet_cant_put(si); |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2437 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2438 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2439 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2440 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2441 | break; |
| 2442 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2443 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2444 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2445 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2446 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2447 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2448 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2449 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2450 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2451 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2452 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2453 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2454 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2455 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2456 | if (stats_table_request(si, appctx->st0)) |
| 2457 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2458 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2459 | case STAT_CLI_O_PATS: |
| 2460 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2461 | appctx->st0 = STAT_CLI_PROMPT; |
| 2462 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2463 | case STAT_CLI_O_PAT: |
| 2464 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2465 | appctx->st0 = STAT_CLI_PROMPT; |
| 2466 | break; |
| 2467 | case STAT_CLI_O_MLOOK: |
| 2468 | if (stats_map_lookup(si)) |
| 2469 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2470 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2471 | case STAT_CLI_O_POOLS: |
| 2472 | if (stats_dump_pools_to_buffer(si)) |
| 2473 | appctx->st0 = STAT_CLI_PROMPT; |
| 2474 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2475 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2476 | case STAT_CLI_O_TLSK: |
| 2477 | if (stats_tlskeys_list(si)) |
| 2478 | appctx->st0 = STAT_CLI_PROMPT; |
| 2479 | break; |
| 2480 | #endif |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2481 | default: /* abnormal state */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2482 | cli_release_handler(appctx); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2483 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2484 | break; |
| 2485 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2486 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2487 | /* 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] | 2488 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2489 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2490 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2491 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2492 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2493 | } |
| 2494 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2495 | /* 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] | 2496 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2497 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2498 | |
| 2499 | /* Now we close the output if one of the writers did so, |
| 2500 | * or if we're not in interactive mode and the request |
| 2501 | * buffer is empty. This still allows pipelined requests |
| 2502 | * to be sent in non-interactive mode. |
| 2503 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2504 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2505 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2506 | continue; |
| 2507 | } |
| 2508 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2509 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2510 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2511 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2512 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2513 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2514 | 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] | 2515 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2516 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2517 | /* 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] | 2518 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2519 | * we forward the close to the request side so that it flows upstream to |
| 2520 | * the client. |
| 2521 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2522 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2523 | } |
| 2524 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2525 | 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] | 2526 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2527 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2528 | /* We have no more processing to do, and nothing more to send, and |
| 2529 | * the client side has closed. So we'll forward this state downstream |
| 2530 | * on the response buffer. |
| 2531 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2532 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2533 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2534 | } |
| 2535 | |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 2536 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2537 | 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] | 2538 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2539 | si->state, req->flags, res->flags, req->buf->i, req->buf->o, res->buf->i, res->buf->o); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2540 | } |
| 2541 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2542 | /* This function dumps information onto the stream interface's read buffer. |
| 2543 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2544 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2545 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2546 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2547 | { |
| 2548 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2549 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2550 | #ifdef USE_OPENSSL |
| 2551 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2552 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2553 | int ssl_reuse = 0; |
| 2554 | |
| 2555 | if (ssl_key_rate < ssl_sess_rate) { |
| 2556 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2557 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2558 | } |
| 2559 | #endif |
| 2560 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2561 | chunk_printf(&trash, |
| 2562 | "Name: " PRODUCT_NAME "\n" |
| 2563 | "Version: " HAPROXY_VERSION "\n" |
| 2564 | "Release_date: " HAPROXY_DATE "\n" |
| 2565 | "Nbproc: %d\n" |
| 2566 | "Process_num: %d\n" |
| 2567 | "Pid: %d\n" |
| 2568 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2569 | "Uptime_sec: %d\n" |
| 2570 | "Memmax_MB: %d\n" |
| 2571 | "Ulimit-n: %d\n" |
| 2572 | "Maxsock: %d\n" |
| 2573 | "Maxconn: %d\n" |
| 2574 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2575 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2576 | "CumConns: %d\n" |
Warren Turkal | b197d7f | 2015-01-27 15:04:16 -0800 | [diff] [blame] | 2577 | "CumReq: %u\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2578 | #ifdef USE_OPENSSL |
| 2579 | "MaxSslConns: %d\n" |
| 2580 | "CurrSslConns: %d\n" |
| 2581 | "CumSslConns: %d\n" |
| 2582 | #endif |
| 2583 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2584 | "PipesUsed: %d\n" |
| 2585 | "PipesFree: %d\n" |
| 2586 | "ConnRate: %d\n" |
| 2587 | "ConnRateLimit: %d\n" |
| 2588 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2589 | "SessRate: %d\n" |
| 2590 | "SessRateLimit: %d\n" |
| 2591 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2592 | #ifdef USE_OPENSSL |
| 2593 | "SslRate: %d\n" |
| 2594 | "SslRateLimit: %d\n" |
| 2595 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2596 | "SslFrontendKeyRate: %d\n" |
| 2597 | "SslFrontendMaxKeyRate: %d\n" |
| 2598 | "SslFrontendSessionReuse_pct: %d\n" |
| 2599 | "SslBackendKeyRate: %d\n" |
| 2600 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2601 | "SslCacheLookups: %u\n" |
| 2602 | "SslCacheMisses: %u\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2603 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2604 | "CompressBpsIn: %u\n" |
| 2605 | "CompressBpsOut: %u\n" |
| 2606 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2607 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2608 | "ZlibMemUsage: %ld\n" |
| 2609 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2610 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2611 | "Tasks: %d\n" |
| 2612 | "Run_queue: %d\n" |
| 2613 | "Idle_pct: %d\n" |
| 2614 | "node: %s\n" |
| 2615 | "description: %s\n" |
| 2616 | "", |
| 2617 | global.nbproc, |
| 2618 | relative_pid, |
| 2619 | pid, |
| 2620 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2621 | up, |
| 2622 | global.rlimit_memmax, |
| 2623 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2624 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2625 | actconn, totalconn, global.req_count, |
| 2626 | #ifdef USE_OPENSSL |
| 2627 | global.maxsslconn, sslconns, totalsslconns, |
| 2628 | #endif |
| 2629 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2630 | 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] | 2631 | 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] | 2632 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2633 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2634 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2635 | ssl_reuse, |
| 2636 | 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] | 2637 | global.shctx_lookups, global.shctx_misses, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2638 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2639 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2640 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2641 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2642 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2643 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2644 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2645 | global.node, global.desc ? global.desc : "" |
| 2646 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2647 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2648 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2649 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2650 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2651 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2652 | |
| 2653 | return 1; |
| 2654 | } |
| 2655 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2656 | /* This function dumps memory usage information onto the stream interface's |
| 2657 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2658 | * completion. No state is used. |
| 2659 | */ |
| 2660 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2661 | { |
| 2662 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2663 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2664 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2665 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2666 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2667 | return 1; |
| 2668 | } |
| 2669 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2670 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2671 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2672 | * 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] | 2673 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2674 | 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] | 2675 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2676 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2677 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2678 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2679 | if (!(px->cap & PR_CAP_FE)) |
| 2680 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2681 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2682 | 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] | 2683 | return 0; |
| 2684 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2685 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2686 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2687 | /* name, queue */ |
| 2688 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2689 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2690 | 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] | 2691 | /* Column sub-heading for Enable or Disable server */ |
| 2692 | chunk_appendf(&trash, "<td></td>"); |
| 2693 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2694 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2695 | chunk_appendf(&trash, |
| 2696 | "<td class=ac>" |
| 2697 | "<a name=\"%s/Frontend\"></a>" |
| 2698 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2699 | "<td colspan=3></td>" |
| 2700 | "", |
| 2701 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2702 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2703 | chunk_appendf(&trash, |
| 2704 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2705 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2706 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2707 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2708 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2709 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2710 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2711 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2712 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2713 | if (px->mode == PR_MODE_HTTP) |
| 2714 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2715 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2716 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2717 | |
| 2718 | chunk_appendf(&trash, |
| 2719 | "</table></div></u></td>" |
| 2720 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2721 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2722 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2723 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2724 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2725 | U2H(px->fe_counters.sps_max), |
| 2726 | U2H(px->fe_counters.cps_max), |
| 2727 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2728 | |
| 2729 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2730 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2731 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2732 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2733 | |
| 2734 | chunk_appendf(&trash, |
| 2735 | "</table></div></u></td>" |
| 2736 | /* sessions rate : limit */ |
| 2737 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2738 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2739 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2740 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2741 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2742 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2743 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2744 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2745 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2746 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2747 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2748 | U2H(px->fe_counters.cum_sess), |
| 2749 | U2H(px->fe_counters.cum_conn), |
| 2750 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2751 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2752 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2753 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2754 | chunk_appendf(&trash, |
| 2755 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2756 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2757 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2758 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2759 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2760 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2761 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2762 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2763 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2764 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2765 | U2H(px->fe_counters.p.http.cum_req), |
| 2766 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2767 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2768 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2769 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2770 | (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] | 2771 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2772 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2773 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2774 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2775 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2776 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2777 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2778 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2779 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2780 | /* sessions: lbtot, lastsess */ |
| 2781 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2782 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2783 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2784 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2785 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2786 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2787 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2788 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2789 | "<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] | 2790 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2791 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2792 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2793 | px->fe_counters.comp_in ? |
| 2794 | (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] | 2795 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2796 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2797 | chunk_appendf(&trash, |
| 2798 | /* denied: req, resp */ |
| 2799 | "<td>%s</td><td>%s</td>" |
| 2800 | /* errors : request, connect, response */ |
| 2801 | "<td>%s</td><td></td><td></td>" |
| 2802 | /* warnings: retries, redispatches */ |
| 2803 | "<td></td><td></td>" |
| 2804 | /* server status : reflect frontend status */ |
| 2805 | "<td class=ac>%s</td>" |
| 2806 | /* rest of server: nothing */ |
| 2807 | "<td class=ac colspan=8></td></tr>" |
| 2808 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2809 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2810 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2811 | px->state == PR_STREADY ? "OPEN" : |
| 2812 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2813 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2814 | else { /* CSV mode */ |
| 2815 | chunk_appendf(&trash, |
| 2816 | /* pxid, name, queue cur, queue max, */ |
| 2817 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2818 | /* sessions : current, max, limit, total */ |
| 2819 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2820 | /* bytes : in, out */ |
| 2821 | "%lld,%lld," |
| 2822 | /* denied: req, resp */ |
| 2823 | "%lld,%lld," |
| 2824 | /* errors : request, connect, response */ |
| 2825 | "%lld,,," |
| 2826 | /* warnings: retries, redispatches */ |
| 2827 | ",," |
| 2828 | /* server status : reflect frontend status */ |
| 2829 | "%s," |
| 2830 | /* rest of server: nothing */ |
| 2831 | ",,,,,,,," |
| 2832 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2833 | "%d,%d,0,,,,%d," |
| 2834 | /* rate, rate_lim, rate_max */ |
| 2835 | "%u,%u,%u," |
| 2836 | /* check_status, check_code, check_duration */ |
| 2837 | ",,,", |
| 2838 | px->id, |
| 2839 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2840 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2841 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2842 | px->fe_counters.failed_req, |
| 2843 | px->state == PR_STREADY ? "OPEN" : |
| 2844 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2845 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2846 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2847 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2848 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2849 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2850 | if (px->mode == PR_MODE_HTTP) { |
| 2851 | for (i=1; i<6; i++) |
| 2852 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2853 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2854 | } |
| 2855 | else |
| 2856 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2857 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2858 | /* failed health analyses */ |
| 2859 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2860 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2861 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2862 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2863 | read_freq_ctr(&px->fe_req_per_sec), |
| 2864 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2865 | |
| 2866 | /* errors: cli_aborts, srv_aborts */ |
| 2867 | chunk_appendf(&trash, ",,"); |
| 2868 | |
| 2869 | /* compression: in, out, bypassed */ |
| 2870 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2871 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2872 | |
| 2873 | /* compression: comp_rsp */ |
| 2874 | chunk_appendf(&trash, "%lld,", |
| 2875 | px->fe_counters.p.http.comp_rsp); |
| 2876 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2877 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2878 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2879 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2880 | /* finish with EOL */ |
| 2881 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2882 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2883 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2884 | } |
| 2885 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2886 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2887 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2888 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2889 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2890 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2891 | 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] | 2892 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2893 | struct appctx *appctx = __objt_appctx(si->end); |
| 2894 | |
| 2895 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2896 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2897 | 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] | 2898 | /* Column sub-heading for Enable or Disable server */ |
| 2899 | chunk_appendf(&trash, "<td></td>"); |
| 2900 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2901 | chunk_appendf(&trash, |
| 2902 | /* frontend name, listener name */ |
| 2903 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2904 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2905 | "", |
| 2906 | px->id, l->name, |
| 2907 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2908 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2909 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2910 | if (flags & ST_SHLGNDS) { |
| 2911 | char str[INET6_ADDRSTRLEN]; |
| 2912 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2913 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2914 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2915 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2916 | port = get_host_port(&l->addr); |
| 2917 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2918 | case AF_INET: |
| 2919 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2920 | break; |
| 2921 | case AF_INET6: |
| 2922 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2923 | break; |
| 2924 | case AF_UNIX: |
| 2925 | chunk_appendf(&trash, "unix, "); |
| 2926 | break; |
| 2927 | case -1: |
| 2928 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2929 | break; |
| 2930 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2931 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2932 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2933 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2934 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2935 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2936 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2937 | /* queue */ |
| 2938 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2939 | /* sessions rate: current, max, limit */ |
| 2940 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2941 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2942 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2943 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2944 | /* bytes: in, out */ |
| 2945 | "<td>%s</td><td>%s</td>" |
| 2946 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2947 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2948 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2949 | 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] | 2950 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2951 | chunk_appendf(&trash, |
| 2952 | /* denied: req, resp */ |
| 2953 | "<td>%s</td><td>%s</td>" |
| 2954 | /* errors: request, connect, response */ |
| 2955 | "<td>%s</td><td></td><td></td>" |
| 2956 | /* warnings: retries, redispatches */ |
| 2957 | "<td></td><td></td>" |
| 2958 | /* server status: reflect listener status */ |
| 2959 | "<td class=ac>%s</td>" |
| 2960 | /* rest of server: nothing */ |
| 2961 | "<td class=ac colspan=8></td></tr>" |
| 2962 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2963 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2964 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2965 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2966 | } |
| 2967 | else { /* CSV mode */ |
| 2968 | chunk_appendf(&trash, |
| 2969 | /* pxid, name, queue cur, queue max, */ |
| 2970 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2971 | /* sessions: current, max, limit, total */ |
| 2972 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2973 | /* bytes: in, out */ |
| 2974 | "%lld,%lld," |
| 2975 | /* denied: req, resp */ |
| 2976 | "%lld,%lld," |
| 2977 | /* errors: request, connect, response */ |
| 2978 | "%lld,,," |
| 2979 | /* warnings: retries, redispatches */ |
| 2980 | ",," |
| 2981 | /* server status: reflect listener status */ |
| 2982 | "%s," |
| 2983 | /* rest of server: nothing */ |
| 2984 | ",,,,,,,," |
| 2985 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2986 | "%d,%d,%d,,,,%d," |
| 2987 | /* rate, rate_lim, rate_max */ |
| 2988 | ",,," |
| 2989 | /* check_status, check_code, check_duration */ |
| 2990 | ",,," |
| 2991 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2992 | ",,,,,," |
| 2993 | /* failed health analyses */ |
| 2994 | "," |
| 2995 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2996 | ",,," |
| 2997 | /* errors: cli_aborts, srv_aborts */ |
| 2998 | ",," |
| 2999 | /* compression: in, out, bypassed, comp_rsp */ |
| 3000 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3001 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 3002 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3003 | "\n", |
| 3004 | px->id, l->name, |
| 3005 | l->nbconn, l->counters->conn_max, |
| 3006 | l->maxconn, l->counters->cum_conn, |
| 3007 | l->counters->bytes_in, l->counters->bytes_out, |
| 3008 | l->counters->denied_req, l->counters->denied_resp, |
| 3009 | l->counters->failed_req, |
| 3010 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 3011 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 3012 | } |
| 3013 | return 1; |
| 3014 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3015 | |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3016 | enum srv_stats_state { |
| 3017 | SRV_STATS_STATE_DOWN = 0, |
| 3018 | SRV_STATS_STATE_DOWN_AGENT, |
| 3019 | SRV_STATS_STATE_GOING_UP, |
| 3020 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 3021 | SRV_STATS_STATE_UP, |
| 3022 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 3023 | SRV_STATS_STATE_NOLB, |
| 3024 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 3025 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3026 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3027 | SRV_STATS_STATE_NO_CHECK, |
| 3028 | |
| 3029 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 3030 | }; |
| 3031 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3032 | enum srv_stats_colour { |
| 3033 | SRV_STATS_COLOUR_DOWN = 0, |
| 3034 | SRV_STATS_COLOUR_GOING_UP, |
| 3035 | SRV_STATS_COLOUR_GOING_DOWN, |
| 3036 | SRV_STATS_COLOUR_UP, |
| 3037 | SRV_STATS_COLOUR_NOLB, |
| 3038 | SRV_STATS_COLOUR_DRAINING, |
| 3039 | SRV_STATS_COLOUR_NO_CHECK, |
| 3040 | |
| 3041 | SRV_STATS_COLOUR_COUNT, /* Must be last */ |
| 3042 | }; |
| 3043 | |
| 3044 | static const char *srv_stats_colour_st[SRV_STATS_COLOUR_COUNT] = { |
| 3045 | [SRV_STATS_COLOUR_DOWN] = "down", |
| 3046 | [SRV_STATS_COLOUR_GOING_UP] = "going_up", |
| 3047 | [SRV_STATS_COLOUR_GOING_DOWN] = "going_down", |
| 3048 | [SRV_STATS_COLOUR_UP] = "up", |
| 3049 | [SRV_STATS_COLOUR_NOLB] = "nolb", |
| 3050 | [SRV_STATS_COLOUR_DRAINING] = "draining", |
| 3051 | [SRV_STATS_COLOUR_NO_CHECK] = "no_check", |
| 3052 | }; |
| 3053 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3054 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 3055 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 3056 | * 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] | 3057 | * if it emits anything, zero otherwise. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3058 | */ |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3059 | 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] | 3060 | enum srv_stats_state state, enum srv_stats_colour colour) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3061 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3062 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3063 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3064 | char str[INET6_ADDRSTRLEN]; |
| 3065 | struct chunk src; |
| 3066 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3067 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3068 | /* we have "via" which is the tracked server as described in the configuration, |
| 3069 | * and "ref" which is the checked server and the end of the chain. |
| 3070 | */ |
| 3071 | via = sv->track ? sv->track : sv; |
| 3072 | ref = via; |
| 3073 | while (ref->track) |
| 3074 | ref = ref->track; |
| 3075 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3076 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3077 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3078 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 3079 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 3080 | [SRV_STATS_STATE_GOING_UP] = "DN %d/%d ↑", |
| 3081 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d ↓", |
| 3082 | [SRV_STATS_STATE_UP] = "UP", |
| 3083 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d ↓", |
| 3084 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 3085 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d ↓", |
| 3086 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3087 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3088 | [SRV_STATS_STATE_NO_CHECK] = "<i>no check</i>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3089 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3090 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3091 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3092 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 3093 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3094 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3095 | "<tr class=\"%s_%s\">", |
| 3096 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", srv_stats_colour_st[colour]); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3097 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3098 | 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] | 3099 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3100 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3101 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3102 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3103 | chunk_appendf(&trash, |
| 3104 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3105 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3106 | "", |
| 3107 | px->id, sv->id, |
| 3108 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3109 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3110 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3111 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3112 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3113 | |
| 3114 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 3115 | case AF_INET: |
| 3116 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 3117 | break; |
| 3118 | case AF_INET6: |
| 3119 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 3120 | break; |
| 3121 | case AF_UNIX: |
| 3122 | chunk_appendf(&trash, "unix, "); |
| 3123 | break; |
| 3124 | case -1: |
| 3125 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3126 | break; |
| 3127 | default: /* address family not supported */ |
| 3128 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3129 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3130 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3131 | /* id */ |
| 3132 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3133 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3134 | /* cookie */ |
| 3135 | if (sv->cookie) { |
| 3136 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3137 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3138 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3139 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3140 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3141 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3142 | } |
| 3143 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3144 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3145 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3146 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3147 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3148 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3149 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3150 | /* sessions rate : current, max, limit */ |
| 3151 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3152 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3153 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3154 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3155 | 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] | 3156 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3157 | |
| 3158 | chunk_appendf(&trash, |
| 3159 | /* sessions: current, max, limit, total */ |
| 3160 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3161 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3162 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3163 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3164 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3165 | U2H(sv->counters.cum_sess), |
| 3166 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3167 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3168 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3169 | if (px->mode == PR_MODE_HTTP) { |
| 3170 | unsigned long long tot; |
| 3171 | for (tot = i = 0; i < 6; i++) |
| 3172 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3173 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3174 | chunk_appendf(&trash, |
| 3175 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3176 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3177 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3178 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3179 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3180 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3181 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3182 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3183 | U2H(tot), |
| 3184 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3185 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3186 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3187 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3188 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3189 | 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] | 3190 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3191 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3192 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3193 | 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))); |
| 3194 | 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))); |
| 3195 | if (px->mode == PR_MODE_HTTP) |
| 3196 | 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))); |
| 3197 | 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))); |
| 3198 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3199 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3200 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3201 | /* sessions: lbtot, last */ |
| 3202 | "<td>%s</td><td>%s</td>", |
| 3203 | U2H(sv->counters.cum_lbconn), |
| 3204 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3205 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3206 | chunk_appendf(&trash, |
| 3207 | /* bytes : in, out */ |
| 3208 | "<td>%s</td><td>%s</td>" |
| 3209 | /* denied: req, resp */ |
| 3210 | "<td></td><td>%s</td>" |
| 3211 | /* errors : request, connect */ |
| 3212 | "<td></td><td>%s</td>" |
| 3213 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3214 | "<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] | 3215 | /* warnings: retries, redispatches */ |
| 3216 | "<td>%lld</td><td>%lld</td>" |
| 3217 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3218 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3219 | U2H(sv->counters.failed_secu), |
| 3220 | U2H(sv->counters.failed_conns), |
| 3221 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3222 | sv->counters.cli_aborts, |
| 3223 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3224 | sv->counters.retries, sv->counters.redispatches); |
| 3225 | |
| 3226 | /* status, lest check */ |
| 3227 | chunk_appendf(&trash, "<td class=ac>"); |
| 3228 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3229 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3230 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3231 | chunk_appendf(&trash, "MAINT"); |
| 3232 | } |
Simon Horman | 0766e44 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3233 | 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] | 3234 | 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] | 3235 | /* DOWN (agent) */ |
| 3236 | 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] | 3237 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3238 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3239 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3240 | chunk_appendf(&trash, |
| 3241 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3242 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3243 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3244 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3245 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3246 | if ((sv->state == SRV_ST_STOPPED) && |
| 3247 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3248 | chunk_appendf(&trash, |
| 3249 | "</td><td class=ac><u> %s%s", |
| 3250 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3251 | get_check_status_info(sv->agent.status)); |
| 3252 | |
| 3253 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3254 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3255 | |
| 3256 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3257 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3258 | |
| 3259 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3260 | get_check_status_description(sv->agent.status)); |
| 3261 | if (*sv->agent.desc) { |
| 3262 | chunk_appendf(&trash, ": "); |
| 3263 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3264 | chunk_htmlencode(&trash, &src); |
| 3265 | } |
| 3266 | chunk_appendf(&trash, "</div></u>"); |
| 3267 | } |
| 3268 | 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] | 3269 | chunk_appendf(&trash, |
| 3270 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3271 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3272 | get_check_status_info(sv->check.status)); |
| 3273 | |
| 3274 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3275 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3276 | |
| 3277 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3278 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3279 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3280 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3281 | get_check_status_description(sv->check.status)); |
| 3282 | if (*sv->check.desc) { |
| 3283 | chunk_appendf(&trash, ": "); |
| 3284 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3285 | chunk_htmlencode(&trash, &src); |
| 3286 | } |
| 3287 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3288 | } |
| 3289 | else |
| 3290 | chunk_appendf(&trash, "</td><td>"); |
| 3291 | |
| 3292 | chunk_appendf(&trash, |
| 3293 | /* weight */ |
| 3294 | "</td><td class=ac>%d</td>" |
| 3295 | /* act, bck */ |
| 3296 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3297 | "", |
| 3298 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3299 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3300 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3301 | |
| 3302 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3303 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3304 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3305 | |
| 3306 | if (ref->observe) |
| 3307 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3308 | |
| 3309 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3310 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3311 | "<td>%lld</td><td>%s</td>" |
| 3312 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3313 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3314 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3315 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3316 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3317 | /* tracking a server */ |
| 3318 | chunk_appendf(&trash, |
| 3319 | "<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] | 3320 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3321 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3322 | else |
| 3323 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3324 | |
| 3325 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3326 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3327 | 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] | 3328 | else |
| 3329 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3330 | } |
| 3331 | else { /* CSV mode */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3332 | struct chunk *out = get_trash_chunk(); |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3333 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3334 | [SRV_STATS_STATE_DOWN] = "DOWN,", |
| 3335 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent),", |
| 3336 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d,", |
| 3337 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d,", |
| 3338 | [SRV_STATS_STATE_UP] = "UP,", |
| 3339 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d,", |
| 3340 | [SRV_STATS_STATE_NOLB] = "NOLB,", |
| 3341 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d,", |
| 3342 | [SRV_STATS_STATE_DRAIN] = "DRAIN,", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3343 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3344 | [SRV_STATS_STATE_NO_CHECK] = "no check," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3345 | }; |
| 3346 | |
| 3347 | chunk_appendf(&trash, |
| 3348 | /* pxid, name */ |
| 3349 | "%s,%s," |
| 3350 | /* queue : current, max */ |
| 3351 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3352 | /* sessions : current, max, limit, total */ |
| 3353 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3354 | /* bytes : in, out */ |
| 3355 | "%lld,%lld," |
| 3356 | /* denied: req, resp */ |
| 3357 | ",%lld," |
| 3358 | /* errors : request, connect, response */ |
| 3359 | ",%lld,%lld," |
| 3360 | /* warnings: retries, redispatches */ |
| 3361 | "%lld,%lld," |
| 3362 | "", |
| 3363 | px->id, sv->id, |
| 3364 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3365 | 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] | 3366 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3367 | sv->counters.failed_secu, |
| 3368 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3369 | sv->counters.retries, sv->counters.redispatches); |
| 3370 | |
| 3371 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3372 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3373 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3374 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3375 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3376 | else |
| 3377 | chunk_appendf(&trash, |
| 3378 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3379 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3380 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3381 | |
| 3382 | chunk_appendf(&trash, |
| 3383 | /* weight, active, backup */ |
| 3384 | "%d,%d,%d," |
| 3385 | "", |
| 3386 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3387 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3388 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3389 | |
| 3390 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3391 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3392 | chunk_appendf(&trash, |
| 3393 | "%lld,%lld,%d,%d,", |
| 3394 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3395 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3396 | else |
| 3397 | chunk_appendf(&trash, ",,,,"); |
| 3398 | |
| 3399 | /* queue limit, pid, iid, sid, */ |
| 3400 | chunk_appendf(&trash, |
| 3401 | "%s," |
| 3402 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3403 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3404 | relative_pid, px->uuid, sv->puid); |
| 3405 | |
| 3406 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3407 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3408 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3409 | |
| 3410 | /* sessions: lbtot */ |
| 3411 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3412 | |
| 3413 | /* tracked */ |
| 3414 | if (sv->track) |
| 3415 | chunk_appendf(&trash, "%s/%s,", |
| 3416 | sv->track->proxy->id, sv->track->id); |
| 3417 | else |
| 3418 | chunk_appendf(&trash, ","); |
| 3419 | |
| 3420 | /* type */ |
| 3421 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3422 | |
| 3423 | /* rate */ |
| 3424 | chunk_appendf(&trash, "%u,,%u,", |
| 3425 | read_freq_ctr(&sv->sess_per_sec), |
| 3426 | sv->counters.sps_max); |
| 3427 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3428 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3429 | /* check_status */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3430 | chunk_appendf(&trash, "%s,", csv_enc(get_check_status_info(sv->check.status), 1, out)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3431 | |
| 3432 | /* check_code */ |
| 3433 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3434 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3435 | else |
| 3436 | chunk_appendf(&trash, ","); |
| 3437 | |
| 3438 | /* check_duration */ |
| 3439 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3440 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3441 | else |
| 3442 | chunk_appendf(&trash, ","); |
| 3443 | |
| 3444 | } |
| 3445 | else |
| 3446 | chunk_appendf(&trash, ",,,"); |
| 3447 | |
| 3448 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3449 | if (px->mode == PR_MODE_HTTP) { |
| 3450 | for (i=1; i<6; i++) |
| 3451 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3452 | |
| 3453 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3454 | } |
| 3455 | else |
| 3456 | chunk_appendf(&trash, ",,,,,,"); |
| 3457 | |
| 3458 | /* failed health analyses */ |
| 3459 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3460 | |
| 3461 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3462 | chunk_appendf(&trash, ",,,"); |
| 3463 | |
| 3464 | /* errors: cli_aborts, srv_aborts */ |
| 3465 | chunk_appendf(&trash, "%lld,%lld,", |
| 3466 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3467 | |
| 3468 | /* compression: in, out, bypassed, comp_rsp */ |
| 3469 | chunk_appendf(&trash, ",,,,"); |
| 3470 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3471 | /* lastsess */ |
| 3472 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3473 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3474 | /* capture of last check and agent statuses */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3475 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->check.desc), 1, out) : ""); |
| 3476 | chunk_appendf(&trash, "%s,", ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->agent.desc), 1, out) : ""); |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3477 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3478 | /* qtime, ctime, rtime, ttime, */ |
| 3479 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3480 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3481 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3482 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3483 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3484 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3485 | /* finish with EOL */ |
| 3486 | chunk_appendf(&trash, "\n"); |
| 3487 | } |
| 3488 | return 1; |
| 3489 | } |
| 3490 | |
| 3491 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3492 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3493 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3494 | */ |
| 3495 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3496 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3497 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3498 | struct chunk src; |
| 3499 | int i; |
| 3500 | |
| 3501 | if (!(px->cap & PR_CAP_BE)) |
| 3502 | return 0; |
| 3503 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3504 | 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] | 3505 | return 0; |
| 3506 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3507 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3508 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3509 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3510 | /* Column sub-heading for Enable or Disable server */ |
| 3511 | chunk_appendf(&trash, "<td></td>"); |
| 3512 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3513 | chunk_appendf(&trash, |
| 3514 | "<td class=ac>" |
| 3515 | /* name */ |
| 3516 | "%s<a name=\"%s/Backend\"></a>" |
| 3517 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3518 | "", |
| 3519 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3520 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3521 | |
| 3522 | if (flags & ST_SHLGNDS) { |
| 3523 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3524 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3525 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3526 | |
| 3527 | /* cookie */ |
| 3528 | if (px->cookie_name) { |
| 3529 | chunk_appendf(&trash, ", cookie: '"); |
| 3530 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3531 | chunk_htmlencode(&trash, &src); |
| 3532 | chunk_appendf(&trash, "'"); |
| 3533 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3534 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3538 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3539 | /* queue : current, max */ |
| 3540 | "<td>%s</td><td>%s</td><td></td>" |
| 3541 | /* sessions rate : current, max, limit */ |
| 3542 | "<td>%s</td><td>%s</td><td></td>" |
| 3543 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3544 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3545 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3546 | 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] | 3547 | |
| 3548 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3549 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3550 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3551 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3552 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3553 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3554 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3555 | U2H(px->be_counters.cum_conn), |
| 3556 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3557 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3558 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3559 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3560 | chunk_appendf(&trash, |
| 3561 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3562 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3563 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3564 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3565 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3566 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3567 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3568 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3569 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3570 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3571 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3572 | U2H(px->be_counters.p.http.cum_req), |
| 3573 | U2H(px->be_counters.p.http.rsp[1]), |
| 3574 | U2H(px->be_counters.p.http.rsp[2]), |
| 3575 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3576 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3577 | (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] | 3578 | U2H(px->be_counters.p.http.rsp[3]), |
| 3579 | U2H(px->be_counters.p.http.rsp[4]), |
| 3580 | U2H(px->be_counters.p.http.rsp[5]), |
| 3581 | U2H(px->be_counters.p.http.rsp[0]), |
| 3582 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3583 | } |
| 3584 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3585 | 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))); |
| 3586 | 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))); |
| 3587 | if (px->mode == PR_MODE_HTTP) |
| 3588 | 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))); |
| 3589 | 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))); |
| 3590 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3591 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3592 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3593 | /* sessions: lbtot, last */ |
| 3594 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3595 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3596 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3597 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3598 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3599 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3600 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3601 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3602 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3603 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3604 | "<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] | 3605 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3606 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3607 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3608 | px->be_counters.comp_in ? |
| 3609 | (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] | 3610 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3611 | |
| 3612 | chunk_appendf(&trash, |
| 3613 | /* denied: req, resp */ |
| 3614 | "<td>%s</td><td>%s</td>" |
| 3615 | /* errors : request, connect */ |
| 3616 | "<td></td><td>%s</td>" |
| 3617 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3618 | "<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] | 3619 | /* warnings: retries, redispatches */ |
| 3620 | "<td>%lld</td><td>%lld</td>" |
| 3621 | /* backend status: reflect backend status (up/down): we display UP |
| 3622 | * if the backend has known working servers or if it has no server at |
| 3623 | * all (eg: for stats). Then we display the total weight, number of |
| 3624 | * active and backups. */ |
| 3625 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3626 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3627 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3628 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3629 | U2H(px->be_counters.failed_conns), |
| 3630 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3631 | px->be_counters.cli_aborts, |
| 3632 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3633 | px->be_counters.retries, px->be_counters.redispatches, |
| 3634 | human_time(now.tv_sec - px->last_change, 1), |
| 3635 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3636 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3637 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3638 | px->srv_act, px->srv_bck); |
| 3639 | |
| 3640 | chunk_appendf(&trash, |
| 3641 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3642 | "<td class=ac> </td><td>%d</td>" |
| 3643 | "<td>%s</td>" |
| 3644 | "<td></td>" |
| 3645 | "</tr>", |
| 3646 | px->down_trans, |
| 3647 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3648 | } |
| 3649 | else { /* CSV mode */ |
| 3650 | chunk_appendf(&trash, |
| 3651 | /* pxid, name */ |
| 3652 | "%s,BACKEND," |
| 3653 | /* queue : current, max */ |
| 3654 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3655 | /* sessions : current, max, limit, total */ |
| 3656 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3657 | /* bytes : in, out */ |
| 3658 | "%lld,%lld," |
| 3659 | /* denied: req, resp */ |
| 3660 | "%lld,%lld," |
| 3661 | /* errors : request, connect, response */ |
| 3662 | ",%lld,%lld," |
| 3663 | /* warnings: retries, redispatches */ |
| 3664 | "%lld,%lld," |
| 3665 | /* backend status: reflect backend status (up/down): we display UP |
| 3666 | * if the backend has known working servers or if it has no server at |
| 3667 | * all (eg: for stats). Then we display the total weight, number of |
| 3668 | * active and backups. */ |
| 3669 | "%s," |
| 3670 | "%d,%d,%d," |
| 3671 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3672 | ",%d,%d,%d,," |
| 3673 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3674 | "%d,%d,0,,%lld,,%d," |
| 3675 | /* rate, rate_lim, rate_max, */ |
| 3676 | "%u,,%u," |
| 3677 | /* check_status, check_code, check_duration */ |
| 3678 | ",,,", |
| 3679 | px->id, |
| 3680 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3681 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3682 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3683 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3684 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3685 | px->be_counters.retries, px->be_counters.redispatches, |
| 3686 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3687 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3688 | px->srv_act, px->srv_bck, |
| 3689 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3690 | px->srv?be_downtime(px):0, |
| 3691 | relative_pid, px->uuid, |
| 3692 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3693 | read_freq_ctr(&px->be_sess_per_sec), |
| 3694 | px->be_counters.sps_max); |
| 3695 | |
| 3696 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3697 | if (px->mode == PR_MODE_HTTP) { |
| 3698 | for (i=1; i<6; i++) |
| 3699 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3700 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3701 | } |
| 3702 | else |
| 3703 | chunk_appendf(&trash, ",,,,,,"); |
| 3704 | |
| 3705 | /* failed health analyses */ |
| 3706 | chunk_appendf(&trash, ","); |
| 3707 | |
| 3708 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3709 | chunk_appendf(&trash, ",,,"); |
| 3710 | |
| 3711 | /* errors: cli_aborts, srv_aborts */ |
| 3712 | chunk_appendf(&trash, "%lld,%lld,", |
| 3713 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3714 | |
| 3715 | /* compression: in, out, bypassed */ |
| 3716 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3717 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3718 | |
| 3719 | /* compression: comp_rsp */ |
| 3720 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3721 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3722 | /* lastsess, last_chk, last_agt, */ |
| 3723 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3724 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3725 | /* qtime, ctime, rtime, ttime, */ |
| 3726 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3727 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 3728 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 3729 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 3730 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 3731 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3732 | /* finish with EOL */ |
| 3733 | chunk_appendf(&trash, "\n"); |
| 3734 | } |
| 3735 | return 1; |
| 3736 | } |
| 3737 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3738 | /* 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] | 3739 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3740 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3741 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3742 | 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] | 3743 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3744 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3745 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3746 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3747 | 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] | 3748 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3749 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3750 | /* 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] | 3751 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3752 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3753 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3754 | 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] | 3755 | 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] | 3756 | } |
| 3757 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3758 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 3759 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | /* print a new table */ |
| 3763 | chunk_appendf(&trash, |
| 3764 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3765 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3766 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3767 | |
| 3768 | chunk_appendf(&trash, |
| 3769 | "<a name=\"%s\"></a>%s" |
| 3770 | "<a class=px href=\"#%s\">%s</a>", |
| 3771 | px->id, |
| 3772 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3773 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3774 | |
| 3775 | if (uri->flags & ST_SHLGNDS) { |
| 3776 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3777 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3778 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3779 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3780 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3784 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3785 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3786 | "</tr>\n" |
| 3787 | "</table>\n" |
| 3788 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3789 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3790 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3791 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3792 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3793 | 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] | 3794 | /* Column heading for Enable or Disable server */ |
| 3795 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3796 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3797 | |
| 3798 | chunk_appendf(&trash, |
| 3799 | "<th rowspan=2></th>" |
| 3800 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3801 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3802 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3803 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3804 | "<th colspan=9>Server</th>" |
| 3805 | "</tr>\n" |
| 3806 | "<tr class=\"titre\">" |
| 3807 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3808 | "<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] | 3809 | "<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] | 3810 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3811 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3812 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3813 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3814 | "<th>Thrtle</th>\n" |
| 3815 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3816 | } |
| 3817 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3818 | /* 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] | 3819 | * 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] | 3820 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3821 | 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] | 3822 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3823 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3824 | chunk_appendf(&trash, "</table>"); |
| 3825 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3826 | 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] | 3827 | /* close the form used to enable/disable this proxy servers */ |
| 3828 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3829 | "Choose the action to perform on the checked servers : " |
| 3830 | "<select name=action>" |
| 3831 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 3832 | "<option value=\"ready\">Set state to READY</option>" |
| 3833 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 3834 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 3835 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3836 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3837 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3838 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3839 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3840 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3841 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3842 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3843 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3844 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3845 | "</select>" |
| 3846 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3847 | " <input type=\"submit\" value=\"Apply\">" |
| 3848 | "</form>", |
| 3849 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3853 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3854 | |
| 3855 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3856 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3857 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3858 | * buffer space, or non-zero if everything completed. This function is used |
| 3859 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3860 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3861 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3862 | 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] | 3863 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3864 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3865 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 3866 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3867 | 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] | 3868 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3869 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3870 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3871 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3872 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3873 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3874 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3875 | if (uri && uri->scope) { |
| 3876 | /* we have a limited scope, we have to check the proxy name */ |
| 3877 | struct stat_scope *scope; |
| 3878 | int len; |
| 3879 | |
| 3880 | len = strlen(px->id); |
| 3881 | scope = uri->scope; |
| 3882 | |
| 3883 | while (scope) { |
| 3884 | /* match exact proxy name */ |
| 3885 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3886 | break; |
| 3887 | |
| 3888 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3889 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3890 | break; |
| 3891 | scope = scope->next; |
| 3892 | } |
| 3893 | |
| 3894 | /* proxy name not found : don't dump anything */ |
| 3895 | if (scope == NULL) |
| 3896 | return 1; |
| 3897 | } |
| 3898 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3899 | /* if the user has requested a limited output and the proxy |
| 3900 | * name does not match, skip it. |
| 3901 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3902 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3903 | 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] | 3904 | return 1; |
| 3905 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3906 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3907 | (appctx->ctx.stats.iid != -1) && |
| 3908 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3909 | return 1; |
| 3910 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3911 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3912 | /* fall through */ |
| 3913 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3914 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3915 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3916 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3917 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3918 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3919 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3920 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3921 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3922 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3923 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3924 | /* fall through */ |
| 3925 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3926 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3927 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3928 | if (stats_dump_fe_stats(si, px)) { |
| 3929 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3930 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3931 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3932 | } |
| 3933 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3934 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3935 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3936 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3937 | /* fall through */ |
| 3938 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3939 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3940 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3941 | 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] | 3942 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3943 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3944 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3945 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3946 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3947 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3948 | if (!l->counters) |
| 3949 | continue; |
| 3950 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3951 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3952 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3953 | break; |
| 3954 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3955 | 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] | 3956 | continue; |
| 3957 | } |
| 3958 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3959 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3960 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) { |
| 3961 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3962 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3963 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3964 | } |
| 3965 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3966 | } |
| 3967 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3968 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3969 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3970 | /* fall through */ |
| 3971 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3972 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3973 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3974 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3975 | enum srv_stats_state sv_state; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3976 | enum srv_stats_colour sv_colour; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3977 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3978 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3979 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3980 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3981 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3982 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3983 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3984 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3985 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3986 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3987 | break; |
| 3988 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3989 | 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] | 3990 | continue; |
| 3991 | } |
| 3992 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3993 | svs = sv; |
| 3994 | while (svs->track) |
| 3995 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3996 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3997 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3998 | if ((svs->check.state & CHK_ST_ENABLED) && |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3999 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4000 | sv_state = SRV_STATS_STATE_UP_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4001 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4002 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4003 | sv_state = SRV_STATS_STATE_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4004 | sv_colour = SRV_STATS_COLOUR_UP; |
| 4005 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4006 | |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4007 | if (sv_state == SRV_STATS_STATE_UP && !svs->uweight) |
| 4008 | sv_colour = SRV_STATS_COLOUR_DRAINING; |
| 4009 | |
| 4010 | if (sv->admin & SRV_ADMF_DRAIN) { |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4011 | if (svs->agent.state & CHK_ST_ENABLED) |
| 4012 | sv_state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4013 | else if (sv_state == SRV_STATS_STATE_UP_GOING_DOWN) |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4014 | sv_state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4015 | else |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4016 | sv_state = SRV_STATS_STATE_DRAIN; |
| 4017 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4018 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4019 | 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] | 4020 | sv_state = SRV_STATS_STATE_NO_CHECK; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4021 | sv_colour = SRV_STATS_COLOUR_NO_CHECK; |
| 4022 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4023 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4024 | else if (sv->state == SRV_ST_STOPPING) { |
| 4025 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4026 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4027 | sv_state = SRV_STATS_STATE_NOLB; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4028 | sv_colour = SRV_STATS_COLOUR_NOLB; |
| 4029 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4030 | sv_state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4031 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4032 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4033 | } |
| 4034 | else { /* stopped */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4035 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4036 | sv_state = SRV_STATS_STATE_DOWN_AGENT; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4037 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4038 | } else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4039 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4040 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4041 | } 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] | 4042 | sv_state = SRV_STATS_STATE_GOING_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4043 | sv_colour = SRV_STATS_COLOUR_GOING_UP; |
| 4044 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4045 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4046 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4047 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4048 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4049 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4050 | 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] | 4051 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4052 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4053 | continue; |
| 4054 | } |
| 4055 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4056 | 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] | 4057 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4058 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4059 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4060 | } |
| 4061 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4062 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4063 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4064 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4065 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4066 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4067 | case STAT_PX_ST_BE: |
| 4068 | /* print the backend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4069 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) { |
| 4070 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4071 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4072 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4073 | } |
| 4074 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4075 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4076 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4077 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4078 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4079 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4080 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4081 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4082 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4083 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4084 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4085 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4086 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4087 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4088 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4089 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4090 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4091 | case STAT_PX_ST_FIN: |
| 4092 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4093 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4094 | default: |
| 4095 | /* unknown state, we should put an abort() here ! */ |
| 4096 | return 1; |
| 4097 | } |
| 4098 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4099 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4100 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4101 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4102 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4103 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4104 | { |
| 4105 | /* WARNING! This must fit in the first buffer !!! */ |
| 4106 | chunk_appendf(&trash, |
| 4107 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4108 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4109 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4110 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4111 | "<style type=\"text/css\"><!--\n" |
| 4112 | "body {" |
| 4113 | " font-family: arial, helvetica, sans-serif;" |
| 4114 | " font-size: 12px;" |
| 4115 | " font-weight: normal;" |
| 4116 | " color: black;" |
| 4117 | " background: white;" |
| 4118 | "}\n" |
| 4119 | "th,td {" |
| 4120 | " font-size: 10px;" |
| 4121 | "}\n" |
| 4122 | "h1 {" |
| 4123 | " font-size: x-large;" |
| 4124 | " margin-bottom: 0.5em;" |
| 4125 | "}\n" |
| 4126 | "h2 {" |
| 4127 | " font-family: helvetica, arial;" |
| 4128 | " font-size: x-large;" |
| 4129 | " font-weight: bold;" |
| 4130 | " font-style: italic;" |
| 4131 | " color: #6020a0;" |
| 4132 | " margin-top: 0em;" |
| 4133 | " margin-bottom: 0em;" |
| 4134 | "}\n" |
| 4135 | "h3 {" |
| 4136 | " font-family: helvetica, arial;" |
| 4137 | " font-size: 16px;" |
| 4138 | " font-weight: bold;" |
| 4139 | " color: #b00040;" |
| 4140 | " background: #e8e8d0;" |
| 4141 | " margin-top: 0em;" |
| 4142 | " margin-bottom: 0em;" |
| 4143 | "}\n" |
| 4144 | "li {" |
| 4145 | " margin-top: 0.25em;" |
| 4146 | " margin-right: 2em;" |
| 4147 | "}\n" |
| 4148 | ".hr {margin-top: 0.25em;" |
| 4149 | " border-color: black;" |
| 4150 | " border-bottom-style: solid;" |
| 4151 | "}\n" |
| 4152 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4153 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4154 | ".frontend {background: #e8e8d0;}\n" |
| 4155 | ".socket {background: #d0d0d0;}\n" |
| 4156 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4157 | ".active_down {background: #ff9090;}\n" |
| 4158 | ".active_going_up {background: #ffd020;}\n" |
| 4159 | ".active_going_down {background: #ffffa0;}\n" |
| 4160 | ".active_up {background: #c0ffc0;}\n" |
| 4161 | ".active_nolb {background: #20a0ff;}\n" |
| 4162 | ".active_draining {background: #20a0FF;}\n" |
| 4163 | ".active_no_check {background: #e0e0e0;}\n" |
| 4164 | ".backup_down {background: #ff9090;}\n" |
| 4165 | ".backup_going_up {background: #ff80ff;}\n" |
| 4166 | ".backup_going_down {background: #c060ff;}\n" |
| 4167 | ".backup_up {background: #b0d0ff;}\n" |
| 4168 | ".backup_nolb {background: #90b0e0;}\n" |
| 4169 | ".backup_draining {background: #cc9900;}\n" |
| 4170 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4171 | ".maintain {background: #c07820;}\n" |
| 4172 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4173 | "\n" |
| 4174 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4175 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4176 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4177 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4178 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4179 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4180 | "\n" |
| 4181 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4182 | "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" |
| 4183 | "table.tbl td.ac { text-align: center;}\n" |
| 4184 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4185 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4186 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4187 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4188 | "\n" |
| 4189 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4190 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4191 | "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] | 4192 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4193 | "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] | 4194 | "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] | 4195 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4196 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4197 | " display:block;\n" |
| 4198 | " visibility:hidden;\n" |
| 4199 | " z-index:2147483647;\n" |
| 4200 | " position:absolute;\n" |
| 4201 | " padding:2px 4px 3px;\n" |
| 4202 | " background:#f0f060; color:#000000;\n" |
| 4203 | " border:1px solid #7040c0;\n" |
| 4204 | " white-space:nowrap;\n" |
| 4205 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4206 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4207 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4208 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4209 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4210 | "-->\n" |
| 4211 | "</style></head>\n", |
| 4212 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4213 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4214 | ); |
| 4215 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4216 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4217 | /* 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] | 4218 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4219 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4220 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4221 | 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] | 4222 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4223 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4224 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4225 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4226 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4227 | /* WARNING! this has to fit the first packet too. |
| 4228 | * We are around 3.5 kB, add adding entries will |
| 4229 | * become tricky if we want to support 4kB buffers ! |
| 4230 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4231 | chunk_appendf(&trash, |
| 4232 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4233 | PRODUCT_NAME "%s</a></h1>\n" |
| 4234 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4235 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4236 | "<h3>> General process information</h3>\n" |
| 4237 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4238 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4239 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4240 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4241 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4242 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4243 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4244 | "</td><td align=\"center\" nowrap>\n" |
| 4245 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4246 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4247 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4248 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4249 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4250 | "<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] | 4251 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4252 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4253 | "<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] | 4254 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4255 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4256 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4257 | "</tr><tr>\n" |
| 4258 | "<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] | 4259 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4260 | "<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] | 4261 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4262 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4263 | "</td>" |
| 4264 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4265 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4266 | "", |
| 4267 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4268 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4269 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4270 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4271 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4272 | pid, relative_pid, global.nbproc, |
| 4273 | up / 86400, (up % 86400) / 3600, |
| 4274 | (up % 3600) / 60, (up % 60), |
| 4275 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4276 | global.rlimit_memmax ? " MB" : "", |
| 4277 | global.rlimit_nofile, |
| 4278 | global.maxsock, global.maxconn, global.maxpipes, |
| 4279 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4280 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4281 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4282 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4283 | /* 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] | 4284 | 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] | 4285 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4286 | |
| 4287 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4288 | "<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] | 4289 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4290 | STAT_SCOPE_TXT_MAXLEN); |
| 4291 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4292 | /* 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] | 4293 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4294 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4295 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4296 | 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] | 4297 | 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] | 4298 | } |
| 4299 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4300 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4301 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4302 | "<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] | 4303 | uri->uri_prefix, |
| 4304 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4305 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4306 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4307 | else |
| 4308 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4309 | "<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] | 4310 | uri->uri_prefix, |
| 4311 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4312 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4313 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4314 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4315 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4316 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4317 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4318 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4319 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4320 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4321 | "", |
| 4322 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4323 | else |
| 4324 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4325 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4326 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4327 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4328 | ";norefresh", |
| 4329 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4330 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4331 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4332 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4333 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4334 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4335 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4336 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4337 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4338 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4339 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4340 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4341 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4342 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4343 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4344 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4345 | chunk_appendf(&trash, |
| 4346 | "</ul></td>" |
| 4347 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4348 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4349 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4350 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4351 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4352 | "</ul>" |
| 4353 | "</td>" |
| 4354 | "</tr></table>\n" |
| 4355 | "" |
| 4356 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4357 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4358 | if (appctx->ctx.stats.st_code) { |
| 4359 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4360 | case STAT_STATUS_DONE: |
| 4361 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4362 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4363 | "<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] | 4364 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4365 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4366 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4367 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4368 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4369 | break; |
| 4370 | case STAT_STATUS_NONE: |
| 4371 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4372 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4373 | "<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] | 4374 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4375 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4376 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4377 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4378 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4379 | break; |
| 4380 | case STAT_STATUS_PART: |
| 4381 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4382 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4383 | "<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] | 4384 | "Action partially processed.<br>" |
| 4385 | "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] | 4386 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4387 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4388 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4389 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4390 | break; |
| 4391 | case STAT_STATUS_ERRP: |
| 4392 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4393 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4394 | "<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] | 4395 | "Action not processed because of invalid parameters." |
| 4396 | "<ul>" |
| 4397 | "<li>The action is maybe unknown.</li>" |
| 4398 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4399 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4400 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4401 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4402 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4403 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4404 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4405 | break; |
| 4406 | case STAT_STATUS_EXCD: |
| 4407 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4408 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4409 | "<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] | 4410 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4411 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4412 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4413 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4414 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4415 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4416 | break; |
| 4417 | case STAT_STATUS_DENY: |
| 4418 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4419 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4420 | "<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] | 4421 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4422 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4423 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4424 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4425 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4426 | break; |
| 4427 | default: |
| 4428 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4429 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4430 | "<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] | 4431 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4432 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4433 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4434 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4435 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4436 | } |
| 4437 | chunk_appendf(&trash, "<p>\n"); |
| 4438 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4439 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4440 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4441 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4442 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4443 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4444 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4445 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4446 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4447 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4448 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4449 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4450 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4451 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4452 | * 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] | 4453 | * 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] | 4454 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4455 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4456 | 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] | 4457 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4458 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4459 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4460 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4461 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4462 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4463 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4464 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4465 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4466 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4467 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4468 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4469 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4470 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4471 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4472 | else |
| 4473 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4474 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4475 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4476 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4477 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4478 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4479 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4480 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4481 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4482 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4483 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4484 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4485 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4486 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4487 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4488 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4489 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4490 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4491 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4492 | appctx->ctx.stats.px = proxy; |
| 4493 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4494 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4495 | /* fall through */ |
| 4496 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4497 | case STAT_ST_LIST: |
| 4498 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4499 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4500 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4501 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4502 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4503 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4504 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4505 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4506 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4507 | 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] | 4508 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4509 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4510 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4511 | appctx->ctx.stats.px = px->next; |
| 4512 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4513 | } |
| 4514 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4515 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4516 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4517 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4518 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4519 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4520 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4521 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4522 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4523 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4524 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4525 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4526 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4527 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4528 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4529 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4530 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4531 | case STAT_ST_FIN: |
| 4532 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4533 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4534 | default: |
| 4535 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4536 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4537 | return -1; |
| 4538 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4539 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4540 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4541 | /* We reached the stats page through a POST request. The appctx is |
| 4542 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4543 | * Parse the posted data and enable/disable servers if necessary. |
| 4544 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4545 | */ |
| 4546 | static int stats_process_http_post(struct stream_interface *si) |
| 4547 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4548 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4549 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4550 | |
| 4551 | struct proxy *px = NULL; |
| 4552 | struct server *sv = NULL; |
| 4553 | |
| 4554 | char key[LINESIZE]; |
| 4555 | int action = ST_ADM_ACTION_NONE; |
| 4556 | int reprocess = 0; |
| 4557 | |
| 4558 | int total_servers = 0; |
| 4559 | int altered_servers = 0; |
| 4560 | |
| 4561 | char *first_param, *cur_param, *next_param, *end_params; |
| 4562 | char *st_cur_param = NULL; |
| 4563 | char *st_next_param = NULL; |
| 4564 | |
| 4565 | struct chunk *temp; |
| 4566 | int reql; |
| 4567 | |
| 4568 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4569 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4570 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4571 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4572 | goto out; |
| 4573 | } |
| 4574 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4575 | 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] | 4576 | if (reql <= 0) { |
| 4577 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4578 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4579 | return 0; |
| 4580 | } |
| 4581 | |
| 4582 | first_param = temp->str; |
| 4583 | end_params = temp->str + reql; |
| 4584 | cur_param = next_param = end_params; |
| 4585 | *end_params = '\0'; |
| 4586 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4587 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4588 | |
| 4589 | /* |
| 4590 | * Parse the parameters in reverse order to only store the last value. |
| 4591 | * From the html form, the backend and the action are at the end. |
| 4592 | */ |
| 4593 | while (cur_param > first_param) { |
| 4594 | char *value; |
| 4595 | int poffset, plen; |
| 4596 | |
| 4597 | cur_param--; |
| 4598 | |
| 4599 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4600 | reprocess_servers: |
| 4601 | /* Parse the key */ |
| 4602 | poffset = (cur_param != first_param ? 1 : 0); |
| 4603 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4604 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4605 | strncpy(key, cur_param + poffset, plen); |
| 4606 | key[plen - 1] = '\0'; |
| 4607 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4608 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4609 | goto out; |
| 4610 | } |
| 4611 | |
| 4612 | /* Parse the value */ |
| 4613 | value = key; |
| 4614 | while (*value != '\0' && *value != '=') { |
| 4615 | value++; |
| 4616 | } |
| 4617 | if (*value == '=') { |
| 4618 | /* Ok, a value is found, we can mark the end of the key */ |
| 4619 | *value++ = '\0'; |
| 4620 | } |
| 4621 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4622 | break; |
| 4623 | |
| 4624 | /* Now we can check the key to see what to do */ |
| 4625 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 4626 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4627 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4628 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4629 | goto out; |
| 4630 | } |
| 4631 | } |
| 4632 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4633 | if (strcmp(value, "ready") == 0) { |
| 4634 | action = ST_ADM_ACTION_READY; |
| 4635 | } |
| 4636 | else if (strcmp(value, "drain") == 0) { |
| 4637 | action = ST_ADM_ACTION_DRAIN; |
| 4638 | } |
| 4639 | else if (strcmp(value, "maint") == 0) { |
| 4640 | action = ST_ADM_ACTION_MAINT; |
| 4641 | } |
| 4642 | else if (strcmp(value, "shutdown") == 0) { |
| 4643 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4644 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4645 | else if (strcmp(value, "dhlth") == 0) { |
| 4646 | action = ST_ADM_ACTION_DHLTH; |
| 4647 | } |
| 4648 | else if (strcmp(value, "ehlth") == 0) { |
| 4649 | action = ST_ADM_ACTION_EHLTH; |
| 4650 | } |
| 4651 | else if (strcmp(value, "hrunn") == 0) { |
| 4652 | action = ST_ADM_ACTION_HRUNN; |
| 4653 | } |
| 4654 | else if (strcmp(value, "hnolb") == 0) { |
| 4655 | action = ST_ADM_ACTION_HNOLB; |
| 4656 | } |
| 4657 | else if (strcmp(value, "hdown") == 0) { |
| 4658 | action = ST_ADM_ACTION_HDOWN; |
| 4659 | } |
| 4660 | else if (strcmp(value, "dagent") == 0) { |
| 4661 | action = ST_ADM_ACTION_DAGENT; |
| 4662 | } |
| 4663 | else if (strcmp(value, "eagent") == 0) { |
| 4664 | action = ST_ADM_ACTION_EAGENT; |
| 4665 | } |
| 4666 | else if (strcmp(value, "arunn") == 0) { |
| 4667 | action = ST_ADM_ACTION_ARUNN; |
| 4668 | } |
| 4669 | else if (strcmp(value, "adown") == 0) { |
| 4670 | action = ST_ADM_ACTION_ADOWN; |
| 4671 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4672 | /* else these are the old supported methods */ |
| 4673 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4674 | action = ST_ADM_ACTION_DISABLE; |
| 4675 | } |
| 4676 | else if (strcmp(value, "enable") == 0) { |
| 4677 | action = ST_ADM_ACTION_ENABLE; |
| 4678 | } |
| 4679 | else if (strcmp(value, "stop") == 0) { |
| 4680 | action = ST_ADM_ACTION_STOP; |
| 4681 | } |
| 4682 | else if (strcmp(value, "start") == 0) { |
| 4683 | action = ST_ADM_ACTION_START; |
| 4684 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4685 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4686 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4687 | goto out; |
| 4688 | } |
| 4689 | } |
| 4690 | else if (strcmp(key, "s") == 0) { |
| 4691 | if (!(px && action)) { |
| 4692 | /* |
| 4693 | * Indicates that we'll need to reprocess the parameters |
| 4694 | * as soon as backend and action are known |
| 4695 | */ |
| 4696 | if (!reprocess) { |
| 4697 | st_cur_param = cur_param; |
| 4698 | st_next_param = next_param; |
| 4699 | } |
| 4700 | reprocess = 1; |
| 4701 | } |
| 4702 | else if ((sv = findserver(px, value)) != NULL) { |
| 4703 | switch (action) { |
| 4704 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4705 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4706 | altered_servers++; |
| 4707 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4708 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4709 | } |
| 4710 | break; |
| 4711 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4712 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4713 | altered_servers++; |
| 4714 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4715 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4716 | } |
| 4717 | break; |
| 4718 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4719 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 4720 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4721 | altered_servers++; |
| 4722 | total_servers++; |
| 4723 | } |
| 4724 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4725 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4726 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 4727 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4728 | altered_servers++; |
| 4729 | total_servers++; |
| 4730 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4731 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4732 | case ST_ADM_ACTION_DHLTH: |
| 4733 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4734 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4735 | altered_servers++; |
| 4736 | total_servers++; |
| 4737 | } |
| 4738 | break; |
| 4739 | case ST_ADM_ACTION_EHLTH: |
| 4740 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4741 | sv->check.state |= CHK_ST_ENABLED; |
| 4742 | altered_servers++; |
| 4743 | total_servers++; |
| 4744 | } |
| 4745 | break; |
| 4746 | case ST_ADM_ACTION_HRUNN: |
| 4747 | if (!(sv->track)) { |
| 4748 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4749 | srv_set_running(sv, "changed from Web interface"); |
| 4750 | altered_servers++; |
| 4751 | total_servers++; |
| 4752 | } |
| 4753 | break; |
| 4754 | case ST_ADM_ACTION_HNOLB: |
| 4755 | if (!(sv->track)) { |
| 4756 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4757 | srv_set_stopping(sv, "changed from Web interface"); |
| 4758 | altered_servers++; |
| 4759 | total_servers++; |
| 4760 | } |
| 4761 | break; |
| 4762 | case ST_ADM_ACTION_HDOWN: |
| 4763 | if (!(sv->track)) { |
| 4764 | sv->check.health = 0; |
| 4765 | srv_set_stopped(sv, "changed from Web interface"); |
| 4766 | altered_servers++; |
| 4767 | total_servers++; |
| 4768 | } |
| 4769 | break; |
| 4770 | case ST_ADM_ACTION_DAGENT: |
| 4771 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4772 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4773 | altered_servers++; |
| 4774 | total_servers++; |
| 4775 | } |
| 4776 | break; |
| 4777 | case ST_ADM_ACTION_EAGENT: |
| 4778 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4779 | sv->agent.state |= CHK_ST_ENABLED; |
| 4780 | altered_servers++; |
| 4781 | total_servers++; |
| 4782 | } |
| 4783 | break; |
| 4784 | case ST_ADM_ACTION_ARUNN: |
| 4785 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4786 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 4787 | srv_set_running(sv, "changed from Web interface"); |
| 4788 | altered_servers++; |
| 4789 | total_servers++; |
| 4790 | } |
| 4791 | break; |
| 4792 | case ST_ADM_ACTION_ADOWN: |
| 4793 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4794 | sv->agent.health = 0; |
| 4795 | srv_set_stopped(sv, "changed from Web interface"); |
| 4796 | altered_servers++; |
| 4797 | total_servers++; |
| 4798 | } |
| 4799 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4800 | case ST_ADM_ACTION_READY: |
| 4801 | srv_adm_set_ready(sv); |
| 4802 | altered_servers++; |
| 4803 | total_servers++; |
| 4804 | break; |
| 4805 | case ST_ADM_ACTION_DRAIN: |
| 4806 | srv_adm_set_drain(sv); |
| 4807 | altered_servers++; |
| 4808 | total_servers++; |
| 4809 | break; |
| 4810 | case ST_ADM_ACTION_MAINT: |
| 4811 | srv_adm_set_maint(sv); |
| 4812 | altered_servers++; |
| 4813 | total_servers++; |
| 4814 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4815 | case ST_ADM_ACTION_SHUTDOWN: |
| 4816 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4817 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4818 | |
| 4819 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4820 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 4821 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4822 | |
| 4823 | altered_servers++; |
| 4824 | total_servers++; |
| 4825 | } |
| 4826 | break; |
| 4827 | } |
| 4828 | } else { |
| 4829 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4830 | total_servers++; |
| 4831 | } |
| 4832 | } |
| 4833 | if (reprocess && px && action) { |
| 4834 | /* Now, we know the backend and the action chosen by the user. |
| 4835 | * We can safely restart from the first server parameter |
| 4836 | * to reprocess them |
| 4837 | */ |
| 4838 | cur_param = st_cur_param; |
| 4839 | next_param = st_next_param; |
| 4840 | reprocess = 0; |
| 4841 | goto reprocess_servers; |
| 4842 | } |
| 4843 | |
| 4844 | next_param = cur_param; |
| 4845 | } |
| 4846 | } |
| 4847 | |
| 4848 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4849 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4850 | } |
| 4851 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4852 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4853 | } |
| 4854 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4855 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4856 | } |
| 4857 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4858 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4859 | } |
| 4860 | out: |
| 4861 | return 1; |
| 4862 | } |
| 4863 | |
| 4864 | |
| 4865 | static int stats_send_http_headers(struct stream_interface *si) |
| 4866 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4867 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4868 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4869 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4870 | |
| 4871 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4872 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4873 | "Cache-Control: no-cache\r\n" |
| 4874 | "Connection: close\r\n" |
| 4875 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4876 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4877 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4878 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4879 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4880 | uri->refresh); |
| 4881 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4882 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4883 | |
| 4884 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4885 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4886 | else |
| 4887 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4888 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4889 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4890 | s->logs.tv_request = now; |
| 4891 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4892 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4893 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4894 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4895 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4896 | |
| 4897 | return 1; |
| 4898 | } |
| 4899 | |
| 4900 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4901 | { |
| 4902 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4903 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4904 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4905 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4906 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4907 | /* 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] | 4908 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4909 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4910 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4911 | 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] | 4912 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | /* We don't want to land on the posted stats page because a refresh will |
| 4916 | * repost the data. We don't want this to happen on accident so we redirect |
| 4917 | * the browse to the stats page with a GET. |
| 4918 | */ |
| 4919 | chunk_printf(&trash, |
| 4920 | "HTTP/1.1 303 See Other\r\n" |
| 4921 | "Cache-Control: no-cache\r\n" |
| 4922 | "Content-Type: text/plain\r\n" |
| 4923 | "Connection: close\r\n" |
| 4924 | "Location: %s;st=%s%s%s%s\r\n" |
| 4925 | "\r\n", |
| 4926 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4927 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4928 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4929 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4930 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4931 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4932 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4933 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4934 | scope_txt); |
| 4935 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4936 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4937 | s->logs.tv_request = now; |
| 4938 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4939 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4940 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4941 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4942 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4943 | |
| 4944 | return 1; |
| 4945 | } |
| 4946 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4947 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4948 | * 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] | 4949 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4950 | * automatically unregisters itself once transfer is complete. |
| 4951 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 4952 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4953 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 4954 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4955 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4956 | struct channel *req = si_oc(si); |
| 4957 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4958 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4959 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4960 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4961 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4962 | /* check that the output is not closed */ |
| 4963 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4964 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4965 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4966 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4967 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4968 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4969 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4970 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4971 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4972 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4973 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4974 | } |
| 4975 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4976 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4977 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4978 | unsigned int data_len; |
| 4979 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 4980 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4981 | |
| 4982 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4983 | /* One difficulty we're facing is that we must prevent |
| 4984 | * the input data from being automatically forwarded to |
| 4985 | * the output area. For this, we temporarily disable |
| 4986 | * forwarding on the channel. |
| 4987 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4988 | last_fwd = si_ic(si)->to_forward; |
| 4989 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4990 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4991 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4992 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4993 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 4994 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4995 | } |
| 4996 | } |
| 4997 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4998 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4999 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5000 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5001 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5002 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5003 | |
| 5004 | /* Now we must either adjust or remove the chunk size. This is |
| 5005 | * not easy because the chunk size might wrap at the end of the |
| 5006 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5007 | * the size, then restore the buffer's contents. Note that we can |
| 5008 | * only do that because no forwarding is scheduled on the stats |
| 5009 | * applet. |
| 5010 | */ |
| 5011 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5012 | si_ic(si)->total -= (last_len - prev_len); |
| 5013 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5014 | |
| 5015 | if (last_len != data_len) { |
| 5016 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5017 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5018 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5019 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5020 | si_ic(si)->total += (last_len - data_len); |
| 5021 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5022 | } |
| 5023 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5024 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5025 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5026 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5027 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5028 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5029 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5030 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5031 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5032 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5033 | } |
| 5034 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5035 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5036 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5037 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5038 | } |
| 5039 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5040 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5041 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5042 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5043 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5044 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5045 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5046 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5047 | } |
| 5048 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5049 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5050 | res->flags |= CF_READ_NULL; |
| 5051 | si_shutr(si); |
| 5052 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5053 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5054 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5055 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5056 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5057 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5058 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5059 | si_shutr(si); |
| 5060 | res->flags |= CF_READ_NULL; |
| 5061 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5062 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5063 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5064 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5065 | } |
| 5066 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5067 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5068 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5069 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5070 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5071 | return "NONE"; |
| 5072 | return conn->ctrl->name; |
| 5073 | } |
| 5074 | |
| 5075 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5076 | { |
| 5077 | static char ptr[17]; |
| 5078 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5079 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5080 | return "NONE"; |
| 5081 | |
| 5082 | if (conn->xprt == &raw_sock) |
| 5083 | return "RAW"; |
| 5084 | |
| 5085 | #ifdef USE_OPENSSL |
| 5086 | if (conn->xprt == &ssl_sock) |
| 5087 | return "SSL"; |
| 5088 | #endif |
| 5089 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5090 | return ptr; |
| 5091 | } |
| 5092 | |
| 5093 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5094 | { |
| 5095 | static char ptr[17]; |
| 5096 | |
| 5097 | if (!conn->data) |
| 5098 | return "NONE"; |
| 5099 | |
| 5100 | if (conn->data == &sess_conn_cb) |
| 5101 | return "SESS"; |
| 5102 | |
| 5103 | if (conn->data == &si_conn_cb) |
| 5104 | return "STRM"; |
| 5105 | |
| 5106 | if (conn->data == &check_conn_cb) |
| 5107 | return "CHCK"; |
| 5108 | |
| 5109 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5110 | return ptr; |
| 5111 | } |
| 5112 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5113 | /* This function dumps a complete stream state onto the stream interface's |
| 5114 | * 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] | 5115 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5116 | * 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] | 5117 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5118 | 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] | 5119 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5120 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5121 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5122 | extern const char *monthname[12]; |
| 5123 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5124 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5125 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5126 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5127 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5128 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5129 | 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] | 5130 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5131 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5132 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5133 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5134 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5135 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5136 | appctx->ctx.sess.uid = 0; |
| 5137 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5138 | return 1; |
| 5139 | } |
| 5140 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5141 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5142 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5143 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5144 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5145 | /* fall through */ |
| 5146 | |
| 5147 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5148 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5149 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5150 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5151 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5152 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5153 | 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] | 5154 | sess->uniq_id, |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5155 | 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] | 5156 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5157 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5158 | 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] | 5159 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5160 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5161 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5162 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5163 | break; |
| 5164 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5165 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5166 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5167 | default: |
| 5168 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5169 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5170 | break; |
| 5171 | } |
| 5172 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5173 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5174 | " 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] | 5175 | 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] | 5176 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5177 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5178 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5179 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5180 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5181 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5182 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5183 | if (conn) |
| 5184 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5185 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5186 | 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] | 5187 | case AF_INET: |
| 5188 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5189 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5190 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5191 | break; |
| 5192 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5193 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5194 | break; |
| 5195 | default: |
| 5196 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5197 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5198 | break; |
| 5199 | } |
| 5200 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5201 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5202 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5203 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5204 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5205 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5206 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5207 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5208 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5209 | conn = objt_conn(sess->si[1].end); |
| 5210 | if (conn) |
| 5211 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5212 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5213 | 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] | 5214 | case AF_INET: |
| 5215 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5216 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5217 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5218 | break; |
| 5219 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5220 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5221 | break; |
| 5222 | default: |
| 5223 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5224 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5225 | break; |
| 5226 | } |
| 5227 | |
| 5228 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5229 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5230 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5231 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5232 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5233 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5234 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5235 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5236 | if (conn) |
| 5237 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5238 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5239 | 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] | 5240 | case AF_INET: |
| 5241 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5242 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5243 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5244 | break; |
| 5245 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5246 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5247 | break; |
| 5248 | default: |
| 5249 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5250 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5251 | break; |
| 5252 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5253 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5254 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5255 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5256 | sess->task, |
| 5257 | sess->task->state, |
| 5258 | sess->task->nice, sess->task->calls, |
| 5259 | sess->task->expire ? |
| 5260 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5261 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5262 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5263 | task_in_rq(sess->task) ? ", running" : ""); |
| 5264 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5265 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5266 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5267 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5268 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5269 | if (sess->txn) |
| 5270 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5271 | " 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] | 5272 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5273 | 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] | 5274 | |
| 5275 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5276 | " 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] | 5277 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5278 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5279 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5280 | obj_type_name(sess->si[0].end), |
| 5281 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5282 | sess->si[0].exp ? |
| 5283 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5284 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5285 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5286 | sess->si[0].err_type); |
| 5287 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5288 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5289 | " 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] | 5290 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5291 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5292 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5293 | obj_type_name(sess->si[1].end), |
| 5294 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5295 | sess->si[1].exp ? |
| 5296 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5297 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5298 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5299 | sess->si[1].err_type); |
| 5300 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5301 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5302 | chunk_appendf(&trash, |
| 5303 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5304 | conn, |
| 5305 | get_conn_ctrl_name(conn), |
| 5306 | get_conn_xprt_name(conn), |
| 5307 | get_conn_data_name(conn), |
| 5308 | obj_type_name(conn->target), |
| 5309 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5310 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5311 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5312 | " 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] | 5313 | conn->flags, |
| 5314 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5315 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5316 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5317 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5318 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5319 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5320 | chunk_appendf(&trash, |
| 5321 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5322 | tmpctx, |
| 5323 | tmpctx->st0, |
| 5324 | tmpctx->st1, |
| 5325 | tmpctx->st2, |
| 5326 | tmpctx->applet->name); |
| 5327 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5328 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5329 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5330 | chunk_appendf(&trash, |
| 5331 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5332 | conn, |
| 5333 | get_conn_ctrl_name(conn), |
| 5334 | get_conn_xprt_name(conn), |
| 5335 | get_conn_data_name(conn), |
| 5336 | obj_type_name(conn->target), |
| 5337 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5338 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5339 | chunk_appendf(&trash, |
| 5340 | " 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] | 5341 | conn->flags, |
| 5342 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5343 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5344 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5345 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5346 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5347 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5348 | chunk_appendf(&trash, |
| 5349 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5350 | tmpctx, |
| 5351 | tmpctx->st0, |
| 5352 | tmpctx->st1, |
| 5353 | tmpctx->st2, |
| 5354 | tmpctx->applet->name); |
| 5355 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5356 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5357 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5358 | " 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] | 5359 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5360 | &sess->req, |
| 5361 | sess->req.flags, sess->req.analysers, |
| 5362 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5363 | sess->req.to_forward, sess->req.total, |
| 5364 | sess->req.analyse_exp ? |
| 5365 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5366 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5367 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5368 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5369 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5370 | sess->req.rex ? |
| 5371 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5372 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5373 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5374 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5375 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5376 | " 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] | 5377 | sess->req.wex ? |
| 5378 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5379 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5380 | sess->req.buf, |
| 5381 | sess->req.buf->data, sess->req.buf->o, |
| 5382 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5383 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5384 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5385 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5386 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5387 | " 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] | 5388 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5389 | &sess->res, |
| 5390 | sess->res.flags, sess->res.analysers, |
| 5391 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5392 | sess->res.to_forward, sess->res.total, |
| 5393 | sess->res.analyse_exp ? |
| 5394 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5395 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5396 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5397 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5398 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5399 | sess->res.rex ? |
| 5400 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5401 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5402 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5403 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5404 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5405 | " 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] | 5406 | sess->res.wex ? |
| 5407 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5408 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5409 | sess->res.buf, |
| 5410 | sess->res.buf->data, sess->res.buf->o, |
| 5411 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5412 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5413 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5414 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5415 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5416 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5417 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5418 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5419 | |
| 5420 | /* use other states to dump the contents */ |
| 5421 | } |
| 5422 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5423 | appctx->ctx.sess.uid = 0; |
| 5424 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5425 | return 1; |
| 5426 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5427 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 5428 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 5429 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 5430 | struct appctx *appctx = __objt_appctx(si->end); |
| 5431 | |
| 5432 | switch (appctx->st2) { |
| 5433 | case STAT_ST_INIT: |
| 5434 | /* Display the column headers. If the message cannot be sent, |
| 5435 | * quit the fucntion with returning 0. The function is called |
| 5436 | * later and restart at the state "STAT_ST_INIT". |
| 5437 | */ |
| 5438 | chunk_reset(&trash); |
| 5439 | chunk_appendf(&trash, "# id (file)\n"); |
| 5440 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5441 | si_applet_cant_put(si); |
| 5442 | return 0; |
| 5443 | } |
| 5444 | |
| 5445 | /* Now, we start the browsing of the references lists. |
| 5446 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5447 | * avalaible field of this pointer is <list>. It is used with the function |
| 5448 | * tlskeys_list_get_next() for retruning the first avalaible entry |
| 5449 | */ |
| 5450 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 5451 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 5452 | |
| 5453 | appctx->st2 = STAT_ST_LIST; |
| 5454 | /* fall through */ |
| 5455 | |
| 5456 | case STAT_ST_LIST: |
| 5457 | while (appctx->ctx.tlskeys.ref) { |
| 5458 | chunk_reset(&trash); |
| 5459 | |
| 5460 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 5461 | appctx->ctx.tlskeys.ref->filename); |
| 5462 | |
| 5463 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5464 | /* let's try again later from this stream. We add ourselves into |
| 5465 | * this stream's users so that it can remove us upon termination. |
| 5466 | */ |
| 5467 | si_applet_cant_put(si); |
| 5468 | return 0; |
| 5469 | } |
| 5470 | |
| 5471 | /* get next list entry and check the end of the list */ |
| 5472 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 5473 | } |
| 5474 | |
| 5475 | appctx->st2 = STAT_ST_FIN; |
| 5476 | /* fall through */ |
| 5477 | |
| 5478 | default: |
| 5479 | appctx->st2 = STAT_ST_FIN; |
| 5480 | return 1; |
| 5481 | } |
| 5482 | return 0; |
| 5483 | } |
| 5484 | #endif |
| 5485 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5486 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5487 | { |
| 5488 | struct appctx *appctx = __objt_appctx(si->end); |
| 5489 | |
| 5490 | switch (appctx->st2) { |
| 5491 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5492 | /* Display the column headers. If the message cannot be sent, |
| 5493 | * quit the fucntion with returning 0. The function is called |
| 5494 | * later and restart at the state "STAT_ST_INIT". |
| 5495 | */ |
| 5496 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5497 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5498 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5499 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5500 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5501 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5502 | |
| 5503 | /* Now, we start the browsing of the references lists. |
| 5504 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5505 | * avalaible field of this pointer is <list>. It is used with the function |
| 5506 | * pat_list_get_next() for retruning the first avalaible entry |
| 5507 | */ |
| 5508 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5509 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5510 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5511 | appctx->st2 = STAT_ST_LIST; |
| 5512 | /* fall through */ |
| 5513 | |
| 5514 | case STAT_ST_LIST: |
| 5515 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5516 | chunk_reset(&trash); |
| 5517 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5518 | /* Build messages. If the reference is used by another category than |
| 5519 | * the listed categorie, display the information in the massage. |
| 5520 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5521 | 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] | 5522 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5523 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5524 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5525 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5526 | /* let's try again later from this stream. We add ourselves into |
| 5527 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5528 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5529 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5530 | return 0; |
| 5531 | } |
| 5532 | |
| 5533 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5534 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5535 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | appctx->st2 = STAT_ST_FIN; |
| 5539 | /* fall through */ |
| 5540 | |
| 5541 | default: |
| 5542 | appctx->st2 = STAT_ST_FIN; |
| 5543 | return 1; |
| 5544 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5545 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5546 | } |
| 5547 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5548 | static int stats_map_lookup(struct stream_interface *si) |
| 5549 | { |
| 5550 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5551 | struct sample sample; |
| 5552 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5553 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5554 | |
| 5555 | switch (appctx->st2) { |
| 5556 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5557 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5558 | 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] | 5559 | 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] | 5560 | appctx->st2 = STAT_ST_LIST; |
| 5561 | /* fall through */ |
| 5562 | |
| 5563 | case STAT_ST_LIST: |
| 5564 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5565 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5566 | /* initialise chunk to build new message */ |
| 5567 | chunk_reset(&trash); |
| 5568 | |
| 5569 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 5570 | sample.type = SMP_T_STR; |
| 5571 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5572 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 5573 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5574 | if (appctx->ctx.map.expr->pat_head->match && |
| 5575 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5576 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5577 | else |
| 5578 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5579 | |
| 5580 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5581 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5582 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5583 | break; |
| 5584 | if (match_method >= PAT_MATCH_NUM) |
| 5585 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5586 | else |
| 5587 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5588 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5589 | /* case sensitive */ |
| 5590 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5591 | chunk_appendf(&trash, ", case=insensitive"); |
| 5592 | else |
| 5593 | chunk_appendf(&trash, ", case=sensitive"); |
| 5594 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5595 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5596 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5597 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5598 | chunk_appendf(&trash, ", found=no"); |
| 5599 | else |
| 5600 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | /* Display match and match info */ |
| 5604 | else { |
| 5605 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5606 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5607 | chunk_appendf(&trash, ", found=yes"); |
| 5608 | else |
| 5609 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5610 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5611 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5612 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5613 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5614 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5615 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5616 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5617 | /* display pattern */ |
| 5618 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5619 | if (pat->ref && pat->ref->pattern) |
| 5620 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5621 | else |
| 5622 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5623 | } |
| 5624 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5625 | if (pat->ref && pat->ref->pattern) |
| 5626 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5627 | else |
| 5628 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5629 | } |
| 5630 | |
| 5631 | /* display return value */ |
| 5632 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5633 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5634 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5635 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5636 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5637 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5638 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5639 | } |
| 5640 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5641 | chunk_appendf(&trash, "\n"); |
| 5642 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5643 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5644 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5645 | /* let's try again later from this stream. We add ourselves into |
| 5646 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5647 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5648 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5649 | return 0; |
| 5650 | } |
| 5651 | |
| 5652 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5653 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5654 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5655 | } |
| 5656 | |
| 5657 | appctx->st2 = STAT_ST_FIN; |
| 5658 | /* fall through */ |
| 5659 | |
| 5660 | default: |
| 5661 | appctx->st2 = STAT_ST_FIN; |
| 5662 | free(appctx->ctx.map.chunk.str); |
| 5663 | return 1; |
| 5664 | } |
| 5665 | } |
| 5666 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5667 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5668 | { |
| 5669 | struct appctx *appctx = __objt_appctx(si->end); |
| 5670 | |
| 5671 | switch (appctx->st2) { |
| 5672 | |
| 5673 | case STAT_ST_INIT: |
| 5674 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5675 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5676 | struct pat_ref_elt *, list); |
| 5677 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5678 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5679 | appctx->st2 = STAT_ST_LIST; |
| 5680 | /* fall through */ |
| 5681 | |
| 5682 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5683 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5684 | chunk_reset(&trash); |
| 5685 | |
| 5686 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5687 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5688 | chunk_appendf(&trash, "%p %s %s\n", |
| 5689 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5690 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5691 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5692 | chunk_appendf(&trash, "%p %s\n", |
| 5693 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5694 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5695 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5696 | /* let's try again later from this stream. We add ourselves into |
| 5697 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5698 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5699 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5700 | return 0; |
| 5701 | } |
| 5702 | |
| 5703 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5704 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5705 | struct pat_ref_elt *, list); |
| 5706 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5707 | break; |
| 5708 | } |
| 5709 | |
| 5710 | appctx->st2 = STAT_ST_FIN; |
| 5711 | /* fall through */ |
| 5712 | |
| 5713 | default: |
| 5714 | appctx->st2 = STAT_ST_FIN; |
| 5715 | return 1; |
| 5716 | } |
| 5717 | } |
| 5718 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5719 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5720 | * 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] | 5721 | * to be called again, otherwise non-zero. It is designed to be called |
| 5722 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5723 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5724 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5725 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5726 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5727 | struct connection *conn; |
| 5728 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5729 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5730 | /* 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] | 5731 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5732 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5733 | if (appctx->st2 == STAT_ST_LIST) { |
| 5734 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5735 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5736 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5737 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5738 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5739 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5740 | } |
| 5741 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5742 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5743 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5744 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5745 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5746 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5747 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5748 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5749 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5750 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5751 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5752 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5753 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5754 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5755 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5756 | /* fall through */ |
| 5757 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5758 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5759 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5760 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5761 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5762 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5763 | } |
| 5764 | |
| 5765 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5766 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5767 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5768 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5769 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5770 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5771 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5772 | if (appctx->ctx.sess.target) { |
| 5773 | 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] | 5774 | goto next_sess; |
| 5775 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5776 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5777 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5778 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5779 | return 0; |
| 5780 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5781 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5782 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5783 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5784 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5785 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5786 | break; |
| 5787 | } |
| 5788 | else |
| 5789 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5790 | } |
| 5791 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5792 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5793 | "%p: proto=%s", |
| 5794 | curr_sess, |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5795 | strm_li(curr_sess)->proto->name); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5796 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5797 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5798 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5799 | 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] | 5800 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5801 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5802 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5803 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5804 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5805 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5806 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5807 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5808 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5809 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5810 | break; |
| 5811 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5812 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5813 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5814 | strm_li(curr_sess)->luid, |
| 5815 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5816 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5817 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5818 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5819 | break; |
| 5820 | } |
| 5821 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5822 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5823 | " ts=%02x age=%s calls=%d", |
| 5824 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5825 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5826 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5827 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5828 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5829 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5830 | curr_sess->req.flags, |
| 5831 | curr_sess->req.buf->i, |
| 5832 | curr_sess->req.analysers, |
| 5833 | curr_sess->req.rex ? |
| 5834 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5835 | TICKS_TO_MS(1000)) : ""); |
| 5836 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5837 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5838 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5839 | curr_sess->req.wex ? |
| 5840 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5841 | TICKS_TO_MS(1000)) : ""); |
| 5842 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5843 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5844 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5845 | curr_sess->req.analyse_exp ? |
| 5846 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5847 | TICKS_TO_MS(1000)) : ""); |
| 5848 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5849 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5850 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5851 | curr_sess->res.flags, |
| 5852 | curr_sess->res.buf->i, |
| 5853 | curr_sess->res.analysers, |
| 5854 | curr_sess->res.rex ? |
| 5855 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5856 | TICKS_TO_MS(1000)) : ""); |
| 5857 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5858 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5859 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5860 | curr_sess->res.wex ? |
| 5861 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5862 | TICKS_TO_MS(1000)) : ""); |
| 5863 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5864 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5865 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5866 | curr_sess->res.analyse_exp ? |
| 5867 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5868 | TICKS_TO_MS(1000)) : ""); |
| 5869 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5870 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5871 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5872 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5873 | curr_sess->si[0].state, |
| 5874 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5875 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5876 | curr_sess->si[0].exp ? |
| 5877 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5878 | TICKS_TO_MS(1000)) : ""); |
| 5879 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5880 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5881 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5882 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5883 | curr_sess->si[1].state, |
| 5884 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5885 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5886 | curr_sess->si[1].exp ? |
| 5887 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5888 | TICKS_TO_MS(1000)) : ""); |
| 5889 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5890 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5891 | " exp=%s", |
| 5892 | curr_sess->task->expire ? |
| 5893 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5894 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5895 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5896 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5897 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5898 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5899 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5900 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5901 | /* let's try again later from this stream. We add ourselves into |
| 5902 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5903 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5904 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5905 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5906 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5907 | } |
| 5908 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5909 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5910 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5911 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5912 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5913 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5914 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5915 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5916 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5917 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5918 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5919 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5920 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5921 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5922 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5923 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5924 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5925 | appctx->ctx.sess.target = NULL; |
| 5926 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5927 | return 1; |
| 5928 | } |
| 5929 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5930 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5931 | /* fall through */ |
| 5932 | |
| 5933 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5934 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5935 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5936 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5937 | } |
| 5938 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5939 | /* This is called when the stream interface is closed. For instance, upon an |
| 5940 | * 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] | 5941 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5942 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5943 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5944 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5945 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5946 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5947 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5948 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5949 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5950 | free(appctx->ctx.cli.err); |
| 5951 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5952 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5953 | free(appctx->ctx.map.chunk.str); |
| 5954 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5955 | } |
| 5956 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5957 | /* This function is used to either dump tables states (when action is set |
| 5958 | * 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] | 5959 | * It returns 0 if the output buffer is full and it needs to be called |
| 5960 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5961 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5962 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5963 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5964 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5965 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5966 | struct ebmb_node *eb; |
| 5967 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5968 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5969 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5970 | |
| 5971 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5972 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5973 | * - STAT_ST_INIT : the first call |
| 5974 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5975 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5976 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5977 | * and the entry pointer points to the next entry to be dumped, |
| 5978 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5979 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5980 | * data though. |
| 5981 | */ |
| 5982 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5983 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5984 | /* 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] | 5985 | if (appctx->st2 == STAT_ST_LIST) { |
| 5986 | appctx->ctx.table.entry->ref_cnt--; |
| 5987 | 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] | 5988 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5989 | return 1; |
| 5990 | } |
| 5991 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5992 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5993 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5994 | while (appctx->st2 != STAT_ST_FIN) { |
| 5995 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5996 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5997 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5998 | if (!appctx->ctx.table.proxy) |
| 5999 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6000 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6001 | appctx->ctx.table.entry = NULL; |
| 6002 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6003 | break; |
| 6004 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6005 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6006 | if (!appctx->ctx.table.proxy || |
| 6007 | (appctx->ctx.table.target && |
| 6008 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6009 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6010 | break; |
| 6011 | } |
| 6012 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6013 | if (appctx->ctx.table.proxy->table.size) { |
| 6014 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6015 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6016 | return 0; |
| 6017 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6018 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6019 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6020 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6021 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6022 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6023 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6024 | appctx->ctx.table.entry->ref_cnt++; |
| 6025 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6026 | break; |
| 6027 | } |
| 6028 | } |
| 6029 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6030 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6031 | break; |
| 6032 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6033 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6034 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6035 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6036 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6037 | /* we're filtering on some data contents */ |
| 6038 | void *ptr; |
| 6039 | long long data; |
| 6040 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6041 | dt = appctx->ctx.table.data_type; |
| 6042 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6043 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6044 | dt); |
| 6045 | |
| 6046 | data = 0; |
| 6047 | switch (stktable_data_types[dt].std_type) { |
| 6048 | case STD_T_SINT: |
| 6049 | data = stktable_data_cast(ptr, std_t_sint); |
| 6050 | break; |
| 6051 | case STD_T_UINT: |
| 6052 | data = stktable_data_cast(ptr, std_t_uint); |
| 6053 | break; |
| 6054 | case STD_T_ULL: |
| 6055 | data = stktable_data_cast(ptr, std_t_ull); |
| 6056 | break; |
| 6057 | case STD_T_FRQP: |
| 6058 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6059 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6060 | break; |
| 6061 | } |
| 6062 | |
| 6063 | /* 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] | 6064 | if ((data < appctx->ctx.table.value && |
| 6065 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6066 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6067 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6068 | (data == appctx->ctx.table.value && |
| 6069 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6070 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6071 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6072 | (data > appctx->ctx.table.value && |
| 6073 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6074 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6075 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6076 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6077 | } |
| 6078 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6079 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6080 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6081 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6082 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6083 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6084 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6085 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6086 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6087 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6088 | struct stksess *old = appctx->ctx.table.entry; |
| 6089 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6090 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6091 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6092 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6093 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6094 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6095 | break; |
| 6096 | } |
| 6097 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6098 | |
| 6099 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6100 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6101 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6102 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6103 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6104 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6105 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6106 | break; |
| 6107 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6108 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6109 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6110 | break; |
| 6111 | } |
| 6112 | } |
| 6113 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6114 | } |
| 6115 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6116 | /* 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] | 6117 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6118 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6119 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6120 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6121 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6122 | * after the offset. The new pointer is returned. |
| 6123 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6124 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6125 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6126 | { |
| 6127 | int end; |
| 6128 | unsigned char c; |
| 6129 | |
| 6130 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6131 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6132 | return ptr; |
| 6133 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6134 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6135 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6136 | while (ptr < len && ptr < bsize) { |
| 6137 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6138 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6139 | if (out->len > end - 2) |
| 6140 | break; |
| 6141 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6142 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6143 | if (out->len > end - 3) |
| 6144 | break; |
| 6145 | out->str[out->len++] = '\\'; |
| 6146 | switch (c) { |
| 6147 | case '\t': c = 't'; break; |
| 6148 | case '\n': c = 'n'; break; |
| 6149 | case '\r': c = 'r'; break; |
| 6150 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6151 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6152 | } |
| 6153 | out->str[out->len++] = c; |
| 6154 | } else { |
| 6155 | if (out->len > end - 5) |
| 6156 | break; |
| 6157 | out->str[out->len++] = '\\'; |
| 6158 | out->str[out->len++] = 'x'; |
| 6159 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6160 | out->str[out->len++] = hextab[c & 0xF]; |
| 6161 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6162 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6163 | /* we had a line break, let's return now */ |
| 6164 | out->str[out->len++] = '\n'; |
| 6165 | *line = ptr; |
| 6166 | return ptr; |
| 6167 | } |
| 6168 | } |
| 6169 | /* we have an incomplete line, we return it as-is */ |
| 6170 | out->str[out->len++] = '\n'; |
| 6171 | return ptr; |
| 6172 | } |
| 6173 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6174 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6175 | * 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] | 6176 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6177 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6178 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6179 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6180 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6181 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6182 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6183 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6184 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6185 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6186 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6187 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6188 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6189 | /* the function had not been called yet, let's prepare the |
| 6190 | * buffer for a response. |
| 6191 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6192 | struct tm tm; |
| 6193 | |
| 6194 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6195 | 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] | 6196 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6197 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6198 | error_snapshot_id); |
| 6199 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6200 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6201 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6202 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6203 | return 0; |
| 6204 | } |
| 6205 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6206 | appctx->ctx.errors.px = proxy; |
| 6207 | appctx->ctx.errors.buf = 0; |
| 6208 | appctx->ctx.errors.bol = 0; |
| 6209 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6210 | } |
| 6211 | |
| 6212 | /* we have two inner loops here, one for the proxy, the other one for |
| 6213 | * the buffer. |
| 6214 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6215 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6216 | struct error_snapshot *es; |
| 6217 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6218 | if (appctx->ctx.errors.buf == 0) |
| 6219 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6220 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6221 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6222 | |
| 6223 | if (!es->when.tv_sec) |
| 6224 | goto next; |
| 6225 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6226 | if (appctx->ctx.errors.iid >= 0 && |
| 6227 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6228 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6229 | goto next; |
| 6230 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6231 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6232 | /* just print headers now */ |
| 6233 | |
| 6234 | char pn[INET6_ADDRSTRLEN]; |
| 6235 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6236 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6237 | |
| 6238 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6239 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6240 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6241 | 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] | 6242 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6243 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6244 | case AF_INET: |
| 6245 | case AF_INET6: |
| 6246 | port = get_host_port(&es->src); |
| 6247 | break; |
| 6248 | default: |
| 6249 | port = 0; |
| 6250 | } |
| 6251 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6252 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6253 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6254 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6255 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6256 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6257 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6258 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6259 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6260 | break; |
| 6261 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6262 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6263 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6264 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6265 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6266 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6267 | break; |
| 6268 | } |
| 6269 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6270 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6271 | ", server %s (#%d), event #%u\n" |
| 6272 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6273 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6274 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6275 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6276 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6277 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6278 | es->ev_id, |
| 6279 | pn, port, es->sid, es->s_flags, |
| 6280 | es->state, es->m_flags, es->t_flags, |
| 6281 | es->m_clen, es->m_blen, |
| 6282 | es->b_flags, es->b_out, es->b_tot, |
| 6283 | es->len, es->b_wrap, es->pos); |
| 6284 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6285 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6286 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6287 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6288 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6289 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6290 | appctx->ctx.errors.ptr = 0; |
| 6291 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6292 | } |
| 6293 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6294 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6295 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6296 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6297 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6298 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6299 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6300 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6301 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6302 | goto next; |
| 6303 | } |
| 6304 | |
| 6305 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6306 | 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] | 6307 | int newptr; |
| 6308 | int newline; |
| 6309 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6310 | newline = appctx->ctx.errors.bol; |
| 6311 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6312 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6313 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6314 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6315 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6316 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6317 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6318 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6319 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6320 | appctx->ctx.errors.ptr = newptr; |
| 6321 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6322 | }; |
| 6323 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6324 | appctx->ctx.errors.bol = 0; |
| 6325 | appctx->ctx.errors.ptr = -1; |
| 6326 | appctx->ctx.errors.buf++; |
| 6327 | if (appctx->ctx.errors.buf > 1) { |
| 6328 | appctx->ctx.errors.buf = 0; |
| 6329 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6330 | } |
| 6331 | } |
| 6332 | |
| 6333 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6334 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6335 | } |
| 6336 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6337 | /* parse the "level" argument on the bind lines */ |
| 6338 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6339 | { |
| 6340 | if (!*args[cur_arg + 1]) { |
| 6341 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6342 | return ERR_ALERT | ERR_FATAL; |
| 6343 | } |
| 6344 | |
| 6345 | if (!strcmp(args[cur_arg+1], "user")) |
| 6346 | conf->level = ACCESS_LVL_USER; |
| 6347 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6348 | conf->level = ACCESS_LVL_OPER; |
| 6349 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6350 | conf->level = ACCESS_LVL_ADMIN; |
| 6351 | else { |
| 6352 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6353 | args[cur_arg], args[cur_arg+1]); |
| 6354 | return ERR_ALERT | ERR_FATAL; |
| 6355 | } |
| 6356 | |
| 6357 | return 0; |
| 6358 | } |
| 6359 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 6360 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6361 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6362 | .name = "<STATS>", /* used for logging */ |
| 6363 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6364 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6365 | }; |
| 6366 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 6367 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6368 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6369 | .name = "<CLI>", /* used for logging */ |
| 6370 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6371 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6372 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6373 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6374 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6375 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6376 | { 0, NULL, NULL }, |
| 6377 | }}; |
| 6378 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6379 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6380 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6381 | { NULL, NULL, 0 }, |
| 6382 | }}; |
| 6383 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6384 | __attribute__((constructor)) |
| 6385 | static void __dumpstats_module_init(void) |
| 6386 | { |
| 6387 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6388 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6389 | } |
| 6390 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6391 | /* |
| 6392 | * Local variables: |
| 6393 | * c-indent-level: 8 |
| 6394 | * c-basic-offset: 8 |
| 6395 | * End: |
| 6396 | */ |