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 | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 869 | appctx->ctx.table.target = find_stktable(args[2]); |
| 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 */ |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3332 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3333 | [SRV_STATS_STATE_DOWN] = "DOWN,", |
| 3334 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent),", |
| 3335 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d,", |
| 3336 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d,", |
| 3337 | [SRV_STATS_STATE_UP] = "UP,", |
| 3338 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d,", |
| 3339 | [SRV_STATS_STATE_NOLB] = "NOLB,", |
| 3340 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d,", |
| 3341 | [SRV_STATS_STATE_DRAIN] = "DRAIN,", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3342 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3343 | [SRV_STATS_STATE_NO_CHECK] = "no check," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3344 | }; |
| 3345 | |
| 3346 | chunk_appendf(&trash, |
| 3347 | /* pxid, name */ |
| 3348 | "%s,%s," |
| 3349 | /* queue : current, max */ |
| 3350 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3351 | /* sessions : current, max, limit, total */ |
| 3352 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3353 | /* bytes : in, out */ |
| 3354 | "%lld,%lld," |
| 3355 | /* denied: req, resp */ |
| 3356 | ",%lld," |
| 3357 | /* errors : request, connect, response */ |
| 3358 | ",%lld,%lld," |
| 3359 | /* warnings: retries, redispatches */ |
| 3360 | "%lld,%lld," |
| 3361 | "", |
| 3362 | px->id, sv->id, |
| 3363 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3364 | 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] | 3365 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3366 | sv->counters.failed_secu, |
| 3367 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3368 | sv->counters.retries, sv->counters.redispatches); |
| 3369 | |
| 3370 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3371 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3372 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3373 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3374 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3375 | else |
| 3376 | chunk_appendf(&trash, |
| 3377 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3378 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3379 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3380 | |
| 3381 | chunk_appendf(&trash, |
| 3382 | /* weight, active, backup */ |
| 3383 | "%d,%d,%d," |
| 3384 | "", |
| 3385 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3386 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3387 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3388 | |
| 3389 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3390 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3391 | chunk_appendf(&trash, |
| 3392 | "%lld,%lld,%d,%d,", |
| 3393 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3394 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3395 | else |
| 3396 | chunk_appendf(&trash, ",,,,"); |
| 3397 | |
| 3398 | /* queue limit, pid, iid, sid, */ |
| 3399 | chunk_appendf(&trash, |
| 3400 | "%s," |
| 3401 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3402 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3403 | relative_pid, px->uuid, sv->puid); |
| 3404 | |
| 3405 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3406 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3407 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3408 | |
| 3409 | /* sessions: lbtot */ |
| 3410 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3411 | |
| 3412 | /* tracked */ |
| 3413 | if (sv->track) |
| 3414 | chunk_appendf(&trash, "%s/%s,", |
| 3415 | sv->track->proxy->id, sv->track->id); |
| 3416 | else |
| 3417 | chunk_appendf(&trash, ","); |
| 3418 | |
| 3419 | /* type */ |
| 3420 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3421 | |
| 3422 | /* rate */ |
| 3423 | chunk_appendf(&trash, "%u,,%u,", |
| 3424 | read_freq_ctr(&sv->sess_per_sec), |
| 3425 | sv->counters.sps_max); |
| 3426 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3427 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3428 | /* check_status */ |
| 3429 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 3430 | |
| 3431 | /* check_code */ |
| 3432 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3433 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3434 | else |
| 3435 | chunk_appendf(&trash, ","); |
| 3436 | |
| 3437 | /* check_duration */ |
| 3438 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3439 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3440 | else |
| 3441 | chunk_appendf(&trash, ","); |
| 3442 | |
| 3443 | } |
| 3444 | else |
| 3445 | chunk_appendf(&trash, ",,,"); |
| 3446 | |
| 3447 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3448 | if (px->mode == PR_MODE_HTTP) { |
| 3449 | for (i=1; i<6; i++) |
| 3450 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3451 | |
| 3452 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3453 | } |
| 3454 | else |
| 3455 | chunk_appendf(&trash, ",,,,,,"); |
| 3456 | |
| 3457 | /* failed health analyses */ |
| 3458 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3459 | |
| 3460 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3461 | chunk_appendf(&trash, ",,,"); |
| 3462 | |
| 3463 | /* errors: cli_aborts, srv_aborts */ |
| 3464 | chunk_appendf(&trash, "%lld,%lld,", |
| 3465 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3466 | |
| 3467 | /* compression: in, out, bypassed, comp_rsp */ |
| 3468 | chunk_appendf(&trash, ",,,,"); |
| 3469 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3470 | /* lastsess */ |
| 3471 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3472 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3473 | /* capture of last check and agent statuses */ |
| 3474 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->check.desc) : ""); |
| 3475 | chunk_appendf(&trash, "%s,", ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? cstr(sv->agent.desc) : ""); |
| 3476 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3477 | /* qtime, ctime, rtime, ttime, */ |
| 3478 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3479 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3480 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3481 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3482 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3483 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3484 | /* finish with EOL */ |
| 3485 | chunk_appendf(&trash, "\n"); |
| 3486 | } |
| 3487 | return 1; |
| 3488 | } |
| 3489 | |
| 3490 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3491 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3492 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3493 | */ |
| 3494 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3495 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3496 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3497 | struct chunk src; |
| 3498 | int i; |
| 3499 | |
| 3500 | if (!(px->cap & PR_CAP_BE)) |
| 3501 | return 0; |
| 3502 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3503 | 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] | 3504 | return 0; |
| 3505 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3506 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3507 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3508 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3509 | /* Column sub-heading for Enable or Disable server */ |
| 3510 | chunk_appendf(&trash, "<td></td>"); |
| 3511 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3512 | chunk_appendf(&trash, |
| 3513 | "<td class=ac>" |
| 3514 | /* name */ |
| 3515 | "%s<a name=\"%s/Backend\"></a>" |
| 3516 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3517 | "", |
| 3518 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3519 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3520 | |
| 3521 | if (flags & ST_SHLGNDS) { |
| 3522 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3523 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3524 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3525 | |
| 3526 | /* cookie */ |
| 3527 | if (px->cookie_name) { |
| 3528 | chunk_appendf(&trash, ", cookie: '"); |
| 3529 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3530 | chunk_htmlencode(&trash, &src); |
| 3531 | chunk_appendf(&trash, "'"); |
| 3532 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3533 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3537 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3538 | /* queue : current, max */ |
| 3539 | "<td>%s</td><td>%s</td><td></td>" |
| 3540 | /* sessions rate : current, max, limit */ |
| 3541 | "<td>%s</td><td>%s</td><td></td>" |
| 3542 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3543 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3544 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3545 | 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] | 3546 | |
| 3547 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3548 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3549 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3550 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3551 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3552 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3553 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3554 | U2H(px->be_counters.cum_conn), |
| 3555 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3556 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3557 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3558 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3559 | chunk_appendf(&trash, |
| 3560 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3561 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3562 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3563 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3564 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3565 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3566 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3567 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3568 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3569 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3570 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3571 | U2H(px->be_counters.p.http.cum_req), |
| 3572 | U2H(px->be_counters.p.http.rsp[1]), |
| 3573 | U2H(px->be_counters.p.http.rsp[2]), |
| 3574 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3575 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3576 | (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] | 3577 | U2H(px->be_counters.p.http.rsp[3]), |
| 3578 | U2H(px->be_counters.p.http.rsp[4]), |
| 3579 | U2H(px->be_counters.p.http.rsp[5]), |
| 3580 | U2H(px->be_counters.p.http.rsp[0]), |
| 3581 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3582 | } |
| 3583 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3584 | 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))); |
| 3585 | 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))); |
| 3586 | if (px->mode == PR_MODE_HTTP) |
| 3587 | 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))); |
| 3588 | 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))); |
| 3589 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3590 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3591 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3592 | /* sessions: lbtot, last */ |
| 3593 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3594 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3595 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3596 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3597 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3598 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3599 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3600 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3601 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3602 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3603 | "<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] | 3604 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3605 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3606 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3607 | px->be_counters.comp_in ? |
| 3608 | (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] | 3609 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3610 | |
| 3611 | chunk_appendf(&trash, |
| 3612 | /* denied: req, resp */ |
| 3613 | "<td>%s</td><td>%s</td>" |
| 3614 | /* errors : request, connect */ |
| 3615 | "<td></td><td>%s</td>" |
| 3616 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3617 | "<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] | 3618 | /* warnings: retries, redispatches */ |
| 3619 | "<td>%lld</td><td>%lld</td>" |
| 3620 | /* backend status: reflect backend status (up/down): we display UP |
| 3621 | * if the backend has known working servers or if it has no server at |
| 3622 | * all (eg: for stats). Then we display the total weight, number of |
| 3623 | * active and backups. */ |
| 3624 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3625 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3626 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3627 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3628 | U2H(px->be_counters.failed_conns), |
| 3629 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3630 | px->be_counters.cli_aborts, |
| 3631 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3632 | px->be_counters.retries, px->be_counters.redispatches, |
| 3633 | human_time(now.tv_sec - px->last_change, 1), |
| 3634 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3635 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3636 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3637 | px->srv_act, px->srv_bck); |
| 3638 | |
| 3639 | chunk_appendf(&trash, |
| 3640 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3641 | "<td class=ac> </td><td>%d</td>" |
| 3642 | "<td>%s</td>" |
| 3643 | "<td></td>" |
| 3644 | "</tr>", |
| 3645 | px->down_trans, |
| 3646 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3647 | } |
| 3648 | else { /* CSV mode */ |
| 3649 | chunk_appendf(&trash, |
| 3650 | /* pxid, name */ |
| 3651 | "%s,BACKEND," |
| 3652 | /* queue : current, max */ |
| 3653 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3654 | /* sessions : current, max, limit, total */ |
| 3655 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3656 | /* bytes : in, out */ |
| 3657 | "%lld,%lld," |
| 3658 | /* denied: req, resp */ |
| 3659 | "%lld,%lld," |
| 3660 | /* errors : request, connect, response */ |
| 3661 | ",%lld,%lld," |
| 3662 | /* warnings: retries, redispatches */ |
| 3663 | "%lld,%lld," |
| 3664 | /* backend status: reflect backend status (up/down): we display UP |
| 3665 | * if the backend has known working servers or if it has no server at |
| 3666 | * all (eg: for stats). Then we display the total weight, number of |
| 3667 | * active and backups. */ |
| 3668 | "%s," |
| 3669 | "%d,%d,%d," |
| 3670 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3671 | ",%d,%d,%d,," |
| 3672 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3673 | "%d,%d,0,,%lld,,%d," |
| 3674 | /* rate, rate_lim, rate_max, */ |
| 3675 | "%u,,%u," |
| 3676 | /* check_status, check_code, check_duration */ |
| 3677 | ",,,", |
| 3678 | px->id, |
| 3679 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3680 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3681 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3682 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3683 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3684 | px->be_counters.retries, px->be_counters.redispatches, |
| 3685 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3686 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3687 | px->srv_act, px->srv_bck, |
| 3688 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3689 | px->srv?be_downtime(px):0, |
| 3690 | relative_pid, px->uuid, |
| 3691 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3692 | read_freq_ctr(&px->be_sess_per_sec), |
| 3693 | px->be_counters.sps_max); |
| 3694 | |
| 3695 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3696 | if (px->mode == PR_MODE_HTTP) { |
| 3697 | for (i=1; i<6; i++) |
| 3698 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3699 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3700 | } |
| 3701 | else |
| 3702 | chunk_appendf(&trash, ",,,,,,"); |
| 3703 | |
| 3704 | /* failed health analyses */ |
| 3705 | chunk_appendf(&trash, ","); |
| 3706 | |
| 3707 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3708 | chunk_appendf(&trash, ",,,"); |
| 3709 | |
| 3710 | /* errors: cli_aborts, srv_aborts */ |
| 3711 | chunk_appendf(&trash, "%lld,%lld,", |
| 3712 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3713 | |
| 3714 | /* compression: in, out, bypassed */ |
| 3715 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3716 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3717 | |
| 3718 | /* compression: comp_rsp */ |
| 3719 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3720 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3721 | /* lastsess, last_chk, last_agt, */ |
| 3722 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3723 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3724 | /* qtime, ctime, rtime, ttime, */ |
| 3725 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3726 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 3727 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 3728 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 3729 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 3730 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3731 | /* finish with EOL */ |
| 3732 | chunk_appendf(&trash, "\n"); |
| 3733 | } |
| 3734 | return 1; |
| 3735 | } |
| 3736 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3737 | /* 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] | 3738 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3739 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3740 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3741 | 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] | 3742 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3743 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3744 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3745 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3746 | 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] | 3747 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3748 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3749 | /* 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] | 3750 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3751 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3752 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3753 | 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] | 3754 | 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] | 3755 | } |
| 3756 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3757 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 3758 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | /* print a new table */ |
| 3762 | chunk_appendf(&trash, |
| 3763 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3764 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3765 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3766 | |
| 3767 | chunk_appendf(&trash, |
| 3768 | "<a name=\"%s\"></a>%s" |
| 3769 | "<a class=px href=\"#%s\">%s</a>", |
| 3770 | px->id, |
| 3771 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3772 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3773 | |
| 3774 | if (uri->flags & ST_SHLGNDS) { |
| 3775 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3776 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3777 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3778 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3779 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3783 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3784 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3785 | "</tr>\n" |
| 3786 | "</table>\n" |
| 3787 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3788 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3789 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3790 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3791 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3792 | 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] | 3793 | /* Column heading for Enable or Disable server */ |
| 3794 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3795 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3796 | |
| 3797 | chunk_appendf(&trash, |
| 3798 | "<th rowspan=2></th>" |
| 3799 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3800 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3801 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3802 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3803 | "<th colspan=9>Server</th>" |
| 3804 | "</tr>\n" |
| 3805 | "<tr class=\"titre\">" |
| 3806 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3807 | "<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] | 3808 | "<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] | 3809 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3810 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3811 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3812 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3813 | "<th>Thrtle</th>\n" |
| 3814 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3815 | } |
| 3816 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3817 | /* 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] | 3818 | * 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] | 3819 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3820 | 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] | 3821 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3822 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3823 | chunk_appendf(&trash, "</table>"); |
| 3824 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3825 | 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] | 3826 | /* close the form used to enable/disable this proxy servers */ |
| 3827 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3828 | "Choose the action to perform on the checked servers : " |
| 3829 | "<select name=action>" |
| 3830 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 3831 | "<option value=\"ready\">Set state to READY</option>" |
| 3832 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 3833 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 3834 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3835 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3836 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3837 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3838 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3839 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3840 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3841 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3842 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3843 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3844 | "</select>" |
| 3845 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3846 | " <input type=\"submit\" value=\"Apply\">" |
| 3847 | "</form>", |
| 3848 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3852 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3853 | |
| 3854 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3855 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3856 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3857 | * buffer space, or non-zero if everything completed. This function is used |
| 3858 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3859 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3860 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3861 | 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] | 3862 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3863 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3864 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 3865 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3866 | 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] | 3867 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3868 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3869 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3870 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3871 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3872 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3873 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3874 | if (uri && uri->scope) { |
| 3875 | /* we have a limited scope, we have to check the proxy name */ |
| 3876 | struct stat_scope *scope; |
| 3877 | int len; |
| 3878 | |
| 3879 | len = strlen(px->id); |
| 3880 | scope = uri->scope; |
| 3881 | |
| 3882 | while (scope) { |
| 3883 | /* match exact proxy name */ |
| 3884 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3885 | break; |
| 3886 | |
| 3887 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3888 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3889 | break; |
| 3890 | scope = scope->next; |
| 3891 | } |
| 3892 | |
| 3893 | /* proxy name not found : don't dump anything */ |
| 3894 | if (scope == NULL) |
| 3895 | return 1; |
| 3896 | } |
| 3897 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3898 | /* if the user has requested a limited output and the proxy |
| 3899 | * name does not match, skip it. |
| 3900 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3901 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3902 | 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] | 3903 | return 1; |
| 3904 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3905 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3906 | (appctx->ctx.stats.iid != -1) && |
| 3907 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3908 | return 1; |
| 3909 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3910 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3911 | /* fall through */ |
| 3912 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3913 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3914 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3915 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3916 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3917 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3918 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3919 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3920 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3921 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3922 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3923 | /* fall through */ |
| 3924 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3925 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3926 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3927 | if (stats_dump_fe_stats(si, px)) { |
| 3928 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3929 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3930 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3931 | } |
| 3932 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3933 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3934 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3935 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3936 | /* fall through */ |
| 3937 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3938 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3939 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3940 | 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] | 3941 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3942 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3943 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3944 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3945 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3946 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3947 | if (!l->counters) |
| 3948 | continue; |
| 3949 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3950 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3951 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3952 | break; |
| 3953 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3954 | 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] | 3955 | continue; |
| 3956 | } |
| 3957 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3958 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3959 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) { |
| 3960 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3961 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3962 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3963 | } |
| 3964 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3965 | } |
| 3966 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3967 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3968 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3969 | /* fall through */ |
| 3970 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3971 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3972 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3973 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3974 | enum srv_stats_state sv_state; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3975 | enum srv_stats_colour sv_colour; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3976 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3977 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3978 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3979 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3980 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3981 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3982 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3983 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3984 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3985 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3986 | break; |
| 3987 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3988 | 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] | 3989 | continue; |
| 3990 | } |
| 3991 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3992 | svs = sv; |
| 3993 | while (svs->track) |
| 3994 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3995 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3996 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 3997 | if ((svs->check.state & CHK_ST_ENABLED) && |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3998 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3999 | sv_state = SRV_STATS_STATE_UP_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4000 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4001 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4002 | sv_state = SRV_STATS_STATE_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4003 | sv_colour = SRV_STATS_COLOUR_UP; |
| 4004 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4005 | |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4006 | if (sv_state == SRV_STATS_STATE_UP && !svs->uweight) |
| 4007 | sv_colour = SRV_STATS_COLOUR_DRAINING; |
| 4008 | |
| 4009 | if (sv->admin & SRV_ADMF_DRAIN) { |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4010 | if (svs->agent.state & CHK_ST_ENABLED) |
| 4011 | sv_state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4012 | else if (sv_state == SRV_STATS_STATE_UP_GOING_DOWN) |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4013 | sv_state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4014 | else |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4015 | sv_state = SRV_STATS_STATE_DRAIN; |
| 4016 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4017 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4018 | 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] | 4019 | sv_state = SRV_STATS_STATE_NO_CHECK; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4020 | sv_colour = SRV_STATS_COLOUR_NO_CHECK; |
| 4021 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4022 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4023 | else if (sv->state == SRV_ST_STOPPING) { |
| 4024 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4025 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4026 | sv_state = SRV_STATS_STATE_NOLB; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4027 | sv_colour = SRV_STATS_COLOUR_NOLB; |
| 4028 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4029 | sv_state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4030 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4031 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4032 | } |
| 4033 | else { /* stopped */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4034 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4035 | sv_state = SRV_STATS_STATE_DOWN_AGENT; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4036 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4037 | } else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4038 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4039 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4040 | } 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] | 4041 | sv_state = SRV_STATS_STATE_GOING_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4042 | sv_colour = SRV_STATS_COLOUR_GOING_UP; |
| 4043 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4044 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4045 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4046 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4047 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4048 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4049 | 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] | 4050 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4051 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4052 | continue; |
| 4053 | } |
| 4054 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4055 | 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] | 4056 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4057 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4058 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4059 | } |
| 4060 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4061 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4062 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4063 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4064 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4065 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4066 | case STAT_PX_ST_BE: |
| 4067 | /* print the backend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4068 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) { |
| 4069 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4070 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4071 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4072 | } |
| 4073 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4074 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4075 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4076 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4077 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4078 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4079 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4080 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4081 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4082 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4083 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4084 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4085 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4086 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4087 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4088 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4089 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4090 | case STAT_PX_ST_FIN: |
| 4091 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4092 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4093 | default: |
| 4094 | /* unknown state, we should put an abort() here ! */ |
| 4095 | return 1; |
| 4096 | } |
| 4097 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4098 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4099 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4100 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4101 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4102 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4103 | { |
| 4104 | /* WARNING! This must fit in the first buffer !!! */ |
| 4105 | chunk_appendf(&trash, |
| 4106 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4107 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4108 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4109 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4110 | "<style type=\"text/css\"><!--\n" |
| 4111 | "body {" |
| 4112 | " font-family: arial, helvetica, sans-serif;" |
| 4113 | " font-size: 12px;" |
| 4114 | " font-weight: normal;" |
| 4115 | " color: black;" |
| 4116 | " background: white;" |
| 4117 | "}\n" |
| 4118 | "th,td {" |
| 4119 | " font-size: 10px;" |
| 4120 | "}\n" |
| 4121 | "h1 {" |
| 4122 | " font-size: x-large;" |
| 4123 | " margin-bottom: 0.5em;" |
| 4124 | "}\n" |
| 4125 | "h2 {" |
| 4126 | " font-family: helvetica, arial;" |
| 4127 | " font-size: x-large;" |
| 4128 | " font-weight: bold;" |
| 4129 | " font-style: italic;" |
| 4130 | " color: #6020a0;" |
| 4131 | " margin-top: 0em;" |
| 4132 | " margin-bottom: 0em;" |
| 4133 | "}\n" |
| 4134 | "h3 {" |
| 4135 | " font-family: helvetica, arial;" |
| 4136 | " font-size: 16px;" |
| 4137 | " font-weight: bold;" |
| 4138 | " color: #b00040;" |
| 4139 | " background: #e8e8d0;" |
| 4140 | " margin-top: 0em;" |
| 4141 | " margin-bottom: 0em;" |
| 4142 | "}\n" |
| 4143 | "li {" |
| 4144 | " margin-top: 0.25em;" |
| 4145 | " margin-right: 2em;" |
| 4146 | "}\n" |
| 4147 | ".hr {margin-top: 0.25em;" |
| 4148 | " border-color: black;" |
| 4149 | " border-bottom-style: solid;" |
| 4150 | "}\n" |
| 4151 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4152 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4153 | ".frontend {background: #e8e8d0;}\n" |
| 4154 | ".socket {background: #d0d0d0;}\n" |
| 4155 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4156 | ".active_down {background: #ff9090;}\n" |
| 4157 | ".active_going_up {background: #ffd020;}\n" |
| 4158 | ".active_going_down {background: #ffffa0;}\n" |
| 4159 | ".active_up {background: #c0ffc0;}\n" |
| 4160 | ".active_nolb {background: #20a0ff;}\n" |
| 4161 | ".active_draining {background: #20a0FF;}\n" |
| 4162 | ".active_no_check {background: #e0e0e0;}\n" |
| 4163 | ".backup_down {background: #ff9090;}\n" |
| 4164 | ".backup_going_up {background: #ff80ff;}\n" |
| 4165 | ".backup_going_down {background: #c060ff;}\n" |
| 4166 | ".backup_up {background: #b0d0ff;}\n" |
| 4167 | ".backup_nolb {background: #90b0e0;}\n" |
| 4168 | ".backup_draining {background: #cc9900;}\n" |
| 4169 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4170 | ".maintain {background: #c07820;}\n" |
| 4171 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4172 | "\n" |
| 4173 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4174 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4175 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4176 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4177 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4178 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4179 | "\n" |
| 4180 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4181 | "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" |
| 4182 | "table.tbl td.ac { text-align: center;}\n" |
| 4183 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4184 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4185 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4186 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4187 | "\n" |
| 4188 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4189 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4190 | "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] | 4191 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4192 | "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] | 4193 | "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] | 4194 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4195 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4196 | " display:block;\n" |
| 4197 | " visibility:hidden;\n" |
| 4198 | " z-index:2147483647;\n" |
| 4199 | " position:absolute;\n" |
| 4200 | " padding:2px 4px 3px;\n" |
| 4201 | " background:#f0f060; color:#000000;\n" |
| 4202 | " border:1px solid #7040c0;\n" |
| 4203 | " white-space:nowrap;\n" |
| 4204 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4205 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4206 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4207 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4208 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4209 | "-->\n" |
| 4210 | "</style></head>\n", |
| 4211 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4212 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4213 | ); |
| 4214 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4215 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4216 | /* 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] | 4217 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4218 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4219 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4220 | 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] | 4221 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4222 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4223 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4224 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4225 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4226 | /* WARNING! this has to fit the first packet too. |
| 4227 | * We are around 3.5 kB, add adding entries will |
| 4228 | * become tricky if we want to support 4kB buffers ! |
| 4229 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4230 | chunk_appendf(&trash, |
| 4231 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4232 | PRODUCT_NAME "%s</a></h1>\n" |
| 4233 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4234 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4235 | "<h3>> General process information</h3>\n" |
| 4236 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4237 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4238 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4239 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4240 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4241 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4242 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4243 | "</td><td align=\"center\" nowrap>\n" |
| 4244 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4245 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4246 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4247 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4248 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4249 | "<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] | 4250 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4251 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4252 | "<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] | 4253 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4254 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4255 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4256 | "</tr><tr>\n" |
| 4257 | "<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] | 4258 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4259 | "<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] | 4260 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4261 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4262 | "</td>" |
| 4263 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4264 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4265 | "", |
| 4266 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4267 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4268 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4269 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4270 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4271 | pid, relative_pid, global.nbproc, |
| 4272 | up / 86400, (up % 86400) / 3600, |
| 4273 | (up % 3600) / 60, (up % 60), |
| 4274 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4275 | global.rlimit_memmax ? " MB" : "", |
| 4276 | global.rlimit_nofile, |
| 4277 | global.maxsock, global.maxconn, global.maxpipes, |
| 4278 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4279 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4280 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4281 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4282 | /* 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] | 4283 | 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] | 4284 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4285 | |
| 4286 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4287 | "<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] | 4288 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4289 | STAT_SCOPE_TXT_MAXLEN); |
| 4290 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4291 | /* 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] | 4292 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4293 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4294 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4295 | 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] | 4296 | 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] | 4297 | } |
| 4298 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4299 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4300 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4301 | "<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] | 4302 | uri->uri_prefix, |
| 4303 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4304 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4305 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4306 | else |
| 4307 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4308 | "<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] | 4309 | uri->uri_prefix, |
| 4310 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4311 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4312 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4313 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4314 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4315 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4316 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4317 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4318 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4319 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4320 | "", |
| 4321 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4322 | else |
| 4323 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4324 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4325 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4326 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4327 | ";norefresh", |
| 4328 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4329 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4330 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4331 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4332 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4333 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4334 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4335 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4336 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4337 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4338 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4339 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4340 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4341 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4342 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4343 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4344 | chunk_appendf(&trash, |
| 4345 | "</ul></td>" |
| 4346 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4347 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4348 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4349 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4350 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4351 | "</ul>" |
| 4352 | "</td>" |
| 4353 | "</tr></table>\n" |
| 4354 | "" |
| 4355 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4356 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4357 | if (appctx->ctx.stats.st_code) { |
| 4358 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4359 | case STAT_STATUS_DONE: |
| 4360 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4361 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4362 | "<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] | 4363 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4364 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4365 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4366 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4367 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4368 | break; |
| 4369 | case STAT_STATUS_NONE: |
| 4370 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4371 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4372 | "<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] | 4373 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4374 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4375 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4376 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4377 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4378 | break; |
| 4379 | case STAT_STATUS_PART: |
| 4380 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4381 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4382 | "<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] | 4383 | "Action partially processed.<br>" |
| 4384 | "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] | 4385 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4386 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4387 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4388 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4389 | break; |
| 4390 | case STAT_STATUS_ERRP: |
| 4391 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4392 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4393 | "<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] | 4394 | "Action not processed because of invalid parameters." |
| 4395 | "<ul>" |
| 4396 | "<li>The action is maybe unknown.</li>" |
| 4397 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4398 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4399 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4400 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4401 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4402 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4403 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4404 | break; |
| 4405 | case STAT_STATUS_EXCD: |
| 4406 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4407 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4408 | "<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] | 4409 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4410 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4411 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4412 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4413 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4414 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4415 | break; |
| 4416 | case STAT_STATUS_DENY: |
| 4417 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4418 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4419 | "<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] | 4420 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4421 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4422 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4423 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4424 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4425 | break; |
| 4426 | default: |
| 4427 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4428 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4429 | "<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] | 4430 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4431 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4432 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4433 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4434 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4435 | } |
| 4436 | chunk_appendf(&trash, "<p>\n"); |
| 4437 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4438 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4439 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4440 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4441 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4442 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4443 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4444 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4445 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4446 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4447 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4448 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4449 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4450 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4451 | * 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] | 4452 | * 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] | 4453 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4454 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4455 | 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] | 4456 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4457 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4458 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4459 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4460 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4461 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4462 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4463 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4464 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4465 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4466 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4467 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4468 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4469 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4470 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4471 | else |
| 4472 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4473 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4474 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4475 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4476 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4477 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4478 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4479 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4480 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4481 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4482 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4483 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4484 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4485 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4486 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4487 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4488 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4489 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4490 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4491 | appctx->ctx.stats.px = proxy; |
| 4492 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4493 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4494 | /* fall through */ |
| 4495 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4496 | case STAT_ST_LIST: |
| 4497 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4498 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4499 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4500 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4501 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4502 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4503 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4504 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4505 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4506 | 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] | 4507 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4508 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4509 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4510 | appctx->ctx.stats.px = px->next; |
| 4511 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4512 | } |
| 4513 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4514 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4515 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4516 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4517 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4518 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4519 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4520 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4521 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4522 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4523 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4524 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4525 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4526 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4527 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4528 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4529 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4530 | case STAT_ST_FIN: |
| 4531 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4532 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4533 | default: |
| 4534 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4535 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4536 | return -1; |
| 4537 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4538 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4539 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4540 | /* We reached the stats page through a POST request. The appctx is |
| 4541 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4542 | * Parse the posted data and enable/disable servers if necessary. |
| 4543 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4544 | */ |
| 4545 | static int stats_process_http_post(struct stream_interface *si) |
| 4546 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4547 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4548 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4549 | |
| 4550 | struct proxy *px = NULL; |
| 4551 | struct server *sv = NULL; |
| 4552 | |
| 4553 | char key[LINESIZE]; |
| 4554 | int action = ST_ADM_ACTION_NONE; |
| 4555 | int reprocess = 0; |
| 4556 | |
| 4557 | int total_servers = 0; |
| 4558 | int altered_servers = 0; |
| 4559 | |
| 4560 | char *first_param, *cur_param, *next_param, *end_params; |
| 4561 | char *st_cur_param = NULL; |
| 4562 | char *st_next_param = NULL; |
| 4563 | |
| 4564 | struct chunk *temp; |
| 4565 | int reql; |
| 4566 | |
| 4567 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4568 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4569 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4570 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4571 | goto out; |
| 4572 | } |
| 4573 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4574 | 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] | 4575 | if (reql <= 0) { |
| 4576 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4577 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4578 | return 0; |
| 4579 | } |
| 4580 | |
| 4581 | first_param = temp->str; |
| 4582 | end_params = temp->str + reql; |
| 4583 | cur_param = next_param = end_params; |
| 4584 | *end_params = '\0'; |
| 4585 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4586 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4587 | |
| 4588 | /* |
| 4589 | * Parse the parameters in reverse order to only store the last value. |
| 4590 | * From the html form, the backend and the action are at the end. |
| 4591 | */ |
| 4592 | while (cur_param > first_param) { |
| 4593 | char *value; |
| 4594 | int poffset, plen; |
| 4595 | |
| 4596 | cur_param--; |
| 4597 | |
| 4598 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4599 | reprocess_servers: |
| 4600 | /* Parse the key */ |
| 4601 | poffset = (cur_param != first_param ? 1 : 0); |
| 4602 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4603 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4604 | strncpy(key, cur_param + poffset, plen); |
| 4605 | key[plen - 1] = '\0'; |
| 4606 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4607 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4608 | goto out; |
| 4609 | } |
| 4610 | |
| 4611 | /* Parse the value */ |
| 4612 | value = key; |
| 4613 | while (*value != '\0' && *value != '=') { |
| 4614 | value++; |
| 4615 | } |
| 4616 | if (*value == '=') { |
| 4617 | /* Ok, a value is found, we can mark the end of the key */ |
| 4618 | *value++ = '\0'; |
| 4619 | } |
| 4620 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4621 | break; |
| 4622 | |
| 4623 | /* Now we can check the key to see what to do */ |
| 4624 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 4625 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4626 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4627 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4628 | goto out; |
| 4629 | } |
| 4630 | } |
| 4631 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4632 | if (strcmp(value, "ready") == 0) { |
| 4633 | action = ST_ADM_ACTION_READY; |
| 4634 | } |
| 4635 | else if (strcmp(value, "drain") == 0) { |
| 4636 | action = ST_ADM_ACTION_DRAIN; |
| 4637 | } |
| 4638 | else if (strcmp(value, "maint") == 0) { |
| 4639 | action = ST_ADM_ACTION_MAINT; |
| 4640 | } |
| 4641 | else if (strcmp(value, "shutdown") == 0) { |
| 4642 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4643 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4644 | else if (strcmp(value, "dhlth") == 0) { |
| 4645 | action = ST_ADM_ACTION_DHLTH; |
| 4646 | } |
| 4647 | else if (strcmp(value, "ehlth") == 0) { |
| 4648 | action = ST_ADM_ACTION_EHLTH; |
| 4649 | } |
| 4650 | else if (strcmp(value, "hrunn") == 0) { |
| 4651 | action = ST_ADM_ACTION_HRUNN; |
| 4652 | } |
| 4653 | else if (strcmp(value, "hnolb") == 0) { |
| 4654 | action = ST_ADM_ACTION_HNOLB; |
| 4655 | } |
| 4656 | else if (strcmp(value, "hdown") == 0) { |
| 4657 | action = ST_ADM_ACTION_HDOWN; |
| 4658 | } |
| 4659 | else if (strcmp(value, "dagent") == 0) { |
| 4660 | action = ST_ADM_ACTION_DAGENT; |
| 4661 | } |
| 4662 | else if (strcmp(value, "eagent") == 0) { |
| 4663 | action = ST_ADM_ACTION_EAGENT; |
| 4664 | } |
| 4665 | else if (strcmp(value, "arunn") == 0) { |
| 4666 | action = ST_ADM_ACTION_ARUNN; |
| 4667 | } |
| 4668 | else if (strcmp(value, "adown") == 0) { |
| 4669 | action = ST_ADM_ACTION_ADOWN; |
| 4670 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4671 | /* else these are the old supported methods */ |
| 4672 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4673 | action = ST_ADM_ACTION_DISABLE; |
| 4674 | } |
| 4675 | else if (strcmp(value, "enable") == 0) { |
| 4676 | action = ST_ADM_ACTION_ENABLE; |
| 4677 | } |
| 4678 | else if (strcmp(value, "stop") == 0) { |
| 4679 | action = ST_ADM_ACTION_STOP; |
| 4680 | } |
| 4681 | else if (strcmp(value, "start") == 0) { |
| 4682 | action = ST_ADM_ACTION_START; |
| 4683 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4684 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4685 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4686 | goto out; |
| 4687 | } |
| 4688 | } |
| 4689 | else if (strcmp(key, "s") == 0) { |
| 4690 | if (!(px && action)) { |
| 4691 | /* |
| 4692 | * Indicates that we'll need to reprocess the parameters |
| 4693 | * as soon as backend and action are known |
| 4694 | */ |
| 4695 | if (!reprocess) { |
| 4696 | st_cur_param = cur_param; |
| 4697 | st_next_param = next_param; |
| 4698 | } |
| 4699 | reprocess = 1; |
| 4700 | } |
| 4701 | else if ((sv = findserver(px, value)) != NULL) { |
| 4702 | switch (action) { |
| 4703 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4704 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4705 | altered_servers++; |
| 4706 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4707 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4708 | } |
| 4709 | break; |
| 4710 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4711 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4712 | altered_servers++; |
| 4713 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4714 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4715 | } |
| 4716 | break; |
| 4717 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4718 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 4719 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4720 | altered_servers++; |
| 4721 | total_servers++; |
| 4722 | } |
| 4723 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4724 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4725 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 4726 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4727 | altered_servers++; |
| 4728 | total_servers++; |
| 4729 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4730 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4731 | case ST_ADM_ACTION_DHLTH: |
| 4732 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4733 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4734 | altered_servers++; |
| 4735 | total_servers++; |
| 4736 | } |
| 4737 | break; |
| 4738 | case ST_ADM_ACTION_EHLTH: |
| 4739 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4740 | sv->check.state |= CHK_ST_ENABLED; |
| 4741 | altered_servers++; |
| 4742 | total_servers++; |
| 4743 | } |
| 4744 | break; |
| 4745 | case ST_ADM_ACTION_HRUNN: |
| 4746 | if (!(sv->track)) { |
| 4747 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4748 | srv_set_running(sv, "changed from Web interface"); |
| 4749 | altered_servers++; |
| 4750 | total_servers++; |
| 4751 | } |
| 4752 | break; |
| 4753 | case ST_ADM_ACTION_HNOLB: |
| 4754 | if (!(sv->track)) { |
| 4755 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4756 | srv_set_stopping(sv, "changed from Web interface"); |
| 4757 | altered_servers++; |
| 4758 | total_servers++; |
| 4759 | } |
| 4760 | break; |
| 4761 | case ST_ADM_ACTION_HDOWN: |
| 4762 | if (!(sv->track)) { |
| 4763 | sv->check.health = 0; |
| 4764 | srv_set_stopped(sv, "changed from Web interface"); |
| 4765 | altered_servers++; |
| 4766 | total_servers++; |
| 4767 | } |
| 4768 | break; |
| 4769 | case ST_ADM_ACTION_DAGENT: |
| 4770 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4771 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4772 | altered_servers++; |
| 4773 | total_servers++; |
| 4774 | } |
| 4775 | break; |
| 4776 | case ST_ADM_ACTION_EAGENT: |
| 4777 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4778 | sv->agent.state |= CHK_ST_ENABLED; |
| 4779 | altered_servers++; |
| 4780 | total_servers++; |
| 4781 | } |
| 4782 | break; |
| 4783 | case ST_ADM_ACTION_ARUNN: |
| 4784 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4785 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 4786 | srv_set_running(sv, "changed from Web interface"); |
| 4787 | altered_servers++; |
| 4788 | total_servers++; |
| 4789 | } |
| 4790 | break; |
| 4791 | case ST_ADM_ACTION_ADOWN: |
| 4792 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4793 | sv->agent.health = 0; |
| 4794 | srv_set_stopped(sv, "changed from Web interface"); |
| 4795 | altered_servers++; |
| 4796 | total_servers++; |
| 4797 | } |
| 4798 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4799 | case ST_ADM_ACTION_READY: |
| 4800 | srv_adm_set_ready(sv); |
| 4801 | altered_servers++; |
| 4802 | total_servers++; |
| 4803 | break; |
| 4804 | case ST_ADM_ACTION_DRAIN: |
| 4805 | srv_adm_set_drain(sv); |
| 4806 | altered_servers++; |
| 4807 | total_servers++; |
| 4808 | break; |
| 4809 | case ST_ADM_ACTION_MAINT: |
| 4810 | srv_adm_set_maint(sv); |
| 4811 | altered_servers++; |
| 4812 | total_servers++; |
| 4813 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4814 | case ST_ADM_ACTION_SHUTDOWN: |
| 4815 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4816 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4817 | |
| 4818 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4819 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 4820 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4821 | |
| 4822 | altered_servers++; |
| 4823 | total_servers++; |
| 4824 | } |
| 4825 | break; |
| 4826 | } |
| 4827 | } else { |
| 4828 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4829 | total_servers++; |
| 4830 | } |
| 4831 | } |
| 4832 | if (reprocess && px && action) { |
| 4833 | /* Now, we know the backend and the action chosen by the user. |
| 4834 | * We can safely restart from the first server parameter |
| 4835 | * to reprocess them |
| 4836 | */ |
| 4837 | cur_param = st_cur_param; |
| 4838 | next_param = st_next_param; |
| 4839 | reprocess = 0; |
| 4840 | goto reprocess_servers; |
| 4841 | } |
| 4842 | |
| 4843 | next_param = cur_param; |
| 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4848 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4849 | } |
| 4850 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4851 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4852 | } |
| 4853 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4854 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4855 | } |
| 4856 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4857 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4858 | } |
| 4859 | out: |
| 4860 | return 1; |
| 4861 | } |
| 4862 | |
| 4863 | |
| 4864 | static int stats_send_http_headers(struct stream_interface *si) |
| 4865 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4866 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4867 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4868 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4869 | |
| 4870 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4871 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4872 | "Cache-Control: no-cache\r\n" |
| 4873 | "Connection: close\r\n" |
| 4874 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4875 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4876 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4877 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4878 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4879 | uri->refresh); |
| 4880 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4881 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4882 | |
| 4883 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4884 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4885 | else |
| 4886 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4887 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4888 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4889 | s->logs.tv_request = now; |
| 4890 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4891 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4892 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4893 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4894 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4895 | |
| 4896 | return 1; |
| 4897 | } |
| 4898 | |
| 4899 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4900 | { |
| 4901 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4902 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4903 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4904 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4905 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4906 | /* 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] | 4907 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4908 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4909 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4910 | 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] | 4911 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | /* We don't want to land on the posted stats page because a refresh will |
| 4915 | * repost the data. We don't want this to happen on accident so we redirect |
| 4916 | * the browse to the stats page with a GET. |
| 4917 | */ |
| 4918 | chunk_printf(&trash, |
| 4919 | "HTTP/1.1 303 See Other\r\n" |
| 4920 | "Cache-Control: no-cache\r\n" |
| 4921 | "Content-Type: text/plain\r\n" |
| 4922 | "Connection: close\r\n" |
| 4923 | "Location: %s;st=%s%s%s%s\r\n" |
| 4924 | "\r\n", |
| 4925 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4926 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4927 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4928 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4929 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4930 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4931 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4932 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4933 | scope_txt); |
| 4934 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4935 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4936 | s->logs.tv_request = now; |
| 4937 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4938 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4939 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4940 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4941 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4942 | |
| 4943 | return 1; |
| 4944 | } |
| 4945 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4946 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4947 | * 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] | 4948 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4949 | * automatically unregisters itself once transfer is complete. |
| 4950 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 4951 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4952 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 4953 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4954 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4955 | struct channel *req = si_oc(si); |
| 4956 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4957 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4958 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4959 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4960 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4961 | /* check that the output is not closed */ |
| 4962 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4963 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4964 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4965 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4966 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4967 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4968 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4969 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4970 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4971 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4972 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4973 | } |
| 4974 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4975 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4976 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4977 | unsigned int data_len; |
| 4978 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 4979 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4980 | |
| 4981 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 4982 | /* One difficulty we're facing is that we must prevent |
| 4983 | * the input data from being automatically forwarded to |
| 4984 | * the output area. For this, we temporarily disable |
| 4985 | * forwarding on the channel. |
| 4986 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4987 | last_fwd = si_ic(si)->to_forward; |
| 4988 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4989 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4990 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4991 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4992 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 4993 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4994 | } |
| 4995 | } |
| 4996 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4997 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4998 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4999 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5000 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5001 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5002 | |
| 5003 | /* Now we must either adjust or remove the chunk size. This is |
| 5004 | * not easy because the chunk size might wrap at the end of the |
| 5005 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5006 | * the size, then restore the buffer's contents. Note that we can |
| 5007 | * only do that because no forwarding is scheduled on the stats |
| 5008 | * applet. |
| 5009 | */ |
| 5010 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5011 | si_ic(si)->total -= (last_len - prev_len); |
| 5012 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5013 | |
| 5014 | if (last_len != data_len) { |
| 5015 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5016 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5017 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5018 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5019 | si_ic(si)->total += (last_len - data_len); |
| 5020 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5021 | } |
| 5022 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5023 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5024 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5025 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5026 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5027 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5028 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5029 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5030 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5031 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5032 | } |
| 5033 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5034 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5035 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5036 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5037 | } |
| 5038 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5039 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5040 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5041 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5042 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5043 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5044 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5045 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5046 | } |
| 5047 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5048 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5049 | res->flags |= CF_READ_NULL; |
| 5050 | si_shutr(si); |
| 5051 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5052 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5053 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5054 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5055 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5056 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5057 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5058 | si_shutr(si); |
| 5059 | res->flags |= CF_READ_NULL; |
| 5060 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5061 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5062 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5063 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5064 | } |
| 5065 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5066 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5067 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5068 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5069 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5070 | return "NONE"; |
| 5071 | return conn->ctrl->name; |
| 5072 | } |
| 5073 | |
| 5074 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5075 | { |
| 5076 | static char ptr[17]; |
| 5077 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5078 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5079 | return "NONE"; |
| 5080 | |
| 5081 | if (conn->xprt == &raw_sock) |
| 5082 | return "RAW"; |
| 5083 | |
| 5084 | #ifdef USE_OPENSSL |
| 5085 | if (conn->xprt == &ssl_sock) |
| 5086 | return "SSL"; |
| 5087 | #endif |
| 5088 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5089 | return ptr; |
| 5090 | } |
| 5091 | |
| 5092 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5093 | { |
| 5094 | static char ptr[17]; |
| 5095 | |
| 5096 | if (!conn->data) |
| 5097 | return "NONE"; |
| 5098 | |
| 5099 | if (conn->data == &sess_conn_cb) |
| 5100 | return "SESS"; |
| 5101 | |
| 5102 | if (conn->data == &si_conn_cb) |
| 5103 | return "STRM"; |
| 5104 | |
| 5105 | if (conn->data == &check_conn_cb) |
| 5106 | return "CHCK"; |
| 5107 | |
| 5108 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5109 | return ptr; |
| 5110 | } |
| 5111 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5112 | /* This function dumps a complete stream state onto the stream interface's |
| 5113 | * 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] | 5114 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5115 | * 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] | 5116 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5117 | 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] | 5118 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5119 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5120 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5121 | extern const char *monthname[12]; |
| 5122 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5123 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5124 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5125 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5126 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5127 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5128 | 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] | 5129 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5130 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5131 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5132 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5133 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5134 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5135 | appctx->ctx.sess.uid = 0; |
| 5136 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5137 | return 1; |
| 5138 | } |
| 5139 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5140 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5141 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5142 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5143 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5144 | /* fall through */ |
| 5145 | |
| 5146 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5147 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5148 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5149 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5150 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5151 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5152 | 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] | 5153 | sess->uniq_id, |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5154 | 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] | 5155 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5156 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5157 | 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] | 5158 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5159 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5160 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5161 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5162 | break; |
| 5163 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5164 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5165 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5166 | default: |
| 5167 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5168 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5169 | break; |
| 5170 | } |
| 5171 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5172 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5173 | " 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] | 5174 | 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] | 5175 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5176 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5177 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5178 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5179 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5180 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5181 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5182 | if (conn) |
| 5183 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5184 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5185 | 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] | 5186 | case AF_INET: |
| 5187 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5188 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5189 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5190 | break; |
| 5191 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5192 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5193 | break; |
| 5194 | default: |
| 5195 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5196 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5197 | break; |
| 5198 | } |
| 5199 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5200 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5201 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5202 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5203 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5204 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5205 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5206 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5207 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5208 | conn = objt_conn(sess->si[1].end); |
| 5209 | if (conn) |
| 5210 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5211 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5212 | 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] | 5213 | case AF_INET: |
| 5214 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5215 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5216 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5217 | break; |
| 5218 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5219 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5220 | break; |
| 5221 | default: |
| 5222 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5223 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5224 | break; |
| 5225 | } |
| 5226 | |
| 5227 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5228 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5229 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5230 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5231 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5232 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5233 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5234 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5235 | if (conn) |
| 5236 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5237 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5238 | 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] | 5239 | case AF_INET: |
| 5240 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5241 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5242 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5243 | break; |
| 5244 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5245 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5246 | break; |
| 5247 | default: |
| 5248 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5249 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5250 | break; |
| 5251 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5252 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5253 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5254 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5255 | sess->task, |
| 5256 | sess->task->state, |
| 5257 | sess->task->nice, sess->task->calls, |
| 5258 | sess->task->expire ? |
| 5259 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5260 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5261 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5262 | task_in_rq(sess->task) ? ", running" : ""); |
| 5263 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5264 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5265 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5266 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5267 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5268 | if (sess->txn) |
| 5269 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5270 | " 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] | 5271 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5272 | 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] | 5273 | |
| 5274 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5275 | " 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] | 5276 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5277 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5278 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5279 | obj_type_name(sess->si[0].end), |
| 5280 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5281 | sess->si[0].exp ? |
| 5282 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5283 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5284 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5285 | sess->si[0].err_type); |
| 5286 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5287 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5288 | " 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] | 5289 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5290 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5291 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5292 | obj_type_name(sess->si[1].end), |
| 5293 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5294 | sess->si[1].exp ? |
| 5295 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5296 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5297 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5298 | sess->si[1].err_type); |
| 5299 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5300 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5301 | chunk_appendf(&trash, |
| 5302 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5303 | conn, |
| 5304 | get_conn_ctrl_name(conn), |
| 5305 | get_conn_xprt_name(conn), |
| 5306 | get_conn_data_name(conn), |
| 5307 | obj_type_name(conn->target), |
| 5308 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5309 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5310 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5311 | " 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] | 5312 | conn->flags, |
| 5313 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5314 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5315 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5316 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5317 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5318 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5319 | chunk_appendf(&trash, |
| 5320 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5321 | tmpctx, |
| 5322 | tmpctx->st0, |
| 5323 | tmpctx->st1, |
| 5324 | tmpctx->st2, |
| 5325 | tmpctx->applet->name); |
| 5326 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5327 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5328 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5329 | chunk_appendf(&trash, |
| 5330 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5331 | conn, |
| 5332 | get_conn_ctrl_name(conn), |
| 5333 | get_conn_xprt_name(conn), |
| 5334 | get_conn_data_name(conn), |
| 5335 | obj_type_name(conn->target), |
| 5336 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5337 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5338 | chunk_appendf(&trash, |
| 5339 | " 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] | 5340 | conn->flags, |
| 5341 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5342 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5343 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5344 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5345 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5346 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5347 | chunk_appendf(&trash, |
| 5348 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5349 | tmpctx, |
| 5350 | tmpctx->st0, |
| 5351 | tmpctx->st1, |
| 5352 | tmpctx->st2, |
| 5353 | tmpctx->applet->name); |
| 5354 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5355 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5356 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5357 | " 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] | 5358 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5359 | &sess->req, |
| 5360 | sess->req.flags, sess->req.analysers, |
| 5361 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5362 | sess->req.to_forward, sess->req.total, |
| 5363 | sess->req.analyse_exp ? |
| 5364 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5365 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5366 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5367 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5368 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5369 | sess->req.rex ? |
| 5370 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5371 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5372 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5373 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5374 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5375 | " 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] | 5376 | sess->req.wex ? |
| 5377 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5378 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5379 | sess->req.buf, |
| 5380 | sess->req.buf->data, sess->req.buf->o, |
| 5381 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5382 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5383 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5384 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5385 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5386 | " 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] | 5387 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5388 | &sess->res, |
| 5389 | sess->res.flags, sess->res.analysers, |
| 5390 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5391 | sess->res.to_forward, sess->res.total, |
| 5392 | sess->res.analyse_exp ? |
| 5393 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5394 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5395 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5396 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5397 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5398 | sess->res.rex ? |
| 5399 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5400 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5401 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5402 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5403 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5404 | " 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] | 5405 | sess->res.wex ? |
| 5406 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5407 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5408 | sess->res.buf, |
| 5409 | sess->res.buf->data, sess->res.buf->o, |
| 5410 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5411 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5412 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5413 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5414 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5415 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5416 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5417 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5418 | |
| 5419 | /* use other states to dump the contents */ |
| 5420 | } |
| 5421 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5422 | appctx->ctx.sess.uid = 0; |
| 5423 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5424 | return 1; |
| 5425 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5426 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 5427 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 5428 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 5429 | struct appctx *appctx = __objt_appctx(si->end); |
| 5430 | |
| 5431 | switch (appctx->st2) { |
| 5432 | case STAT_ST_INIT: |
| 5433 | /* Display the column headers. If the message cannot be sent, |
| 5434 | * quit the fucntion with returning 0. The function is called |
| 5435 | * later and restart at the state "STAT_ST_INIT". |
| 5436 | */ |
| 5437 | chunk_reset(&trash); |
| 5438 | chunk_appendf(&trash, "# id (file)\n"); |
| 5439 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5440 | si_applet_cant_put(si); |
| 5441 | return 0; |
| 5442 | } |
| 5443 | |
| 5444 | /* Now, we start the browsing of the references lists. |
| 5445 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5446 | * avalaible field of this pointer is <list>. It is used with the function |
| 5447 | * tlskeys_list_get_next() for retruning the first avalaible entry |
| 5448 | */ |
| 5449 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 5450 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 5451 | |
| 5452 | appctx->st2 = STAT_ST_LIST; |
| 5453 | /* fall through */ |
| 5454 | |
| 5455 | case STAT_ST_LIST: |
| 5456 | while (appctx->ctx.tlskeys.ref) { |
| 5457 | chunk_reset(&trash); |
| 5458 | |
| 5459 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 5460 | appctx->ctx.tlskeys.ref->filename); |
| 5461 | |
| 5462 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5463 | /* let's try again later from this stream. We add ourselves into |
| 5464 | * this stream's users so that it can remove us upon termination. |
| 5465 | */ |
| 5466 | si_applet_cant_put(si); |
| 5467 | return 0; |
| 5468 | } |
| 5469 | |
| 5470 | /* get next list entry and check the end of the list */ |
| 5471 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 5472 | } |
| 5473 | |
| 5474 | appctx->st2 = STAT_ST_FIN; |
| 5475 | /* fall through */ |
| 5476 | |
| 5477 | default: |
| 5478 | appctx->st2 = STAT_ST_FIN; |
| 5479 | return 1; |
| 5480 | } |
| 5481 | return 0; |
| 5482 | } |
| 5483 | #endif |
| 5484 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5485 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5486 | { |
| 5487 | struct appctx *appctx = __objt_appctx(si->end); |
| 5488 | |
| 5489 | switch (appctx->st2) { |
| 5490 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5491 | /* Display the column headers. If the message cannot be sent, |
| 5492 | * quit the fucntion with returning 0. The function is called |
| 5493 | * later and restart at the state "STAT_ST_INIT". |
| 5494 | */ |
| 5495 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5496 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5497 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5498 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5499 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5500 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5501 | |
| 5502 | /* Now, we start the browsing of the references lists. |
| 5503 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5504 | * avalaible field of this pointer is <list>. It is used with the function |
| 5505 | * pat_list_get_next() for retruning the first avalaible entry |
| 5506 | */ |
| 5507 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5508 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5509 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5510 | appctx->st2 = STAT_ST_LIST; |
| 5511 | /* fall through */ |
| 5512 | |
| 5513 | case STAT_ST_LIST: |
| 5514 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5515 | chunk_reset(&trash); |
| 5516 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5517 | /* Build messages. If the reference is used by another category than |
| 5518 | * the listed categorie, display the information in the massage. |
| 5519 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5520 | 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] | 5521 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5522 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5523 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5524 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5525 | /* let's try again later from this stream. We add ourselves into |
| 5526 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5527 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5528 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5529 | return 0; |
| 5530 | } |
| 5531 | |
| 5532 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5533 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5534 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | appctx->st2 = STAT_ST_FIN; |
| 5538 | /* fall through */ |
| 5539 | |
| 5540 | default: |
| 5541 | appctx->st2 = STAT_ST_FIN; |
| 5542 | return 1; |
| 5543 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5544 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5545 | } |
| 5546 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5547 | static int stats_map_lookup(struct stream_interface *si) |
| 5548 | { |
| 5549 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5550 | struct sample sample; |
| 5551 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5552 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5553 | |
| 5554 | switch (appctx->st2) { |
| 5555 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5556 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5557 | 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] | 5558 | 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] | 5559 | appctx->st2 = STAT_ST_LIST; |
| 5560 | /* fall through */ |
| 5561 | |
| 5562 | case STAT_ST_LIST: |
| 5563 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5564 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5565 | /* initialise chunk to build new message */ |
| 5566 | chunk_reset(&trash); |
| 5567 | |
| 5568 | /* execute pattern matching */ |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 5569 | sample.type = SMP_T_STR; |
| 5570 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5571 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 5572 | sample.data.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5573 | if (appctx->ctx.map.expr->pat_head->match && |
| 5574 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5575 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5576 | else |
| 5577 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5578 | |
| 5579 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5580 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5581 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5582 | break; |
| 5583 | if (match_method >= PAT_MATCH_NUM) |
| 5584 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5585 | else |
| 5586 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5587 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5588 | /* case sensitive */ |
| 5589 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5590 | chunk_appendf(&trash, ", case=insensitive"); |
| 5591 | else |
| 5592 | chunk_appendf(&trash, ", case=sensitive"); |
| 5593 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5594 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5595 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5596 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5597 | chunk_appendf(&trash, ", found=no"); |
| 5598 | else |
| 5599 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5600 | } |
| 5601 | |
| 5602 | /* Display match and match info */ |
| 5603 | else { |
| 5604 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5605 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5606 | chunk_appendf(&trash, ", found=yes"); |
| 5607 | else |
| 5608 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5609 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5610 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5611 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5612 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5613 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5614 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5615 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5616 | /* display pattern */ |
| 5617 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5618 | if (pat->ref && pat->ref->pattern) |
| 5619 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5620 | else |
| 5621 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5622 | } |
| 5623 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5624 | if (pat->ref && pat->ref->pattern) |
| 5625 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5626 | else |
| 5627 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5628 | } |
| 5629 | |
| 5630 | /* display return value */ |
| 5631 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5632 | if (pat->smp && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5633 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5634 | pat->ref->sample, smp_to_type[pat->smp->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5635 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5636 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5637 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5638 | } |
| 5639 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5640 | chunk_appendf(&trash, "\n"); |
| 5641 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5642 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5643 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5644 | /* let's try again later from this stream. We add ourselves into |
| 5645 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5646 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5647 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5648 | return 0; |
| 5649 | } |
| 5650 | |
| 5651 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5652 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5653 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5654 | } |
| 5655 | |
| 5656 | appctx->st2 = STAT_ST_FIN; |
| 5657 | /* fall through */ |
| 5658 | |
| 5659 | default: |
| 5660 | appctx->st2 = STAT_ST_FIN; |
| 5661 | free(appctx->ctx.map.chunk.str); |
| 5662 | return 1; |
| 5663 | } |
| 5664 | } |
| 5665 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5666 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5667 | { |
| 5668 | struct appctx *appctx = __objt_appctx(si->end); |
| 5669 | |
| 5670 | switch (appctx->st2) { |
| 5671 | |
| 5672 | case STAT_ST_INIT: |
| 5673 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5674 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5675 | struct pat_ref_elt *, list); |
| 5676 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5677 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5678 | appctx->st2 = STAT_ST_LIST; |
| 5679 | /* fall through */ |
| 5680 | |
| 5681 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5682 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5683 | chunk_reset(&trash); |
| 5684 | |
| 5685 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5686 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5687 | chunk_appendf(&trash, "%p %s %s\n", |
| 5688 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5689 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5690 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5691 | chunk_appendf(&trash, "%p %s\n", |
| 5692 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5693 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5694 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5695 | /* let's try again later from this stream. We add ourselves into |
| 5696 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5697 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5698 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5699 | return 0; |
| 5700 | } |
| 5701 | |
| 5702 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5703 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5704 | struct pat_ref_elt *, list); |
| 5705 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5706 | break; |
| 5707 | } |
| 5708 | |
| 5709 | appctx->st2 = STAT_ST_FIN; |
| 5710 | /* fall through */ |
| 5711 | |
| 5712 | default: |
| 5713 | appctx->st2 = STAT_ST_FIN; |
| 5714 | return 1; |
| 5715 | } |
| 5716 | } |
| 5717 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5718 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5719 | * 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] | 5720 | * to be called again, otherwise non-zero. It is designed to be called |
| 5721 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5722 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5723 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5724 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5725 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5726 | struct connection *conn; |
| 5727 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5728 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5729 | /* 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] | 5730 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5731 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5732 | if (appctx->st2 == STAT_ST_LIST) { |
| 5733 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5734 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5735 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5736 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5737 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5738 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5739 | } |
| 5740 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5741 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5742 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5743 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5744 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5745 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5746 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5747 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5748 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5749 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5750 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5751 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5752 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5753 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5754 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5755 | /* fall through */ |
| 5756 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5757 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5758 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5759 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5760 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5761 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5762 | } |
| 5763 | |
| 5764 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5765 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5766 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5767 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5768 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5769 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5770 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5771 | if (appctx->ctx.sess.target) { |
| 5772 | 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] | 5773 | goto next_sess; |
| 5774 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5775 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5776 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5777 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5778 | return 0; |
| 5779 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5780 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5781 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5782 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5783 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5784 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5785 | break; |
| 5786 | } |
| 5787 | else |
| 5788 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5789 | } |
| 5790 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5791 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5792 | "%p: proto=%s", |
| 5793 | curr_sess, |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5794 | strm_li(curr_sess)->proto->name); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5795 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5796 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5797 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5798 | 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] | 5799 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5800 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5801 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5802 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5803 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5804 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5805 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5806 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5807 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5808 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5809 | break; |
| 5810 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5811 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5812 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5813 | strm_li(curr_sess)->luid, |
| 5814 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5815 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5816 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5817 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5818 | break; |
| 5819 | } |
| 5820 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5821 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5822 | " ts=%02x age=%s calls=%d", |
| 5823 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5824 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5825 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5826 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5827 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5828 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5829 | curr_sess->req.flags, |
| 5830 | curr_sess->req.buf->i, |
| 5831 | curr_sess->req.analysers, |
| 5832 | curr_sess->req.rex ? |
| 5833 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5834 | TICKS_TO_MS(1000)) : ""); |
| 5835 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5836 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5837 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5838 | curr_sess->req.wex ? |
| 5839 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5840 | TICKS_TO_MS(1000)) : ""); |
| 5841 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5842 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5843 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5844 | curr_sess->req.analyse_exp ? |
| 5845 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5846 | TICKS_TO_MS(1000)) : ""); |
| 5847 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5848 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5849 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5850 | curr_sess->res.flags, |
| 5851 | curr_sess->res.buf->i, |
| 5852 | curr_sess->res.analysers, |
| 5853 | curr_sess->res.rex ? |
| 5854 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5855 | TICKS_TO_MS(1000)) : ""); |
| 5856 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5857 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5858 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5859 | curr_sess->res.wex ? |
| 5860 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5861 | TICKS_TO_MS(1000)) : ""); |
| 5862 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5863 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5864 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5865 | curr_sess->res.analyse_exp ? |
| 5866 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5867 | TICKS_TO_MS(1000)) : ""); |
| 5868 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5869 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5870 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5871 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5872 | curr_sess->si[0].state, |
| 5873 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5874 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5875 | curr_sess->si[0].exp ? |
| 5876 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5877 | TICKS_TO_MS(1000)) : ""); |
| 5878 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5879 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5880 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5881 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5882 | curr_sess->si[1].state, |
| 5883 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5884 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5885 | curr_sess->si[1].exp ? |
| 5886 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5887 | TICKS_TO_MS(1000)) : ""); |
| 5888 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5889 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5890 | " exp=%s", |
| 5891 | curr_sess->task->expire ? |
| 5892 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5893 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5894 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5895 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5896 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5897 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5898 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5899 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5900 | /* let's try again later from this stream. We add ourselves into |
| 5901 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5902 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5903 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5904 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5905 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5906 | } |
| 5907 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5908 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5909 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5910 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5911 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5912 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5913 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5914 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5915 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5916 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5917 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5918 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5919 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5920 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5921 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5922 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5923 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5924 | appctx->ctx.sess.target = NULL; |
| 5925 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5926 | return 1; |
| 5927 | } |
| 5928 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5929 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5930 | /* fall through */ |
| 5931 | |
| 5932 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5933 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5934 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5935 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5936 | } |
| 5937 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5938 | /* This is called when the stream interface is closed. For instance, upon an |
| 5939 | * 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] | 5940 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5941 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5942 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5943 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5944 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5945 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5946 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5947 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 5948 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 5949 | free(appctx->ctx.cli.err); |
| 5950 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5951 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 5952 | free(appctx->ctx.map.chunk.str); |
| 5953 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5954 | } |
| 5955 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5956 | /* This function is used to either dump tables states (when action is set |
| 5957 | * 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] | 5958 | * It returns 0 if the output buffer is full and it needs to be called |
| 5959 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5960 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5961 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5962 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5963 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5964 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5965 | struct ebmb_node *eb; |
| 5966 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5967 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5968 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5969 | |
| 5970 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5971 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5972 | * - STAT_ST_INIT : the first call |
| 5973 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5974 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5975 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5976 | * and the entry pointer points to the next entry to be dumped, |
| 5977 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5978 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5979 | * data though. |
| 5980 | */ |
| 5981 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5982 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5983 | /* 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] | 5984 | if (appctx->st2 == STAT_ST_LIST) { |
| 5985 | appctx->ctx.table.entry->ref_cnt--; |
| 5986 | 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] | 5987 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5988 | return 1; |
| 5989 | } |
| 5990 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5991 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5992 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5993 | while (appctx->st2 != STAT_ST_FIN) { |
| 5994 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5995 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5996 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5997 | if (!appctx->ctx.table.proxy) |
| 5998 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5999 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6000 | appctx->ctx.table.entry = NULL; |
| 6001 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6002 | break; |
| 6003 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6004 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6005 | if (!appctx->ctx.table.proxy || |
| 6006 | (appctx->ctx.table.target && |
| 6007 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6008 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6009 | break; |
| 6010 | } |
| 6011 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6012 | if (appctx->ctx.table.proxy->table.size) { |
| 6013 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6014 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6015 | return 0; |
| 6016 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6017 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6018 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6019 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6020 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6021 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6022 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6023 | appctx->ctx.table.entry->ref_cnt++; |
| 6024 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6025 | break; |
| 6026 | } |
| 6027 | } |
| 6028 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6029 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6030 | break; |
| 6031 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6032 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6033 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6034 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6035 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6036 | /* we're filtering on some data contents */ |
| 6037 | void *ptr; |
| 6038 | long long data; |
| 6039 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6040 | dt = appctx->ctx.table.data_type; |
| 6041 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6042 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6043 | dt); |
| 6044 | |
| 6045 | data = 0; |
| 6046 | switch (stktable_data_types[dt].std_type) { |
| 6047 | case STD_T_SINT: |
| 6048 | data = stktable_data_cast(ptr, std_t_sint); |
| 6049 | break; |
| 6050 | case STD_T_UINT: |
| 6051 | data = stktable_data_cast(ptr, std_t_uint); |
| 6052 | break; |
| 6053 | case STD_T_ULL: |
| 6054 | data = stktable_data_cast(ptr, std_t_ull); |
| 6055 | break; |
| 6056 | case STD_T_FRQP: |
| 6057 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6058 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6059 | break; |
| 6060 | } |
| 6061 | |
| 6062 | /* 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] | 6063 | if ((data < appctx->ctx.table.value && |
| 6064 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6065 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6066 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6067 | (data == appctx->ctx.table.value && |
| 6068 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6069 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6070 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6071 | (data > appctx->ctx.table.value && |
| 6072 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6073 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6074 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6075 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6076 | } |
| 6077 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6078 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6079 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6080 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6081 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6082 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6083 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6084 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6085 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6086 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6087 | struct stksess *old = appctx->ctx.table.entry; |
| 6088 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6089 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6090 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6091 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6092 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6093 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6094 | break; |
| 6095 | } |
| 6096 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6097 | |
| 6098 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6099 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6100 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6101 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6102 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6103 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6104 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6105 | break; |
| 6106 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6107 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6108 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6109 | break; |
| 6110 | } |
| 6111 | } |
| 6112 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6113 | } |
| 6114 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6115 | /* 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] | 6116 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6117 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6118 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6119 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6120 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6121 | * after the offset. The new pointer is returned. |
| 6122 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6123 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6124 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6125 | { |
| 6126 | int end; |
| 6127 | unsigned char c; |
| 6128 | |
| 6129 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6130 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6131 | return ptr; |
| 6132 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6133 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6134 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6135 | while (ptr < len && ptr < bsize) { |
| 6136 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6137 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6138 | if (out->len > end - 2) |
| 6139 | break; |
| 6140 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6141 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6142 | if (out->len > end - 3) |
| 6143 | break; |
| 6144 | out->str[out->len++] = '\\'; |
| 6145 | switch (c) { |
| 6146 | case '\t': c = 't'; break; |
| 6147 | case '\n': c = 'n'; break; |
| 6148 | case '\r': c = 'r'; break; |
| 6149 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6150 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6151 | } |
| 6152 | out->str[out->len++] = c; |
| 6153 | } else { |
| 6154 | if (out->len > end - 5) |
| 6155 | break; |
| 6156 | out->str[out->len++] = '\\'; |
| 6157 | out->str[out->len++] = 'x'; |
| 6158 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6159 | out->str[out->len++] = hextab[c & 0xF]; |
| 6160 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6161 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6162 | /* we had a line break, let's return now */ |
| 6163 | out->str[out->len++] = '\n'; |
| 6164 | *line = ptr; |
| 6165 | return ptr; |
| 6166 | } |
| 6167 | } |
| 6168 | /* we have an incomplete line, we return it as-is */ |
| 6169 | out->str[out->len++] = '\n'; |
| 6170 | return ptr; |
| 6171 | } |
| 6172 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6173 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6174 | * 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] | 6175 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6176 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6177 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6178 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6179 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6180 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6181 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6182 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6183 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6184 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6185 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6186 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6187 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6188 | /* the function had not been called yet, let's prepare the |
| 6189 | * buffer for a response. |
| 6190 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6191 | struct tm tm; |
| 6192 | |
| 6193 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6194 | 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] | 6195 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6196 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6197 | error_snapshot_id); |
| 6198 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6199 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6200 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6201 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6202 | return 0; |
| 6203 | } |
| 6204 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6205 | appctx->ctx.errors.px = proxy; |
| 6206 | appctx->ctx.errors.buf = 0; |
| 6207 | appctx->ctx.errors.bol = 0; |
| 6208 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6209 | } |
| 6210 | |
| 6211 | /* we have two inner loops here, one for the proxy, the other one for |
| 6212 | * the buffer. |
| 6213 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6214 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6215 | struct error_snapshot *es; |
| 6216 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6217 | if (appctx->ctx.errors.buf == 0) |
| 6218 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6219 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6220 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6221 | |
| 6222 | if (!es->when.tv_sec) |
| 6223 | goto next; |
| 6224 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6225 | if (appctx->ctx.errors.iid >= 0 && |
| 6226 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6227 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6228 | goto next; |
| 6229 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6230 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6231 | /* just print headers now */ |
| 6232 | |
| 6233 | char pn[INET6_ADDRSTRLEN]; |
| 6234 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6235 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6236 | |
| 6237 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6238 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6239 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6240 | 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] | 6241 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6242 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6243 | case AF_INET: |
| 6244 | case AF_INET6: |
| 6245 | port = get_host_port(&es->src); |
| 6246 | break; |
| 6247 | default: |
| 6248 | port = 0; |
| 6249 | } |
| 6250 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6251 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6252 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6253 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6254 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6255 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6256 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6257 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6258 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6259 | break; |
| 6260 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6261 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6262 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6263 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6264 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6265 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6266 | break; |
| 6267 | } |
| 6268 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6269 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6270 | ", server %s (#%d), event #%u\n" |
| 6271 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6272 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6273 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6274 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6275 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6276 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6277 | es->ev_id, |
| 6278 | pn, port, es->sid, es->s_flags, |
| 6279 | es->state, es->m_flags, es->t_flags, |
| 6280 | es->m_clen, es->m_blen, |
| 6281 | es->b_flags, es->b_out, es->b_tot, |
| 6282 | es->len, es->b_wrap, es->pos); |
| 6283 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6284 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6285 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6286 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6287 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6288 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6289 | appctx->ctx.errors.ptr = 0; |
| 6290 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6291 | } |
| 6292 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6293 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6294 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6295 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6296 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6297 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6298 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6299 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6300 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6301 | goto next; |
| 6302 | } |
| 6303 | |
| 6304 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6305 | 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] | 6306 | int newptr; |
| 6307 | int newline; |
| 6308 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6309 | newline = appctx->ctx.errors.bol; |
| 6310 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6311 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6312 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6313 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6314 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6315 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6316 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6317 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6318 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6319 | appctx->ctx.errors.ptr = newptr; |
| 6320 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6321 | }; |
| 6322 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6323 | appctx->ctx.errors.bol = 0; |
| 6324 | appctx->ctx.errors.ptr = -1; |
| 6325 | appctx->ctx.errors.buf++; |
| 6326 | if (appctx->ctx.errors.buf > 1) { |
| 6327 | appctx->ctx.errors.buf = 0; |
| 6328 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6333 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6334 | } |
| 6335 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6336 | /* parse the "level" argument on the bind lines */ |
| 6337 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6338 | { |
| 6339 | if (!*args[cur_arg + 1]) { |
| 6340 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6341 | return ERR_ALERT | ERR_FATAL; |
| 6342 | } |
| 6343 | |
| 6344 | if (!strcmp(args[cur_arg+1], "user")) |
| 6345 | conf->level = ACCESS_LVL_USER; |
| 6346 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6347 | conf->level = ACCESS_LVL_OPER; |
| 6348 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6349 | conf->level = ACCESS_LVL_ADMIN; |
| 6350 | else { |
| 6351 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6352 | args[cur_arg], args[cur_arg+1]); |
| 6353 | return ERR_ALERT | ERR_FATAL; |
| 6354 | } |
| 6355 | |
| 6356 | return 0; |
| 6357 | } |
| 6358 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 6359 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6360 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6361 | .name = "<STATS>", /* used for logging */ |
| 6362 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6363 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6364 | }; |
| 6365 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 6366 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6367 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6368 | .name = "<CLI>", /* used for logging */ |
| 6369 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6370 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6371 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6372 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6373 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6374 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6375 | { 0, NULL, NULL }, |
| 6376 | }}; |
| 6377 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6378 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6379 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6380 | { NULL, NULL, 0 }, |
| 6381 | }}; |
| 6382 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6383 | __attribute__((constructor)) |
| 6384 | static void __dumpstats_module_init(void) |
| 6385 | { |
| 6386 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6387 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6388 | } |
| 6389 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6390 | /* |
| 6391 | * Local variables: |
| 6392 | * c-indent-level: 8 |
| 6393 | * c-basic-offset: 8 |
| 6394 | * End: |
| 6395 | */ |