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