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 */ |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 95 | STAT_CLI_O_SERVERS_STATE, /* dump server state and changing information */ |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 96 | STAT_CLI_O_BACKEND, /* dump backend list */ |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 97 | STAT_CLI_O_ENV, /* dump environment */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 100 | /* Actions available for the stats admin forms */ |
| 101 | enum { |
| 102 | ST_ADM_ACTION_NONE = 0, |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 103 | |
| 104 | /* enable/disable health checks */ |
| 105 | ST_ADM_ACTION_DHLTH, |
| 106 | ST_ADM_ACTION_EHLTH, |
| 107 | |
| 108 | /* force health check status */ |
| 109 | ST_ADM_ACTION_HRUNN, |
| 110 | ST_ADM_ACTION_HNOLB, |
| 111 | ST_ADM_ACTION_HDOWN, |
| 112 | |
| 113 | /* enable/disable agent checks */ |
| 114 | ST_ADM_ACTION_DAGENT, |
| 115 | ST_ADM_ACTION_EAGENT, |
| 116 | |
| 117 | /* force agent check status */ |
| 118 | ST_ADM_ACTION_ARUNN, |
| 119 | ST_ADM_ACTION_ADOWN, |
| 120 | |
| 121 | /* set admin state */ |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 122 | ST_ADM_ACTION_READY, |
| 123 | ST_ADM_ACTION_DRAIN, |
| 124 | ST_ADM_ACTION_MAINT, |
| 125 | ST_ADM_ACTION_SHUTDOWN, |
| 126 | /* these are the ancient actions, still available for compatibility */ |
| 127 | ST_ADM_ACTION_DISABLE, |
| 128 | ST_ADM_ACTION_ENABLE, |
| 129 | ST_ADM_ACTION_STOP, |
| 130 | ST_ADM_ACTION_START, |
| 131 | }; |
| 132 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 133 | static int stats_dump_backend_to_buffer(struct stream_interface *si); |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 134 | static int stats_dump_env_to_buffer(struct stream_interface *si); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 135 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 136 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 137 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 138 | 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] | 139 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 140 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 141 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 142 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 143 | 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] | 144 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 145 | static int stats_pats_list(struct stream_interface *si); |
| 146 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 147 | static int stats_map_lookup(struct stream_interface *si); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 148 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 149 | static int stats_tlskeys_list(struct stream_interface *si); |
| 150 | #endif |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 151 | static void cli_release_handler(struct appctx *appctx); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 152 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 153 | static void dump_servers_state(struct proxy *backend, struct chunk *buf); |
| 154 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 155 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 156 | * cli_io_handler() |
| 157 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 158 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 159 | * -> stats_dump_info_to_buffer() // "show info" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 160 | * -> stats_dump_backend_to_buffer() // "show backend" |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 161 | * -> stats_dump_servers_state_to_buffer() // "show servers state [<backend name>]" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 162 | * -> stats_dump_stat_to_buffer() // "show stat" |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 163 | * -> stats_dump_resolvers_to_buffer() // "show stat resolver <id>" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 164 | * -> stats_dump_csv_header() |
| 165 | * -> stats_dump_proxy_to_buffer() |
| 166 | * -> stats_dump_fe_stats() |
| 167 | * -> stats_dump_li_stats() |
| 168 | * -> stats_dump_sv_stats() |
| 169 | * -> stats_dump_be_stats() |
| 170 | * |
| 171 | * http_stats_io_handler() |
| 172 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 173 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 174 | * -> stats_dump_html_head() // emits the HTML headers |
| 175 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 176 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 177 | * -> stats_dump_html_px_hdr() |
| 178 | * -> stats_dump_fe_stats() |
| 179 | * -> stats_dump_li_stats() |
| 180 | * -> stats_dump_sv_stats() |
| 181 | * -> stats_dump_be_stats() |
| 182 | * -> stats_dump_html_px_end() |
| 183 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 184 | */ |
| 185 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 186 | static struct applet cli_applet; |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 187 | |
| 188 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 189 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 190 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 191 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 192 | " help : this message\n" |
| 193 | " prompt : toggle interactive mode with prompt\n" |
| 194 | " quit : disconnect\n" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 195 | " show backend : list backends in the current running config\n" |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 196 | " show env [var] : dump environment variables known to the process\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 197 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 198 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 199 | " show stat : report counters for each proxy and server\n" |
| 200 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 201 | " 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] | 202 | " show table [id]: report table usage stats or dump this table's contents\n" |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 203 | " show servers state [id]: dump volatile server information (for backend <id>)\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 204 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 205 | " set weight : change a server's weight\n" |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 206 | " set server : change a server's state, weight or address\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 207 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 208 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 209 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 210 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 211 | " disable : put a server or frontend in maintenance mode\n" |
| 212 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 213 | " 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] | 214 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 215 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 216 | " add acl : add acl entry\n" |
| 217 | " del acl : delete acl entry\n" |
| 218 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 219 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 220 | " get map : reports the keys and values matching a sample for a map\n" |
| 221 | " set map : modify map entry\n" |
| 222 | " add map : add map entry\n" |
| 223 | " del map : delete map entry\n" |
| 224 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 225 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 226 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 227 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 228 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 229 | "Permission denied\n" |
| 230 | ""; |
| 231 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 232 | /* data transmission states for the stats responses */ |
| 233 | enum { |
| 234 | STAT_ST_INIT = 0, |
| 235 | STAT_ST_HEAD, |
| 236 | STAT_ST_INFO, |
| 237 | STAT_ST_LIST, |
| 238 | STAT_ST_END, |
| 239 | STAT_ST_FIN, |
| 240 | }; |
| 241 | |
| 242 | /* data transmission states for the stats responses inside a proxy */ |
| 243 | enum { |
| 244 | STAT_PX_ST_INIT = 0, |
| 245 | STAT_PX_ST_TH, |
| 246 | STAT_PX_ST_FE, |
| 247 | STAT_PX_ST_LI, |
| 248 | STAT_PX_ST_SV, |
| 249 | STAT_PX_ST_BE, |
| 250 | STAT_PX_ST_END, |
| 251 | STAT_PX_ST_FIN, |
| 252 | }; |
| 253 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 254 | extern const char *stat_status_codes[]; |
| 255 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 256 | /* allocate a new stats frontend named <name>, and return it |
| 257 | * (or NULL in case of lack of memory). |
| 258 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 259 | 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] | 260 | { |
| 261 | struct proxy *fe; |
| 262 | |
| 263 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 264 | if (!fe) |
| 265 | return NULL; |
| 266 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 267 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 268 | fe->next = proxy; |
| 269 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 270 | fe->last_change = now.tv_sec; |
| 271 | fe->id = strdup("GLOBAL"); |
| 272 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 273 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 274 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 275 | fe->conf.file = strdup(file); |
| 276 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 277 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 278 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 279 | |
| 280 | /* the stats frontend is the only one able to assign ID #0 */ |
| 281 | fe->conf.id.key = fe->uuid = 0; |
| 282 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 283 | return fe; |
| 284 | } |
| 285 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 286 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 287 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 288 | * error message into the <err> buffer which will be preallocated. The trailing |
| 289 | * '\n' must not be written. The function must be called with <args> pointing to |
| 290 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 291 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 292 | 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] | 293 | struct proxy *defpx, const char *file, int line, |
| 294 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 295 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 296 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 297 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 298 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 299 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 300 | int cur_arg; |
| 301 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 302 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 303 | 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] | 304 | return -1; |
| 305 | } |
| 306 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 307 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 308 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 309 | 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] | 310 | return -1; |
| 311 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 314 | 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] | 315 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 316 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 317 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 318 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 319 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 320 | return -1; |
| 321 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 322 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 323 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 324 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 325 | static int bind_dumped; |
| 326 | struct bind_kw *kw; |
| 327 | |
| 328 | kw = bind_find_kw(args[cur_arg]); |
| 329 | if (kw) { |
| 330 | if (!kw->parse) { |
| 331 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 332 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 333 | return -1; |
| 334 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 335 | |
Willy Tarreau | 061b5de | 2015-10-13 15:06:57 +0200 | [diff] [blame] | 336 | if (kw->parse(args, cur_arg, global.stats_fe, bind_conf, err) != 0) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 337 | if (err && *err) |
| 338 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 339 | else |
| 340 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 341 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 342 | return -1; |
| 343 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 344 | |
| 345 | cur_arg += 1 + kw->skip; |
| 346 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 347 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 348 | |
| 349 | if (!bind_dumped) { |
| 350 | bind_dump_kws(err); |
| 351 | indent_msg(err, 4); |
| 352 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 353 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 354 | |
| 355 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 356 | args[0], args[1], args[cur_arg], |
| 357 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 358 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 359 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 360 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 361 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 362 | l->maxconn = global.stats_fe->maxconn; |
| 363 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 364 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 365 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 366 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 367 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 368 | l->nice = -64; /* we want to boost priority for local stats */ |
| 369 | global.maxsock += l->maxconn; |
| 370 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 371 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 372 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 373 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 374 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 375 | |
| 376 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 377 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 378 | return -1; |
| 379 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 380 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 381 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 382 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 383 | return -1; |
| 384 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 385 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 386 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 387 | 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] | 388 | return -1; |
| 389 | } |
| 390 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 391 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 392 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 393 | else if (!strcmp(args[1], "maxconn")) { |
| 394 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 395 | |
| 396 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 397 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 398 | return -1; |
| 399 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 400 | |
| 401 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 402 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 403 | 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] | 404 | return -1; |
| 405 | } |
| 406 | } |
| 407 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 408 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 409 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 410 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 411 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 412 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 413 | if (!global.stats_fe) { |
| 414 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 415 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 416 | return -1; |
| 417 | } |
| 418 | } |
| 419 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 420 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 421 | unsigned int low, high; |
| 422 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 423 | if (strcmp(args[cur_arg], "all") == 0) { |
| 424 | set = 0; |
| 425 | break; |
| 426 | } |
| 427 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 428 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 429 | } |
| 430 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 431 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 432 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 433 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 434 | char *dash = strchr(args[cur_arg], '-'); |
| 435 | |
| 436 | low = high = str2uic(args[cur_arg]); |
| 437 | if (dash) |
| 438 | high = str2uic(dash + 1); |
| 439 | |
| 440 | if (high < low) { |
| 441 | unsigned int swap = low; |
| 442 | low = high; |
| 443 | high = swap; |
| 444 | } |
| 445 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 446 | if (low < 1 || high > LONGBITS) { |
| 447 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 448 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 449 | return -1; |
| 450 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 451 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 452 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 453 | } |
| 454 | else { |
| 455 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 456 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 457 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 458 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 459 | } |
| 460 | cur_arg++; |
| 461 | } |
| 462 | global.stats_fe->bind_proc = set; |
| 463 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 464 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 465 | 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] | 466 | return -1; |
| 467 | } |
| 468 | return 0; |
| 469 | } |
| 470 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 471 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 472 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 473 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 474 | * 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] | 475 | */ |
| 476 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 477 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 478 | chunk_appendf(&trash, |
| 479 | "# pxname,svname," |
| 480 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 481 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 482 | "bin,bout," |
| 483 | "dreq,dresp," |
| 484 | "ereq,econ,eresp," |
| 485 | "wretr,wredis," |
| 486 | "status,weight,act,bck," |
| 487 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 488 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 489 | "rate,rate_lim,rate_max," |
| 490 | "check_status,check_code,check_duration," |
| 491 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 492 | "req_rate,req_rate_max,req_tot," |
| 493 | "cli_abrt,srv_abrt," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 494 | "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] | 495 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 496 | } |
| 497 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 498 | /* print a string of text buffer to <out>. The format is : |
| 499 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 500 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 501 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 502 | */ |
| 503 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 504 | { |
| 505 | unsigned char c; |
| 506 | int ptr = 0; |
| 507 | |
| 508 | while (buf[ptr] && ptr < bsize) { |
| 509 | c = buf[ptr]; |
| 510 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 511 | if (out->len > out->size - 1) |
| 512 | break; |
| 513 | out->str[out->len++] = c; |
| 514 | } |
| 515 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 516 | if (out->len > out->size - 2) |
| 517 | break; |
| 518 | out->str[out->len++] = '\\'; |
| 519 | switch (c) { |
| 520 | case ' ': c = ' '; break; |
| 521 | case '\t': c = 't'; break; |
| 522 | case '\n': c = 'n'; break; |
| 523 | case '\r': c = 'r'; break; |
| 524 | case '\e': c = 'e'; break; |
| 525 | case '\\': c = '\\'; break; |
| 526 | } |
| 527 | out->str[out->len++] = c; |
| 528 | } |
| 529 | else { |
| 530 | if (out->len > out->size - 4) |
| 531 | break; |
| 532 | out->str[out->len++] = '\\'; |
| 533 | out->str[out->len++] = 'x'; |
| 534 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 535 | out->str[out->len++] = hextab[c & 0xF]; |
| 536 | } |
| 537 | ptr++; |
| 538 | } |
| 539 | |
| 540 | return ptr; |
| 541 | } |
| 542 | |
| 543 | /* print a buffer in hexa. |
| 544 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 545 | */ |
| 546 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 547 | { |
| 548 | unsigned char c; |
| 549 | int ptr = 0; |
| 550 | |
| 551 | while (ptr < bsize) { |
| 552 | c = buf[ptr]; |
| 553 | |
| 554 | if (out->len > out->size - 2) |
| 555 | break; |
| 556 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 557 | out->str[out->len++] = hextab[c & 0xF]; |
| 558 | |
| 559 | ptr++; |
| 560 | } |
| 561 | return ptr; |
| 562 | } |
| 563 | |
| 564 | /* Dump the status of a table to a stream interface's |
| 565 | * read buffer. It returns 0 if the output buffer is full |
| 566 | * and needs to be called again, otherwise non-zero. |
| 567 | */ |
| 568 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 569 | struct proxy *proxy, struct proxy *target) |
| 570 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 571 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 572 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 573 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 574 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 575 | |
| 576 | /* any other information should be dumped here */ |
| 577 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 578 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 579 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 580 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 581 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 582 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 583 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 584 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 585 | |
| 586 | return 1; |
| 587 | } |
| 588 | |
| 589 | /* Dump the a table entry to a stream interface's |
| 590 | * read buffer. It returns 0 if the output buffer is full |
| 591 | * and needs to be called again, otherwise non-zero. |
| 592 | */ |
| 593 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 594 | struct proxy *proxy, struct stksess *entry) |
| 595 | { |
| 596 | int dt; |
| 597 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 598 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 599 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 600 | if (proxy->table.type == SMP_T_IPV4) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 601 | char addr[INET_ADDRSTRLEN]; |
| 602 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 603 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 604 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 605 | else if (proxy->table.type == SMP_T_IPV6) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 606 | char addr[INET6_ADDRSTRLEN]; |
| 607 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 608 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 609 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 610 | else if (proxy->table.type == SMP_T_SINT) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 611 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 612 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 613 | else if (proxy->table.type == SMP_T_STR) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 614 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 615 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 616 | } |
| 617 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 618 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 619 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 620 | } |
| 621 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 622 | 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] | 623 | |
| 624 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 625 | void *ptr; |
| 626 | |
| 627 | if (proxy->table.data_ofs[dt] == 0) |
| 628 | continue; |
| 629 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 630 | 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] | 631 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 632 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 633 | |
| 634 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 635 | switch (stktable_data_types[dt].std_type) { |
| 636 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 637 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 638 | break; |
| 639 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 640 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 641 | break; |
| 642 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 643 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 644 | break; |
| 645 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 646 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 647 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 648 | proxy->table.data_arg[dt].u)); |
| 649 | break; |
| 650 | } |
| 651 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 652 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 653 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 654 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 655 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 656 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 657 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 658 | |
| 659 | return 1; |
| 660 | } |
| 661 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 662 | 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] | 663 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 664 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 665 | struct appctx *appctx = __objt_appctx(si->end); |
| 666 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 667 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 668 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 669 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 670 | long long value; |
| 671 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 672 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 673 | void *ptr; |
| 674 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 675 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 676 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 677 | |
| 678 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 679 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 680 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 681 | return; |
| 682 | } |
| 683 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 684 | switch (px->table.type) { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 685 | case SMP_T_IPV4: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 686 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 687 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 688 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 689 | case SMP_T_IPV6: |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 690 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 691 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 692 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 693 | case SMP_T_SINT: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 694 | { |
| 695 | char *endptr; |
| 696 | unsigned long val; |
| 697 | errno = 0; |
| 698 | val = strtoul(args[4], &endptr, 10); |
| 699 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 700 | (errno != 0 && val == 0) || endptr == args[4] || |
| 701 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 702 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 703 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 704 | return; |
| 705 | } |
| 706 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 707 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 708 | break; |
| 709 | } |
| 710 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 711 | case SMP_T_STR: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 712 | static_table_key->key = args[4]; |
| 713 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 714 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 715 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 716 | switch (action) { |
| 717 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 718 | 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] | 719 | break; |
| 720 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 721 | 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] | 722 | break; |
| 723 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 724 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 725 | break; |
| 726 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 727 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 728 | return; |
| 729 | } |
| 730 | |
| 731 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 732 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 733 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 734 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 735 | return; |
| 736 | } |
| 737 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 738 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 739 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 740 | switch (action) { |
| 741 | case STAT_CLI_O_TAB: |
| 742 | if (!ts) |
| 743 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 744 | chunk_reset(&trash); |
| 745 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 746 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 747 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 748 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 749 | |
| 750 | case STAT_CLI_O_CLR: |
| 751 | if (!ts) |
| 752 | return; |
| 753 | if (ts->ref_cnt) { |
| 754 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 755 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 756 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 757 | return; |
| 758 | } |
| 759 | stksess_kill(&px->table, ts); |
| 760 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 761 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 762 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 763 | if (ts) |
| 764 | stktable_touch(&px->table, ts, 1); |
| 765 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 766 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 767 | if (!ts) { |
| 768 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 769 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 770 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 771 | return; |
| 772 | } |
| 773 | stktable_store(&px->table, ts, 1); |
| 774 | } |
| 775 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 776 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 777 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 778 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 779 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 780 | return; |
| 781 | } |
| 782 | |
| 783 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 784 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 785 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 786 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 787 | return; |
| 788 | } |
| 789 | |
| 790 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 791 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 792 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 793 | return; |
| 794 | } |
| 795 | |
| 796 | 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] | 797 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 798 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 799 | return; |
| 800 | } |
| 801 | |
| 802 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 803 | |
| 804 | switch (stktable_data_types[data_type].std_type) { |
| 805 | case STD_T_SINT: |
| 806 | stktable_data_cast(ptr, std_t_sint) = value; |
| 807 | break; |
| 808 | case STD_T_UINT: |
| 809 | stktable_data_cast(ptr, std_t_uint) = value; |
| 810 | break; |
| 811 | case STD_T_ULL: |
| 812 | stktable_data_cast(ptr, std_t_ull) = value; |
| 813 | break; |
| 814 | case STD_T_FRQP: |
| 815 | /* We set both the current and previous values. That way |
| 816 | * the reported frequency is stable during all the period |
| 817 | * then slowly fades out. This allows external tools to |
| 818 | * push measures without having to update them too often. |
| 819 | */ |
| 820 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 821 | frqp->curr_tick = now_ms; |
| 822 | frqp->prev_ctr = 0; |
| 823 | frqp->curr_ctr = value; |
| 824 | break; |
| 825 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 826 | } |
| 827 | break; |
| 828 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 829 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 830 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 831 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 832 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 833 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 834 | } |
| 835 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 836 | 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] | 837 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 838 | struct appctx *appctx = __objt_appctx(si->end); |
| 839 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 840 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 841 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 842 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 843 | return; |
| 844 | } |
| 845 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 846 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 847 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 848 | if (appctx->ctx.table.data_type < 0) { |
| 849 | appctx->ctx.cli.msg = "Unknown data type\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 (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 855 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 856 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 857 | return; |
| 858 | } |
| 859 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 860 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 861 | if (appctx->ctx.table.data_op < 0) { |
| 862 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 863 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 864 | return; |
| 865 | } |
| 866 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 867 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 868 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 869 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 870 | return; |
| 871 | } |
| 872 | } |
| 873 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 874 | 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] | 875 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 876 | struct appctx *appctx = __objt_appctx(si->end); |
| 877 | |
| 878 | appctx->ctx.table.data_type = -1; |
| 879 | appctx->st2 = STAT_ST_INIT; |
| 880 | appctx->ctx.table.target = NULL; |
| 881 | appctx->ctx.table.proxy = NULL; |
| 882 | appctx->ctx.table.entry = NULL; |
| 883 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 884 | |
| 885 | if (*args[2]) { |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 886 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 887 | if (!appctx->ctx.table.target) { |
| 888 | appctx->ctx.cli.msg = "No such table\n"; |
| 889 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 890 | return; |
| 891 | } |
| 892 | } |
| 893 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 894 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 895 | goto err_args; |
| 896 | return; |
| 897 | } |
| 898 | |
| 899 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 900 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 901 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 902 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 903 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 904 | goto err_args; |
| 905 | |
| 906 | return; |
| 907 | |
| 908 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 909 | switch (action) { |
| 910 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 911 | 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] | 912 | break; |
| 913 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 914 | 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] | 915 | break; |
| 916 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 917 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 918 | break; |
| 919 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 920 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 921 | } |
| 922 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 923 | /* 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] | 924 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 925 | * level to be admin. |
| 926 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 927 | 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] | 928 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 929 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 930 | struct proxy *px; |
| 931 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 932 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 933 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 934 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 935 | return NULL; |
| 936 | } |
| 937 | |
| 938 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 939 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 940 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 941 | return NULL; |
| 942 | } |
| 943 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 944 | px = proxy_fe_by_name(arg); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 945 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 946 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 947 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 948 | return NULL; |
| 949 | } |
| 950 | return px; |
| 951 | } |
| 952 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 953 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 954 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 955 | * 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] | 956 | * the <arg> is modified to remove the '/'. |
| 957 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 958 | 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] | 959 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 960 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 961 | struct proxy *px; |
| 962 | struct server *sv; |
| 963 | char *line; |
| 964 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 965 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 966 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 967 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 968 | return NULL; |
| 969 | } |
| 970 | |
| 971 | /* split "backend/server" and make <line> point to server */ |
| 972 | for (line = arg; *line; line++) |
| 973 | if (*line == '/') { |
| 974 | *line++ = '\0'; |
| 975 | break; |
| 976 | } |
| 977 | |
| 978 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 979 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 980 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 981 | return NULL; |
| 982 | } |
| 983 | |
| 984 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 985 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 986 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 987 | return NULL; |
| 988 | } |
| 989 | |
| 990 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 991 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 992 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 993 | return NULL; |
| 994 | } |
| 995 | |
| 996 | return sv; |
| 997 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 998 | |
| 999 | /* This function is used with TLS ticket keys management. It permits to browse |
| 1000 | * each reference. The variable <getnext> must contain the current node, |
| 1001 | * <end> point to the root node. |
| 1002 | */ |
| 1003 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1004 | static inline |
| 1005 | struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end) |
| 1006 | { |
| 1007 | struct tls_keys_ref *ref = getnext; |
| 1008 | |
| 1009 | while (1) { |
| 1010 | |
| 1011 | /* Get next list entry. */ |
| 1012 | ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list); |
| 1013 | |
| 1014 | /* If the entry is the last of the list, return NULL. */ |
| 1015 | if (&ref->list == end) |
| 1016 | return NULL; |
| 1017 | |
| 1018 | return ref; |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | static inline |
| 1023 | struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference) |
| 1024 | { |
| 1025 | int id; |
| 1026 | char *error; |
| 1027 | |
| 1028 | /* If the reference starts by a '#', this is numeric id. */ |
| 1029 | if (reference[0] == '#') { |
| 1030 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1031 | id = strtol(reference + 1, &error, 10); |
| 1032 | if (*error != '\0') |
| 1033 | return NULL; |
| 1034 | |
| 1035 | /* Perform the unique id lookup. */ |
| 1036 | return tlskeys_ref_lookupid(id); |
| 1037 | } |
| 1038 | |
| 1039 | /* Perform the string lookup. */ |
| 1040 | return tlskeys_ref_lookup(reference); |
| 1041 | } |
| 1042 | #endif |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1043 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1044 | /* This function is used with map and acl management. It permits to browse |
| 1045 | * each reference. The variable <getnext> must contain the current node, |
| 1046 | * <end> point to the root node and the <flags> permit to filter required |
| 1047 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1048 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1049 | static inline |
| 1050 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1051 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1052 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1053 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1054 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1055 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1056 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1057 | /* Get next list entry. */ |
| 1058 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1059 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1060 | /* If the entry is the last of the list, return NULL. */ |
| 1061 | if (&ref->list == end) |
| 1062 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1063 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1064 | /* If the entry match the flag, return it. */ |
| 1065 | if (ref->flags & flags) |
| 1066 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1070 | static inline |
| 1071 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1072 | { |
| 1073 | int id; |
| 1074 | char *error; |
| 1075 | |
| 1076 | /* If the reference starts by a '#', this is numeric id. */ |
| 1077 | if (reference[0] == '#') { |
| 1078 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1079 | id = strtol(reference + 1, &error, 10); |
| 1080 | if (*error != '\0') |
| 1081 | return NULL; |
| 1082 | |
| 1083 | /* Perform the unique id lookup. */ |
| 1084 | return pat_ref_lookupid(id); |
| 1085 | } |
| 1086 | |
| 1087 | /* Perform the string lookup. */ |
| 1088 | return pat_ref_lookup(reference); |
| 1089 | } |
| 1090 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1091 | /* This function is used with map and acl management. It permits to browse |
| 1092 | * each reference. |
| 1093 | */ |
| 1094 | static inline |
| 1095 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1096 | { |
| 1097 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1098 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1099 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1100 | return NULL; |
| 1101 | return expr; |
| 1102 | } |
| 1103 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1104 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1105 | * 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] | 1106 | * 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] | 1107 | * designating the function which will have to process the request, which can |
| 1108 | * 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] | 1109 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1110 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1111 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1112 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1113 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1114 | char *args[MAX_STATS_ARGS + 1]; |
| 1115 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1116 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1117 | |
| 1118 | while (isspace((unsigned char)*line)) |
| 1119 | line++; |
| 1120 | |
| 1121 | arg = 0; |
| 1122 | args[arg] = line; |
| 1123 | |
| 1124 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1125 | if (*line == '\\') { |
| 1126 | line++; |
| 1127 | if (*line == '\0') |
| 1128 | break; |
| 1129 | } |
| 1130 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1131 | *line++ = '\0'; |
| 1132 | |
| 1133 | while (isspace((unsigned char)*line)) |
| 1134 | line++; |
| 1135 | |
| 1136 | args[++arg] = line; |
| 1137 | continue; |
| 1138 | } |
| 1139 | |
| 1140 | line++; |
| 1141 | } |
| 1142 | |
| 1143 | while (++arg <= MAX_STATS_ARGS) |
| 1144 | args[arg] = line; |
| 1145 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1146 | /* remove \ */ |
| 1147 | arg = 0; |
| 1148 | while (*args[arg] != '\0') { |
| 1149 | j = 0; |
| 1150 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1151 | if (args[arg][i] == '\\') |
| 1152 | continue; |
| 1153 | args[arg][j] = args[arg][i]; |
| 1154 | j++; |
| 1155 | } |
| 1156 | args[arg][j] = '\0'; |
| 1157 | arg++; |
| 1158 | } |
| 1159 | |
Willy Tarreau | 6bcb95d | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1160 | appctx->ctx.stats.scope_str = 0; |
| 1161 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1162 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1163 | if (strcmp(args[0], "show") == 0) { |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 1164 | if (strcmp(args[1], "backend") == 0) { |
| 1165 | appctx->st2 = STAT_ST_INIT; |
| 1166 | appctx->st0 = STAT_CLI_O_BACKEND; |
| 1167 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 1168 | else if (strcmp(args[1], "env") == 0) { |
| 1169 | extern char **environ; |
| 1170 | |
| 1171 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
| 1172 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1173 | appctx->st0 = STAT_CLI_PRINT; |
| 1174 | return 1; |
| 1175 | } |
| 1176 | appctx->ctx.env.var = environ; |
| 1177 | appctx->st2 = STAT_ST_INIT; |
| 1178 | appctx->st0 = STAT_CLI_O_ENV; // stats_dump_env_to_buffer |
| 1179 | |
| 1180 | if (*args[2]) { |
| 1181 | int len = strlen(args[2]); |
| 1182 | |
| 1183 | for (; *appctx->ctx.env.var; appctx->ctx.env.var++) { |
| 1184 | if (strncmp(*appctx->ctx.env.var, args[2], len) == 0 && |
| 1185 | (*appctx->ctx.env.var)[len] == '=') |
| 1186 | break; |
| 1187 | } |
| 1188 | if (!*appctx->ctx.env.var) { |
| 1189 | appctx->ctx.cli.msg = "Variable not found\n"; |
| 1190 | appctx->st0 = STAT_CLI_PRINT; |
| 1191 | return 1; |
| 1192 | } |
| 1193 | appctx->st2 = STAT_ST_END; |
| 1194 | } |
| 1195 | } |
| 1196 | else if (strcmp(args[1], "stat") == 0) { |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1197 | if (strcmp(args[2], "resolvers") == 0) { |
| 1198 | struct dns_resolvers *presolvers; |
| 1199 | |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1200 | if (*args[3]) { |
| 1201 | appctx->ctx.resolvers.ptr = NULL; |
| 1202 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 1203 | if (strcmp(presolvers->id, args[3]) == 0) { |
| 1204 | appctx->ctx.resolvers.ptr = presolvers; |
| 1205 | break; |
| 1206 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1207 | } |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1208 | if (appctx->ctx.resolvers.ptr == NULL) { |
| 1209 | appctx->ctx.cli.msg = "Can't find that resolvers section\n"; |
| 1210 | appctx->st0 = STAT_CLI_PRINT; |
| 1211 | return 1; |
| 1212 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | appctx->st2 = STAT_ST_INIT; |
| 1216 | appctx->st0 = STAT_CLI_O_RESOLVERS; |
| 1217 | return 1; |
| 1218 | } |
| 1219 | else if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1220 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1221 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1222 | appctx->ctx.stats.type = atoi(args[3]); |
| 1223 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1224 | } |
| 1225 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1226 | appctx->st2 = STAT_ST_INIT; |
| 1227 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1228 | } |
| 1229 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1230 | appctx->st2 = STAT_ST_INIT; |
| 1231 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1232 | } |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1233 | else if (strcmp(args[1], "servers") == 0 && strcmp(args[2], "state") == 0) { |
| 1234 | appctx->ctx.server_state.backend = NULL; |
| 1235 | |
| 1236 | /* check if a backend name has been provided */ |
| 1237 | if (*args[3]) { |
| 1238 | /* read server state from local file */ |
| 1239 | appctx->ctx.server_state.backend = proxy_be_by_name(args[3]); |
| 1240 | |
| 1241 | if (appctx->ctx.server_state.backend == NULL) { |
| 1242 | appctx->ctx.cli.msg = "Can't find backend.\n"; |
| 1243 | appctx->st0 = STAT_CLI_PRINT; |
| 1244 | return 1; |
| 1245 | } |
| 1246 | } |
| 1247 | appctx->st2 = STAT_ST_INIT; |
| 1248 | appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer |
| 1249 | return 1; |
| 1250 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1251 | else if (strcmp(args[1], "pools") == 0) { |
| 1252 | appctx->st2 = STAT_ST_INIT; |
| 1253 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1254 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1255 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1256 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1257 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1258 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1259 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1260 | return 1; |
| 1261 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1262 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1263 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1264 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1265 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1266 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1267 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1268 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1269 | appctx->ctx.sess.pos = 0; |
| 1270 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1271 | } |
| 1272 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1273 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1274 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1275 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1276 | return 1; |
| 1277 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1278 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1279 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1280 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1281 | appctx->ctx.errors.iid = -1; |
| 1282 | appctx->ctx.errors.px = NULL; |
| 1283 | appctx->st2 = STAT_ST_INIT; |
| 1284 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1285 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1286 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1287 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1288 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1289 | else if (strcmp(args[1], "tls-keys") == 0) { |
| 1290 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1291 | appctx->st2 = STAT_ST_INIT; |
| 1292 | appctx->st0 = STAT_CLI_O_TLSK; |
| 1293 | #else |
| 1294 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1295 | "that doesn't support specifying TLS ticket keys\n"; |
| 1296 | appctx->st0 = STAT_CLI_PRINT; |
| 1297 | #endif |
| 1298 | return 1; |
| 1299 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1300 | else if (strcmp(args[1], "map") == 0 || |
| 1301 | strcmp(args[1], "acl") == 0) { |
| 1302 | |
| 1303 | /* Set ACL or MAP flags. */ |
| 1304 | if (args[1][0] == 'm') |
| 1305 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1306 | else |
| 1307 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1308 | |
| 1309 | /* no parameter: display all map avalaible */ |
| 1310 | if (!*args[2]) { |
| 1311 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1312 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1313 | return 1; |
| 1314 | } |
| 1315 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1316 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1317 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1318 | if (!appctx->ctx.map.ref || |
| 1319 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1320 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1321 | 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] | 1322 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1323 | 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] | 1324 | appctx->st0 = STAT_CLI_PRINT; |
| 1325 | return 1; |
| 1326 | } |
| 1327 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1328 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1329 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1330 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1331 | return 0; |
| 1332 | } |
| 1333 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1334 | else if (strcmp(args[0], "clear") == 0) { |
| 1335 | if (strcmp(args[1], "counters") == 0) { |
| 1336 | struct proxy *px; |
| 1337 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1338 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1339 | int clrall = 0; |
| 1340 | |
| 1341 | if (strcmp(args[2], "all") == 0) |
| 1342 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1343 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1344 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1345 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1346 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1347 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1348 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1349 | return 1; |
| 1350 | } |
| 1351 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1352 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1353 | if (clrall) { |
| 1354 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1355 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1356 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1357 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1358 | px->be_counters.conn_max = 0; |
| 1359 | px->be_counters.p.http.rps_max = 0; |
| 1360 | px->be_counters.sps_max = 0; |
| 1361 | px->be_counters.cps_max = 0; |
| 1362 | px->be_counters.nbpend_max = 0; |
| 1363 | |
| 1364 | px->fe_counters.conn_max = 0; |
| 1365 | px->fe_counters.p.http.rps_max = 0; |
| 1366 | px->fe_counters.sps_max = 0; |
| 1367 | px->fe_counters.cps_max = 0; |
| 1368 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1369 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1370 | |
| 1371 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1372 | if (clrall) |
| 1373 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1374 | else { |
| 1375 | sv->counters.cur_sess_max = 0; |
| 1376 | sv->counters.nbpend_max = 0; |
| 1377 | sv->counters.sps_max = 0; |
| 1378 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1379 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1380 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1381 | if (li->counters) { |
| 1382 | if (clrall) |
| 1383 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1384 | else |
| 1385 | li->counters->conn_max = 0; |
| 1386 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1387 | } |
| 1388 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1389 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1390 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1391 | return 1; |
| 1392 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1393 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1394 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1395 | /* end of processing */ |
| 1396 | return 1; |
| 1397 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1398 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1399 | /* Set ACL or MAP flags. */ |
| 1400 | if (args[1][0] == 'm') |
| 1401 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1402 | else |
| 1403 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1404 | |
| 1405 | /* no parameter */ |
| 1406 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1407 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1408 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1409 | else |
| 1410 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1411 | appctx->st0 = STAT_CLI_PRINT; |
| 1412 | return 1; |
| 1413 | } |
| 1414 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1415 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1416 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1417 | if (!appctx->ctx.map.ref || |
| 1418 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1419 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1420 | 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] | 1421 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1422 | 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] | 1423 | appctx->st0 = STAT_CLI_PRINT; |
| 1424 | return 1; |
| 1425 | } |
| 1426 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1427 | /* Clear all. */ |
| 1428 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1429 | |
| 1430 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1431 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1432 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1433 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1434 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1435 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1436 | return 0; |
| 1437 | } |
| 1438 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1439 | else if (strcmp(args[0], "get") == 0) { |
| 1440 | if (strcmp(args[1], "weight") == 0) { |
| 1441 | struct proxy *px; |
| 1442 | struct server *sv; |
| 1443 | |
| 1444 | /* split "backend/server" and make <line> point to server */ |
| 1445 | for (line = args[2]; *line; line++) |
| 1446 | if (*line == '/') { |
| 1447 | *line++ = '\0'; |
| 1448 | break; |
| 1449 | } |
| 1450 | |
| 1451 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1452 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1453 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1454 | return 1; |
| 1455 | } |
| 1456 | |
| 1457 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1458 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1459 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1460 | return 1; |
| 1461 | } |
| 1462 | |
| 1463 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1464 | 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] | 1465 | if (bi_putstr(si_ic(si), trash.str) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 1466 | si_applet_cant_put(si); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1467 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1468 | return 1; |
| 1469 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1470 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1471 | /* Set flags. */ |
| 1472 | if (args[1][0] == 'm') |
| 1473 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1474 | else |
| 1475 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1476 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1477 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1478 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1479 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1480 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1481 | else |
| 1482 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1483 | appctx->st0 = STAT_CLI_PRINT; |
| 1484 | return 1; |
| 1485 | } |
| 1486 | |
| 1487 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1488 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1489 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1490 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1491 | 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] | 1492 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1493 | 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] | 1494 | appctx->st0 = STAT_CLI_PRINT; |
| 1495 | return 1; |
| 1496 | } |
| 1497 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1498 | /* copy input string. The string must be allocated because |
| 1499 | * it may be used over multiple iterations. It's released |
| 1500 | * at the end and upon abort anyway. |
| 1501 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1502 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1503 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1504 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1505 | if (!appctx->ctx.map.chunk.str) { |
| 1506 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1507 | appctx->st0 = STAT_CLI_PRINT; |
| 1508 | return 1; |
| 1509 | } |
| 1510 | |
| 1511 | /* prepare response */ |
| 1512 | appctx->st2 = STAT_ST_INIT; |
| 1513 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1514 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1515 | else { /* not "get weight" */ |
| 1516 | return 0; |
| 1517 | } |
| 1518 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1519 | else if (strcmp(args[0], "set") == 0) { |
| 1520 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1521 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1522 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1523 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1524 | sv = expect_server_admin(s, si, args[2]); |
| 1525 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1526 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1527 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1528 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1529 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1530 | appctx->ctx.cli.msg = warning; |
| 1531 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1532 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1533 | return 1; |
| 1534 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1535 | else if (strcmp(args[1], "server") == 0) { |
| 1536 | struct server *sv; |
| 1537 | const char *warning; |
| 1538 | |
| 1539 | sv = expect_server_admin(s, si, args[2]); |
| 1540 | if (!sv) |
| 1541 | return 1; |
| 1542 | |
| 1543 | if (strcmp(args[3], "weight") == 0) { |
| 1544 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1545 | if (warning) { |
| 1546 | appctx->ctx.cli.msg = warning; |
| 1547 | appctx->st0 = STAT_CLI_PRINT; |
| 1548 | } |
| 1549 | } |
| 1550 | else if (strcmp(args[3], "state") == 0) { |
| 1551 | if (strcmp(args[4], "ready") == 0) |
| 1552 | srv_adm_set_ready(sv); |
| 1553 | else if (strcmp(args[4], "drain") == 0) |
| 1554 | srv_adm_set_drain(sv); |
| 1555 | else if (strcmp(args[4], "maint") == 0) |
| 1556 | srv_adm_set_maint(sv); |
| 1557 | else { |
| 1558 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1559 | appctx->st0 = STAT_CLI_PRINT; |
| 1560 | } |
| 1561 | } |
| 1562 | else if (strcmp(args[3], "health") == 0) { |
| 1563 | if (sv->track) { |
| 1564 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1565 | appctx->st0 = STAT_CLI_PRINT; |
| 1566 | } |
| 1567 | else if (strcmp(args[4], "up") == 0) { |
| 1568 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1569 | srv_set_running(sv, "changed from CLI"); |
| 1570 | } |
| 1571 | else if (strcmp(args[4], "stopping") == 0) { |
| 1572 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1573 | srv_set_stopping(sv, "changed from CLI"); |
| 1574 | } |
| 1575 | else if (strcmp(args[4], "down") == 0) { |
| 1576 | sv->check.health = 0; |
| 1577 | srv_set_stopped(sv, "changed from CLI"); |
| 1578 | } |
| 1579 | else { |
| 1580 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1581 | appctx->st0 = STAT_CLI_PRINT; |
| 1582 | } |
| 1583 | } |
| 1584 | else if (strcmp(args[3], "agent") == 0) { |
| 1585 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1586 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1587 | appctx->st0 = STAT_CLI_PRINT; |
| 1588 | } |
| 1589 | else if (strcmp(args[4], "up") == 0) { |
| 1590 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1591 | srv_set_running(sv, "changed from CLI"); |
| 1592 | } |
| 1593 | else if (strcmp(args[4], "down") == 0) { |
| 1594 | sv->agent.health = 0; |
| 1595 | srv_set_stopped(sv, "changed from CLI"); |
| 1596 | } |
| 1597 | else { |
| 1598 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1599 | appctx->st0 = STAT_CLI_PRINT; |
| 1600 | } |
| 1601 | } |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1602 | else if (strcmp(args[3], "addr") == 0) { |
Thierry Fournier | 09a9178 | 2016-02-24 08:25:39 +0100 | [diff] [blame] | 1603 | warning = server_parse_addr_change_request(sv, args[4], "stats command"); |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1604 | if (warning) { |
| 1605 | appctx->ctx.cli.msg = warning; |
| 1606 | appctx->st0 = STAT_CLI_PRINT; |
| 1607 | } |
| 1608 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1609 | else { |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1610 | 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] | 1611 | appctx->st0 = STAT_CLI_PRINT; |
| 1612 | } |
| 1613 | return 1; |
| 1614 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1615 | else if (strcmp(args[1], "timeout") == 0) { |
| 1616 | if (strcmp(args[2], "cli") == 0) { |
| 1617 | unsigned timeout; |
| 1618 | const char *res; |
| 1619 | |
| 1620 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1621 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1622 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1623 | return 1; |
| 1624 | } |
| 1625 | |
| 1626 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1627 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1628 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1629 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1630 | return 1; |
| 1631 | } |
| 1632 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1633 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1634 | return 1; |
| 1635 | } |
| 1636 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1637 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1638 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1639 | return 1; |
| 1640 | } |
| 1641 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1642 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1643 | if (strcmp(args[2], "frontend") == 0) { |
| 1644 | struct proxy *px; |
| 1645 | struct listener *l; |
| 1646 | int v; |
| 1647 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1648 | px = expect_frontend_admin(s, si, args[3]); |
| 1649 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1650 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1651 | |
| 1652 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1653 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1654 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1655 | return 1; |
| 1656 | } |
| 1657 | |
| 1658 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1659 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1660 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1661 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1662 | return 1; |
| 1663 | } |
| 1664 | |
| 1665 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1666 | * its listeners. The blocked ones will be dequeued. |
| 1667 | */ |
| 1668 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1669 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1670 | l->maxconn = v; |
| 1671 | if (l->state == LI_FULL) |
| 1672 | resume_listener(l); |
| 1673 | } |
| 1674 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1675 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1676 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1677 | |
| 1678 | return 1; |
| 1679 | } |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1680 | else if (strcmp(args[2], "server") == 0) { |
| 1681 | struct server *sv; |
| 1682 | int v; |
| 1683 | |
| 1684 | sv = expect_server_admin(s, si, args[3]); |
| 1685 | if (!sv) |
| 1686 | return 1; |
| 1687 | |
| 1688 | if (!*args[4]) { |
| 1689 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1690 | appctx->st0 = STAT_CLI_PRINT; |
| 1691 | return 1; |
| 1692 | } |
| 1693 | |
| 1694 | v = atoi(args[4]); |
| 1695 | if (v < 0) { |
| 1696 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1697 | appctx->st0 = STAT_CLI_PRINT; |
| 1698 | return 1; |
| 1699 | } |
| 1700 | |
| 1701 | if (sv->maxconn == sv->minconn) { // static maxconn |
| 1702 | sv->maxconn = sv->minconn = v; |
| 1703 | } else { // dynamic maxconn |
| 1704 | sv->maxconn = v; |
| 1705 | } |
| 1706 | |
| 1707 | if (may_dequeue_tasks(sv, sv->proxy)) |
| 1708 | process_srv_queue(sv); |
| 1709 | |
| 1710 | return 1; |
| 1711 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1712 | else if (strcmp(args[2], "global") == 0) { |
| 1713 | int v; |
| 1714 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1715 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1716 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1717 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1718 | return 1; |
| 1719 | } |
| 1720 | |
| 1721 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1722 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1723 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1724 | return 1; |
| 1725 | } |
| 1726 | |
| 1727 | v = atoi(args[3]); |
| 1728 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1729 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1730 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1731 | return 1; |
| 1732 | } |
| 1733 | |
| 1734 | /* check for unlimited values */ |
| 1735 | if (v <= 0) |
| 1736 | v = global.hardmaxconn; |
| 1737 | |
| 1738 | global.maxconn = v; |
| 1739 | |
| 1740 | /* Dequeues all of the listeners waiting for a resource */ |
| 1741 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1742 | dequeue_all_listeners(&global_listener_queue); |
| 1743 | |
| 1744 | return 1; |
| 1745 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1746 | else { |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1747 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend', 'server', and 'global'.\n"; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1748 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1749 | return 1; |
| 1750 | } |
| 1751 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1752 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1753 | if (strcmp(args[2], "connections") == 0) { |
| 1754 | if (strcmp(args[3], "global") == 0) { |
| 1755 | int v; |
| 1756 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1757 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1758 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1759 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1760 | return 1; |
| 1761 | } |
| 1762 | |
| 1763 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1764 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1765 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1766 | return 1; |
| 1767 | } |
| 1768 | |
| 1769 | v = atoi(args[4]); |
| 1770 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1771 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1772 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1773 | return 1; |
| 1774 | } |
| 1775 | |
| 1776 | global.cps_lim = v; |
| 1777 | |
| 1778 | /* Dequeues all of the listeners waiting for a resource */ |
| 1779 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1780 | dequeue_all_listeners(&global_listener_queue); |
| 1781 | |
| 1782 | return 1; |
| 1783 | } |
| 1784 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1785 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1786 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1787 | return 1; |
| 1788 | } |
| 1789 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1790 | else if (strcmp(args[2], "sessions") == 0) { |
| 1791 | if (strcmp(args[3], "global") == 0) { |
| 1792 | int v; |
| 1793 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1794 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1795 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1796 | appctx->st0 = STAT_CLI_PRINT; |
| 1797 | return 1; |
| 1798 | } |
| 1799 | |
| 1800 | if (!*args[4]) { |
| 1801 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1802 | appctx->st0 = STAT_CLI_PRINT; |
| 1803 | return 1; |
| 1804 | } |
| 1805 | |
| 1806 | v = atoi(args[4]); |
| 1807 | if (v < 0) { |
| 1808 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1809 | appctx->st0 = STAT_CLI_PRINT; |
| 1810 | return 1; |
| 1811 | } |
| 1812 | |
| 1813 | global.sps_lim = v; |
| 1814 | |
| 1815 | /* Dequeues all of the listeners waiting for a resource */ |
| 1816 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1817 | dequeue_all_listeners(&global_listener_queue); |
| 1818 | |
| 1819 | return 1; |
| 1820 | } |
| 1821 | else { |
| 1822 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1823 | appctx->st0 = STAT_CLI_PRINT; |
| 1824 | return 1; |
| 1825 | } |
| 1826 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1827 | #ifdef USE_OPENSSL |
| 1828 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1829 | if (strcmp(args[3], "global") == 0) { |
| 1830 | int v; |
| 1831 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1832 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1833 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1834 | appctx->st0 = STAT_CLI_PRINT; |
| 1835 | return 1; |
| 1836 | } |
| 1837 | |
| 1838 | if (!*args[4]) { |
| 1839 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1840 | appctx->st0 = STAT_CLI_PRINT; |
| 1841 | return 1; |
| 1842 | } |
| 1843 | |
| 1844 | v = atoi(args[4]); |
| 1845 | if (v < 0) { |
| 1846 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1847 | appctx->st0 = STAT_CLI_PRINT; |
| 1848 | return 1; |
| 1849 | } |
| 1850 | |
| 1851 | global.ssl_lim = v; |
| 1852 | |
| 1853 | /* Dequeues all of the listeners waiting for a resource */ |
| 1854 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1855 | dequeue_all_listeners(&global_listener_queue); |
| 1856 | |
| 1857 | return 1; |
| 1858 | } |
| 1859 | else { |
| 1860 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1861 | appctx->st0 = STAT_CLI_PRINT; |
| 1862 | return 1; |
| 1863 | } |
| 1864 | } |
| 1865 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1866 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1867 | if (strcmp(args[3], "global") == 0) { |
| 1868 | int v; |
| 1869 | |
Willy Tarreau | a1c2b2c | 2015-11-26 18:32:39 +0100 | [diff] [blame] | 1870 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1871 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1872 | appctx->st0 = STAT_CLI_PRINT; |
| 1873 | return 1; |
| 1874 | } |
| 1875 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1876 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1877 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1878 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1879 | return 1; |
| 1880 | } |
| 1881 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1882 | v = atoi(args[4]); |
| 1883 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1884 | } |
| 1885 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1886 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1887 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1888 | return 1; |
| 1889 | } |
| 1890 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1891 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1892 | 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] | 1893 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1894 | return 1; |
| 1895 | } |
| 1896 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1897 | else if (strcmp(args[1], "table") == 0) { |
| 1898 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1899 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1900 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1901 | char *err; |
| 1902 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1903 | /* Set flags. */ |
| 1904 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1905 | |
| 1906 | /* Expect three parameters: map name, key and new value. */ |
| 1907 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 1908 | 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] | 1909 | appctx->st0 = STAT_CLI_PRINT; |
| 1910 | return 1; |
| 1911 | } |
| 1912 | |
| 1913 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1914 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1915 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1916 | 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] | 1917 | appctx->st0 = STAT_CLI_PRINT; |
| 1918 | return 1; |
| 1919 | } |
| 1920 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1921 | /* If the entry identifier start with a '#', it is considered as |
| 1922 | * pointer id |
| 1923 | */ |
| 1924 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 1925 | struct pat_ref_elt *ref; |
| 1926 | long long int conv; |
| 1927 | char *error; |
| 1928 | |
| 1929 | /* Convert argument to integer value. */ |
| 1930 | conv = strtoll(&args[3][1], &error, 16); |
| 1931 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1932 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1933 | appctx->st0 = STAT_CLI_PRINT; |
| 1934 | return 1; |
| 1935 | } |
| 1936 | |
| 1937 | /* Convert and check integer to pointer. */ |
| 1938 | ref = (struct pat_ref_elt *)(long)conv; |
| 1939 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1940 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1941 | appctx->st0 = STAT_CLI_PRINT; |
| 1942 | return 1; |
| 1943 | } |
| 1944 | |
| 1945 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1946 | err = NULL; |
| 1947 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 1948 | if (err) |
| 1949 | memprintf(&err, "%s.\n", err); |
| 1950 | appctx->ctx.cli.err = err; |
| 1951 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1952 | return 1; |
| 1953 | } |
| 1954 | } |
| 1955 | else { |
| 1956 | /* Else, use the entry identifier as pattern |
| 1957 | * string, and update the value. |
| 1958 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 1959 | err = NULL; |
| 1960 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 1961 | if (err) |
| 1962 | memprintf(&err, "%s.\n", err); |
| 1963 | appctx->ctx.cli.err = err; |
| 1964 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 1965 | return 1; |
| 1966 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1967 | } |
| 1968 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1969 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1970 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1971 | return 1; |
| 1972 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1973 | #ifdef USE_OPENSSL |
| 1974 | else if (strcmp(args[1], "ssl") == 0) { |
| 1975 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 1976 | #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] | 1977 | char *err = NULL; |
| 1978 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 1979 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 1980 | if (!*args[3]) { |
| 1981 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 1982 | appctx->st0 = STAT_CLI_PRINT; |
| 1983 | return 1; |
| 1984 | } |
| 1985 | |
| 1986 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 1987 | if (trash.len < 0) { |
| 1988 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 1989 | appctx->st0 = STAT_CLI_PRINT; |
| 1990 | return 1; |
| 1991 | } |
| 1992 | |
| 1993 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 1994 | if (err) { |
| 1995 | memprintf(&err, "%s.\n", err); |
| 1996 | appctx->ctx.cli.err = err; |
| 1997 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 1998 | } |
| 1999 | return 1; |
| 2000 | } |
| 2001 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 2002 | appctx->st0 = STAT_CLI_PRINT; |
| 2003 | return 1; |
| 2004 | #else |
| 2005 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 2006 | appctx->st0 = STAT_CLI_PRINT; |
| 2007 | return 1; |
| 2008 | #endif |
| 2009 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2010 | else if (strcmp(args[2], "tls-key") == 0) { |
| 2011 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2012 | /* Expect two parameters: the filename and the new new TLS key in encoding */ |
| 2013 | if (!*args[3] || !*args[4]) { |
| 2014 | appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n"; |
| 2015 | appctx->st0 = STAT_CLI_PRINT; |
| 2016 | return 1; |
| 2017 | } |
| 2018 | |
| 2019 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]); |
| 2020 | if(!appctx->ctx.tlskeys.ref) { |
| 2021 | appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n"; |
| 2022 | appctx->st0 = STAT_CLI_PRINT; |
| 2023 | return 1; |
| 2024 | } |
| 2025 | |
| 2026 | trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size); |
| 2027 | if (trash.len != sizeof(struct tls_sess_key)) { |
| 2028 | appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n"; |
| 2029 | appctx->st0 = STAT_CLI_PRINT; |
| 2030 | return 1; |
| 2031 | } |
| 2032 | |
Pradeep Jindal | cc79b00 | 2015-08-20 18:25:17 +0530 | [diff] [blame] | 2033 | memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len); |
| 2034 | appctx->ctx.tlskeys.ref->tls_ticket_enc_index = (appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 1) % TLS_TICKETS_NO; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2035 | |
| 2036 | appctx->ctx.cli.msg = "TLS ticket key updated!"; |
| 2037 | appctx->st0 = STAT_CLI_PRINT; |
| 2038 | return 1; |
| 2039 | #else |
| 2040 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 2041 | "that doesn't support specifying TLS ticket keys\n"; |
| 2042 | appctx->st0 = STAT_CLI_PRINT; |
| 2043 | return 1; |
| 2044 | #endif |
| 2045 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2046 | else { |
| 2047 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 2048 | appctx->st0 = STAT_CLI_PRINT; |
| 2049 | return 1; |
| 2050 | } |
| 2051 | } |
| 2052 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 2053 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 2054 | return 0; |
| 2055 | } |
| 2056 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2057 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2058 | if (strcmp(args[1], "agent") == 0) { |
| 2059 | struct server *sv; |
| 2060 | |
| 2061 | sv = expect_server_admin(s, si, args[2]); |
| 2062 | if (!sv) |
| 2063 | return 1; |
| 2064 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2065 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 2066 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 2067 | appctx->st0 = STAT_CLI_PRINT; |
| 2068 | return 1; |
| 2069 | } |
| 2070 | |
| 2071 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2072 | return 1; |
| 2073 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2074 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2075 | struct server *sv; |
| 2076 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2077 | sv = expect_server_admin(s, si, args[2]); |
| 2078 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2079 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2080 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2081 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 2082 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 2083 | appctx->st0 = STAT_CLI_PRINT; |
| 2084 | return 1; |
| 2085 | } |
| 2086 | |
| 2087 | sv->check.state |= CHK_ST_ENABLED; |
| 2088 | return 1; |
| 2089 | } |
| 2090 | else if (strcmp(args[1], "server") == 0) { |
| 2091 | struct server *sv; |
| 2092 | |
| 2093 | sv = expect_server_admin(s, si, args[2]); |
| 2094 | if (!sv) |
| 2095 | return 1; |
| 2096 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2097 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2098 | return 1; |
| 2099 | } |
| 2100 | else if (strcmp(args[1], "frontend") == 0) { |
| 2101 | struct proxy *px; |
| 2102 | |
| 2103 | px = expect_frontend_admin(s, si, args[2]); |
| 2104 | if (!px) |
| 2105 | return 1; |
| 2106 | |
| 2107 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2108 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 2109 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2110 | return 1; |
| 2111 | } |
| 2112 | |
| 2113 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2114 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 2115 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2116 | return 1; |
| 2117 | } |
| 2118 | |
| 2119 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2120 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 2121 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2122 | return 1; |
| 2123 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2124 | return 1; |
| 2125 | } |
| 2126 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2127 | 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] | 2128 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2129 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2133 | if (strcmp(args[1], "agent") == 0) { |
| 2134 | struct server *sv; |
| 2135 | |
| 2136 | sv = expect_server_admin(s, si, args[2]); |
| 2137 | if (!sv) |
| 2138 | return 1; |
| 2139 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2140 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2141 | return 1; |
| 2142 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2143 | else if (strcmp(args[1], "health") == 0) { |
| 2144 | struct server *sv; |
| 2145 | |
| 2146 | sv = expect_server_admin(s, si, args[2]); |
| 2147 | if (!sv) |
| 2148 | return 1; |
| 2149 | |
| 2150 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2151 | return 1; |
| 2152 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2153 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2154 | struct server *sv; |
| 2155 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2156 | sv = expect_server_admin(s, si, args[2]); |
| 2157 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2158 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2159 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2160 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2161 | return 1; |
| 2162 | } |
| 2163 | else if (strcmp(args[1], "frontend") == 0) { |
| 2164 | struct proxy *px; |
| 2165 | |
| 2166 | px = expect_frontend_admin(s, si, args[2]); |
| 2167 | if (!px) |
| 2168 | return 1; |
| 2169 | |
| 2170 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2171 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 2172 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2173 | return 1; |
| 2174 | } |
| 2175 | |
| 2176 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2177 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 2178 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2179 | return 1; |
| 2180 | } |
| 2181 | |
| 2182 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2183 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 2184 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2185 | return 1; |
| 2186 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2187 | return 1; |
| 2188 | } |
| 2189 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2190 | 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] | 2191 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2192 | return 1; |
| 2193 | } |
| 2194 | } |
| 2195 | else if (strcmp(args[0], "shutdown") == 0) { |
| 2196 | if (strcmp(args[1], "frontend") == 0) { |
| 2197 | struct proxy *px; |
| 2198 | |
| 2199 | px = expect_frontend_admin(s, si, args[2]); |
| 2200 | if (!px) |
| 2201 | return 1; |
| 2202 | |
| 2203 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2204 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 2205 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2206 | return 1; |
| 2207 | } |
| 2208 | |
| 2209 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2210 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2211 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2212 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2213 | stop_proxy(px); |
| 2214 | return 1; |
| 2215 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2216 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2217 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2218 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2219 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2220 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2221 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2222 | return 1; |
| 2223 | } |
| 2224 | |
| 2225 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2226 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2227 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2228 | return 1; |
| 2229 | } |
| 2230 | |
| 2231 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2232 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2233 | /* first, look for the requested stream in the stream table */ |
| 2234 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2235 | if (sess == ptr) |
| 2236 | break; |
| 2237 | } |
| 2238 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2239 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2240 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2241 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2242 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2243 | return 1; |
| 2244 | } |
| 2245 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2246 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2247 | return 1; |
| 2248 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2249 | else if (strcmp(args[1], "sessions") == 0) { |
| 2250 | if (strcmp(args[2], "server") == 0) { |
| 2251 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2252 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2253 | |
| 2254 | sv = expect_server_admin(s, si, args[3]); |
| 2255 | if (!sv) |
| 2256 | return 1; |
| 2257 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2258 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2259 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2260 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2261 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2262 | |
| 2263 | return 1; |
| 2264 | } |
| 2265 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2266 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2267 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2268 | return 1; |
| 2269 | } |
| 2270 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2271 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2272 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2273 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2274 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2275 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2276 | } |
| 2277 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2278 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2279 | if (args[1][0] == 'm') |
| 2280 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2281 | else |
| 2282 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2283 | |
| 2284 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2285 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2286 | if (!*args[2] || !*args[3]) { |
| 2287 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2288 | appctx->st0 = STAT_CLI_PRINT; |
| 2289 | return 1; |
| 2290 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2291 | } |
| 2292 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2293 | else { |
| 2294 | if (!*args[2] || !*args[3]) { |
| 2295 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2296 | appctx->st0 = STAT_CLI_PRINT; |
| 2297 | return 1; |
| 2298 | } |
| 2299 | } |
| 2300 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2301 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2302 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2303 | if (!appctx->ctx.map.ref || |
| 2304 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2305 | 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] | 2306 | appctx->st0 = STAT_CLI_PRINT; |
| 2307 | return 1; |
| 2308 | } |
| 2309 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2310 | /* If the entry identifier start with a '#', it is considered as |
| 2311 | * pointer id |
| 2312 | */ |
| 2313 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2314 | struct pat_ref_elt *ref; |
| 2315 | long long int conv; |
| 2316 | char *error; |
| 2317 | |
| 2318 | /* Convert argument to integer value. */ |
| 2319 | conv = strtoll(&args[3][1], &error, 16); |
| 2320 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2321 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2322 | appctx->st0 = STAT_CLI_PRINT; |
| 2323 | return 1; |
| 2324 | } |
| 2325 | |
| 2326 | /* Convert and check integer to pointer. */ |
| 2327 | ref = (struct pat_ref_elt *)(long)conv; |
| 2328 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2329 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2330 | appctx->st0 = STAT_CLI_PRINT; |
| 2331 | return 1; |
| 2332 | } |
| 2333 | |
| 2334 | /* Try to delete the entry. */ |
| 2335 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2336 | /* The entry is not found, send message. */ |
| 2337 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2338 | appctx->st0 = STAT_CLI_PRINT; |
| 2339 | return 1; |
| 2340 | } |
| 2341 | } |
| 2342 | else { |
| 2343 | /* Else, use the entry identifier as pattern |
| 2344 | * string and try to delete the entry. |
| 2345 | */ |
| 2346 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2347 | /* The entry is not found, send message. */ |
| 2348 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2349 | appctx->st0 = STAT_CLI_PRINT; |
| 2350 | return 1; |
| 2351 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2352 | } |
| 2353 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2354 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2355 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2356 | return 1; |
| 2357 | } |
| 2358 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2359 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2360 | appctx->st0 = STAT_CLI_PRINT; |
| 2361 | return 1; |
| 2362 | } |
| 2363 | } |
| 2364 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2365 | if (strcmp(args[1], "map") == 0 || |
| 2366 | strcmp(args[1], "acl") == 0) { |
| 2367 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2368 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2369 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2370 | /* Set flags. */ |
| 2371 | if (args[1][0] == 'm') |
| 2372 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2373 | else |
| 2374 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2375 | |
| 2376 | /* If the keywork is "map", we expect three parameters, if it |
| 2377 | * is "acl", we expect only two parameters |
| 2378 | */ |
| 2379 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2380 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2381 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2382 | appctx->st0 = STAT_CLI_PRINT; |
| 2383 | return 1; |
| 2384 | } |
| 2385 | } |
| 2386 | else { |
| 2387 | if (!*args[2] || !*args[3]) { |
| 2388 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2389 | appctx->st0 = STAT_CLI_PRINT; |
| 2390 | return 1; |
| 2391 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2392 | } |
| 2393 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2394 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2395 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2396 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2397 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2398 | 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] | 2399 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2400 | 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] | 2401 | appctx->st0 = STAT_CLI_PRINT; |
| 2402 | return 1; |
| 2403 | } |
| 2404 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2405 | /* The command "add acl" is prohibited if the reference |
| 2406 | * use samples. |
| 2407 | */ |
| 2408 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2409 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2410 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2411 | "You must use the command 'add map' to add values.\n"; |
| 2412 | appctx->st0 = STAT_CLI_PRINT; |
| 2413 | return 1; |
| 2414 | } |
| 2415 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2416 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2417 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2418 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2419 | 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] | 2420 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2421 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2422 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2423 | if (err) |
| 2424 | memprintf(&err, "%s.\n", err); |
| 2425 | appctx->ctx.cli.err = err; |
| 2426 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2427 | return 1; |
| 2428 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2429 | |
| 2430 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2431 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2432 | return 1; |
| 2433 | } |
| 2434 | else { /* unknown "del" parameter */ |
| 2435 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2436 | appctx->st0 = STAT_CLI_PRINT; |
| 2437 | return 1; |
| 2438 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2439 | } |
| 2440 | 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] | 2441 | return 0; |
| 2442 | } |
| 2443 | return 1; |
| 2444 | } |
| 2445 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2446 | /* 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] | 2447 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2448 | * state machine handling requests and various responses. We read a request, |
| 2449 | * 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] | 2450 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2451 | * 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] | 2452 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2453 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2454 | static void cli_io_handler(struct appctx *appctx) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2455 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2456 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2457 | struct channel *req = si_oc(si); |
| 2458 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2459 | int reql; |
| 2460 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2461 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2462 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2463 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2464 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2465 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2466 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2467 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2468 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2469 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2470 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2471 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2472 | /* Let's close for real now. We just close the request |
| 2473 | * side, the conditions below will complete if needed. |
| 2474 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2475 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2476 | break; |
| 2477 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2478 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2479 | /* ensure we have some output room left in the event we |
| 2480 | * would want to return some info right after parsing. |
| 2481 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2482 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2483 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2484 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2485 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2486 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2487 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2488 | if (reql <= 0) { /* closed or EOL not found */ |
| 2489 | if (reql == 0) |
| 2490 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2491 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2492 | continue; |
| 2493 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2494 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2495 | /* seek for a possible semi-colon. If we find one, we |
| 2496 | * replace it with an LF and skip only this part. |
| 2497 | */ |
| 2498 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2499 | if (trash.str[len] == ';') { |
| 2500 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2501 | reql = len + 1; |
| 2502 | break; |
| 2503 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2504 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2505 | /* now it is time to check that we have a full line, |
| 2506 | * remove the trailing \n and possibly \r, then cut the |
| 2507 | * line. |
| 2508 | */ |
| 2509 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2510 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2511 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2512 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2513 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2514 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2515 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2516 | len--; |
| 2517 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2518 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2519 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2520 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2521 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2522 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2523 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2524 | continue; |
| 2525 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2526 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2527 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2528 | else if (strcmp(trash.str, "help") == 0 || |
| 2529 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2530 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2531 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2532 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2533 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2534 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2535 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2536 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2537 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2538 | /* if prompt is disabled, print help on empty lines, |
| 2539 | * so that the user at least knows how to enable |
| 2540 | * prompt and find help. |
| 2541 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2542 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2543 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2547 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2548 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2549 | } |
Willy Tarreau | 68c00c7 | 2015-09-25 19:21:19 +0200 | [diff] [blame] | 2550 | else { /* output functions */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2551 | switch (appctx->st0) { |
Andrew Hayworth | e32d186 | 2015-10-02 15:08:10 +0000 | [diff] [blame] | 2552 | case STAT_CLI_PROMPT: |
| 2553 | break; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2554 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2555 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2556 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2557 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2558 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2559 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2560 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2561 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2562 | free(appctx->ctx.cli.err); |
| 2563 | appctx->st0 = STAT_CLI_PROMPT; |
| 2564 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2565 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2566 | si_applet_cant_put(si); |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2567 | break; |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 2568 | case STAT_CLI_O_BACKEND: |
| 2569 | if (stats_dump_backend_to_buffer(si)) |
| 2570 | appctx->st0 = STAT_CLI_PROMPT; |
| 2571 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2572 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2573 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2574 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2575 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2576 | case STAT_CLI_O_SERVERS_STATE: |
| 2577 | if (stats_dump_servers_state_to_buffer(si)) |
| 2578 | appctx->st0 = STAT_CLI_PROMPT; |
| 2579 | break; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2580 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2581 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2582 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2583 | break; |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 2584 | case STAT_CLI_O_RESOLVERS: |
| 2585 | if (stats_dump_resolvers_to_buffer(si)) |
| 2586 | appctx->st0 = STAT_CLI_PROMPT; |
| 2587 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2588 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2589 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2590 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2591 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2592 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2593 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2594 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2595 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2596 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2597 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2598 | if (stats_table_request(si, appctx->st0)) |
| 2599 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2600 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2601 | case STAT_CLI_O_PATS: |
| 2602 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2603 | appctx->st0 = STAT_CLI_PROMPT; |
| 2604 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2605 | case STAT_CLI_O_PAT: |
| 2606 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2607 | appctx->st0 = STAT_CLI_PROMPT; |
| 2608 | break; |
| 2609 | case STAT_CLI_O_MLOOK: |
| 2610 | if (stats_map_lookup(si)) |
| 2611 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2612 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2613 | case STAT_CLI_O_POOLS: |
| 2614 | if (stats_dump_pools_to_buffer(si)) |
| 2615 | appctx->st0 = STAT_CLI_PROMPT; |
| 2616 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2617 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2618 | case STAT_CLI_O_TLSK: |
| 2619 | if (stats_tlskeys_list(si)) |
| 2620 | appctx->st0 = STAT_CLI_PROMPT; |
| 2621 | break; |
| 2622 | #endif |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 2623 | case STAT_CLI_O_ENV: /* environment dump */ |
| 2624 | if (stats_dump_env_to_buffer(si)) |
| 2625 | appctx->st0 = STAT_CLI_PROMPT; |
| 2626 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2627 | default: /* abnormal state */ |
Willy Tarreau | 5cfa3bc | 2015-09-25 20:08:51 +0200 | [diff] [blame] | 2628 | si->flags |= SI_FL_ERR; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2629 | break; |
| 2630 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2631 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2632 | /* 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] | 2633 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2634 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2635 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2636 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2637 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2638 | } |
| 2639 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2640 | /* 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] | 2641 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2642 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2643 | |
| 2644 | /* Now we close the output if one of the writers did so, |
| 2645 | * or if we're not in interactive mode and the request |
| 2646 | * buffer is empty. This still allows pipelined requests |
| 2647 | * to be sent in non-interactive mode. |
| 2648 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2649 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2650 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2651 | continue; |
| 2652 | } |
| 2653 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2654 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2655 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2656 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2657 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2658 | |
Willy Tarreau | c9e930a | 2015-09-25 20:06:08 +0200 | [diff] [blame] | 2659 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2660 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2661 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2662 | /* 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] | 2663 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2664 | * we forward the close to the request side so that it flows upstream to |
| 2665 | * the client. |
| 2666 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2667 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2668 | } |
| 2669 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2670 | 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] | 2671 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2672 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2673 | /* We have no more processing to do, and nothing more to send, and |
| 2674 | * the client side has closed. So we'll forward this state downstream |
| 2675 | * on the response buffer. |
| 2676 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2677 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2678 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2679 | } |
| 2680 | |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 2681 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2682 | 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] | 2683 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2684 | 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] | 2685 | } |
| 2686 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2687 | /* This function dumps information onto the stream interface's read buffer. |
| 2688 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2689 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2690 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2691 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2692 | { |
| 2693 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2694 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2695 | #ifdef USE_OPENSSL |
| 2696 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2697 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2698 | int ssl_reuse = 0; |
| 2699 | |
| 2700 | if (ssl_key_rate < ssl_sess_rate) { |
| 2701 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2702 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2703 | } |
| 2704 | #endif |
| 2705 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2706 | chunk_printf(&trash, |
| 2707 | "Name: " PRODUCT_NAME "\n" |
| 2708 | "Version: " HAPROXY_VERSION "\n" |
| 2709 | "Release_date: " HAPROXY_DATE "\n" |
| 2710 | "Nbproc: %d\n" |
| 2711 | "Process_num: %d\n" |
| 2712 | "Pid: %d\n" |
| 2713 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2714 | "Uptime_sec: %d\n" |
| 2715 | "Memmax_MB: %d\n" |
Willy Tarreau | 58102cf | 2015-10-28 16:24:21 +0100 | [diff] [blame] | 2716 | "PoolAlloc_MB: %d\n" |
| 2717 | "PoolUsed_MB: %d\n" |
| 2718 | "PoolFailed: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2719 | "Ulimit-n: %d\n" |
| 2720 | "Maxsock: %d\n" |
| 2721 | "Maxconn: %d\n" |
| 2722 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2723 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2724 | "CumConns: %d\n" |
Warren Turkal | b197d7f | 2015-01-27 15:04:16 -0800 | [diff] [blame] | 2725 | "CumReq: %u\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2726 | #ifdef USE_OPENSSL |
| 2727 | "MaxSslConns: %d\n" |
| 2728 | "CurrSslConns: %d\n" |
| 2729 | "CumSslConns: %d\n" |
| 2730 | #endif |
| 2731 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2732 | "PipesUsed: %d\n" |
| 2733 | "PipesFree: %d\n" |
| 2734 | "ConnRate: %d\n" |
| 2735 | "ConnRateLimit: %d\n" |
| 2736 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2737 | "SessRate: %d\n" |
| 2738 | "SessRateLimit: %d\n" |
| 2739 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2740 | #ifdef USE_OPENSSL |
| 2741 | "SslRate: %d\n" |
| 2742 | "SslRateLimit: %d\n" |
| 2743 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2744 | "SslFrontendKeyRate: %d\n" |
| 2745 | "SslFrontendMaxKeyRate: %d\n" |
| 2746 | "SslFrontendSessionReuse_pct: %d\n" |
| 2747 | "SslBackendKeyRate: %d\n" |
| 2748 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2749 | "SslCacheLookups: %u\n" |
| 2750 | "SslCacheMisses: %u\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2751 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2752 | "CompressBpsIn: %u\n" |
| 2753 | "CompressBpsOut: %u\n" |
| 2754 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2755 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2756 | "ZlibMemUsage: %ld\n" |
| 2757 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2758 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2759 | "Tasks: %d\n" |
| 2760 | "Run_queue: %d\n" |
| 2761 | "Idle_pct: %d\n" |
| 2762 | "node: %s\n" |
| 2763 | "description: %s\n" |
| 2764 | "", |
| 2765 | global.nbproc, |
| 2766 | relative_pid, |
| 2767 | pid, |
| 2768 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2769 | up, |
| 2770 | global.rlimit_memmax, |
Willy Tarreau | 58102cf | 2015-10-28 16:24:21 +0100 | [diff] [blame] | 2771 | (int)(pool_total_allocated() / 1048576L), |
| 2772 | (int)(pool_total_used() / 1048576L), |
| 2773 | pool_total_failures(), |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2774 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2775 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2776 | actconn, totalconn, global.req_count, |
| 2777 | #ifdef USE_OPENSSL |
| 2778 | global.maxsslconn, sslconns, totalsslconns, |
| 2779 | #endif |
| 2780 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2781 | 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] | 2782 | 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] | 2783 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2784 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2785 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2786 | ssl_reuse, |
| 2787 | 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] | 2788 | global.shctx_lookups, global.shctx_misses, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2789 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2790 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2791 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2792 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2793 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2794 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2795 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2796 | global.node, global.desc ? global.desc : "" |
| 2797 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2798 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2799 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2800 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2801 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2802 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2803 | |
| 2804 | return 1; |
| 2805 | } |
| 2806 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2807 | /* dumps server state information into <buf> for all the servers found in <backend> |
| 2808 | * These information are all the parameters which may change during HAProxy runtime. |
| 2809 | * By default, we only export to the last known server state file format. |
| 2810 | * These information can be used at next startup to recover same level of server state. |
| 2811 | */ |
| 2812 | static void dump_servers_state(struct proxy *backend, struct chunk *buf) |
| 2813 | { |
| 2814 | struct server *srv; |
| 2815 | char srv_addr[INET6_ADDRSTRLEN + 1]; |
| 2816 | time_t srv_time_since_last_change; |
| 2817 | int bk_f_forced_id, srv_f_forced_id; |
| 2818 | |
| 2819 | /* we don't want to report any state if the backend is not enabled on this process */ |
| 2820 | if (backend->bind_proc && !(backend->bind_proc & (1UL << (relative_pid - 1)))) |
| 2821 | return; |
| 2822 | |
| 2823 | srv = backend->srv; |
| 2824 | |
| 2825 | while (srv) { |
| 2826 | srv_addr[0] = '\0'; |
| 2827 | srv_time_since_last_change = 0; |
| 2828 | bk_f_forced_id = 0; |
| 2829 | srv_f_forced_id = 0; |
| 2830 | |
| 2831 | switch (srv->addr.ss_family) { |
| 2832 | case AF_INET: |
| 2833 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr, |
| 2834 | srv_addr, INET_ADDRSTRLEN + 1); |
| 2835 | break; |
| 2836 | case AF_INET6: |
| 2837 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr, |
| 2838 | srv_addr, INET6_ADDRSTRLEN + 1); |
| 2839 | break; |
| 2840 | } |
| 2841 | srv_time_since_last_change = now.tv_sec - srv->last_change; |
| 2842 | bk_f_forced_id = backend->options & PR_O_FORCED_ID ? 1 : 0; |
| 2843 | srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0; |
| 2844 | |
| 2845 | chunk_appendf(buf, |
| 2846 | "%d %s " |
| 2847 | "%d %s %s " |
| 2848 | "%d %d %d %d %ld " |
| 2849 | "%d %d %d %d %d " |
| 2850 | "%d %d" |
| 2851 | "\n", |
| 2852 | backend->uuid, backend->id, |
| 2853 | srv->puid, srv->id, srv_addr, |
David Carlier | 081b336 | 2015-11-18 06:10:22 +0000 | [diff] [blame] | 2854 | srv->state, srv->admin, srv->uweight, srv->iweight, (long int)srv_time_since_last_change, |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2855 | srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state, |
| 2856 | bk_f_forced_id, srv_f_forced_id); |
| 2857 | |
| 2858 | srv = srv->next; |
| 2859 | } |
| 2860 | } |
| 2861 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 2862 | /* Parses backend list and simply report backend names */ |
| 2863 | static int stats_dump_backend_to_buffer(struct stream_interface *si) |
| 2864 | { |
| 2865 | extern struct proxy *proxy; |
| 2866 | struct proxy *curproxy; |
| 2867 | |
| 2868 | chunk_reset(&trash); |
| 2869 | chunk_printf(&trash, "# name\n"); |
| 2870 | |
| 2871 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 2872 | /* looking for backends only */ |
| 2873 | if (!(curproxy->cap & PR_CAP_BE)) |
| 2874 | continue; |
| 2875 | |
| 2876 | /* we don't want to list a backend which is bound to this process */ |
| 2877 | if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1)))) |
| 2878 | continue; |
| 2879 | |
| 2880 | chunk_appendf(&trash, "%s\n", curproxy->id); |
| 2881 | } |
| 2882 | |
| 2883 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 2884 | si_applet_cant_put(si); |
| 2885 | return 0; |
| 2886 | } |
| 2887 | |
| 2888 | return 1; |
| 2889 | } |
| 2890 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2891 | /* Parses backend list or simply use backend name provided by the user to return |
| 2892 | * states of servers to stdout. |
| 2893 | */ |
| 2894 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si) |
| 2895 | { |
| 2896 | struct appctx *appctx = __objt_appctx(si->end); |
| 2897 | extern struct proxy *proxy; |
| 2898 | struct proxy *curproxy; |
| 2899 | |
| 2900 | chunk_reset(&trash); |
| 2901 | |
| 2902 | chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); |
| 2903 | |
| 2904 | if (appctx->ctx.server_state.backend) { |
| 2905 | dump_servers_state(appctx->ctx.server_state.backend, &trash); |
| 2906 | } |
| 2907 | else { |
| 2908 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 2909 | /* servers are only in backends */ |
| 2910 | if (!(curproxy->cap & PR_CAP_BE)) |
| 2911 | continue; |
| 2912 | |
| 2913 | dump_servers_state(curproxy, &trash); |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 2918 | si_applet_cant_put(si); |
| 2919 | return 0; |
| 2920 | } |
| 2921 | |
| 2922 | return 1; |
| 2923 | } |
| 2924 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2925 | /* This function dumps memory usage information onto the stream interface's |
| 2926 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 2927 | * completion. No state is used. |
| 2928 | */ |
| 2929 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 2930 | { |
| 2931 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2932 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2933 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2934 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2935 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2936 | return 1; |
| 2937 | } |
| 2938 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2939 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2940 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2941 | * 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] | 2942 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2943 | 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] | 2944 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2945 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2946 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2947 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2948 | if (!(px->cap & PR_CAP_FE)) |
| 2949 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2950 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2951 | 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] | 2952 | return 0; |
| 2953 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2954 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2955 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2956 | /* name, queue */ |
| 2957 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2958 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2959 | 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] | 2960 | /* Column sub-heading for Enable or Disable server */ |
| 2961 | chunk_appendf(&trash, "<td></td>"); |
| 2962 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2963 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2964 | chunk_appendf(&trash, |
| 2965 | "<td class=ac>" |
| 2966 | "<a name=\"%s/Frontend\"></a>" |
| 2967 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2968 | "<td colspan=3></td>" |
| 2969 | "", |
| 2970 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2971 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2972 | chunk_appendf(&trash, |
| 2973 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2974 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2975 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2976 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2977 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2978 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2979 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2980 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2981 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2982 | if (px->mode == PR_MODE_HTTP) |
| 2983 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2984 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2985 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2986 | |
| 2987 | chunk_appendf(&trash, |
| 2988 | "</table></div></u></td>" |
| 2989 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2990 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2991 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2992 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2993 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2994 | U2H(px->fe_counters.sps_max), |
| 2995 | U2H(px->fe_counters.cps_max), |
| 2996 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2997 | |
| 2998 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2999 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3000 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3001 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3002 | |
| 3003 | chunk_appendf(&trash, |
| 3004 | "</table></div></u></td>" |
| 3005 | /* sessions rate : limit */ |
| 3006 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3007 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3008 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3009 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3010 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3011 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3012 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3013 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 3014 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3015 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3016 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 3017 | U2H(px->fe_counters.cum_sess), |
| 3018 | U2H(px->fe_counters.cum_conn), |
| 3019 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3020 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3021 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3022 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3023 | chunk_appendf(&trash, |
| 3024 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3025 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3026 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3027 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3028 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3029 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3030 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3031 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3032 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3033 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3034 | U2H(px->fe_counters.p.http.cum_req), |
| 3035 | U2H(px->fe_counters.p.http.rsp[1]), |
| 3036 | U2H(px->fe_counters.p.http.rsp[2]), |
| 3037 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3038 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3039 | (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] | 3040 | U2H(px->fe_counters.p.http.rsp[3]), |
| 3041 | U2H(px->fe_counters.p.http.rsp[4]), |
| 3042 | U2H(px->fe_counters.p.http.rsp[5]), |
| 3043 | U2H(px->fe_counters.p.http.rsp[0]), |
| 3044 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3045 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3046 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3047 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3048 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3049 | /* sessions: lbtot, lastsess */ |
| 3050 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3051 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3052 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3053 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3054 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3055 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3056 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3057 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3058 | "<td>%s%s<div class=tips><table class=det>" |
| 3059 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3060 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3061 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3062 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3063 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3064 | "</table></div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3065 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3066 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3067 | U2H(px->fe_counters.bytes_out), |
| 3068 | U2H(px->fe_counters.comp_in), |
| 3069 | U2H(px->fe_counters.comp_out), |
| 3070 | px->fe_counters.comp_in ? (int)(px->fe_counters.comp_out * 100 / px->fe_counters.comp_in) : 0, |
| 3071 | U2H(px->fe_counters.comp_byp), |
| 3072 | U2H(px->fe_counters.comp_in - px->fe_counters.comp_out), |
| 3073 | px->fe_counters.bytes_out ? (int)((px->fe_counters.comp_in - px->fe_counters.comp_out) * 100 / px->fe_counters.bytes_out) : 0, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3074 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3075 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3076 | chunk_appendf(&trash, |
| 3077 | /* denied: req, resp */ |
| 3078 | "<td>%s</td><td>%s</td>" |
| 3079 | /* errors : request, connect, response */ |
| 3080 | "<td>%s</td><td></td><td></td>" |
| 3081 | /* warnings: retries, redispatches */ |
| 3082 | "<td></td><td></td>" |
| 3083 | /* server status : reflect frontend status */ |
| 3084 | "<td class=ac>%s</td>" |
| 3085 | /* rest of server: nothing */ |
| 3086 | "<td class=ac colspan=8></td></tr>" |
| 3087 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3088 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 3089 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3090 | px->state == PR_STREADY ? "OPEN" : |
| 3091 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3092 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3093 | else { /* CSV mode */ |
| 3094 | chunk_appendf(&trash, |
| 3095 | /* pxid, name, queue cur, queue max, */ |
| 3096 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3097 | /* sessions : current, max, limit, total */ |
| 3098 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3099 | /* bytes : in, out */ |
| 3100 | "%lld,%lld," |
| 3101 | /* denied: req, resp */ |
| 3102 | "%lld,%lld," |
| 3103 | /* errors : request, connect, response */ |
| 3104 | "%lld,,," |
| 3105 | /* warnings: retries, redispatches */ |
| 3106 | ",," |
| 3107 | /* server status : reflect frontend status */ |
| 3108 | "%s," |
| 3109 | /* rest of server: nothing */ |
| 3110 | ",,,,,,,," |
| 3111 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3112 | "%d,%d,0,,,,%d," |
| 3113 | /* rate, rate_lim, rate_max */ |
| 3114 | "%u,%u,%u," |
| 3115 | /* check_status, check_code, check_duration */ |
| 3116 | ",,,", |
| 3117 | px->id, |
| 3118 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 3119 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 3120 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 3121 | px->fe_counters.failed_req, |
| 3122 | px->state == PR_STREADY ? "OPEN" : |
| 3123 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 3124 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 3125 | read_freq_ctr(&px->fe_sess_per_sec), |
| 3126 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3127 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3128 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3129 | if (px->mode == PR_MODE_HTTP) { |
| 3130 | for (i=1; i<6; i++) |
| 3131 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 3132 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 3133 | } |
| 3134 | else |
| 3135 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3136 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3137 | /* failed health analyses */ |
| 3138 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3139 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3140 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3141 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 3142 | read_freq_ctr(&px->fe_req_per_sec), |
| 3143 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 3144 | |
| 3145 | /* errors: cli_aborts, srv_aborts */ |
| 3146 | chunk_appendf(&trash, ",,"); |
| 3147 | |
| 3148 | /* compression: in, out, bypassed */ |
| 3149 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3150 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 3151 | |
| 3152 | /* compression: comp_rsp */ |
| 3153 | chunk_appendf(&trash, "%lld,", |
| 3154 | px->fe_counters.p.http.comp_rsp); |
| 3155 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3156 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 3157 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3158 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3159 | /* finish with EOL */ |
| 3160 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3161 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3162 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3163 | } |
| 3164 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3165 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 3166 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 3167 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 3168 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3169 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3170 | 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] | 3171 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3172 | struct appctx *appctx = __objt_appctx(si->end); |
| 3173 | |
| 3174 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3175 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3176 | 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] | 3177 | /* Column sub-heading for Enable or Disable server */ |
| 3178 | chunk_appendf(&trash, "<td></td>"); |
| 3179 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3180 | chunk_appendf(&trash, |
| 3181 | /* frontend name, listener name */ |
| 3182 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 3183 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 3184 | "", |
| 3185 | px->id, l->name, |
| 3186 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3187 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3188 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3189 | if (flags & ST_SHLGNDS) { |
| 3190 | char str[INET6_ADDRSTRLEN]; |
| 3191 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3192 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3193 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3194 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3195 | port = get_host_port(&l->addr); |
| 3196 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 3197 | case AF_INET: |
| 3198 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 3199 | break; |
| 3200 | case AF_INET6: |
| 3201 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 3202 | break; |
| 3203 | case AF_UNIX: |
| 3204 | chunk_appendf(&trash, "unix, "); |
| 3205 | break; |
| 3206 | case -1: |
| 3207 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3208 | break; |
| 3209 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3210 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3211 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3212 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3213 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3214 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3215 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3216 | /* queue */ |
| 3217 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3218 | /* sessions rate: current, max, limit */ |
| 3219 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3220 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3221 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3222 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3223 | /* bytes: in, out */ |
| 3224 | "<td>%s</td><td>%s</td>" |
| 3225 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3226 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3227 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 3228 | 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] | 3229 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3230 | chunk_appendf(&trash, |
| 3231 | /* denied: req, resp */ |
| 3232 | "<td>%s</td><td>%s</td>" |
| 3233 | /* errors: request, connect, response */ |
| 3234 | "<td>%s</td><td></td><td></td>" |
| 3235 | /* warnings: retries, redispatches */ |
| 3236 | "<td></td><td></td>" |
| 3237 | /* server status: reflect listener status */ |
| 3238 | "<td class=ac>%s</td>" |
| 3239 | /* rest of server: nothing */ |
| 3240 | "<td class=ac colspan=8></td></tr>" |
| 3241 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3242 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 3243 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3244 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 3245 | } |
| 3246 | else { /* CSV mode */ |
| 3247 | chunk_appendf(&trash, |
| 3248 | /* pxid, name, queue cur, queue max, */ |
| 3249 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3250 | /* sessions: current, max, limit, total */ |
| 3251 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3252 | /* bytes: in, out */ |
| 3253 | "%lld,%lld," |
| 3254 | /* denied: req, resp */ |
| 3255 | "%lld,%lld," |
| 3256 | /* errors: request, connect, response */ |
| 3257 | "%lld,,," |
| 3258 | /* warnings: retries, redispatches */ |
| 3259 | ",," |
| 3260 | /* server status: reflect listener status */ |
| 3261 | "%s," |
| 3262 | /* rest of server: nothing */ |
| 3263 | ",,,,,,,," |
| 3264 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3265 | "%d,%d,%d,,,,%d," |
| 3266 | /* rate, rate_lim, rate_max */ |
| 3267 | ",,," |
| 3268 | /* check_status, check_code, check_duration */ |
| 3269 | ",,," |
| 3270 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3271 | ",,,,,," |
| 3272 | /* failed health analyses */ |
| 3273 | "," |
| 3274 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3275 | ",,," |
| 3276 | /* errors: cli_aborts, srv_aborts */ |
| 3277 | ",," |
| 3278 | /* compression: in, out, bypassed, comp_rsp */ |
| 3279 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3280 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 3281 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3282 | "\n", |
| 3283 | px->id, l->name, |
| 3284 | l->nbconn, l->counters->conn_max, |
| 3285 | l->maxconn, l->counters->cum_conn, |
| 3286 | l->counters->bytes_in, l->counters->bytes_out, |
| 3287 | l->counters->denied_req, l->counters->denied_resp, |
| 3288 | l->counters->failed_req, |
| 3289 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 3290 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 3291 | } |
| 3292 | return 1; |
| 3293 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3294 | |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3295 | enum srv_stats_state { |
| 3296 | SRV_STATS_STATE_DOWN = 0, |
| 3297 | SRV_STATS_STATE_DOWN_AGENT, |
| 3298 | SRV_STATS_STATE_GOING_UP, |
| 3299 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 3300 | SRV_STATS_STATE_UP, |
| 3301 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 3302 | SRV_STATS_STATE_NOLB, |
| 3303 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 3304 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3305 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3306 | SRV_STATS_STATE_NO_CHECK, |
| 3307 | |
| 3308 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 3309 | }; |
| 3310 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3311 | enum srv_stats_colour { |
| 3312 | SRV_STATS_COLOUR_DOWN = 0, |
| 3313 | SRV_STATS_COLOUR_GOING_UP, |
| 3314 | SRV_STATS_COLOUR_GOING_DOWN, |
| 3315 | SRV_STATS_COLOUR_UP, |
| 3316 | SRV_STATS_COLOUR_NOLB, |
| 3317 | SRV_STATS_COLOUR_DRAINING, |
| 3318 | SRV_STATS_COLOUR_NO_CHECK, |
| 3319 | |
| 3320 | SRV_STATS_COLOUR_COUNT, /* Must be last */ |
| 3321 | }; |
| 3322 | |
| 3323 | static const char *srv_stats_colour_st[SRV_STATS_COLOUR_COUNT] = { |
| 3324 | [SRV_STATS_COLOUR_DOWN] = "down", |
| 3325 | [SRV_STATS_COLOUR_GOING_UP] = "going_up", |
| 3326 | [SRV_STATS_COLOUR_GOING_DOWN] = "going_down", |
| 3327 | [SRV_STATS_COLOUR_UP] = "up", |
| 3328 | [SRV_STATS_COLOUR_NOLB] = "nolb", |
| 3329 | [SRV_STATS_COLOUR_DRAINING] = "draining", |
| 3330 | [SRV_STATS_COLOUR_NO_CHECK] = "no_check", |
| 3331 | }; |
| 3332 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3333 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 3334 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 3335 | * 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] | 3336 | * if it emits anything, zero otherwise. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3337 | */ |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3338 | 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] | 3339 | enum srv_stats_state state, enum srv_stats_colour colour) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3340 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3341 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3342 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3343 | char str[INET6_ADDRSTRLEN]; |
| 3344 | struct chunk src; |
| 3345 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3346 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3347 | /* we have "via" which is the tracked server as described in the configuration, |
| 3348 | * and "ref" which is the checked server and the end of the chain. |
| 3349 | */ |
| 3350 | via = sv->track ? sv->track : sv; |
| 3351 | ref = via; |
| 3352 | while (ref->track) |
| 3353 | ref = ref->track; |
| 3354 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3355 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3356 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3357 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 3358 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 3359 | [SRV_STATS_STATE_GOING_UP] = "DN %d/%d ↑", |
| 3360 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d ↓", |
| 3361 | [SRV_STATS_STATE_UP] = "UP", |
| 3362 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d ↓", |
| 3363 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 3364 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d ↓", |
| 3365 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3366 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3367 | [SRV_STATS_STATE_NO_CHECK] = "<i>no check</i>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3368 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3369 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3370 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3371 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 3372 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3373 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3374 | "<tr class=\"%s_%s\">", |
| 3375 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", srv_stats_colour_st[colour]); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3376 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3377 | 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] | 3378 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3379 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3380 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3381 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3382 | chunk_appendf(&trash, |
| 3383 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3384 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3385 | "", |
| 3386 | px->id, sv->id, |
| 3387 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3388 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3389 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3390 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3391 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3392 | |
| 3393 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 3394 | case AF_INET: |
| 3395 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 3396 | break; |
| 3397 | case AF_INET6: |
| 3398 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 3399 | break; |
| 3400 | case AF_UNIX: |
| 3401 | chunk_appendf(&trash, "unix, "); |
| 3402 | break; |
| 3403 | case -1: |
| 3404 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3405 | break; |
| 3406 | default: /* address family not supported */ |
| 3407 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3408 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3409 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3410 | /* id */ |
| 3411 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3412 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3413 | /* cookie */ |
| 3414 | if (sv->cookie) { |
| 3415 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3416 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3417 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3418 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3419 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3420 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3421 | } |
| 3422 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3423 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3424 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3425 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3426 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3427 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3428 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3429 | /* sessions rate : current, max, limit */ |
| 3430 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3431 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3432 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3433 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3434 | 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] | 3435 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3436 | |
| 3437 | chunk_appendf(&trash, |
| 3438 | /* sessions: current, max, limit, total */ |
| 3439 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3440 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3441 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3442 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3443 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3444 | U2H(sv->counters.cum_sess), |
| 3445 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3446 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3447 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3448 | if (px->mode == PR_MODE_HTTP) { |
| 3449 | unsigned long long tot; |
| 3450 | for (tot = i = 0; i < 6; i++) |
| 3451 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3452 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3453 | chunk_appendf(&trash, |
| 3454 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3455 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3456 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3457 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3458 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3459 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3460 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3461 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3462 | U2H(tot), |
| 3463 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3464 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3465 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3466 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3467 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3468 | 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] | 3469 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3470 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3471 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3472 | 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))); |
| 3473 | 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))); |
| 3474 | if (px->mode == PR_MODE_HTTP) |
| 3475 | 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))); |
| 3476 | 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))); |
| 3477 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3478 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3479 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3480 | /* sessions: lbtot, last */ |
| 3481 | "<td>%s</td><td>%s</td>", |
| 3482 | U2H(sv->counters.cum_lbconn), |
| 3483 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3484 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3485 | chunk_appendf(&trash, |
| 3486 | /* bytes : in, out */ |
| 3487 | "<td>%s</td><td>%s</td>" |
| 3488 | /* denied: req, resp */ |
| 3489 | "<td></td><td>%s</td>" |
| 3490 | /* errors : request, connect */ |
| 3491 | "<td></td><td>%s</td>" |
| 3492 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3493 | "<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] | 3494 | /* warnings: retries, redispatches */ |
| 3495 | "<td>%lld</td><td>%lld</td>" |
| 3496 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3497 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3498 | U2H(sv->counters.failed_secu), |
| 3499 | U2H(sv->counters.failed_conns), |
| 3500 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3501 | sv->counters.cli_aborts, |
| 3502 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3503 | sv->counters.retries, sv->counters.redispatches); |
| 3504 | |
| 3505 | /* status, lest check */ |
| 3506 | chunk_appendf(&trash, "<td class=ac>"); |
| 3507 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3508 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3509 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3510 | chunk_appendf(&trash, "MAINT"); |
| 3511 | } |
Simon Horman | 0766e44 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3512 | 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] | 3513 | 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] | 3514 | /* DOWN (agent) */ |
| 3515 | 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] | 3516 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3517 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3518 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3519 | chunk_appendf(&trash, |
| 3520 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3521 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3522 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3523 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3524 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3525 | if ((sv->state == SRV_ST_STOPPED) && |
| 3526 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3527 | chunk_appendf(&trash, |
| 3528 | "</td><td class=ac><u> %s%s", |
| 3529 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3530 | get_check_status_info(sv->agent.status)); |
| 3531 | |
| 3532 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3533 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3534 | |
| 3535 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3536 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3537 | |
| 3538 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3539 | get_check_status_description(sv->agent.status)); |
| 3540 | if (*sv->agent.desc) { |
| 3541 | chunk_appendf(&trash, ": "); |
| 3542 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3543 | chunk_htmlencode(&trash, &src); |
| 3544 | } |
| 3545 | chunk_appendf(&trash, "</div></u>"); |
| 3546 | } |
| 3547 | 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] | 3548 | chunk_appendf(&trash, |
| 3549 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3550 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3551 | get_check_status_info(sv->check.status)); |
| 3552 | |
| 3553 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3554 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3555 | |
| 3556 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3557 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3558 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3559 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3560 | get_check_status_description(sv->check.status)); |
| 3561 | if (*sv->check.desc) { |
| 3562 | chunk_appendf(&trash, ": "); |
| 3563 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3564 | chunk_htmlencode(&trash, &src); |
| 3565 | } |
| 3566 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3567 | } |
| 3568 | else |
| 3569 | chunk_appendf(&trash, "</td><td>"); |
| 3570 | |
| 3571 | chunk_appendf(&trash, |
| 3572 | /* weight */ |
| 3573 | "</td><td class=ac>%d</td>" |
| 3574 | /* act, bck */ |
| 3575 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3576 | "", |
| 3577 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3578 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3579 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3580 | |
| 3581 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3582 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3583 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3584 | |
| 3585 | if (ref->observe) |
| 3586 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3587 | |
| 3588 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3589 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3590 | "<td>%lld</td><td>%s</td>" |
| 3591 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3592 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3593 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3594 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3595 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3596 | /* tracking a server */ |
| 3597 | chunk_appendf(&trash, |
| 3598 | "<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] | 3599 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3600 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3601 | else |
| 3602 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3603 | |
| 3604 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3605 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3606 | 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] | 3607 | else |
| 3608 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3609 | } |
| 3610 | else { /* CSV mode */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3611 | struct chunk *out = get_trash_chunk(); |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3612 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3613 | [SRV_STATS_STATE_DOWN] = "DOWN,", |
| 3614 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent),", |
| 3615 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d,", |
| 3616 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d,", |
| 3617 | [SRV_STATS_STATE_UP] = "UP,", |
| 3618 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d,", |
| 3619 | [SRV_STATS_STATE_NOLB] = "NOLB,", |
| 3620 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d,", |
| 3621 | [SRV_STATS_STATE_DRAIN] = "DRAIN,", |
Raghu Udiyar | 0d6b7a4 | 2016-02-05 22:30:11 +0530 | [diff] [blame] | 3622 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent),", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3623 | [SRV_STATS_STATE_NO_CHECK] = "no check," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3624 | }; |
| 3625 | |
| 3626 | chunk_appendf(&trash, |
| 3627 | /* pxid, name */ |
| 3628 | "%s,%s," |
| 3629 | /* queue : current, max */ |
| 3630 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3631 | /* sessions : current, max, limit, total */ |
| 3632 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3633 | /* bytes : in, out */ |
| 3634 | "%lld,%lld," |
| 3635 | /* denied: req, resp */ |
| 3636 | ",%lld," |
| 3637 | /* errors : request, connect, response */ |
| 3638 | ",%lld,%lld," |
| 3639 | /* warnings: retries, redispatches */ |
| 3640 | "%lld,%lld," |
| 3641 | "", |
| 3642 | px->id, sv->id, |
| 3643 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3644 | 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] | 3645 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3646 | sv->counters.failed_secu, |
| 3647 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3648 | sv->counters.retries, sv->counters.redispatches); |
| 3649 | |
| 3650 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3651 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3652 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3653 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3654 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3655 | else |
| 3656 | chunk_appendf(&trash, |
| 3657 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3658 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3659 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3660 | |
| 3661 | chunk_appendf(&trash, |
| 3662 | /* weight, active, backup */ |
| 3663 | "%d,%d,%d," |
| 3664 | "", |
| 3665 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3666 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3667 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3668 | |
| 3669 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3670 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3671 | chunk_appendf(&trash, |
| 3672 | "%lld,%lld,%d,%d,", |
| 3673 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3674 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3675 | else |
| 3676 | chunk_appendf(&trash, ",,,,"); |
| 3677 | |
| 3678 | /* queue limit, pid, iid, sid, */ |
| 3679 | chunk_appendf(&trash, |
| 3680 | "%s," |
| 3681 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3682 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3683 | relative_pid, px->uuid, sv->puid); |
| 3684 | |
| 3685 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3686 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3687 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3688 | |
| 3689 | /* sessions: lbtot */ |
| 3690 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3691 | |
| 3692 | /* tracked */ |
| 3693 | if (sv->track) |
| 3694 | chunk_appendf(&trash, "%s/%s,", |
| 3695 | sv->track->proxy->id, sv->track->id); |
| 3696 | else |
| 3697 | chunk_appendf(&trash, ","); |
| 3698 | |
| 3699 | /* type */ |
| 3700 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3701 | |
| 3702 | /* rate */ |
| 3703 | chunk_appendf(&trash, "%u,,%u,", |
| 3704 | read_freq_ctr(&sv->sess_per_sec), |
| 3705 | sv->counters.sps_max); |
| 3706 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3707 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3708 | /* check_status */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3709 | 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] | 3710 | |
| 3711 | /* check_code */ |
| 3712 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3713 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3714 | else |
| 3715 | chunk_appendf(&trash, ","); |
| 3716 | |
| 3717 | /* check_duration */ |
| 3718 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3719 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3720 | else |
| 3721 | chunk_appendf(&trash, ","); |
| 3722 | |
| 3723 | } |
| 3724 | else |
| 3725 | chunk_appendf(&trash, ",,,"); |
| 3726 | |
| 3727 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3728 | if (px->mode == PR_MODE_HTTP) { |
| 3729 | for (i=1; i<6; i++) |
| 3730 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3731 | |
| 3732 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3733 | } |
| 3734 | else |
| 3735 | chunk_appendf(&trash, ",,,,,,"); |
| 3736 | |
| 3737 | /* failed health analyses */ |
| 3738 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3739 | |
| 3740 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3741 | chunk_appendf(&trash, ",,,"); |
| 3742 | |
| 3743 | /* errors: cli_aborts, srv_aborts */ |
| 3744 | chunk_appendf(&trash, "%lld,%lld,", |
| 3745 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3746 | |
| 3747 | /* compression: in, out, bypassed, comp_rsp */ |
| 3748 | chunk_appendf(&trash, ",,,,"); |
| 3749 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3750 | /* lastsess */ |
| 3751 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3752 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3753 | /* capture of last check and agent statuses */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3754 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->check.desc), 1, out) : ""); |
| 3755 | 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] | 3756 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3757 | /* qtime, ctime, rtime, ttime, */ |
| 3758 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3759 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3760 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3761 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3762 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3763 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3764 | /* finish with EOL */ |
| 3765 | chunk_appendf(&trash, "\n"); |
| 3766 | } |
| 3767 | return 1; |
| 3768 | } |
| 3769 | |
| 3770 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3771 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3772 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3773 | */ |
| 3774 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3775 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3776 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3777 | struct chunk src; |
| 3778 | int i; |
| 3779 | |
| 3780 | if (!(px->cap & PR_CAP_BE)) |
| 3781 | return 0; |
| 3782 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3783 | 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] | 3784 | return 0; |
| 3785 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3786 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3787 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3788 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3789 | /* Column sub-heading for Enable or Disable server */ |
| 3790 | chunk_appendf(&trash, "<td></td>"); |
| 3791 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3792 | chunk_appendf(&trash, |
| 3793 | "<td class=ac>" |
| 3794 | /* name */ |
| 3795 | "%s<a name=\"%s/Backend\"></a>" |
| 3796 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3797 | "", |
| 3798 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3799 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3800 | |
| 3801 | if (flags & ST_SHLGNDS) { |
| 3802 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3803 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3804 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 3805 | |
| 3806 | /* cookie */ |
| 3807 | if (px->cookie_name) { |
| 3808 | chunk_appendf(&trash, ", cookie: '"); |
| 3809 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 3810 | chunk_htmlencode(&trash, &src); |
| 3811 | chunk_appendf(&trash, "'"); |
| 3812 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3813 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3817 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3818 | /* queue : current, max */ |
| 3819 | "<td>%s</td><td>%s</td><td></td>" |
| 3820 | /* sessions rate : current, max, limit */ |
| 3821 | "<td>%s</td><td>%s</td><td></td>" |
| 3822 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3823 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3824 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 3825 | 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] | 3826 | |
| 3827 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3828 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3829 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3830 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3831 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3832 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3833 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3834 | U2H(px->be_counters.cum_conn), |
| 3835 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3836 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3837 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3838 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3839 | chunk_appendf(&trash, |
| 3840 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3841 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3842 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3843 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3844 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3845 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3846 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3847 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3848 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3849 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3850 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3851 | U2H(px->be_counters.p.http.cum_req), |
| 3852 | U2H(px->be_counters.p.http.rsp[1]), |
| 3853 | U2H(px->be_counters.p.http.rsp[2]), |
| 3854 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3855 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3856 | (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] | 3857 | U2H(px->be_counters.p.http.rsp[3]), |
| 3858 | U2H(px->be_counters.p.http.rsp[4]), |
| 3859 | U2H(px->be_counters.p.http.rsp[5]), |
| 3860 | U2H(px->be_counters.p.http.rsp[0]), |
| 3861 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3862 | } |
| 3863 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3864 | 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))); |
| 3865 | 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))); |
| 3866 | if (px->mode == PR_MODE_HTTP) |
| 3867 | 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))); |
| 3868 | 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))); |
| 3869 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3870 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3871 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3872 | /* sessions: lbtot, last */ |
| 3873 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3874 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3875 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3876 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3877 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3878 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3879 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3880 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3881 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3882 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3883 | "<td>%s%s<div class=tips><table class=det>" |
| 3884 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3885 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3886 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3887 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3888 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3889 | "</table></div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3890 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3891 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3892 | U2H(px->be_counters.bytes_out), |
| 3893 | U2H(px->be_counters.comp_in), |
| 3894 | U2H(px->be_counters.comp_out), |
| 3895 | px->be_counters.comp_in ? (int)(px->be_counters.comp_out * 100 / px->be_counters.comp_in) : 0, |
| 3896 | U2H(px->be_counters.comp_byp), |
| 3897 | U2H(px->be_counters.comp_in - px->be_counters.comp_out), |
| 3898 | px->be_counters.bytes_out ? (int)((px->be_counters.comp_in - px->be_counters.comp_out) * 100 / px->be_counters.bytes_out) : 0, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3899 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3900 | |
| 3901 | chunk_appendf(&trash, |
| 3902 | /* denied: req, resp */ |
| 3903 | "<td>%s</td><td>%s</td>" |
| 3904 | /* errors : request, connect */ |
| 3905 | "<td></td><td>%s</td>" |
| 3906 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3907 | "<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] | 3908 | /* warnings: retries, redispatches */ |
| 3909 | "<td>%lld</td><td>%lld</td>" |
| 3910 | /* backend status: reflect backend status (up/down): we display UP |
| 3911 | * if the backend has known working servers or if it has no server at |
| 3912 | * all (eg: for stats). Then we display the total weight, number of |
| 3913 | * active and backups. */ |
| 3914 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3915 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3916 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3917 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3918 | U2H(px->be_counters.failed_conns), |
| 3919 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3920 | px->be_counters.cli_aborts, |
| 3921 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3922 | px->be_counters.retries, px->be_counters.redispatches, |
| 3923 | human_time(now.tv_sec - px->last_change, 1), |
| 3924 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3925 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3926 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3927 | px->srv_act, px->srv_bck); |
| 3928 | |
| 3929 | chunk_appendf(&trash, |
| 3930 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3931 | "<td class=ac> </td><td>%d</td>" |
| 3932 | "<td>%s</td>" |
| 3933 | "<td></td>" |
| 3934 | "</tr>", |
| 3935 | px->down_trans, |
| 3936 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3937 | } |
| 3938 | else { /* CSV mode */ |
| 3939 | chunk_appendf(&trash, |
| 3940 | /* pxid, name */ |
| 3941 | "%s,BACKEND," |
| 3942 | /* queue : current, max */ |
| 3943 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3944 | /* sessions : current, max, limit, total */ |
| 3945 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3946 | /* bytes : in, out */ |
| 3947 | "%lld,%lld," |
| 3948 | /* denied: req, resp */ |
| 3949 | "%lld,%lld," |
| 3950 | /* errors : request, connect, response */ |
| 3951 | ",%lld,%lld," |
| 3952 | /* warnings: retries, redispatches */ |
| 3953 | "%lld,%lld," |
| 3954 | /* backend status: reflect backend status (up/down): we display UP |
| 3955 | * if the backend has known working servers or if it has no server at |
| 3956 | * all (eg: for stats). Then we display the total weight, number of |
| 3957 | * active and backups. */ |
| 3958 | "%s," |
| 3959 | "%d,%d,%d," |
| 3960 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3961 | ",%d,%d,%d,," |
| 3962 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3963 | "%d,%d,0,,%lld,,%d," |
| 3964 | /* rate, rate_lim, rate_max, */ |
| 3965 | "%u,,%u," |
| 3966 | /* check_status, check_code, check_duration */ |
| 3967 | ",,,", |
| 3968 | px->id, |
| 3969 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3970 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3971 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3972 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3973 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3974 | px->be_counters.retries, px->be_counters.redispatches, |
| 3975 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3976 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3977 | px->srv_act, px->srv_bck, |
| 3978 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3979 | px->srv?be_downtime(px):0, |
| 3980 | relative_pid, px->uuid, |
| 3981 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3982 | read_freq_ctr(&px->be_sess_per_sec), |
| 3983 | px->be_counters.sps_max); |
| 3984 | |
| 3985 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3986 | if (px->mode == PR_MODE_HTTP) { |
| 3987 | for (i=1; i<6; i++) |
| 3988 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3989 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3990 | } |
| 3991 | else |
| 3992 | chunk_appendf(&trash, ",,,,,,"); |
| 3993 | |
| 3994 | /* failed health analyses */ |
| 3995 | chunk_appendf(&trash, ","); |
| 3996 | |
| 3997 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3998 | chunk_appendf(&trash, ",,,"); |
| 3999 | |
| 4000 | /* errors: cli_aborts, srv_aborts */ |
| 4001 | chunk_appendf(&trash, "%lld,%lld,", |
| 4002 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 4003 | |
| 4004 | /* compression: in, out, bypassed */ |
| 4005 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 4006 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 4007 | |
| 4008 | /* compression: comp_rsp */ |
| 4009 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 4010 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 4011 | /* lastsess, last_chk, last_agt, */ |
| 4012 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 4013 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4014 | /* qtime, ctime, rtime, ttime, */ |
| 4015 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 4016 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 4017 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 4018 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 4019 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 4020 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4021 | /* finish with EOL */ |
| 4022 | chunk_appendf(&trash, "\n"); |
| 4023 | } |
| 4024 | return 1; |
| 4025 | } |
| 4026 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4027 | /* 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] | 4028 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4029 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4030 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4031 | 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] | 4032 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4033 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4034 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4035 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4036 | 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] | 4037 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4038 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4039 | /* 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] | 4040 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4041 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4042 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4043 | 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] | 4044 | 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] | 4045 | } |
| 4046 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4047 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4048 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | /* print a new table */ |
| 4052 | chunk_appendf(&trash, |
| 4053 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4054 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4055 | "<th class=\"pxname\" width=\"10%%\">"); |
| 4056 | |
| 4057 | chunk_appendf(&trash, |
| 4058 | "<a name=\"%s\"></a>%s" |
| 4059 | "<a class=px href=\"#%s\">%s</a>", |
| 4060 | px->id, |
| 4061 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 4062 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4063 | |
| 4064 | if (uri->flags & ST_SHLGNDS) { |
| 4065 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4066 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4067 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 4068 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4069 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4073 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4074 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 4075 | "</tr>\n" |
| 4076 | "</table>\n" |
| 4077 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4078 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4079 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 4080 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 4081 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4082 | 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] | 4083 | /* Column heading for Enable or Disable server */ |
| 4084 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4085 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4086 | |
| 4087 | chunk_appendf(&trash, |
| 4088 | "<th rowspan=2></th>" |
| 4089 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4090 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4091 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 4092 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 4093 | "<th colspan=9>Server</th>" |
| 4094 | "</tr>\n" |
| 4095 | "<tr class=\"titre\">" |
| 4096 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 4097 | "<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] | 4098 | "<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] | 4099 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 4100 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 4101 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 4102 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 4103 | "<th>Thrtle</th>\n" |
| 4104 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4105 | } |
| 4106 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4107 | /* 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] | 4108 | * 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] | 4109 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4110 | 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] | 4111 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4112 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4113 | chunk_appendf(&trash, "</table>"); |
| 4114 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4115 | 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] | 4116 | /* close the form used to enable/disable this proxy servers */ |
| 4117 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4118 | "Choose the action to perform on the checked servers : " |
| 4119 | "<select name=action>" |
| 4120 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4121 | "<option value=\"ready\">Set state to READY</option>" |
| 4122 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 4123 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4124 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 4125 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 4126 | "<option value=\"hrunn\">Health: force UP</option>" |
| 4127 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 4128 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 4129 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 4130 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 4131 | "<option value=\"arunn\">Agent: force UP</option>" |
| 4132 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4133 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 4134 | "</select>" |
| 4135 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 4136 | " <input type=\"submit\" value=\"Apply\">" |
| 4137 | "</form>", |
| 4138 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4142 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4143 | |
| 4144 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4145 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 4146 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 4147 | * buffer space, or non-zero if everything completed. This function is used |
| 4148 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 4149 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4150 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4151 | 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] | 4152 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4153 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4154 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4155 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 4156 | 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] | 4157 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4158 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4159 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4160 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4161 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4162 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4163 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4164 | if (uri && uri->scope) { |
| 4165 | /* we have a limited scope, we have to check the proxy name */ |
| 4166 | struct stat_scope *scope; |
| 4167 | int len; |
| 4168 | |
| 4169 | len = strlen(px->id); |
| 4170 | scope = uri->scope; |
| 4171 | |
| 4172 | while (scope) { |
| 4173 | /* match exact proxy name */ |
| 4174 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 4175 | break; |
| 4176 | |
| 4177 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 4178 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4179 | break; |
| 4180 | scope = scope->next; |
| 4181 | } |
| 4182 | |
| 4183 | /* proxy name not found : don't dump anything */ |
| 4184 | if (scope == NULL) |
| 4185 | return 1; |
| 4186 | } |
| 4187 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4188 | /* if the user has requested a limited output and the proxy |
| 4189 | * name does not match, skip it. |
| 4190 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4191 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4192 | 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] | 4193 | return 1; |
| 4194 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4195 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 4196 | (appctx->ctx.stats.iid != -1) && |
| 4197 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4198 | return 1; |
| 4199 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4200 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4201 | /* fall through */ |
| 4202 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4203 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4204 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4205 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4206 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4207 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4208 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4209 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4210 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4211 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4212 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4213 | /* fall through */ |
| 4214 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4215 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4216 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4217 | if (stats_dump_fe_stats(si, px)) { |
| 4218 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4219 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4220 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4221 | } |
| 4222 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4223 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4224 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 4225 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4226 | /* fall through */ |
| 4227 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4228 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4229 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4230 | 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] | 4231 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4232 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4233 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4234 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4235 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4236 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4237 | if (!l->counters) |
| 4238 | continue; |
| 4239 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4240 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4241 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4242 | break; |
| 4243 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4244 | 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] | 4245 | continue; |
| 4246 | } |
| 4247 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4248 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4249 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) { |
| 4250 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4251 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4252 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4253 | } |
| 4254 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4255 | } |
| 4256 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4257 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 4258 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4259 | /* fall through */ |
| 4260 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4261 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4262 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4263 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4264 | enum srv_stats_state sv_state; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4265 | enum srv_stats_colour sv_colour; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4266 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4267 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4268 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4269 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4270 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4271 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4272 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4273 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4274 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4275 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4276 | break; |
| 4277 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4278 | 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] | 4279 | continue; |
| 4280 | } |
| 4281 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4282 | svs = sv; |
| 4283 | while (svs->track) |
| 4284 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4285 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4286 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4287 | if ((svs->check.state & CHK_ST_ENABLED) && |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4288 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4289 | sv_state = SRV_STATS_STATE_UP_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4290 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4291 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4292 | sv_state = SRV_STATS_STATE_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4293 | sv_colour = SRV_STATS_COLOUR_UP; |
| 4294 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4295 | |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4296 | if (sv_state == SRV_STATS_STATE_UP && !svs->uweight) |
| 4297 | sv_colour = SRV_STATS_COLOUR_DRAINING; |
| 4298 | |
| 4299 | if (sv->admin & SRV_ADMF_DRAIN) { |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4300 | if (svs->agent.state & CHK_ST_ENABLED) |
| 4301 | sv_state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4302 | else if (sv_state == SRV_STATS_STATE_UP_GOING_DOWN) |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4303 | sv_state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4304 | else |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4305 | sv_state = SRV_STATS_STATE_DRAIN; |
| 4306 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4307 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4308 | 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] | 4309 | sv_state = SRV_STATS_STATE_NO_CHECK; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4310 | sv_colour = SRV_STATS_COLOUR_NO_CHECK; |
| 4311 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4312 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4313 | else if (sv->state == SRV_ST_STOPPING) { |
| 4314 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4315 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4316 | sv_state = SRV_STATS_STATE_NOLB; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4317 | sv_colour = SRV_STATS_COLOUR_NOLB; |
| 4318 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4319 | sv_state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4320 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4321 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4322 | } |
| 4323 | else { /* stopped */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4324 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4325 | sv_state = SRV_STATS_STATE_DOWN_AGENT; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4326 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4327 | } else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4328 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4329 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4330 | } 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] | 4331 | sv_state = SRV_STATS_STATE_GOING_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4332 | sv_colour = SRV_STATS_COLOUR_GOING_UP; |
| 4333 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4334 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4335 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4336 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4337 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4338 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4339 | 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] | 4340 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4341 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4342 | continue; |
| 4343 | } |
| 4344 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4345 | 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] | 4346 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4347 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4348 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4349 | } |
| 4350 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4351 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4352 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4353 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4354 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4355 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4356 | case STAT_PX_ST_BE: |
| 4357 | /* print the backend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4358 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) { |
| 4359 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4360 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4361 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4362 | } |
| 4363 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4364 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4365 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4366 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4367 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4368 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4369 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4370 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4371 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4372 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4373 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4374 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4375 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4376 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4377 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4378 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4379 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4380 | case STAT_PX_ST_FIN: |
| 4381 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4382 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4383 | default: |
| 4384 | /* unknown state, we should put an abort() here ! */ |
| 4385 | return 1; |
| 4386 | } |
| 4387 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4388 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4389 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4390 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4391 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4392 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4393 | { |
| 4394 | /* WARNING! This must fit in the first buffer !!! */ |
| 4395 | chunk_appendf(&trash, |
| 4396 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4397 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4398 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4399 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4400 | "<style type=\"text/css\"><!--\n" |
| 4401 | "body {" |
| 4402 | " font-family: arial, helvetica, sans-serif;" |
| 4403 | " font-size: 12px;" |
| 4404 | " font-weight: normal;" |
| 4405 | " color: black;" |
| 4406 | " background: white;" |
| 4407 | "}\n" |
| 4408 | "th,td {" |
| 4409 | " font-size: 10px;" |
| 4410 | "}\n" |
| 4411 | "h1 {" |
| 4412 | " font-size: x-large;" |
| 4413 | " margin-bottom: 0.5em;" |
| 4414 | "}\n" |
| 4415 | "h2 {" |
| 4416 | " font-family: helvetica, arial;" |
| 4417 | " font-size: x-large;" |
| 4418 | " font-weight: bold;" |
| 4419 | " font-style: italic;" |
| 4420 | " color: #6020a0;" |
| 4421 | " margin-top: 0em;" |
| 4422 | " margin-bottom: 0em;" |
| 4423 | "}\n" |
| 4424 | "h3 {" |
| 4425 | " font-family: helvetica, arial;" |
| 4426 | " font-size: 16px;" |
| 4427 | " font-weight: bold;" |
| 4428 | " color: #b00040;" |
| 4429 | " background: #e8e8d0;" |
| 4430 | " margin-top: 0em;" |
| 4431 | " margin-bottom: 0em;" |
| 4432 | "}\n" |
| 4433 | "li {" |
| 4434 | " margin-top: 0.25em;" |
| 4435 | " margin-right: 2em;" |
| 4436 | "}\n" |
| 4437 | ".hr {margin-top: 0.25em;" |
| 4438 | " border-color: black;" |
| 4439 | " border-bottom-style: solid;" |
| 4440 | "}\n" |
| 4441 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4442 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4443 | ".frontend {background: #e8e8d0;}\n" |
| 4444 | ".socket {background: #d0d0d0;}\n" |
| 4445 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4446 | ".active_down {background: #ff9090;}\n" |
| 4447 | ".active_going_up {background: #ffd020;}\n" |
| 4448 | ".active_going_down {background: #ffffa0;}\n" |
| 4449 | ".active_up {background: #c0ffc0;}\n" |
| 4450 | ".active_nolb {background: #20a0ff;}\n" |
| 4451 | ".active_draining {background: #20a0FF;}\n" |
| 4452 | ".active_no_check {background: #e0e0e0;}\n" |
| 4453 | ".backup_down {background: #ff9090;}\n" |
| 4454 | ".backup_going_up {background: #ff80ff;}\n" |
| 4455 | ".backup_going_down {background: #c060ff;}\n" |
| 4456 | ".backup_up {background: #b0d0ff;}\n" |
| 4457 | ".backup_nolb {background: #90b0e0;}\n" |
| 4458 | ".backup_draining {background: #cc9900;}\n" |
| 4459 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4460 | ".maintain {background: #c07820;}\n" |
| 4461 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4462 | "\n" |
| 4463 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4464 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4465 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4466 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4467 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4468 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4469 | "\n" |
| 4470 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4471 | "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" |
| 4472 | "table.tbl td.ac { text-align: center;}\n" |
| 4473 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4474 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4475 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4476 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4477 | "\n" |
| 4478 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4479 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4480 | "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] | 4481 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4482 | "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] | 4483 | "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] | 4484 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4485 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4486 | " display:block;\n" |
| 4487 | " visibility:hidden;\n" |
| 4488 | " z-index:2147483647;\n" |
| 4489 | " position:absolute;\n" |
| 4490 | " padding:2px 4px 3px;\n" |
| 4491 | " background:#f0f060; color:#000000;\n" |
| 4492 | " border:1px solid #7040c0;\n" |
| 4493 | " white-space:nowrap;\n" |
| 4494 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4495 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4496 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4497 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4498 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4499 | "-->\n" |
| 4500 | "</style></head>\n", |
| 4501 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4502 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4503 | ); |
| 4504 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4505 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4506 | /* 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] | 4507 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4508 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4509 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4510 | 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] | 4511 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4512 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4513 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4514 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4515 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4516 | /* WARNING! this has to fit the first packet too. |
| 4517 | * We are around 3.5 kB, add adding entries will |
| 4518 | * become tricky if we want to support 4kB buffers ! |
| 4519 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4520 | chunk_appendf(&trash, |
| 4521 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4522 | PRODUCT_NAME "%s</a></h1>\n" |
| 4523 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4524 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4525 | "<h3>> General process information</h3>\n" |
| 4526 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4527 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4528 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4529 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4530 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4531 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4532 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4533 | "</td><td align=\"center\" nowrap>\n" |
| 4534 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4535 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4536 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4537 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4538 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4539 | "<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] | 4540 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4541 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4542 | "<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] | 4543 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4544 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4545 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4546 | "</tr><tr>\n" |
| 4547 | "<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] | 4548 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4549 | "<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] | 4550 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4551 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4552 | "</td>" |
| 4553 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4554 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4555 | "", |
| 4556 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4557 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4558 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4559 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4560 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4561 | pid, relative_pid, global.nbproc, |
| 4562 | up / 86400, (up % 86400) / 3600, |
| 4563 | (up % 3600) / 60, (up % 60), |
| 4564 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4565 | global.rlimit_memmax ? " MB" : "", |
| 4566 | global.rlimit_nofile, |
| 4567 | global.maxsock, global.maxconn, global.maxpipes, |
| 4568 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4569 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4570 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4571 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4572 | /* 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] | 4573 | 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] | 4574 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4575 | |
| 4576 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4577 | "<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] | 4578 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4579 | STAT_SCOPE_TXT_MAXLEN); |
| 4580 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4581 | /* 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] | 4582 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4583 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4584 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4585 | 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] | 4586 | 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] | 4587 | } |
| 4588 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4589 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4590 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4591 | "<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] | 4592 | uri->uri_prefix, |
| 4593 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4594 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4595 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4596 | else |
| 4597 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4598 | "<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] | 4599 | uri->uri_prefix, |
| 4600 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4601 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4602 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4603 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4604 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4605 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4606 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4607 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4608 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4609 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4610 | "", |
| 4611 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4612 | else |
| 4613 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4614 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4615 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4616 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4617 | ";norefresh", |
| 4618 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4619 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4620 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4621 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4622 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4623 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4624 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4625 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4626 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4627 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4628 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4629 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4630 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4631 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4632 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4633 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4634 | chunk_appendf(&trash, |
| 4635 | "</ul></td>" |
| 4636 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4637 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4638 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4639 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4640 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4641 | "</ul>" |
| 4642 | "</td>" |
| 4643 | "</tr></table>\n" |
| 4644 | "" |
| 4645 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4646 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4647 | if (appctx->ctx.stats.st_code) { |
| 4648 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4649 | case STAT_STATUS_DONE: |
| 4650 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4651 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4652 | "<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] | 4653 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4654 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4655 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4656 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4657 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4658 | break; |
| 4659 | case STAT_STATUS_NONE: |
| 4660 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4661 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4662 | "<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] | 4663 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4664 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4665 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4666 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4667 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4668 | break; |
| 4669 | case STAT_STATUS_PART: |
| 4670 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4671 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4672 | "<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] | 4673 | "Action partially processed.<br>" |
| 4674 | "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] | 4675 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4676 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4677 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4678 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4679 | break; |
| 4680 | case STAT_STATUS_ERRP: |
| 4681 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4682 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4683 | "<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] | 4684 | "Action not processed because of invalid parameters." |
| 4685 | "<ul>" |
| 4686 | "<li>The action is maybe unknown.</li>" |
| 4687 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4688 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4689 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4690 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4691 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4692 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4693 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4694 | break; |
| 4695 | case STAT_STATUS_EXCD: |
| 4696 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4697 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4698 | "<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] | 4699 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4700 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4701 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4702 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4703 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4704 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4705 | break; |
| 4706 | case STAT_STATUS_DENY: |
| 4707 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4708 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4709 | "<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] | 4710 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4711 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4712 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4713 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4714 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4715 | break; |
| 4716 | default: |
| 4717 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4718 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4719 | "<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] | 4720 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4721 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4722 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4723 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4724 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4725 | } |
| 4726 | chunk_appendf(&trash, "<p>\n"); |
| 4727 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4728 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4729 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4730 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4731 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4732 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4733 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4734 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4735 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4736 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4737 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4738 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4739 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4740 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4741 | * 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] | 4742 | * 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] | 4743 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4744 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4745 | 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] | 4746 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4747 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4748 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4749 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4750 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4751 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4752 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4753 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4754 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4755 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4756 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4757 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4758 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4759 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4760 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4761 | else |
| 4762 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4763 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4764 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4765 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4766 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4767 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4768 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4769 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4770 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4771 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4772 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4773 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4774 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4775 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4776 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4777 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4778 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4779 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4780 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4781 | appctx->ctx.stats.px = proxy; |
| 4782 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4783 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4784 | /* fall through */ |
| 4785 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4786 | case STAT_ST_LIST: |
| 4787 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4788 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4789 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4790 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4791 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4792 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4793 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4794 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4795 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 4796 | 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] | 4797 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4798 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4799 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4800 | appctx->ctx.stats.px = px->next; |
| 4801 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4802 | } |
| 4803 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4804 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4805 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4806 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4807 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4808 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4809 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4810 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4811 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4812 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4813 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4814 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4815 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4816 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4817 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4818 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 4819 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4820 | case STAT_ST_FIN: |
| 4821 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4822 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4823 | default: |
| 4824 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4825 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4826 | return -1; |
| 4827 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4828 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4829 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4830 | /* We reached the stats page through a POST request. The appctx is |
| 4831 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4832 | * Parse the posted data and enable/disable servers if necessary. |
| 4833 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4834 | */ |
| 4835 | static int stats_process_http_post(struct stream_interface *si) |
| 4836 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4837 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4838 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4839 | |
| 4840 | struct proxy *px = NULL; |
| 4841 | struct server *sv = NULL; |
| 4842 | |
| 4843 | char key[LINESIZE]; |
| 4844 | int action = ST_ADM_ACTION_NONE; |
| 4845 | int reprocess = 0; |
| 4846 | |
| 4847 | int total_servers = 0; |
| 4848 | int altered_servers = 0; |
| 4849 | |
| 4850 | char *first_param, *cur_param, *next_param, *end_params; |
| 4851 | char *st_cur_param = NULL; |
| 4852 | char *st_next_param = NULL; |
| 4853 | |
| 4854 | struct chunk *temp; |
| 4855 | int reql; |
| 4856 | |
| 4857 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4858 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4859 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4860 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4861 | goto out; |
| 4862 | } |
| 4863 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 4864 | 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] | 4865 | if (reql <= 0) { |
| 4866 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4867 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4868 | return 0; |
| 4869 | } |
| 4870 | |
| 4871 | first_param = temp->str; |
| 4872 | end_params = temp->str + reql; |
| 4873 | cur_param = next_param = end_params; |
| 4874 | *end_params = '\0'; |
| 4875 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4876 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4877 | |
| 4878 | /* |
| 4879 | * Parse the parameters in reverse order to only store the last value. |
| 4880 | * From the html form, the backend and the action are at the end. |
| 4881 | */ |
| 4882 | while (cur_param > first_param) { |
| 4883 | char *value; |
| 4884 | int poffset, plen; |
| 4885 | |
| 4886 | cur_param--; |
| 4887 | |
| 4888 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4889 | reprocess_servers: |
| 4890 | /* Parse the key */ |
| 4891 | poffset = (cur_param != first_param ? 1 : 0); |
| 4892 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4893 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4894 | strncpy(key, cur_param + poffset, plen); |
| 4895 | key[plen - 1] = '\0'; |
| 4896 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4897 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4898 | goto out; |
| 4899 | } |
| 4900 | |
| 4901 | /* Parse the value */ |
| 4902 | value = key; |
| 4903 | while (*value != '\0' && *value != '=') { |
| 4904 | value++; |
| 4905 | } |
| 4906 | if (*value == '=') { |
| 4907 | /* Ok, a value is found, we can mark the end of the key */ |
| 4908 | *value++ = '\0'; |
| 4909 | } |
| 4910 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4911 | break; |
| 4912 | |
| 4913 | /* Now we can check the key to see what to do */ |
| 4914 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 4915 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4916 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4917 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4918 | goto out; |
| 4919 | } |
| 4920 | } |
| 4921 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4922 | if (strcmp(value, "ready") == 0) { |
| 4923 | action = ST_ADM_ACTION_READY; |
| 4924 | } |
| 4925 | else if (strcmp(value, "drain") == 0) { |
| 4926 | action = ST_ADM_ACTION_DRAIN; |
| 4927 | } |
| 4928 | else if (strcmp(value, "maint") == 0) { |
| 4929 | action = ST_ADM_ACTION_MAINT; |
| 4930 | } |
| 4931 | else if (strcmp(value, "shutdown") == 0) { |
| 4932 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4933 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4934 | else if (strcmp(value, "dhlth") == 0) { |
| 4935 | action = ST_ADM_ACTION_DHLTH; |
| 4936 | } |
| 4937 | else if (strcmp(value, "ehlth") == 0) { |
| 4938 | action = ST_ADM_ACTION_EHLTH; |
| 4939 | } |
| 4940 | else if (strcmp(value, "hrunn") == 0) { |
| 4941 | action = ST_ADM_ACTION_HRUNN; |
| 4942 | } |
| 4943 | else if (strcmp(value, "hnolb") == 0) { |
| 4944 | action = ST_ADM_ACTION_HNOLB; |
| 4945 | } |
| 4946 | else if (strcmp(value, "hdown") == 0) { |
| 4947 | action = ST_ADM_ACTION_HDOWN; |
| 4948 | } |
| 4949 | else if (strcmp(value, "dagent") == 0) { |
| 4950 | action = ST_ADM_ACTION_DAGENT; |
| 4951 | } |
| 4952 | else if (strcmp(value, "eagent") == 0) { |
| 4953 | action = ST_ADM_ACTION_EAGENT; |
| 4954 | } |
| 4955 | else if (strcmp(value, "arunn") == 0) { |
| 4956 | action = ST_ADM_ACTION_ARUNN; |
| 4957 | } |
| 4958 | else if (strcmp(value, "adown") == 0) { |
| 4959 | action = ST_ADM_ACTION_ADOWN; |
| 4960 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4961 | /* else these are the old supported methods */ |
| 4962 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4963 | action = ST_ADM_ACTION_DISABLE; |
| 4964 | } |
| 4965 | else if (strcmp(value, "enable") == 0) { |
| 4966 | action = ST_ADM_ACTION_ENABLE; |
| 4967 | } |
| 4968 | else if (strcmp(value, "stop") == 0) { |
| 4969 | action = ST_ADM_ACTION_STOP; |
| 4970 | } |
| 4971 | else if (strcmp(value, "start") == 0) { |
| 4972 | action = ST_ADM_ACTION_START; |
| 4973 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4974 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4975 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4976 | goto out; |
| 4977 | } |
| 4978 | } |
| 4979 | else if (strcmp(key, "s") == 0) { |
| 4980 | if (!(px && action)) { |
| 4981 | /* |
| 4982 | * Indicates that we'll need to reprocess the parameters |
| 4983 | * as soon as backend and action are known |
| 4984 | */ |
| 4985 | if (!reprocess) { |
| 4986 | st_cur_param = cur_param; |
| 4987 | st_next_param = next_param; |
| 4988 | } |
| 4989 | reprocess = 1; |
| 4990 | } |
| 4991 | else if ((sv = findserver(px, value)) != NULL) { |
| 4992 | switch (action) { |
| 4993 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4994 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4995 | altered_servers++; |
| 4996 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 4997 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4998 | } |
| 4999 | break; |
| 5000 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5001 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5002 | altered_servers++; |
| 5003 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5004 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5005 | } |
| 5006 | break; |
| 5007 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5008 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 5009 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5010 | altered_servers++; |
| 5011 | total_servers++; |
| 5012 | } |
| 5013 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5014 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5015 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 5016 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5017 | altered_servers++; |
| 5018 | total_servers++; |
| 5019 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5020 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5021 | case ST_ADM_ACTION_DHLTH: |
| 5022 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5023 | sv->check.state &= ~CHK_ST_ENABLED; |
| 5024 | altered_servers++; |
| 5025 | total_servers++; |
| 5026 | } |
| 5027 | break; |
| 5028 | case ST_ADM_ACTION_EHLTH: |
| 5029 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5030 | sv->check.state |= CHK_ST_ENABLED; |
| 5031 | altered_servers++; |
| 5032 | total_servers++; |
| 5033 | } |
| 5034 | break; |
| 5035 | case ST_ADM_ACTION_HRUNN: |
| 5036 | if (!(sv->track)) { |
| 5037 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5038 | srv_set_running(sv, "changed from Web interface"); |
| 5039 | altered_servers++; |
| 5040 | total_servers++; |
| 5041 | } |
| 5042 | break; |
| 5043 | case ST_ADM_ACTION_HNOLB: |
| 5044 | if (!(sv->track)) { |
| 5045 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5046 | srv_set_stopping(sv, "changed from Web interface"); |
| 5047 | altered_servers++; |
| 5048 | total_servers++; |
| 5049 | } |
| 5050 | break; |
| 5051 | case ST_ADM_ACTION_HDOWN: |
| 5052 | if (!(sv->track)) { |
| 5053 | sv->check.health = 0; |
| 5054 | srv_set_stopped(sv, "changed from Web interface"); |
| 5055 | altered_servers++; |
| 5056 | total_servers++; |
| 5057 | } |
| 5058 | break; |
| 5059 | case ST_ADM_ACTION_DAGENT: |
| 5060 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5061 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 5062 | altered_servers++; |
| 5063 | total_servers++; |
| 5064 | } |
| 5065 | break; |
| 5066 | case ST_ADM_ACTION_EAGENT: |
| 5067 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5068 | sv->agent.state |= CHK_ST_ENABLED; |
| 5069 | altered_servers++; |
| 5070 | total_servers++; |
| 5071 | } |
| 5072 | break; |
| 5073 | case ST_ADM_ACTION_ARUNN: |
| 5074 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5075 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 5076 | srv_set_running(sv, "changed from Web interface"); |
| 5077 | altered_servers++; |
| 5078 | total_servers++; |
| 5079 | } |
| 5080 | break; |
| 5081 | case ST_ADM_ACTION_ADOWN: |
| 5082 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5083 | sv->agent.health = 0; |
| 5084 | srv_set_stopped(sv, "changed from Web interface"); |
| 5085 | altered_servers++; |
| 5086 | total_servers++; |
| 5087 | } |
| 5088 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5089 | case ST_ADM_ACTION_READY: |
| 5090 | srv_adm_set_ready(sv); |
| 5091 | altered_servers++; |
| 5092 | total_servers++; |
| 5093 | break; |
| 5094 | case ST_ADM_ACTION_DRAIN: |
| 5095 | srv_adm_set_drain(sv); |
| 5096 | altered_servers++; |
| 5097 | total_servers++; |
| 5098 | break; |
| 5099 | case ST_ADM_ACTION_MAINT: |
| 5100 | srv_adm_set_maint(sv); |
| 5101 | altered_servers++; |
| 5102 | total_servers++; |
| 5103 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5104 | case ST_ADM_ACTION_SHUTDOWN: |
| 5105 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5106 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5107 | |
| 5108 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 5109 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 5110 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5111 | |
| 5112 | altered_servers++; |
| 5113 | total_servers++; |
| 5114 | } |
| 5115 | break; |
| 5116 | } |
| 5117 | } else { |
| 5118 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 5119 | total_servers++; |
| 5120 | } |
| 5121 | } |
| 5122 | if (reprocess && px && action) { |
| 5123 | /* Now, we know the backend and the action chosen by the user. |
| 5124 | * We can safely restart from the first server parameter |
| 5125 | * to reprocess them |
| 5126 | */ |
| 5127 | cur_param = st_cur_param; |
| 5128 | next_param = st_next_param; |
| 5129 | reprocess = 0; |
| 5130 | goto reprocess_servers; |
| 5131 | } |
| 5132 | |
| 5133 | next_param = cur_param; |
| 5134 | } |
| 5135 | } |
| 5136 | |
| 5137 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5138 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5139 | } |
| 5140 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5141 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5142 | } |
| 5143 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5144 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5145 | } |
| 5146 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5147 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5148 | } |
| 5149 | out: |
| 5150 | return 1; |
| 5151 | } |
| 5152 | |
| 5153 | |
| 5154 | static int stats_send_http_headers(struct stream_interface *si) |
| 5155 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5156 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5157 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5158 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5159 | |
| 5160 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 5161 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5162 | "Cache-Control: no-cache\r\n" |
| 5163 | "Connection: close\r\n" |
| 5164 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5165 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5166 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5167 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5168 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 5169 | uri->refresh); |
| 5170 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5171 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 5172 | |
| 5173 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 5174 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 5175 | else |
| 5176 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5177 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5178 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5179 | s->logs.tv_request = now; |
| 5180 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5181 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5182 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5183 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5184 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5185 | |
| 5186 | return 1; |
| 5187 | } |
| 5188 | |
| 5189 | static int stats_send_http_redirect(struct stream_interface *si) |
| 5190 | { |
| 5191 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5192 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5193 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5194 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5195 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5196 | /* 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] | 5197 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5198 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5199 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5200 | 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] | 5201 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | /* We don't want to land on the posted stats page because a refresh will |
| 5205 | * repost the data. We don't want this to happen on accident so we redirect |
| 5206 | * the browse to the stats page with a GET. |
| 5207 | */ |
| 5208 | chunk_printf(&trash, |
| 5209 | "HTTP/1.1 303 See Other\r\n" |
| 5210 | "Cache-Control: no-cache\r\n" |
| 5211 | "Content-Type: text/plain\r\n" |
| 5212 | "Connection: close\r\n" |
| 5213 | "Location: %s;st=%s%s%s%s\r\n" |
Willy Tarreau | fdfcc9d | 2016-01-26 13:57:29 +0100 | [diff] [blame] | 5214 | "Content-length: 0\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5215 | "\r\n", |
| 5216 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5217 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 5218 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 5219 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 5220 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5221 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5222 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5223 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5224 | scope_txt); |
| 5225 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5226 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5227 | s->logs.tv_request = now; |
| 5228 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5229 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5230 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5231 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5232 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5233 | |
| 5234 | return 1; |
| 5235 | } |
| 5236 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5237 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 5238 | * 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] | 5239 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5240 | * automatically unregisters itself once transfer is complete. |
| 5241 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5242 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5243 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5244 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5245 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5246 | struct channel *req = si_oc(si); |
| 5247 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5248 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5249 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 5250 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5251 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5252 | /* check that the output is not closed */ |
| 5253 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5254 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5255 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5256 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5257 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5258 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5259 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5260 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5261 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5262 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5263 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5264 | } |
| 5265 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5266 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5267 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5268 | unsigned int data_len; |
| 5269 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 5270 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5271 | |
| 5272 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5273 | /* One difficulty we're facing is that we must prevent |
| 5274 | * the input data from being automatically forwarded to |
| 5275 | * the output area. For this, we temporarily disable |
| 5276 | * forwarding on the channel. |
| 5277 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5278 | last_fwd = si_ic(si)->to_forward; |
| 5279 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5280 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5281 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5282 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5283 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5284 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5285 | } |
| 5286 | } |
| 5287 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5288 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5289 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5290 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5291 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5292 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5293 | |
| 5294 | /* Now we must either adjust or remove the chunk size. This is |
| 5295 | * not easy because the chunk size might wrap at the end of the |
| 5296 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5297 | * the size, then restore the buffer's contents. Note that we can |
| 5298 | * only do that because no forwarding is scheduled on the stats |
| 5299 | * applet. |
| 5300 | */ |
| 5301 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5302 | si_ic(si)->total -= (last_len - prev_len); |
| 5303 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5304 | |
| 5305 | if (last_len != data_len) { |
| 5306 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5307 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5308 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5309 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5310 | si_ic(si)->total += (last_len - data_len); |
| 5311 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5312 | } |
| 5313 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5314 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5315 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5316 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5317 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5318 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5319 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5320 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5321 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5322 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5323 | } |
| 5324 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5325 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5326 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5327 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5328 | } |
| 5329 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5330 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5331 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5332 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5333 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5334 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5335 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5336 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5337 | } |
| 5338 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5339 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5340 | res->flags |= CF_READ_NULL; |
| 5341 | si_shutr(si); |
| 5342 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5343 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5344 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5345 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5346 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5347 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5348 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5349 | si_shutr(si); |
| 5350 | res->flags |= CF_READ_NULL; |
| 5351 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5352 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5353 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5354 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5355 | } |
| 5356 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5357 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5358 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5359 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5360 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5361 | return "NONE"; |
| 5362 | return conn->ctrl->name; |
| 5363 | } |
| 5364 | |
| 5365 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5366 | { |
| 5367 | static char ptr[17]; |
| 5368 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5369 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5370 | return "NONE"; |
| 5371 | |
| 5372 | if (conn->xprt == &raw_sock) |
| 5373 | return "RAW"; |
| 5374 | |
| 5375 | #ifdef USE_OPENSSL |
| 5376 | if (conn->xprt == &ssl_sock) |
| 5377 | return "SSL"; |
| 5378 | #endif |
| 5379 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5380 | return ptr; |
| 5381 | } |
| 5382 | |
| 5383 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5384 | { |
| 5385 | static char ptr[17]; |
| 5386 | |
| 5387 | if (!conn->data) |
| 5388 | return "NONE"; |
| 5389 | |
| 5390 | if (conn->data == &sess_conn_cb) |
| 5391 | return "SESS"; |
| 5392 | |
| 5393 | if (conn->data == &si_conn_cb) |
| 5394 | return "STRM"; |
| 5395 | |
| 5396 | if (conn->data == &check_conn_cb) |
| 5397 | return "CHCK"; |
| 5398 | |
| 5399 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5400 | return ptr; |
| 5401 | } |
| 5402 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5403 | /* This function dumps a complete stream state onto the stream interface's |
| 5404 | * 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] | 5405 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5406 | * 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] | 5407 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5408 | 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] | 5409 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5410 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5411 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5412 | extern const char *monthname[12]; |
| 5413 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5414 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5415 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5416 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5417 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5418 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5419 | 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] | 5420 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5421 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5422 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5423 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5424 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5425 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5426 | appctx->ctx.sess.uid = 0; |
| 5427 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5428 | return 1; |
| 5429 | } |
| 5430 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5431 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5432 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5433 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5434 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5435 | /* fall through */ |
| 5436 | |
| 5437 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5438 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5439 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5440 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5441 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5442 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5443 | 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] | 5444 | sess->uniq_id, |
Willy Tarreau | 666f504 | 2015-06-17 19:49:52 +0200 | [diff] [blame] | 5445 | strm_li(sess) ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5446 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5447 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5448 | 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] | 5449 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5450 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5451 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5452 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5453 | break; |
| 5454 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5455 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5456 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5457 | default: |
| 5458 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5459 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5460 | break; |
| 5461 | } |
| 5462 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5463 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5464 | " 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] | 5465 | 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] | 5466 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5467 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5468 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5469 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5470 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5471 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5472 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5473 | if (conn) |
| 5474 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5475 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5476 | 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] | 5477 | case AF_INET: |
| 5478 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5479 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5480 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5481 | break; |
| 5482 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5483 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5484 | break; |
| 5485 | default: |
| 5486 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5487 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5488 | break; |
| 5489 | } |
| 5490 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5491 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5492 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5493 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5494 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5495 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5496 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5497 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5498 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5499 | conn = objt_conn(sess->si[1].end); |
| 5500 | if (conn) |
| 5501 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5502 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5503 | 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] | 5504 | case AF_INET: |
| 5505 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5506 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5507 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5508 | break; |
| 5509 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5510 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5511 | break; |
| 5512 | default: |
| 5513 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5514 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5515 | break; |
| 5516 | } |
| 5517 | |
| 5518 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5519 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5520 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5521 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5522 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5523 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5524 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5525 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5526 | if (conn) |
| 5527 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5528 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5529 | 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] | 5530 | case AF_INET: |
| 5531 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5532 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5533 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5534 | break; |
| 5535 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5536 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5537 | break; |
| 5538 | default: |
| 5539 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5540 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5541 | break; |
| 5542 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5543 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5544 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5545 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5546 | sess->task, |
| 5547 | sess->task->state, |
| 5548 | sess->task->nice, sess->task->calls, |
| 5549 | sess->task->expire ? |
| 5550 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5551 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5552 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5553 | task_in_rq(sess->task) ? ", running" : ""); |
| 5554 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5555 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5556 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5557 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5558 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5559 | if (sess->txn) |
| 5560 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5561 | " 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] | 5562 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5563 | 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] | 5564 | |
| 5565 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5566 | " 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] | 5567 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5568 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5569 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5570 | obj_type_name(sess->si[0].end), |
| 5571 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5572 | sess->si[0].exp ? |
| 5573 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5574 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5575 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5576 | sess->si[0].err_type); |
| 5577 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5578 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5579 | " 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] | 5580 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5581 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5582 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5583 | obj_type_name(sess->si[1].end), |
| 5584 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5585 | sess->si[1].exp ? |
| 5586 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5587 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5588 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5589 | sess->si[1].err_type); |
| 5590 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5591 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5592 | chunk_appendf(&trash, |
| 5593 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5594 | conn, |
| 5595 | get_conn_ctrl_name(conn), |
| 5596 | get_conn_xprt_name(conn), |
| 5597 | get_conn_data_name(conn), |
| 5598 | obj_type_name(conn->target), |
| 5599 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5600 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5601 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5602 | " 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] | 5603 | conn->flags, |
| 5604 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5605 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5606 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5607 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5608 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5609 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5610 | chunk_appendf(&trash, |
| 5611 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5612 | tmpctx, |
| 5613 | tmpctx->st0, |
| 5614 | tmpctx->st1, |
| 5615 | tmpctx->st2, |
| 5616 | tmpctx->applet->name); |
| 5617 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5618 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5619 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5620 | chunk_appendf(&trash, |
| 5621 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5622 | conn, |
| 5623 | get_conn_ctrl_name(conn), |
| 5624 | get_conn_xprt_name(conn), |
| 5625 | get_conn_data_name(conn), |
| 5626 | obj_type_name(conn->target), |
| 5627 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5628 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5629 | chunk_appendf(&trash, |
Willy Tarreau | ceeafb5 | 2016-01-25 15:27:17 +0100 | [diff] [blame] | 5630 | " 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] | 5631 | conn->flags, |
| 5632 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5633 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5634 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5635 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5636 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5637 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5638 | chunk_appendf(&trash, |
| 5639 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5640 | tmpctx, |
| 5641 | tmpctx->st0, |
| 5642 | tmpctx->st1, |
| 5643 | tmpctx->st2, |
| 5644 | tmpctx->applet->name); |
| 5645 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5646 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5647 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5648 | " 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] | 5649 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5650 | &sess->req, |
| 5651 | sess->req.flags, sess->req.analysers, |
| 5652 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5653 | sess->req.to_forward, sess->req.total, |
| 5654 | sess->req.analyse_exp ? |
| 5655 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5656 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5657 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5658 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5659 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5660 | sess->req.rex ? |
| 5661 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5662 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5663 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5664 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5665 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5666 | " 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] | 5667 | sess->req.wex ? |
| 5668 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5669 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5670 | sess->req.buf, |
| 5671 | sess->req.buf->data, sess->req.buf->o, |
| 5672 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5673 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5674 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5675 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5676 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5677 | " 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] | 5678 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5679 | &sess->res, |
| 5680 | sess->res.flags, sess->res.analysers, |
| 5681 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5682 | sess->res.to_forward, sess->res.total, |
| 5683 | sess->res.analyse_exp ? |
| 5684 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5685 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5686 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5687 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5688 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5689 | sess->res.rex ? |
| 5690 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5691 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5692 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5693 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5694 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5695 | " 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] | 5696 | sess->res.wex ? |
| 5697 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5698 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5699 | sess->res.buf, |
| 5700 | sess->res.buf->data, sess->res.buf->o, |
| 5701 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5702 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5703 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5704 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5705 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5706 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5707 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5708 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5709 | |
| 5710 | /* use other states to dump the contents */ |
| 5711 | } |
| 5712 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5713 | appctx->ctx.sess.uid = 0; |
| 5714 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5715 | return 1; |
| 5716 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5717 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 5718 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 5719 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 5720 | struct appctx *appctx = __objt_appctx(si->end); |
| 5721 | |
| 5722 | switch (appctx->st2) { |
| 5723 | case STAT_ST_INIT: |
| 5724 | /* Display the column headers. If the message cannot be sent, |
| 5725 | * quit the fucntion with returning 0. The function is called |
| 5726 | * later and restart at the state "STAT_ST_INIT". |
| 5727 | */ |
| 5728 | chunk_reset(&trash); |
| 5729 | chunk_appendf(&trash, "# id (file)\n"); |
| 5730 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5731 | si_applet_cant_put(si); |
| 5732 | return 0; |
| 5733 | } |
| 5734 | |
| 5735 | /* Now, we start the browsing of the references lists. |
| 5736 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5737 | * avalaible field of this pointer is <list>. It is used with the function |
| 5738 | * tlskeys_list_get_next() for retruning the first avalaible entry |
| 5739 | */ |
| 5740 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 5741 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 5742 | |
| 5743 | appctx->st2 = STAT_ST_LIST; |
| 5744 | /* fall through */ |
| 5745 | |
| 5746 | case STAT_ST_LIST: |
| 5747 | while (appctx->ctx.tlskeys.ref) { |
| 5748 | chunk_reset(&trash); |
| 5749 | |
| 5750 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 5751 | appctx->ctx.tlskeys.ref->filename); |
| 5752 | |
| 5753 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5754 | /* let's try again later from this stream. We add ourselves into |
| 5755 | * this stream's users so that it can remove us upon termination. |
| 5756 | */ |
| 5757 | si_applet_cant_put(si); |
| 5758 | return 0; |
| 5759 | } |
| 5760 | |
| 5761 | /* get next list entry and check the end of the list */ |
| 5762 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 5763 | } |
| 5764 | |
| 5765 | appctx->st2 = STAT_ST_FIN; |
| 5766 | /* fall through */ |
| 5767 | |
| 5768 | default: |
| 5769 | appctx->st2 = STAT_ST_FIN; |
| 5770 | return 1; |
| 5771 | } |
| 5772 | return 0; |
| 5773 | } |
| 5774 | #endif |
| 5775 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5776 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5777 | { |
| 5778 | struct appctx *appctx = __objt_appctx(si->end); |
| 5779 | |
| 5780 | switch (appctx->st2) { |
| 5781 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5782 | /* Display the column headers. If the message cannot be sent, |
| 5783 | * quit the fucntion with returning 0. The function is called |
| 5784 | * later and restart at the state "STAT_ST_INIT". |
| 5785 | */ |
| 5786 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5787 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5788 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5789 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5790 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5791 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5792 | |
| 5793 | /* Now, we start the browsing of the references lists. |
| 5794 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5795 | * avalaible field of this pointer is <list>. It is used with the function |
| 5796 | * pat_list_get_next() for retruning the first avalaible entry |
| 5797 | */ |
| 5798 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 5799 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5800 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5801 | appctx->st2 = STAT_ST_LIST; |
| 5802 | /* fall through */ |
| 5803 | |
| 5804 | case STAT_ST_LIST: |
| 5805 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5806 | chunk_reset(&trash); |
| 5807 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5808 | /* Build messages. If the reference is used by another category than |
| 5809 | * the listed categorie, display the information in the massage. |
| 5810 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 5811 | 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] | 5812 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 5813 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5814 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5815 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5816 | /* let's try again later from this stream. We add ourselves into |
| 5817 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5818 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5819 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5820 | return 0; |
| 5821 | } |
| 5822 | |
| 5823 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5824 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 5825 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | appctx->st2 = STAT_ST_FIN; |
| 5829 | /* fall through */ |
| 5830 | |
| 5831 | default: |
| 5832 | appctx->st2 = STAT_ST_FIN; |
| 5833 | return 1; |
| 5834 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5835 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5836 | } |
| 5837 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5838 | static int stats_map_lookup(struct stream_interface *si) |
| 5839 | { |
| 5840 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5841 | struct sample sample; |
| 5842 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5843 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5844 | |
| 5845 | switch (appctx->st2) { |
| 5846 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5847 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 5848 | 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] | 5849 | 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] | 5850 | appctx->st2 = STAT_ST_LIST; |
| 5851 | /* fall through */ |
| 5852 | |
| 5853 | case STAT_ST_LIST: |
| 5854 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5855 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5856 | /* initialise chunk to build new message */ |
| 5857 | chunk_reset(&trash); |
| 5858 | |
| 5859 | /* execute pattern matching */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 5860 | sample.data.type = SMP_T_STR; |
Andreas Seltenreich | 9727cf4 | 2016-03-03 19:32:25 +0100 | [diff] [blame] | 5861 | sample.flags = SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 5862 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 5863 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 5864 | if (appctx->ctx.map.expr->pat_head->match && |
| 5865 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5866 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 5867 | else |
| 5868 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5869 | |
| 5870 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5871 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 5872 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 5873 | break; |
| 5874 | if (match_method >= PAT_MATCH_NUM) |
| 5875 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 5876 | else |
| 5877 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5878 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5879 | /* case sensitive */ |
| 5880 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 5881 | chunk_appendf(&trash, ", case=insensitive"); |
| 5882 | else |
| 5883 | chunk_appendf(&trash, ", case=sensitive"); |
| 5884 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5885 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5886 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5887 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5888 | chunk_appendf(&trash, ", found=no"); |
| 5889 | else |
| 5890 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | /* Display match and match info */ |
| 5894 | else { |
| 5895 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5896 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 5897 | chunk_appendf(&trash, ", found=yes"); |
| 5898 | else |
| 5899 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5900 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 5901 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 5902 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5903 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5904 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5905 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5906 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5907 | /* display pattern */ |
| 5908 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 5909 | if (pat->ref && pat->ref->pattern) |
| 5910 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 5911 | else |
| 5912 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5913 | } |
| 5914 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5915 | if (pat->ref && pat->ref->pattern) |
| 5916 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 5917 | else |
| 5918 | chunk_appendf(&trash, ", pattern=unknown"); |
| 5919 | } |
| 5920 | |
| 5921 | /* display return value */ |
| 5922 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 5923 | if (pat->data && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 03d0e45 | 2015-07-23 18:33:41 +0200 | [diff] [blame] | 5924 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
Thierry FOURNIER | 7d4335c | 2015-08-19 09:05:25 +0200 | [diff] [blame] | 5925 | smp_to_type[pat->data->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5926 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 5927 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5928 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5929 | } |
| 5930 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 5931 | chunk_appendf(&trash, "\n"); |
| 5932 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5933 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5934 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5935 | /* let's try again later from this stream. We add ourselves into |
| 5936 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5937 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5938 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5939 | return 0; |
| 5940 | } |
| 5941 | |
| 5942 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5943 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 5944 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | appctx->st2 = STAT_ST_FIN; |
| 5948 | /* fall through */ |
| 5949 | |
| 5950 | default: |
| 5951 | appctx->st2 = STAT_ST_FIN; |
| 5952 | free(appctx->ctx.map.chunk.str); |
| 5953 | return 1; |
| 5954 | } |
| 5955 | } |
| 5956 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5957 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5958 | { |
| 5959 | struct appctx *appctx = __objt_appctx(si->end); |
| 5960 | |
| 5961 | switch (appctx->st2) { |
| 5962 | |
| 5963 | case STAT_ST_INIT: |
| 5964 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5965 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 5966 | struct pat_ref_elt *, list); |
| 5967 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 5968 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5969 | appctx->st2 = STAT_ST_LIST; |
| 5970 | /* fall through */ |
| 5971 | |
| 5972 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5973 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5974 | chunk_reset(&trash); |
| 5975 | |
| 5976 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5977 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5978 | chunk_appendf(&trash, "%p %s %s\n", |
| 5979 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 5980 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5981 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 5982 | chunk_appendf(&trash, "%p %s\n", |
| 5983 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5984 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5985 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5986 | /* let's try again later from this stream. We add ourselves into |
| 5987 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5988 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5989 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5990 | return 0; |
| 5991 | } |
| 5992 | |
| 5993 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5994 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 5995 | struct pat_ref_elt *, list); |
| 5996 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5997 | break; |
| 5998 | } |
| 5999 | |
| 6000 | appctx->st2 = STAT_ST_FIN; |
| 6001 | /* fall through */ |
| 6002 | |
| 6003 | default: |
| 6004 | appctx->st2 = STAT_ST_FIN; |
| 6005 | return 1; |
| 6006 | } |
| 6007 | } |
| 6008 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6009 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6010 | * 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] | 6011 | * to be called again, otherwise non-zero. It is designed to be called |
| 6012 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6013 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6014 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6015 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6016 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6017 | struct connection *conn; |
| 6018 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6019 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6020 | /* 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] | 6021 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6022 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6023 | if (appctx->st2 == STAT_ST_LIST) { |
| 6024 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6025 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6026 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6027 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6028 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6029 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6030 | } |
| 6031 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6032 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6033 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6034 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6035 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6036 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6037 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6038 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6039 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6040 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6041 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6042 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6043 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6044 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6045 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6046 | /* fall through */ |
| 6047 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6048 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6049 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6050 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6051 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6052 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6053 | } |
| 6054 | |
| 6055 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6056 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 6057 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6058 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6059 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6060 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6061 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6062 | if (appctx->ctx.sess.target) { |
| 6063 | 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] | 6064 | goto next_sess; |
| 6065 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6066 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6067 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6068 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6069 | return 0; |
| 6070 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6071 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6072 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6073 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 6074 | if (appctx->ctx.sess.target != (void *)-1) { |
| 6075 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6076 | break; |
| 6077 | } |
| 6078 | else |
| 6079 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6080 | } |
| 6081 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6082 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6083 | "%p: proto=%s", |
| 6084 | curr_sess, |
Willy Tarreau | f1e0212 | 2015-09-23 12:16:43 +0200 | [diff] [blame] | 6085 | strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6086 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6087 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6088 | 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] | 6089 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6090 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6091 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6092 | " src=%s:%d fe=%s be=%s srv=%s", |
| 6093 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6094 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6095 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6096 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6097 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6098 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6099 | break; |
| 6100 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6101 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6102 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6103 | strm_li(curr_sess)->luid, |
| 6104 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6105 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6106 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6107 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6108 | break; |
| 6109 | } |
| 6110 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6111 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 6112 | " ts=%02x age=%s calls=%d", |
| 6113 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 6114 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 6115 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6116 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6117 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6118 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6119 | curr_sess->req.flags, |
| 6120 | curr_sess->req.buf->i, |
| 6121 | curr_sess->req.analysers, |
| 6122 | curr_sess->req.rex ? |
| 6123 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6124 | TICKS_TO_MS(1000)) : ""); |
| 6125 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6126 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6127 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6128 | curr_sess->req.wex ? |
| 6129 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6130 | TICKS_TO_MS(1000)) : ""); |
| 6131 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6132 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6133 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6134 | curr_sess->req.analyse_exp ? |
| 6135 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6136 | TICKS_TO_MS(1000)) : ""); |
| 6137 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6138 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6139 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6140 | curr_sess->res.flags, |
| 6141 | curr_sess->res.buf->i, |
| 6142 | curr_sess->res.analysers, |
| 6143 | curr_sess->res.rex ? |
| 6144 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6145 | TICKS_TO_MS(1000)) : ""); |
| 6146 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6147 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6148 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6149 | curr_sess->res.wex ? |
| 6150 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6151 | TICKS_TO_MS(1000)) : ""); |
| 6152 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6153 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6154 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6155 | curr_sess->res.analyse_exp ? |
| 6156 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6157 | TICKS_TO_MS(1000)) : ""); |
| 6158 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6159 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6160 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6161 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 6162 | curr_sess->si[0].state, |
| 6163 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6164 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6165 | curr_sess->si[0].exp ? |
| 6166 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 6167 | TICKS_TO_MS(1000)) : ""); |
| 6168 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6169 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6170 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6171 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 6172 | curr_sess->si[1].state, |
| 6173 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6174 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6175 | curr_sess->si[1].exp ? |
| 6176 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 6177 | TICKS_TO_MS(1000)) : ""); |
| 6178 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6179 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6180 | " exp=%s", |
| 6181 | curr_sess->task->expire ? |
| 6182 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 6183 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 6184 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6185 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6186 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6187 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6188 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6189 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6190 | /* let's try again later from this stream. We add ourselves into |
| 6191 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6192 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6193 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6194 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6195 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6196 | } |
| 6197 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6198 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6199 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6200 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6201 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6202 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6203 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6204 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6205 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6206 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6207 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6208 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6209 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6210 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6211 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6212 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6213 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6214 | appctx->ctx.sess.target = NULL; |
| 6215 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6216 | return 1; |
| 6217 | } |
| 6218 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6219 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6220 | /* fall through */ |
| 6221 | |
| 6222 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6223 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6224 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6225 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 6226 | } |
| 6227 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6228 | /* This is called when the stream interface is closed. For instance, upon an |
| 6229 | * 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] | 6230 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6231 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 6232 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6233 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6234 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 6235 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 6236 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6237 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6238 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 6239 | free(appctx->ctx.cli.err); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6240 | appctx->ctx.cli.err = NULL; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6241 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6242 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 6243 | free(appctx->ctx.map.chunk.str); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6244 | appctx->ctx.map.chunk.str = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6245 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6246 | } |
| 6247 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6248 | /* This function is used to either dump tables states (when action is set |
| 6249 | * 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] | 6250 | * It returns 0 if the output buffer is full and it needs to be called |
| 6251 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6252 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6253 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6254 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6255 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6256 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6257 | struct ebmb_node *eb; |
| 6258 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6259 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6260 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6261 | |
| 6262 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6263 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6264 | * - STAT_ST_INIT : the first call |
| 6265 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6266 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6267 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6268 | * and the entry pointer points to the next entry to be dumped, |
| 6269 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6270 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6271 | * data though. |
| 6272 | */ |
| 6273 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6274 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6275 | /* 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] | 6276 | if (appctx->st2 == STAT_ST_LIST) { |
| 6277 | appctx->ctx.table.entry->ref_cnt--; |
| 6278 | 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] | 6279 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6280 | return 1; |
| 6281 | } |
| 6282 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6283 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6284 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6285 | while (appctx->st2 != STAT_ST_FIN) { |
| 6286 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6287 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6288 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 6289 | if (!appctx->ctx.table.proxy) |
| 6290 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6291 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6292 | appctx->ctx.table.entry = NULL; |
| 6293 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6294 | break; |
| 6295 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6296 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6297 | if (!appctx->ctx.table.proxy || |
| 6298 | (appctx->ctx.table.target && |
| 6299 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6300 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6301 | break; |
| 6302 | } |
| 6303 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6304 | if (appctx->ctx.table.proxy->table.size) { |
| 6305 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6306 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6307 | return 0; |
| 6308 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6309 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6310 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6311 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6312 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6313 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6314 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6315 | appctx->ctx.table.entry->ref_cnt++; |
| 6316 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6317 | break; |
| 6318 | } |
| 6319 | } |
| 6320 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6321 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6322 | break; |
| 6323 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6324 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6325 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6326 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6327 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6328 | /* we're filtering on some data contents */ |
| 6329 | void *ptr; |
| 6330 | long long data; |
| 6331 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6332 | dt = appctx->ctx.table.data_type; |
| 6333 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6334 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6335 | dt); |
| 6336 | |
| 6337 | data = 0; |
| 6338 | switch (stktable_data_types[dt].std_type) { |
| 6339 | case STD_T_SINT: |
| 6340 | data = stktable_data_cast(ptr, std_t_sint); |
| 6341 | break; |
| 6342 | case STD_T_UINT: |
| 6343 | data = stktable_data_cast(ptr, std_t_uint); |
| 6344 | break; |
| 6345 | case STD_T_ULL: |
| 6346 | data = stktable_data_cast(ptr, std_t_ull); |
| 6347 | break; |
| 6348 | case STD_T_FRQP: |
| 6349 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6350 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6351 | break; |
| 6352 | } |
| 6353 | |
| 6354 | /* 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] | 6355 | if ((data < appctx->ctx.table.value && |
| 6356 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6357 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6358 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6359 | (data == appctx->ctx.table.value && |
| 6360 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6361 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6362 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6363 | (data > appctx->ctx.table.value && |
| 6364 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6365 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6366 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6367 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6368 | } |
| 6369 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6370 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6371 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6372 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6373 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6374 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6375 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6376 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6377 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6378 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6379 | struct stksess *old = appctx->ctx.table.entry; |
| 6380 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6381 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6382 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6383 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6384 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6385 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6386 | break; |
| 6387 | } |
| 6388 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6389 | |
| 6390 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6391 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6392 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6393 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6394 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6395 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6396 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6397 | break; |
| 6398 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6399 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6400 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6401 | break; |
| 6402 | } |
| 6403 | } |
| 6404 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6405 | } |
| 6406 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6407 | /* 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] | 6408 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6409 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6410 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6411 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6412 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6413 | * after the offset. The new pointer is returned. |
| 6414 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6415 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6416 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6417 | { |
| 6418 | int end; |
| 6419 | unsigned char c; |
| 6420 | |
| 6421 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6422 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6423 | return ptr; |
| 6424 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6425 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6426 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6427 | while (ptr < len && ptr < bsize) { |
| 6428 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6429 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6430 | if (out->len > end - 2) |
| 6431 | break; |
| 6432 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6433 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6434 | if (out->len > end - 3) |
| 6435 | break; |
| 6436 | out->str[out->len++] = '\\'; |
| 6437 | switch (c) { |
| 6438 | case '\t': c = 't'; break; |
| 6439 | case '\n': c = 'n'; break; |
| 6440 | case '\r': c = 'r'; break; |
| 6441 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6442 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6443 | } |
| 6444 | out->str[out->len++] = c; |
| 6445 | } else { |
| 6446 | if (out->len > end - 5) |
| 6447 | break; |
| 6448 | out->str[out->len++] = '\\'; |
| 6449 | out->str[out->len++] = 'x'; |
| 6450 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6451 | out->str[out->len++] = hextab[c & 0xF]; |
| 6452 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6453 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6454 | /* we had a line break, let's return now */ |
| 6455 | out->str[out->len++] = '\n'; |
| 6456 | *line = ptr; |
| 6457 | return ptr; |
| 6458 | } |
| 6459 | } |
| 6460 | /* we have an incomplete line, we return it as-is */ |
| 6461 | out->str[out->len++] = '\n'; |
| 6462 | return ptr; |
| 6463 | } |
| 6464 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6465 | /* This function dumps counters from all resolvers section and associated name servers. |
| 6466 | * It returns 0 if the output buffer is full and it needs |
| 6467 | * to be called again, otherwise non-zero. |
| 6468 | */ |
| 6469 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si) |
| 6470 | { |
| 6471 | struct appctx *appctx = __objt_appctx(si->end); |
| 6472 | struct dns_resolvers *presolvers; |
| 6473 | struct dns_nameserver *pnameserver; |
| 6474 | |
| 6475 | chunk_reset(&trash); |
| 6476 | |
| 6477 | switch (appctx->st2) { |
| 6478 | case STAT_ST_INIT: |
| 6479 | appctx->st2 = STAT_ST_LIST; /* let's start producing data */ |
| 6480 | /* fall through */ |
| 6481 | |
| 6482 | case STAT_ST_LIST: |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 6483 | if (LIST_ISEMPTY(&dns_resolvers)) { |
| 6484 | chunk_appendf(&trash, "No resolvers found\n"); |
| 6485 | } |
| 6486 | else { |
| 6487 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 6488 | if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers) |
| 6489 | continue; |
| 6490 | |
| 6491 | chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id); |
| 6492 | list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) { |
| 6493 | chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id); |
| 6494 | chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent); |
| 6495 | chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid); |
| 6496 | chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update); |
| 6497 | chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname); |
| 6498 | chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error); |
| 6499 | chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err); |
| 6500 | chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx); |
| 6501 | chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout); |
| 6502 | chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused); |
| 6503 | chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other); |
| 6504 | chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid); |
| 6505 | chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big); |
| 6506 | chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated); |
| 6507 | chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated); |
| 6508 | } |
| 6509 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6510 | } |
| 6511 | |
| 6512 | /* display response */ |
| 6513 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6514 | /* let's try again later from this session. We add ourselves into |
| 6515 | * this session's users so that it can remove us upon termination. |
| 6516 | */ |
| 6517 | si->flags |= SI_FL_WAIT_ROOM; |
| 6518 | return 0; |
| 6519 | } |
| 6520 | |
| 6521 | appctx->st2 = STAT_ST_FIN; |
| 6522 | /* fall through */ |
| 6523 | |
| 6524 | default: |
| 6525 | appctx->st2 = STAT_ST_FIN; |
| 6526 | return 1; |
| 6527 | } |
| 6528 | } |
| 6529 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6530 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6531 | * 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] | 6532 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6533 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6534 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6535 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6536 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6537 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6538 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6539 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6540 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6541 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6542 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6543 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6544 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6545 | /* the function had not been called yet, let's prepare the |
| 6546 | * buffer for a response. |
| 6547 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6548 | struct tm tm; |
| 6549 | |
| 6550 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6551 | 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] | 6552 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6553 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6554 | error_snapshot_id); |
| 6555 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6556 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6557 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6558 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6559 | return 0; |
| 6560 | } |
| 6561 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6562 | appctx->ctx.errors.px = proxy; |
| 6563 | appctx->ctx.errors.buf = 0; |
| 6564 | appctx->ctx.errors.bol = 0; |
| 6565 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6566 | } |
| 6567 | |
| 6568 | /* we have two inner loops here, one for the proxy, the other one for |
| 6569 | * the buffer. |
| 6570 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6571 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6572 | struct error_snapshot *es; |
| 6573 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6574 | if (appctx->ctx.errors.buf == 0) |
| 6575 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6576 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6577 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6578 | |
| 6579 | if (!es->when.tv_sec) |
| 6580 | goto next; |
| 6581 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6582 | if (appctx->ctx.errors.iid >= 0 && |
| 6583 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6584 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6585 | goto next; |
| 6586 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6587 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6588 | /* just print headers now */ |
| 6589 | |
| 6590 | char pn[INET6_ADDRSTRLEN]; |
| 6591 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6592 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6593 | |
| 6594 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6595 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6596 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6597 | 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] | 6598 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6599 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6600 | case AF_INET: |
| 6601 | case AF_INET6: |
| 6602 | port = get_host_port(&es->src); |
| 6603 | break; |
| 6604 | default: |
| 6605 | port = 0; |
| 6606 | } |
| 6607 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6608 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6609 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6610 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6611 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6612 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6613 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6614 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6615 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6616 | break; |
| 6617 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6618 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6619 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6620 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6621 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6622 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6623 | break; |
| 6624 | } |
| 6625 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6626 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6627 | ", server %s (#%d), event #%u\n" |
| 6628 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6629 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6630 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6631 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6632 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6633 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6634 | es->ev_id, |
| 6635 | pn, port, es->sid, es->s_flags, |
| 6636 | es->state, es->m_flags, es->t_flags, |
| 6637 | es->m_clen, es->m_blen, |
| 6638 | es->b_flags, es->b_out, es->b_tot, |
| 6639 | es->len, es->b_wrap, es->pos); |
| 6640 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6641 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6642 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6643 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6644 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6645 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6646 | appctx->ctx.errors.ptr = 0; |
| 6647 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6648 | } |
| 6649 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6650 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6651 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6652 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6653 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6654 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6655 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6656 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6657 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6658 | goto next; |
| 6659 | } |
| 6660 | |
| 6661 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6662 | 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] | 6663 | int newptr; |
| 6664 | int newline; |
| 6665 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6666 | newline = appctx->ctx.errors.bol; |
| 6667 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6668 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6669 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6670 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6671 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6672 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6673 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6674 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6675 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6676 | appctx->ctx.errors.ptr = newptr; |
| 6677 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6678 | }; |
| 6679 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6680 | appctx->ctx.errors.bol = 0; |
| 6681 | appctx->ctx.errors.ptr = -1; |
| 6682 | appctx->ctx.errors.buf++; |
| 6683 | if (appctx->ctx.errors.buf > 1) { |
| 6684 | appctx->ctx.errors.buf = 0; |
| 6685 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6686 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 6687 | } |
| 6688 | |
| 6689 | /* dump complete */ |
| 6690 | return 1; |
| 6691 | } |
| 6692 | |
| 6693 | /* This function dumps all environmnent variables to the buffer. It returns 0 |
| 6694 | * if the output buffer is full and it needs to be called again, otherwise |
| 6695 | * non-zero. Dumps only one entry if st2 == STAT_ST_END. |
| 6696 | */ |
| 6697 | static int stats_dump_env_to_buffer(struct stream_interface *si) |
| 6698 | { |
| 6699 | struct appctx *appctx = __objt_appctx(si->end); |
| 6700 | |
| 6701 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 6702 | return 1; |
| 6703 | |
| 6704 | chunk_reset(&trash); |
| 6705 | |
| 6706 | /* we have two inner loops here, one for the proxy, the other one for |
| 6707 | * the buffer. |
| 6708 | */ |
| 6709 | while (*appctx->ctx.env.var) { |
| 6710 | chunk_printf(&trash, "%s\n", *appctx->ctx.env.var); |
| 6711 | |
| 6712 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6713 | si_applet_cant_put(si); |
| 6714 | return 0; |
| 6715 | } |
| 6716 | if (appctx->st2 == STAT_ST_END) |
| 6717 | break; |
| 6718 | appctx->ctx.env.var++; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6722 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6723 | } |
| 6724 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6725 | /* parse the "level" argument on the bind lines */ |
| 6726 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6727 | { |
| 6728 | if (!*args[cur_arg + 1]) { |
| 6729 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6730 | return ERR_ALERT | ERR_FATAL; |
| 6731 | } |
| 6732 | |
| 6733 | if (!strcmp(args[cur_arg+1], "user")) |
| 6734 | conf->level = ACCESS_LVL_USER; |
| 6735 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6736 | conf->level = ACCESS_LVL_OPER; |
| 6737 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6738 | conf->level = ACCESS_LVL_ADMIN; |
| 6739 | else { |
| 6740 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6741 | args[cur_arg], args[cur_arg+1]); |
| 6742 | return ERR_ALERT | ERR_FATAL; |
| 6743 | } |
| 6744 | |
| 6745 | return 0; |
| 6746 | } |
| 6747 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 6748 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6749 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6750 | .name = "<STATS>", /* used for logging */ |
| 6751 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6752 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6753 | }; |
| 6754 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 6755 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6756 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6757 | .name = "<CLI>", /* used for logging */ |
| 6758 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6759 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6760 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6761 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6762 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6763 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6764 | { 0, NULL, NULL }, |
| 6765 | }}; |
| 6766 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6767 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6768 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6769 | { NULL, NULL, 0 }, |
| 6770 | }}; |
| 6771 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6772 | __attribute__((constructor)) |
| 6773 | static void __dumpstats_module_init(void) |
| 6774 | { |
| 6775 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6776 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6777 | } |
| 6778 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6779 | /* |
| 6780 | * Local variables: |
| 6781 | * c-indent-level: 8 |
| 6782 | * c-basic-offset: 8 |
| 6783 | * End: |
| 6784 | */ |