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> |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 42 | #include <types/dns.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 43 | |
| 44 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 45 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 46 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 47 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 48 | #include <proto/dumpstats.h> |
| 49 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 50 | #include <proto/freq_ctr.h> |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 51 | #include <proto/frontend.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 52 | #include <proto/log.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 53 | #include <proto/pattern.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 54 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 55 | #include <proto/listener.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 56 | #include <proto/map.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 57 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 58 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 59 | #include <proto/proxy.h> |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 60 | #include <proto/sample.h> |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 61 | #include <proto/session.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 62 | #include <proto/stream.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 63 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 64 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 65 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 66 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 67 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 68 | #ifdef USE_OPENSSL |
| 69 | #include <proto/ssl_sock.h> |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 70 | #include <types/ssl_sock.h> |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 71 | #endif |
| 72 | |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 73 | /* stats socket states */ |
| 74 | enum { |
| 75 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 76 | STAT_CLI_END, /* final state, let's close */ |
| 77 | STAT_CLI_GETREQ, /* wait for a request */ |
| 78 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 79 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 80 | STAT_CLI_PRINT, /* display message in cli->msg */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 81 | 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] | 82 | STAT_CLI_O_INFO, /* dump info */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 83 | STAT_CLI_O_SESS, /* dump streams */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 84 | STAT_CLI_O_ERR, /* dump errors */ |
| 85 | STAT_CLI_O_TAB, /* dump tables */ |
| 86 | STAT_CLI_O_CLR, /* clear tables */ |
| 87 | STAT_CLI_O_SET, /* set entries in tables */ |
| 88 | STAT_CLI_O_STAT, /* dump stats */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 89 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 90 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 91 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 92 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 93 | STAT_CLI_O_TLSK, /* list all TLS ticket keys references */ |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 94 | STAT_CLI_O_RESOLVERS,/* dump a resolver's section nameservers counters */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 95 | }; |
| 96 | |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 97 | /* Actions available for the stats admin forms */ |
| 98 | enum { |
| 99 | ST_ADM_ACTION_NONE = 0, |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 100 | |
| 101 | /* enable/disable health checks */ |
| 102 | ST_ADM_ACTION_DHLTH, |
| 103 | ST_ADM_ACTION_EHLTH, |
| 104 | |
| 105 | /* force health check status */ |
| 106 | ST_ADM_ACTION_HRUNN, |
| 107 | ST_ADM_ACTION_HNOLB, |
| 108 | ST_ADM_ACTION_HDOWN, |
| 109 | |
| 110 | /* enable/disable agent checks */ |
| 111 | ST_ADM_ACTION_DAGENT, |
| 112 | ST_ADM_ACTION_EAGENT, |
| 113 | |
| 114 | /* force agent check status */ |
| 115 | ST_ADM_ACTION_ARUNN, |
| 116 | ST_ADM_ACTION_ADOWN, |
| 117 | |
| 118 | /* set admin state */ |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 119 | ST_ADM_ACTION_READY, |
| 120 | ST_ADM_ACTION_DRAIN, |
| 121 | ST_ADM_ACTION_MAINT, |
| 122 | ST_ADM_ACTION_SHUTDOWN, |
| 123 | /* these are the ancient actions, still available for compatibility */ |
| 124 | ST_ADM_ACTION_DISABLE, |
| 125 | ST_ADM_ACTION_ENABLE, |
| 126 | ST_ADM_ACTION_STOP, |
| 127 | ST_ADM_ACTION_START, |
| 128 | }; |
| 129 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 130 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 131 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 132 | 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] | 133 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 134 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 135 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 136 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 137 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri); |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 138 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 139 | static int stats_pats_list(struct stream_interface *si); |
| 140 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 141 | static int stats_map_lookup(struct stream_interface *si); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 142 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 143 | static int stats_tlskeys_list(struct stream_interface *si); |
| 144 | #endif |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 145 | static void cli_release_handler(struct appctx *appctx); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 146 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 147 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 148 | * cli_io_handler() |
| 149 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 150 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 151 | * -> stats_dump_info_to_buffer() // "show info" |
| 152 | * -> stats_dump_stat_to_buffer() // "show stat" |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 153 | * -> stats_dump_resolvers_to_buffer() // "show stat resolver <id>" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 154 | * -> stats_dump_csv_header() |
| 155 | * -> stats_dump_proxy_to_buffer() |
| 156 | * -> stats_dump_fe_stats() |
| 157 | * -> stats_dump_li_stats() |
| 158 | * -> stats_dump_sv_stats() |
| 159 | * -> stats_dump_be_stats() |
| 160 | * |
| 161 | * http_stats_io_handler() |
| 162 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 163 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 164 | * -> stats_dump_html_head() // emits the HTML headers |
| 165 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 166 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 167 | * -> stats_dump_html_px_hdr() |
| 168 | * -> stats_dump_fe_stats() |
| 169 | * -> stats_dump_li_stats() |
| 170 | * -> stats_dump_sv_stats() |
| 171 | * -> stats_dump_be_stats() |
| 172 | * -> stats_dump_html_px_end() |
| 173 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 174 | */ |
| 175 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 176 | static struct applet cli_applet; |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 177 | |
| 178 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 179 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 180 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 181 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 182 | " help : this message\n" |
| 183 | " prompt : toggle interactive mode with prompt\n" |
| 184 | " quit : disconnect\n" |
| 185 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 186 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 187 | " show stat : report counters for each proxy and server\n" |
| 188 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 189 | " 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] | 190 | " 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] | 191 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 192 | " set weight : change a server's weight\n" |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 193 | " set server : change a server's state, weight or address\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 194 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 195 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 196 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 197 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 198 | " disable : put a server or frontend in maintenance mode\n" |
| 199 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 200 | " 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] | 201 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 202 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 203 | " add acl : add acl entry\n" |
| 204 | " del acl : delete acl entry\n" |
| 205 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 206 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 207 | " get map : reports the keys and values matching a sample for a map\n" |
| 208 | " set map : modify map entry\n" |
| 209 | " add map : add map entry\n" |
| 210 | " del map : delete map entry\n" |
| 211 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 212 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 213 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 214 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 215 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 216 | "Permission denied\n" |
| 217 | ""; |
| 218 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 219 | /* data transmission states for the stats responses */ |
| 220 | enum { |
| 221 | STAT_ST_INIT = 0, |
| 222 | STAT_ST_HEAD, |
| 223 | STAT_ST_INFO, |
| 224 | STAT_ST_LIST, |
| 225 | STAT_ST_END, |
| 226 | STAT_ST_FIN, |
| 227 | }; |
| 228 | |
| 229 | /* data transmission states for the stats responses inside a proxy */ |
| 230 | enum { |
| 231 | STAT_PX_ST_INIT = 0, |
| 232 | STAT_PX_ST_TH, |
| 233 | STAT_PX_ST_FE, |
| 234 | STAT_PX_ST_LI, |
| 235 | STAT_PX_ST_SV, |
| 236 | STAT_PX_ST_BE, |
| 237 | STAT_PX_ST_END, |
| 238 | STAT_PX_ST_FIN, |
| 239 | }; |
| 240 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 241 | extern const char *stat_status_codes[]; |
| 242 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 243 | /* allocate a new stats frontend named <name>, and return it |
| 244 | * (or NULL in case of lack of memory). |
| 245 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 246 | 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] | 247 | { |
| 248 | struct proxy *fe; |
| 249 | |
| 250 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 251 | if (!fe) |
| 252 | return NULL; |
| 253 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 254 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 255 | fe->next = proxy; |
| 256 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 257 | fe->last_change = now.tv_sec; |
| 258 | fe->id = strdup("GLOBAL"); |
| 259 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 260 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 261 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 262 | fe->conf.file = strdup(file); |
| 263 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 264 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 265 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 266 | |
| 267 | /* the stats frontend is the only one able to assign ID #0 */ |
| 268 | fe->conf.id.key = fe->uuid = 0; |
| 269 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 270 | return fe; |
| 271 | } |
| 272 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 273 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 274 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 275 | * error message into the <err> buffer which will be preallocated. The trailing |
| 276 | * '\n' must not be written. The function must be called with <args> pointing to |
| 277 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 278 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 279 | 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] | 280 | struct proxy *defpx, const char *file, int line, |
| 281 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 282 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 283 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 284 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 285 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 286 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 287 | int cur_arg; |
| 288 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 289 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 290 | 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] | 291 | return -1; |
| 292 | } |
| 293 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 294 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 295 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 296 | 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] | 297 | return -1; |
| 298 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 299 | } |
| 300 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 301 | 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] | 302 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 303 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 304 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 305 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 306 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 307 | return -1; |
| 308 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 309 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 310 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 311 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 312 | static int bind_dumped; |
| 313 | struct bind_kw *kw; |
| 314 | |
| 315 | kw = bind_find_kw(args[cur_arg]); |
| 316 | if (kw) { |
| 317 | if (!kw->parse) { |
| 318 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 319 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 320 | return -1; |
| 321 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 322 | |
| 323 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 324 | if (err && *err) |
| 325 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 326 | else |
| 327 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 328 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 329 | return -1; |
| 330 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 331 | |
| 332 | cur_arg += 1 + kw->skip; |
| 333 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 334 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 335 | |
| 336 | if (!bind_dumped) { |
| 337 | bind_dump_kws(err); |
| 338 | indent_msg(err, 4); |
| 339 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 340 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 341 | |
| 342 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 343 | args[0], args[1], args[cur_arg], |
| 344 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 345 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 346 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 347 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 348 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 349 | l->maxconn = global.stats_fe->maxconn; |
| 350 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 351 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 352 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 353 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 354 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 355 | l->nice = -64; /* we want to boost priority for local stats */ |
| 356 | global.maxsock += l->maxconn; |
| 357 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 358 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 359 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 360 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 361 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 362 | |
| 363 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 364 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 365 | return -1; |
| 366 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 367 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 368 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 369 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 370 | return -1; |
| 371 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 372 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 373 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 374 | 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] | 375 | return -1; |
| 376 | } |
| 377 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 378 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 379 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 380 | else if (!strcmp(args[1], "maxconn")) { |
| 381 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 382 | |
| 383 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 384 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 385 | return -1; |
| 386 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 387 | |
| 388 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 389 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 390 | 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] | 391 | return -1; |
| 392 | } |
| 393 | } |
| 394 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 395 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 396 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 397 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 398 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 399 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 400 | if (!global.stats_fe) { |
| 401 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 402 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 403 | return -1; |
| 404 | } |
| 405 | } |
| 406 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 407 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 408 | unsigned int low, high; |
| 409 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 410 | if (strcmp(args[cur_arg], "all") == 0) { |
| 411 | set = 0; |
| 412 | break; |
| 413 | } |
| 414 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 415 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 416 | } |
| 417 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 418 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 419 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 420 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 421 | char *dash = strchr(args[cur_arg], '-'); |
| 422 | |
| 423 | low = high = str2uic(args[cur_arg]); |
| 424 | if (dash) |
| 425 | high = str2uic(dash + 1); |
| 426 | |
| 427 | if (high < low) { |
| 428 | unsigned int swap = low; |
| 429 | low = high; |
| 430 | high = swap; |
| 431 | } |
| 432 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 433 | if (low < 1 || high > LONGBITS) { |
| 434 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 435 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 436 | return -1; |
| 437 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 438 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 439 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 440 | } |
| 441 | else { |
| 442 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 443 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 444 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 445 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 446 | } |
| 447 | cur_arg++; |
| 448 | } |
| 449 | global.stats_fe->bind_proc = set; |
| 450 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 451 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 452 | 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] | 453 | return -1; |
| 454 | } |
| 455 | return 0; |
| 456 | } |
| 457 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 458 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 459 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 460 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 461 | * 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] | 462 | */ |
| 463 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 464 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 465 | chunk_appendf(&trash, |
| 466 | "# pxname,svname," |
| 467 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 468 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 469 | "bin,bout," |
| 470 | "dreq,dresp," |
| 471 | "ereq,econ,eresp," |
| 472 | "wretr,wredis," |
| 473 | "status,weight,act,bck," |
| 474 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 475 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 476 | "rate,rate_lim,rate_max," |
| 477 | "check_status,check_code,check_duration," |
| 478 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 479 | "req_rate,req_rate_max,req_tot," |
| 480 | "cli_abrt,srv_abrt," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 481 | "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] | 482 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 483 | } |
| 484 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 485 | /* print a string of text buffer to <out>. The format is : |
| 486 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 487 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 488 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 489 | */ |
| 490 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 491 | { |
| 492 | unsigned char c; |
| 493 | int ptr = 0; |
| 494 | |
| 495 | while (buf[ptr] && ptr < bsize) { |
| 496 | c = buf[ptr]; |
| 497 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 498 | if (out->len > out->size - 1) |
| 499 | break; |
| 500 | out->str[out->len++] = c; |
| 501 | } |
| 502 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 503 | if (out->len > out->size - 2) |
| 504 | break; |
| 505 | out->str[out->len++] = '\\'; |
| 506 | switch (c) { |
| 507 | case ' ': c = ' '; break; |
| 508 | case '\t': c = 't'; break; |
| 509 | case '\n': c = 'n'; break; |
| 510 | case '\r': c = 'r'; break; |
| 511 | case '\e': c = 'e'; break; |
| 512 | case '\\': c = '\\'; break; |
| 513 | } |
| 514 | out->str[out->len++] = c; |
| 515 | } |
| 516 | else { |
| 517 | if (out->len > out->size - 4) |
| 518 | break; |
| 519 | out->str[out->len++] = '\\'; |
| 520 | out->str[out->len++] = 'x'; |
| 521 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 522 | out->str[out->len++] = hextab[c & 0xF]; |
| 523 | } |
| 524 | ptr++; |
| 525 | } |
| 526 | |
| 527 | return ptr; |
| 528 | } |
| 529 | |
| 530 | /* print a buffer in hexa. |
| 531 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 532 | */ |
| 533 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 534 | { |
| 535 | unsigned char c; |
| 536 | int ptr = 0; |
| 537 | |
| 538 | while (ptr < bsize) { |
| 539 | c = buf[ptr]; |
| 540 | |
| 541 | if (out->len > out->size - 2) |
| 542 | break; |
| 543 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 544 | out->str[out->len++] = hextab[c & 0xF]; |
| 545 | |
| 546 | ptr++; |
| 547 | } |
| 548 | return ptr; |
| 549 | } |
| 550 | |
| 551 | /* Dump the status of a table to a stream interface's |
| 552 | * read buffer. It returns 0 if the output buffer is full |
| 553 | * and needs to be called again, otherwise non-zero. |
| 554 | */ |
| 555 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 556 | struct proxy *proxy, struct proxy *target) |
| 557 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 558 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 559 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 560 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 561 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 562 | |
| 563 | /* any other information should be dumped here */ |
| 564 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 565 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 566 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 567 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 568 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 569 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 570 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 571 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 572 | |
| 573 | return 1; |
| 574 | } |
| 575 | |
| 576 | /* Dump the a table entry to a stream interface's |
| 577 | * read buffer. It returns 0 if the output buffer is full |
| 578 | * and needs to be called again, otherwise non-zero. |
| 579 | */ |
| 580 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 581 | struct proxy *proxy, struct stksess *entry) |
| 582 | { |
| 583 | int dt; |
| 584 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 585 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 586 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 587 | if (proxy->table.type == SMP_T_IPV4) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 588 | char addr[INET_ADDRSTRLEN]; |
| 589 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 590 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 591 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 592 | else if (proxy->table.type == SMP_T_IPV6) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 593 | char addr[INET6_ADDRSTRLEN]; |
| 594 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 595 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 596 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 597 | else if (proxy->table.type == SMP_T_SINT) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 598 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 599 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 600 | else if (proxy->table.type == SMP_T_STR) { |
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_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 603 | } |
| 604 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 605 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 606 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 607 | } |
| 608 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 609 | 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] | 610 | |
| 611 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 612 | void *ptr; |
| 613 | |
| 614 | if (proxy->table.data_ofs[dt] == 0) |
| 615 | continue; |
| 616 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 617 | 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] | 618 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 619 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 620 | |
| 621 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 622 | switch (stktable_data_types[dt].std_type) { |
| 623 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 624 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 625 | break; |
| 626 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 627 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 628 | break; |
| 629 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 630 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 631 | break; |
| 632 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 633 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 634 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 635 | proxy->table.data_arg[dt].u)); |
| 636 | break; |
| 637 | } |
| 638 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 639 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 640 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 641 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 642 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 643 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 644 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 645 | |
| 646 | return 1; |
| 647 | } |
| 648 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 649 | 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] | 650 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 651 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 652 | struct appctx *appctx = __objt_appctx(si->end); |
| 653 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 654 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 655 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 656 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 657 | long long value; |
| 658 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 659 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 660 | void *ptr; |
| 661 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 662 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 663 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 664 | |
| 665 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 666 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 667 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 668 | return; |
| 669 | } |
| 670 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 671 | switch (px->table.type) { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 672 | case SMP_T_IPV4: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 673 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 674 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 675 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 676 | case SMP_T_IPV6: |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 677 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 678 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 679 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 680 | case SMP_T_SINT: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 681 | { |
| 682 | char *endptr; |
| 683 | unsigned long val; |
| 684 | errno = 0; |
| 685 | val = strtoul(args[4], &endptr, 10); |
| 686 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 687 | (errno != 0 && val == 0) || endptr == args[4] || |
| 688 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 689 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 690 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 691 | return; |
| 692 | } |
| 693 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 694 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 695 | break; |
| 696 | } |
| 697 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 698 | case SMP_T_STR: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 699 | static_table_key->key = args[4]; |
| 700 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 701 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 702 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 703 | switch (action) { |
| 704 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 705 | 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] | 706 | break; |
| 707 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 708 | 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] | 709 | break; |
| 710 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 711 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 712 | break; |
| 713 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 714 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 715 | return; |
| 716 | } |
| 717 | |
| 718 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 719 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 720 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 721 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 722 | return; |
| 723 | } |
| 724 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 725 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 726 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 727 | switch (action) { |
| 728 | case STAT_CLI_O_TAB: |
| 729 | if (!ts) |
| 730 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 731 | chunk_reset(&trash); |
| 732 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 733 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 734 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 735 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 736 | |
| 737 | case STAT_CLI_O_CLR: |
| 738 | if (!ts) |
| 739 | return; |
| 740 | if (ts->ref_cnt) { |
| 741 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 742 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 743 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 744 | return; |
| 745 | } |
| 746 | stksess_kill(&px->table, ts); |
| 747 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 748 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 749 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 750 | if (ts) |
| 751 | stktable_touch(&px->table, ts, 1); |
| 752 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 753 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 754 | if (!ts) { |
| 755 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 756 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 757 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 758 | return; |
| 759 | } |
| 760 | stktable_store(&px->table, ts, 1); |
| 761 | } |
| 762 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 763 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 764 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 765 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 766 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 767 | return; |
| 768 | } |
| 769 | |
| 770 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 771 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 772 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 773 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 774 | return; |
| 775 | } |
| 776 | |
| 777 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 778 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 779 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 780 | return; |
| 781 | } |
| 782 | |
| 783 | 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] | 784 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 785 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 786 | return; |
| 787 | } |
| 788 | |
| 789 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 790 | |
| 791 | switch (stktable_data_types[data_type].std_type) { |
| 792 | case STD_T_SINT: |
| 793 | stktable_data_cast(ptr, std_t_sint) = value; |
| 794 | break; |
| 795 | case STD_T_UINT: |
| 796 | stktable_data_cast(ptr, std_t_uint) = value; |
| 797 | break; |
| 798 | case STD_T_ULL: |
| 799 | stktable_data_cast(ptr, std_t_ull) = value; |
| 800 | break; |
| 801 | case STD_T_FRQP: |
| 802 | /* We set both the current and previous values. That way |
| 803 | * the reported frequency is stable during all the period |
| 804 | * then slowly fades out. This allows external tools to |
| 805 | * push measures without having to update them too often. |
| 806 | */ |
| 807 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 808 | frqp->curr_tick = now_ms; |
| 809 | frqp->prev_ctr = 0; |
| 810 | frqp->curr_ctr = value; |
| 811 | break; |
| 812 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 813 | } |
| 814 | break; |
| 815 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 816 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 817 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 818 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 819 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 820 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 821 | } |
| 822 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 823 | 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] | 824 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 825 | struct appctx *appctx = __objt_appctx(si->end); |
| 826 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 827 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 828 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 829 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 830 | return; |
| 831 | } |
| 832 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 833 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 834 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 835 | if (appctx->ctx.table.data_type < 0) { |
| 836 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 837 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 838 | return; |
| 839 | } |
| 840 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 841 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 842 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 843 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 844 | return; |
| 845 | } |
| 846 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 847 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 848 | if (appctx->ctx.table.data_op < 0) { |
| 849 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 850 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 851 | return; |
| 852 | } |
| 853 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 854 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 855 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 856 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 857 | return; |
| 858 | } |
| 859 | } |
| 860 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 861 | 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] | 862 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 863 | struct appctx *appctx = __objt_appctx(si->end); |
| 864 | |
| 865 | appctx->ctx.table.data_type = -1; |
| 866 | appctx->st2 = STAT_ST_INIT; |
| 867 | appctx->ctx.table.target = NULL; |
| 868 | appctx->ctx.table.proxy = NULL; |
| 869 | appctx->ctx.table.entry = NULL; |
| 870 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 871 | |
| 872 | if (*args[2]) { |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 873 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 874 | if (!appctx->ctx.table.target) { |
| 875 | appctx->ctx.cli.msg = "No such table\n"; |
| 876 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 877 | return; |
| 878 | } |
| 879 | } |
| 880 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 881 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 882 | goto err_args; |
| 883 | return; |
| 884 | } |
| 885 | |
| 886 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 887 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 888 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 889 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 890 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 891 | goto err_args; |
| 892 | |
| 893 | return; |
| 894 | |
| 895 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 896 | switch (action) { |
| 897 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 898 | 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] | 899 | break; |
| 900 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 901 | 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] | 902 | break; |
| 903 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 904 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 905 | break; |
| 906 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 907 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 908 | } |
| 909 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 910 | /* 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] | 911 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 912 | * level to be admin. |
| 913 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 914 | 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] | 915 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 916 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 917 | struct proxy *px; |
| 918 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 919 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 920 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 921 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 922 | return NULL; |
| 923 | } |
| 924 | |
| 925 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 926 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 927 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 928 | return NULL; |
| 929 | } |
| 930 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 931 | px = proxy_fe_by_name(arg); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 932 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 933 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 934 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 935 | return NULL; |
| 936 | } |
| 937 | return px; |
| 938 | } |
| 939 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 940 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 941 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 942 | * 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] | 943 | * the <arg> is modified to remove the '/'. |
| 944 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 945 | 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] | 946 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 947 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 948 | struct proxy *px; |
| 949 | struct server *sv; |
| 950 | char *line; |
| 951 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 952 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 953 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 954 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 955 | return NULL; |
| 956 | } |
| 957 | |
| 958 | /* split "backend/server" and make <line> point to server */ |
| 959 | for (line = arg; *line; line++) |
| 960 | if (*line == '/') { |
| 961 | *line++ = '\0'; |
| 962 | break; |
| 963 | } |
| 964 | |
| 965 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 966 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 967 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 968 | return NULL; |
| 969 | } |
| 970 | |
| 971 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 972 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 973 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 974 | return NULL; |
| 975 | } |
| 976 | |
| 977 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 978 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 979 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 980 | return NULL; |
| 981 | } |
| 982 | |
| 983 | return sv; |
| 984 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 985 | |
| 986 | /* This function is used with TLS ticket keys management. It permits to browse |
| 987 | * each reference. The variable <getnext> must contain the current node, |
| 988 | * <end> point to the root node. |
| 989 | */ |
| 990 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 991 | static inline |
| 992 | struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end) |
| 993 | { |
| 994 | struct tls_keys_ref *ref = getnext; |
| 995 | |
| 996 | while (1) { |
| 997 | |
| 998 | /* Get next list entry. */ |
| 999 | ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list); |
| 1000 | |
| 1001 | /* If the entry is the last of the list, return NULL. */ |
| 1002 | if (&ref->list == end) |
| 1003 | return NULL; |
| 1004 | |
| 1005 | return ref; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | static inline |
| 1010 | struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference) |
| 1011 | { |
| 1012 | int id; |
| 1013 | char *error; |
| 1014 | |
| 1015 | /* If the reference starts by a '#', this is numeric id. */ |
| 1016 | if (reference[0] == '#') { |
| 1017 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1018 | id = strtol(reference + 1, &error, 10); |
| 1019 | if (*error != '\0') |
| 1020 | return NULL; |
| 1021 | |
| 1022 | /* Perform the unique id lookup. */ |
| 1023 | return tlskeys_ref_lookupid(id); |
| 1024 | } |
| 1025 | |
| 1026 | /* Perform the string lookup. */ |
| 1027 | return tlskeys_ref_lookup(reference); |
| 1028 | } |
| 1029 | #endif |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1030 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1031 | /* This function is used with map and acl management. It permits to browse |
| 1032 | * each reference. The variable <getnext> must contain the current node, |
| 1033 | * <end> point to the root node and the <flags> permit to filter required |
| 1034 | * nodes. |
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 | static inline |
| 1037 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1038 | unsigned int flags) |
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 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1041 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1042 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1043 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1044 | /* Get next list entry. */ |
| 1045 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
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 is the last of the list, return NULL. */ |
| 1048 | if (&ref->list == end) |
| 1049 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1050 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1051 | /* If the entry match the flag, return it. */ |
| 1052 | if (ref->flags & flags) |
| 1053 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1054 | } |
| 1055 | } |
| 1056 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1057 | static inline |
| 1058 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1059 | { |
| 1060 | int id; |
| 1061 | char *error; |
| 1062 | |
| 1063 | /* If the reference starts by a '#', this is numeric id. */ |
| 1064 | if (reference[0] == '#') { |
| 1065 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1066 | id = strtol(reference + 1, &error, 10); |
| 1067 | if (*error != '\0') |
| 1068 | return NULL; |
| 1069 | |
| 1070 | /* Perform the unique id lookup. */ |
| 1071 | return pat_ref_lookupid(id); |
| 1072 | } |
| 1073 | |
| 1074 | /* Perform the string lookup. */ |
| 1075 | return pat_ref_lookup(reference); |
| 1076 | } |
| 1077 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1078 | /* This function is used with map and acl management. It permits to browse |
| 1079 | * each reference. |
| 1080 | */ |
| 1081 | static inline |
| 1082 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1083 | { |
| 1084 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1085 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1086 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1087 | return NULL; |
| 1088 | return expr; |
| 1089 | } |
| 1090 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1091 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1092 | * 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] | 1093 | * 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] | 1094 | * designating the function which will have to process the request, which can |
| 1095 | * 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] | 1096 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1097 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1098 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1099 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1100 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1101 | char *args[MAX_STATS_ARGS + 1]; |
| 1102 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1103 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1104 | |
| 1105 | while (isspace((unsigned char)*line)) |
| 1106 | line++; |
| 1107 | |
| 1108 | arg = 0; |
| 1109 | args[arg] = line; |
| 1110 | |
| 1111 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1112 | if (*line == '\\') { |
| 1113 | line++; |
| 1114 | if (*line == '\0') |
| 1115 | break; |
| 1116 | } |
| 1117 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1118 | *line++ = '\0'; |
| 1119 | |
| 1120 | while (isspace((unsigned char)*line)) |
| 1121 | line++; |
| 1122 | |
| 1123 | args[++arg] = line; |
| 1124 | continue; |
| 1125 | } |
| 1126 | |
| 1127 | line++; |
| 1128 | } |
| 1129 | |
| 1130 | while (++arg <= MAX_STATS_ARGS) |
| 1131 | args[arg] = line; |
| 1132 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1133 | /* remove \ */ |
| 1134 | arg = 0; |
| 1135 | while (*args[arg] != '\0') { |
| 1136 | j = 0; |
| 1137 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1138 | if (args[arg][i] == '\\') |
| 1139 | continue; |
| 1140 | args[arg][j] = args[arg][i]; |
| 1141 | j++; |
| 1142 | } |
| 1143 | args[arg][j] = '\0'; |
| 1144 | arg++; |
| 1145 | } |
| 1146 | |
Willy Tarreau | 6bcb95d | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1147 | appctx->ctx.stats.scope_str = 0; |
| 1148 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1149 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1150 | if (strcmp(args[0], "show") == 0) { |
| 1151 | if (strcmp(args[1], "stat") == 0) { |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1152 | if (strcmp(args[2], "resolvers") == 0) { |
| 1153 | struct dns_resolvers *presolvers; |
| 1154 | |
| 1155 | if (!*args[3]) { |
| 1156 | appctx->ctx.cli.msg = "Missing resolver section identifier.\n"; |
| 1157 | appctx->st0 = STAT_CLI_PRINT; |
| 1158 | return 1; |
| 1159 | } |
| 1160 | |
| 1161 | appctx->ctx.resolvers.ptr = NULL; |
| 1162 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 1163 | if (strcmp(presolvers->id, args[3]) == 0) { |
| 1164 | appctx->ctx.resolvers.ptr = presolvers; |
| 1165 | break; |
| 1166 | } |
| 1167 | } |
| 1168 | if (appctx->ctx.resolvers.ptr == NULL) { |
| 1169 | appctx->ctx.cli.msg = "Can't find resolvers section.\n"; |
| 1170 | appctx->st0 = STAT_CLI_PRINT; |
| 1171 | return 1; |
| 1172 | } |
| 1173 | |
| 1174 | appctx->st2 = STAT_ST_INIT; |
| 1175 | appctx->st0 = STAT_CLI_O_RESOLVERS; |
| 1176 | return 1; |
| 1177 | } |
| 1178 | else if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1179 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1180 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1181 | appctx->ctx.stats.type = atoi(args[3]); |
| 1182 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1185 | appctx->st2 = STAT_ST_INIT; |
| 1186 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1187 | } |
| 1188 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1189 | appctx->st2 = STAT_ST_INIT; |
| 1190 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1191 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1192 | else if (strcmp(args[1], "pools") == 0) { |
| 1193 | appctx->st2 = STAT_ST_INIT; |
| 1194 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1195 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1196 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1197 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1198 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1199 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1200 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1201 | return 1; |
| 1202 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1203 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1204 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1205 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1206 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1207 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1208 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1209 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1210 | appctx->ctx.sess.pos = 0; |
| 1211 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1212 | } |
| 1213 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1214 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1215 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1216 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1217 | return 1; |
| 1218 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1219 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1220 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1221 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1222 | appctx->ctx.errors.iid = -1; |
| 1223 | appctx->ctx.errors.px = NULL; |
| 1224 | appctx->st2 = STAT_ST_INIT; |
| 1225 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1226 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1227 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1228 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1229 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1230 | else if (strcmp(args[1], "tls-keys") == 0) { |
| 1231 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1232 | appctx->st2 = STAT_ST_INIT; |
| 1233 | appctx->st0 = STAT_CLI_O_TLSK; |
| 1234 | #else |
| 1235 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1236 | "that doesn't support specifying TLS ticket keys\n"; |
| 1237 | appctx->st0 = STAT_CLI_PRINT; |
| 1238 | #endif |
| 1239 | return 1; |
| 1240 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1241 | else if (strcmp(args[1], "map") == 0 || |
| 1242 | strcmp(args[1], "acl") == 0) { |
| 1243 | |
| 1244 | /* Set ACL or MAP flags. */ |
| 1245 | if (args[1][0] == 'm') |
| 1246 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1247 | else |
| 1248 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1249 | |
| 1250 | /* no parameter: display all map avalaible */ |
| 1251 | if (!*args[2]) { |
| 1252 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1253 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1254 | return 1; |
| 1255 | } |
| 1256 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1257 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1258 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1259 | if (!appctx->ctx.map.ref || |
| 1260 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1261 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1262 | 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] | 1263 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1264 | 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] | 1265 | appctx->st0 = STAT_CLI_PRINT; |
| 1266 | return 1; |
| 1267 | } |
| 1268 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1269 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1270 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1271 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1272 | return 0; |
| 1273 | } |
| 1274 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1275 | else if (strcmp(args[0], "clear") == 0) { |
| 1276 | if (strcmp(args[1], "counters") == 0) { |
| 1277 | struct proxy *px; |
| 1278 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1279 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1280 | int clrall = 0; |
| 1281 | |
| 1282 | if (strcmp(args[2], "all") == 0) |
| 1283 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1284 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1285 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1286 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1287 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1288 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1289 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1290 | return 1; |
| 1291 | } |
| 1292 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1293 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1294 | if (clrall) { |
| 1295 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1296 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1297 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1298 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1299 | px->be_counters.conn_max = 0; |
| 1300 | px->be_counters.p.http.rps_max = 0; |
| 1301 | px->be_counters.sps_max = 0; |
| 1302 | px->be_counters.cps_max = 0; |
| 1303 | px->be_counters.nbpend_max = 0; |
| 1304 | |
| 1305 | px->fe_counters.conn_max = 0; |
| 1306 | px->fe_counters.p.http.rps_max = 0; |
| 1307 | px->fe_counters.sps_max = 0; |
| 1308 | px->fe_counters.cps_max = 0; |
| 1309 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1310 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1311 | |
| 1312 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1313 | if (clrall) |
| 1314 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1315 | else { |
| 1316 | sv->counters.cur_sess_max = 0; |
| 1317 | sv->counters.nbpend_max = 0; |
| 1318 | sv->counters.sps_max = 0; |
| 1319 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1320 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1321 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1322 | if (li->counters) { |
| 1323 | if (clrall) |
| 1324 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1325 | else |
| 1326 | li->counters->conn_max = 0; |
| 1327 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1328 | } |
| 1329 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1330 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1331 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1332 | return 1; |
| 1333 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1334 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1335 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1336 | /* end of processing */ |
| 1337 | return 1; |
| 1338 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1339 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1340 | /* Set ACL or MAP flags. */ |
| 1341 | if (args[1][0] == 'm') |
| 1342 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1343 | else |
| 1344 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1345 | |
| 1346 | /* no parameter */ |
| 1347 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1348 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1349 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1350 | else |
| 1351 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1352 | appctx->st0 = STAT_CLI_PRINT; |
| 1353 | return 1; |
| 1354 | } |
| 1355 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1356 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1357 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1358 | if (!appctx->ctx.map.ref || |
| 1359 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1360 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1361 | 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] | 1362 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1363 | 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] | 1364 | appctx->st0 = STAT_CLI_PRINT; |
| 1365 | return 1; |
| 1366 | } |
| 1367 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1368 | /* Clear all. */ |
| 1369 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1370 | |
| 1371 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1372 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1373 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1374 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1375 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1376 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1377 | return 0; |
| 1378 | } |
| 1379 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1380 | else if (strcmp(args[0], "get") == 0) { |
| 1381 | if (strcmp(args[1], "weight") == 0) { |
| 1382 | struct proxy *px; |
| 1383 | struct server *sv; |
| 1384 | |
| 1385 | /* split "backend/server" and make <line> point to server */ |
| 1386 | for (line = args[2]; *line; line++) |
| 1387 | if (*line == '/') { |
| 1388 | *line++ = '\0'; |
| 1389 | break; |
| 1390 | } |
| 1391 | |
| 1392 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1393 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1394 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1395 | return 1; |
| 1396 | } |
| 1397 | |
| 1398 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1399 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1400 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1401 | return 1; |
| 1402 | } |
| 1403 | |
| 1404 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1405 | 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] | 1406 | if (bi_putstr(si_ic(si), trash.str) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 1407 | si_applet_cant_put(si); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1408 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1409 | return 1; |
| 1410 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1411 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1412 | /* Set flags. */ |
| 1413 | if (args[1][0] == 'm') |
| 1414 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1415 | else |
| 1416 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1417 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1418 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1419 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1420 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1421 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1422 | else |
| 1423 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1424 | appctx->st0 = STAT_CLI_PRINT; |
| 1425 | return 1; |
| 1426 | } |
| 1427 | |
| 1428 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1429 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1430 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1431 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1432 | 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] | 1433 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1434 | 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] | 1435 | appctx->st0 = STAT_CLI_PRINT; |
| 1436 | return 1; |
| 1437 | } |
| 1438 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1439 | /* copy input string. The string must be allocated because |
| 1440 | * it may be used over multiple iterations. It's released |
| 1441 | * at the end and upon abort anyway. |
| 1442 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1443 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1444 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1445 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1446 | if (!appctx->ctx.map.chunk.str) { |
| 1447 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1448 | appctx->st0 = STAT_CLI_PRINT; |
| 1449 | return 1; |
| 1450 | } |
| 1451 | |
| 1452 | /* prepare response */ |
| 1453 | appctx->st2 = STAT_ST_INIT; |
| 1454 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1455 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1456 | else { /* not "get weight" */ |
| 1457 | return 0; |
| 1458 | } |
| 1459 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1460 | else if (strcmp(args[0], "set") == 0) { |
| 1461 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1462 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1463 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1464 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1465 | sv = expect_server_admin(s, si, args[2]); |
| 1466 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1467 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1468 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1469 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1470 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1471 | appctx->ctx.cli.msg = warning; |
| 1472 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1473 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1474 | return 1; |
| 1475 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1476 | else if (strcmp(args[1], "server") == 0) { |
| 1477 | struct server *sv; |
| 1478 | const char *warning; |
| 1479 | |
| 1480 | sv = expect_server_admin(s, si, args[2]); |
| 1481 | if (!sv) |
| 1482 | return 1; |
| 1483 | |
| 1484 | if (strcmp(args[3], "weight") == 0) { |
| 1485 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1486 | if (warning) { |
| 1487 | appctx->ctx.cli.msg = warning; |
| 1488 | appctx->st0 = STAT_CLI_PRINT; |
| 1489 | } |
| 1490 | } |
| 1491 | else if (strcmp(args[3], "state") == 0) { |
| 1492 | if (strcmp(args[4], "ready") == 0) |
| 1493 | srv_adm_set_ready(sv); |
| 1494 | else if (strcmp(args[4], "drain") == 0) |
| 1495 | srv_adm_set_drain(sv); |
| 1496 | else if (strcmp(args[4], "maint") == 0) |
| 1497 | srv_adm_set_maint(sv); |
| 1498 | else { |
| 1499 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1500 | appctx->st0 = STAT_CLI_PRINT; |
| 1501 | } |
| 1502 | } |
| 1503 | else if (strcmp(args[3], "health") == 0) { |
| 1504 | if (sv->track) { |
| 1505 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1506 | appctx->st0 = STAT_CLI_PRINT; |
| 1507 | } |
| 1508 | else if (strcmp(args[4], "up") == 0) { |
| 1509 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1510 | srv_set_running(sv, "changed from CLI"); |
| 1511 | } |
| 1512 | else if (strcmp(args[4], "stopping") == 0) { |
| 1513 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1514 | srv_set_stopping(sv, "changed from CLI"); |
| 1515 | } |
| 1516 | else if (strcmp(args[4], "down") == 0) { |
| 1517 | sv->check.health = 0; |
| 1518 | srv_set_stopped(sv, "changed from CLI"); |
| 1519 | } |
| 1520 | else { |
| 1521 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1522 | appctx->st0 = STAT_CLI_PRINT; |
| 1523 | } |
| 1524 | } |
| 1525 | else if (strcmp(args[3], "agent") == 0) { |
| 1526 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1527 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1528 | appctx->st0 = STAT_CLI_PRINT; |
| 1529 | } |
| 1530 | else if (strcmp(args[4], "up") == 0) { |
| 1531 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1532 | srv_set_running(sv, "changed from CLI"); |
| 1533 | } |
| 1534 | else if (strcmp(args[4], "down") == 0) { |
| 1535 | sv->agent.health = 0; |
| 1536 | srv_set_stopped(sv, "changed from CLI"); |
| 1537 | } |
| 1538 | else { |
| 1539 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1540 | appctx->st0 = STAT_CLI_PRINT; |
| 1541 | } |
| 1542 | } |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1543 | else if (strcmp(args[3], "addr") == 0) { |
| 1544 | warning = server_parse_addr_change_request(sv, args[4]); |
| 1545 | if (warning) { |
| 1546 | appctx->ctx.cli.msg = warning; |
| 1547 | appctx->st0 = STAT_CLI_PRINT; |
| 1548 | } |
| 1549 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1550 | else { |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1551 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state', 'weight' and 'addr'.\n"; |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1552 | appctx->st0 = STAT_CLI_PRINT; |
| 1553 | } |
| 1554 | return 1; |
| 1555 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1556 | else if (strcmp(args[1], "timeout") == 0) { |
| 1557 | if (strcmp(args[2], "cli") == 0) { |
| 1558 | unsigned timeout; |
| 1559 | const char *res; |
| 1560 | |
| 1561 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1562 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1563 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1564 | return 1; |
| 1565 | } |
| 1566 | |
| 1567 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1568 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1569 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1570 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1571 | return 1; |
| 1572 | } |
| 1573 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1574 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1575 | return 1; |
| 1576 | } |
| 1577 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1578 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1579 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1580 | return 1; |
| 1581 | } |
| 1582 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1583 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1584 | if (strcmp(args[2], "frontend") == 0) { |
| 1585 | struct proxy *px; |
| 1586 | struct listener *l; |
| 1587 | int v; |
| 1588 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1589 | px = expect_frontend_admin(s, si, args[3]); |
| 1590 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1591 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1592 | |
| 1593 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1594 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1595 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1596 | return 1; |
| 1597 | } |
| 1598 | |
| 1599 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1600 | if (v < 0) { |
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 | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1603 | return 1; |
| 1604 | } |
| 1605 | |
| 1606 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1607 | * its listeners. The blocked ones will be dequeued. |
| 1608 | */ |
| 1609 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1610 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1611 | l->maxconn = v; |
| 1612 | if (l->state == LI_FULL) |
| 1613 | resume_listener(l); |
| 1614 | } |
| 1615 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1616 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1617 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1618 | |
| 1619 | return 1; |
| 1620 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1621 | else if (strcmp(args[2], "global") == 0) { |
| 1622 | int v; |
| 1623 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1624 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1625 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1626 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1627 | return 1; |
| 1628 | } |
| 1629 | |
| 1630 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1631 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1632 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1633 | return 1; |
| 1634 | } |
| 1635 | |
| 1636 | v = atoi(args[3]); |
| 1637 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1638 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1639 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1640 | return 1; |
| 1641 | } |
| 1642 | |
| 1643 | /* check for unlimited values */ |
| 1644 | if (v <= 0) |
| 1645 | v = global.hardmaxconn; |
| 1646 | |
| 1647 | global.maxconn = v; |
| 1648 | |
| 1649 | /* Dequeues all of the listeners waiting for a resource */ |
| 1650 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1651 | dequeue_all_listeners(&global_listener_queue); |
| 1652 | |
| 1653 | return 1; |
| 1654 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1655 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1656 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1657 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1658 | return 1; |
| 1659 | } |
| 1660 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1661 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1662 | if (strcmp(args[2], "connections") == 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 | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1667 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1668 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1669 | return 1; |
| 1670 | } |
| 1671 | |
| 1672 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1673 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1674 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1675 | return 1; |
| 1676 | } |
| 1677 | |
| 1678 | v = atoi(args[4]); |
| 1679 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1680 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1681 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1682 | return 1; |
| 1683 | } |
| 1684 | |
| 1685 | global.cps_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 { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1694 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1695 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1696 | return 1; |
| 1697 | } |
| 1698 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1699 | else if (strcmp(args[2], "sessions") == 0) { |
| 1700 | if (strcmp(args[3], "global") == 0) { |
| 1701 | int v; |
| 1702 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1703 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1704 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1705 | appctx->st0 = STAT_CLI_PRINT; |
| 1706 | return 1; |
| 1707 | } |
| 1708 | |
| 1709 | if (!*args[4]) { |
| 1710 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1711 | appctx->st0 = STAT_CLI_PRINT; |
| 1712 | return 1; |
| 1713 | } |
| 1714 | |
| 1715 | v = atoi(args[4]); |
| 1716 | if (v < 0) { |
| 1717 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1718 | appctx->st0 = STAT_CLI_PRINT; |
| 1719 | return 1; |
| 1720 | } |
| 1721 | |
| 1722 | global.sps_lim = v; |
| 1723 | |
| 1724 | /* Dequeues all of the listeners waiting for a resource */ |
| 1725 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1726 | dequeue_all_listeners(&global_listener_queue); |
| 1727 | |
| 1728 | return 1; |
| 1729 | } |
| 1730 | else { |
| 1731 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1732 | appctx->st0 = STAT_CLI_PRINT; |
| 1733 | return 1; |
| 1734 | } |
| 1735 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1736 | #ifdef USE_OPENSSL |
| 1737 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1738 | if (strcmp(args[3], "global") == 0) { |
| 1739 | int v; |
| 1740 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1741 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1742 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1743 | appctx->st0 = STAT_CLI_PRINT; |
| 1744 | return 1; |
| 1745 | } |
| 1746 | |
| 1747 | if (!*args[4]) { |
| 1748 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1749 | appctx->st0 = STAT_CLI_PRINT; |
| 1750 | return 1; |
| 1751 | } |
| 1752 | |
| 1753 | v = atoi(args[4]); |
| 1754 | if (v < 0) { |
| 1755 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1756 | appctx->st0 = STAT_CLI_PRINT; |
| 1757 | return 1; |
| 1758 | } |
| 1759 | |
| 1760 | global.ssl_lim = v; |
| 1761 | |
| 1762 | /* Dequeues all of the listeners waiting for a resource */ |
| 1763 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1764 | dequeue_all_listeners(&global_listener_queue); |
| 1765 | |
| 1766 | return 1; |
| 1767 | } |
| 1768 | else { |
| 1769 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1770 | appctx->st0 = STAT_CLI_PRINT; |
| 1771 | return 1; |
| 1772 | } |
| 1773 | } |
| 1774 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1775 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1776 | if (strcmp(args[3], "global") == 0) { |
| 1777 | int v; |
| 1778 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1779 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1780 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1781 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1782 | return 1; |
| 1783 | } |
| 1784 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1785 | v = atoi(args[4]); |
| 1786 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1787 | } |
| 1788 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1789 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1790 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1791 | return 1; |
| 1792 | } |
| 1793 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1794 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1795 | 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] | 1796 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1797 | return 1; |
| 1798 | } |
| 1799 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1800 | else if (strcmp(args[1], "table") == 0) { |
| 1801 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1802 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1803 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1804 | char *err; |
| 1805 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1806 | /* Set flags. */ |
| 1807 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1808 | |
| 1809 | /* Expect three parameters: map name, key and new value. */ |
| 1810 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1811 | 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] | 1812 | appctx->st0 = STAT_CLI_PRINT; |
| 1813 | return 1; |
| 1814 | } |
| 1815 | |
| 1816 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1817 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1818 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1819 | 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] | 1820 | appctx->st0 = STAT_CLI_PRINT; |
| 1821 | return 1; |
| 1822 | } |
| 1823 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1824 | /* If the entry identifier start with a '#', it is considered as |
| 1825 | * pointer id |
| 1826 | */ |
| 1827 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1828 | struct pat_ref_elt *ref; |
| 1829 | long long int conv; |
| 1830 | char *error; |
| 1831 | |
| 1832 | /* Convert argument to integer value. */ |
| 1833 | conv = strtoll(&args[3][1], &error, 16); |
| 1834 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1835 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1836 | appctx->st0 = STAT_CLI_PRINT; |
| 1837 | return 1; |
| 1838 | } |
| 1839 | |
| 1840 | /* Convert and check integer to pointer. */ |
| 1841 | ref = (struct pat_ref_elt *)(long)conv; |
| 1842 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1843 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1844 | appctx->st0 = STAT_CLI_PRINT; |
| 1845 | return 1; |
| 1846 | } |
| 1847 | |
| 1848 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1849 | err = NULL; |
| 1850 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1851 | if (err) |
| 1852 | memprintf(&err, "%s.\n", err); |
| 1853 | appctx->ctx.cli.err = err; |
| 1854 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1855 | return 1; |
| 1856 | } |
| 1857 | } |
| 1858 | else { |
| 1859 | /* Else, use the entry identifier as pattern |
| 1860 | * string, and update the value. |
| 1861 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1862 | err = NULL; |
| 1863 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1864 | if (err) |
| 1865 | memprintf(&err, "%s.\n", err); |
| 1866 | appctx->ctx.cli.err = err; |
| 1867 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1868 | return 1; |
| 1869 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1870 | } |
| 1871 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1872 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1873 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1874 | return 1; |
| 1875 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1876 | #ifdef USE_OPENSSL |
| 1877 | else if (strcmp(args[1], "ssl") == 0) { |
| 1878 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 1879 | #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] | 1880 | char *err = NULL; |
| 1881 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 1882 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1883 | if (!*args[3]) { |
| 1884 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 1885 | appctx->st0 = STAT_CLI_PRINT; |
| 1886 | return 1; |
| 1887 | } |
| 1888 | |
| 1889 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 1890 | if (trash.len < 0) { |
| 1891 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 1892 | appctx->st0 = STAT_CLI_PRINT; |
| 1893 | return 1; |
| 1894 | } |
| 1895 | |
| 1896 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 1897 | if (err) { |
| 1898 | memprintf(&err, "%s.\n", err); |
| 1899 | appctx->ctx.cli.err = err; |
| 1900 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 1901 | } |
| 1902 | return 1; |
| 1903 | } |
| 1904 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 1905 | appctx->st0 = STAT_CLI_PRINT; |
| 1906 | return 1; |
| 1907 | #else |
| 1908 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 1909 | appctx->st0 = STAT_CLI_PRINT; |
| 1910 | return 1; |
| 1911 | #endif |
| 1912 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1913 | else if (strcmp(args[2], "tls-key") == 0) { |
| 1914 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1915 | /* Expect two parameters: the filename and the new new TLS key in encoding */ |
| 1916 | if (!*args[3] || !*args[4]) { |
| 1917 | appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n"; |
| 1918 | appctx->st0 = STAT_CLI_PRINT; |
| 1919 | return 1; |
| 1920 | } |
| 1921 | |
| 1922 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]); |
| 1923 | if(!appctx->ctx.tlskeys.ref) { |
| 1924 | appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n"; |
| 1925 | appctx->st0 = STAT_CLI_PRINT; |
| 1926 | return 1; |
| 1927 | } |
| 1928 | |
| 1929 | trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size); |
| 1930 | if (trash.len != sizeof(struct tls_sess_key)) { |
| 1931 | appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n"; |
| 1932 | appctx->st0 = STAT_CLI_PRINT; |
| 1933 | return 1; |
| 1934 | } |
| 1935 | |
Pradeep Jindal | cc79b00 | 2015-08-20 18:25:17 +0530 | [diff] [blame] | 1936 | memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len); |
| 1937 | appctx->ctx.tlskeys.ref->tls_ticket_enc_index = (appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 1) % TLS_TICKETS_NO; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1938 | |
| 1939 | appctx->ctx.cli.msg = "TLS ticket key updated!"; |
| 1940 | appctx->st0 = STAT_CLI_PRINT; |
| 1941 | return 1; |
| 1942 | #else |
| 1943 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1944 | "that doesn't support specifying TLS ticket keys\n"; |
| 1945 | appctx->st0 = STAT_CLI_PRINT; |
| 1946 | return 1; |
| 1947 | #endif |
| 1948 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1949 | else { |
| 1950 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 1951 | appctx->st0 = STAT_CLI_PRINT; |
| 1952 | return 1; |
| 1953 | } |
| 1954 | } |
| 1955 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1956 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1957 | return 0; |
| 1958 | } |
| 1959 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1960 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1961 | if (strcmp(args[1], "agent") == 0) { |
| 1962 | struct server *sv; |
| 1963 | |
| 1964 | sv = expect_server_admin(s, si, args[2]); |
| 1965 | if (!sv) |
| 1966 | return 1; |
| 1967 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1968 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1969 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1970 | appctx->st0 = STAT_CLI_PRINT; |
| 1971 | return 1; |
| 1972 | } |
| 1973 | |
| 1974 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1975 | return 1; |
| 1976 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1977 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1978 | struct server *sv; |
| 1979 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1980 | sv = expect_server_admin(s, si, args[2]); |
| 1981 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1982 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1983 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 1984 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 1985 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 1986 | appctx->st0 = STAT_CLI_PRINT; |
| 1987 | return 1; |
| 1988 | } |
| 1989 | |
| 1990 | sv->check.state |= CHK_ST_ENABLED; |
| 1991 | return 1; |
| 1992 | } |
| 1993 | else if (strcmp(args[1], "server") == 0) { |
| 1994 | struct server *sv; |
| 1995 | |
| 1996 | sv = expect_server_admin(s, si, args[2]); |
| 1997 | if (!sv) |
| 1998 | return 1; |
| 1999 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2000 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2001 | return 1; |
| 2002 | } |
| 2003 | else if (strcmp(args[1], "frontend") == 0) { |
| 2004 | struct proxy *px; |
| 2005 | |
| 2006 | px = expect_frontend_admin(s, si, args[2]); |
| 2007 | if (!px) |
| 2008 | return 1; |
| 2009 | |
| 2010 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2011 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 2012 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2013 | return 1; |
| 2014 | } |
| 2015 | |
| 2016 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2017 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 2018 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2019 | return 1; |
| 2020 | } |
| 2021 | |
| 2022 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2023 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 2024 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2025 | return 1; |
| 2026 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2027 | return 1; |
| 2028 | } |
| 2029 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2030 | 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] | 2031 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2032 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2033 | } |
| 2034 | } |
| 2035 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2036 | if (strcmp(args[1], "agent") == 0) { |
| 2037 | struct server *sv; |
| 2038 | |
| 2039 | sv = expect_server_admin(s, si, args[2]); |
| 2040 | if (!sv) |
| 2041 | return 1; |
| 2042 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2043 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2044 | return 1; |
| 2045 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2046 | else if (strcmp(args[1], "health") == 0) { |
| 2047 | struct server *sv; |
| 2048 | |
| 2049 | sv = expect_server_admin(s, si, args[2]); |
| 2050 | if (!sv) |
| 2051 | return 1; |
| 2052 | |
| 2053 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2054 | return 1; |
| 2055 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2056 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2057 | struct server *sv; |
| 2058 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2059 | sv = expect_server_admin(s, si, args[2]); |
| 2060 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2061 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2062 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2063 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2064 | return 1; |
| 2065 | } |
| 2066 | else if (strcmp(args[1], "frontend") == 0) { |
| 2067 | struct proxy *px; |
| 2068 | |
| 2069 | px = expect_frontend_admin(s, si, args[2]); |
| 2070 | if (!px) |
| 2071 | return 1; |
| 2072 | |
| 2073 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2074 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 2075 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2076 | return 1; |
| 2077 | } |
| 2078 | |
| 2079 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2080 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 2081 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2082 | return 1; |
| 2083 | } |
| 2084 | |
| 2085 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2086 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 2087 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2088 | return 1; |
| 2089 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2090 | return 1; |
| 2091 | } |
| 2092 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2093 | 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] | 2094 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2095 | return 1; |
| 2096 | } |
| 2097 | } |
| 2098 | else if (strcmp(args[0], "shutdown") == 0) { |
| 2099 | if (strcmp(args[1], "frontend") == 0) { |
| 2100 | struct proxy *px; |
| 2101 | |
| 2102 | px = expect_frontend_admin(s, si, args[2]); |
| 2103 | if (!px) |
| 2104 | return 1; |
| 2105 | |
| 2106 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2107 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 2108 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2109 | return 1; |
| 2110 | } |
| 2111 | |
| 2112 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2113 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2114 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2115 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2116 | stop_proxy(px); |
| 2117 | return 1; |
| 2118 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2119 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2120 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2121 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2122 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2123 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2124 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2125 | return 1; |
| 2126 | } |
| 2127 | |
| 2128 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2129 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2130 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2131 | return 1; |
| 2132 | } |
| 2133 | |
| 2134 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2135 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2136 | /* first, look for the requested stream in the stream table */ |
| 2137 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2138 | if (sess == ptr) |
| 2139 | break; |
| 2140 | } |
| 2141 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2142 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2143 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2144 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2145 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2146 | return 1; |
| 2147 | } |
| 2148 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2149 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2150 | return 1; |
| 2151 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2152 | else if (strcmp(args[1], "sessions") == 0) { |
| 2153 | if (strcmp(args[2], "server") == 0) { |
| 2154 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2155 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2156 | |
| 2157 | sv = expect_server_admin(s, si, args[3]); |
| 2158 | if (!sv) |
| 2159 | return 1; |
| 2160 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2161 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2162 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2163 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2164 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2165 | |
| 2166 | return 1; |
| 2167 | } |
| 2168 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2169 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2170 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2171 | return 1; |
| 2172 | } |
| 2173 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2174 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2175 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2176 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2177 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2178 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2179 | } |
| 2180 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2181 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2182 | if (args[1][0] == 'm') |
| 2183 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2184 | else |
| 2185 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2186 | |
| 2187 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2188 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2189 | if (!*args[2] || !*args[3]) { |
| 2190 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2191 | appctx->st0 = STAT_CLI_PRINT; |
| 2192 | return 1; |
| 2193 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2194 | } |
| 2195 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2196 | else { |
| 2197 | if (!*args[2] || !*args[3]) { |
| 2198 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2199 | appctx->st0 = STAT_CLI_PRINT; |
| 2200 | return 1; |
| 2201 | } |
| 2202 | } |
| 2203 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2204 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2205 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2206 | if (!appctx->ctx.map.ref || |
| 2207 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2208 | 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] | 2209 | appctx->st0 = STAT_CLI_PRINT; |
| 2210 | return 1; |
| 2211 | } |
| 2212 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2213 | /* If the entry identifier start with a '#', it is considered as |
| 2214 | * pointer id |
| 2215 | */ |
| 2216 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2217 | struct pat_ref_elt *ref; |
| 2218 | long long int conv; |
| 2219 | char *error; |
| 2220 | |
| 2221 | /* Convert argument to integer value. */ |
| 2222 | conv = strtoll(&args[3][1], &error, 16); |
| 2223 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2224 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2225 | appctx->st0 = STAT_CLI_PRINT; |
| 2226 | return 1; |
| 2227 | } |
| 2228 | |
| 2229 | /* Convert and check integer to pointer. */ |
| 2230 | ref = (struct pat_ref_elt *)(long)conv; |
| 2231 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2232 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2233 | appctx->st0 = STAT_CLI_PRINT; |
| 2234 | return 1; |
| 2235 | } |
| 2236 | |
| 2237 | /* Try to delete the entry. */ |
| 2238 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2239 | /* The entry is not found, send message. */ |
| 2240 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2241 | appctx->st0 = STAT_CLI_PRINT; |
| 2242 | return 1; |
| 2243 | } |
| 2244 | } |
| 2245 | else { |
| 2246 | /* Else, use the entry identifier as pattern |
| 2247 | * string and try to delete the entry. |
| 2248 | */ |
| 2249 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2250 | /* The entry is not found, send message. */ |
| 2251 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2252 | appctx->st0 = STAT_CLI_PRINT; |
| 2253 | return 1; |
| 2254 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2255 | } |
| 2256 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2257 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2258 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2259 | return 1; |
| 2260 | } |
| 2261 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2262 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2263 | appctx->st0 = STAT_CLI_PRINT; |
| 2264 | return 1; |
| 2265 | } |
| 2266 | } |
| 2267 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2268 | if (strcmp(args[1], "map") == 0 || |
| 2269 | strcmp(args[1], "acl") == 0) { |
| 2270 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2271 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2272 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2273 | /* Set flags. */ |
| 2274 | if (args[1][0] == 'm') |
| 2275 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2276 | else |
| 2277 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2278 | |
| 2279 | /* If the keywork is "map", we expect three parameters, if it |
| 2280 | * is "acl", we expect only two parameters |
| 2281 | */ |
| 2282 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2283 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2284 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2285 | appctx->st0 = STAT_CLI_PRINT; |
| 2286 | return 1; |
| 2287 | } |
| 2288 | } |
| 2289 | else { |
| 2290 | if (!*args[2] || !*args[3]) { |
| 2291 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2292 | appctx->st0 = STAT_CLI_PRINT; |
| 2293 | return 1; |
| 2294 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2295 | } |
| 2296 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2297 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2298 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2299 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2300 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2301 | 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] | 2302 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2303 | 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] | 2304 | appctx->st0 = STAT_CLI_PRINT; |
| 2305 | return 1; |
| 2306 | } |
| 2307 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2308 | /* The command "add acl" is prohibited if the reference |
| 2309 | * use samples. |
| 2310 | */ |
| 2311 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2312 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2313 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2314 | "You must use the command 'add map' to add values.\n"; |
| 2315 | appctx->st0 = STAT_CLI_PRINT; |
| 2316 | return 1; |
| 2317 | } |
| 2318 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2319 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2320 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2321 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2322 | 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] | 2323 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2324 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2325 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2326 | if (err) |
| 2327 | memprintf(&err, "%s.\n", err); |
| 2328 | appctx->ctx.cli.err = err; |
| 2329 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2330 | return 1; |
| 2331 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2332 | |
| 2333 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2334 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2335 | return 1; |
| 2336 | } |
| 2337 | else { /* unknown "del" parameter */ |
| 2338 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2339 | appctx->st0 = STAT_CLI_PRINT; |
| 2340 | return 1; |
| 2341 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2342 | } |
| 2343 | 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] | 2344 | return 0; |
| 2345 | } |
| 2346 | return 1; |
| 2347 | } |
| 2348 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2349 | /* 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] | 2350 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2351 | * state machine handling requests and various responses. We read a request, |
| 2352 | * 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] | 2353 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2354 | * 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] | 2355 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2356 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2357 | static void cli_io_handler(struct appctx *appctx) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2358 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2359 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2360 | struct channel *req = si_oc(si); |
| 2361 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2362 | int reql; |
| 2363 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2364 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2365 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2366 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2367 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2368 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2369 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2370 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2371 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2372 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2373 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2374 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2375 | /* Let's close for real now. We just close the request |
| 2376 | * side, the conditions below will complete if needed. |
| 2377 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2378 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2379 | break; |
| 2380 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2381 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2382 | /* ensure we have some output room left in the event we |
| 2383 | * would want to return some info right after parsing. |
| 2384 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2385 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2386 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2387 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2388 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2389 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2390 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2391 | if (reql <= 0) { /* closed or EOL not found */ |
| 2392 | if (reql == 0) |
| 2393 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2394 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2395 | continue; |
| 2396 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2397 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2398 | /* seek for a possible semi-colon. If we find one, we |
| 2399 | * replace it with an LF and skip only this part. |
| 2400 | */ |
| 2401 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2402 | if (trash.str[len] == ';') { |
| 2403 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2404 | reql = len + 1; |
| 2405 | break; |
| 2406 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2407 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2408 | /* now it is time to check that we have a full line, |
| 2409 | * remove the trailing \n and possibly \r, then cut the |
| 2410 | * line. |
| 2411 | */ |
| 2412 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2413 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2414 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2415 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2416 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2417 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2418 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2419 | len--; |
| 2420 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2421 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2422 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2423 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2424 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2425 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2426 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2427 | continue; |
| 2428 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2429 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2430 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2431 | else if (strcmp(trash.str, "help") == 0 || |
| 2432 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2433 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2434 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2435 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2436 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2437 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2438 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2439 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2440 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2441 | /* if prompt is disabled, print help on empty lines, |
| 2442 | * so that the user at least knows how to enable |
| 2443 | * prompt and find help. |
| 2444 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2445 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2446 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2450 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2451 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2452 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2453 | 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] | 2454 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2455 | cli_release_handler(appctx); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2456 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2457 | continue; |
| 2458 | } |
| 2459 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2460 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2461 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2462 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2463 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2464 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2465 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2466 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2467 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2468 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2469 | free(appctx->ctx.cli.err); |
| 2470 | appctx->st0 = STAT_CLI_PROMPT; |
| 2471 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2472 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2473 | si_applet_cant_put(si); |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2474 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2475 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2476 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2477 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2478 | break; |
| 2479 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2480 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2481 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2482 | break; |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 2483 | case STAT_CLI_O_RESOLVERS: |
| 2484 | if (stats_dump_resolvers_to_buffer(si)) |
| 2485 | appctx->st0 = STAT_CLI_PROMPT; |
| 2486 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2487 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2488 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2489 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2490 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2491 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2492 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2493 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2494 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2495 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2496 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2497 | if (stats_table_request(si, appctx->st0)) |
| 2498 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2499 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2500 | case STAT_CLI_O_PATS: |
| 2501 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2502 | appctx->st0 = STAT_CLI_PROMPT; |
| 2503 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2504 | case STAT_CLI_O_PAT: |
| 2505 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2506 | appctx->st0 = STAT_CLI_PROMPT; |
| 2507 | break; |
| 2508 | case STAT_CLI_O_MLOOK: |
| 2509 | if (stats_map_lookup(si)) |
| 2510 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2511 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2512 | case STAT_CLI_O_POOLS: |
| 2513 | if (stats_dump_pools_to_buffer(si)) |
| 2514 | appctx->st0 = STAT_CLI_PROMPT; |
| 2515 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2516 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2517 | case STAT_CLI_O_TLSK: |
| 2518 | if (stats_tlskeys_list(si)) |
| 2519 | appctx->st0 = STAT_CLI_PROMPT; |
| 2520 | break; |
| 2521 | #endif |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2522 | default: /* abnormal state */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2523 | cli_release_handler(appctx); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2524 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2525 | break; |
| 2526 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2527 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2528 | /* 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] | 2529 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2530 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2531 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2532 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2533 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2534 | } |
| 2535 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2536 | /* 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] | 2537 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2538 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2539 | |
| 2540 | /* Now we close the output if one of the writers did so, |
| 2541 | * or if we're not in interactive mode and the request |
| 2542 | * buffer is empty. This still allows pipelined requests |
| 2543 | * to be sent in non-interactive mode. |
| 2544 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2545 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2546 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2547 | continue; |
| 2548 | } |
| 2549 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2550 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2551 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2552 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2553 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2554 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2555 | 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] | 2556 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2557 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2558 | /* 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] | 2559 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2560 | * we forward the close to the request side so that it flows upstream to |
| 2561 | * the client. |
| 2562 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2563 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2564 | } |
| 2565 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2566 | 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] | 2567 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2568 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2569 | /* We have no more processing to do, and nothing more to send, and |
| 2570 | * the client side has closed. So we'll forward this state downstream |
| 2571 | * on the response buffer. |
| 2572 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2573 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2574 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2575 | } |
| 2576 | |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 2577 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2578 | 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] | 2579 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2580 | 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] | 2581 | } |
| 2582 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2583 | /* This function dumps information onto the stream interface's read buffer. |
| 2584 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2585 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2586 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2587 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2588 | { |
| 2589 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2590 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2591 | #ifdef USE_OPENSSL |
| 2592 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2593 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2594 | int ssl_reuse = 0; |
| 2595 | |
| 2596 | if (ssl_key_rate < ssl_sess_rate) { |
| 2597 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2598 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2599 | } |
| 2600 | #endif |
| 2601 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2602 | chunk_printf(&trash, |
| 2603 | "Name: " PRODUCT_NAME "\n" |
| 2604 | "Version: " HAPROXY_VERSION "\n" |
| 2605 | "Release_date: " HAPROXY_DATE "\n" |
| 2606 | "Nbproc: %d\n" |
| 2607 | "Process_num: %d\n" |
| 2608 | "Pid: %d\n" |
| 2609 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2610 | "Uptime_sec: %d\n" |
| 2611 | "Memmax_MB: %d\n" |
| 2612 | "Ulimit-n: %d\n" |
| 2613 | "Maxsock: %d\n" |
| 2614 | "Maxconn: %d\n" |
| 2615 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2616 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2617 | "CumConns: %d\n" |
Warren Turkal | b197d7f | 2015-01-27 15:04:16 -0800 | [diff] [blame] | 2618 | "CumReq: %u\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2619 | #ifdef USE_OPENSSL |
| 2620 | "MaxSslConns: %d\n" |
| 2621 | "CurrSslConns: %d\n" |
| 2622 | "CumSslConns: %d\n" |
| 2623 | #endif |
| 2624 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2625 | "PipesUsed: %d\n" |
| 2626 | "PipesFree: %d\n" |
| 2627 | "ConnRate: %d\n" |
| 2628 | "ConnRateLimit: %d\n" |
| 2629 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2630 | "SessRate: %d\n" |
| 2631 | "SessRateLimit: %d\n" |
| 2632 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2633 | #ifdef USE_OPENSSL |
| 2634 | "SslRate: %d\n" |
| 2635 | "SslRateLimit: %d\n" |
| 2636 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2637 | "SslFrontendKeyRate: %d\n" |
| 2638 | "SslFrontendMaxKeyRate: %d\n" |
| 2639 | "SslFrontendSessionReuse_pct: %d\n" |
| 2640 | "SslBackendKeyRate: %d\n" |
| 2641 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2642 | "SslCacheLookups: %u\n" |
| 2643 | "SslCacheMisses: %u\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2644 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2645 | "CompressBpsIn: %u\n" |
| 2646 | "CompressBpsOut: %u\n" |
| 2647 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2648 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2649 | "ZlibMemUsage: %ld\n" |
| 2650 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2651 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2652 | "Tasks: %d\n" |
| 2653 | "Run_queue: %d\n" |
| 2654 | "Idle_pct: %d\n" |
| 2655 | "node: %s\n" |
| 2656 | "description: %s\n" |
| 2657 | "", |
| 2658 | global.nbproc, |
| 2659 | relative_pid, |
| 2660 | pid, |
| 2661 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2662 | up, |
| 2663 | global.rlimit_memmax, |
| 2664 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2665 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2666 | actconn, totalconn, global.req_count, |
| 2667 | #ifdef USE_OPENSSL |
| 2668 | global.maxsslconn, sslconns, totalsslconns, |
| 2669 | #endif |
| 2670 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2671 | 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] | 2672 | 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] | 2673 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2674 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2675 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2676 | ssl_reuse, |
| 2677 | 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] | 2678 | global.shctx_lookups, global.shctx_misses, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2679 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2680 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2681 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2682 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2683 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2684 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2685 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2686 | global.node, global.desc ? global.desc : "" |
| 2687 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2688 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2689 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2690 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2691 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2692 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2693 | |
| 2694 | return 1; |
| 2695 | } |
| 2696 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2697 | /* This function dumps memory usage information onto the stream interface's |
| 2698 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2699 | * completion. No state is used. |
| 2700 | */ |
| 2701 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2702 | { |
| 2703 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2704 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2705 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2706 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2707 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2708 | return 1; |
| 2709 | } |
| 2710 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2711 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2712 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2713 | * 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] | 2714 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2715 | 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] | 2716 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2717 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2718 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2719 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2720 | if (!(px->cap & PR_CAP_FE)) |
| 2721 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2722 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2723 | 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] | 2724 | return 0; |
| 2725 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2726 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2727 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2728 | /* name, queue */ |
| 2729 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2730 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2731 | 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] | 2732 | /* Column sub-heading for Enable or Disable server */ |
| 2733 | chunk_appendf(&trash, "<td></td>"); |
| 2734 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2735 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2736 | chunk_appendf(&trash, |
| 2737 | "<td class=ac>" |
| 2738 | "<a name=\"%s/Frontend\"></a>" |
| 2739 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2740 | "<td colspan=3></td>" |
| 2741 | "", |
| 2742 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2743 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2744 | chunk_appendf(&trash, |
| 2745 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2746 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2747 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2748 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2749 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2750 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2751 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2752 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2753 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2754 | if (px->mode == PR_MODE_HTTP) |
| 2755 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2756 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2757 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2758 | |
| 2759 | chunk_appendf(&trash, |
| 2760 | "</table></div></u></td>" |
| 2761 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2762 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2763 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2764 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2765 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2766 | U2H(px->fe_counters.sps_max), |
| 2767 | U2H(px->fe_counters.cps_max), |
| 2768 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2769 | |
| 2770 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2771 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2772 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2773 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2774 | |
| 2775 | chunk_appendf(&trash, |
| 2776 | "</table></div></u></td>" |
| 2777 | /* sessions rate : limit */ |
| 2778 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2779 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2780 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2781 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2782 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2783 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2784 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2785 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2786 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2787 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2788 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2789 | U2H(px->fe_counters.cum_sess), |
| 2790 | U2H(px->fe_counters.cum_conn), |
| 2791 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2792 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2793 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2794 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2795 | chunk_appendf(&trash, |
| 2796 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2797 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2798 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2799 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2800 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2801 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2802 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2803 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2804 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2805 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2806 | U2H(px->fe_counters.p.http.cum_req), |
| 2807 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2808 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2809 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2810 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2811 | (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] | 2812 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2813 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2814 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2815 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2816 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2817 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2818 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2819 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2820 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2821 | /* sessions: lbtot, lastsess */ |
| 2822 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2823 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2824 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2825 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2826 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2827 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2828 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2829 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 2830 | "<td>%s%s<div class=tips><table class=det>" |
| 2831 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 2832 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 2833 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2834 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 2835 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2836 | "</table></div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2837 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2838 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 2839 | U2H(px->fe_counters.bytes_out), |
| 2840 | U2H(px->fe_counters.comp_in), |
| 2841 | U2H(px->fe_counters.comp_out), |
| 2842 | px->fe_counters.comp_in ? (int)(px->fe_counters.comp_out * 100 / px->fe_counters.comp_in) : 0, |
| 2843 | U2H(px->fe_counters.comp_byp), |
| 2844 | U2H(px->fe_counters.comp_in - px->fe_counters.comp_out), |
| 2845 | px->fe_counters.bytes_out ? (int)((px->fe_counters.comp_in - px->fe_counters.comp_out) * 100 / px->fe_counters.bytes_out) : 0, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2846 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2847 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2848 | chunk_appendf(&trash, |
| 2849 | /* denied: req, resp */ |
| 2850 | "<td>%s</td><td>%s</td>" |
| 2851 | /* errors : request, connect, response */ |
| 2852 | "<td>%s</td><td></td><td></td>" |
| 2853 | /* warnings: retries, redispatches */ |
| 2854 | "<td></td><td></td>" |
| 2855 | /* server status : reflect frontend status */ |
| 2856 | "<td class=ac>%s</td>" |
| 2857 | /* rest of server: nothing */ |
| 2858 | "<td class=ac colspan=8></td></tr>" |
| 2859 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2860 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2861 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2862 | px->state == PR_STREADY ? "OPEN" : |
| 2863 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2864 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2865 | else { /* CSV mode */ |
| 2866 | chunk_appendf(&trash, |
| 2867 | /* pxid, name, queue cur, queue max, */ |
| 2868 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2869 | /* sessions : current, max, limit, total */ |
| 2870 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2871 | /* bytes : in, out */ |
| 2872 | "%lld,%lld," |
| 2873 | /* denied: req, resp */ |
| 2874 | "%lld,%lld," |
| 2875 | /* errors : request, connect, response */ |
| 2876 | "%lld,,," |
| 2877 | /* warnings: retries, redispatches */ |
| 2878 | ",," |
| 2879 | /* server status : reflect frontend status */ |
| 2880 | "%s," |
| 2881 | /* rest of server: nothing */ |
| 2882 | ",,,,,,,," |
| 2883 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2884 | "%d,%d,0,,,,%d," |
| 2885 | /* rate, rate_lim, rate_max */ |
| 2886 | "%u,%u,%u," |
| 2887 | /* check_status, check_code, check_duration */ |
| 2888 | ",,,", |
| 2889 | px->id, |
| 2890 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2891 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2892 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2893 | px->fe_counters.failed_req, |
| 2894 | px->state == PR_STREADY ? "OPEN" : |
| 2895 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2896 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2897 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2898 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2899 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2900 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2901 | if (px->mode == PR_MODE_HTTP) { |
| 2902 | for (i=1; i<6; i++) |
| 2903 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2904 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2905 | } |
| 2906 | else |
| 2907 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2908 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2909 | /* failed health analyses */ |
| 2910 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2911 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2912 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2913 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2914 | read_freq_ctr(&px->fe_req_per_sec), |
| 2915 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2916 | |
| 2917 | /* errors: cli_aborts, srv_aborts */ |
| 2918 | chunk_appendf(&trash, ",,"); |
| 2919 | |
| 2920 | /* compression: in, out, bypassed */ |
| 2921 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2922 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2923 | |
| 2924 | /* compression: comp_rsp */ |
| 2925 | chunk_appendf(&trash, "%lld,", |
| 2926 | px->fe_counters.p.http.comp_rsp); |
| 2927 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 2928 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 2929 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 2930 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2931 | /* finish with EOL */ |
| 2932 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2933 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2934 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2935 | } |
| 2936 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2937 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2938 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2939 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2940 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2941 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2942 | 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] | 2943 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2944 | struct appctx *appctx = __objt_appctx(si->end); |
| 2945 | |
| 2946 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2947 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2948 | 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] | 2949 | /* Column sub-heading for Enable or Disable server */ |
| 2950 | chunk_appendf(&trash, "<td></td>"); |
| 2951 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2952 | chunk_appendf(&trash, |
| 2953 | /* frontend name, listener name */ |
| 2954 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2955 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2956 | "", |
| 2957 | px->id, l->name, |
| 2958 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2959 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2960 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2961 | if (flags & ST_SHLGNDS) { |
| 2962 | char str[INET6_ADDRSTRLEN]; |
| 2963 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2964 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2965 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2966 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2967 | port = get_host_port(&l->addr); |
| 2968 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2969 | case AF_INET: |
| 2970 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2971 | break; |
| 2972 | case AF_INET6: |
| 2973 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2974 | break; |
| 2975 | case AF_UNIX: |
| 2976 | chunk_appendf(&trash, "unix, "); |
| 2977 | break; |
| 2978 | case -1: |
| 2979 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2980 | break; |
| 2981 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2982 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2983 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2984 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2985 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2986 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2987 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2988 | /* queue */ |
| 2989 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2990 | /* sessions rate: current, max, limit */ |
| 2991 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2992 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2993 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 2994 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2995 | /* bytes: in, out */ |
| 2996 | "<td>%s</td><td>%s</td>" |
| 2997 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2998 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2999 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 3000 | 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] | 3001 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3002 | chunk_appendf(&trash, |
| 3003 | /* denied: req, resp */ |
| 3004 | "<td>%s</td><td>%s</td>" |
| 3005 | /* errors: request, connect, response */ |
| 3006 | "<td>%s</td><td></td><td></td>" |
| 3007 | /* warnings: retries, redispatches */ |
| 3008 | "<td></td><td></td>" |
| 3009 | /* server status: reflect listener status */ |
| 3010 | "<td class=ac>%s</td>" |
| 3011 | /* rest of server: nothing */ |
| 3012 | "<td class=ac colspan=8></td></tr>" |
| 3013 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3014 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 3015 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3016 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 3017 | } |
| 3018 | else { /* CSV mode */ |
| 3019 | chunk_appendf(&trash, |
| 3020 | /* pxid, name, queue cur, queue max, */ |
| 3021 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3022 | /* sessions: current, max, limit, total */ |
| 3023 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3024 | /* bytes: in, out */ |
| 3025 | "%lld,%lld," |
| 3026 | /* denied: req, resp */ |
| 3027 | "%lld,%lld," |
| 3028 | /* errors: request, connect, response */ |
| 3029 | "%lld,,," |
| 3030 | /* warnings: retries, redispatches */ |
| 3031 | ",," |
| 3032 | /* server status: reflect listener status */ |
| 3033 | "%s," |
| 3034 | /* rest of server: nothing */ |
| 3035 | ",,,,,,,," |
| 3036 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3037 | "%d,%d,%d,,,,%d," |
| 3038 | /* rate, rate_lim, rate_max */ |
| 3039 | ",,," |
| 3040 | /* check_status, check_code, check_duration */ |
| 3041 | ",,," |
| 3042 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3043 | ",,,,,," |
| 3044 | /* failed health analyses */ |
| 3045 | "," |
| 3046 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3047 | ",,," |
| 3048 | /* errors: cli_aborts, srv_aborts */ |
| 3049 | ",," |
| 3050 | /* compression: in, out, bypassed, comp_rsp */ |
| 3051 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3052 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 3053 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3054 | "\n", |
| 3055 | px->id, l->name, |
| 3056 | l->nbconn, l->counters->conn_max, |
| 3057 | l->maxconn, l->counters->cum_conn, |
| 3058 | l->counters->bytes_in, l->counters->bytes_out, |
| 3059 | l->counters->denied_req, l->counters->denied_resp, |
| 3060 | l->counters->failed_req, |
| 3061 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 3062 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 3063 | } |
| 3064 | return 1; |
| 3065 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3066 | |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3067 | enum srv_stats_state { |
| 3068 | SRV_STATS_STATE_DOWN = 0, |
| 3069 | SRV_STATS_STATE_DOWN_AGENT, |
| 3070 | SRV_STATS_STATE_GOING_UP, |
| 3071 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 3072 | SRV_STATS_STATE_UP, |
| 3073 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 3074 | SRV_STATS_STATE_NOLB, |
| 3075 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 3076 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3077 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3078 | SRV_STATS_STATE_NO_CHECK, |
| 3079 | |
| 3080 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 3081 | }; |
| 3082 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3083 | enum srv_stats_colour { |
| 3084 | SRV_STATS_COLOUR_DOWN = 0, |
| 3085 | SRV_STATS_COLOUR_GOING_UP, |
| 3086 | SRV_STATS_COLOUR_GOING_DOWN, |
| 3087 | SRV_STATS_COLOUR_UP, |
| 3088 | SRV_STATS_COLOUR_NOLB, |
| 3089 | SRV_STATS_COLOUR_DRAINING, |
| 3090 | SRV_STATS_COLOUR_NO_CHECK, |
| 3091 | |
| 3092 | SRV_STATS_COLOUR_COUNT, /* Must be last */ |
| 3093 | }; |
| 3094 | |
| 3095 | static const char *srv_stats_colour_st[SRV_STATS_COLOUR_COUNT] = { |
| 3096 | [SRV_STATS_COLOUR_DOWN] = "down", |
| 3097 | [SRV_STATS_COLOUR_GOING_UP] = "going_up", |
| 3098 | [SRV_STATS_COLOUR_GOING_DOWN] = "going_down", |
| 3099 | [SRV_STATS_COLOUR_UP] = "up", |
| 3100 | [SRV_STATS_COLOUR_NOLB] = "nolb", |
| 3101 | [SRV_STATS_COLOUR_DRAINING] = "draining", |
| 3102 | [SRV_STATS_COLOUR_NO_CHECK] = "no_check", |
| 3103 | }; |
| 3104 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3105 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 3106 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 3107 | * 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] | 3108 | * if it emits anything, zero otherwise. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3109 | */ |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3110 | 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] | 3111 | enum srv_stats_state state, enum srv_stats_colour colour) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3112 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3113 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3114 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3115 | char str[INET6_ADDRSTRLEN]; |
| 3116 | struct chunk src; |
| 3117 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3118 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3119 | /* we have "via" which is the tracked server as described in the configuration, |
| 3120 | * and "ref" which is the checked server and the end of the chain. |
| 3121 | */ |
| 3122 | via = sv->track ? sv->track : sv; |
| 3123 | ref = via; |
| 3124 | while (ref->track) |
| 3125 | ref = ref->track; |
| 3126 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3127 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3128 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3129 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 3130 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 3131 | [SRV_STATS_STATE_GOING_UP] = "DN %d/%d ↑", |
| 3132 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d ↓", |
| 3133 | [SRV_STATS_STATE_UP] = "UP", |
| 3134 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d ↓", |
| 3135 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 3136 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d ↓", |
| 3137 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3138 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3139 | [SRV_STATS_STATE_NO_CHECK] = "<i>no check</i>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3140 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3141 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3142 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3143 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 3144 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3145 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3146 | "<tr class=\"%s_%s\">", |
| 3147 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", srv_stats_colour_st[colour]); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3148 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3149 | 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] | 3150 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3151 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3152 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3153 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3154 | chunk_appendf(&trash, |
| 3155 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3156 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3157 | "", |
| 3158 | px->id, sv->id, |
| 3159 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3160 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3161 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3162 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3163 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3164 | |
| 3165 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 3166 | case AF_INET: |
| 3167 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 3168 | break; |
| 3169 | case AF_INET6: |
| 3170 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 3171 | break; |
| 3172 | case AF_UNIX: |
| 3173 | chunk_appendf(&trash, "unix, "); |
| 3174 | break; |
| 3175 | case -1: |
| 3176 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3177 | break; |
| 3178 | default: /* address family not supported */ |
| 3179 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3180 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3181 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3182 | /* id */ |
| 3183 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3184 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3185 | /* cookie */ |
| 3186 | if (sv->cookie) { |
| 3187 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3188 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3189 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3190 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3191 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3192 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3193 | } |
| 3194 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3195 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3196 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3197 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3198 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3199 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3200 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3201 | /* sessions rate : current, max, limit */ |
| 3202 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3203 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3204 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3205 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3206 | 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] | 3207 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3208 | |
| 3209 | chunk_appendf(&trash, |
| 3210 | /* sessions: current, max, limit, total */ |
| 3211 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3212 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3213 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3214 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3215 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3216 | U2H(sv->counters.cum_sess), |
| 3217 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3218 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3219 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3220 | if (px->mode == PR_MODE_HTTP) { |
| 3221 | unsigned long long tot; |
| 3222 | for (tot = i = 0; i < 6; i++) |
| 3223 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3224 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3225 | chunk_appendf(&trash, |
| 3226 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3227 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3228 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3229 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3230 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3231 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3232 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3233 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3234 | U2H(tot), |
| 3235 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3236 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3237 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3238 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3239 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3240 | 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] | 3241 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3242 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3243 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3244 | 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))); |
| 3245 | 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))); |
| 3246 | if (px->mode == PR_MODE_HTTP) |
| 3247 | 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))); |
| 3248 | 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))); |
| 3249 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3250 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3251 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3252 | /* sessions: lbtot, last */ |
| 3253 | "<td>%s</td><td>%s</td>", |
| 3254 | U2H(sv->counters.cum_lbconn), |
| 3255 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3256 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3257 | chunk_appendf(&trash, |
| 3258 | /* bytes : in, out */ |
| 3259 | "<td>%s</td><td>%s</td>" |
| 3260 | /* denied: req, resp */ |
| 3261 | "<td></td><td>%s</td>" |
| 3262 | /* errors : request, connect */ |
| 3263 | "<td></td><td>%s</td>" |
| 3264 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3265 | "<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] | 3266 | /* warnings: retries, redispatches */ |
| 3267 | "<td>%lld</td><td>%lld</td>" |
| 3268 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3269 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3270 | U2H(sv->counters.failed_secu), |
| 3271 | U2H(sv->counters.failed_conns), |
| 3272 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3273 | sv->counters.cli_aborts, |
| 3274 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3275 | sv->counters.retries, sv->counters.redispatches); |
| 3276 | |
| 3277 | /* status, lest check */ |
| 3278 | chunk_appendf(&trash, "<td class=ac>"); |
| 3279 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3280 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3281 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3282 | chunk_appendf(&trash, "MAINT"); |
| 3283 | } |
Simon Horman | 0766e44 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3284 | 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] | 3285 | 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] | 3286 | /* DOWN (agent) */ |
| 3287 | 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] | 3288 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3289 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3290 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3291 | chunk_appendf(&trash, |
| 3292 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3293 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3294 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3295 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3296 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3297 | if ((sv->state == SRV_ST_STOPPED) && |
| 3298 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3299 | chunk_appendf(&trash, |
| 3300 | "</td><td class=ac><u> %s%s", |
| 3301 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3302 | get_check_status_info(sv->agent.status)); |
| 3303 | |
| 3304 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3305 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3306 | |
| 3307 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3308 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3309 | |
| 3310 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3311 | get_check_status_description(sv->agent.status)); |
| 3312 | if (*sv->agent.desc) { |
| 3313 | chunk_appendf(&trash, ": "); |
| 3314 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3315 | chunk_htmlencode(&trash, &src); |
| 3316 | } |
| 3317 | chunk_appendf(&trash, "</div></u>"); |
| 3318 | } |
| 3319 | 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] | 3320 | chunk_appendf(&trash, |
| 3321 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3322 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3323 | get_check_status_info(sv->check.status)); |
| 3324 | |
| 3325 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3326 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3327 | |
| 3328 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3329 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3330 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3331 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3332 | get_check_status_description(sv->check.status)); |
| 3333 | if (*sv->check.desc) { |
| 3334 | chunk_appendf(&trash, ": "); |
| 3335 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3336 | chunk_htmlencode(&trash, &src); |
| 3337 | } |
| 3338 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3339 | } |
| 3340 | else |
| 3341 | chunk_appendf(&trash, "</td><td>"); |
| 3342 | |
| 3343 | chunk_appendf(&trash, |
| 3344 | /* weight */ |
| 3345 | "</td><td class=ac>%d</td>" |
| 3346 | /* act, bck */ |
| 3347 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3348 | "", |
| 3349 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3350 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3351 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3352 | |
| 3353 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3354 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3355 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3356 | |
| 3357 | if (ref->observe) |
| 3358 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3359 | |
| 3360 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3361 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3362 | "<td>%lld</td><td>%s</td>" |
| 3363 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3364 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3365 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3366 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3367 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3368 | /* tracking a server */ |
| 3369 | chunk_appendf(&trash, |
| 3370 | "<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] | 3371 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3372 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3373 | else |
| 3374 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3375 | |
| 3376 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3377 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3378 | 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] | 3379 | else |
| 3380 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3381 | } |
| 3382 | else { /* CSV mode */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3383 | struct chunk *out = get_trash_chunk(); |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3384 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3385 | [SRV_STATS_STATE_DOWN] = "DOWN,", |
| 3386 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent),", |
| 3387 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d,", |
| 3388 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d,", |
| 3389 | [SRV_STATS_STATE_UP] = "UP,", |
| 3390 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d,", |
| 3391 | [SRV_STATS_STATE_NOLB] = "NOLB,", |
| 3392 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d,", |
| 3393 | [SRV_STATS_STATE_DRAIN] = "DRAIN,", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3394 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3395 | [SRV_STATS_STATE_NO_CHECK] = "no check," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3396 | }; |
| 3397 | |
| 3398 | chunk_appendf(&trash, |
| 3399 | /* pxid, name */ |
| 3400 | "%s,%s," |
| 3401 | /* queue : current, max */ |
| 3402 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3403 | /* sessions : current, max, limit, total */ |
| 3404 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3405 | /* bytes : in, out */ |
| 3406 | "%lld,%lld," |
| 3407 | /* denied: req, resp */ |
| 3408 | ",%lld," |
| 3409 | /* errors : request, connect, response */ |
| 3410 | ",%lld,%lld," |
| 3411 | /* warnings: retries, redispatches */ |
| 3412 | "%lld,%lld," |
| 3413 | "", |
| 3414 | px->id, sv->id, |
| 3415 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3416 | 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] | 3417 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3418 | sv->counters.failed_secu, |
| 3419 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3420 | sv->counters.retries, sv->counters.redispatches); |
| 3421 | |
| 3422 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3423 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3424 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3425 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3426 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3427 | else |
| 3428 | chunk_appendf(&trash, |
| 3429 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3430 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3431 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3432 | |
| 3433 | chunk_appendf(&trash, |
| 3434 | /* weight, active, backup */ |
| 3435 | "%d,%d,%d," |
| 3436 | "", |
| 3437 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3438 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3439 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3440 | |
| 3441 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3442 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3443 | chunk_appendf(&trash, |
| 3444 | "%lld,%lld,%d,%d,", |
| 3445 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3446 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3447 | else |
| 3448 | chunk_appendf(&trash, ",,,,"); |
| 3449 | |
| 3450 | /* queue limit, pid, iid, sid, */ |
| 3451 | chunk_appendf(&trash, |
| 3452 | "%s," |
| 3453 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3454 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3455 | relative_pid, px->uuid, sv->puid); |
| 3456 | |
| 3457 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3458 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3459 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3460 | |
| 3461 | /* sessions: lbtot */ |
| 3462 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3463 | |
| 3464 | /* tracked */ |
| 3465 | if (sv->track) |
| 3466 | chunk_appendf(&trash, "%s/%s,", |
| 3467 | sv->track->proxy->id, sv->track->id); |
| 3468 | else |
| 3469 | chunk_appendf(&trash, ","); |
| 3470 | |
| 3471 | /* type */ |
| 3472 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3473 | |
| 3474 | /* rate */ |
| 3475 | chunk_appendf(&trash, "%u,,%u,", |
| 3476 | read_freq_ctr(&sv->sess_per_sec), |
| 3477 | sv->counters.sps_max); |
| 3478 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3479 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3480 | /* check_status */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3481 | chunk_appendf(&trash, "%s,", csv_enc(get_check_status_info(sv->check.status), 1, out)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3482 | |
| 3483 | /* check_code */ |
| 3484 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3485 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3486 | else |
| 3487 | chunk_appendf(&trash, ","); |
| 3488 | |
| 3489 | /* check_duration */ |
| 3490 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3491 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3492 | else |
| 3493 | chunk_appendf(&trash, ","); |
| 3494 | |
| 3495 | } |
| 3496 | else |
| 3497 | chunk_appendf(&trash, ",,,"); |
| 3498 | |
| 3499 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3500 | if (px->mode == PR_MODE_HTTP) { |
| 3501 | for (i=1; i<6; i++) |
| 3502 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3503 | |
| 3504 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3505 | } |
| 3506 | else |
| 3507 | chunk_appendf(&trash, ",,,,,,"); |
| 3508 | |
| 3509 | /* failed health analyses */ |
| 3510 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3511 | |
| 3512 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3513 | chunk_appendf(&trash, ",,,"); |
| 3514 | |
| 3515 | /* errors: cli_aborts, srv_aborts */ |
| 3516 | chunk_appendf(&trash, "%lld,%lld,", |
| 3517 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3518 | |
| 3519 | /* compression: in, out, bypassed, comp_rsp */ |
| 3520 | chunk_appendf(&trash, ",,,,"); |
| 3521 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3522 | /* lastsess */ |
| 3523 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3524 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3525 | /* capture of last check and agent statuses */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3526 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->check.desc), 1, out) : ""); |
| 3527 | chunk_appendf(&trash, "%s,", ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->agent.desc), 1, out) : ""); |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3528 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3529 | /* qtime, ctime, rtime, ttime, */ |
| 3530 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3531 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3532 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3533 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3534 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3535 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3536 | /* finish with EOL */ |
| 3537 | chunk_appendf(&trash, "\n"); |
| 3538 | } |
| 3539 | return 1; |
| 3540 | } |
| 3541 | |
| 3542 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3543 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3544 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3545 | */ |
| 3546 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3547 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3548 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3549 | struct chunk src; |
| 3550 | int i; |
| 3551 | |
| 3552 | if (!(px->cap & PR_CAP_BE)) |
| 3553 | return 0; |
| 3554 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3555 | 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] | 3556 | return 0; |
| 3557 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3558 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3559 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3560 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3561 | /* Column sub-heading for Enable or Disable server */ |
| 3562 | chunk_appendf(&trash, "<td></td>"); |
| 3563 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3564 | chunk_appendf(&trash, |
| 3565 | "<td class=ac>" |
| 3566 | /* name */ |
| 3567 | "%s<a name=\"%s/Backend\"></a>" |
| 3568 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3569 | "", |
| 3570 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3571 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3572 | |
| 3573 | if (flags & ST_SHLGNDS) { |
| 3574 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3575 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3576 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3577 | |
| 3578 | /* cookie */ |
| 3579 | if (px->cookie_name) { |
| 3580 | chunk_appendf(&trash, ", cookie: '"); |
| 3581 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3582 | chunk_htmlencode(&trash, &src); |
| 3583 | chunk_appendf(&trash, "'"); |
| 3584 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3585 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3589 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3590 | /* queue : current, max */ |
| 3591 | "<td>%s</td><td>%s</td><td></td>" |
| 3592 | /* sessions rate : current, max, limit */ |
| 3593 | "<td>%s</td><td>%s</td><td></td>" |
| 3594 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3595 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3596 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3597 | 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] | 3598 | |
| 3599 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3600 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3601 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3602 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3603 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3604 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3605 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3606 | U2H(px->be_counters.cum_conn), |
| 3607 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3608 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3609 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3610 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3611 | chunk_appendf(&trash, |
| 3612 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3613 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3614 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3615 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3616 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3617 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3618 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3619 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3620 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3621 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3622 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3623 | U2H(px->be_counters.p.http.cum_req), |
| 3624 | U2H(px->be_counters.p.http.rsp[1]), |
| 3625 | U2H(px->be_counters.p.http.rsp[2]), |
| 3626 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3627 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3628 | (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] | 3629 | U2H(px->be_counters.p.http.rsp[3]), |
| 3630 | U2H(px->be_counters.p.http.rsp[4]), |
| 3631 | U2H(px->be_counters.p.http.rsp[5]), |
| 3632 | U2H(px->be_counters.p.http.rsp[0]), |
| 3633 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3634 | } |
| 3635 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3636 | 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))); |
| 3637 | 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))); |
| 3638 | if (px->mode == PR_MODE_HTTP) |
| 3639 | 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))); |
| 3640 | 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))); |
| 3641 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3642 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3643 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3644 | /* sessions: lbtot, last */ |
| 3645 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3646 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3647 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3648 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3649 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3650 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3651 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3652 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3653 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3654 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3655 | "<td>%s%s<div class=tips><table class=det>" |
| 3656 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3657 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3658 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3659 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3660 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3661 | "</table></div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3662 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3663 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3664 | U2H(px->be_counters.bytes_out), |
| 3665 | U2H(px->be_counters.comp_in), |
| 3666 | U2H(px->be_counters.comp_out), |
| 3667 | px->be_counters.comp_in ? (int)(px->be_counters.comp_out * 100 / px->be_counters.comp_in) : 0, |
| 3668 | U2H(px->be_counters.comp_byp), |
| 3669 | U2H(px->be_counters.comp_in - px->be_counters.comp_out), |
| 3670 | px->be_counters.bytes_out ? (int)((px->be_counters.comp_in - px->be_counters.comp_out) * 100 / px->be_counters.bytes_out) : 0, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3671 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3672 | |
| 3673 | chunk_appendf(&trash, |
| 3674 | /* denied: req, resp */ |
| 3675 | "<td>%s</td><td>%s</td>" |
| 3676 | /* errors : request, connect */ |
| 3677 | "<td></td><td>%s</td>" |
| 3678 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3679 | "<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] | 3680 | /* warnings: retries, redispatches */ |
| 3681 | "<td>%lld</td><td>%lld</td>" |
| 3682 | /* backend status: reflect backend status (up/down): we display UP |
| 3683 | * if the backend has known working servers or if it has no server at |
| 3684 | * all (eg: for stats). Then we display the total weight, number of |
| 3685 | * active and backups. */ |
| 3686 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3687 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3688 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3689 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3690 | U2H(px->be_counters.failed_conns), |
| 3691 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3692 | px->be_counters.cli_aborts, |
| 3693 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3694 | px->be_counters.retries, px->be_counters.redispatches, |
| 3695 | human_time(now.tv_sec - px->last_change, 1), |
| 3696 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3697 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3698 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3699 | px->srv_act, px->srv_bck); |
| 3700 | |
| 3701 | chunk_appendf(&trash, |
| 3702 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3703 | "<td class=ac> </td><td>%d</td>" |
| 3704 | "<td>%s</td>" |
| 3705 | "<td></td>" |
| 3706 | "</tr>", |
| 3707 | px->down_trans, |
| 3708 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3709 | } |
| 3710 | else { /* CSV mode */ |
| 3711 | chunk_appendf(&trash, |
| 3712 | /* pxid, name */ |
| 3713 | "%s,BACKEND," |
| 3714 | /* queue : current, max */ |
| 3715 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3716 | /* sessions : current, max, limit, total */ |
| 3717 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3718 | /* bytes : in, out */ |
| 3719 | "%lld,%lld," |
| 3720 | /* denied: req, resp */ |
| 3721 | "%lld,%lld," |
| 3722 | /* errors : request, connect, response */ |
| 3723 | ",%lld,%lld," |
| 3724 | /* warnings: retries, redispatches */ |
| 3725 | "%lld,%lld," |
| 3726 | /* backend status: reflect backend status (up/down): we display UP |
| 3727 | * if the backend has known working servers or if it has no server at |
| 3728 | * all (eg: for stats). Then we display the total weight, number of |
| 3729 | * active and backups. */ |
| 3730 | "%s," |
| 3731 | "%d,%d,%d," |
| 3732 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3733 | ",%d,%d,%d,," |
| 3734 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3735 | "%d,%d,0,,%lld,,%d," |
| 3736 | /* rate, rate_lim, rate_max, */ |
| 3737 | "%u,,%u," |
| 3738 | /* check_status, check_code, check_duration */ |
| 3739 | ",,,", |
| 3740 | px->id, |
| 3741 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3742 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3743 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3744 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3745 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3746 | px->be_counters.retries, px->be_counters.redispatches, |
| 3747 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3748 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3749 | px->srv_act, px->srv_bck, |
| 3750 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3751 | px->srv?be_downtime(px):0, |
| 3752 | relative_pid, px->uuid, |
| 3753 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3754 | read_freq_ctr(&px->be_sess_per_sec), |
| 3755 | px->be_counters.sps_max); |
| 3756 | |
| 3757 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3758 | if (px->mode == PR_MODE_HTTP) { |
| 3759 | for (i=1; i<6; i++) |
| 3760 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3761 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3762 | } |
| 3763 | else |
| 3764 | chunk_appendf(&trash, ",,,,,,"); |
| 3765 | |
| 3766 | /* failed health analyses */ |
| 3767 | chunk_appendf(&trash, ","); |
| 3768 | |
| 3769 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3770 | chunk_appendf(&trash, ",,,"); |
| 3771 | |
| 3772 | /* errors: cli_aborts, srv_aborts */ |
| 3773 | chunk_appendf(&trash, "%lld,%lld,", |
| 3774 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3775 | |
| 3776 | /* compression: in, out, bypassed */ |
| 3777 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3778 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3779 | |
| 3780 | /* compression: comp_rsp */ |
| 3781 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3782 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3783 | /* lastsess, last_chk, last_agt, */ |
| 3784 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3785 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3786 | /* qtime, ctime, rtime, ttime, */ |
| 3787 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3788 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 3789 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 3790 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 3791 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 3792 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3793 | /* finish with EOL */ |
| 3794 | chunk_appendf(&trash, "\n"); |
| 3795 | } |
| 3796 | return 1; |
| 3797 | } |
| 3798 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3799 | /* 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] | 3800 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3801 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3802 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3803 | 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] | 3804 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3805 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3806 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3807 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3808 | 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] | 3809 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3810 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3811 | /* 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] | 3812 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3813 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3814 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3815 | 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] | 3816 | 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] | 3817 | } |
| 3818 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3819 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 3820 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | /* print a new table */ |
| 3824 | chunk_appendf(&trash, |
| 3825 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3826 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3827 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3828 | |
| 3829 | chunk_appendf(&trash, |
| 3830 | "<a name=\"%s\"></a>%s" |
| 3831 | "<a class=px href=\"#%s\">%s</a>", |
| 3832 | px->id, |
| 3833 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3834 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3835 | |
| 3836 | if (uri->flags & ST_SHLGNDS) { |
| 3837 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3838 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3839 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3840 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3841 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3845 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3846 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3847 | "</tr>\n" |
| 3848 | "</table>\n" |
| 3849 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3850 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3851 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3852 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3853 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3854 | 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] | 3855 | /* Column heading for Enable or Disable server */ |
| 3856 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3857 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3858 | |
| 3859 | chunk_appendf(&trash, |
| 3860 | "<th rowspan=2></th>" |
| 3861 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3862 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3863 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3864 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3865 | "<th colspan=9>Server</th>" |
| 3866 | "</tr>\n" |
| 3867 | "<tr class=\"titre\">" |
| 3868 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3869 | "<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] | 3870 | "<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] | 3871 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3872 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3873 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3874 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3875 | "<th>Thrtle</th>\n" |
| 3876 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3877 | } |
| 3878 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3879 | /* 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] | 3880 | * 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] | 3881 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3882 | 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] | 3883 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3884 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3885 | chunk_appendf(&trash, "</table>"); |
| 3886 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3887 | 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] | 3888 | /* close the form used to enable/disable this proxy servers */ |
| 3889 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3890 | "Choose the action to perform on the checked servers : " |
| 3891 | "<select name=action>" |
| 3892 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 3893 | "<option value=\"ready\">Set state to READY</option>" |
| 3894 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 3895 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 3896 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3897 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3898 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3899 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3900 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3901 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3902 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3903 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3904 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3905 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3906 | "</select>" |
| 3907 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3908 | " <input type=\"submit\" value=\"Apply\">" |
| 3909 | "</form>", |
| 3910 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3911 | } |
| 3912 | |
| 3913 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3914 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3915 | |
| 3916 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3917 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3918 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3919 | * buffer space, or non-zero if everything completed. This function is used |
| 3920 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3921 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3922 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3923 | 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] | 3924 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3925 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3926 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 3927 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3928 | 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] | 3929 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3930 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3931 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3932 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3933 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3934 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3935 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3936 | if (uri && uri->scope) { |
| 3937 | /* we have a limited scope, we have to check the proxy name */ |
| 3938 | struct stat_scope *scope; |
| 3939 | int len; |
| 3940 | |
| 3941 | len = strlen(px->id); |
| 3942 | scope = uri->scope; |
| 3943 | |
| 3944 | while (scope) { |
| 3945 | /* match exact proxy name */ |
| 3946 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3947 | break; |
| 3948 | |
| 3949 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3950 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3951 | break; |
| 3952 | scope = scope->next; |
| 3953 | } |
| 3954 | |
| 3955 | /* proxy name not found : don't dump anything */ |
| 3956 | if (scope == NULL) |
| 3957 | return 1; |
| 3958 | } |
| 3959 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3960 | /* if the user has requested a limited output and the proxy |
| 3961 | * name does not match, skip it. |
| 3962 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3963 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 3964 | 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] | 3965 | return 1; |
| 3966 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3967 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3968 | (appctx->ctx.stats.iid != -1) && |
| 3969 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3970 | return 1; |
| 3971 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3972 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3973 | /* fall through */ |
| 3974 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3975 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3976 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3977 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3978 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3979 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3980 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3981 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3982 | } |
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 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3985 | /* fall through */ |
| 3986 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3987 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3988 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3989 | if (stats_dump_fe_stats(si, px)) { |
| 3990 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3991 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3992 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3993 | } |
| 3994 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3995 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3996 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3997 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3998 | /* fall through */ |
| 3999 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4000 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4001 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4002 | 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] | 4003 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4004 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4005 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4006 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4007 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4008 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4009 | if (!l->counters) |
| 4010 | continue; |
| 4011 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4012 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4013 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4014 | break; |
| 4015 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4016 | 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] | 4017 | continue; |
| 4018 | } |
| 4019 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4020 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4021 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) { |
| 4022 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4023 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4024 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4025 | } |
| 4026 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4027 | } |
| 4028 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4029 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 4030 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4031 | /* fall through */ |
| 4032 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4033 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4034 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4035 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4036 | enum srv_stats_state sv_state; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4037 | enum srv_stats_colour sv_colour; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4038 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4039 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4040 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4041 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4042 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4043 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4044 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4045 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4046 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4047 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4048 | break; |
| 4049 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4050 | 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] | 4051 | continue; |
| 4052 | } |
| 4053 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4054 | svs = sv; |
| 4055 | while (svs->track) |
| 4056 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4057 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4058 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4059 | if ((svs->check.state & CHK_ST_ENABLED) && |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4060 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4061 | sv_state = SRV_STATS_STATE_UP_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4062 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4063 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4064 | sv_state = SRV_STATS_STATE_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4065 | sv_colour = SRV_STATS_COLOUR_UP; |
| 4066 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4067 | |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4068 | if (sv_state == SRV_STATS_STATE_UP && !svs->uweight) |
| 4069 | sv_colour = SRV_STATS_COLOUR_DRAINING; |
| 4070 | |
| 4071 | if (sv->admin & SRV_ADMF_DRAIN) { |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4072 | if (svs->agent.state & CHK_ST_ENABLED) |
| 4073 | sv_state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4074 | else if (sv_state == SRV_STATS_STATE_UP_GOING_DOWN) |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4075 | sv_state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4076 | else |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4077 | sv_state = SRV_STATS_STATE_DRAIN; |
| 4078 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4079 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4080 | 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] | 4081 | sv_state = SRV_STATS_STATE_NO_CHECK; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4082 | sv_colour = SRV_STATS_COLOUR_NO_CHECK; |
| 4083 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4084 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4085 | else if (sv->state == SRV_ST_STOPPING) { |
| 4086 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4087 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4088 | sv_state = SRV_STATS_STATE_NOLB; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4089 | sv_colour = SRV_STATS_COLOUR_NOLB; |
| 4090 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4091 | sv_state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4092 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4093 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4094 | } |
| 4095 | else { /* stopped */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4096 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4097 | sv_state = SRV_STATS_STATE_DOWN_AGENT; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4098 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4099 | } else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4100 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4101 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4102 | } 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] | 4103 | sv_state = SRV_STATS_STATE_GOING_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4104 | sv_colour = SRV_STATS_COLOUR_GOING_UP; |
| 4105 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4106 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4107 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4108 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4109 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4110 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4111 | 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] | 4112 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4113 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4114 | continue; |
| 4115 | } |
| 4116 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4117 | 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] | 4118 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4119 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4120 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4121 | } |
| 4122 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4123 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4124 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4125 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4126 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4127 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4128 | case STAT_PX_ST_BE: |
| 4129 | /* print the backend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4130 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) { |
| 4131 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4132 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4133 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4134 | } |
| 4135 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4136 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4137 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4138 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4139 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4140 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4141 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4142 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4143 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4144 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4145 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4146 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4147 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4148 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4149 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4150 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4151 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4152 | case STAT_PX_ST_FIN: |
| 4153 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4154 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4155 | default: |
| 4156 | /* unknown state, we should put an abort() here ! */ |
| 4157 | return 1; |
| 4158 | } |
| 4159 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4160 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4161 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4162 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4163 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4164 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4165 | { |
| 4166 | /* WARNING! This must fit in the first buffer !!! */ |
| 4167 | chunk_appendf(&trash, |
| 4168 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4169 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4170 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4171 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4172 | "<style type=\"text/css\"><!--\n" |
| 4173 | "body {" |
| 4174 | " font-family: arial, helvetica, sans-serif;" |
| 4175 | " font-size: 12px;" |
| 4176 | " font-weight: normal;" |
| 4177 | " color: black;" |
| 4178 | " background: white;" |
| 4179 | "}\n" |
| 4180 | "th,td {" |
| 4181 | " font-size: 10px;" |
| 4182 | "}\n" |
| 4183 | "h1 {" |
| 4184 | " font-size: x-large;" |
| 4185 | " margin-bottom: 0.5em;" |
| 4186 | "}\n" |
| 4187 | "h2 {" |
| 4188 | " font-family: helvetica, arial;" |
| 4189 | " font-size: x-large;" |
| 4190 | " font-weight: bold;" |
| 4191 | " font-style: italic;" |
| 4192 | " color: #6020a0;" |
| 4193 | " margin-top: 0em;" |
| 4194 | " margin-bottom: 0em;" |
| 4195 | "}\n" |
| 4196 | "h3 {" |
| 4197 | " font-family: helvetica, arial;" |
| 4198 | " font-size: 16px;" |
| 4199 | " font-weight: bold;" |
| 4200 | " color: #b00040;" |
| 4201 | " background: #e8e8d0;" |
| 4202 | " margin-top: 0em;" |
| 4203 | " margin-bottom: 0em;" |
| 4204 | "}\n" |
| 4205 | "li {" |
| 4206 | " margin-top: 0.25em;" |
| 4207 | " margin-right: 2em;" |
| 4208 | "}\n" |
| 4209 | ".hr {margin-top: 0.25em;" |
| 4210 | " border-color: black;" |
| 4211 | " border-bottom-style: solid;" |
| 4212 | "}\n" |
| 4213 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4214 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4215 | ".frontend {background: #e8e8d0;}\n" |
| 4216 | ".socket {background: #d0d0d0;}\n" |
| 4217 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4218 | ".active_down {background: #ff9090;}\n" |
| 4219 | ".active_going_up {background: #ffd020;}\n" |
| 4220 | ".active_going_down {background: #ffffa0;}\n" |
| 4221 | ".active_up {background: #c0ffc0;}\n" |
| 4222 | ".active_nolb {background: #20a0ff;}\n" |
| 4223 | ".active_draining {background: #20a0FF;}\n" |
| 4224 | ".active_no_check {background: #e0e0e0;}\n" |
| 4225 | ".backup_down {background: #ff9090;}\n" |
| 4226 | ".backup_going_up {background: #ff80ff;}\n" |
| 4227 | ".backup_going_down {background: #c060ff;}\n" |
| 4228 | ".backup_up {background: #b0d0ff;}\n" |
| 4229 | ".backup_nolb {background: #90b0e0;}\n" |
| 4230 | ".backup_draining {background: #cc9900;}\n" |
| 4231 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4232 | ".maintain {background: #c07820;}\n" |
| 4233 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4234 | "\n" |
| 4235 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4236 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4237 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4238 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4239 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4240 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4241 | "\n" |
| 4242 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4243 | "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" |
| 4244 | "table.tbl td.ac { text-align: center;}\n" |
| 4245 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4246 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4247 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4248 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4249 | "\n" |
| 4250 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4251 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4252 | "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] | 4253 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4254 | "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] | 4255 | "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] | 4256 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4257 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4258 | " display:block;\n" |
| 4259 | " visibility:hidden;\n" |
| 4260 | " z-index:2147483647;\n" |
| 4261 | " position:absolute;\n" |
| 4262 | " padding:2px 4px 3px;\n" |
| 4263 | " background:#f0f060; color:#000000;\n" |
| 4264 | " border:1px solid #7040c0;\n" |
| 4265 | " white-space:nowrap;\n" |
| 4266 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4267 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4268 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4269 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4270 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4271 | "-->\n" |
| 4272 | "</style></head>\n", |
| 4273 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4274 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4275 | ); |
| 4276 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4277 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4278 | /* 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] | 4279 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4280 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4281 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4282 | 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] | 4283 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4284 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4285 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4286 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4287 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4288 | /* WARNING! this has to fit the first packet too. |
| 4289 | * We are around 3.5 kB, add adding entries will |
| 4290 | * become tricky if we want to support 4kB buffers ! |
| 4291 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4292 | chunk_appendf(&trash, |
| 4293 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4294 | PRODUCT_NAME "%s</a></h1>\n" |
| 4295 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4296 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4297 | "<h3>> General process information</h3>\n" |
| 4298 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4299 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4300 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4301 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4302 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4303 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4304 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4305 | "</td><td align=\"center\" nowrap>\n" |
| 4306 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4307 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4308 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4309 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4310 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4311 | "<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] | 4312 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4313 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4314 | "<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] | 4315 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4316 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4317 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4318 | "</tr><tr>\n" |
| 4319 | "<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] | 4320 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4321 | "<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] | 4322 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4323 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4324 | "</td>" |
| 4325 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4326 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4327 | "", |
| 4328 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4329 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4330 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4331 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4332 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4333 | pid, relative_pid, global.nbproc, |
| 4334 | up / 86400, (up % 86400) / 3600, |
| 4335 | (up % 3600) / 60, (up % 60), |
| 4336 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4337 | global.rlimit_memmax ? " MB" : "", |
| 4338 | global.rlimit_nofile, |
| 4339 | global.maxsock, global.maxconn, global.maxpipes, |
| 4340 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4341 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4342 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4343 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4344 | /* 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] | 4345 | 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] | 4346 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4347 | |
| 4348 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4349 | "<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] | 4350 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4351 | STAT_SCOPE_TXT_MAXLEN); |
| 4352 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4353 | /* 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] | 4354 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4355 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4356 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4357 | 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] | 4358 | 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] | 4359 | } |
| 4360 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4361 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4362 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4363 | "<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] | 4364 | uri->uri_prefix, |
| 4365 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4366 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4367 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4368 | else |
| 4369 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4370 | "<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] | 4371 | uri->uri_prefix, |
| 4372 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4373 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4374 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4375 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4376 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4377 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4378 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4379 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4380 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4381 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4382 | "", |
| 4383 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4384 | else |
| 4385 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4386 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4387 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4388 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4389 | ";norefresh", |
| 4390 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4391 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4392 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4393 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4394 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4395 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4396 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4397 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4398 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4399 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4400 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4401 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4402 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4403 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4404 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4405 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4406 | chunk_appendf(&trash, |
| 4407 | "</ul></td>" |
| 4408 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4409 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4410 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4411 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4412 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4413 | "</ul>" |
| 4414 | "</td>" |
| 4415 | "</tr></table>\n" |
| 4416 | "" |
| 4417 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4418 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4419 | if (appctx->ctx.stats.st_code) { |
| 4420 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4421 | case STAT_STATUS_DONE: |
| 4422 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4423 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4424 | "<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] | 4425 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4426 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4427 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4428 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4429 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4430 | break; |
| 4431 | case STAT_STATUS_NONE: |
| 4432 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4433 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4434 | "<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] | 4435 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4436 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4437 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4438 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4439 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4440 | break; |
| 4441 | case STAT_STATUS_PART: |
| 4442 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4443 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4444 | "<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] | 4445 | "Action partially processed.<br>" |
| 4446 | "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] | 4447 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4448 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4449 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4450 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4451 | break; |
| 4452 | case STAT_STATUS_ERRP: |
| 4453 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4454 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4455 | "<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] | 4456 | "Action not processed because of invalid parameters." |
| 4457 | "<ul>" |
| 4458 | "<li>The action is maybe unknown.</li>" |
| 4459 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4460 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4461 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4462 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4463 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4464 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4465 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4466 | break; |
| 4467 | case STAT_STATUS_EXCD: |
| 4468 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4469 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4470 | "<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] | 4471 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4472 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4473 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4474 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4475 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4476 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4477 | break; |
| 4478 | case STAT_STATUS_DENY: |
| 4479 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4480 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4481 | "<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] | 4482 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4483 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4484 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4485 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4486 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4487 | break; |
| 4488 | default: |
| 4489 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4490 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4491 | "<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] | 4492 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4493 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4494 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4495 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4496 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4497 | } |
| 4498 | chunk_appendf(&trash, "<p>\n"); |
| 4499 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4500 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4501 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4502 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4503 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4504 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4505 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4506 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4507 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4508 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4509 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4510 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4511 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4512 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4513 | * 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] | 4514 | * 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] | 4515 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4516 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4517 | 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] | 4518 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4519 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4520 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4521 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4522 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4523 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4524 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4525 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4526 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4527 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4528 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4529 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4530 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4531 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4532 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4533 | else |
| 4534 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4535 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4536 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4537 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4538 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4539 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4540 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4541 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4542 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4543 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4544 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4545 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4546 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4547 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4548 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4549 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4550 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4551 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4552 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4553 | appctx->ctx.stats.px = proxy; |
| 4554 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4555 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4556 | /* fall through */ |
| 4557 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4558 | case STAT_ST_LIST: |
| 4559 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4560 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4561 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4562 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4563 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4564 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4565 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4566 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4567 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4568 | 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] | 4569 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4570 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4571 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4572 | appctx->ctx.stats.px = px->next; |
| 4573 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4574 | } |
| 4575 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4576 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4577 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4578 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4579 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4580 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4581 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4582 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4583 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4584 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4585 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4586 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4587 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4588 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4589 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4590 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4591 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4592 | case STAT_ST_FIN: |
| 4593 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4594 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4595 | default: |
| 4596 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4597 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4598 | return -1; |
| 4599 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4600 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4601 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4602 | /* We reached the stats page through a POST request. The appctx is |
| 4603 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4604 | * Parse the posted data and enable/disable servers if necessary. |
| 4605 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4606 | */ |
| 4607 | static int stats_process_http_post(struct stream_interface *si) |
| 4608 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4609 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4610 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4611 | |
| 4612 | struct proxy *px = NULL; |
| 4613 | struct server *sv = NULL; |
| 4614 | |
| 4615 | char key[LINESIZE]; |
| 4616 | int action = ST_ADM_ACTION_NONE; |
| 4617 | int reprocess = 0; |
| 4618 | |
| 4619 | int total_servers = 0; |
| 4620 | int altered_servers = 0; |
| 4621 | |
| 4622 | char *first_param, *cur_param, *next_param, *end_params; |
| 4623 | char *st_cur_param = NULL; |
| 4624 | char *st_next_param = NULL; |
| 4625 | |
| 4626 | struct chunk *temp; |
| 4627 | int reql; |
| 4628 | |
| 4629 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4630 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4631 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4632 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4633 | goto out; |
| 4634 | } |
| 4635 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4636 | 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] | 4637 | if (reql <= 0) { |
| 4638 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4639 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4640 | return 0; |
| 4641 | } |
| 4642 | |
| 4643 | first_param = temp->str; |
| 4644 | end_params = temp->str + reql; |
| 4645 | cur_param = next_param = end_params; |
| 4646 | *end_params = '\0'; |
| 4647 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4648 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4649 | |
| 4650 | /* |
| 4651 | * Parse the parameters in reverse order to only store the last value. |
| 4652 | * From the html form, the backend and the action are at the end. |
| 4653 | */ |
| 4654 | while (cur_param > first_param) { |
| 4655 | char *value; |
| 4656 | int poffset, plen; |
| 4657 | |
| 4658 | cur_param--; |
| 4659 | |
| 4660 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4661 | reprocess_servers: |
| 4662 | /* Parse the key */ |
| 4663 | poffset = (cur_param != first_param ? 1 : 0); |
| 4664 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4665 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4666 | strncpy(key, cur_param + poffset, plen); |
| 4667 | key[plen - 1] = '\0'; |
| 4668 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4669 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4670 | goto out; |
| 4671 | } |
| 4672 | |
| 4673 | /* Parse the value */ |
| 4674 | value = key; |
| 4675 | while (*value != '\0' && *value != '=') { |
| 4676 | value++; |
| 4677 | } |
| 4678 | if (*value == '=') { |
| 4679 | /* Ok, a value is found, we can mark the end of the key */ |
| 4680 | *value++ = '\0'; |
| 4681 | } |
| 4682 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4683 | break; |
| 4684 | |
| 4685 | /* Now we can check the key to see what to do */ |
| 4686 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 4687 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4688 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4689 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4690 | goto out; |
| 4691 | } |
| 4692 | } |
| 4693 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4694 | if (strcmp(value, "ready") == 0) { |
| 4695 | action = ST_ADM_ACTION_READY; |
| 4696 | } |
| 4697 | else if (strcmp(value, "drain") == 0) { |
| 4698 | action = ST_ADM_ACTION_DRAIN; |
| 4699 | } |
| 4700 | else if (strcmp(value, "maint") == 0) { |
| 4701 | action = ST_ADM_ACTION_MAINT; |
| 4702 | } |
| 4703 | else if (strcmp(value, "shutdown") == 0) { |
| 4704 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4705 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4706 | else if (strcmp(value, "dhlth") == 0) { |
| 4707 | action = ST_ADM_ACTION_DHLTH; |
| 4708 | } |
| 4709 | else if (strcmp(value, "ehlth") == 0) { |
| 4710 | action = ST_ADM_ACTION_EHLTH; |
| 4711 | } |
| 4712 | else if (strcmp(value, "hrunn") == 0) { |
| 4713 | action = ST_ADM_ACTION_HRUNN; |
| 4714 | } |
| 4715 | else if (strcmp(value, "hnolb") == 0) { |
| 4716 | action = ST_ADM_ACTION_HNOLB; |
| 4717 | } |
| 4718 | else if (strcmp(value, "hdown") == 0) { |
| 4719 | action = ST_ADM_ACTION_HDOWN; |
| 4720 | } |
| 4721 | else if (strcmp(value, "dagent") == 0) { |
| 4722 | action = ST_ADM_ACTION_DAGENT; |
| 4723 | } |
| 4724 | else if (strcmp(value, "eagent") == 0) { |
| 4725 | action = ST_ADM_ACTION_EAGENT; |
| 4726 | } |
| 4727 | else if (strcmp(value, "arunn") == 0) { |
| 4728 | action = ST_ADM_ACTION_ARUNN; |
| 4729 | } |
| 4730 | else if (strcmp(value, "adown") == 0) { |
| 4731 | action = ST_ADM_ACTION_ADOWN; |
| 4732 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4733 | /* else these are the old supported methods */ |
| 4734 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4735 | action = ST_ADM_ACTION_DISABLE; |
| 4736 | } |
| 4737 | else if (strcmp(value, "enable") == 0) { |
| 4738 | action = ST_ADM_ACTION_ENABLE; |
| 4739 | } |
| 4740 | else if (strcmp(value, "stop") == 0) { |
| 4741 | action = ST_ADM_ACTION_STOP; |
| 4742 | } |
| 4743 | else if (strcmp(value, "start") == 0) { |
| 4744 | action = ST_ADM_ACTION_START; |
| 4745 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4746 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4747 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4748 | goto out; |
| 4749 | } |
| 4750 | } |
| 4751 | else if (strcmp(key, "s") == 0) { |
| 4752 | if (!(px && action)) { |
| 4753 | /* |
| 4754 | * Indicates that we'll need to reprocess the parameters |
| 4755 | * as soon as backend and action are known |
| 4756 | */ |
| 4757 | if (!reprocess) { |
| 4758 | st_cur_param = cur_param; |
| 4759 | st_next_param = next_param; |
| 4760 | } |
| 4761 | reprocess = 1; |
| 4762 | } |
| 4763 | else if ((sv = findserver(px, value)) != NULL) { |
| 4764 | switch (action) { |
| 4765 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4766 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4767 | altered_servers++; |
| 4768 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4769 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4770 | } |
| 4771 | break; |
| 4772 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4773 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4774 | altered_servers++; |
| 4775 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4776 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4777 | } |
| 4778 | break; |
| 4779 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4780 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 4781 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4782 | altered_servers++; |
| 4783 | total_servers++; |
| 4784 | } |
| 4785 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4786 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4787 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 4788 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4789 | altered_servers++; |
| 4790 | total_servers++; |
| 4791 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4792 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4793 | case ST_ADM_ACTION_DHLTH: |
| 4794 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4795 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4796 | altered_servers++; |
| 4797 | total_servers++; |
| 4798 | } |
| 4799 | break; |
| 4800 | case ST_ADM_ACTION_EHLTH: |
| 4801 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4802 | sv->check.state |= CHK_ST_ENABLED; |
| 4803 | altered_servers++; |
| 4804 | total_servers++; |
| 4805 | } |
| 4806 | break; |
| 4807 | case ST_ADM_ACTION_HRUNN: |
| 4808 | if (!(sv->track)) { |
| 4809 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4810 | srv_set_running(sv, "changed from Web interface"); |
| 4811 | altered_servers++; |
| 4812 | total_servers++; |
| 4813 | } |
| 4814 | break; |
| 4815 | case ST_ADM_ACTION_HNOLB: |
| 4816 | if (!(sv->track)) { |
| 4817 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 4818 | srv_set_stopping(sv, "changed from Web interface"); |
| 4819 | altered_servers++; |
| 4820 | total_servers++; |
| 4821 | } |
| 4822 | break; |
| 4823 | case ST_ADM_ACTION_HDOWN: |
| 4824 | if (!(sv->track)) { |
| 4825 | sv->check.health = 0; |
| 4826 | srv_set_stopped(sv, "changed from Web interface"); |
| 4827 | altered_servers++; |
| 4828 | total_servers++; |
| 4829 | } |
| 4830 | break; |
| 4831 | case ST_ADM_ACTION_DAGENT: |
| 4832 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4833 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4834 | altered_servers++; |
| 4835 | total_servers++; |
| 4836 | } |
| 4837 | break; |
| 4838 | case ST_ADM_ACTION_EAGENT: |
| 4839 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4840 | sv->agent.state |= CHK_ST_ENABLED; |
| 4841 | altered_servers++; |
| 4842 | total_servers++; |
| 4843 | } |
| 4844 | break; |
| 4845 | case ST_ADM_ACTION_ARUNN: |
| 4846 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4847 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 4848 | srv_set_running(sv, "changed from Web interface"); |
| 4849 | altered_servers++; |
| 4850 | total_servers++; |
| 4851 | } |
| 4852 | break; |
| 4853 | case ST_ADM_ACTION_ADOWN: |
| 4854 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4855 | sv->agent.health = 0; |
| 4856 | srv_set_stopped(sv, "changed from Web interface"); |
| 4857 | altered_servers++; |
| 4858 | total_servers++; |
| 4859 | } |
| 4860 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4861 | case ST_ADM_ACTION_READY: |
| 4862 | srv_adm_set_ready(sv); |
| 4863 | altered_servers++; |
| 4864 | total_servers++; |
| 4865 | break; |
| 4866 | case ST_ADM_ACTION_DRAIN: |
| 4867 | srv_adm_set_drain(sv); |
| 4868 | altered_servers++; |
| 4869 | total_servers++; |
| 4870 | break; |
| 4871 | case ST_ADM_ACTION_MAINT: |
| 4872 | srv_adm_set_maint(sv); |
| 4873 | altered_servers++; |
| 4874 | total_servers++; |
| 4875 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4876 | case ST_ADM_ACTION_SHUTDOWN: |
| 4877 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4878 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4879 | |
| 4880 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4881 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 4882 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4883 | |
| 4884 | altered_servers++; |
| 4885 | total_servers++; |
| 4886 | } |
| 4887 | break; |
| 4888 | } |
| 4889 | } else { |
| 4890 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4891 | total_servers++; |
| 4892 | } |
| 4893 | } |
| 4894 | if (reprocess && px && action) { |
| 4895 | /* Now, we know the backend and the action chosen by the user. |
| 4896 | * We can safely restart from the first server parameter |
| 4897 | * to reprocess them |
| 4898 | */ |
| 4899 | cur_param = st_cur_param; |
| 4900 | next_param = st_next_param; |
| 4901 | reprocess = 0; |
| 4902 | goto reprocess_servers; |
| 4903 | } |
| 4904 | |
| 4905 | next_param = cur_param; |
| 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4910 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4911 | } |
| 4912 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4913 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4914 | } |
| 4915 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4916 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4917 | } |
| 4918 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4919 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4920 | } |
| 4921 | out: |
| 4922 | return 1; |
| 4923 | } |
| 4924 | |
| 4925 | |
| 4926 | static int stats_send_http_headers(struct stream_interface *si) |
| 4927 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4928 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4929 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4930 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4931 | |
| 4932 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 4933 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4934 | "Cache-Control: no-cache\r\n" |
| 4935 | "Connection: close\r\n" |
| 4936 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4937 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4938 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4939 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4940 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4941 | uri->refresh); |
| 4942 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 4943 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 4944 | |
| 4945 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 4946 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 4947 | else |
| 4948 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4949 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4950 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4951 | s->logs.tv_request = now; |
| 4952 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4953 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4954 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4955 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4956 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4957 | |
| 4958 | return 1; |
| 4959 | } |
| 4960 | |
| 4961 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4962 | { |
| 4963 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4964 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4965 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4966 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4967 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4968 | /* 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] | 4969 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4970 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4971 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4972 | 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] | 4973 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | /* We don't want to land on the posted stats page because a refresh will |
| 4977 | * repost the data. We don't want this to happen on accident so we redirect |
| 4978 | * the browse to the stats page with a GET. |
| 4979 | */ |
| 4980 | chunk_printf(&trash, |
| 4981 | "HTTP/1.1 303 See Other\r\n" |
| 4982 | "Cache-Control: no-cache\r\n" |
| 4983 | "Content-Type: text/plain\r\n" |
| 4984 | "Connection: close\r\n" |
| 4985 | "Location: %s;st=%s%s%s%s\r\n" |
| 4986 | "\r\n", |
| 4987 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4988 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4989 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4990 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4991 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4992 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4993 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4994 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4995 | scope_txt); |
| 4996 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4997 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4998 | s->logs.tv_request = now; |
| 4999 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5000 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5001 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5002 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5003 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5004 | |
| 5005 | return 1; |
| 5006 | } |
| 5007 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5008 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 5009 | * 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] | 5010 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5011 | * automatically unregisters itself once transfer is complete. |
| 5012 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5013 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5014 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5015 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5016 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5017 | struct channel *req = si_oc(si); |
| 5018 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5019 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5020 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 5021 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5022 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5023 | /* check that the output is not closed */ |
| 5024 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5025 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5026 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5027 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5028 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5029 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5030 | if (s->txn->meth == HTTP_METH_HEAD) |
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 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5033 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5034 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5035 | } |
| 5036 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5037 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5038 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5039 | unsigned int data_len; |
| 5040 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 5041 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5042 | |
| 5043 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5044 | /* One difficulty we're facing is that we must prevent |
| 5045 | * the input data from being automatically forwarded to |
| 5046 | * the output area. For this, we temporarily disable |
| 5047 | * forwarding on the channel. |
| 5048 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5049 | last_fwd = si_ic(si)->to_forward; |
| 5050 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5051 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5052 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5053 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5054 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5055 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5056 | } |
| 5057 | } |
| 5058 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5059 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5060 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5061 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5062 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5063 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5064 | |
| 5065 | /* Now we must either adjust or remove the chunk size. This is |
| 5066 | * not easy because the chunk size might wrap at the end of the |
| 5067 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5068 | * the size, then restore the buffer's contents. Note that we can |
| 5069 | * only do that because no forwarding is scheduled on the stats |
| 5070 | * applet. |
| 5071 | */ |
| 5072 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5073 | si_ic(si)->total -= (last_len - prev_len); |
| 5074 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5075 | |
| 5076 | if (last_len != data_len) { |
| 5077 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5078 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5079 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5080 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5081 | si_ic(si)->total += (last_len - data_len); |
| 5082 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5083 | } |
| 5084 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5085 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5086 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5087 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5088 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5089 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5090 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5091 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5092 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5093 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5094 | } |
| 5095 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5096 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5097 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5098 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5099 | } |
| 5100 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5101 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5102 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5103 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5104 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5105 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5106 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5107 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5108 | } |
| 5109 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5110 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5111 | res->flags |= CF_READ_NULL; |
| 5112 | si_shutr(si); |
| 5113 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5114 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5115 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5116 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5117 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5118 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5119 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5120 | si_shutr(si); |
| 5121 | res->flags |= CF_READ_NULL; |
| 5122 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5123 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5124 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5125 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5126 | } |
| 5127 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5128 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5129 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5130 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5131 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5132 | return "NONE"; |
| 5133 | return conn->ctrl->name; |
| 5134 | } |
| 5135 | |
| 5136 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5137 | { |
| 5138 | static char ptr[17]; |
| 5139 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5140 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5141 | return "NONE"; |
| 5142 | |
| 5143 | if (conn->xprt == &raw_sock) |
| 5144 | return "RAW"; |
| 5145 | |
| 5146 | #ifdef USE_OPENSSL |
| 5147 | if (conn->xprt == &ssl_sock) |
| 5148 | return "SSL"; |
| 5149 | #endif |
| 5150 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5151 | return ptr; |
| 5152 | } |
| 5153 | |
| 5154 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5155 | { |
| 5156 | static char ptr[17]; |
| 5157 | |
| 5158 | if (!conn->data) |
| 5159 | return "NONE"; |
| 5160 | |
| 5161 | if (conn->data == &sess_conn_cb) |
| 5162 | return "SESS"; |
| 5163 | |
| 5164 | if (conn->data == &si_conn_cb) |
| 5165 | return "STRM"; |
| 5166 | |
| 5167 | if (conn->data == &check_conn_cb) |
| 5168 | return "CHCK"; |
| 5169 | |
| 5170 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5171 | return ptr; |
| 5172 | } |
| 5173 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5174 | /* This function dumps a complete stream state onto the stream interface's |
| 5175 | * 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] | 5176 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5177 | * 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] | 5178 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5179 | 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] | 5180 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5181 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5182 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5183 | extern const char *monthname[12]; |
| 5184 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5185 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5186 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5187 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5188 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5189 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5190 | 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] | 5191 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5192 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5193 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5194 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5195 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5196 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5197 | appctx->ctx.sess.uid = 0; |
| 5198 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5199 | return 1; |
| 5200 | } |
| 5201 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5202 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5203 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5204 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5205 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5206 | /* fall through */ |
| 5207 | |
| 5208 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5209 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5210 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5211 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5212 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5213 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5214 | 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] | 5215 | sess->uniq_id, |
Willy Tarreau | 666f504 | 2015-06-17 19:49:52 +0200 | [diff] [blame] | 5216 | strm_li(sess) ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5217 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5218 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5219 | 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] | 5220 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5221 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5222 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5223 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5224 | break; |
| 5225 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5226 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5227 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5228 | default: |
| 5229 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5230 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5231 | break; |
| 5232 | } |
| 5233 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5234 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5235 | " 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] | 5236 | 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] | 5237 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5238 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5239 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5240 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5241 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5242 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5243 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5244 | if (conn) |
| 5245 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5246 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5247 | 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] | 5248 | case AF_INET: |
| 5249 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5250 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5251 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5252 | break; |
| 5253 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5254 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5255 | break; |
| 5256 | default: |
| 5257 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5258 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5259 | break; |
| 5260 | } |
| 5261 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5262 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5263 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5264 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5265 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5266 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5267 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5268 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5269 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5270 | conn = objt_conn(sess->si[1].end); |
| 5271 | if (conn) |
| 5272 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5273 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5274 | 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] | 5275 | case AF_INET: |
| 5276 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5277 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5278 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5279 | break; |
| 5280 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5281 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5282 | break; |
| 5283 | default: |
| 5284 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5285 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5286 | break; |
| 5287 | } |
| 5288 | |
| 5289 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5290 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5291 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5292 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5293 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5294 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5295 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5296 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5297 | if (conn) |
| 5298 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5299 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5300 | 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] | 5301 | case AF_INET: |
| 5302 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5303 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5304 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5305 | break; |
| 5306 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5307 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5308 | break; |
| 5309 | default: |
| 5310 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5311 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5312 | break; |
| 5313 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5314 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5315 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5316 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5317 | sess->task, |
| 5318 | sess->task->state, |
| 5319 | sess->task->nice, sess->task->calls, |
| 5320 | sess->task->expire ? |
| 5321 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5322 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5323 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5324 | task_in_rq(sess->task) ? ", running" : ""); |
| 5325 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5326 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5327 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5328 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5329 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5330 | if (sess->txn) |
| 5331 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5332 | " 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] | 5333 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5334 | 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] | 5335 | |
| 5336 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5337 | " 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] | 5338 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5339 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5340 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5341 | obj_type_name(sess->si[0].end), |
| 5342 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5343 | sess->si[0].exp ? |
| 5344 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5345 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5346 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5347 | sess->si[0].err_type); |
| 5348 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5349 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5350 | " 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] | 5351 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5352 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5353 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5354 | obj_type_name(sess->si[1].end), |
| 5355 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5356 | sess->si[1].exp ? |
| 5357 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5358 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5359 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5360 | sess->si[1].err_type); |
| 5361 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5362 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5363 | chunk_appendf(&trash, |
| 5364 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5365 | conn, |
| 5366 | get_conn_ctrl_name(conn), |
| 5367 | get_conn_xprt_name(conn), |
| 5368 | get_conn_data_name(conn), |
| 5369 | obj_type_name(conn->target), |
| 5370 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5371 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5372 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5373 | " 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] | 5374 | conn->flags, |
| 5375 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5376 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5377 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5378 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5379 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5380 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5381 | chunk_appendf(&trash, |
| 5382 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5383 | tmpctx, |
| 5384 | tmpctx->st0, |
| 5385 | tmpctx->st1, |
| 5386 | tmpctx->st2, |
| 5387 | tmpctx->applet->name); |
| 5388 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5389 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5390 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5391 | chunk_appendf(&trash, |
| 5392 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5393 | conn, |
| 5394 | get_conn_ctrl_name(conn), |
| 5395 | get_conn_xprt_name(conn), |
| 5396 | get_conn_data_name(conn), |
| 5397 | obj_type_name(conn->target), |
| 5398 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5399 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5400 | chunk_appendf(&trash, |
| 5401 | " 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] | 5402 | conn->flags, |
| 5403 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5404 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5405 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5406 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5407 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5408 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5409 | chunk_appendf(&trash, |
| 5410 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5411 | tmpctx, |
| 5412 | tmpctx->st0, |
| 5413 | tmpctx->st1, |
| 5414 | tmpctx->st2, |
| 5415 | tmpctx->applet->name); |
| 5416 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5417 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5418 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5419 | " 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] | 5420 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5421 | &sess->req, |
| 5422 | sess->req.flags, sess->req.analysers, |
| 5423 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5424 | sess->req.to_forward, sess->req.total, |
| 5425 | sess->req.analyse_exp ? |
| 5426 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5427 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5428 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5429 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5430 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5431 | sess->req.rex ? |
| 5432 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5433 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5434 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5435 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5436 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5437 | " 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] | 5438 | sess->req.wex ? |
| 5439 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5440 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5441 | sess->req.buf, |
| 5442 | sess->req.buf->data, sess->req.buf->o, |
| 5443 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5444 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5445 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5446 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5447 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5448 | " 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] | 5449 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5450 | &sess->res, |
| 5451 | sess->res.flags, sess->res.analysers, |
| 5452 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5453 | sess->res.to_forward, sess->res.total, |
| 5454 | sess->res.analyse_exp ? |
| 5455 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5456 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5457 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5458 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5459 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5460 | sess->res.rex ? |
| 5461 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5462 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5463 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5464 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5465 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5466 | " 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] | 5467 | sess->res.wex ? |
| 5468 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5469 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5470 | sess->res.buf, |
| 5471 | sess->res.buf->data, sess->res.buf->o, |
| 5472 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5473 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5474 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5475 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5476 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5477 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5478 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5479 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5480 | |
| 5481 | /* use other states to dump the contents */ |
| 5482 | } |
| 5483 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5484 | appctx->ctx.sess.uid = 0; |
| 5485 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5486 | return 1; |
| 5487 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5488 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 5489 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 5490 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 5491 | struct appctx *appctx = __objt_appctx(si->end); |
| 5492 | |
| 5493 | switch (appctx->st2) { |
| 5494 | case STAT_ST_INIT: |
| 5495 | /* Display the column headers. If the message cannot be sent, |
| 5496 | * quit the fucntion with returning 0. The function is called |
| 5497 | * later and restart at the state "STAT_ST_INIT". |
| 5498 | */ |
| 5499 | chunk_reset(&trash); |
| 5500 | chunk_appendf(&trash, "# id (file)\n"); |
| 5501 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5502 | si_applet_cant_put(si); |
| 5503 | return 0; |
| 5504 | } |
| 5505 | |
| 5506 | /* Now, we start the browsing of the references lists. |
| 5507 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5508 | * avalaible field of this pointer is <list>. It is used with the function |
| 5509 | * tlskeys_list_get_next() for retruning the first avalaible entry |
| 5510 | */ |
| 5511 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 5512 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 5513 | |
| 5514 | appctx->st2 = STAT_ST_LIST; |
| 5515 | /* fall through */ |
| 5516 | |
| 5517 | case STAT_ST_LIST: |
| 5518 | while (appctx->ctx.tlskeys.ref) { |
| 5519 | chunk_reset(&trash); |
| 5520 | |
| 5521 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 5522 | appctx->ctx.tlskeys.ref->filename); |
| 5523 | |
| 5524 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 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. |
| 5527 | */ |
| 5528 | si_applet_cant_put(si); |
| 5529 | return 0; |
| 5530 | } |
| 5531 | |
| 5532 | /* get next list entry and check the end of the list */ |
| 5533 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 5534 | } |
| 5535 | |
| 5536 | appctx->st2 = STAT_ST_FIN; |
| 5537 | /* fall through */ |
| 5538 | |
| 5539 | default: |
| 5540 | appctx->st2 = STAT_ST_FIN; |
| 5541 | return 1; |
| 5542 | } |
| 5543 | return 0; |
| 5544 | } |
| 5545 | #endif |
| 5546 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5547 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5548 | { |
| 5549 | struct appctx *appctx = __objt_appctx(si->end); |
| 5550 | |
| 5551 | switch (appctx->st2) { |
| 5552 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5553 | /* Display the column headers. If the message cannot be sent, |
| 5554 | * quit the fucntion with returning 0. The function is called |
| 5555 | * later and restart at the state "STAT_ST_INIT". |
| 5556 | */ |
| 5557 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5558 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5559 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5560 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5561 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5562 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5563 | |
| 5564 | /* Now, we start the browsing of the references lists. |
| 5565 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5566 | * avalaible field of this pointer is <list>. It is used with the function |
| 5567 | * pat_list_get_next() for retruning the first avalaible entry |
| 5568 | */ |
| 5569 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5570 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5571 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5572 | appctx->st2 = STAT_ST_LIST; |
| 5573 | /* fall through */ |
| 5574 | |
| 5575 | case STAT_ST_LIST: |
| 5576 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5577 | chunk_reset(&trash); |
| 5578 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5579 | /* Build messages. If the reference is used by another category than |
| 5580 | * the listed categorie, display the information in the massage. |
| 5581 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5582 | 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] | 5583 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5584 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5585 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5586 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5587 | /* let's try again later from this stream. We add ourselves into |
| 5588 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5589 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5590 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5591 | return 0; |
| 5592 | } |
| 5593 | |
| 5594 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5595 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5596 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5597 | } |
| 5598 | |
| 5599 | appctx->st2 = STAT_ST_FIN; |
| 5600 | /* fall through */ |
| 5601 | |
| 5602 | default: |
| 5603 | appctx->st2 = STAT_ST_FIN; |
| 5604 | return 1; |
| 5605 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5606 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5607 | } |
| 5608 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5609 | static int stats_map_lookup(struct stream_interface *si) |
| 5610 | { |
| 5611 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5612 | struct sample sample; |
| 5613 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5614 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5615 | |
| 5616 | switch (appctx->st2) { |
| 5617 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5618 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5619 | 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] | 5620 | 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] | 5621 | appctx->st2 = STAT_ST_LIST; |
| 5622 | /* fall through */ |
| 5623 | |
| 5624 | case STAT_ST_LIST: |
| 5625 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5626 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5627 | /* initialise chunk to build new message */ |
| 5628 | chunk_reset(&trash); |
| 5629 | |
| 5630 | /* execute pattern matching */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 5631 | sample.data.type = SMP_T_STR; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 5632 | sample.flags |= SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 5633 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 5634 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5635 | if (appctx->ctx.map.expr->pat_head->match && |
| 5636 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5637 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5638 | else |
| 5639 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5640 | |
| 5641 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5642 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5643 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5644 | break; |
| 5645 | if (match_method >= PAT_MATCH_NUM) |
| 5646 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5647 | else |
| 5648 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5649 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5650 | /* case sensitive */ |
| 5651 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5652 | chunk_appendf(&trash, ", case=insensitive"); |
| 5653 | else |
| 5654 | chunk_appendf(&trash, ", case=sensitive"); |
| 5655 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5656 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5657 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5658 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5659 | chunk_appendf(&trash, ", found=no"); |
| 5660 | else |
| 5661 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5662 | } |
| 5663 | |
| 5664 | /* Display match and match info */ |
| 5665 | else { |
| 5666 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5667 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5668 | chunk_appendf(&trash, ", found=yes"); |
| 5669 | else |
| 5670 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5671 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5672 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5673 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5674 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5675 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5676 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5677 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5678 | /* display pattern */ |
| 5679 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5680 | if (pat->ref && pat->ref->pattern) |
| 5681 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5682 | else |
| 5683 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5684 | } |
| 5685 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5686 | if (pat->ref && pat->ref->pattern) |
| 5687 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5688 | else |
| 5689 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5690 | } |
| 5691 | |
| 5692 | /* display return value */ |
| 5693 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 5694 | if (pat->data && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 03d0e45 | 2015-07-23 18:33:41 +0200 | [diff] [blame] | 5695 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
Thierry FOURNIER | 7d4335c | 2015-08-19 09:05:25 +0200 | [diff] [blame] | 5696 | smp_to_type[pat->data->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5697 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5698 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5699 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5700 | } |
| 5701 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5702 | chunk_appendf(&trash, "\n"); |
| 5703 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5704 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5705 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5706 | /* let's try again later from this stream. We add ourselves into |
| 5707 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5708 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5709 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5710 | return 0; |
| 5711 | } |
| 5712 | |
| 5713 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5714 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5715 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5716 | } |
| 5717 | |
| 5718 | appctx->st2 = STAT_ST_FIN; |
| 5719 | /* fall through */ |
| 5720 | |
| 5721 | default: |
| 5722 | appctx->st2 = STAT_ST_FIN; |
| 5723 | free(appctx->ctx.map.chunk.str); |
| 5724 | return 1; |
| 5725 | } |
| 5726 | } |
| 5727 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5728 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5729 | { |
| 5730 | struct appctx *appctx = __objt_appctx(si->end); |
| 5731 | |
| 5732 | switch (appctx->st2) { |
| 5733 | |
| 5734 | case STAT_ST_INIT: |
| 5735 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5736 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5737 | struct pat_ref_elt *, list); |
| 5738 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5739 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5740 | appctx->st2 = STAT_ST_LIST; |
| 5741 | /* fall through */ |
| 5742 | |
| 5743 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5744 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5745 | chunk_reset(&trash); |
| 5746 | |
| 5747 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5748 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5749 | chunk_appendf(&trash, "%p %s %s\n", |
| 5750 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5751 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5752 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5753 | chunk_appendf(&trash, "%p %s\n", |
| 5754 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5755 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5756 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5757 | /* let's try again later from this stream. We add ourselves into |
| 5758 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5759 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5760 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5761 | return 0; |
| 5762 | } |
| 5763 | |
| 5764 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5765 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5766 | struct pat_ref_elt *, list); |
| 5767 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5768 | break; |
| 5769 | } |
| 5770 | |
| 5771 | appctx->st2 = STAT_ST_FIN; |
| 5772 | /* fall through */ |
| 5773 | |
| 5774 | default: |
| 5775 | appctx->st2 = STAT_ST_FIN; |
| 5776 | return 1; |
| 5777 | } |
| 5778 | } |
| 5779 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5780 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5781 | * 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] | 5782 | * to be called again, otherwise non-zero. It is designed to be called |
| 5783 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5784 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5785 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5786 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5787 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5788 | struct connection *conn; |
| 5789 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5790 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5791 | /* 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] | 5792 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5793 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5794 | if (appctx->st2 == STAT_ST_LIST) { |
| 5795 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5796 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5797 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5798 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5799 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5800 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5801 | } |
| 5802 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5803 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5804 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5805 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5806 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5807 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5808 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5809 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5810 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5811 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5812 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5813 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5814 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5815 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5816 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5817 | /* fall through */ |
| 5818 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5819 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5820 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5821 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 5822 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5823 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5827 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 5828 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5829 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5830 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5831 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5832 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5833 | if (appctx->ctx.sess.target) { |
| 5834 | 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] | 5835 | goto next_sess; |
| 5836 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5837 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5838 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5839 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5840 | return 0; |
| 5841 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5842 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5843 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 5844 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 5845 | if (appctx->ctx.sess.target != (void *)-1) { |
| 5846 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 5847 | break; |
| 5848 | } |
| 5849 | else |
| 5850 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5851 | } |
| 5852 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5853 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5854 | "%p: proto=%s", |
| 5855 | curr_sess, |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5856 | strm_li(curr_sess)->proto->name); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5857 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5858 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5859 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5860 | 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] | 5861 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5862 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5863 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5864 | " src=%s:%d fe=%s be=%s srv=%s", |
| 5865 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5866 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5867 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5868 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5869 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5870 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5871 | break; |
| 5872 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5873 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5874 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5875 | strm_li(curr_sess)->luid, |
| 5876 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5877 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5878 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5879 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5880 | break; |
| 5881 | } |
| 5882 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5883 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 5884 | " ts=%02x age=%s calls=%d", |
| 5885 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 5886 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 5887 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5888 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5889 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5890 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5891 | curr_sess->req.flags, |
| 5892 | curr_sess->req.buf->i, |
| 5893 | curr_sess->req.analysers, |
| 5894 | curr_sess->req.rex ? |
| 5895 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5896 | TICKS_TO_MS(1000)) : ""); |
| 5897 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5898 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5899 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5900 | curr_sess->req.wex ? |
| 5901 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5902 | TICKS_TO_MS(1000)) : ""); |
| 5903 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5904 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5905 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5906 | curr_sess->req.analyse_exp ? |
| 5907 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5908 | TICKS_TO_MS(1000)) : ""); |
| 5909 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5910 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5911 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5912 | curr_sess->res.flags, |
| 5913 | curr_sess->res.buf->i, |
| 5914 | curr_sess->res.analysers, |
| 5915 | curr_sess->res.rex ? |
| 5916 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5917 | TICKS_TO_MS(1000)) : ""); |
| 5918 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5919 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5920 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5921 | curr_sess->res.wex ? |
| 5922 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5923 | TICKS_TO_MS(1000)) : ""); |
| 5924 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5925 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5926 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5927 | curr_sess->res.analyse_exp ? |
| 5928 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5929 | TICKS_TO_MS(1000)) : ""); |
| 5930 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5931 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5932 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5933 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5934 | curr_sess->si[0].state, |
| 5935 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5936 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5937 | curr_sess->si[0].exp ? |
| 5938 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5939 | TICKS_TO_MS(1000)) : ""); |
| 5940 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5941 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5942 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5943 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5944 | curr_sess->si[1].state, |
| 5945 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5946 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5947 | curr_sess->si[1].exp ? |
| 5948 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5949 | TICKS_TO_MS(1000)) : ""); |
| 5950 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5951 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5952 | " exp=%s", |
| 5953 | curr_sess->task->expire ? |
| 5954 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5955 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5956 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5957 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5958 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5959 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5960 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5961 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5962 | /* let's try again later from this stream. We add ourselves into |
| 5963 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5964 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5965 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5966 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5967 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5968 | } |
| 5969 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5970 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5971 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5972 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5973 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5974 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5975 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5976 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5977 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5978 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5979 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5980 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5981 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5982 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5983 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5984 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5985 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5986 | appctx->ctx.sess.target = NULL; |
| 5987 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5988 | return 1; |
| 5989 | } |
| 5990 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5991 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5992 | /* fall through */ |
| 5993 | |
| 5994 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5995 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5996 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5997 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5998 | } |
| 5999 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6000 | /* This is called when the stream interface is closed. For instance, upon an |
| 6001 | * 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] | 6002 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6003 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 6004 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6005 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6006 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 6007 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 6008 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6009 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6010 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 6011 | free(appctx->ctx.cli.err); |
| 6012 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6013 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 6014 | free(appctx->ctx.map.chunk.str); |
| 6015 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6016 | } |
| 6017 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6018 | /* This function is used to either dump tables states (when action is set |
| 6019 | * 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] | 6020 | * It returns 0 if the output buffer is full and it needs to be called |
| 6021 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6022 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6023 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6024 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6025 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6026 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6027 | struct ebmb_node *eb; |
| 6028 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6029 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6030 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6031 | |
| 6032 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6033 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6034 | * - STAT_ST_INIT : the first call |
| 6035 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6036 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6037 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6038 | * and the entry pointer points to the next entry to be dumped, |
| 6039 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6040 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6041 | * data though. |
| 6042 | */ |
| 6043 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6044 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6045 | /* 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] | 6046 | if (appctx->st2 == STAT_ST_LIST) { |
| 6047 | appctx->ctx.table.entry->ref_cnt--; |
| 6048 | 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] | 6049 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6050 | return 1; |
| 6051 | } |
| 6052 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6053 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6054 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6055 | while (appctx->st2 != STAT_ST_FIN) { |
| 6056 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6057 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6058 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 6059 | if (!appctx->ctx.table.proxy) |
| 6060 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6061 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6062 | appctx->ctx.table.entry = NULL; |
| 6063 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6064 | break; |
| 6065 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6066 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6067 | if (!appctx->ctx.table.proxy || |
| 6068 | (appctx->ctx.table.target && |
| 6069 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6070 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6071 | break; |
| 6072 | } |
| 6073 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6074 | if (appctx->ctx.table.proxy->table.size) { |
| 6075 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6076 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6077 | return 0; |
| 6078 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6079 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6080 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6081 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6082 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6083 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6084 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6085 | appctx->ctx.table.entry->ref_cnt++; |
| 6086 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6087 | break; |
| 6088 | } |
| 6089 | } |
| 6090 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6091 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6092 | break; |
| 6093 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6094 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6095 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6096 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6097 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6098 | /* we're filtering on some data contents */ |
| 6099 | void *ptr; |
| 6100 | long long data; |
| 6101 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6102 | dt = appctx->ctx.table.data_type; |
| 6103 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6104 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6105 | dt); |
| 6106 | |
| 6107 | data = 0; |
| 6108 | switch (stktable_data_types[dt].std_type) { |
| 6109 | case STD_T_SINT: |
| 6110 | data = stktable_data_cast(ptr, std_t_sint); |
| 6111 | break; |
| 6112 | case STD_T_UINT: |
| 6113 | data = stktable_data_cast(ptr, std_t_uint); |
| 6114 | break; |
| 6115 | case STD_T_ULL: |
| 6116 | data = stktable_data_cast(ptr, std_t_ull); |
| 6117 | break; |
| 6118 | case STD_T_FRQP: |
| 6119 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6120 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6121 | break; |
| 6122 | } |
| 6123 | |
| 6124 | /* 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] | 6125 | if ((data < appctx->ctx.table.value && |
| 6126 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6127 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6128 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6129 | (data == appctx->ctx.table.value && |
| 6130 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6131 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6132 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6133 | (data > appctx->ctx.table.value && |
| 6134 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6135 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6136 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6137 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6138 | } |
| 6139 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6140 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6141 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6142 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6143 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6144 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6145 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6146 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6147 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6148 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6149 | struct stksess *old = appctx->ctx.table.entry; |
| 6150 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6151 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6152 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6153 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6154 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6155 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6156 | break; |
| 6157 | } |
| 6158 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6159 | |
| 6160 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6161 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6162 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6163 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6164 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6165 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6166 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6167 | break; |
| 6168 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6169 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6170 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6171 | break; |
| 6172 | } |
| 6173 | } |
| 6174 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6175 | } |
| 6176 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6177 | /* 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] | 6178 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6179 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6180 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6181 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6182 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6183 | * after the offset. The new pointer is returned. |
| 6184 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6185 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6186 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6187 | { |
| 6188 | int end; |
| 6189 | unsigned char c; |
| 6190 | |
| 6191 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6192 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6193 | return ptr; |
| 6194 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6195 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6196 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6197 | while (ptr < len && ptr < bsize) { |
| 6198 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6199 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6200 | if (out->len > end - 2) |
| 6201 | break; |
| 6202 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6203 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6204 | if (out->len > end - 3) |
| 6205 | break; |
| 6206 | out->str[out->len++] = '\\'; |
| 6207 | switch (c) { |
| 6208 | case '\t': c = 't'; break; |
| 6209 | case '\n': c = 'n'; break; |
| 6210 | case '\r': c = 'r'; break; |
| 6211 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6212 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6213 | } |
| 6214 | out->str[out->len++] = c; |
| 6215 | } else { |
| 6216 | if (out->len > end - 5) |
| 6217 | break; |
| 6218 | out->str[out->len++] = '\\'; |
| 6219 | out->str[out->len++] = 'x'; |
| 6220 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6221 | out->str[out->len++] = hextab[c & 0xF]; |
| 6222 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6223 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6224 | /* we had a line break, let's return now */ |
| 6225 | out->str[out->len++] = '\n'; |
| 6226 | *line = ptr; |
| 6227 | return ptr; |
| 6228 | } |
| 6229 | } |
| 6230 | /* we have an incomplete line, we return it as-is */ |
| 6231 | out->str[out->len++] = '\n'; |
| 6232 | return ptr; |
| 6233 | } |
| 6234 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6235 | /* This function dumps counters from all resolvers section and associated name servers. |
| 6236 | * It returns 0 if the output buffer is full and it needs |
| 6237 | * to be called again, otherwise non-zero. |
| 6238 | */ |
| 6239 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si) |
| 6240 | { |
| 6241 | struct appctx *appctx = __objt_appctx(si->end); |
| 6242 | struct dns_resolvers *presolvers; |
| 6243 | struct dns_nameserver *pnameserver; |
| 6244 | |
| 6245 | chunk_reset(&trash); |
| 6246 | |
| 6247 | switch (appctx->st2) { |
| 6248 | case STAT_ST_INIT: |
| 6249 | appctx->st2 = STAT_ST_LIST; /* let's start producing data */ |
| 6250 | /* fall through */ |
| 6251 | |
| 6252 | case STAT_ST_LIST: |
| 6253 | presolvers = appctx->ctx.resolvers.ptr; |
| 6254 | chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id); |
| 6255 | list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) { |
| 6256 | chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id); |
| 6257 | chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent); |
| 6258 | chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid); |
| 6259 | chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update); |
| 6260 | chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname); |
| 6261 | chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error); |
| 6262 | chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err); |
| 6263 | chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx); |
| 6264 | chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout); |
| 6265 | chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused); |
| 6266 | chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other); |
| 6267 | chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid); |
| 6268 | chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big); |
Baptiste Assmann | 6cdea93 | 2015-09-02 21:56:05 +0200 | [diff] [blame] | 6269 | chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated); |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6270 | chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated); |
| 6271 | } |
| 6272 | |
| 6273 | /* display response */ |
| 6274 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6275 | /* let's try again later from this session. We add ourselves into |
| 6276 | * this session's users so that it can remove us upon termination. |
| 6277 | */ |
| 6278 | si->flags |= SI_FL_WAIT_ROOM; |
| 6279 | return 0; |
| 6280 | } |
| 6281 | |
| 6282 | appctx->st2 = STAT_ST_FIN; |
| 6283 | /* fall through */ |
| 6284 | |
| 6285 | default: |
| 6286 | appctx->st2 = STAT_ST_FIN; |
| 6287 | return 1; |
| 6288 | } |
| 6289 | } |
| 6290 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6291 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6292 | * 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] | 6293 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6294 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6295 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6296 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6297 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6298 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6299 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6300 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6301 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6302 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6303 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6304 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6305 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6306 | /* the function had not been called yet, let's prepare the |
| 6307 | * buffer for a response. |
| 6308 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6309 | struct tm tm; |
| 6310 | |
| 6311 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6312 | 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] | 6313 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6314 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6315 | error_snapshot_id); |
| 6316 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6317 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6318 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6319 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6320 | return 0; |
| 6321 | } |
| 6322 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6323 | appctx->ctx.errors.px = proxy; |
| 6324 | appctx->ctx.errors.buf = 0; |
| 6325 | appctx->ctx.errors.bol = 0; |
| 6326 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6327 | } |
| 6328 | |
| 6329 | /* we have two inner loops here, one for the proxy, the other one for |
| 6330 | * the buffer. |
| 6331 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6332 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6333 | struct error_snapshot *es; |
| 6334 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6335 | if (appctx->ctx.errors.buf == 0) |
| 6336 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6337 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6338 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6339 | |
| 6340 | if (!es->when.tv_sec) |
| 6341 | goto next; |
| 6342 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6343 | if (appctx->ctx.errors.iid >= 0 && |
| 6344 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6345 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6346 | goto next; |
| 6347 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6348 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6349 | /* just print headers now */ |
| 6350 | |
| 6351 | char pn[INET6_ADDRSTRLEN]; |
| 6352 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6353 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6354 | |
| 6355 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6356 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6357 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6358 | 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] | 6359 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6360 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6361 | case AF_INET: |
| 6362 | case AF_INET6: |
| 6363 | port = get_host_port(&es->src); |
| 6364 | break; |
| 6365 | default: |
| 6366 | port = 0; |
| 6367 | } |
| 6368 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6369 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6370 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6371 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6372 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6373 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6374 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6375 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6376 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6377 | break; |
| 6378 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6379 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6380 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6381 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6382 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6383 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6384 | break; |
| 6385 | } |
| 6386 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6387 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6388 | ", server %s (#%d), event #%u\n" |
| 6389 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6390 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6391 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6392 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6393 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6394 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6395 | es->ev_id, |
| 6396 | pn, port, es->sid, es->s_flags, |
| 6397 | es->state, es->m_flags, es->t_flags, |
| 6398 | es->m_clen, es->m_blen, |
| 6399 | es->b_flags, es->b_out, es->b_tot, |
| 6400 | es->len, es->b_wrap, es->pos); |
| 6401 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6402 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6403 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6404 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6405 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6406 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6407 | appctx->ctx.errors.ptr = 0; |
| 6408 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6409 | } |
| 6410 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6411 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6412 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6413 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6414 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6415 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6416 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6417 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6418 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6419 | goto next; |
| 6420 | } |
| 6421 | |
| 6422 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6423 | 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] | 6424 | int newptr; |
| 6425 | int newline; |
| 6426 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6427 | newline = appctx->ctx.errors.bol; |
| 6428 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6429 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6430 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6431 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6432 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6433 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6434 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6435 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6436 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6437 | appctx->ctx.errors.ptr = newptr; |
| 6438 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6439 | }; |
| 6440 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6441 | appctx->ctx.errors.bol = 0; |
| 6442 | appctx->ctx.errors.ptr = -1; |
| 6443 | appctx->ctx.errors.buf++; |
| 6444 | if (appctx->ctx.errors.buf > 1) { |
| 6445 | appctx->ctx.errors.buf = 0; |
| 6446 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6447 | } |
| 6448 | } |
| 6449 | |
| 6450 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6451 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6452 | } |
| 6453 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6454 | /* parse the "level" argument on the bind lines */ |
| 6455 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6456 | { |
| 6457 | if (!*args[cur_arg + 1]) { |
| 6458 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6459 | return ERR_ALERT | ERR_FATAL; |
| 6460 | } |
| 6461 | |
| 6462 | if (!strcmp(args[cur_arg+1], "user")) |
| 6463 | conf->level = ACCESS_LVL_USER; |
| 6464 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6465 | conf->level = ACCESS_LVL_OPER; |
| 6466 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6467 | conf->level = ACCESS_LVL_ADMIN; |
| 6468 | else { |
| 6469 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6470 | args[cur_arg], args[cur_arg+1]); |
| 6471 | return ERR_ALERT | ERR_FATAL; |
| 6472 | } |
| 6473 | |
| 6474 | return 0; |
| 6475 | } |
| 6476 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 6477 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6478 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6479 | .name = "<STATS>", /* used for logging */ |
| 6480 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6481 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6482 | }; |
| 6483 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 6484 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6485 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6486 | .name = "<CLI>", /* used for logging */ |
| 6487 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6488 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6489 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6490 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6491 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6492 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6493 | { 0, NULL, NULL }, |
| 6494 | }}; |
| 6495 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6496 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6497 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6498 | { NULL, NULL, 0 }, |
| 6499 | }}; |
| 6500 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6501 | __attribute__((constructor)) |
| 6502 | static void __dumpstats_module_init(void) |
| 6503 | { |
| 6504 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6505 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6506 | } |
| 6507 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6508 | /* |
| 6509 | * Local variables: |
| 6510 | * c-indent-level: 8 |
| 6511 | * c-basic-offset: 8 |
| 6512 | * End: |
| 6513 | */ |