blob: 67686d3d461690244a0ec40a82be174010abd33f [file] [log] [blame]
Willy Tarreau91861262007-10-17 17:06:05 +02001/*
Willy Tarreaueb472682010-05-28 18:46:57 +02002 * Functions dedicated to statistics output and the stats socket
Willy Tarreau91861262007-10-17 17:06:05 +02003 *
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004 * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02005 * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl>
Willy Tarreau91861262007-10-17 17:06:05 +02006 *
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 Tarreaufbee7132007-10-18 13:53:22 +020020#include <pwd.h>
21#include <grp.h>
Willy Tarreau91861262007-10-17 17:06:05 +020022
23#include <sys/socket.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26
Willy Tarreau10522fd2008-07-09 20:12:41 +020027#include <common/cfgparse.h>
Willy Tarreau91861262007-10-17 17:06:05 +020028#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 Tarreau0c303ee2008-07-07 00:09:58 +020034#include <common/ticks.h>
Willy Tarreau91861262007-10-17 17:06:05 +020035#include <common/time.h>
36#include <common/uri_auth.h>
37#include <common/version.h>
Emeric Brun4147b2e2014-06-16 18:36:30 +020038#include <common/base64.h>
Willy Tarreau91861262007-10-17 17:06:05 +020039
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020040#include <types/applet.h>
Willy Tarreau91861262007-10-17 17:06:05 +020041#include <types/global.h>
Baptiste Assmann3863f972015-05-17 00:33:24 +020042#include <types/dns.h>
Willy Tarreau91861262007-10-17 17:06:05 +020043
44#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020045#include <proto/channel.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020046#include <proto/checks.h>
William Lallemande3a7d992012-11-20 11:25:20 +010047#include <proto/compression.h>
Willy Tarreau91861262007-10-17 17:06:05 +020048#include <proto/dumpstats.h>
49#include <proto/fd.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010050#include <proto/freq_ctr.h>
Willy Tarreau32b60d42015-03-13 16:14:57 +010051#include <proto/frontend.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020052#include <proto/log.h>
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010053#include <proto/pattern.h>
Willy Tarreaua206fa92009-01-25 14:02:00 +010054#include <proto/pipe.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020055#include <proto/listener.h>
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010056#include <proto/map.h>
Willy Tarreaue6d97022012-11-23 11:19:33 +010057#include <proto/proto_http.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020058#include <proto/proto_uxst.h>
Willy Tarreau89a63132009-08-16 17:41:45 +020059#include <proto/proxy.h>
Willy Tarreau1cf8f082014-02-07 12:14:54 +010060#include <proto/sample.h>
Willy Tarreau9903f0e2015-04-04 18:50:31 +020061#include <proto/session.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020062#include <proto/stream.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020063#include <proto/server.h>
Willy Tarreau75bf2c92012-08-20 17:01:35 +020064#include <proto/raw_sock.h>
Willy Tarreaudded32d2008-11-30 19:48:07 +010065#include <proto/stream_interface.h>
Willy Tarreau4726f532009-03-07 17:25:21 +010066#include <proto/task.h>
Willy Tarreau91861262007-10-17 17:06:05 +020067
Willy Tarreau7a0169a2012-11-19 17:13:16 +010068#ifdef USE_OPENSSL
69#include <proto/ssl_sock.h>
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +020070#include <types/ssl_sock.h>
Willy Tarreau7a0169a2012-11-19 17:13:16 +010071#endif
72
Willy Tarreau91b843d2014-01-28 16:27:17 +010073/* stats socket states */
74enum {
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 FOURNIER364cfdf2014-01-29 19:08:49 +010081 STAT_CLI_PRINT_FREE, /* display message in cli->msg. After the display, free the pointer */
Willy Tarreau91b843d2014-01-28 16:27:17 +010082 STAT_CLI_O_INFO, /* dump info */
Willy Tarreau87b09662015-04-03 00:22:06 +020083 STAT_CLI_O_SESS, /* dump streams */
Willy Tarreau91b843d2014-01-28 16:27:17 +010084 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 FOURNIER1e00d382014-02-11 11:31:40 +010089 STAT_CLI_O_PATS, /* list all pattern reference avalaible */
90 STAT_CLI_O_PAT, /* list all entries of a pattern */
Willy Tarreau91b843d2014-01-28 16:27:17 +010091 STAT_CLI_O_MLOOK, /* lookup a map entry */
Willy Tarreau12833bb2014-01-28 16:49:56 +010092 STAT_CLI_O_POOLS, /* dump memory pools */
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +020093 STAT_CLI_O_TLSK, /* list all TLS ticket keys references */
Baptiste Assmann3863f972015-05-17 00:33:24 +020094 STAT_CLI_O_RESOLVERS,/* dump a resolver's section nameservers counters */
Baptiste Assmann28289462015-07-03 08:01:20 +020095 STAT_CLI_O_SERVERS_STATE, /* dump server state and changing information */
Baptiste Assmann9b6857e2015-09-18 14:49:12 +020096 STAT_CLI_O_BACKEND, /* dump backend list */
Willy Tarreau91b843d2014-01-28 16:27:17 +010097};
98
Willy Tarreaued7df902014-05-22 18:04:49 +020099/* Actions available for the stats admin forms */
100enum {
101 ST_ADM_ACTION_NONE = 0,
Willy Tarreau248a60e2014-05-23 14:59:48 +0200102
103 /* enable/disable health checks */
104 ST_ADM_ACTION_DHLTH,
105 ST_ADM_ACTION_EHLTH,
106
107 /* force health check status */
108 ST_ADM_ACTION_HRUNN,
109 ST_ADM_ACTION_HNOLB,
110 ST_ADM_ACTION_HDOWN,
111
112 /* enable/disable agent checks */
113 ST_ADM_ACTION_DAGENT,
114 ST_ADM_ACTION_EAGENT,
115
116 /* force agent check status */
117 ST_ADM_ACTION_ARUNN,
118 ST_ADM_ACTION_ADOWN,
119
120 /* set admin state */
Willy Tarreaued7df902014-05-22 18:04:49 +0200121 ST_ADM_ACTION_READY,
122 ST_ADM_ACTION_DRAIN,
123 ST_ADM_ACTION_MAINT,
124 ST_ADM_ACTION_SHUTDOWN,
125 /* these are the ancient actions, still available for compatibility */
126 ST_ADM_ACTION_DISABLE,
127 ST_ADM_ACTION_ENABLE,
128 ST_ADM_ACTION_STOP,
129 ST_ADM_ACTION_START,
130};
131
Baptiste Assmann9b6857e2015-09-18 14:49:12 +0200132static int stats_dump_backend_to_buffer(struct stream_interface *si);
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +0100133static int stats_dump_info_to_buffer(struct stream_interface *si);
Baptiste Assmann28289462015-07-03 08:01:20 +0200134static int stats_dump_servers_state_to_buffer(struct stream_interface *si);
Willy Tarreau12833bb2014-01-28 16:49:56 +0100135static int stats_dump_pools_to_buffer(struct stream_interface *si);
Willy Tarreau87b09662015-04-03 00:22:06 +0200136static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct stream *sess);
Simon Horman9bd2c732011-06-15 15:18:44 +0900137static int stats_dump_sess_to_buffer(struct stream_interface *si);
138static int stats_dump_errors_to_buffer(struct stream_interface *si);
Willy Tarreau44455022012-12-05 23:01:12 +0100139static int stats_table_request(struct stream_interface *si, int show);
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +0100140static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri);
141static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri);
Baptiste Assmann3863f972015-05-17 00:33:24 +0200142static int stats_dump_resolvers_to_buffer(struct stream_interface *si);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100143static int stats_pats_list(struct stream_interface *si);
144static int stats_pat_list(struct stream_interface *si);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +0100145static int stats_map_lookup(struct stream_interface *si);
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +0200146#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
147static int stats_tlskeys_list(struct stream_interface *si);
148#endif
Willy Tarreau00a37f02015-04-13 12:05:19 +0200149static void cli_release_handler(struct appctx *appctx);
Simon Horman9bd2c732011-06-15 15:18:44 +0900150
Baptiste Assmann28289462015-07-03 08:01:20 +0200151static void dump_servers_state(struct proxy *backend, struct chunk *buf);
152
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100153/*
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +0100154 * cli_io_handler()
155 * -> stats_dump_sess_to_buffer() // "show sess"
156 * -> stats_dump_errors_to_buffer() // "show errors"
157 * -> stats_dump_info_to_buffer() // "show info"
Baptiste Assmann9b6857e2015-09-18 14:49:12 +0200158 * -> stats_dump_backend_to_buffer() // "show backend"
Baptiste Assmann28289462015-07-03 08:01:20 +0200159 * -> stats_dump_servers_state_to_buffer() // "show servers state [<backend name>]"
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +0100160 * -> stats_dump_stat_to_buffer() // "show stat"
Baptiste Assmann3863f972015-05-17 00:33:24 +0200161 * -> stats_dump_resolvers_to_buffer() // "show stat resolver <id>"
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +0100162 * -> stats_dump_csv_header()
163 * -> stats_dump_proxy_to_buffer()
164 * -> stats_dump_fe_stats()
165 * -> stats_dump_li_stats()
166 * -> stats_dump_sv_stats()
167 * -> stats_dump_be_stats()
168 *
169 * http_stats_io_handler()
170 * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML
171 * -> stats_dump_csv_header() // emits the CSV headers (same as above)
172 * -> stats_dump_html_head() // emits the HTML headers
173 * -> stats_dump_html_info() // emits the equivalent of "show info" at the top
174 * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML
175 * -> stats_dump_html_px_hdr()
176 * -> stats_dump_fe_stats()
177 * -> stats_dump_li_stats()
178 * -> stats_dump_sv_stats()
179 * -> stats_dump_be_stats()
180 * -> stats_dump_html_px_end()
181 * -> stats_dump_html_end() // emits HTML trailer
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100182 */
183
Willy Tarreau30576452015-04-13 13:50:30 +0200184static struct applet cli_applet;
Simon Horman9bd2c732011-06-15 15:18:44 +0900185
186static const char stats_sock_usage_msg[] =
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200187 "Unknown command. Please enter one of the following commands only :\n"
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200188 " clear counters : clear max statistics counters (add 'all' for all counters)\n"
Willy Tarreau88ee3972010-07-13 13:48:00 +0200189 " clear table : remove an entry from a table\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200190 " help : this message\n"
191 " prompt : toggle interactive mode with prompt\n"
192 " quit : disconnect\n"
Baptiste Assmann9b6857e2015-09-18 14:49:12 +0200193 " show backend : list backends in the current running config\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200194 " show info : report information about the running process\n"
Willy Tarreau12833bb2014-01-28 16:49:56 +0100195 " show pools : report information about the memory pools usage\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200196 " show stat : report counters for each proxy and server\n"
197 " show errors : report last request and response errors for each proxy\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100198 " show sess [id] : report the list of current sessions or dump this session\n"
Willy Tarreau69f58c82010-07-12 17:55:33 +0200199 " show table [id]: report table usage stats or dump this table's contents\n"
Baptiste Assmann28289462015-07-03 08:01:20 +0200200 " show servers state [id]: dump volatile server information (for backend <id>)\n"
Willy Tarreau38338fa2009-10-10 18:37:29 +0200201 " get weight : report a server's current weight\n"
Willy Tarreau4483d432009-10-10 19:30:08 +0200202 " set weight : change a server's weight\n"
Baptiste Assmann3d8f8312015-04-13 22:54:33 +0200203 " set server : change a server's state, weight or address\n"
Willy Tarreau654694e2012-06-07 01:03:16 +0200204 " set table [id] : update or create a table entry's data\n"
Willy Tarreau7aabd112010-01-26 10:59:06 +0100205 " set timeout : change a timeout setting\n"
Willy Tarreau2a0f4d22011-08-02 11:49:05 +0200206 " set maxconn : change a maxconn setting\n"
Willy Tarreauf5b22872011-09-07 16:13:44 +0200207 " set rate-limit : change a rate limiting value\n"
Willy Tarreaua295edc2011-09-07 23:21:03 +0200208 " disable : put a server or frontend in maintenance mode\n"
209 " enable : re-enable a server or frontend which is in maintenance mode\n"
210 " shutdown : kill a session or a frontend (eg:to release listening ports)\n"
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100211 " show acl [id] : report avalaible acls or dump an acl's contents\n"
212 " get acl : reports the patterns matching a sample for an ACL\n"
213 " add acl : add acl entry\n"
214 " del acl : delete acl entry\n"
215 " clear acl <id> : clear the content of this acl\n"
Thierry FOURNIER1432a0c2014-03-11 13:42:38 +0100216 " show map [id] : report avalaible maps or dump a map's contents\n"
217 " get map : reports the keys and values matching a sample for a map\n"
218 " set map : modify map entry\n"
219 " add map : add map entry\n"
220 " del map : delete map entry\n"
221 " clear map <id> : clear the content of this map\n"
Emeric Brun4147b2e2014-06-16 18:36:30 +0200222 " set ssl <stmt> : set statement for ssl\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200223 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200224
Simon Horman9bd2c732011-06-15 15:18:44 +0900225static const char stats_permission_denied_msg[] =
Willy Tarreau6162db22009-10-10 17:13:00 +0200226 "Permission denied\n"
227 "";
228
Willy Tarreau295a8372011-03-10 11:25:07 +0100229/* data transmission states for the stats responses */
230enum {
231 STAT_ST_INIT = 0,
232 STAT_ST_HEAD,
233 STAT_ST_INFO,
234 STAT_ST_LIST,
235 STAT_ST_END,
236 STAT_ST_FIN,
237};
238
239/* data transmission states for the stats responses inside a proxy */
240enum {
241 STAT_PX_ST_INIT = 0,
242 STAT_PX_ST_TH,
243 STAT_PX_ST_FE,
244 STAT_PX_ST_LI,
245 STAT_PX_ST_SV,
246 STAT_PX_ST_BE,
247 STAT_PX_ST_END,
248 STAT_PX_ST_FIN,
249};
250
Cyril Bonté19979e12012-04-04 12:57:21 +0200251extern const char *stat_status_codes[];
252
Willy Tarreau07e9e642010-08-17 21:48:17 +0200253/* allocate a new stats frontend named <name>, and return it
254 * (or NULL in case of lack of memory).
255 */
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200256static struct proxy *alloc_stats_fe(const char *name, const char *file, int line)
Willy Tarreau07e9e642010-08-17 21:48:17 +0200257{
258 struct proxy *fe;
259
260 fe = (struct proxy *)calloc(1, sizeof(struct proxy));
261 if (!fe)
262 return NULL;
263
Willy Tarreau237250c2011-07-29 01:49:03 +0200264 init_new_proxy(fe);
Willy Tarreau050536d2012-10-04 08:47:34 +0200265 fe->next = proxy;
266 proxy = fe;
Willy Tarreau07e9e642010-08-17 21:48:17 +0200267 fe->last_change = now.tv_sec;
268 fe->id = strdup("GLOBAL");
269 fe->cap = PR_CAP_FE;
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200270 fe->maxconn = 10; /* default to 10 concurrent connections */
271 fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200272 fe->conf.file = strdup(file);
273 fe->conf.line = line;
Willy Tarreau32b60d42015-03-13 16:14:57 +0100274 fe->accept = frontend_accept;
Willy Tarreauf87ab942015-03-13 15:55:16 +0100275 fe->default_target = &cli_applet.obj_type;
Willy Tarreau050536d2012-10-04 08:47:34 +0200276
277 /* the stats frontend is the only one able to assign ID #0 */
278 fe->conf.id.key = fe->uuid = 0;
279 eb32_insert(&used_proxy_id, &fe->conf.id);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200280 return fe;
281}
282
Willy Tarreaufbee7132007-10-18 13:53:22 +0200283/* This function parses a "stats" statement in the "global" section. It returns
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200284 * -1 if there is any error, otherwise zero. If it returns -1, it will write an
285 * error message into the <err> buffer which will be preallocated. The trailing
286 * '\n' must not be written. The function must be called with <args> pointing to
287 * the first word after "stats".
Willy Tarreaufbee7132007-10-18 13:53:22 +0200288 */
Willy Tarreau10522fd2008-07-09 20:12:41 +0200289static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
Willy Tarreau28a47d62012-09-18 20:02:48 +0200290 struct proxy *defpx, const char *file, int line,
291 char **err)
Willy Tarreaufbee7132007-10-18 13:53:22 +0200292{
Willy Tarreau4348fad2012-09-20 16:48:07 +0200293 struct bind_conf *bind_conf;
Willy Tarreauc53d4222012-09-20 20:19:28 +0200294 struct listener *l;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200295
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200296 if (!strcmp(args[1], "socket")) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200297 int cur_arg;
298
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200299 if (*args[2] == 0) {
Willy Tarreauc53d4222012-09-20 20:19:28 +0200300 memprintf(err, "'%s %s' in global section expects an address or a path to a UNIX socket", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200301 return -1;
302 }
303
Willy Tarreau89a63132009-08-16 17:41:45 +0200304 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200305 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200306 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreau89a63132009-08-16 17:41:45 +0200307 return -1;
308 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200309 }
310
Willy Tarreau4348fad2012-09-20 16:48:07 +0200311 bind_conf = bind_conf_alloc(&global.stats_fe->conf.bind, file, line, args[2]);
Willy Tarreau290e63a2012-09-20 18:07:14 +0200312 bind_conf->level = ACCESS_LVL_OPER; /* default access level */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200313
Willy Tarreauc53d4222012-09-20 20:19:28 +0200314 if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) {
315 memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n",
316 file, line, args[0], args[1], err && *err ? *err : "error");
317 return -1;
318 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200319
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200320 cur_arg = 3;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200321 while (*args[cur_arg]) {
Willy Tarreaud5781202012-09-22 19:32:35 +0200322 static int bind_dumped;
323 struct bind_kw *kw;
324
325 kw = bind_find_kw(args[cur_arg]);
326 if (kw) {
327 if (!kw->parse) {
328 memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).",
329 args[0], args[1], args[cur_arg]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200330 return -1;
331 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200332
Willy Tarreau061b5de2015-10-13 15:06:57 +0200333 if (kw->parse(args, cur_arg, global.stats_fe, bind_conf, err) != 0) {
Willy Tarreaud5781202012-09-22 19:32:35 +0200334 if (err && *err)
335 memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err);
336 else
337 memprintf(err, "'%s %s' : error encountered while processing '%s'",
338 args[0], args[1], args[cur_arg]);
Willy Tarreau6162db22009-10-10 17:13:00 +0200339 return -1;
340 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200341
342 cur_arg += 1 + kw->skip;
343 continue;
Willy Tarreau6162db22009-10-10 17:13:00 +0200344 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200345
346 if (!bind_dumped) {
347 bind_dump_kws(err);
348 indent_msg(err, 4);
349 bind_dumped = 1;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200350 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200351
352 memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s",
353 args[0], args[1], args[cur_arg],
354 err && *err ? " Registered keywords :" : "", err && *err ? *err : "");
355 return -1;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200356 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100357
Willy Tarreauc53d4222012-09-20 20:19:28 +0200358 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
359 l->maxconn = global.stats_fe->maxconn;
360 l->backlog = global.stats_fe->backlog;
Willy Tarreau9903f0e2015-04-04 18:50:31 +0200361 l->accept = session_accept_fd;
Willy Tarreau87b09662015-04-03 00:22:06 +0200362 l->handler = process_stream;
Willy Tarreau10b688f2015-03-13 16:43:12 +0100363 l->default_target = global.stats_fe->default_target;
Willy Tarreauc53d4222012-09-20 20:19:28 +0200364 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
365 l->nice = -64; /* we want to boost priority for local stats */
366 global.maxsock += l->maxconn;
367 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200368 }
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200369 else if (!strcmp(args[1], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100370 unsigned timeout;
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200371 const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS);
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100372
373 if (res) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200374 memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res);
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100375 return -1;
376 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200377
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100378 if (!timeout) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200379 memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200380 return -1;
381 }
Willy Tarreau07e9e642010-08-17 21:48:17 +0200382 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200383 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200384 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200385 return -1;
386 }
387 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200388 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200389 }
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200390 else if (!strcmp(args[1], "maxconn")) {
391 int maxconn = atol(args[2]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200392
393 if (maxconn <= 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200394 memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200395 return -1;
396 }
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200397
398 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200399 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200400 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200401 return -1;
402 }
403 }
404 global.stats_fe->maxconn = maxconn;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200405 }
Willy Tarreau35b7b162012-10-22 23:17:18 +0200406 else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */
407 int cur_arg = 2;
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100408 unsigned long set = 0;
Willy Tarreau35b7b162012-10-22 23:17:18 +0200409
Willy Tarreau91319572013-04-20 09:48:50 +0200410 if (!global.stats_fe) {
411 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
412 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
413 return -1;
414 }
415 }
416
Willy Tarreau35b7b162012-10-22 23:17:18 +0200417 while (*args[cur_arg]) {
Willy Tarreau110ecc12012-11-15 17:50:01 +0100418 unsigned int low, high;
419
Willy Tarreau35b7b162012-10-22 23:17:18 +0200420 if (strcmp(args[cur_arg], "all") == 0) {
421 set = 0;
422 break;
423 }
424 else if (strcmp(args[cur_arg], "odd") == 0) {
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100425 set |= ~0UL/3UL; /* 0x555....555 */
Willy Tarreau35b7b162012-10-22 23:17:18 +0200426 }
427 else if (strcmp(args[cur_arg], "even") == 0) {
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100428 set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */
Willy Tarreau35b7b162012-10-22 23:17:18 +0200429 }
Willy Tarreau83d84cf2012-11-22 01:04:31 +0100430 else if (isdigit((int)*args[cur_arg])) {
Willy Tarreau110ecc12012-11-15 17:50:01 +0100431 char *dash = strchr(args[cur_arg], '-');
432
433 low = high = str2uic(args[cur_arg]);
434 if (dash)
435 high = str2uic(dash + 1);
436
437 if (high < low) {
438 unsigned int swap = low;
439 low = high;
440 high = swap;
441 }
442
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100443 if (low < 1 || high > LONGBITS) {
444 memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n",
445 args[0], args[1], LONGBITS);
Willy Tarreau35b7b162012-10-22 23:17:18 +0200446 return -1;
447 }
Willy Tarreau110ecc12012-11-15 17:50:01 +0100448 while (low <= high)
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100449 set |= 1UL << (low++ - 1);
Willy Tarreau110ecc12012-11-15 17:50:01 +0100450 }
451 else {
452 memprintf(err,
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100453 "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n",
454 args[0], args[1], LONGBITS);
Willy Tarreau110ecc12012-11-15 17:50:01 +0100455 return -1;
Willy Tarreau35b7b162012-10-22 23:17:18 +0200456 }
457 cur_arg++;
458 }
459 global.stats_fe->bind_proc = set;
460 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200461 else {
Willy Tarreau35b7b162012-10-22 23:17:18 +0200462 memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200463 return -1;
464 }
465 return 0;
466}
467
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100468/* Dumps the stats CSV header to the trash buffer which. The caller is responsible
469 * for clearing it if needed.
Willy Tarreauf522f3d2014-02-10 22:22:49 +0100470 * NOTE: Some tools happen to rely on the field position instead of its name,
471 * so please only append new fields at the end, never in the middle.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100472 */
473static void stats_dump_csv_header()
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100474{
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100475 chunk_appendf(&trash,
476 "# pxname,svname,"
477 "qcur,qmax,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +0100478 "scur,smax,slim,stot,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100479 "bin,bout,"
480 "dreq,dresp,"
481 "ereq,econ,eresp,"
482 "wretr,wredis,"
483 "status,weight,act,bck,"
484 "chkfail,chkdown,lastchg,downtime,qlimit,"
485 "pid,iid,sid,throttle,lbtot,tracked,type,"
486 "rate,rate_lim,rate_max,"
487 "check_status,check_code,check_duration,"
488 "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,"
489 "req_rate,req_rate_max,req_tot,"
490 "cli_abrt,srv_abrt,"
Willy Tarreauf5b1cc32014-06-17 12:20:59 +0200491 "comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100492 "\n");
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100493}
494
Simon Hormand9366582011-06-15 15:18:45 +0900495/* print a string of text buffer to <out>. The format is :
496 * Non-printable chars \t, \n, \r and \e are * encoded in C format.
497 * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped.
498 * Print stopped if null char or <bsize> is reached, or if no more place in the chunk.
499 */
500static int dump_text(struct chunk *out, const char *buf, int bsize)
501{
502 unsigned char c;
503 int ptr = 0;
504
505 while (buf[ptr] && ptr < bsize) {
506 c = buf[ptr];
507 if (isprint(c) && isascii(c) && c != '\\' && c != ' ') {
508 if (out->len > out->size - 1)
509 break;
510 out->str[out->len++] = c;
511 }
512 else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') {
513 if (out->len > out->size - 2)
514 break;
515 out->str[out->len++] = '\\';
516 switch (c) {
517 case ' ': c = ' '; break;
518 case '\t': c = 't'; break;
519 case '\n': c = 'n'; break;
520 case '\r': c = 'r'; break;
521 case '\e': c = 'e'; break;
522 case '\\': c = '\\'; break;
523 }
524 out->str[out->len++] = c;
525 }
526 else {
527 if (out->len > out->size - 4)
528 break;
529 out->str[out->len++] = '\\';
530 out->str[out->len++] = 'x';
531 out->str[out->len++] = hextab[(c >> 4) & 0xF];
532 out->str[out->len++] = hextab[c & 0xF];
533 }
534 ptr++;
535 }
536
537 return ptr;
538}
539
540/* print a buffer in hexa.
541 * Print stopped if <bsize> is reached, or if no more place in the chunk.
542 */
543static int dump_binary(struct chunk *out, const char *buf, int bsize)
544{
545 unsigned char c;
546 int ptr = 0;
547
548 while (ptr < bsize) {
549 c = buf[ptr];
550
551 if (out->len > out->size - 2)
552 break;
553 out->str[out->len++] = hextab[(c >> 4) & 0xF];
554 out->str[out->len++] = hextab[c & 0xF];
555
556 ptr++;
557 }
558 return ptr;
559}
560
561/* Dump the status of a table to a stream interface's
562 * read buffer. It returns 0 if the output buffer is full
563 * and needs to be called again, otherwise non-zero.
564 */
565static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si,
566 struct proxy *proxy, struct proxy *target)
567{
Willy Tarreau87b09662015-04-03 00:22:06 +0200568 struct stream *s = si_strm(si);
Simon Hormand9366582011-06-15 15:18:45 +0900569
Willy Tarreau77804732012-10-29 16:14:26 +0100570 chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n",
Simon Hormand9366582011-06-15 15:18:45 +0900571 proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current);
572
573 /* any other information should be dumped here */
574
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200575 if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER)
Willy Tarreau77804732012-10-29 16:14:26 +0100576 chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n");
Simon Hormand9366582011-06-15 15:18:45 +0900577
Willy Tarreaubc18da12015-03-13 14:00:47 +0100578 if (bi_putchk(si_ic(si), msg) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +0200579 si_applet_cant_put(si);
Simon Hormand9366582011-06-15 15:18:45 +0900580 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +0100581 }
Simon Hormand9366582011-06-15 15:18:45 +0900582
583 return 1;
584}
585
586/* Dump the a table entry to a stream interface's
587 * read buffer. It returns 0 if the output buffer is full
588 * and needs to be called again, otherwise non-zero.
589 */
590static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si,
591 struct proxy *proxy, struct stksess *entry)
592{
593 int dt;
594
Willy Tarreau77804732012-10-29 16:14:26 +0100595 chunk_appendf(msg, "%p:", entry);
Simon Hormand9366582011-06-15 15:18:45 +0900596
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200597 if (proxy->table.type == SMP_T_IPV4) {
Simon Hormand9366582011-06-15 15:18:45 +0900598 char addr[INET_ADDRSTRLEN];
599 inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr));
Willy Tarreau77804732012-10-29 16:14:26 +0100600 chunk_appendf(msg, " key=%s", addr);
Simon Hormand9366582011-06-15 15:18:45 +0900601 }
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200602 else if (proxy->table.type == SMP_T_IPV6) {
Simon Hormand9366582011-06-15 15:18:45 +0900603 char addr[INET6_ADDRSTRLEN];
604 inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr));
Willy Tarreau77804732012-10-29 16:14:26 +0100605 chunk_appendf(msg, " key=%s", addr);
Simon Hormand9366582011-06-15 15:18:45 +0900606 }
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200607 else if (proxy->table.type == SMP_T_SINT) {
Willy Tarreau77804732012-10-29 16:14:26 +0100608 chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key);
Simon Hormand9366582011-06-15 15:18:45 +0900609 }
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200610 else if (proxy->table.type == SMP_T_STR) {
Willy Tarreau77804732012-10-29 16:14:26 +0100611 chunk_appendf(msg, " key=");
Simon Hormand9366582011-06-15 15:18:45 +0900612 dump_text(msg, (const char *)entry->key.key, proxy->table.key_size);
613 }
614 else {
Willy Tarreau77804732012-10-29 16:14:26 +0100615 chunk_appendf(msg, " key=");
Simon Hormand9366582011-06-15 15:18:45 +0900616 dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size);
617 }
618
Willy Tarreau77804732012-10-29 16:14:26 +0100619 chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire));
Simon Hormand9366582011-06-15 15:18:45 +0900620
621 for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) {
622 void *ptr;
623
624 if (proxy->table.data_ofs[dt] == 0)
625 continue;
626 if (stktable_data_types[dt].arg_type == ARG_T_DELAY)
Willy Tarreau77804732012-10-29 16:14:26 +0100627 chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u);
Simon Hormand9366582011-06-15 15:18:45 +0900628 else
Willy Tarreau77804732012-10-29 16:14:26 +0100629 chunk_appendf(msg, " %s=", stktable_data_types[dt].name);
Simon Hormand9366582011-06-15 15:18:45 +0900630
631 ptr = stktable_data_ptr(&proxy->table, entry, dt);
632 switch (stktable_data_types[dt].std_type) {
633 case STD_T_SINT:
Willy Tarreau77804732012-10-29 16:14:26 +0100634 chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint));
Simon Hormand9366582011-06-15 15:18:45 +0900635 break;
636 case STD_T_UINT:
Willy Tarreau77804732012-10-29 16:14:26 +0100637 chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint));
Simon Hormand9366582011-06-15 15:18:45 +0900638 break;
639 case STD_T_ULL:
Willy Tarreau77804732012-10-29 16:14:26 +0100640 chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull));
Simon Hormand9366582011-06-15 15:18:45 +0900641 break;
642 case STD_T_FRQP:
Willy Tarreau77804732012-10-29 16:14:26 +0100643 chunk_appendf(msg, "%d",
Simon Hormand9366582011-06-15 15:18:45 +0900644 read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
645 proxy->table.data_arg[dt].u));
646 break;
647 }
648 }
Willy Tarreau77804732012-10-29 16:14:26 +0100649 chunk_appendf(msg, "\n");
Simon Hormand9366582011-06-15 15:18:45 +0900650
Willy Tarreaubc18da12015-03-13 14:00:47 +0100651 if (bi_putchk(si_ic(si), msg) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +0200652 si_applet_cant_put(si);
Simon Hormand9366582011-06-15 15:18:45 +0900653 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +0100654 }
Simon Hormand9366582011-06-15 15:18:45 +0900655
656 return 1;
657}
658
Willy Tarreaudec98142012-06-06 23:37:08 +0200659static void stats_sock_table_key_request(struct stream_interface *si, char **args, int action)
Simon Horman121f3052011-06-15 15:18:46 +0900660{
Willy Tarreau87b09662015-04-03 00:22:06 +0200661 struct stream *s = si_strm(si);
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100662 struct appctx *appctx = __objt_appctx(si->end);
663 struct proxy *px = appctx->ctx.table.target;
Simon Horman121f3052011-06-15 15:18:46 +0900664 struct stksess *ts;
Simon Hormancec9a222011-06-15 15:18:51 +0900665 uint32_t uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900666 unsigned char ip6_key[sizeof(struct in6_addr)];
Willy Tarreau654694e2012-06-07 01:03:16 +0200667 long long value;
668 int data_type;
Willy Tarreau47060b62013-08-01 21:11:42 +0200669 int cur_arg;
Willy Tarreau654694e2012-06-07 01:03:16 +0200670 void *ptr;
671 struct freq_ctr_period *frqp;
Simon Horman121f3052011-06-15 15:18:46 +0900672
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100673 appctx->st0 = STAT_CLI_OUTPUT;
Simon Horman121f3052011-06-15 15:18:46 +0900674
675 if (!*args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100676 appctx->ctx.cli.msg = "Key value expected\n";
677 appctx->st0 = STAT_CLI_PRINT;
Simon Horman121f3052011-06-15 15:18:46 +0900678 return;
679 }
680
Simon Hormanc5b89f62011-06-15 15:18:50 +0900681 switch (px->table.type) {
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200682 case SMP_T_IPV4:
Simon Hormancec9a222011-06-15 15:18:51 +0900683 uint32_key = htonl(inetaddr_host(args[4]));
Willy Tarreau07115412012-10-29 21:56:59 +0100684 static_table_key->key = &uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900685 break;
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200686 case SMP_T_IPV6:
Simon Hormanc5b89f62011-06-15 15:18:50 +0900687 inet_pton(AF_INET6, args[4], ip6_key);
Willy Tarreau07115412012-10-29 21:56:59 +0100688 static_table_key->key = &ip6_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900689 break;
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200690 case SMP_T_SINT:
Simon Hormancec9a222011-06-15 15:18:51 +0900691 {
692 char *endptr;
693 unsigned long val;
694 errno = 0;
695 val = strtoul(args[4], &endptr, 10);
696 if ((errno == ERANGE && val == ULONG_MAX) ||
697 (errno != 0 && val == 0) || endptr == args[4] ||
698 val > 0xffffffff) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100699 appctx->ctx.cli.msg = "Invalid key\n";
700 appctx->st0 = STAT_CLI_PRINT;
Simon Hormancec9a222011-06-15 15:18:51 +0900701 return;
702 }
703 uint32_key = (uint32_t) val;
Willy Tarreau07115412012-10-29 21:56:59 +0100704 static_table_key->key = &uint32_key;
Simon Hormancec9a222011-06-15 15:18:51 +0900705 break;
706 }
707 break;
Thierry FOURNIER5d24ebc2015-07-24 08:46:42 +0200708 case SMP_T_STR:
Willy Tarreau07115412012-10-29 21:56:59 +0100709 static_table_key->key = args[4];
710 static_table_key->key_len = strlen(args[4]);
Simon Horman619e3cc2011-06-15 15:18:52 +0900711 break;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900712 default:
Willy Tarreaudec98142012-06-06 23:37:08 +0200713 switch (action) {
714 case STAT_CLI_O_TAB:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100715 appctx->ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200716 break;
717 case STAT_CLI_O_CLR:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100718 appctx->ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6, string and integer is not supported\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200719 break;
720 default:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100721 appctx->ctx.cli.msg = "Unknown action\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200722 break;
723 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100724 appctx->st0 = STAT_CLI_PRINT;
Simon Horman121f3052011-06-15 15:18:46 +0900725 return;
726 }
727
728 /* check permissions */
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200729 if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100730 appctx->ctx.cli.msg = stats_permission_denied_msg;
731 appctx->st0 = STAT_CLI_PRINT;
Simon Horman121f3052011-06-15 15:18:46 +0900732 return;
733 }
734
Willy Tarreau07115412012-10-29 21:56:59 +0100735 ts = stktable_lookup_key(&px->table, static_table_key);
Simon Horman17bce342011-06-15 15:18:47 +0900736
Willy Tarreaudec98142012-06-06 23:37:08 +0200737 switch (action) {
738 case STAT_CLI_O_TAB:
739 if (!ts)
740 return;
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100741 chunk_reset(&trash);
742 if (!stats_dump_table_head_to_buffer(&trash, si, px, px))
Simon Horman17bce342011-06-15 15:18:47 +0900743 return;
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100744 stats_dump_table_entry_to_buffer(&trash, si, px, ts);
Simon Horman121f3052011-06-15 15:18:46 +0900745 return;
Willy Tarreaudec98142012-06-06 23:37:08 +0200746
747 case STAT_CLI_O_CLR:
748 if (!ts)
749 return;
750 if (ts->ref_cnt) {
751 /* don't delete an entry which is currently referenced */
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100752 appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n";
753 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaudec98142012-06-06 23:37:08 +0200754 return;
755 }
756 stksess_kill(&px->table, ts);
757 break;
Simon Horman17bce342011-06-15 15:18:47 +0900758
Willy Tarreau654694e2012-06-07 01:03:16 +0200759 case STAT_CLI_O_SET:
Willy Tarreau654694e2012-06-07 01:03:16 +0200760 if (ts)
761 stktable_touch(&px->table, ts, 1);
762 else {
Willy Tarreau07115412012-10-29 21:56:59 +0100763 ts = stksess_new(&px->table, static_table_key);
Willy Tarreau654694e2012-06-07 01:03:16 +0200764 if (!ts) {
765 /* don't delete an entry which is currently referenced */
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100766 appctx->ctx.cli.msg = "Unable to allocate a new entry\n";
767 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau654694e2012-06-07 01:03:16 +0200768 return;
769 }
770 stktable_store(&px->table, ts, 1);
771 }
772
Willy Tarreau47060b62013-08-01 21:11:42 +0200773 for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) {
774 if (strncmp(args[cur_arg], "data.", 5) != 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100775 appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n";
776 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau47060b62013-08-01 21:11:42 +0200777 return;
778 }
779
780 data_type = stktable_get_data_type(args[cur_arg] + 5);
781 if (data_type < 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100782 appctx->ctx.cli.msg = "Unknown data type\n";
783 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau47060b62013-08-01 21:11:42 +0200784 return;
785 }
786
787 if (!px->table.data_ofs[data_type]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100788 appctx->ctx.cli.msg = "Data type not stored in this table\n";
789 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau47060b62013-08-01 21:11:42 +0200790 return;
791 }
792
793 if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100794 appctx->ctx.cli.msg = "Require a valid integer value to store\n";
795 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau47060b62013-08-01 21:11:42 +0200796 return;
797 }
798
799 ptr = stktable_data_ptr(&px->table, ts, data_type);
800
801 switch (stktable_data_types[data_type].std_type) {
802 case STD_T_SINT:
803 stktable_data_cast(ptr, std_t_sint) = value;
804 break;
805 case STD_T_UINT:
806 stktable_data_cast(ptr, std_t_uint) = value;
807 break;
808 case STD_T_ULL:
809 stktable_data_cast(ptr, std_t_ull) = value;
810 break;
811 case STD_T_FRQP:
812 /* We set both the current and previous values. That way
813 * the reported frequency is stable during all the period
814 * then slowly fades out. This allows external tools to
815 * push measures without having to update them too often.
816 */
817 frqp = &stktable_data_cast(ptr, std_t_frqp);
818 frqp->curr_tick = now_ms;
819 frqp->prev_ctr = 0;
820 frqp->curr_ctr = value;
821 break;
822 }
Willy Tarreau654694e2012-06-07 01:03:16 +0200823 }
824 break;
825
Willy Tarreaudec98142012-06-06 23:37:08 +0200826 default:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100827 appctx->ctx.cli.msg = "Unknown action\n";
828 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaudec98142012-06-06 23:37:08 +0200829 break;
Simon Horman121f3052011-06-15 15:18:46 +0900830 }
Simon Horman121f3052011-06-15 15:18:46 +0900831}
832
Willy Tarreau654694e2012-06-07 01:03:16 +0200833static void stats_sock_table_data_request(struct stream_interface *si, char **args, int action)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900834{
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100835 struct appctx *appctx = __objt_appctx(si->end);
836
Willy Tarreau04b3a192013-04-13 09:41:37 +0200837 if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100838 appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions";
839 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau654694e2012-06-07 01:03:16 +0200840 return;
841 }
842
Simon Hormand5b9fd92011-06-15 15:18:48 +0900843 /* condition on stored data value */
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100844 appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5);
845 if (appctx->ctx.table.data_type < 0) {
846 appctx->ctx.cli.msg = "Unknown data type\n";
847 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900848 return;
849 }
850
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100851 if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) {
852 appctx->ctx.cli.msg = "Data type not stored in this table\n";
853 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900854 return;
855 }
856
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100857 appctx->ctx.table.data_op = get_std_op(args[4]);
858 if (appctx->ctx.table.data_op < 0) {
859 appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n";
860 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900861 return;
862 }
863
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100864 if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) {
865 appctx->ctx.cli.msg = "Require a valid integer value to compare against\n";
866 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900867 return;
868 }
869}
870
Willy Tarreaudec98142012-06-06 23:37:08 +0200871static void stats_sock_table_request(struct stream_interface *si, char **args, int action)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900872{
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100873 struct appctx *appctx = __objt_appctx(si->end);
874
875 appctx->ctx.table.data_type = -1;
876 appctx->st2 = STAT_ST_INIT;
877 appctx->ctx.table.target = NULL;
878 appctx->ctx.table.proxy = NULL;
879 appctx->ctx.table.entry = NULL;
880 appctx->st0 = action;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900881
882 if (*args[2]) {
Willy Tarreaue2dc1fa2015-05-26 12:08:07 +0200883 appctx->ctx.table.target = proxy_tbl_by_name(args[2]);
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100884 if (!appctx->ctx.table.target) {
885 appctx->ctx.cli.msg = "No such table\n";
886 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900887 return;
888 }
889 }
890 else {
Willy Tarreaudec98142012-06-06 23:37:08 +0200891 if (action != STAT_CLI_O_TAB)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900892 goto err_args;
893 return;
894 }
895
896 if (strcmp(args[3], "key") == 0)
Willy Tarreaudec98142012-06-06 23:37:08 +0200897 stats_sock_table_key_request(si, args, action);
Simon Hormanc88b8872011-06-15 15:18:49 +0900898 else if (strncmp(args[3], "data.", 5) == 0)
Willy Tarreau654694e2012-06-07 01:03:16 +0200899 stats_sock_table_data_request(si, args, action);
Simon Hormanc88b8872011-06-15 15:18:49 +0900900 else if (*args[3])
Simon Hormand5b9fd92011-06-15 15:18:48 +0900901 goto err_args;
902
903 return;
904
905err_args:
Willy Tarreaudec98142012-06-06 23:37:08 +0200906 switch (action) {
907 case STAT_CLI_O_TAB:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100908 appctx->ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200909 break;
910 case STAT_CLI_O_CLR:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100911 appctx->ctx.cli.msg = "Required arguments: <table> \"data.<store_data_type>\" <operator> <value> or <table> key <key>\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200912 break;
913 default:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100914 appctx->ctx.cli.msg = "Unknown action\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200915 break;
916 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100917 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900918}
919
Willy Tarreau532a4502011-09-07 22:37:44 +0200920/* Expects to find a frontend named <arg> and returns it, otherwise displays various
Willy Tarreau87b09662015-04-03 00:22:06 +0200921 * adequate error messages and returns NULL. This function also expects the stream
Willy Tarreau532a4502011-09-07 22:37:44 +0200922 * level to be admin.
923 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200924static struct proxy *expect_frontend_admin(struct stream *s, struct stream_interface *si, const char *arg)
Willy Tarreau532a4502011-09-07 22:37:44 +0200925{
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100926 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau532a4502011-09-07 22:37:44 +0200927 struct proxy *px;
928
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200929 if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100930 appctx->ctx.cli.msg = stats_permission_denied_msg;
931 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +0200932 return NULL;
933 }
934
935 if (!*arg) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100936 appctx->ctx.cli.msg = "A frontend name is expected.\n";
937 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +0200938 return NULL;
939 }
940
Willy Tarreau9e0bb102015-05-26 11:24:42 +0200941 px = proxy_fe_by_name(arg);
Willy Tarreau532a4502011-09-07 22:37:44 +0200942 if (!px) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100943 appctx->ctx.cli.msg = "No such frontend.\n";
944 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +0200945 return NULL;
946 }
947 return px;
948}
949
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200950/* Expects to find a backend and a server in <arg> under the form <backend>/<server>,
951 * and returns the pointer to the server. Otherwise, display adequate error messages
Willy Tarreau87b09662015-04-03 00:22:06 +0200952 * and returns NULL. This function also expects the stream level to be admin. Note:
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200953 * the <arg> is modified to remove the '/'.
954 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200955static struct server *expect_server_admin(struct stream *s, struct stream_interface *si, char *arg)
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200956{
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100957 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200958 struct proxy *px;
959 struct server *sv;
960 char *line;
961
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200962 if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100963 appctx->ctx.cli.msg = stats_permission_denied_msg;
964 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200965 return NULL;
966 }
967
968 /* split "backend/server" and make <line> point to server */
969 for (line = arg; *line; line++)
970 if (*line == '/') {
971 *line++ = '\0';
972 break;
973 }
974
975 if (!*line || !*arg) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100976 appctx->ctx.cli.msg = "Require 'backend/server'.\n";
977 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200978 return NULL;
979 }
980
981 if (!get_backend_server(arg, line, &px, &sv)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100982 appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
983 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200984 return NULL;
985 }
986
987 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100988 appctx->ctx.cli.msg = "Proxy is disabled.\n";
989 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200990 return NULL;
991 }
992
993 return sv;
994}
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +0200995
996/* This function is used with TLS ticket keys management. It permits to browse
997 * each reference. The variable <getnext> must contain the current node,
998 * <end> point to the root node.
999 */
1000#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
1001static inline
1002struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end)
1003{
1004 struct tls_keys_ref *ref = getnext;
1005
1006 while (1) {
1007
1008 /* Get next list entry. */
1009 ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list);
1010
1011 /* If the entry is the last of the list, return NULL. */
1012 if (&ref->list == end)
1013 return NULL;
1014
1015 return ref;
1016 }
1017}
1018
1019static inline
1020struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference)
1021{
1022 int id;
1023 char *error;
1024
1025 /* If the reference starts by a '#', this is numeric id. */
1026 if (reference[0] == '#') {
1027 /* Try to convert the numeric id. If the conversion fails, the lookup fails. */
1028 id = strtol(reference + 1, &error, 10);
1029 if (*error != '\0')
1030 return NULL;
1031
1032 /* Perform the unique id lookup. */
1033 return tlskeys_ref_lookupid(id);
1034 }
1035
1036 /* Perform the string lookup. */
1037 return tlskeys_ref_lookup(reference);
1038}
1039#endif
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001040
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001041/* This function is used with map and acl management. It permits to browse
1042 * each reference. The variable <getnext> must contain the current node,
1043 * <end> point to the root node and the <flags> permit to filter required
1044 * nodes.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001045 */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001046static inline
1047struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end,
1048 unsigned int flags)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001049{
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001050 struct pat_ref *ref = getnext;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001051
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001052 while (1) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001053
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001054 /* Get next list entry. */
1055 ref = LIST_NEXT(&ref->list, struct pat_ref *, list);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001056
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001057 /* If the entry is the last of the list, return NULL. */
1058 if (&ref->list == end)
1059 return NULL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001060
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001061 /* If the entry match the flag, return it. */
1062 if (ref->flags & flags)
1063 return ref;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001064 }
1065}
1066
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001067static inline
1068struct pat_ref *pat_ref_lookup_ref(const char *reference)
1069{
1070 int id;
1071 char *error;
1072
1073 /* If the reference starts by a '#', this is numeric id. */
1074 if (reference[0] == '#') {
1075 /* Try to convert the numeric id. If the conversion fails, the lookup fails. */
1076 id = strtol(reference + 1, &error, 10);
1077 if (*error != '\0')
1078 return NULL;
1079
1080 /* Perform the unique id lookup. */
1081 return pat_ref_lookupid(id);
1082 }
1083
1084 /* Perform the string lookup. */
1085 return pat_ref_lookup(reference);
1086}
1087
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001088/* This function is used with map and acl management. It permits to browse
1089 * each reference.
1090 */
1091static inline
1092struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end)
1093{
1094 struct pattern_expr *expr;
Thierry FOURNIERc5959fd2014-01-20 14:29:33 +01001095 expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list);
1096 if (&expr->list == end)
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001097 return NULL;
1098 return expr;
1099}
1100
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001101/* Processes the stats interpreter on the statistics socket. This function is
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001102 * called from an applet running in a stream interface. The function returns 1
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001103 * if the request was understood, otherwise zero. It sets appctx->st0 to a value
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001104 * designating the function which will have to process the request, which can
1105 * also be the print function to display the return message set into cli.msg.
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001106 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001107static int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001108{
Willy Tarreau87b09662015-04-03 00:22:06 +02001109 struct stream *s = si_strm(si);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001110 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001111 char *args[MAX_STATS_ARGS + 1];
1112 int arg;
Thierry FOURNIER48bcfda2013-12-10 18:54:58 +01001113 int i, j;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001114
1115 while (isspace((unsigned char)*line))
1116 line++;
1117
1118 arg = 0;
1119 args[arg] = line;
1120
1121 while (*line && arg < MAX_STATS_ARGS) {
Thierry FOURNIER48bcfda2013-12-10 18:54:58 +01001122 if (*line == '\\') {
1123 line++;
1124 if (*line == '\0')
1125 break;
1126 }
1127 else if (isspace((unsigned char)*line)) {
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001128 *line++ = '\0';
1129
1130 while (isspace((unsigned char)*line))
1131 line++;
1132
1133 args[++arg] = line;
1134 continue;
1135 }
1136
1137 line++;
1138 }
1139
1140 while (++arg <= MAX_STATS_ARGS)
1141 args[arg] = line;
1142
Thierry FOURNIER48bcfda2013-12-10 18:54:58 +01001143 /* remove \ */
1144 arg = 0;
1145 while (*args[arg] != '\0') {
1146 j = 0;
1147 for (i=0; args[arg][i] != '\0'; i++) {
1148 if (args[arg][i] == '\\')
1149 continue;
1150 args[arg][j] = args[arg][i];
1151 j++;
1152 }
1153 args[arg][j] = '\0';
1154 arg++;
1155 }
1156
Willy Tarreau6bcb95d2015-05-04 18:07:56 +02001157 appctx->ctx.stats.scope_str = 0;
1158 appctx->ctx.stats.scope_len = 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001159 appctx->ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001160 if (strcmp(args[0], "show") == 0) {
Baptiste Assmann9b6857e2015-09-18 14:49:12 +02001161 if (strcmp(args[1], "backend") == 0) {
1162 appctx->st2 = STAT_ST_INIT;
1163 appctx->st0 = STAT_CLI_O_BACKEND;
1164 }
1165 else if (strcmp(args[1], "stat") == 0) {
Baptiste Assmann3863f972015-05-17 00:33:24 +02001166 if (strcmp(args[2], "resolvers") == 0) {
1167 struct dns_resolvers *presolvers;
1168
Andrew Hayworth68d05342015-10-02 20:33:01 +00001169 if (*args[3]) {
1170 appctx->ctx.resolvers.ptr = NULL;
1171 list_for_each_entry(presolvers, &dns_resolvers, list) {
1172 if (strcmp(presolvers->id, args[3]) == 0) {
1173 appctx->ctx.resolvers.ptr = presolvers;
1174 break;
1175 }
Baptiste Assmann3863f972015-05-17 00:33:24 +02001176 }
Andrew Hayworth68d05342015-10-02 20:33:01 +00001177 if (appctx->ctx.resolvers.ptr == NULL) {
1178 appctx->ctx.cli.msg = "Can't find that resolvers section\n";
1179 appctx->st0 = STAT_CLI_PRINT;
1180 return 1;
1181 }
Baptiste Assmann3863f972015-05-17 00:33:24 +02001182 }
1183
1184 appctx->st2 = STAT_ST_INIT;
1185 appctx->st0 = STAT_CLI_O_RESOLVERS;
1186 return 1;
1187 }
1188 else if (*args[2] && *args[3] && *args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001189 appctx->ctx.stats.flags |= STAT_BOUND;
1190 appctx->ctx.stats.iid = atoi(args[2]);
1191 appctx->ctx.stats.type = atoi(args[3]);
1192 appctx->ctx.stats.sid = atoi(args[4]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001193 }
1194
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001195 appctx->st2 = STAT_ST_INIT;
1196 appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001197 }
1198 else if (strcmp(args[1], "info") == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001199 appctx->st2 = STAT_ST_INIT;
1200 appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001201 }
Baptiste Assmann28289462015-07-03 08:01:20 +02001202 else if (strcmp(args[1], "servers") == 0 && strcmp(args[2], "state") == 0) {
1203 appctx->ctx.server_state.backend = NULL;
1204
1205 /* check if a backend name has been provided */
1206 if (*args[3]) {
1207 /* read server state from local file */
1208 appctx->ctx.server_state.backend = proxy_be_by_name(args[3]);
1209
1210 if (appctx->ctx.server_state.backend == NULL) {
1211 appctx->ctx.cli.msg = "Can't find backend.\n";
1212 appctx->st0 = STAT_CLI_PRINT;
1213 return 1;
1214 }
1215 }
1216 appctx->st2 = STAT_ST_INIT;
1217 appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer
1218 return 1;
1219 }
Willy Tarreau12833bb2014-01-28 16:49:56 +01001220 else if (strcmp(args[1], "pools") == 0) {
1221 appctx->st2 = STAT_ST_INIT;
1222 appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer
1223 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001224 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001225 appctx->st2 = STAT_ST_INIT;
Willy Tarreaud0d8da92015-04-04 02:10:38 +02001226 if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001227 appctx->ctx.cli.msg = stats_permission_denied_msg;
1228 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +02001229 return 1;
1230 }
Willy Tarreau76153662012-11-26 01:16:39 +01001231 if (*args[2] && strcmp(args[2], "all") == 0)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001232 appctx->ctx.sess.target = (void *)-1;
Willy Tarreau76153662012-11-26 01:16:39 +01001233 else if (*args[2])
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001234 appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01001235 else
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001236 appctx->ctx.sess.target = NULL;
Willy Tarreau87b09662015-04-03 00:22:06 +02001237 appctx->ctx.sess.section = 0; /* start with stream status */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001238 appctx->ctx.sess.pos = 0;
1239 appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001240 }
1241 else if (strcmp(args[1], "errors") == 0) {
Willy Tarreaud0d8da92015-04-04 02:10:38 +02001242 if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001243 appctx->ctx.cli.msg = stats_permission_denied_msg;
1244 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +02001245 return 1;
1246 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001247 if (*args[2])
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001248 appctx->ctx.errors.iid = atoi(args[2]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001249 else
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001250 appctx->ctx.errors.iid = -1;
1251 appctx->ctx.errors.px = NULL;
1252 appctx->st2 = STAT_ST_INIT;
1253 appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001254 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02001255 else if (strcmp(args[1], "table") == 0) {
Willy Tarreaudec98142012-06-06 23:37:08 +02001256 stats_sock_table_request(si, args, STAT_CLI_O_TAB);
Willy Tarreau69f58c82010-07-12 17:55:33 +02001257 }
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +02001258 else if (strcmp(args[1], "tls-keys") == 0) {
1259#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
1260 appctx->st2 = STAT_ST_INIT;
1261 appctx->st0 = STAT_CLI_O_TLSK;
1262#else
1263 appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL "
1264 "that doesn't support specifying TLS ticket keys\n";
1265 appctx->st0 = STAT_CLI_PRINT;
1266#endif
1267 return 1;
1268 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001269 else if (strcmp(args[1], "map") == 0 ||
1270 strcmp(args[1], "acl") == 0) {
1271
1272 /* Set ACL or MAP flags. */
1273 if (args[1][0] == 'm')
1274 appctx->ctx.map.display_flags = PAT_REF_MAP;
1275 else
1276 appctx->ctx.map.display_flags = PAT_REF_ACL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001277
1278 /* no parameter: display all map avalaible */
1279 if (!*args[2]) {
1280 appctx->st2 = STAT_ST_INIT;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001281 appctx->st0 = STAT_CLI_O_PATS;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001282 return 1;
1283 }
1284
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001285 /* lookup into the refs and check the map flag */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001286 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001287 if (!appctx->ctx.map.ref ||
1288 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
1289 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001290 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001291 else
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001292 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001293 appctx->st0 = STAT_CLI_PRINT;
1294 return 1;
1295 }
1296 appctx->st2 = STAT_ST_INIT;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001297 appctx->st0 = STAT_CLI_O_PAT;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001298 }
Aman Guptaceafb4a2012-04-02 18:57:54 -07001299 else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001300 return 0;
1301 }
1302 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001303 else if (strcmp(args[0], "clear") == 0) {
1304 if (strcmp(args[1], "counters") == 0) {
1305 struct proxy *px;
1306 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001307 struct listener *li;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001308 int clrall = 0;
1309
1310 if (strcmp(args[2], "all") == 0)
1311 clrall = 1;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001312
Willy Tarreau6162db22009-10-10 17:13:00 +02001313 /* check permissions */
Willy Tarreaud0d8da92015-04-04 02:10:38 +02001314 if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER ||
1315 (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001316 appctx->ctx.cli.msg = stats_permission_denied_msg;
1317 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +02001318 return 1;
1319 }
1320
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001321 for (px = proxy; px; px = px->next) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001322 if (clrall) {
1323 memset(&px->be_counters, 0, sizeof(px->be_counters));
1324 memset(&px->fe_counters, 0, sizeof(px->fe_counters));
1325 }
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001326 else {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001327 px->be_counters.conn_max = 0;
1328 px->be_counters.p.http.rps_max = 0;
1329 px->be_counters.sps_max = 0;
1330 px->be_counters.cps_max = 0;
1331 px->be_counters.nbpend_max = 0;
1332
1333 px->fe_counters.conn_max = 0;
1334 px->fe_counters.p.http.rps_max = 0;
1335 px->fe_counters.sps_max = 0;
1336 px->fe_counters.cps_max = 0;
1337 px->fe_counters.nbpend_max = 0;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001338 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001339
1340 for (sv = px->srv; sv; sv = sv->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001341 if (clrall)
1342 memset(&sv->counters, 0, sizeof(sv->counters));
1343 else {
1344 sv->counters.cur_sess_max = 0;
1345 sv->counters.nbpend_max = 0;
1346 sv->counters.sps_max = 0;
1347 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001348
Willy Tarreaua7944ad2012-09-26 21:03:11 +02001349 list_for_each_entry(li, &px->conf.listeners, by_fe)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001350 if (li->counters) {
1351 if (clrall)
1352 memset(li->counters, 0, sizeof(*li->counters));
1353 else
1354 li->counters->conn_max = 0;
1355 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001356 }
1357
Willy Tarreau81c25d02011-09-07 15:17:21 +02001358 global.cps_max = 0;
Willy Tarreau93e7c002013-10-07 18:51:07 +02001359 global.sps_max = 0;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001360 return 1;
1361 }
Willy Tarreau88ee3972010-07-13 13:48:00 +02001362 else if (strcmp(args[1], "table") == 0) {
Willy Tarreaudec98142012-06-06 23:37:08 +02001363 stats_sock_table_request(si, args, STAT_CLI_O_CLR);
Willy Tarreau88ee3972010-07-13 13:48:00 +02001364 /* end of processing */
1365 return 1;
1366 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001367 else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
1368 /* Set ACL or MAP flags. */
1369 if (args[1][0] == 'm')
1370 appctx->ctx.map.display_flags = PAT_REF_MAP;
1371 else
1372 appctx->ctx.map.display_flags = PAT_REF_ACL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001373
1374 /* no parameter */
1375 if (!*args[2]) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001376 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
1377 appctx->ctx.cli.msg = "Missing map identifier.\n";
1378 else
1379 appctx->ctx.cli.msg = "Missing ACL identifier.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001380 appctx->st0 = STAT_CLI_PRINT;
1381 return 1;
1382 }
1383
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001384 /* lookup into the refs and check the map flag */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001385 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001386 if (!appctx->ctx.map.ref ||
1387 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
1388 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001389 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001390 else
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001391 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001392 appctx->st0 = STAT_CLI_PRINT;
1393 return 1;
1394 }
1395
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001396 /* Clear all. */
1397 pat_ref_prune(appctx->ctx.map.ref);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001398
1399 /* return response */
Thierry FOURNIER07e78c52014-12-18 15:28:01 +01001400 appctx->st0 = STAT_CLI_PROMPT;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001401 return 1;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001402 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001403 else {
Willy Tarreau88ee3972010-07-13 13:48:00 +02001404 /* unknown "clear" argument */
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001405 return 0;
1406 }
1407 }
Willy Tarreau38338fa2009-10-10 18:37:29 +02001408 else if (strcmp(args[0], "get") == 0) {
1409 if (strcmp(args[1], "weight") == 0) {
1410 struct proxy *px;
1411 struct server *sv;
1412
1413 /* split "backend/server" and make <line> point to server */
1414 for (line = args[2]; *line; line++)
1415 if (*line == '/') {
1416 *line++ = '\0';
1417 break;
1418 }
1419
1420 if (!*line) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001421 appctx->ctx.cli.msg = "Require 'backend/server'.\n";
1422 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +02001423 return 1;
1424 }
1425
1426 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001427 appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
1428 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +02001429 return 1;
1430 }
1431
1432 /* return server's effective weight at the moment */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001433 snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight);
Willy Tarreaubc18da12015-03-13 14:00:47 +01001434 if (bi_putstr(si_ic(si), trash.str) == -1)
Willy Tarreaufe127932015-04-21 19:23:39 +02001435 si_applet_cant_put(si);
Willy Tarreaubc18da12015-03-13 14:00:47 +01001436
Willy Tarreau38338fa2009-10-10 18:37:29 +02001437 return 1;
1438 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001439 else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
1440 /* Set flags. */
1441 if (args[1][0] == 'm')
1442 appctx->ctx.map.display_flags = PAT_REF_MAP;
1443 else
1444 appctx->ctx.map.display_flags = PAT_REF_ACL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001445
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001446 /* No parameter. */
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001447 if (!*args[2] || !*args[3]) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001448 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
1449 appctx->ctx.cli.msg = "Missing map identifier and/or key.\n";
1450 else
1451 appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001452 appctx->st0 = STAT_CLI_PRINT;
1453 return 1;
1454 }
1455
1456 /* lookup into the maps */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001457 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001458 if (!appctx->ctx.map.ref) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001459 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001460 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001461 else
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001462 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001463 appctx->st0 = STAT_CLI_PRINT;
1464 return 1;
1465 }
1466
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001467 /* copy input string. The string must be allocated because
1468 * it may be used over multiple iterations. It's released
1469 * at the end and upon abort anyway.
1470 */
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001471 appctx->ctx.map.chunk.len = strlen(args[3]);
1472 appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1;
1473 appctx->ctx.map.chunk.str = strdup(args[3]);
1474 if (!appctx->ctx.map.chunk.str) {
1475 appctx->ctx.cli.msg = "Out of memory error.\n";
1476 appctx->st0 = STAT_CLI_PRINT;
1477 return 1;
1478 }
1479
1480 /* prepare response */
1481 appctx->st2 = STAT_ST_INIT;
1482 appctx->st0 = STAT_CLI_O_MLOOK;
1483 }
Willy Tarreau38338fa2009-10-10 18:37:29 +02001484 else { /* not "get weight" */
1485 return 0;
1486 }
1487 }
Willy Tarreau4483d432009-10-10 19:30:08 +02001488 else if (strcmp(args[0], "set") == 0) {
1489 if (strcmp(args[1], "weight") == 0) {
Willy Tarreau4483d432009-10-10 19:30:08 +02001490 struct server *sv;
Simon Horman7d09b9a2013-02-12 10:45:51 +09001491 const char *warning;
Willy Tarreau4483d432009-10-10 19:30:08 +02001492
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001493 sv = expect_server_admin(s, si, args[2]);
1494 if (!sv)
Willy Tarreau4483d432009-10-10 19:30:08 +02001495 return 1;
Willy Tarreau4483d432009-10-10 19:30:08 +02001496
Simon Horman7d09b9a2013-02-12 10:45:51 +09001497 warning = server_parse_weight_change_request(sv, args[3]);
1498 if (warning) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001499 appctx->ctx.cli.msg = warning;
1500 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001501 }
Willy Tarreau4483d432009-10-10 19:30:08 +02001502 return 1;
1503 }
Willy Tarreau2a4b70f2014-05-22 18:42:35 +02001504 else if (strcmp(args[1], "server") == 0) {
1505 struct server *sv;
1506 const char *warning;
1507
1508 sv = expect_server_admin(s, si, args[2]);
1509 if (!sv)
1510 return 1;
1511
1512 if (strcmp(args[3], "weight") == 0) {
1513 warning = server_parse_weight_change_request(sv, args[4]);
1514 if (warning) {
1515 appctx->ctx.cli.msg = warning;
1516 appctx->st0 = STAT_CLI_PRINT;
1517 }
1518 }
1519 else if (strcmp(args[3], "state") == 0) {
1520 if (strcmp(args[4], "ready") == 0)
1521 srv_adm_set_ready(sv);
1522 else if (strcmp(args[4], "drain") == 0)
1523 srv_adm_set_drain(sv);
1524 else if (strcmp(args[4], "maint") == 0)
1525 srv_adm_set_maint(sv);
1526 else {
1527 appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n";
1528 appctx->st0 = STAT_CLI_PRINT;
1529 }
1530 }
1531 else if (strcmp(args[3], "health") == 0) {
1532 if (sv->track) {
1533 appctx->ctx.cli.msg = "cannot change health on a tracking server.\n";
1534 appctx->st0 = STAT_CLI_PRINT;
1535 }
1536 else if (strcmp(args[4], "up") == 0) {
1537 sv->check.health = sv->check.rise + sv->check.fall - 1;
1538 srv_set_running(sv, "changed from CLI");
1539 }
1540 else if (strcmp(args[4], "stopping") == 0) {
1541 sv->check.health = sv->check.rise + sv->check.fall - 1;
1542 srv_set_stopping(sv, "changed from CLI");
1543 }
1544 else if (strcmp(args[4], "down") == 0) {
1545 sv->check.health = 0;
1546 srv_set_stopped(sv, "changed from CLI");
1547 }
1548 else {
1549 appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n";
1550 appctx->st0 = STAT_CLI_PRINT;
1551 }
1552 }
1553 else if (strcmp(args[3], "agent") == 0) {
1554 if (!(sv->agent.state & CHK_ST_ENABLED)) {
1555 appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n";
1556 appctx->st0 = STAT_CLI_PRINT;
1557 }
1558 else if (strcmp(args[4], "up") == 0) {
1559 sv->agent.health = sv->agent.rise + sv->agent.fall - 1;
1560 srv_set_running(sv, "changed from CLI");
1561 }
1562 else if (strcmp(args[4], "down") == 0) {
1563 sv->agent.health = 0;
1564 srv_set_stopped(sv, "changed from CLI");
1565 }
1566 else {
1567 appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n";
1568 appctx->st0 = STAT_CLI_PRINT;
1569 }
1570 }
Baptiste Assmann3d8f8312015-04-13 22:54:33 +02001571 else if (strcmp(args[3], "addr") == 0) {
1572 warning = server_parse_addr_change_request(sv, args[4]);
1573 if (warning) {
1574 appctx->ctx.cli.msg = warning;
1575 appctx->st0 = STAT_CLI_PRINT;
1576 }
1577 }
Willy Tarreau2a4b70f2014-05-22 18:42:35 +02001578 else {
Baptiste Assmann3d8f8312015-04-13 22:54:33 +02001579 appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state', 'weight' and 'addr'.\n";
Willy Tarreau2a4b70f2014-05-22 18:42:35 +02001580 appctx->st0 = STAT_CLI_PRINT;
1581 }
1582 return 1;
1583 }
Willy Tarreau7aabd112010-01-26 10:59:06 +01001584 else if (strcmp(args[1], "timeout") == 0) {
1585 if (strcmp(args[2], "cli") == 0) {
1586 unsigned timeout;
1587 const char *res;
1588
1589 if (!*args[3]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001590 appctx->ctx.cli.msg = "Expects an integer value.\n";
1591 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001592 return 1;
1593 }
1594
1595 res = parse_time_err(args[3], &timeout, TIME_UNIT_S);
1596 if (res || timeout < 1) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001597 appctx->ctx.cli.msg = "Invalid timeout value.\n";
1598 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001599 return 1;
1600 }
1601
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01001602 s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000);
Willy Tarreau7aabd112010-01-26 10:59:06 +01001603 return 1;
1604 }
1605 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001606 appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n";
1607 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001608 return 1;
1609 }
1610 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001611 else if (strcmp(args[1], "maxconn") == 0) {
1612 if (strcmp(args[2], "frontend") == 0) {
1613 struct proxy *px;
1614 struct listener *l;
1615 int v;
1616
Willy Tarreau532a4502011-09-07 22:37:44 +02001617 px = expect_frontend_admin(s, si, args[3]);
1618 if (!px)
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001619 return 1;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001620
1621 if (!*args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001622 appctx->ctx.cli.msg = "Integer value expected.\n";
1623 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001624 return 1;
1625 }
1626
1627 v = atoi(args[4]);
Willy Tarreau3c7a79d2012-09-26 21:07:15 +02001628 if (v < 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001629 appctx->ctx.cli.msg = "Value out of range.\n";
1630 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001631 return 1;
1632 }
1633
1634 /* OK, the value is fine, so we assign it to the proxy and to all of
1635 * its listeners. The blocked ones will be dequeued.
1636 */
1637 px->maxconn = v;
Willy Tarreaua7944ad2012-09-26 21:03:11 +02001638 list_for_each_entry(l, &px->conf.listeners, by_fe) {
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001639 l->maxconn = v;
1640 if (l->state == LI_FULL)
1641 resume_listener(l);
1642 }
1643
Willy Tarreaud0d8da92015-04-04 02:10:38 +02001644 if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue))
1645 dequeue_all_listeners(&strm_fe(s)->listener_queue);
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001646
1647 return 1;
1648 }
Andrew Hayworthedb93a72015-10-27 21:46:25 +00001649 else if (strcmp(args[2], "server") == 0) {
1650 struct server *sv;
1651 int v;
1652
1653 sv = expect_server_admin(s, si, args[3]);
1654 if (!sv)
1655 return 1;
1656
1657 if (!*args[4]) {
1658 appctx->ctx.cli.msg = "Integer value expected.\n";
1659 appctx->st0 = STAT_CLI_PRINT;
1660 return 1;
1661 }
1662
1663 v = atoi(args[4]);
1664 if (v < 0) {
1665 appctx->ctx.cli.msg = "Value out of range.\n";
1666 appctx->st0 = STAT_CLI_PRINT;
1667 return 1;
1668 }
1669
1670 if (sv->maxconn == sv->minconn) { // static maxconn
1671 sv->maxconn = sv->minconn = v;
1672 } else { // dynamic maxconn
1673 sv->maxconn = v;
1674 }
1675
1676 if (may_dequeue_tasks(sv, sv->proxy))
1677 process_srv_queue(sv);
1678
1679 return 1;
1680 }
Willy Tarreau91886b62011-09-07 14:38:31 +02001681 else if (strcmp(args[2], "global") == 0) {
1682 int v;
1683
Willy Tarreaud0d8da92015-04-04 02:10:38 +02001684 if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001685 appctx->ctx.cli.msg = stats_permission_denied_msg;
1686 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau91886b62011-09-07 14:38:31 +02001687 return 1;
1688 }
1689
1690 if (!*args[3]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001691 appctx->ctx.cli.msg = "Expects an integer value.\n";
1692 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau91886b62011-09-07 14:38:31 +02001693 return 1;
1694 }
1695
1696 v = atoi(args[3]);
1697 if (v > global.hardmaxconn) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001698 appctx->ctx.cli.msg = "Value out of range.\n";
1699 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau91886b62011-09-07 14:38:31 +02001700 return 1;
1701 }
1702
1703 /* check for unlimited values */
1704 if (v <= 0)
1705 v = global.hardmaxconn;
1706
1707 global.maxconn = v;
1708
1709 /* Dequeues all of the listeners waiting for a resource */
1710 if (!LIST_ISEMPTY(&global_listener_queue))
1711 dequeue_all_listeners(&global_listener_queue);
1712
1713 return 1;
1714 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001715 else {
Andrew Hayworthedb93a72015-10-27 21:46:25 +00001716 appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend', 'server', and 'global'.\n";
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001717 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001718 return 1;
1719 }
1720 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001721 else if (strcmp(args[1], "rate-limit") == 0) {
1722 if (strcmp(args[2], "connections") == 0) {
1723 if (strcmp(args[3], "global") == 0) {
1724 int v;
1725
Willy Tarreaud0d8da92015-04-04 02:10:38 +02001726 if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001727 appctx->ctx.cli.msg = stats_permission_denied_msg;
1728 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001729 return 1;
1730 }
1731
1732 if (!*args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001733 appctx->ctx.cli.msg = "Expects an integer value.\n";
1734 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001735 return 1;
1736 }
1737
1738 v = atoi(args[4]);
1739 if (v < 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001740 appctx->ctx.cli.msg = "Value out of range.\n";
1741 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001742 return 1;
1743 }
1744
1745 global.cps_lim = v;
1746
1747 /* Dequeues all of the listeners waiting for a resource */
1748 if (!LIST_ISEMPTY(&global_listener_queue))
1749 dequeue_all_listeners(&global_listener_queue);
1750
1751 return 1;
1752 }
1753 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001754 appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n";
1755 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001756 return 1;
1757 }
1758 }
Willy Tarreau93e7c002013-10-07 18:51:07 +02001759 else if (strcmp(args[2], "sessions") == 0) {
1760 if (strcmp(args[3], "global") == 0) {
1761 int v;
1762
Willy Tarreaud0d8da92015-04-04 02:10:38 +02001763 if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau93e7c002013-10-07 18:51:07 +02001764 appctx->ctx.cli.msg = stats_permission_denied_msg;
1765 appctx->st0 = STAT_CLI_PRINT;
1766 return 1;
1767 }
1768
1769 if (!*args[4]) {
1770 appctx->ctx.cli.msg = "Expects an integer value.\n";
1771 appctx->st0 = STAT_CLI_PRINT;
1772 return 1;
1773 }
1774
1775 v = atoi(args[4]);
1776 if (v < 0) {
1777 appctx->ctx.cli.msg = "Value out of range.\n";
1778 appctx->st0 = STAT_CLI_PRINT;
1779 return 1;
1780 }
1781
1782 global.sps_lim = v;
1783
1784 /* Dequeues all of the listeners waiting for a resource */
1785 if (!LIST_ISEMPTY(&global_listener_queue))
1786 dequeue_all_listeners(&global_listener_queue);
1787
1788 return 1;
1789 }
1790 else {
1791 appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n";
1792 appctx->st0 = STAT_CLI_PRINT;
1793 return 1;
1794 }
1795 }
Willy Tarreaue43d5322013-10-07 20:01:52 +02001796#ifdef USE_OPENSSL
1797 else if (strcmp(args[2], "ssl-sessions") == 0) {
1798 if (strcmp(args[3], "global") == 0) {
1799 int v;
1800
Willy Tarreaud0d8da92015-04-04 02:10:38 +02001801 if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreaue43d5322013-10-07 20:01:52 +02001802 appctx->ctx.cli.msg = stats_permission_denied_msg;
1803 appctx->st0 = STAT_CLI_PRINT;
1804 return 1;
1805 }
1806
1807 if (!*args[4]) {
1808 appctx->ctx.cli.msg = "Expects an integer value.\n";
1809 appctx->st0 = STAT_CLI_PRINT;
1810 return 1;
1811 }
1812
1813 v = atoi(args[4]);
1814 if (v < 0) {
1815 appctx->ctx.cli.msg = "Value out of range.\n";
1816 appctx->st0 = STAT_CLI_PRINT;
1817 return 1;
1818 }
1819
1820 global.ssl_lim = v;
1821
1822 /* Dequeues all of the listeners waiting for a resource */
1823 if (!LIST_ISEMPTY(&global_listener_queue))
1824 dequeue_all_listeners(&global_listener_queue);
1825
1826 return 1;
1827 }
1828 else {
1829 appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n";
1830 appctx->st0 = STAT_CLI_PRINT;
1831 return 1;
1832 }
1833 }
1834#endif
William Lallemandd85f9172012-11-09 17:05:39 +01001835 else if (strcmp(args[2], "http-compression") == 0) {
1836 if (strcmp(args[3], "global") == 0) {
1837 int v;
1838
Willy Tarreau85d47f92012-11-21 00:29:50 +01001839 if (!*args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001840 appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n";
1841 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau85d47f92012-11-21 00:29:50 +01001842 return 1;
1843 }
1844
William Lallemandd85f9172012-11-09 17:05:39 +01001845 v = atoi(args[4]);
1846 global.comp_rate_lim = v * 1024; /* Kilo to bytes. */
1847 }
1848 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001849 appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n";
1850 appctx->st0 = STAT_CLI_PRINT;
William Lallemandd85f9172012-11-09 17:05:39 +01001851 return 1;
1852 }
1853 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001854 else {
Willy Tarreaue43d5322013-10-07 20:01:52 +02001855 appctx->ctx.cli.msg = "'set rate-limit' supports 'connections', 'sessions', 'ssl-sessions', and 'http-compression'.\n";
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001856 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001857 return 1;
1858 }
1859 }
Willy Tarreau654694e2012-06-07 01:03:16 +02001860 else if (strcmp(args[1], "table") == 0) {
1861 stats_sock_table_request(si, args, STAT_CLI_O_SET);
1862 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001863 else if (strcmp(args[1], "map") == 0) {
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01001864 char *err;
1865
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001866 /* Set flags. */
1867 appctx->ctx.map.display_flags = PAT_REF_MAP;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001868
1869 /* Expect three parameters: map name, key and new value. */
1870 if (!*args[2] || !*args[3] || !*args[4]) {
Thierry FOURNIERd5723432014-03-11 13:52:44 +01001871 appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001872 appctx->st0 = STAT_CLI_PRINT;
1873 return 1;
1874 }
1875
1876 /* Lookup the reference in the maps. */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001877 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001878 if (!appctx->ctx.map.ref) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001879 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001880 appctx->st0 = STAT_CLI_PRINT;
1881 return 1;
1882 }
1883
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001884 /* If the entry identifier start with a '#', it is considered as
1885 * pointer id
1886 */
1887 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
1888 struct pat_ref_elt *ref;
1889 long long int conv;
1890 char *error;
1891
1892 /* Convert argument to integer value. */
1893 conv = strtoll(&args[3][1], &error, 16);
1894 if (*error != '\0') {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001895 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001896 appctx->st0 = STAT_CLI_PRINT;
1897 return 1;
1898 }
1899
1900 /* Convert and check integer to pointer. */
1901 ref = (struct pat_ref_elt *)(long)conv;
1902 if ((long long int)(long)ref != conv) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001903 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001904 appctx->st0 = STAT_CLI_PRINT;
1905 return 1;
1906 }
1907
1908 /* Try to delete the entry. */
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01001909 err = NULL;
1910 if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) {
1911 if (err)
1912 memprintf(&err, "%s.\n", err);
1913 appctx->ctx.cli.err = err;
1914 appctx->st0 = STAT_CLI_PRINT_FREE;
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001915 return 1;
1916 }
1917 }
1918 else {
1919 /* Else, use the entry identifier as pattern
1920 * string, and update the value.
1921 */
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01001922 err = NULL;
1923 if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) {
1924 if (err)
1925 memprintf(&err, "%s.\n", err);
1926 appctx->ctx.cli.err = err;
1927 appctx->st0 = STAT_CLI_PRINT_FREE;
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001928 return 1;
1929 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001930 }
1931
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001932 /* The set is done, send message. */
Thierry FOURNIER07e78c52014-12-18 15:28:01 +01001933 appctx->st0 = STAT_CLI_PROMPT;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001934 return 1;
1935 }
Emeric Brun4147b2e2014-06-16 18:36:30 +02001936#ifdef USE_OPENSSL
1937 else if (strcmp(args[1], "ssl") == 0) {
1938 if (strcmp(args[2], "ocsp-response") == 0) {
Lukas Tribuse4e30f72014-12-09 16:32:51 +01001939#if (defined SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB && !defined OPENSSL_NO_OCSP)
Emeric Brun4147b2e2014-06-16 18:36:30 +02001940 char *err = NULL;
1941
Emeric Brunaf4ef742014-06-19 14:10:45 +02001942 /* Expect one parameter: the new response in base64 encoding */
Emeric Brun4147b2e2014-06-16 18:36:30 +02001943 if (!*args[3]) {
1944 appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n";
1945 appctx->st0 = STAT_CLI_PRINT;
1946 return 1;
1947 }
1948
1949 trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size);
1950 if (trash.len < 0) {
1951 appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n";
1952 appctx->st0 = STAT_CLI_PRINT;
1953 return 1;
1954 }
1955
1956 if (ssl_sock_update_ocsp_response(&trash, &err)) {
1957 if (err) {
1958 memprintf(&err, "%s.\n", err);
1959 appctx->ctx.cli.err = err;
1960 appctx->st0 = STAT_CLI_PRINT_FREE;
1961 }
1962 return 1;
1963 }
1964 appctx->ctx.cli.msg = "OCSP Response updated!";
1965 appctx->st0 = STAT_CLI_PRINT;
1966 return 1;
1967#else
1968 appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n";
1969 appctx->st0 = STAT_CLI_PRINT;
1970 return 1;
1971#endif
1972 }
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +02001973 else if (strcmp(args[2], "tls-key") == 0) {
1974#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
1975 /* Expect two parameters: the filename and the new new TLS key in encoding */
1976 if (!*args[3] || !*args[4]) {
1977 appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n";
1978 appctx->st0 = STAT_CLI_PRINT;
1979 return 1;
1980 }
1981
1982 appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]);
1983 if(!appctx->ctx.tlskeys.ref) {
1984 appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n";
1985 appctx->st0 = STAT_CLI_PRINT;
1986 return 1;
1987 }
1988
1989 trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size);
1990 if (trash.len != sizeof(struct tls_sess_key)) {
1991 appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n";
1992 appctx->st0 = STAT_CLI_PRINT;
1993 return 1;
1994 }
1995
Pradeep Jindalcc79b002015-08-20 18:25:17 +05301996 memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len);
1997 appctx->ctx.tlskeys.ref->tls_ticket_enc_index = (appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 1) % TLS_TICKETS_NO;
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +02001998
1999 appctx->ctx.cli.msg = "TLS ticket key updated!";
2000 appctx->st0 = STAT_CLI_PRINT;
2001 return 1;
2002#else
2003 appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL "
2004 "that doesn't support specifying TLS ticket keys\n";
2005 appctx->st0 = STAT_CLI_PRINT;
2006 return 1;
2007#endif
2008 }
Emeric Brun4147b2e2014-06-16 18:36:30 +02002009 else {
2010 appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n";
2011 appctx->st0 = STAT_CLI_PRINT;
2012 return 1;
2013 }
2014 }
2015#endif
Willy Tarreau7aabd112010-01-26 10:59:06 +01002016 else { /* unknown "set" parameter */
Willy Tarreau4483d432009-10-10 19:30:08 +02002017 return 0;
2018 }
2019 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002020 else if (strcmp(args[0], "enable") == 0) {
Simon Horman671b6f02013-11-25 10:46:39 +09002021 if (strcmp(args[1], "agent") == 0) {
2022 struct server *sv;
2023
2024 sv = expect_server_admin(s, si, args[2]);
2025 if (!sv)
2026 return 1;
2027
Willy Tarreau2e10f5a2013-12-11 20:11:55 +01002028 if (!(sv->agent.state & CHK_ST_CONFIGURED)) {
2029 appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n";
2030 appctx->st0 = STAT_CLI_PRINT;
2031 return 1;
2032 }
2033
2034 sv->agent.state |= CHK_ST_ENABLED;
Simon Horman671b6f02013-11-25 10:46:39 +09002035 return 1;
2036 }
Willy Tarreau9b5aecd2014-05-23 11:53:10 +02002037 else if (strcmp(args[1], "health") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01002038 struct server *sv;
2039
Willy Tarreaud52c41e2011-09-07 23:41:01 +02002040 sv = expect_server_admin(s, si, args[2]);
2041 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01002042 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01002043
Willy Tarreau9b5aecd2014-05-23 11:53:10 +02002044 if (!(sv->check.state & CHK_ST_CONFIGURED)) {
2045 appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n";
2046 appctx->st0 = STAT_CLI_PRINT;
2047 return 1;
2048 }
2049
2050 sv->check.state |= CHK_ST_ENABLED;
2051 return 1;
2052 }
2053 else if (strcmp(args[1], "server") == 0) {
2054 struct server *sv;
2055
2056 sv = expect_server_admin(s, si, args[2]);
2057 if (!sv)
2058 return 1;
2059
Willy Tarreaubfc7b7a2014-05-22 16:14:34 +02002060 srv_adm_set_ready(sv);
Willy Tarreau532a4502011-09-07 22:37:44 +02002061 return 1;
2062 }
2063 else if (strcmp(args[1], "frontend") == 0) {
2064 struct proxy *px;
2065
2066 px = expect_frontend_admin(s, si, args[2]);
2067 if (!px)
2068 return 1;
2069
2070 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002071 appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n";
2072 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002073 return 1;
2074 }
2075
2076 if (px->state != PR_STPAUSED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002077 appctx->ctx.cli.msg = "Frontend is already enabled.\n";
2078 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002079 return 1;
2080 }
2081
2082 if (!resume_proxy(px)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002083 appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n";
2084 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002085 return 1;
2086 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002087 return 1;
2088 }
2089 else { /* unknown "enable" parameter */
Willy Tarreau9b5aecd2014-05-23 11:53:10 +02002090 appctx->ctx.cli.msg = "'enable' only supports 'agent', 'frontend', 'health', and 'server'.\n";
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002091 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002092 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01002093 }
2094 }
2095 else if (strcmp(args[0], "disable") == 0) {
Simon Horman671b6f02013-11-25 10:46:39 +09002096 if (strcmp(args[1], "agent") == 0) {
2097 struct server *sv;
2098
2099 sv = expect_server_admin(s, si, args[2]);
2100 if (!sv)
2101 return 1;
2102
Willy Tarreau2e10f5a2013-12-11 20:11:55 +01002103 sv->agent.state &= ~CHK_ST_ENABLED;
Simon Horman671b6f02013-11-25 10:46:39 +09002104 return 1;
2105 }
Willy Tarreau9b5aecd2014-05-23 11:53:10 +02002106 else if (strcmp(args[1], "health") == 0) {
2107 struct server *sv;
2108
2109 sv = expect_server_admin(s, si, args[2]);
2110 if (!sv)
2111 return 1;
2112
2113 sv->check.state &= ~CHK_ST_ENABLED;
2114 return 1;
2115 }
Simon Horman671b6f02013-11-25 10:46:39 +09002116 else if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01002117 struct server *sv;
2118
Willy Tarreaud52c41e2011-09-07 23:41:01 +02002119 sv = expect_server_admin(s, si, args[2]);
2120 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01002121 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01002122
Willy Tarreaubfc7b7a2014-05-22 16:14:34 +02002123 srv_adm_set_maint(sv);
Willy Tarreau532a4502011-09-07 22:37:44 +02002124 return 1;
2125 }
2126 else if (strcmp(args[1], "frontend") == 0) {
2127 struct proxy *px;
2128
2129 px = expect_frontend_admin(s, si, args[2]);
2130 if (!px)
2131 return 1;
2132
2133 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002134 appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n";
2135 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002136 return 1;
2137 }
2138
2139 if (px->state == PR_STPAUSED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002140 appctx->ctx.cli.msg = "Frontend is already disabled.\n";
2141 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002142 return 1;
2143 }
2144
2145 if (!pause_proxy(px)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002146 appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n";
2147 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002148 return 1;
2149 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002150 return 1;
2151 }
2152 else { /* unknown "disable" parameter */
Willy Tarreau9b5aecd2014-05-23 11:53:10 +02002153 appctx->ctx.cli.msg = "'disable' only supports 'agent', 'frontend', 'health', and 'server'.\n";
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002154 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002155 return 1;
2156 }
2157 }
2158 else if (strcmp(args[0], "shutdown") == 0) {
2159 if (strcmp(args[1], "frontend") == 0) {
2160 struct proxy *px;
2161
2162 px = expect_frontend_admin(s, si, args[2]);
2163 if (!px)
2164 return 1;
2165
2166 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002167 appctx->ctx.cli.msg = "Frontend was already shut down.\n";
2168 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002169 return 1;
2170 }
2171
2172 Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
2173 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
2174 send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
2175 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
2176 stop_proxy(px);
2177 return 1;
2178 }
Willy Tarreaua295edc2011-09-07 23:21:03 +02002179 else if (strcmp(args[1], "session") == 0) {
Willy Tarreau87b09662015-04-03 00:22:06 +02002180 struct stream *sess, *ptr;
Willy Tarreaua295edc2011-09-07 23:21:03 +02002181
Willy Tarreaud0d8da92015-04-04 02:10:38 +02002182 if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002183 appctx->ctx.cli.msg = stats_permission_denied_msg;
2184 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaua295edc2011-09-07 23:21:03 +02002185 return 1;
2186 }
2187
2188 if (!*args[2]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002189 appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n";
2190 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaua295edc2011-09-07 23:21:03 +02002191 return 1;
2192 }
2193
2194 ptr = (void *)strtoul(args[2], NULL, 0);
2195
Willy Tarreau87b09662015-04-03 00:22:06 +02002196 /* first, look for the requested stream in the stream table */
2197 list_for_each_entry(sess, &streams, list) {
Willy Tarreaua295edc2011-09-07 23:21:03 +02002198 if (sess == ptr)
2199 break;
2200 }
2201
Willy Tarreau87b09662015-04-03 00:22:06 +02002202 /* do we have the stream ? */
Willy Tarreaua295edc2011-09-07 23:21:03 +02002203 if (sess != ptr) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002204 appctx->ctx.cli.msg = "No such session (use 'show sess').\n";
2205 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaua295edc2011-09-07 23:21:03 +02002206 return 1;
2207 }
2208
Willy Tarreaue7dff022015-04-03 01:14:29 +02002209 stream_shutdown(sess, SF_ERR_KILLED);
Willy Tarreaua295edc2011-09-07 23:21:03 +02002210 return 1;
2211 }
Willy Tarreau52b2d222011-09-07 23:48:48 +02002212 else if (strcmp(args[1], "sessions") == 0) {
2213 if (strcmp(args[2], "server") == 0) {
2214 struct server *sv;
Willy Tarreau87b09662015-04-03 00:22:06 +02002215 struct stream *sess, *sess_bck;
Willy Tarreau52b2d222011-09-07 23:48:48 +02002216
2217 sv = expect_server_admin(s, si, args[3]);
2218 if (!sv)
2219 return 1;
2220
Willy Tarreau87b09662015-04-03 00:22:06 +02002221 /* kill all the stream that are on this server */
Willy Tarreau52b2d222011-09-07 23:48:48 +02002222 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
2223 if (sess->srv_conn == sv)
Willy Tarreaue7dff022015-04-03 01:14:29 +02002224 stream_shutdown(sess, SF_ERR_KILLED);
Willy Tarreau52b2d222011-09-07 23:48:48 +02002225
2226 return 1;
2227 }
2228 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002229 appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n";
2230 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau52b2d222011-09-07 23:48:48 +02002231 return 1;
2232 }
2233 }
Willy Tarreau532a4502011-09-07 22:37:44 +02002234 else { /* unknown "disable" parameter */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002235 appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n";
2236 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002237 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01002238 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002239 }
2240 else if (strcmp(args[0], "del") == 0) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002241 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
2242 if (args[1][0] == 'm')
2243 appctx->ctx.map.display_flags = PAT_REF_MAP;
2244 else
2245 appctx->ctx.map.display_flags = PAT_REF_ACL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002246
2247 /* Expect two parameters: map name and key. */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002248 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
2249 if (!*args[2] || !*args[3]) {
2250 appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n";
2251 appctx->st0 = STAT_CLI_PRINT;
2252 return 1;
2253 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002254 }
2255
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002256 else {
2257 if (!*args[2] || !*args[3]) {
2258 appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n";
2259 appctx->st0 = STAT_CLI_PRINT;
2260 return 1;
2261 }
2262 }
2263
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002264 /* Lookup the reference in the maps. */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01002265 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002266 if (!appctx->ctx.map.ref ||
2267 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002268 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002269 appctx->st0 = STAT_CLI_PRINT;
2270 return 1;
2271 }
2272
Thierry FOURNIER9356c682014-01-28 15:55:37 +01002273 /* If the entry identifier start with a '#', it is considered as
2274 * pointer id
2275 */
2276 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
2277 struct pat_ref_elt *ref;
2278 long long int conv;
2279 char *error;
2280
2281 /* Convert argument to integer value. */
2282 conv = strtoll(&args[3][1], &error, 16);
2283 if (*error != '\0') {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002284 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01002285 appctx->st0 = STAT_CLI_PRINT;
2286 return 1;
2287 }
2288
2289 /* Convert and check integer to pointer. */
2290 ref = (struct pat_ref_elt *)(long)conv;
2291 if ((long long int)(long)ref != conv) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002292 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01002293 appctx->st0 = STAT_CLI_PRINT;
2294 return 1;
2295 }
2296
2297 /* Try to delete the entry. */
2298 if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) {
2299 /* The entry is not found, send message. */
2300 appctx->ctx.cli.msg = "Key not found.\n";
2301 appctx->st0 = STAT_CLI_PRINT;
2302 return 1;
2303 }
2304 }
2305 else {
2306 /* Else, use the entry identifier as pattern
2307 * string and try to delete the entry.
2308 */
2309 if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) {
2310 /* The entry is not found, send message. */
2311 appctx->ctx.cli.msg = "Key not found.\n";
2312 appctx->st0 = STAT_CLI_PRINT;
2313 return 1;
2314 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002315 }
2316
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002317 /* The deletion is done, send message. */
Thierry FOURNIER07e78c52014-12-18 15:28:01 +01002318 appctx->st0 = STAT_CLI_PROMPT;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002319 return 1;
2320 }
2321 else { /* unknown "del" parameter */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002322 appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002323 appctx->st0 = STAT_CLI_PRINT;
2324 return 1;
2325 }
2326 }
2327 else if (strcmp(args[0], "add") == 0) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002328 if (strcmp(args[1], "map") == 0 ||
2329 strcmp(args[1], "acl") == 0) {
2330 int ret;
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002331 char *err;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002332
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002333 /* Set flags. */
2334 if (args[1][0] == 'm')
2335 appctx->ctx.map.display_flags = PAT_REF_MAP;
2336 else
2337 appctx->ctx.map.display_flags = PAT_REF_ACL;
2338
2339 /* If the keywork is "map", we expect three parameters, if it
2340 * is "acl", we expect only two parameters
2341 */
2342 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
2343 if (!*args[2] || !*args[3] || !*args[4]) {
2344 appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n";
2345 appctx->st0 = STAT_CLI_PRINT;
2346 return 1;
2347 }
2348 }
2349 else {
2350 if (!*args[2] || !*args[3]) {
2351 appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n";
2352 appctx->st0 = STAT_CLI_PRINT;
2353 return 1;
2354 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002355 }
2356
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002357 /* Lookup for the reference. */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01002358 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002359 if (!appctx->ctx.map.ref) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002360 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002361 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002362 else
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002363 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002364 appctx->st0 = STAT_CLI_PRINT;
2365 return 1;
2366 }
2367
Thierry FOURNIER64c585f2014-01-29 20:02:36 +01002368 /* The command "add acl" is prohibited if the reference
2369 * use samples.
2370 */
2371 if ((appctx->ctx.map.display_flags & PAT_REF_ACL) &&
2372 (appctx->ctx.map.ref->flags & PAT_REF_SMP)) {
2373 appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. "
2374 "You must use the command 'add map' to add values.\n";
2375 appctx->st0 = STAT_CLI_PRINT;
2376 return 1;
2377 }
2378
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002379 /* Add value. */
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002380 err = NULL;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002381 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIERe47e4e22014-04-28 11:18:57 +02002382 ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], &err);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002383 else
Thierry FOURNIERe47e4e22014-04-28 11:18:57 +02002384 ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002385 if (!ret) {
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002386 if (err)
2387 memprintf(&err, "%s.\n", err);
2388 appctx->ctx.cli.err = err;
2389 appctx->st0 = STAT_CLI_PRINT_FREE;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002390 return 1;
2391 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002392
2393 /* The add is done, send message. */
Thierry FOURNIER07e78c52014-12-18 15:28:01 +01002394 appctx->st0 = STAT_CLI_PROMPT;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002395 return 1;
2396 }
2397 else { /* unknown "del" parameter */
2398 appctx->ctx.cli.msg = "'add' only supports 'map'.\n";
2399 appctx->st0 = STAT_CLI_PRINT;
2400 return 1;
2401 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002402 }
2403 else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002404 return 0;
2405 }
2406 return 1;
2407}
2408
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002409/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002410 * used to processes I/O from/to the stats unix socket. The system relies on a
2411 * state machine handling requests and various responses. We read a request,
2412 * then we process it and send the response, and we possibly display a prompt.
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002413 * Then we can read again. The state is stored in appctx->st0 and is one of the
2414 * STAT_CLI_* constants. appctx->st1 is used to indicate whether prompt is enabled
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002415 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002416 */
Willy Tarreau00a37f02015-04-13 12:05:19 +02002417static void cli_io_handler(struct appctx *appctx)
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002418{
Willy Tarreau00a37f02015-04-13 12:05:19 +02002419 struct stream_interface *si = appctx->owner;
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002420 struct channel *req = si_oc(si);
2421 struct channel *res = si_ic(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002422 int reql;
2423 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002424
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002425 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2426 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002427
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002428 while (1) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002429 if (appctx->st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002430 /* Stats output not initialized yet */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002431 memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats));
2432 appctx->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002433 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002434 else if (appctx->st0 == STAT_CLI_END) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002435 /* Let's close for real now. We just close the request
2436 * side, the conditions below will complete if needed.
2437 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02002438 si_shutw(si);
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002439 break;
2440 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002441 else if (appctx->st0 == STAT_CLI_GETREQ) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02002442 /* ensure we have some output room left in the event we
2443 * would want to return some info right after parsing.
2444 */
Willy Tarreau4e4292b2014-11-28 12:18:45 +01002445 if (buffer_almost_full(si_ib(si))) {
Willy Tarreaufe127932015-04-21 19:23:39 +02002446 si_applet_cant_put(si);
Willy Tarreau4e33d862009-10-11 23:35:10 +02002447 break;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01002448 }
Willy Tarreau4e33d862009-10-11 23:35:10 +02002449
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002450 reql = bo_getline(si_oc(si), trash.str, trash.size);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002451 if (reql <= 0) { /* closed or EOL not found */
2452 if (reql == 0)
2453 break;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002454 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002455 continue;
2456 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002457
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002458 /* seek for a possible semi-colon. If we find one, we
2459 * replace it with an LF and skip only this part.
2460 */
2461 for (len = 0; len < reql; len++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002462 if (trash.str[len] == ';') {
2463 trash.str[len] = '\n';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002464 reql = len + 1;
2465 break;
2466 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002467
Willy Tarreau816fc222009-10-04 07:36:58 +02002468 /* now it is time to check that we have a full line,
2469 * remove the trailing \n and possibly \r, then cut the
2470 * line.
2471 */
2472 len = reql - 1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002473 if (trash.str[len] != '\n') {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002474 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002475 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002476 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002477
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002478 if (len && trash.str[len-1] == '\r')
Willy Tarreau816fc222009-10-04 07:36:58 +02002479 len--;
2480
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002481 trash.str[len] = '\0';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002482
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002483 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002484 if (len) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002485 if (strcmp(trash.str, "quit") == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002486 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002487 continue;
2488 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002489 else if (strcmp(trash.str, "prompt") == 0)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002490 appctx->st1 = !appctx->st1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002491 else if (strcmp(trash.str, "help") == 0 ||
2492 !stats_sock_parse_request(si, trash.str)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002493 appctx->ctx.cli.msg = stats_sock_usage_msg;
2494 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02002495 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002496 /* NB: stats_sock_parse_request() may have put
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002497 * another STAT_CLI_O_* into appctx->st0.
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002498 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002499 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002500 else if (!appctx->st1) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002501 /* if prompt is disabled, print help on empty lines,
2502 * so that the user at least knows how to enable
2503 * prompt and find help.
2504 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002505 appctx->ctx.cli.msg = stats_sock_usage_msg;
2506 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002507 }
2508
2509 /* re-adjust req buffer */
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002510 bo_skip(si_oc(si), reql);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002511 req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002512 }
Willy Tarreau68c00c72015-09-25 19:21:19 +02002513 else { /* output functions */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002514 switch (appctx->st0) {
Andrew Hayworthe32d1862015-10-02 15:08:10 +00002515 case STAT_CLI_PROMPT:
2516 break;
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02002517 case STAT_CLI_PRINT:
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002518 if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002519 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreaubc18da12015-03-13 14:00:47 +01002520 else
Willy Tarreaufe127932015-04-21 19:23:39 +02002521 si_applet_cant_put(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002522 break;
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002523 case STAT_CLI_PRINT_FREE:
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002524 if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) {
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002525 free(appctx->ctx.cli.err);
2526 appctx->st0 = STAT_CLI_PROMPT;
2527 }
Willy Tarreaubc18da12015-03-13 14:00:47 +01002528 else
Willy Tarreaufe127932015-04-21 19:23:39 +02002529 si_applet_cant_put(si);
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002530 break;
Baptiste Assmann9b6857e2015-09-18 14:49:12 +02002531 case STAT_CLI_O_BACKEND:
2532 if (stats_dump_backend_to_buffer(si))
2533 appctx->st0 = STAT_CLI_PROMPT;
2534 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002535 case STAT_CLI_O_INFO:
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002536 if (stats_dump_info_to_buffer(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002537 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002538 break;
Baptiste Assmann28289462015-07-03 08:01:20 +02002539 case STAT_CLI_O_SERVERS_STATE:
2540 if (stats_dump_servers_state_to_buffer(si))
2541 appctx->st0 = STAT_CLI_PROMPT;
2542 break;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002543 case STAT_CLI_O_STAT:
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002544 if (stats_dump_stat_to_buffer(si, NULL))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002545 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002546 break;
Baptiste Assmann3863f972015-05-17 00:33:24 +02002547 case STAT_CLI_O_RESOLVERS:
2548 if (stats_dump_resolvers_to_buffer(si))
2549 appctx->st0 = STAT_CLI_PROMPT;
2550 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002551 case STAT_CLI_O_SESS:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002552 if (stats_dump_sess_to_buffer(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002553 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002554 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002555 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002556 if (stats_dump_errors_to_buffer(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002557 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002558 break;
Willy Tarreau69f58c82010-07-12 17:55:33 +02002559 case STAT_CLI_O_TAB:
Simon Hormanc88b8872011-06-15 15:18:49 +09002560 case STAT_CLI_O_CLR:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002561 if (stats_table_request(si, appctx->st0))
2562 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau69f58c82010-07-12 17:55:33 +02002563 break;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002564 case STAT_CLI_O_PATS:
2565 if (stats_pats_list(si))
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002566 appctx->st0 = STAT_CLI_PROMPT;
2567 break;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002568 case STAT_CLI_O_PAT:
2569 if (stats_pat_list(si))
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002570 appctx->st0 = STAT_CLI_PROMPT;
2571 break;
2572 case STAT_CLI_O_MLOOK:
2573 if (stats_map_lookup(si))
2574 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau4efb3532014-01-29 12:13:39 +01002575 break;
Willy Tarreau12833bb2014-01-28 16:49:56 +01002576 case STAT_CLI_O_POOLS:
2577 if (stats_dump_pools_to_buffer(si))
2578 appctx->st0 = STAT_CLI_PROMPT;
2579 break;
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +02002580#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
2581 case STAT_CLI_O_TLSK:
2582 if (stats_tlskeys_list(si))
2583 appctx->st0 = STAT_CLI_PROMPT;
2584 break;
2585#endif
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002586 default: /* abnormal state */
Willy Tarreau5cfa3bc2015-09-25 20:08:51 +02002587 si->flags |= SI_FL_ERR;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002588 break;
2589 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002590
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002591 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002592 if (appctx->st0 == STAT_CLI_PROMPT) {
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002593 if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002594 appctx->st0 = STAT_CLI_GETREQ;
Willy Tarreaubc18da12015-03-13 14:00:47 +01002595 else
Willy Tarreaufe127932015-04-21 19:23:39 +02002596 si_applet_cant_put(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002597 }
2598
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002599 /* If the output functions are still there, it means they require more room. */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002600 if (appctx->st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002601 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002602
2603 /* Now we close the output if one of the writers did so,
2604 * or if we're not in interactive mode and the request
2605 * buffer is empty. This still allows pipelined requests
2606 * to be sent in non-interactive mode.
2607 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002608 if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) {
2609 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002610 continue;
2611 }
2612
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002613 /* switch state back to GETREQ to read next requests */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002614 appctx->st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002615 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002616 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002617
Willy Tarreauc9e930a2015-09-25 20:06:08 +02002618 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002619 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
2620 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
Aman Guptaceafb4a2012-04-02 18:57:54 -07002621 /* Other side has closed, let's abort if we have no more processing to do
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002622 * and nothing more to consume. This is comparable to a broken pipe, so
2623 * we forward the close to the request side so that it flows upstream to
2624 * the client.
2625 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02002626 si_shutw(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002627 }
2628
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002629 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (appctx->st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002630 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
2631 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
2632 /* We have no more processing to do, and nothing more to send, and
2633 * the client side has closed. So we'll forward this state downstream
2634 * on the response buffer.
2635 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02002636 si_shutr(si);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002637 res->flags |= CF_READ_NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002638 }
2639
Willy Tarreau828824a2015-04-19 17:20:03 +02002640 out:
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01002641 DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rqh=%d, rqs=%d, rh=%d, rs=%d\n",
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002642 __FUNCTION__, __LINE__,
Willy Tarreau9b28e032012-10-12 23:49:43 +02002643 si->state, req->flags, res->flags, req->buf->i, req->buf->o, res->buf->i, res->buf->o);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002644}
2645
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002646/* This function dumps information onto the stream interface's read buffer.
2647 * It returns 0 as long as it does not complete, non-zero upon completion.
2648 * No state is used.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002649 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002650static int stats_dump_info_to_buffer(struct stream_interface *si)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002651{
2652 unsigned int up = (now.tv_sec - start_date.tv_sec);
2653
Willy Tarreau0c9c2722014-05-28 12:28:58 +02002654#ifdef USE_OPENSSL
2655 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
2656 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
2657 int ssl_reuse = 0;
2658
2659 if (ssl_key_rate < ssl_sess_rate) {
2660 /* count the ssl reuse ratio and avoid overflows in both directions */
2661 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
2662 }
2663#endif
2664
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002665 chunk_printf(&trash,
2666 "Name: " PRODUCT_NAME "\n"
2667 "Version: " HAPROXY_VERSION "\n"
2668 "Release_date: " HAPROXY_DATE "\n"
2669 "Nbproc: %d\n"
2670 "Process_num: %d\n"
2671 "Pid: %d\n"
2672 "Uptime: %dd %dh%02dm%02ds\n"
2673 "Uptime_sec: %d\n"
2674 "Memmax_MB: %d\n"
Willy Tarreau58102cf2015-10-28 16:24:21 +01002675 "PoolAlloc_MB: %d\n"
2676 "PoolUsed_MB: %d\n"
2677 "PoolFailed: %d\n"
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002678 "Ulimit-n: %d\n"
2679 "Maxsock: %d\n"
2680 "Maxconn: %d\n"
2681 "Hard_maxconn: %d\n"
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002682 "CurrConns: %d\n"
Willy Tarreau71b734c2014-01-28 15:19:44 +01002683 "CumConns: %d\n"
Warren Turkalb197d7f2015-01-27 15:04:16 -08002684 "CumReq: %u\n"
Willy Tarreau71b734c2014-01-28 15:19:44 +01002685#ifdef USE_OPENSSL
2686 "MaxSslConns: %d\n"
2687 "CurrSslConns: %d\n"
2688 "CumSslConns: %d\n"
2689#endif
2690 "Maxpipes: %d\n"
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002691 "PipesUsed: %d\n"
2692 "PipesFree: %d\n"
2693 "ConnRate: %d\n"
2694 "ConnRateLimit: %d\n"
2695 "MaxConnRate: %d\n"
Willy Tarreau93e7c002013-10-07 18:51:07 +02002696 "SessRate: %d\n"
2697 "SessRateLimit: %d\n"
2698 "MaxSessRate: %d\n"
Willy Tarreaue43d5322013-10-07 20:01:52 +02002699#ifdef USE_OPENSSL
2700 "SslRate: %d\n"
2701 "SslRateLimit: %d\n"
2702 "MaxSslRate: %d\n"
Willy Tarreau0c9c2722014-05-28 12:28:58 +02002703 "SslFrontendKeyRate: %d\n"
2704 "SslFrontendMaxKeyRate: %d\n"
2705 "SslFrontendSessionReuse_pct: %d\n"
2706 "SslBackendKeyRate: %d\n"
2707 "SslBackendMaxKeyRate: %d\n"
Willy Tarreauce3f9132014-05-28 16:47:01 +02002708 "SslCacheLookups: %u\n"
2709 "SslCacheMisses: %u\n"
Willy Tarreaue43d5322013-10-07 20:01:52 +02002710#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002711 "CompressBpsIn: %u\n"
2712 "CompressBpsOut: %u\n"
2713 "CompressBpsRateLim: %u\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002714#ifdef USE_ZLIB
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002715 "ZlibMemUsage: %ld\n"
2716 "MaxZlibMemUsage: %ld\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002717#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002718 "Tasks: %d\n"
2719 "Run_queue: %d\n"
2720 "Idle_pct: %d\n"
2721 "node: %s\n"
2722 "description: %s\n"
2723 "",
2724 global.nbproc,
2725 relative_pid,
2726 pid,
2727 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
2728 up,
2729 global.rlimit_memmax,
Willy Tarreau58102cf2015-10-28 16:24:21 +01002730 (int)(pool_total_allocated() / 1048576L),
2731 (int)(pool_total_used() / 1048576L),
2732 pool_total_failures(),
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002733 global.rlimit_nofile,
Willy Tarreau71b734c2014-01-28 15:19:44 +01002734 global.maxsock, global.maxconn, global.hardmaxconn,
2735 actconn, totalconn, global.req_count,
2736#ifdef USE_OPENSSL
2737 global.maxsslconn, sslconns, totalsslconns,
2738#endif
2739 global.maxpipes, pipes_used, pipes_free,
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002740 read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max,
Willy Tarreau93e7c002013-10-07 18:51:07 +02002741 read_freq_ctr(&global.sess_per_sec), global.sps_lim, global.sps_max,
Willy Tarreaue43d5322013-10-07 20:01:52 +02002742#ifdef USE_OPENSSL
Willy Tarreau0c9c2722014-05-28 12:28:58 +02002743 ssl_sess_rate, global.ssl_lim, global.ssl_max,
2744 ssl_key_rate, global.ssl_fe_keys_max,
2745 ssl_reuse,
2746 read_freq_ctr(&global.ssl_be_keys_per_sec), global.ssl_be_keys_max,
Willy Tarreauce3f9132014-05-28 16:47:01 +02002747 global.shctx_lookups, global.shctx_misses,
Willy Tarreaue43d5322013-10-07 20:01:52 +02002748#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002749 read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out),
2750 global.comp_rate_lim,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002751#ifdef USE_ZLIB
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002752 zlib_used_memory, global.maxzlibmem,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002753#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002754 nb_tasks_cur, run_queue_cur, idle_pct,
2755 global.node, global.desc ? global.desc : ""
2756 );
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002757
Willy Tarreaubc18da12015-03-13 14:00:47 +01002758 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02002759 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002760 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01002761 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002762
2763 return 1;
2764}
2765
Baptiste Assmann28289462015-07-03 08:01:20 +02002766/* dumps server state information into <buf> for all the servers found in <backend>
2767 * These information are all the parameters which may change during HAProxy runtime.
2768 * By default, we only export to the last known server state file format.
2769 * These information can be used at next startup to recover same level of server state.
2770 */
2771static void dump_servers_state(struct proxy *backend, struct chunk *buf)
2772{
2773 struct server *srv;
2774 char srv_addr[INET6_ADDRSTRLEN + 1];
2775 time_t srv_time_since_last_change;
2776 int bk_f_forced_id, srv_f_forced_id;
2777
2778 /* we don't want to report any state if the backend is not enabled on this process */
2779 if (backend->bind_proc && !(backend->bind_proc & (1UL << (relative_pid - 1))))
2780 return;
2781
2782 srv = backend->srv;
2783
2784 while (srv) {
2785 srv_addr[0] = '\0';
2786 srv_time_since_last_change = 0;
2787 bk_f_forced_id = 0;
2788 srv_f_forced_id = 0;
2789
2790 switch (srv->addr.ss_family) {
2791 case AF_INET:
2792 inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr,
2793 srv_addr, INET_ADDRSTRLEN + 1);
2794 break;
2795 case AF_INET6:
2796 inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr,
2797 srv_addr, INET6_ADDRSTRLEN + 1);
2798 break;
2799 }
2800 srv_time_since_last_change = now.tv_sec - srv->last_change;
2801 bk_f_forced_id = backend->options & PR_O_FORCED_ID ? 1 : 0;
2802 srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0;
2803
2804 chunk_appendf(buf,
2805 "%d %s "
2806 "%d %s %s "
2807 "%d %d %d %d %ld "
2808 "%d %d %d %d %d "
2809 "%d %d"
2810 "\n",
2811 backend->uuid, backend->id,
2812 srv->puid, srv->id, srv_addr,
2813 srv->state, srv->admin, srv->uweight, srv->iweight, srv_time_since_last_change,
2814 srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state,
2815 bk_f_forced_id, srv_f_forced_id);
2816
2817 srv = srv->next;
2818 }
2819}
2820
Baptiste Assmann9b6857e2015-09-18 14:49:12 +02002821/* Parses backend list and simply report backend names */
2822static int stats_dump_backend_to_buffer(struct stream_interface *si)
2823{
2824 extern struct proxy *proxy;
2825 struct proxy *curproxy;
2826
2827 chunk_reset(&trash);
2828 chunk_printf(&trash, "# name\n");
2829
2830 for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) {
2831 /* looking for backends only */
2832 if (!(curproxy->cap & PR_CAP_BE))
2833 continue;
2834
2835 /* we don't want to list a backend which is bound to this process */
2836 if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1))))
2837 continue;
2838
2839 chunk_appendf(&trash, "%s\n", curproxy->id);
2840 }
2841
2842 if (bi_putchk(si_ic(si), &trash) == -1) {
2843 si_applet_cant_put(si);
2844 return 0;
2845 }
2846
2847 return 1;
2848}
2849
Baptiste Assmann28289462015-07-03 08:01:20 +02002850/* Parses backend list or simply use backend name provided by the user to return
2851 * states of servers to stdout.
2852 */
2853static int stats_dump_servers_state_to_buffer(struct stream_interface *si)
2854{
2855 struct appctx *appctx = __objt_appctx(si->end);
2856 extern struct proxy *proxy;
2857 struct proxy *curproxy;
2858
2859 chunk_reset(&trash);
2860
2861 chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES);
2862
2863 if (appctx->ctx.server_state.backend) {
2864 dump_servers_state(appctx->ctx.server_state.backend, &trash);
2865 }
2866 else {
2867 for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) {
2868 /* servers are only in backends */
2869 if (!(curproxy->cap & PR_CAP_BE))
2870 continue;
2871
2872 dump_servers_state(curproxy, &trash);
2873 }
2874 }
2875
2876 if (bi_putchk(si_ic(si), &trash) == -1) {
2877 si_applet_cant_put(si);
2878 return 0;
2879 }
2880
2881 return 1;
2882}
2883
Willy Tarreau12833bb2014-01-28 16:49:56 +01002884/* This function dumps memory usage information onto the stream interface's
2885 * read buffer. It returns 0 as long as it does not complete, non-zero upon
2886 * completion. No state is used.
2887 */
2888static int stats_dump_pools_to_buffer(struct stream_interface *si)
2889{
2890 dump_pools_to_trash();
Willy Tarreaubc18da12015-03-13 14:00:47 +01002891 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02002892 si_applet_cant_put(si);
Willy Tarreau12833bb2014-01-28 16:49:56 +01002893 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01002894 }
Willy Tarreau12833bb2014-01-28 16:49:56 +01002895 return 1;
2896}
2897
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002898/* Dumps a frontend's line to the trash for the current proxy <px> and uses
2899 * the state from stream interface <si>. The caller is responsible for clearing
2900 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
Cyril Bonté70be45d2010-10-12 00:14:35 +02002901 */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002902static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
Cyril Bonté70be45d2010-10-12 00:14:35 +02002903{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002904 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002905 int i;
Cyril Bonté70be45d2010-10-12 00:14:35 +02002906
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002907 if (!(px->cap & PR_CAP_FE))
2908 return 0;
Cyril Bonté70be45d2010-10-12 00:14:35 +02002909
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002910 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE)))
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002911 return 0;
2912
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002913 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002914 chunk_appendf(&trash,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002915 /* name, queue */
2916 "<tr class=\"frontend\">");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002917
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002918 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002919 /* Column sub-heading for Enable or Disable server */
2920 chunk_appendf(&trash, "<td></td>");
2921 }
Cyril Bonté70be45d2010-10-12 00:14:35 +02002922
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002923 chunk_appendf(&trash,
2924 "<td class=ac>"
2925 "<a name=\"%s/Frontend\"></a>"
2926 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
2927 "<td colspan=3></td>"
2928 "",
2929 px->id, px->id);
Cyril Bonté70be45d2010-10-12 00:14:35 +02002930
Willy Tarreau466c9b52012-12-23 02:25:03 +01002931 chunk_appendf(&trash,
2932 /* sessions rate : current */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002933 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01002934 "<tr><th>Current connection rate:</th><td>%s/s</td></tr>"
2935 "<tr><th>Current session rate:</th><td>%s/s</td></tr>"
2936 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002937 U2H(read_freq_ctr(&px->fe_sess_per_sec)),
2938 U2H(read_freq_ctr(&px->fe_conn_per_sec)),
2939 U2H(read_freq_ctr(&px->fe_sess_per_sec)));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002940
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002941 if (px->mode == PR_MODE_HTTP)
2942 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01002943 "<tr><th>Current request rate:</th><td>%s/s</td></tr>",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002944 U2H(read_freq_ctr(&px->fe_req_per_sec)));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002945
2946 chunk_appendf(&trash,
2947 "</table></div></u></td>"
2948 /* sessions rate : max */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002949 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01002950 "<tr><th>Max connection rate:</th><td>%s/s</td></tr>"
2951 "<tr><th>Max session rate:</th><td>%s/s</td></tr>"
2952 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002953 U2H(px->fe_counters.sps_max),
2954 U2H(px->fe_counters.cps_max),
2955 U2H(px->fe_counters.sps_max));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002956
2957 if (px->mode == PR_MODE_HTTP)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002958 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01002959 "<tr><th>Max request rate:</th><td>%s/s</td></tr>",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002960 U2H(px->fe_counters.p.http.rps_max));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002961
2962 chunk_appendf(&trash,
2963 "</table></div></u></td>"
2964 /* sessions rate : limit */
2965 "<td>%s</td>",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002966 LIM2A(px->fe_sps_lim, "-"));
Cyril Bonté70be45d2010-10-12 00:14:35 +02002967
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002968 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002969 /* sessions: current, max, limit, total */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002970 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002971 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01002972 "<tr><th>Cum. connections:</th><td>%s</td></tr>"
2973 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002974 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002975 U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn),
2976 U2H(px->fe_counters.cum_sess),
2977 U2H(px->fe_counters.cum_conn),
2978 U2H(px->fe_counters.cum_sess));
Cyril Bonté70be45d2010-10-12 00:14:35 +02002979
Willy Tarreau466c9b52012-12-23 02:25:03 +01002980 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002981 if (px->mode == PR_MODE_HTTP) {
Willy Tarreau466c9b52012-12-23 02:25:03 +01002982 chunk_appendf(&trash,
2983 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
2984 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
2985 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
2986 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
2987 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
2988 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
2989 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
2990 "<tr><th>- other responses:</th><td>%s</td></tr>"
2991 "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
2992 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002993 U2H(px->fe_counters.p.http.cum_req),
2994 U2H(px->fe_counters.p.http.rsp[1]),
2995 U2H(px->fe_counters.p.http.rsp[2]),
2996 U2H(px->fe_counters.p.http.comp_rsp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002997 px->fe_counters.p.http.rsp[2] ?
Willy Tarreau466c9b52012-12-23 02:25:03 +01002998 (int)(100*px->fe_counters.p.http.comp_rsp/px->fe_counters.p.http.rsp[2]) : 0,
Willy Tarreau56adcf22012-12-23 18:00:29 +01002999 U2H(px->fe_counters.p.http.rsp[3]),
3000 U2H(px->fe_counters.p.http.rsp[4]),
3001 U2H(px->fe_counters.p.http.rsp[5]),
3002 U2H(px->fe_counters.p.http.rsp[0]),
3003 U2H(px->fe_counters.intercepted_req));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003004 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003005
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003006 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01003007 "</table></div></u></td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003008 /* sessions: lbtot, lastsess */
3009 "<td></td><td></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003010 /* bytes : in */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003011 "<td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003012 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003013 U2H(px->fe_counters.bytes_in));
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003014
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003015 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003016 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
Willy Tarreau4e5d58e2015-07-04 14:35:15 +02003017 "<td>%s%s<div class=tips><table class=det>"
3018 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
3019 "<tr><th>Compression in:</th><td>%s</td></tr>"
3020 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
3021 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
3022 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
3023 "</table></div>%s</td>",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003024 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003025 U2H(px->fe_counters.bytes_out),
Willy Tarreau4e5d58e2015-07-04 14:35:15 +02003026 U2H(px->fe_counters.bytes_out),
3027 U2H(px->fe_counters.comp_in),
3028 U2H(px->fe_counters.comp_out),
3029 px->fe_counters.comp_in ? (int)(px->fe_counters.comp_out * 100 / px->fe_counters.comp_in) : 0,
3030 U2H(px->fe_counters.comp_byp),
3031 U2H(px->fe_counters.comp_in - px->fe_counters.comp_out),
3032 px->fe_counters.bytes_out ? (int)((px->fe_counters.comp_in - px->fe_counters.comp_out) * 100 / px->fe_counters.bytes_out) : 0,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003033 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":"");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003034
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003035 chunk_appendf(&trash,
3036 /* denied: req, resp */
3037 "<td>%s</td><td>%s</td>"
3038 /* errors : request, connect, response */
3039 "<td>%s</td><td></td><td></td>"
3040 /* warnings: retries, redispatches */
3041 "<td></td><td></td>"
3042 /* server status : reflect frontend status */
3043 "<td class=ac>%s</td>"
3044 /* rest of server: nothing */
3045 "<td class=ac colspan=8></td></tr>"
3046 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003047 U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp),
3048 U2H(px->fe_counters.failed_req),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003049 px->state == PR_STREADY ? "OPEN" :
3050 px->state == PR_STFULL ? "FULL" : "STOP");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003051 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003052 else { /* CSV mode */
3053 chunk_appendf(&trash,
3054 /* pxid, name, queue cur, queue max, */
3055 "%s,FRONTEND,,,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003056 /* sessions : current, max, limit, total */
3057 "%d,%d,%d,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003058 /* bytes : in, out */
3059 "%lld,%lld,"
3060 /* denied: req, resp */
3061 "%lld,%lld,"
3062 /* errors : request, connect, response */
3063 "%lld,,,"
3064 /* warnings: retries, redispatches */
3065 ",,"
3066 /* server status : reflect frontend status */
3067 "%s,"
3068 /* rest of server: nothing */
3069 ",,,,,,,,"
3070 /* pid, iid, sid, throttle, lbtot, tracked, type */
3071 "%d,%d,0,,,,%d,"
3072 /* rate, rate_lim, rate_max */
3073 "%u,%u,%u,"
3074 /* check_status, check_code, check_duration */
3075 ",,,",
3076 px->id,
3077 px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess,
3078 px->fe_counters.bytes_in, px->fe_counters.bytes_out,
3079 px->fe_counters.denied_req, px->fe_counters.denied_resp,
3080 px->fe_counters.failed_req,
3081 px->state == PR_STREADY ? "OPEN" :
3082 px->state == PR_STFULL ? "FULL" : "STOP",
3083 relative_pid, px->uuid, STATS_TYPE_FE,
3084 read_freq_ctr(&px->fe_sess_per_sec),
3085 px->fe_sps_lim, px->fe_counters.sps_max);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003086
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003087 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3088 if (px->mode == PR_MODE_HTTP) {
3089 for (i=1; i<6; i++)
3090 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]);
3091 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]);
3092 }
3093 else
3094 chunk_appendf(&trash, ",,,,,,");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003095
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003096 /* failed health analyses */
3097 chunk_appendf(&trash, ",");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003098
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003099 /* requests : req_rate, req_rate_max, req_tot, */
3100 chunk_appendf(&trash, "%u,%u,%lld,",
3101 read_freq_ctr(&px->fe_req_per_sec),
3102 px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req);
3103
3104 /* errors: cli_aborts, srv_aborts */
3105 chunk_appendf(&trash, ",,");
3106
3107 /* compression: in, out, bypassed */
3108 chunk_appendf(&trash, "%lld,%lld,%lld,",
3109 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
3110
3111 /* compression: comp_rsp */
3112 chunk_appendf(&trash, "%lld,",
3113 px->fe_counters.p.http.comp_rsp);
3114
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003115 /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */
3116 chunk_appendf(&trash, ",,,,,,,");
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003117
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003118 /* finish with EOL */
3119 chunk_appendf(&trash, "\n");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003120 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003121 return 1;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003122}
3123
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003124/* Dumps a line for listener <l> and proxy <px> to the trash and uses the state
3125 * from stream interface <si>, and stats flags <flags>. The caller is responsible
3126 * for clearing the trash if needed. Returns non-zero if it emits anything, zero
3127 * otherwise.
Willy Tarreau91861262007-10-17 17:06:05 +02003128 */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003129static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags)
Willy Tarreau91861262007-10-17 17:06:05 +02003130{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003131 struct appctx *appctx = __objt_appctx(si->end);
3132
3133 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003134 chunk_appendf(&trash, "<tr class=socket>");
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003135 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003136 /* Column sub-heading for Enable or Disable server */
3137 chunk_appendf(&trash, "<td></td>");
3138 }
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003139 chunk_appendf(&trash,
3140 /* frontend name, listener name */
3141 "<td class=ac><a name=\"%s/+%s\"></a>%s"
3142 "<a class=lfsb href=\"#%s/+%s\">%s</a>"
3143 "",
3144 px->id, l->name,
3145 (flags & ST_SHLGNDS)?"<u>":"",
3146 px->id, l->name, l->name);
Willy Tarreau91861262007-10-17 17:06:05 +02003147
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003148 if (flags & ST_SHLGNDS) {
3149 char str[INET6_ADDRSTRLEN];
3150 int port;
Willy Tarreau91861262007-10-17 17:06:05 +02003151
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003152 chunk_appendf(&trash, "<div class=tips>");
Willy Tarreau91861262007-10-17 17:06:05 +02003153
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003154 port = get_host_port(&l->addr);
3155 switch (addr_to_str(&l->addr, str, sizeof(str))) {
3156 case AF_INET:
3157 chunk_appendf(&trash, "IPv4: %s:%d, ", str, port);
3158 break;
3159 case AF_INET6:
3160 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port);
3161 break;
3162 case AF_UNIX:
3163 chunk_appendf(&trash, "unix, ");
3164 break;
3165 case -1:
3166 chunk_appendf(&trash, "(%s), ", strerror(errno));
3167 break;
3168 }
Willy Tarreau91861262007-10-17 17:06:05 +02003169
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003170 /* id */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003171 chunk_appendf(&trash, "id: %d</div>", l->luid);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003172 }
Willy Tarreau91861262007-10-17 17:06:05 +02003173
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003174 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003175 /* queue */
3176 "%s</td><td colspan=3></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003177 /* sessions rate: current, max, limit */
3178 "<td colspan=3>&nbsp;</td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003179 /* sessions: current, max, limit, total, lbtot, lastsess */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003180 "<td>%s</td><td>%s</td><td>%s</td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003181 "<td>%s</td><td>&nbsp;</td><td>&nbsp;</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003182 /* bytes: in, out */
3183 "<td>%s</td><td>%s</td>"
3184 "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003185 (flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003186 U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn),
3187 U2H(l->counters->cum_conn), U2H(l->counters->bytes_in), U2H(l->counters->bytes_out));
Willy Tarreau56a560a2009-09-22 19:27:35 +02003188
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003189 chunk_appendf(&trash,
3190 /* denied: req, resp */
3191 "<td>%s</td><td>%s</td>"
3192 /* errors: request, connect, response */
3193 "<td>%s</td><td></td><td></td>"
3194 /* warnings: retries, redispatches */
3195 "<td></td><td></td>"
3196 /* server status: reflect listener status */
3197 "<td class=ac>%s</td>"
3198 /* rest of server: nothing */
3199 "<td class=ac colspan=8></td></tr>"
3200 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003201 U2H(l->counters->denied_req), U2H(l->counters->denied_resp),
3202 U2H(l->counters->failed_req),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003203 (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
3204 }
3205 else { /* CSV mode */
3206 chunk_appendf(&trash,
3207 /* pxid, name, queue cur, queue max, */
3208 "%s,%s,,,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003209 /* sessions: current, max, limit, total */
3210 "%d,%d,%d,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003211 /* bytes: in, out */
3212 "%lld,%lld,"
3213 /* denied: req, resp */
3214 "%lld,%lld,"
3215 /* errors: request, connect, response */
3216 "%lld,,,"
3217 /* warnings: retries, redispatches */
3218 ",,"
3219 /* server status: reflect listener status */
3220 "%s,"
3221 /* rest of server: nothing */
3222 ",,,,,,,,"
3223 /* pid, iid, sid, throttle, lbtot, tracked, type */
3224 "%d,%d,%d,,,,%d,"
3225 /* rate, rate_lim, rate_max */
3226 ",,,"
3227 /* check_status, check_code, check_duration */
3228 ",,,"
3229 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3230 ",,,,,,"
3231 /* failed health analyses */
3232 ","
3233 /* requests : req_rate, req_rate_max, req_tot, */
3234 ",,,"
3235 /* errors: cli_aborts, srv_aborts */
3236 ",,"
3237 /* compression: in, out, bypassed, comp_rsp */
3238 ",,,,"
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003239 /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */
3240 ",,,,,,,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003241 "\n",
3242 px->id, l->name,
3243 l->nbconn, l->counters->conn_max,
3244 l->maxconn, l->counters->cum_conn,
3245 l->counters->bytes_in, l->counters->bytes_out,
3246 l->counters->denied_req, l->counters->denied_resp,
3247 l->counters->failed_req,
3248 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
3249 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
3250 }
3251 return 1;
3252}
Willy Tarreau91861262007-10-17 17:06:05 +02003253
Simon Horman4d2eab62015-04-23 14:51:26 +09003254enum srv_stats_state {
3255 SRV_STATS_STATE_DOWN = 0,
3256 SRV_STATS_STATE_DOWN_AGENT,
3257 SRV_STATS_STATE_GOING_UP,
3258 SRV_STATS_STATE_UP_GOING_DOWN,
3259 SRV_STATS_STATE_UP,
3260 SRV_STATS_STATE_NOLB_GOING_DOWN,
3261 SRV_STATS_STATE_NOLB,
3262 SRV_STATS_STATE_DRAIN_GOING_DOWN,
3263 SRV_STATS_STATE_DRAIN,
Simon Hormanb167b6b2015-04-23 14:51:29 +09003264 SRV_STATS_STATE_DRAIN_AGENT,
Simon Horman4d2eab62015-04-23 14:51:26 +09003265 SRV_STATS_STATE_NO_CHECK,
3266
3267 SRV_STATS_STATE_COUNT, /* Must be last */
3268};
3269
Simon Horman837bfa72015-04-23 14:51:27 +09003270enum srv_stats_colour {
3271 SRV_STATS_COLOUR_DOWN = 0,
3272 SRV_STATS_COLOUR_GOING_UP,
3273 SRV_STATS_COLOUR_GOING_DOWN,
3274 SRV_STATS_COLOUR_UP,
3275 SRV_STATS_COLOUR_NOLB,
3276 SRV_STATS_COLOUR_DRAINING,
3277 SRV_STATS_COLOUR_NO_CHECK,
3278
3279 SRV_STATS_COLOUR_COUNT, /* Must be last */
3280};
3281
3282static const char *srv_stats_colour_st[SRV_STATS_COLOUR_COUNT] = {
3283 [SRV_STATS_COLOUR_DOWN] = "down",
3284 [SRV_STATS_COLOUR_GOING_UP] = "going_up",
3285 [SRV_STATS_COLOUR_GOING_DOWN] = "going_down",
3286 [SRV_STATS_COLOUR_UP] = "up",
3287 [SRV_STATS_COLOUR_NOLB] = "nolb",
3288 [SRV_STATS_COLOUR_DRAINING] = "draining",
3289 [SRV_STATS_COLOUR_NO_CHECK] = "no_check",
3290};
3291
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003292/* Dumps a line for server <sv> and proxy <px> to the trash and uses the state
3293 * from stream interface <si>, stats flags <flags>, and server state <state>.
3294 * The caller is responsible for clearing the trash if needed. Returns non-zero
Simon Horman4d2eab62015-04-23 14:51:26 +09003295 * if it emits anything, zero otherwise.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003296 */
Simon Horman4d2eab62015-04-23 14:51:26 +09003297static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv,
Simon Horman837bfa72015-04-23 14:51:27 +09003298 enum srv_stats_state state, enum srv_stats_colour colour)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003299{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003300 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau32091232014-05-16 13:52:00 +02003301 struct server *via, *ref;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003302 char str[INET6_ADDRSTRLEN];
3303 struct chunk src;
3304 int i;
Willy Tarreau91861262007-10-17 17:06:05 +02003305
Willy Tarreau32091232014-05-16 13:52:00 +02003306 /* we have "via" which is the tracked server as described in the configuration,
3307 * and "ref" which is the checked server and the end of the chain.
3308 */
3309 via = sv->track ? sv->track : sv;
3310 ref = via;
3311 while (ref->track)
3312 ref = ref->track;
3313
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003314 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Simon Horman4d2eab62015-04-23 14:51:26 +09003315 static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = {
3316 [SRV_STATS_STATE_DOWN] = "DOWN",
3317 [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)",
3318 [SRV_STATS_STATE_GOING_UP] = "DN %d/%d &uarr;",
3319 [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d &darr;",
3320 [SRV_STATS_STATE_UP] = "UP",
3321 [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d &darr;",
3322 [SRV_STATS_STATE_NOLB] = "NOLB",
3323 [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d &darr;",
3324 [SRV_STATS_STATE_DRAIN] = "DRAIN",
Simon Hormanb167b6b2015-04-23 14:51:29 +09003325 [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)",
Simon Horman4d2eab62015-04-23 14:51:26 +09003326 [SRV_STATS_STATE_NO_CHECK] = "<i>no check</i>",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003327 };
Willy Tarreau91861262007-10-17 17:06:05 +02003328
Willy Tarreaua0066dd2014-05-16 11:25:16 +02003329 if (sv->admin & SRV_ADMF_MAINT)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003330 chunk_appendf(&trash, "<tr class=\"maintain\">");
3331 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003332 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09003333 "<tr class=\"%s_%s\">",
3334 (sv->flags & SRV_F_BACKUP) ? "backup" : "active", srv_stats_colour_st[colour]);
Willy Tarreau91861262007-10-17 17:06:05 +02003335
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003336 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003337 chunk_appendf(&trash,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003338 "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
3339 sv->id);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003340
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003341 chunk_appendf(&trash,
3342 "<td class=ac><a name=\"%s/%s\"></a>%s"
3343 "<a class=lfsb href=\"#%s/%s\">%s</a>"
3344 "",
3345 px->id, sv->id,
3346 (flags & ST_SHLGNDS) ? "<u>" : "",
3347 px->id, sv->id, sv->id);
Willy Tarreau91861262007-10-17 17:06:05 +02003348
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003349 if (flags & ST_SHLGNDS) {
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003350 chunk_appendf(&trash, "<div class=tips>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003351
3352 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
3353 case AF_INET:
3354 chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr));
3355 break;
3356 case AF_INET6:
3357 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr));
3358 break;
3359 case AF_UNIX:
3360 chunk_appendf(&trash, "unix, ");
3361 break;
3362 case -1:
3363 chunk_appendf(&trash, "(%s), ", strerror(errno));
3364 break;
3365 default: /* address family not supported */
3366 break;
Willy Tarreau55bb8452007-10-17 18:44:57 +02003367 }
Willy Tarreau91861262007-10-17 17:06:05 +02003368
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003369 /* id */
3370 chunk_appendf(&trash, "id: %d", sv->puid);
Willy Tarreau91861262007-10-17 17:06:05 +02003371
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003372 /* cookie */
3373 if (sv->cookie) {
3374 chunk_appendf(&trash, ", cookie: '");
Willy Tarreau5031e6a2007-10-18 11:05:48 +02003375
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003376 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
3377 chunk_htmlencode(&trash, &src);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003378
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003379 chunk_appendf(&trash, "'");
Cyril Bonté70be45d2010-10-12 00:14:35 +02003380 }
3381
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003382 chunk_appendf(&trash, "</div>");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003383 }
Willy Tarreau91861262007-10-17 17:06:05 +02003384
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003385 chunk_appendf(&trash,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003386 /* queue : current, max, limit */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003387 "%s</td><td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003388 /* sessions rate : current, max, limit */
3389 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003390 "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003391 (flags & ST_SHLGNDS) ? "</u>" : "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003392 U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"),
3393 U2H(read_freq_ctr(&sv->sess_per_sec)), U2H(sv->counters.sps_max));
Willy Tarreau91861262007-10-17 17:06:05 +02003394
Willy Tarreau466c9b52012-12-23 02:25:03 +01003395
3396 chunk_appendf(&trash,
3397 /* sessions: current, max, limit, total */
3398 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003399 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01003400 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
3401 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003402 U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"),
3403 U2H(sv->counters.cum_sess),
3404 U2H(sv->counters.cum_sess));
Willy Tarreau91861262007-10-17 17:06:05 +02003405
Willy Tarreau466c9b52012-12-23 02:25:03 +01003406 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
3407 if (px->mode == PR_MODE_HTTP) {
3408 unsigned long long tot;
3409 for (tot = i = 0; i < 6; i++)
3410 tot += sv->counters.p.http.rsp[i];
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003411
Willy Tarreau466c9b52012-12-23 02:25:03 +01003412 chunk_appendf(&trash,
3413 "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>"
3414 "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3415 "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3416 "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3417 "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3418 "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3419 "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3420 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003421 U2H(tot),
3422 U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0,
3423 U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0,
3424 U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0,
3425 U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0,
3426 U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0,
3427 U2H(sv->counters.p.http.rsp[0]), tot ? (int)(100*sv->counters.p.http.rsp[0] / tot) : 0);
Willy Tarreau91861262007-10-17 17:06:05 +02003428 }
Willy Tarreau91861262007-10-17 17:06:05 +02003429
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003430 chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>");
3431 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)));
3432 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)));
3433 if (px->mode == PR_MODE_HTTP)
3434 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)));
3435 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)));
3436
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003437 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01003438 "</table></div></u></td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003439 /* sessions: lbtot, last */
3440 "<td>%s</td><td>%s</td>",
3441 U2H(sv->counters.cum_lbconn),
3442 human_time(srv_lastsession(sv), 1));
Willy Tarreau91861262007-10-17 17:06:05 +02003443
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003444 chunk_appendf(&trash,
3445 /* bytes : in, out */
3446 "<td>%s</td><td>%s</td>"
3447 /* denied: req, resp */
3448 "<td></td><td>%s</td>"
3449 /* errors : request, connect */
3450 "<td></td><td>%s</td>"
3451 /* errors : response */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003452 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003453 /* warnings: retries, redispatches */
3454 "<td>%lld</td><td>%lld</td>"
3455 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003456 U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out),
3457 U2H(sv->counters.failed_secu),
3458 U2H(sv->counters.failed_conns),
3459 U2H(sv->counters.failed_resp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003460 sv->counters.cli_aborts,
3461 sv->counters.srv_aborts,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003462 sv->counters.retries, sv->counters.redispatches);
3463
3464 /* status, lest check */
3465 chunk_appendf(&trash, "<td class=ac>");
3466
Willy Tarreau20125212014-05-13 19:44:56 +02003467 if (sv->admin & SRV_ADMF_MAINT) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003468 chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1));
3469 chunk_appendf(&trash, "MAINT");
3470 }
Simon Horman0766e442014-11-12 15:55:54 +09003471 else if ((ref->agent.state & CHK_ST_ENABLED) && !(sv->agent.health) && (ref->state == SRV_ST_STOPPED)) {
Willy Tarreaucf2924b2014-05-23 12:15:15 +02003472 chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1));
Willy Tarreauac497072014-05-29 01:04:35 +02003473 /* DOWN (agent) */
3474 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 Tarreaucf2924b2014-05-23 12:15:15 +02003475 }
Willy Tarreauff5ae352013-12-11 20:36:34 +01003476 else if (ref->check.state & CHK_ST_ENABLED) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003477 chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1));
3478 chunk_appendf(&trash,
3479 srv_hlt_st[state],
Willy Tarreau892337c2014-05-13 23:41:20 +02003480 (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health),
3481 (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise));
Willy Tarreau55bb8452007-10-17 18:44:57 +02003482 }
Willy Tarreau91861262007-10-17 17:06:05 +02003483
Willy Tarreaucf2924b2014-05-23 12:15:15 +02003484 if ((sv->state == SRV_ST_STOPPED) &&
3485 ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) {
3486 chunk_appendf(&trash,
3487 "</td><td class=ac><u> %s%s",
3488 (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "",
3489 get_check_status_info(sv->agent.status));
3490
3491 if (sv->agent.status >= HCHK_STATUS_L57DATA)
3492 chunk_appendf(&trash, "/%d", sv->agent.code);
3493
3494 if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0)
3495 chunk_appendf(&trash, " in %lums", sv->agent.duration);
3496
3497 chunk_appendf(&trash, "<div class=tips>%s",
3498 get_check_status_description(sv->agent.status));
3499 if (*sv->agent.desc) {
3500 chunk_appendf(&trash, ": ");
3501 chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc));
3502 chunk_htmlencode(&trash, &src);
3503 }
3504 chunk_appendf(&trash, "</div></u>");
3505 }
3506 else if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) {
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003507 chunk_appendf(&trash,
3508 "</td><td class=ac><u> %s%s",
Willy Tarreau2c115e52013-12-11 19:41:16 +01003509 (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003510 get_check_status_info(sv->check.status));
3511
3512 if (sv->check.status >= HCHK_STATUS_L57DATA)
3513 chunk_appendf(&trash, "/%d", sv->check.code);
3514
3515 if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0)
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003516 chunk_appendf(&trash, " in %lums", sv->check.duration);
3517
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003518 chunk_appendf(&trash, "<div class=tips>%s",
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003519 get_check_status_description(sv->check.status));
3520 if (*sv->check.desc) {
3521 chunk_appendf(&trash, ": ");
3522 chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc));
3523 chunk_htmlencode(&trash, &src);
3524 }
3525 chunk_appendf(&trash, "</div></u>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003526 }
3527 else
3528 chunk_appendf(&trash, "</td><td>");
3529
3530 chunk_appendf(&trash,
3531 /* weight */
3532 "</td><td class=ac>%d</td>"
3533 /* act, bck */
3534 "<td class=ac>%s</td><td class=ac>%s</td>"
3535 "",
3536 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreauc93cd162014-05-13 15:54:22 +02003537 (sv->flags & SRV_F_BACKUP) ? "-" : "Y",
3538 (sv->flags & SRV_F_BACKUP) ? "Y" : "-");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003539
3540 /* check failures: unique, fatal, down time */
Willy Tarreauff5ae352013-12-11 20:36:34 +01003541 if (sv->check.state & CHK_ST_ENABLED) {
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003542 chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003543
3544 if (ref->observe)
3545 chunk_appendf(&trash, "/%lld", ref->counters.failed_hana);
3546
3547 chunk_appendf(&trash,
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003548 "<div class=tips>Failed Health Checks%s</div></u></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003549 "<td>%lld</td><td>%s</td>"
3550 "",
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003551 ref->observe ? "/Health Analyses" : "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003552 ref->counters.down_trans, human_time(srv_downtime(sv), 1));
3553 }
Willy Tarreaua0066dd2014-05-16 11:25:16 +02003554 else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) {
3555 /* tracking a server */
3556 chunk_appendf(&trash,
3557 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s</a></td>",
Willy Tarreau32091232014-05-16 13:52:00 +02003558 via->proxy->id, via->id, via->proxy->id, via->id);
Willy Tarreauf4659942013-11-28 10:50:06 +01003559 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003560 else
3561 chunk_appendf(&trash, "<td colspan=3></td>");
3562
3563 /* throttle */
Willy Tarreau892337c2014-05-13 23:41:20 +02003564 if (sv->state == SRV_ST_STARTING && !server_is_draining(sv))
Willy Tarreaud32c3992013-11-21 15:30:45 +01003565 chunk_appendf(&trash, "<td class=ac>%d %%</td></tr>\n", server_throttle_rate(sv));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003566 else
3567 chunk_appendf(&trash, "<td class=ac>-</td></tr>\n");
3568 }
3569 else { /* CSV mode */
Thierry FOURNIERbe1ccae2015-05-28 16:02:01 +02003570 struct chunk *out = get_trash_chunk();
Simon Horman4d2eab62015-04-23 14:51:26 +09003571 static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = {
3572 [SRV_STATS_STATE_DOWN] = "DOWN,",
3573 [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent),",
3574 [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d,",
3575 [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d,",
3576 [SRV_STATS_STATE_UP] = "UP,",
3577 [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d,",
3578 [SRV_STATS_STATE_NOLB] = "NOLB,",
3579 [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d,",
3580 [SRV_STATS_STATE_DRAIN] = "DRAIN,",
Simon Hormanb167b6b2015-04-23 14:51:29 +09003581 [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)",
Simon Horman4d2eab62015-04-23 14:51:26 +09003582 [SRV_STATS_STATE_NO_CHECK] = "no check,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003583 };
3584
3585 chunk_appendf(&trash,
3586 /* pxid, name */
3587 "%s,%s,"
3588 /* queue : current, max */
3589 "%d,%d,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003590 /* sessions : current, max, limit, total */
3591 "%d,%d,%s,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003592 /* bytes : in, out */
3593 "%lld,%lld,"
3594 /* denied: req, resp */
3595 ",%lld,"
3596 /* errors : request, connect, response */
3597 ",%lld,%lld,"
3598 /* warnings: retries, redispatches */
3599 "%lld,%lld,"
3600 "",
3601 px->id, sv->id,
3602 sv->nbpend, sv->counters.nbpend_max,
Willy Tarreau56adcf22012-12-23 18:00:29 +01003603 sv->cur_sess, sv->counters.cur_sess_max, LIM2A(sv->maxconn, ""), sv->counters.cum_sess,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003604 sv->counters.bytes_in, sv->counters.bytes_out,
3605 sv->counters.failed_secu,
3606 sv->counters.failed_conns, sv->counters.failed_resp,
3607 sv->counters.retries, sv->counters.redispatches);
3608
3609 /* status */
Willy Tarreaua0066dd2014-05-16 11:25:16 +02003610 if (sv->admin & SRV_ADMF_IMAINT)
Willy Tarreau32091232014-05-16 13:52:00 +02003611 chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id);
Willy Tarreaua0066dd2014-05-16 11:25:16 +02003612 else if (sv->admin & SRV_ADMF_MAINT)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003613 chunk_appendf(&trash, "MAINT,");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003614 else
3615 chunk_appendf(&trash,
3616 srv_hlt_st[state],
Willy Tarreau892337c2014-05-13 23:41:20 +02003617 (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health),
3618 (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003619
3620 chunk_appendf(&trash,
3621 /* weight, active, backup */
3622 "%d,%d,%d,"
3623 "",
3624 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreauc93cd162014-05-13 15:54:22 +02003625 (sv->flags & SRV_F_BACKUP) ? 0 : 1,
3626 (sv->flags & SRV_F_BACKUP) ? 1 : 0);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003627
3628 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreauff5ae352013-12-11 20:36:34 +01003629 if (sv->check.state & CHK_ST_ENABLED)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003630 chunk_appendf(&trash,
3631 "%lld,%lld,%d,%d,",
3632 sv->counters.failed_checks, sv->counters.down_trans,
3633 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
3634 else
3635 chunk_appendf(&trash, ",,,,");
3636
3637 /* queue limit, pid, iid, sid, */
3638 chunk_appendf(&trash,
3639 "%s,"
3640 "%d,%d,%d,",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003641 LIM2A(sv->maxqueue, ""),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003642 relative_pid, px->uuid, sv->puid);
3643
3644 /* throttle */
Willy Tarreau892337c2014-05-13 23:41:20 +02003645 if (sv->state == SRV_ST_STARTING && !server_is_draining(sv))
Willy Tarreaud32c3992013-11-21 15:30:45 +01003646 chunk_appendf(&trash, "%d", server_throttle_rate(sv));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003647
3648 /* sessions: lbtot */
3649 chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn);
3650
3651 /* tracked */
3652 if (sv->track)
3653 chunk_appendf(&trash, "%s/%s,",
3654 sv->track->proxy->id, sv->track->id);
3655 else
3656 chunk_appendf(&trash, ",");
3657
3658 /* type */
3659 chunk_appendf(&trash, "%d,", STATS_TYPE_SV);
3660
3661 /* rate */
3662 chunk_appendf(&trash, "%u,,%u,",
3663 read_freq_ctr(&sv->sess_per_sec),
3664 sv->counters.sps_max);
3665
Willy Tarreauff5ae352013-12-11 20:36:34 +01003666 if (sv->check.state & CHK_ST_ENABLED) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003667 /* check_status */
Thierry FOURNIERbe1ccae2015-05-28 16:02:01 +02003668 chunk_appendf(&trash, "%s,", csv_enc(get_check_status_info(sv->check.status), 1, out));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003669
3670 /* check_code */
3671 if (sv->check.status >= HCHK_STATUS_L57DATA)
3672 chunk_appendf(&trash, "%u,", sv->check.code);
3673 else
3674 chunk_appendf(&trash, ",");
3675
3676 /* check_duration */
3677 if (sv->check.status >= HCHK_STATUS_CHECKED)
3678 chunk_appendf(&trash, "%lu,", sv->check.duration);
3679 else
3680 chunk_appendf(&trash, ",");
3681
3682 }
3683 else
3684 chunk_appendf(&trash, ",,,");
3685
3686 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3687 if (px->mode == PR_MODE_HTTP) {
3688 for (i=1; i<6; i++)
3689 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]);
3690
3691 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]);
3692 }
3693 else
3694 chunk_appendf(&trash, ",,,,,,");
3695
3696 /* failed health analyses */
3697 chunk_appendf(&trash, "%lld,", sv->counters.failed_hana);
3698
3699 /* requests : req_rate, req_rate_max, req_tot, */
3700 chunk_appendf(&trash, ",,,");
3701
3702 /* errors: cli_aborts, srv_aborts */
3703 chunk_appendf(&trash, "%lld,%lld,",
3704 sv->counters.cli_aborts, sv->counters.srv_aborts);
3705
3706 /* compression: in, out, bypassed, comp_rsp */
3707 chunk_appendf(&trash, ",,,,");
3708
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003709 /* lastsess */
3710 chunk_appendf(&trash, "%d,", srv_lastsession(sv));
3711
Willy Tarreaua28df3e2014-06-16 16:40:14 +02003712 /* capture of last check and agent statuses */
Thierry FOURNIERbe1ccae2015-05-28 16:02:01 +02003713 chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->check.desc), 1, out) : "");
3714 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 Tarreaua28df3e2014-06-16 16:40:14 +02003715
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003716 /* qtime, ctime, rtime, ttime, */
3717 chunk_appendf(&trash, "%u,%u,%u,%u,",
3718 swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES),
3719 swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES),
3720 swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES),
3721 swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES));
3722
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003723 /* finish with EOL */
3724 chunk_appendf(&trash, "\n");
3725 }
3726 return 1;
3727}
3728
3729/* Dumps a line for backend <px> to the trash for and uses the state from stream
3730 * interface <si> and stats flags <flags>. The caller is responsible for clearing
3731 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
3732 */
3733static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags)
3734{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003735 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003736 struct chunk src;
3737 int i;
3738
3739 if (!(px->cap & PR_CAP_BE))
3740 return 0;
3741
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003742 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE)))
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003743 return 0;
3744
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003745 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003746 chunk_appendf(&trash, "<tr class=\"backend\">");
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003747 if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003748 /* Column sub-heading for Enable or Disable server */
3749 chunk_appendf(&trash, "<td></td>");
3750 }
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003751 chunk_appendf(&trash,
3752 "<td class=ac>"
3753 /* name */
3754 "%s<a name=\"%s/Backend\"></a>"
3755 "<a class=lfsb href=\"#%s/Backend\">Backend</a>"
3756 "",
3757 (flags & ST_SHLGNDS)?"<u>":"",
3758 px->id, px->id);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003759
3760 if (flags & ST_SHLGNDS) {
3761 /* balancing */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003762 chunk_appendf(&trash, "<div class=tips>balancing: %s",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003763 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
3764
3765 /* cookie */
3766 if (px->cookie_name) {
3767 chunk_appendf(&trash, ", cookie: '");
3768 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
3769 chunk_htmlencode(&trash, &src);
3770 chunk_appendf(&trash, "'");
3771 }
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003772 chunk_appendf(&trash, "</div>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003773 }
3774
3775 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003776 "%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003777 /* queue : current, max */
3778 "<td>%s</td><td>%s</td><td></td>"
3779 /* sessions rate : current, max, limit */
3780 "<td>%s</td><td>%s</td><td></td>"
3781 "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003782 (flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003783 U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max),
3784 U2H(read_freq_ctr(&px->be_sess_per_sec)), U2H(px->be_counters.sps_max));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003785
3786 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003787 /* sessions: current, max, limit, total */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003788 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003789 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01003790 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003791 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003792 U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn),
3793 U2H(px->be_counters.cum_conn),
3794 U2H(px->be_counters.cum_conn));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003795
Willy Tarreau466c9b52012-12-23 02:25:03 +01003796 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003797 if (px->mode == PR_MODE_HTTP) {
Willy Tarreau466c9b52012-12-23 02:25:03 +01003798 chunk_appendf(&trash,
3799 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
3800 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
3801 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
3802 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
3803 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
3804 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
3805 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
3806 "<tr><th>- other responses:</th><td>%s</td></tr>"
3807 "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003808 "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01003809 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003810 U2H(px->be_counters.p.http.cum_req),
3811 U2H(px->be_counters.p.http.rsp[1]),
3812 U2H(px->be_counters.p.http.rsp[2]),
3813 U2H(px->be_counters.p.http.comp_rsp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003814 px->be_counters.p.http.rsp[2] ?
Willy Tarreau466c9b52012-12-23 02:25:03 +01003815 (int)(100*px->be_counters.p.http.comp_rsp/px->be_counters.p.http.rsp[2]) : 0,
Willy Tarreau56adcf22012-12-23 18:00:29 +01003816 U2H(px->be_counters.p.http.rsp[3]),
3817 U2H(px->be_counters.p.http.rsp[4]),
3818 U2H(px->be_counters.p.http.rsp[5]),
3819 U2H(px->be_counters.p.http.rsp[0]),
3820 U2H(px->be_counters.intercepted_req));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003821 }
3822
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003823 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)));
3824 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)));
3825 if (px->mode == PR_MODE_HTTP)
3826 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)));
3827 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)));
3828
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003829 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01003830 "</table></div></u></td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003831 /* sessions: lbtot, last */
3832 "<td>%s</td><td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003833 /* bytes: in */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003834 "<td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003835 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003836 U2H(px->be_counters.cum_lbconn),
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003837 human_time(be_lastsession(px), 1),
Willy Tarreau56adcf22012-12-23 18:00:29 +01003838 U2H(px->be_counters.bytes_in));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003839
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003840 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003841 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
Willy Tarreau4e5d58e2015-07-04 14:35:15 +02003842 "<td>%s%s<div class=tips><table class=det>"
3843 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
3844 "<tr><th>Compression in:</th><td>%s</td></tr>"
3845 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
3846 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
3847 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
3848 "</table></div>%s</td>",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003849 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003850 U2H(px->be_counters.bytes_out),
Willy Tarreau4e5d58e2015-07-04 14:35:15 +02003851 U2H(px->be_counters.bytes_out),
3852 U2H(px->be_counters.comp_in),
3853 U2H(px->be_counters.comp_out),
3854 px->be_counters.comp_in ? (int)(px->be_counters.comp_out * 100 / px->be_counters.comp_in) : 0,
3855 U2H(px->be_counters.comp_byp),
3856 U2H(px->be_counters.comp_in - px->be_counters.comp_out),
3857 px->be_counters.bytes_out ? (int)((px->be_counters.comp_in - px->be_counters.comp_out) * 100 / px->be_counters.bytes_out) : 0,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003858 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":"");
3859
3860 chunk_appendf(&trash,
3861 /* denied: req, resp */
3862 "<td>%s</td><td>%s</td>"
3863 /* errors : request, connect */
3864 "<td></td><td>%s</td>"
3865 /* errors : response */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003866 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003867 /* warnings: retries, redispatches */
3868 "<td>%lld</td><td>%lld</td>"
3869 /* backend status: reflect backend status (up/down): we display UP
3870 * if the backend has known working servers or if it has no server at
3871 * all (eg: for stats). Then we display the total weight, number of
3872 * active and backups. */
3873 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
3874 "<td class=ac>%d</td><td class=ac>%d</td>"
3875 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003876 U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp),
3877 U2H(px->be_counters.failed_conns),
3878 U2H(px->be_counters.failed_resp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003879 px->be_counters.cli_aborts,
3880 px->be_counters.srv_aborts,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003881 px->be_counters.retries, px->be_counters.redispatches,
3882 human_time(now.tv_sec - px->last_change, 1),
3883 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
3884 "<font color=\"red\"><b>DOWN</b></font>",
3885 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
3886 px->srv_act, px->srv_bck);
3887
3888 chunk_appendf(&trash,
3889 /* rest of backend: nothing, down transitions, total downtime, throttle */
3890 "<td class=ac>&nbsp;</td><td>%d</td>"
3891 "<td>%s</td>"
3892 "<td></td>"
3893 "</tr>",
3894 px->down_trans,
3895 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
3896 }
3897 else { /* CSV mode */
3898 chunk_appendf(&trash,
3899 /* pxid, name */
3900 "%s,BACKEND,"
3901 /* queue : current, max */
3902 "%d,%d,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003903 /* sessions : current, max, limit, total */
3904 "%d,%d,%d,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003905 /* bytes : in, out */
3906 "%lld,%lld,"
3907 /* denied: req, resp */
3908 "%lld,%lld,"
3909 /* errors : request, connect, response */
3910 ",%lld,%lld,"
3911 /* warnings: retries, redispatches */
3912 "%lld,%lld,"
3913 /* backend status: reflect backend status (up/down): we display UP
3914 * if the backend has known working servers or if it has no server at
3915 * all (eg: for stats). Then we display the total weight, number of
3916 * active and backups. */
3917 "%s,"
3918 "%d,%d,%d,"
3919 /* rest of backend: nothing, down transitions, last change, total downtime */
3920 ",%d,%d,%d,,"
3921 /* pid, iid, sid, throttle, lbtot, tracked, type */
3922 "%d,%d,0,,%lld,,%d,"
3923 /* rate, rate_lim, rate_max, */
3924 "%u,,%u,"
3925 /* check_status, check_code, check_duration */
3926 ",,,",
3927 px->id,
3928 px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max,
3929 px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn,
3930 px->be_counters.bytes_in, px->be_counters.bytes_out,
3931 px->be_counters.denied_req, px->be_counters.denied_resp,
3932 px->be_counters.failed_conns, px->be_counters.failed_resp,
3933 px->be_counters.retries, px->be_counters.redispatches,
3934 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
3935 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
3936 px->srv_act, px->srv_bck,
3937 px->down_trans, (int)(now.tv_sec - px->last_change),
3938 px->srv?be_downtime(px):0,
3939 relative_pid, px->uuid,
3940 px->be_counters.cum_lbconn, STATS_TYPE_BE,
3941 read_freq_ctr(&px->be_sess_per_sec),
3942 px->be_counters.sps_max);
3943
3944 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3945 if (px->mode == PR_MODE_HTTP) {
3946 for (i=1; i<6; i++)
3947 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]);
3948 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]);
3949 }
3950 else
3951 chunk_appendf(&trash, ",,,,,,");
3952
3953 /* failed health analyses */
3954 chunk_appendf(&trash, ",");
3955
3956 /* requests : req_rate, req_rate_max, req_tot, */
3957 chunk_appendf(&trash, ",,,");
3958
3959 /* errors: cli_aborts, srv_aborts */
3960 chunk_appendf(&trash, "%lld,%lld,",
3961 px->be_counters.cli_aborts, px->be_counters.srv_aborts);
3962
3963 /* compression: in, out, bypassed */
3964 chunk_appendf(&trash, "%lld,%lld,%lld,",
3965 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
3966
3967 /* compression: comp_rsp */
3968 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp);
3969
Willy Tarreaua28df3e2014-06-16 16:40:14 +02003970 /* lastsess, last_chk, last_agt, */
3971 chunk_appendf(&trash, "%d,,,", be_lastsession(px));
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003972
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003973 /* qtime, ctime, rtime, ttime, */
3974 chunk_appendf(&trash, "%u,%u,%u,%u,",
3975 swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES),
3976 swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES),
3977 swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES),
3978 swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES));
3979
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003980 /* finish with EOL */
3981 chunk_appendf(&trash, "\n");
3982 }
3983 return 1;
3984}
3985
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003986/* Dumps the HTML table header for proxy <px> to the trash for and uses the state from
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003987 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003988 * for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003989 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003990static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003991{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003992 struct appctx *appctx = __objt_appctx(si->end);
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003993 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
3994
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003995 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003996 /* A form to enable/disable this proxy servers */
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003997
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003998 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003999 scope_txt[0] = 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004000 if (appctx->ctx.stats.scope_len) {
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004001 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau4e4292b2014-11-28 12:18:45 +01004002 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004003 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004004 }
4005
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004006 chunk_appendf(&trash,
Jeff Buchbinder2dbbf4d2014-08-29 15:10:08 -05004007 "<form method=\"post\">");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004008 }
4009
4010 /* print a new table */
4011 chunk_appendf(&trash,
4012 "<table class=\"tbl\" width=\"100%%\">\n"
4013 "<tr class=\"titre\">"
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01004014 "<th class=\"pxname\" width=\"10%%\">");
4015
4016 chunk_appendf(&trash,
4017 "<a name=\"%s\"></a>%s"
4018 "<a class=px href=\"#%s\">%s</a>",
4019 px->id,
4020 (uri->flags & ST_SHLGNDS) ? "<u>":"",
4021 px->id, px->id);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004022
4023 if (uri->flags & ST_SHLGNDS) {
4024 /* cap, mode, id */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02004025 chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004026 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
4027 px->uuid);
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01004028 chunk_appendf(&trash, "</div>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004029 }
4030
4031 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01004032 "%s</th>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004033 "<th class=\"%s\" width=\"90%%\">%s</th>"
4034 "</tr>\n"
4035 "</table>\n"
4036 "<table class=\"tbl\" width=\"100%%\">\n"
4037 "<tr class=\"titre\">",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004038 (uri->flags & ST_SHLGNDS) ? "</u>":"",
4039 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
4040
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004041 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004042 /* Column heading for Enable or Disable server */
4043 chunk_appendf(&trash, "<th rowspan=2 width=1></th>");
Willy Tarreau91861262007-10-17 17:06:05 +02004044 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004045
4046 chunk_appendf(&trash,
4047 "<th rowspan=2></th>"
4048 "<th colspan=3>Queue</th>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05004049 "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004050 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
4051 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
4052 "<th colspan=9>Server</th>"
4053 "</tr>\n"
4054 "<tr class=\"titre\">"
4055 "<th>Cur</th><th>Max</th><th>Limit</th>"
4056 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05004057 "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004058 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
4059 "<th>Resp</th><th>Retr</th><th>Redis</th>"
4060 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
4061 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
4062 "<th>Thrtle</th>\n"
4063 "</tr>");
Willy Tarreau91861262007-10-17 17:06:05 +02004064}
4065
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004066/* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004067 * stream interface <si>. The caller is responsible for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004068 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004069static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004070{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004071 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004072 chunk_appendf(&trash, "</table>");
4073
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004074 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004075 /* close the form used to enable/disable this proxy servers */
4076 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004077 "Choose the action to perform on the checked servers : "
4078 "<select name=action>"
4079 "<option value=\"\"></option>"
Willy Tarreaued7df902014-05-22 18:04:49 +02004080 "<option value=\"ready\">Set state to READY</option>"
4081 "<option value=\"drain\">Set state to DRAIN</option>"
Marco Corte8c27bca2014-07-02 17:49:34 +02004082 "<option value=\"maint\">Set state to MAINT</option>"
Willy Tarreau248a60e2014-05-23 14:59:48 +02004083 "<option value=\"dhlth\">Health: disable checks</option>"
4084 "<option value=\"ehlth\">Health: enable checks</option>"
4085 "<option value=\"hrunn\">Health: force UP</option>"
4086 "<option value=\"hnolb\">Health: force NOLB</option>"
4087 "<option value=\"hdown\">Health: force DOWN</option>"
4088 "<option value=\"dagent\">Agent: disable checks</option>"
4089 "<option value=\"eagent\">Agent: enable checks</option>"
4090 "<option value=\"arunn\">Agent: force UP</option>"
4091 "<option value=\"adown\">Agent: force DOWN</option>"
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004092 "<option value=\"shutdown\">Kill Sessions</option>"
4093 "</select>"
4094 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
4095 "&nbsp;<input type=\"submit\" value=\"Apply\">"
4096 "</form>",
4097 px->uuid);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004098 }
4099
4100 chunk_appendf(&trash, "<p>\n");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004101}
Willy Tarreau91861262007-10-17 17:06:05 +02004102
4103/*
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004104 * Dumps statistics for a proxy. The output is sent to the stream interface's
4105 * input buffer. Returns 0 if it had to stop dumping data because of lack of
4106 * buffer space, or non-zero if everything completed. This function is used
4107 * both by the CLI and the HTTP entry points, and is able to dump the output
4108 * in HTML or CSV formats. If the later, <uri> must be NULL.
Willy Tarreau91861262007-10-17 17:06:05 +02004109 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004110static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02004111{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004112 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau87b09662015-04-03 00:22:06 +02004113 struct stream *s = si_strm(si);
Willy Tarreau2bb4a962014-11-28 11:11:05 +01004114 struct channel *rep = si_ic(si);
Willy Tarreau44267702011-10-28 15:35:33 +02004115 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004116 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02004117
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004118 chunk_reset(&trash);
Willy Tarreau91861262007-10-17 17:06:05 +02004119
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004120 switch (appctx->ctx.stats.px_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01004121 case STAT_PX_ST_INIT:
Willy Tarreau91861262007-10-17 17:06:05 +02004122 /* we are on a new proxy */
Willy Tarreau91861262007-10-17 17:06:05 +02004123 if (uri && uri->scope) {
4124 /* we have a limited scope, we have to check the proxy name */
4125 struct stat_scope *scope;
4126 int len;
4127
4128 len = strlen(px->id);
4129 scope = uri->scope;
4130
4131 while (scope) {
4132 /* match exact proxy name */
4133 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
4134 break;
4135
4136 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02004137 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02004138 break;
4139 scope = scope->next;
4140 }
4141
4142 /* proxy name not found : don't dump anything */
4143 if (scope == NULL)
4144 return 1;
4145 }
4146
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004147 /* if the user has requested a limited output and the proxy
4148 * name does not match, skip it.
4149 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004150 if (appctx->ctx.stats.scope_len &&
Willy Tarreau4e4292b2014-11-28 12:18:45 +01004151 strnistr(px->id, strlen(px->id), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL)
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004152 return 1;
4153
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004154 if ((appctx->ctx.stats.flags & STAT_BOUND) &&
4155 (appctx->ctx.stats.iid != -1) &&
4156 (px->uuid != appctx->ctx.stats.iid))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01004157 return 1;
4158
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004159 appctx->ctx.stats.px_st = STAT_PX_ST_TH;
Willy Tarreau91861262007-10-17 17:06:05 +02004160 /* fall through */
4161
Willy Tarreau295a8372011-03-10 11:25:07 +01004162 case STAT_PX_ST_TH:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004163 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004164 stats_dump_html_px_hdr(si, px, uri);
Willy Tarreaubc18da12015-03-13 14:00:47 +01004165 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004166 si_applet_cant_put(si);
Willy Tarreau55bb8452007-10-17 18:44:57 +02004167 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004168 }
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004169 }
Willy Tarreau91861262007-10-17 17:06:05 +02004170
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004171 appctx->ctx.stats.px_st = STAT_PX_ST_FE;
Willy Tarreau91861262007-10-17 17:06:05 +02004172 /* fall through */
4173
Willy Tarreau295a8372011-03-10 11:25:07 +01004174 case STAT_PX_ST_FE:
Willy Tarreau91861262007-10-17 17:06:05 +02004175 /* print the frontend */
Willy Tarreaubc18da12015-03-13 14:00:47 +01004176 if (stats_dump_fe_stats(si, px)) {
4177 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004178 si_applet_cant_put(si);
Willy Tarreau91861262007-10-17 17:06:05 +02004179 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004180 }
4181 }
Willy Tarreau91861262007-10-17 17:06:05 +02004182
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004183 appctx->ctx.stats.l = px->conf.listeners.n;
4184 appctx->ctx.stats.px_st = STAT_PX_ST_LI;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004185 /* fall through */
4186
Willy Tarreau295a8372011-03-10 11:25:07 +01004187 case STAT_PX_ST_LI:
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004188 /* stats.l has been initialized above */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004189 for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) {
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004190 if (buffer_almost_full(rep->buf)) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004191 si_applet_cant_put(si);
Willy Tarreau4e33d862009-10-11 23:35:10 +02004192 return 0;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004193 }
Willy Tarreau4e33d862009-10-11 23:35:10 +02004194
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004195 l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004196 if (!l->counters)
4197 continue;
4198
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004199 if (appctx->ctx.stats.flags & STAT_BOUND) {
4200 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO)))
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004201 break;
4202
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004203 if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004204 continue;
4205 }
4206
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004207 /* print the frontend */
Willy Tarreaubc18da12015-03-13 14:00:47 +01004208 if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) {
4209 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004210 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004211 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004212 }
4213 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004214 }
4215
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004216 appctx->ctx.stats.sv = px->srv; /* may be NULL */
4217 appctx->ctx.stats.px_st = STAT_PX_ST_SV;
Willy Tarreau91861262007-10-17 17:06:05 +02004218 /* fall through */
4219
Willy Tarreau295a8372011-03-10 11:25:07 +01004220 case STAT_PX_ST_SV:
Willy Tarreau91861262007-10-17 17:06:05 +02004221 /* stats.sv has been initialized above */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004222 for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004223 enum srv_stats_state sv_state;
Simon Horman837bfa72015-04-23 14:51:27 +09004224 enum srv_stats_colour sv_colour;
Willy Tarreau91861262007-10-17 17:06:05 +02004225
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004226 if (buffer_almost_full(rep->buf)) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004227 si_applet_cant_put(si);
Willy Tarreau4e33d862009-10-11 23:35:10 +02004228 return 0;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004229 }
Willy Tarreau4e33d862009-10-11 23:35:10 +02004230
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004231 sv = appctx->ctx.stats.sv;
Willy Tarreau91861262007-10-17 17:06:05 +02004232
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004233 if (appctx->ctx.stats.flags & STAT_BOUND) {
4234 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV)))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01004235 break;
4236
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004237 if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid)
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01004238 continue;
4239 }
4240
Willy Tarreau32091232014-05-16 13:52:00 +02004241 svs = sv;
4242 while (svs->track)
4243 svs = svs->track;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01004244
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004245 if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) {
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004246 if ((svs->check.state & CHK_ST_ENABLED) &&
Simon Horman837bfa72015-04-23 14:51:27 +09004247 (svs->check.health < svs->check.rise + svs->check.fall - 1)) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004248 sv_state = SRV_STATS_STATE_UP_GOING_DOWN;
Simon Horman837bfa72015-04-23 14:51:27 +09004249 sv_colour = SRV_STATS_COLOUR_GOING_DOWN;
4250 } else {
Simon Horman4d2eab62015-04-23 14:51:26 +09004251 sv_state = SRV_STATS_STATE_UP;
Simon Horman837bfa72015-04-23 14:51:27 +09004252 sv_colour = SRV_STATS_COLOUR_UP;
4253 }
Willy Tarreau2ea81932007-11-30 12:04:38 +01004254
Simon Horman4463d192015-04-23 14:51:28 +09004255 if (sv_state == SRV_STATS_STATE_UP && !svs->uweight)
4256 sv_colour = SRV_STATS_COLOUR_DRAINING;
4257
4258 if (sv->admin & SRV_ADMF_DRAIN) {
Simon Hormanb167b6b2015-04-23 14:51:29 +09004259 if (svs->agent.state & CHK_ST_ENABLED)
4260 sv_state = SRV_STATS_STATE_DRAIN_AGENT;
4261 else if (sv_state == SRV_STATS_STATE_UP_GOING_DOWN)
Simon Horman4d2eab62015-04-23 14:51:26 +09004262 sv_state = SRV_STATS_STATE_DRAIN_GOING_DOWN;
Simon Horman4463d192015-04-23 14:51:28 +09004263 else
Simon Horman4d2eab62015-04-23 14:51:26 +09004264 sv_state = SRV_STATS_STATE_DRAIN;
4265 }
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004266
Simon Horman837bfa72015-04-23 14:51:27 +09004267 if (sv_state == SRV_STATS_STATE_UP && !(svs->check.state & CHK_ST_ENABLED)) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004268 sv_state = SRV_STATS_STATE_NO_CHECK;
Simon Horman837bfa72015-04-23 14:51:27 +09004269 sv_colour = SRV_STATS_COLOUR_NO_CHECK;
4270 }
Willy Tarreau2ea81932007-11-30 12:04:38 +01004271 }
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004272 else if (sv->state == SRV_ST_STOPPING) {
4273 if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) ||
Simon Horman837bfa72015-04-23 14:51:27 +09004274 (svs->check.health == svs->check.rise + svs->check.fall - 1)) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004275 sv_state = SRV_STATS_STATE_NOLB;
Simon Horman837bfa72015-04-23 14:51:27 +09004276 sv_colour = SRV_STATS_COLOUR_NOLB;
4277 } else {
Simon Horman4d2eab62015-04-23 14:51:26 +09004278 sv_state = SRV_STATS_STATE_NOLB_GOING_DOWN;
Simon Horman837bfa72015-04-23 14:51:27 +09004279 sv_colour = SRV_STATS_COLOUR_GOING_DOWN;
4280 }
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004281 }
4282 else { /* stopped */
Simon Horman837bfa72015-04-23 14:51:27 +09004283 if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004284 sv_state = SRV_STATS_STATE_DOWN_AGENT;
Simon Horman837bfa72015-04-23 14:51:27 +09004285 sv_colour = SRV_STATS_COLOUR_DOWN;
4286 } else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004287 sv_state = SRV_STATS_STATE_DOWN; /* DOWN */
Simon Horman837bfa72015-04-23 14:51:27 +09004288 sv_colour = SRV_STATS_COLOUR_DOWN;
4289 } else if ((svs->agent.state & CHK_ST_ENABLED) || (svs->check.state & CHK_ST_ENABLED)) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004290 sv_state = SRV_STATS_STATE_GOING_UP;
Simon Horman837bfa72015-04-23 14:51:27 +09004291 sv_colour = SRV_STATS_COLOUR_GOING_UP;
4292 } else {
Simon Horman4d2eab62015-04-23 14:51:26 +09004293 sv_state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */
Simon Horman837bfa72015-04-23 14:51:27 +09004294 sv_colour = SRV_STATS_COLOUR_DOWN;
4295 }
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004296 }
Willy Tarreau91861262007-10-17 17:06:05 +02004297
Willy Tarreau9638efa2014-05-23 11:19:57 +02004298 if (((sv_state <= 1) || (sv->admin & SRV_ADMF_MAINT)) && (appctx->ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02004299 /* do not report servers which are DOWN */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004300 appctx->ctx.stats.sv = sv->next;
Willy Tarreau91861262007-10-17 17:06:05 +02004301 continue;
4302 }
4303
Simon Horman837bfa72015-04-23 14:51:27 +09004304 if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state, sv_colour)) {
Willy Tarreaubc18da12015-03-13 14:00:47 +01004305 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004306 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004307 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004308 }
4309 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004310 } /* for sv */
Cyril Bonté474be412010-10-12 00:14:36 +02004311
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004312 appctx->ctx.stats.px_st = STAT_PX_ST_BE;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004313 /* fall through */
Cyril Bonté70be45d2010-10-12 00:14:35 +02004314
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004315 case STAT_PX_ST_BE:
4316 /* print the backend */
Willy Tarreaubc18da12015-03-13 14:00:47 +01004317 if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) {
4318 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004319 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004320 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004321 }
4322 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004323
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004324 appctx->ctx.stats.px_st = STAT_PX_ST_END;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004325 /* fall through */
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004326
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004327 case STAT_PX_ST_END:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004328 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004329 stats_dump_html_px_end(si, px);
Willy Tarreaubc18da12015-03-13 14:00:47 +01004330 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004331 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004332 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004333 }
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004334 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004335
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004336 appctx->ctx.stats.px_st = STAT_PX_ST_FIN;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004337 /* fall through */
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004338
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004339 case STAT_PX_ST_FIN:
4340 return 1;
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004341
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004342 default:
4343 /* unknown state, we should put an abort() here ! */
4344 return 1;
4345 }
4346}
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004347
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004348/* Dumps the HTTP stats head block to the trash for and uses the per-uri
4349 * parameters <uri>. The caller is responsible for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004350 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004351static void stats_dump_html_head(struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004352{
4353 /* WARNING! This must fit in the first buffer !!! */
4354 chunk_appendf(&trash,
4355 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
4356 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
4357 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
4358 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
4359 "<style type=\"text/css\"><!--\n"
4360 "body {"
4361 " font-family: arial, helvetica, sans-serif;"
4362 " font-size: 12px;"
4363 " font-weight: normal;"
4364 " color: black;"
4365 " background: white;"
4366 "}\n"
4367 "th,td {"
4368 " font-size: 10px;"
4369 "}\n"
4370 "h1 {"
4371 " font-size: x-large;"
4372 " margin-bottom: 0.5em;"
4373 "}\n"
4374 "h2 {"
4375 " font-family: helvetica, arial;"
4376 " font-size: x-large;"
4377 " font-weight: bold;"
4378 " font-style: italic;"
4379 " color: #6020a0;"
4380 " margin-top: 0em;"
4381 " margin-bottom: 0em;"
4382 "}\n"
4383 "h3 {"
4384 " font-family: helvetica, arial;"
4385 " font-size: 16px;"
4386 " font-weight: bold;"
4387 " color: #b00040;"
4388 " background: #e8e8d0;"
4389 " margin-top: 0em;"
4390 " margin-bottom: 0em;"
4391 "}\n"
4392 "li {"
4393 " margin-top: 0.25em;"
4394 " margin-right: 2em;"
4395 "}\n"
4396 ".hr {margin-top: 0.25em;"
4397 " border-color: black;"
4398 " border-bottom-style: solid;"
4399 "}\n"
4400 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
4401 ".total {background: #20D0D0;color: #ffff80;}\n"
4402 ".frontend {background: #e8e8d0;}\n"
4403 ".socket {background: #d0d0d0;}\n"
4404 ".backend {background: #e8e8d0;}\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004405 ".active_down {background: #ff9090;}\n"
4406 ".active_going_up {background: #ffd020;}\n"
4407 ".active_going_down {background: #ffffa0;}\n"
4408 ".active_up {background: #c0ffc0;}\n"
4409 ".active_nolb {background: #20a0ff;}\n"
4410 ".active_draining {background: #20a0FF;}\n"
4411 ".active_no_check {background: #e0e0e0;}\n"
4412 ".backup_down {background: #ff9090;}\n"
4413 ".backup_going_up {background: #ff80ff;}\n"
4414 ".backup_going_down {background: #c060ff;}\n"
4415 ".backup_up {background: #b0d0ff;}\n"
4416 ".backup_nolb {background: #90b0e0;}\n"
4417 ".backup_draining {background: #cc9900;}\n"
4418 ".backup_no_check {background: #e0e0e0;}\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004419 ".maintain {background: #c07820;}\n"
4420 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
4421 "\n"
4422 "a.px:link {color: #ffff40; text-decoration: none;}"
4423 "a.px:visited {color: #ffff40; text-decoration: none;}"
4424 "a.px:hover {color: #ffffff; text-decoration: none;}"
4425 "a.lfsb:link {color: #000000; text-decoration: none;}"
4426 "a.lfsb:visited {color: #000000; text-decoration: none;}"
4427 "a.lfsb:hover {color: #505050; text-decoration: none;}"
4428 "\n"
4429 "table.tbl { border-collapse: collapse; border-style: none;}\n"
4430 "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"
4431 "table.tbl td.ac { text-align: center;}\n"
4432 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
4433 "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n"
4434 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
4435 "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n"
4436 "\n"
4437 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
4438 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
4439 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
Willy Tarreau466c9b52012-12-23 02:25:03 +01004440 "table.det { border-collapse: collapse; border-style: none; }\n"
4441 "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 Tarreau6b9d3a82013-12-16 09:00:35 +01004442 "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 Tarreaud9bdcd52012-12-22 20:31:10 +01004443 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02004444 "div.tips {\n"
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01004445 " display:block;\n"
4446 " visibility:hidden;\n"
4447 " z-index:2147483647;\n"
4448 " position:absolute;\n"
4449 " padding:2px 4px 3px;\n"
4450 " background:#f0f060; color:#000000;\n"
4451 " border:1px solid #7040c0;\n"
4452 " white-space:nowrap;\n"
4453 " font-style:normal;font-size:11px;font-weight:normal;\n"
4454 " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n"
4455 " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n"
4456 "}\n"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02004457 "u:hover div.tips {visibility:visible;}\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004458 "-->\n"
4459 "</style></head>\n",
4460 (uri->flags & ST_SHNODE) ? " on " : "",
4461 (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
4462 );
4463}
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004464
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004465/* Dumps the HTML stats information block to the trash for and uses the state from
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004466 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004467 * for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004468 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004469static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004470{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004471 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004472 unsigned int up = (now.tv_sec - start_date.tv_sec);
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004473 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004474
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004475 /* WARNING! this has to fit the first packet too.
4476 * We are around 3.5 kB, add adding entries will
4477 * become tricky if we want to support 4kB buffers !
4478 */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004479 chunk_appendf(&trash,
4480 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
4481 PRODUCT_NAME "%s</a></h1>\n"
4482 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
4483 "<hr width=\"100%%\" class=\"hr\">\n"
4484 "<h3>&gt; General process information</h3>\n"
4485 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
4486 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
4487 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
4488 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
4489 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
4490 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n"
4491 "Running tasks: %d/%d; idle = %d %%<br>\n"
4492 "</td><td align=\"center\" nowrap>\n"
4493 "<table class=\"lgd\"><tr>\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004494 "<td class=\"active_up\">&nbsp;</td><td class=\"noborder\">active UP </td>"
4495 "<td class=\"backup_up\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004496 "</tr><tr>\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004497 "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>"
4498 "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004499 "</tr><tr>\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004500 "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>"
4501 "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004502 "</tr><tr>\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004503 "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
4504 "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004505 "</tr><tr>\n"
4506 "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) &nbsp;</td>"
Geoff Bucarcc8bb922013-04-18 13:53:16 -07004507 "</tr><tr>\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004508 "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance &nbsp;</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004509 "</tr></table>\n"
Willy Tarreau6b7764a2013-12-04 00:43:21 +01004510 "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled."
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004511 "</td>"
4512 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
4513 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
4514 "",
4515 (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING),
4516 pid, (uri->flags & ST_SHNODE) ? " on " : "",
4517 (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
4518 (uri->flags & ST_SHDESC) ? ": " : "",
4519 (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
4520 pid, relative_pid, global.nbproc,
4521 up / 86400, (up % 86400) / 3600,
4522 (up % 3600) / 60, (up % 60),
4523 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
4524 global.rlimit_memmax ? " MB" : "",
4525 global.rlimit_nofile,
4526 global.maxsock, global.maxconn, global.maxpipes,
4527 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
4528 run_queue_cur, nb_tasks_cur, idle_pct
4529 );
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004530
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004531 /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
Willy Tarreau4e4292b2014-11-28 12:18:45 +01004532 memcpy(scope_txt, bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004533 scope_txt[appctx->ctx.stats.scope_len] = '\0';
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004534
4535 chunk_appendf(&trash,
Jeff Buchbinder2dbbf4d2014-08-29 15:10:08 -05004536 "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004537 (appctx->ctx.stats.scope_len > 0) ? scope_txt : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004538 STAT_SCOPE_TXT_MAXLEN);
4539
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004540 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004541 scope_txt[0] = 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004542 if (appctx->ctx.stats.scope_len) {
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004543 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau4e4292b2014-11-28 12:18:45 +01004544 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004545 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004546 }
4547
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004548 if (appctx->ctx.stats.flags & STAT_HIDE_DOWN)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004549 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004550 "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004551 uri->uri_prefix,
4552 "",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004553 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004554 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004555 else
4556 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004557 "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004558 uri->uri_prefix,
4559 ";up",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004560 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004561 scope_txt);
Willy Tarreau91861262007-10-17 17:06:05 +02004562
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004563 if (uri->refresh > 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004564 if (appctx->ctx.stats.flags & STAT_NO_REFRESH)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004565 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004566 "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004567 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004568 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004569 "",
4570 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004571 else
4572 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004573 "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004574 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004575 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004576 ";norefresh",
4577 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004578 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02004579
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004580 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004581 "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004582 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004583 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4584 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004585 scope_txt);
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02004586
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004587 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004588 "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004589 uri->uri_prefix,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004590 (uri->refresh > 0) ? ";norefresh" : "",
4591 scope_txt);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01004592
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004593 chunk_appendf(&trash,
4594 "</ul></td>"
4595 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
4596 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
4597 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
4598 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
4599 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
4600 "</ul>"
4601 "</td>"
4602 "</tr></table>\n"
4603 ""
4604 );
Willy Tarreau4bab24d2007-11-30 18:16:29 +01004605
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004606 if (appctx->ctx.stats.st_code) {
4607 switch (appctx->ctx.stats.st_code) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004608 case STAT_STATUS_DONE:
4609 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004610 "<p><div class=active_up>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004611 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004612 "Action processed successfully."
Willy Tarreauba6be982013-04-19 12:16:55 +02004613 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004614 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4615 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004616 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004617 break;
4618 case STAT_STATUS_NONE:
4619 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004620 "<p><div class=active_going_down>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004621 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004622 "Nothing has changed."
Willy Tarreauba6be982013-04-19 12:16:55 +02004623 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004624 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4625 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004626 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004627 break;
4628 case STAT_STATUS_PART:
4629 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004630 "<p><div class=active_going_down>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004631 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004632 "Action partially processed.<br>"
4633 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
Willy Tarreauba6be982013-04-19 12:16:55 +02004634 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004635 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4636 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004637 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004638 break;
4639 case STAT_STATUS_ERRP:
4640 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004641 "<p><div class=active_down>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004642 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004643 "Action not processed because of invalid parameters."
4644 "<ul>"
4645 "<li>The action is maybe unknown.</li>"
4646 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
4647 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
4648 "</ul>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004649 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004650 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4651 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004652 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004653 break;
4654 case STAT_STATUS_EXCD:
4655 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004656 "<p><div class=active_down>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004657 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004658 "<b>Action not processed : the buffer couldn't store all the data.<br>"
4659 "You should retry with less servers at a time.</b>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004660 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004661 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4662 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004663 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004664 break;
4665 case STAT_STATUS_DENY:
4666 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004667 "<p><div class=active_down>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004668 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004669 "<b>Action denied.</b>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004670 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004671 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4672 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004673 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004674 break;
4675 default:
4676 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004677 "<p><div class=active_no_check>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004678 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004679 "Unexpected result."
Willy Tarreauba6be982013-04-19 12:16:55 +02004680 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004681 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4682 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004683 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004684 }
4685 chunk_appendf(&trash, "<p>\n");
4686 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004687}
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01004688
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004689/* Dumps the HTML stats trailer block to the trash. The caller is responsible
4690 * for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004691 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004692static void stats_dump_html_end()
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004693{
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004694 chunk_appendf(&trash, "</body></html>\n");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004695}
Willy Tarreau7f062c42009-03-05 18:43:00 +01004696
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004697/* This function dumps statistics onto the stream interface's read buffer in
4698 * either CSV or HTML format. <uri> contains some HTML-specific parameters that
Willy Tarreau306f8302013-07-08 15:53:06 +02004699 * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if
4700 * it had to stop writing data and an I/O is needed, 1 if the dump is finished
Willy Tarreau87b09662015-04-03 00:22:06 +02004701 * and the stream must be closed, or -1 in case of any error. This function is
Willy Tarreau306f8302013-07-08 15:53:06 +02004702 * used by both the CLI and the HTTP handlers.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004703 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004704static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004705{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004706 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau2bb4a962014-11-28 11:11:05 +01004707 struct channel *rep = si_ic(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004708 struct proxy *px;
Willy Tarreau7f062c42009-03-05 18:43:00 +01004709
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004710 chunk_reset(&trash);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02004711
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004712 switch (appctx->st2) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004713 case STAT_ST_INIT:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004714 appctx->st2 = STAT_ST_HEAD; /* let's start producing data */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004715 /* fall through */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01004716
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004717 case STAT_ST_HEAD:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004718 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004719 stats_dump_html_head(uri);
Willy Tarreau354898b2012-12-23 18:15:23 +01004720 else
4721 stats_dump_csv_header();
Willy Tarreaud9b587f2010-02-26 10:05:55 +01004722
Willy Tarreaubc18da12015-03-13 14:00:47 +01004723 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004724 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004725 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004726 }
Willy Tarreauae526782010-03-04 20:34:23 +01004727
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004728 appctx->st2 = STAT_ST_INFO;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004729 /* fall through */
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01004730
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004731 case STAT_ST_INFO:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004732 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004733 stats_dump_html_info(si, uri);
Willy Tarreaubc18da12015-03-13 14:00:47 +01004734 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004735 si_applet_cant_put(si);
Willy Tarreau91861262007-10-17 17:06:05 +02004736 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004737 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004738 }
Willy Tarreau91861262007-10-17 17:06:05 +02004739
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004740 appctx->ctx.stats.px = proxy;
4741 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
4742 appctx->st2 = STAT_ST_LIST;
Willy Tarreau91861262007-10-17 17:06:05 +02004743 /* fall through */
4744
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004745 case STAT_ST_LIST:
4746 /* dump proxies */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004747 while (appctx->ctx.stats.px) {
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004748 if (buffer_almost_full(rep->buf)) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004749 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004750 return 0;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004751 }
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004752
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004753 px = appctx->ctx.stats.px;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004754 /* skip the disabled proxies, global frontend and non-networked ones */
4755 if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004756 if (stats_dump_proxy_to_buffer(si, px, uri) == 0)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004757 return 0;
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004758
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004759 appctx->ctx.stats.px = px->next;
4760 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004761 }
4762 /* here, we just have reached the last proxy */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004763
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004764 appctx->st2 = STAT_ST_END;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004765 /* fall through */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004766
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004767 case STAT_ST_END:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004768 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004769 stats_dump_html_end();
Willy Tarreaubc18da12015-03-13 14:00:47 +01004770 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004771 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004772 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004773 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004774 }
Willy Tarreau55058a72012-11-21 08:27:21 +01004775
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004776 appctx->st2 = STAT_ST_FIN;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004777 /* fall through */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02004778
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004779 case STAT_ST_FIN:
4780 return 1;
Willy Tarreau55058a72012-11-21 08:27:21 +01004781
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004782 default:
4783 /* unknown state ! */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004784 appctx->st2 = STAT_ST_FIN;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004785 return -1;
4786 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004787}
Willy Tarreauae526782010-03-04 20:34:23 +01004788
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004789/* We reached the stats page through a POST request. The appctx is
4790 * expected to have already been allocated by the caller.
Willy Tarreau347a35d2013-11-22 17:51:09 +01004791 * Parse the posted data and enable/disable servers if necessary.
4792 * Returns 1 if request was parsed or zero if it needs more data.
4793 */
4794static int stats_process_http_post(struct stream_interface *si)
4795{
Willy Tarreau87b09662015-04-03 00:22:06 +02004796 struct stream *s = si_strm(si);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004797 struct appctx *appctx = objt_appctx(si->end);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004798
4799 struct proxy *px = NULL;
4800 struct server *sv = NULL;
4801
4802 char key[LINESIZE];
4803 int action = ST_ADM_ACTION_NONE;
4804 int reprocess = 0;
4805
4806 int total_servers = 0;
4807 int altered_servers = 0;
4808
4809 char *first_param, *cur_param, *next_param, *end_params;
4810 char *st_cur_param = NULL;
4811 char *st_next_param = NULL;
4812
4813 struct chunk *temp;
4814 int reql;
4815
4816 temp = get_trash_chunk();
Willy Tarreaueee5b512015-04-03 23:46:31 +02004817 if (temp->size < s->txn->req.body_len) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004818 /* too large request */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004819 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004820 goto out;
4821 }
4822
Willy Tarreaueee5b512015-04-03 23:46:31 +02004823 reql = bo_getblk(si_oc(si), temp->str, s->txn->req.body_len, s->txn->req.eoh + 2);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004824 if (reql <= 0) {
4825 /* we need more data */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004826 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004827 return 0;
4828 }
4829
4830 first_param = temp->str;
4831 end_params = temp->str + reql;
4832 cur_param = next_param = end_params;
4833 *end_params = '\0';
4834
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004835 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004836
4837 /*
4838 * Parse the parameters in reverse order to only store the last value.
4839 * From the html form, the backend and the action are at the end.
4840 */
4841 while (cur_param > first_param) {
4842 char *value;
4843 int poffset, plen;
4844
4845 cur_param--;
4846
4847 if ((*cur_param == '&') || (cur_param == first_param)) {
4848 reprocess_servers:
4849 /* Parse the key */
4850 poffset = (cur_param != first_param ? 1 : 0);
4851 plen = next_param - cur_param + (cur_param == first_param ? 1 : 0);
4852 if ((plen > 0) && (plen <= sizeof(key))) {
4853 strncpy(key, cur_param + poffset, plen);
4854 key[plen - 1] = '\0';
4855 } else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004856 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004857 goto out;
4858 }
4859
4860 /* Parse the value */
4861 value = key;
4862 while (*value != '\0' && *value != '=') {
4863 value++;
4864 }
4865 if (*value == '=') {
4866 /* Ok, a value is found, we can mark the end of the key */
4867 *value++ = '\0';
4868 }
4869 if (url_decode(key) < 0 || url_decode(value) < 0)
4870 break;
4871
4872 /* Now we can check the key to see what to do */
4873 if (!px && (strcmp(key, "b") == 0)) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02004874 if ((px = proxy_be_by_name(value)) == NULL) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004875 /* the backend name is unknown or ambiguous (duplicate names) */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004876 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004877 goto out;
4878 }
4879 }
4880 else if (!action && (strcmp(key, "action") == 0)) {
Willy Tarreaued7df902014-05-22 18:04:49 +02004881 if (strcmp(value, "ready") == 0) {
4882 action = ST_ADM_ACTION_READY;
4883 }
4884 else if (strcmp(value, "drain") == 0) {
4885 action = ST_ADM_ACTION_DRAIN;
4886 }
4887 else if (strcmp(value, "maint") == 0) {
4888 action = ST_ADM_ACTION_MAINT;
4889 }
4890 else if (strcmp(value, "shutdown") == 0) {
4891 action = ST_ADM_ACTION_SHUTDOWN;
4892 }
Willy Tarreau248a60e2014-05-23 14:59:48 +02004893 else if (strcmp(value, "dhlth") == 0) {
4894 action = ST_ADM_ACTION_DHLTH;
4895 }
4896 else if (strcmp(value, "ehlth") == 0) {
4897 action = ST_ADM_ACTION_EHLTH;
4898 }
4899 else if (strcmp(value, "hrunn") == 0) {
4900 action = ST_ADM_ACTION_HRUNN;
4901 }
4902 else if (strcmp(value, "hnolb") == 0) {
4903 action = ST_ADM_ACTION_HNOLB;
4904 }
4905 else if (strcmp(value, "hdown") == 0) {
4906 action = ST_ADM_ACTION_HDOWN;
4907 }
4908 else if (strcmp(value, "dagent") == 0) {
4909 action = ST_ADM_ACTION_DAGENT;
4910 }
4911 else if (strcmp(value, "eagent") == 0) {
4912 action = ST_ADM_ACTION_EAGENT;
4913 }
4914 else if (strcmp(value, "arunn") == 0) {
4915 action = ST_ADM_ACTION_ARUNN;
4916 }
4917 else if (strcmp(value, "adown") == 0) {
4918 action = ST_ADM_ACTION_ADOWN;
4919 }
Willy Tarreaued7df902014-05-22 18:04:49 +02004920 /* else these are the old supported methods */
4921 else if (strcmp(value, "disable") == 0) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004922 action = ST_ADM_ACTION_DISABLE;
4923 }
4924 else if (strcmp(value, "enable") == 0) {
4925 action = ST_ADM_ACTION_ENABLE;
4926 }
4927 else if (strcmp(value, "stop") == 0) {
4928 action = ST_ADM_ACTION_STOP;
4929 }
4930 else if (strcmp(value, "start") == 0) {
4931 action = ST_ADM_ACTION_START;
4932 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01004933 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004934 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004935 goto out;
4936 }
4937 }
4938 else if (strcmp(key, "s") == 0) {
4939 if (!(px && action)) {
4940 /*
4941 * Indicates that we'll need to reprocess the parameters
4942 * as soon as backend and action are known
4943 */
4944 if (!reprocess) {
4945 st_cur_param = cur_param;
4946 st_next_param = next_param;
4947 }
4948 reprocess = 1;
4949 }
4950 else if ((sv = findserver(px, value)) != NULL) {
4951 switch (action) {
4952 case ST_ADM_ACTION_DISABLE:
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004953 if (!(sv->admin & SRV_ADMF_FMAINT)) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004954 altered_servers++;
4955 total_servers++;
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004956 srv_set_admin_flag(sv, SRV_ADMF_FMAINT);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004957 }
4958 break;
4959 case ST_ADM_ACTION_ENABLE:
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004960 if (sv->admin & SRV_ADMF_FMAINT) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004961 altered_servers++;
4962 total_servers++;
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004963 srv_clr_admin_flag(sv, SRV_ADMF_FMAINT);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004964 }
4965 break;
4966 case ST_ADM_ACTION_STOP:
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004967 if (!(sv->admin & SRV_ADMF_FDRAIN)) {
4968 srv_set_admin_flag(sv, SRV_ADMF_FDRAIN);
4969 altered_servers++;
4970 total_servers++;
4971 }
4972 break;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004973 case ST_ADM_ACTION_START:
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004974 if (sv->admin & SRV_ADMF_FDRAIN) {
4975 srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN);
4976 altered_servers++;
4977 total_servers++;
4978 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01004979 break;
Willy Tarreau248a60e2014-05-23 14:59:48 +02004980 case ST_ADM_ACTION_DHLTH:
4981 if (sv->check.state & CHK_ST_CONFIGURED) {
4982 sv->check.state &= ~CHK_ST_ENABLED;
4983 altered_servers++;
4984 total_servers++;
4985 }
4986 break;
4987 case ST_ADM_ACTION_EHLTH:
4988 if (sv->check.state & CHK_ST_CONFIGURED) {
4989 sv->check.state |= CHK_ST_ENABLED;
4990 altered_servers++;
4991 total_servers++;
4992 }
4993 break;
4994 case ST_ADM_ACTION_HRUNN:
4995 if (!(sv->track)) {
4996 sv->check.health = sv->check.rise + sv->check.fall - 1;
4997 srv_set_running(sv, "changed from Web interface");
4998 altered_servers++;
4999 total_servers++;
5000 }
5001 break;
5002 case ST_ADM_ACTION_HNOLB:
5003 if (!(sv->track)) {
5004 sv->check.health = sv->check.rise + sv->check.fall - 1;
5005 srv_set_stopping(sv, "changed from Web interface");
5006 altered_servers++;
5007 total_servers++;
5008 }
5009 break;
5010 case ST_ADM_ACTION_HDOWN:
5011 if (!(sv->track)) {
5012 sv->check.health = 0;
5013 srv_set_stopped(sv, "changed from Web interface");
5014 altered_servers++;
5015 total_servers++;
5016 }
5017 break;
5018 case ST_ADM_ACTION_DAGENT:
5019 if (sv->agent.state & CHK_ST_CONFIGURED) {
5020 sv->agent.state &= ~CHK_ST_ENABLED;
5021 altered_servers++;
5022 total_servers++;
5023 }
5024 break;
5025 case ST_ADM_ACTION_EAGENT:
5026 if (sv->agent.state & CHK_ST_CONFIGURED) {
5027 sv->agent.state |= CHK_ST_ENABLED;
5028 altered_servers++;
5029 total_servers++;
5030 }
5031 break;
5032 case ST_ADM_ACTION_ARUNN:
5033 if (sv->agent.state & CHK_ST_ENABLED) {
5034 sv->agent.health = sv->agent.rise + sv->agent.fall - 1;
5035 srv_set_running(sv, "changed from Web interface");
5036 altered_servers++;
5037 total_servers++;
5038 }
5039 break;
5040 case ST_ADM_ACTION_ADOWN:
5041 if (sv->agent.state & CHK_ST_ENABLED) {
5042 sv->agent.health = 0;
5043 srv_set_stopped(sv, "changed from Web interface");
5044 altered_servers++;
5045 total_servers++;
5046 }
5047 break;
Willy Tarreaued7df902014-05-22 18:04:49 +02005048 case ST_ADM_ACTION_READY:
5049 srv_adm_set_ready(sv);
5050 altered_servers++;
5051 total_servers++;
5052 break;
5053 case ST_ADM_ACTION_DRAIN:
5054 srv_adm_set_drain(sv);
5055 altered_servers++;
5056 total_servers++;
5057 break;
5058 case ST_ADM_ACTION_MAINT:
5059 srv_adm_set_maint(sv);
5060 altered_servers++;
5061 total_servers++;
5062 break;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005063 case ST_ADM_ACTION_SHUTDOWN:
5064 if (px->state != PR_STSTOPPED) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005065 struct stream *sess, *sess_bck;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005066
5067 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
5068 if (sess->srv_conn == sv)
Willy Tarreaue7dff022015-04-03 01:14:29 +02005069 stream_shutdown(sess, SF_ERR_KILLED);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005070
5071 altered_servers++;
5072 total_servers++;
5073 }
5074 break;
5075 }
5076 } else {
5077 /* the server name is unknown or ambiguous (duplicate names) */
5078 total_servers++;
5079 }
5080 }
5081 if (reprocess && px && action) {
5082 /* Now, we know the backend and the action chosen by the user.
5083 * We can safely restart from the first server parameter
5084 * to reprocess them
5085 */
5086 cur_param = st_cur_param;
5087 next_param = st_next_param;
5088 reprocess = 0;
5089 goto reprocess_servers;
5090 }
5091
5092 next_param = cur_param;
5093 }
5094 }
5095
5096 if (total_servers == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005097 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005098 }
5099 else if (altered_servers == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005100 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005101 }
5102 else if (altered_servers == total_servers) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005103 appctx->ctx.stats.st_code = STAT_STATUS_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005104 }
5105 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005106 appctx->ctx.stats.st_code = STAT_STATUS_PART;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005107 }
5108 out:
5109 return 1;
5110}
5111
5112
5113static int stats_send_http_headers(struct stream_interface *si)
5114{
Willy Tarreau87b09662015-04-03 00:22:06 +02005115 struct stream *s = si_strm(si);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005116 struct uri_auth *uri = s->be->uri_auth;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005117 struct appctx *appctx = objt_appctx(si->end);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005118
5119 chunk_printf(&trash,
Willy Tarreau8b8995f2014-04-24 22:51:54 +02005120 "HTTP/1.1 200 OK\r\n"
Willy Tarreau347a35d2013-11-22 17:51:09 +01005121 "Cache-Control: no-cache\r\n"
5122 "Connection: close\r\n"
5123 "Content-Type: %s\r\n",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005124 (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain");
Willy Tarreau347a35d2013-11-22 17:51:09 +01005125
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005126 if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH))
Willy Tarreau347a35d2013-11-22 17:51:09 +01005127 chunk_appendf(&trash, "Refresh: %d\r\n",
5128 uri->refresh);
5129
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005130 /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */
5131
5132 if (appctx->ctx.stats.flags & STAT_CHUNKED)
5133 chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n");
5134 else
5135 chunk_appendf(&trash, "\r\n");
Willy Tarreau347a35d2013-11-22 17:51:09 +01005136
Willy Tarreaueee5b512015-04-03 23:46:31 +02005137 s->txn->status = 200;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005138 s->logs.tv_request = now;
5139
Willy Tarreaubc18da12015-03-13 14:00:47 +01005140 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005141 si_applet_cant_put(si);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005142 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005143 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01005144
5145 return 1;
5146}
5147
5148static int stats_send_http_redirect(struct stream_interface *si)
5149{
5150 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
Willy Tarreau87b09662015-04-03 00:22:06 +02005151 struct stream *s = si_strm(si);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005152 struct uri_auth *uri = s->be->uri_auth;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005153 struct appctx *appctx = objt_appctx(si->end);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005154
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005155 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
Willy Tarreau347a35d2013-11-22 17:51:09 +01005156 scope_txt[0] = 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005157 if (appctx->ctx.stats.scope_len) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01005158 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005159 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005160 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005161 }
5162
5163 /* We don't want to land on the posted stats page because a refresh will
5164 * repost the data. We don't want this to happen on accident so we redirect
5165 * the browse to the stats page with a GET.
5166 */
5167 chunk_printf(&trash,
5168 "HTTP/1.1 303 See Other\r\n"
5169 "Cache-Control: no-cache\r\n"
5170 "Content-Type: text/plain\r\n"
5171 "Connection: close\r\n"
5172 "Location: %s;st=%s%s%s%s\r\n"
5173 "\r\n",
5174 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005175 ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) &&
5176 (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) &&
5177 stat_status_codes[appctx->ctx.stats.st_code]) ?
5178 stat_status_codes[appctx->ctx.stats.st_code] :
Willy Tarreau347a35d2013-11-22 17:51:09 +01005179 stat_status_codes[STAT_STATUS_UNKN],
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005180 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
5181 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreau347a35d2013-11-22 17:51:09 +01005182 scope_txt);
5183
Willy Tarreaueee5b512015-04-03 23:46:31 +02005184 s->txn->status = 303;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005185 s->logs.tv_request = now;
5186
Willy Tarreaubc18da12015-03-13 14:00:47 +01005187 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005188 si_applet_cant_put(si);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005189 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005190 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01005191
5192 return 1;
5193}
5194
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005195/* This I/O handler runs as an applet embedded in a stream interface. It is
5196 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005197 * appctx->st0 contains the operation in progress (dump, done). The handler
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005198 * automatically unregisters itself once transfer is complete.
5199 */
Willy Tarreau00a37f02015-04-13 12:05:19 +02005200static void http_stats_io_handler(struct appctx *appctx)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005201{
Willy Tarreau00a37f02015-04-13 12:05:19 +02005202 struct stream_interface *si = appctx->owner;
Willy Tarreau87b09662015-04-03 00:22:06 +02005203 struct stream *s = si_strm(si);
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005204 struct channel *req = si_oc(si);
5205 struct channel *res = si_ic(si);
Willy Tarreau55058a72012-11-21 08:27:21 +01005206
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005207 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
5208 goto out;
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01005209
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005210 /* check that the output is not closed */
5211 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005212 appctx->st0 = STAT_HTTP_DONE;
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02005213
Willy Tarreau347a35d2013-11-22 17:51:09 +01005214 /* all states are processed in sequence */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005215 if (appctx->st0 == STAT_HTTP_HEAD) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01005216 if (stats_send_http_headers(si)) {
Willy Tarreaueee5b512015-04-03 23:46:31 +02005217 if (s->txn->meth == HTTP_METH_HEAD)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005218 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005219 else
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005220 appctx->st0 = STAT_HTTP_DUMP;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005221 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01005222 }
5223
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005224 if (appctx->st0 == STAT_HTTP_DUMP) {
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005225 unsigned int prev_len = si_ib(si)->i;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005226 unsigned int data_len;
5227 unsigned int last_len;
Willy Tarreaucce36482014-04-24 20:26:41 +02005228 unsigned int last_fwd = 0;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005229
5230 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
5231 /* One difficulty we're facing is that we must prevent
5232 * the input data from being automatically forwarded to
5233 * the output area. For this, we temporarily disable
5234 * forwarding on the channel.
5235 */
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005236 last_fwd = si_ic(si)->to_forward;
5237 si_ic(si)->to_forward = 0;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005238 chunk_printf(&trash, "\r\n000000\r\n");
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005239 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005240 si_applet_cant_put(si);
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005241 si_ic(si)->to_forward = last_fwd;
Willy Tarreau828824a2015-04-19 17:20:03 +02005242 goto out;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005243 }
5244 }
5245
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005246 data_len = si_ib(si)->i;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005247 if (stats_dump_stat_to_buffer(si, s->be->uri_auth))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005248 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005249
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005250 last_len = si_ib(si)->i;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005251
5252 /* Now we must either adjust or remove the chunk size. This is
5253 * not easy because the chunk size might wrap at the end of the
5254 * buffer, so we pretend we have nothing in the buffer, we write
5255 * the size, then restore the buffer's contents. Note that we can
5256 * only do that because no forwarding is scheduled on the stats
5257 * applet.
5258 */
5259 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005260 si_ic(si)->total -= (last_len - prev_len);
5261 si_ib(si)->i -= (last_len - prev_len);
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005262
5263 if (last_len != data_len) {
5264 chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len));
Willy Tarreaubc18da12015-03-13 14:00:47 +01005265 if (bi_putchk(si_ic(si), &trash) == -1)
Willy Tarreaufe127932015-04-21 19:23:39 +02005266 si_applet_cant_put(si);
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005267
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005268 si_ic(si)->total += (last_len - data_len);
5269 si_ib(si)->i += (last_len - data_len);
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005270 }
5271 /* now re-enable forwarding */
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005272 channel_forward(si_ic(si), last_fwd);
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005273 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005274 }
Cyril Bonté70be45d2010-10-12 00:14:35 +02005275
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005276 if (appctx->st0 == STAT_HTTP_POST) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01005277 if (stats_process_http_post(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005278 appctx->st0 = STAT_HTTP_LAST;
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005279 else if (si_oc(si)->flags & CF_SHUTR)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005280 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005281 }
5282
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005283 if (appctx->st0 == STAT_HTTP_LAST) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01005284 if (stats_send_http_redirect(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005285 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005286 }
5287
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005288 if (appctx->st0 == STAT_HTTP_DONE) {
5289 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
5290 chunk_printf(&trash, "\r\n0\r\n\r\n");
Willy Tarreaubc18da12015-03-13 14:00:47 +01005291 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005292 si_applet_cant_put(si);
Willy Tarreau828824a2015-04-19 17:20:03 +02005293 goto out;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005294 }
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005295 }
5296 /* eat the whole request */
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005297 bo_skip(si_oc(si), si_ob(si)->o);
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005298 res->flags |= CF_READ_NULL;
5299 si_shutr(si);
5300 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01005301
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005302 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST))
5303 si_shutw(si);
Willy Tarreau91861262007-10-17 17:06:05 +02005304
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005305 if (appctx->st0 == STAT_HTTP_DONE) {
Willy Tarreau96d44912013-11-22 12:25:24 +01005306 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) {
5307 si_shutr(si);
5308 res->flags |= CF_READ_NULL;
5309 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005310 }
Willy Tarreau828824a2015-04-19 17:20:03 +02005311 out:
Willy Tarreaud4da1962015-04-20 01:31:23 +02005312 /* just to make gcc happy */ ;
Willy Tarreau91861262007-10-17 17:06:05 +02005313}
5314
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005315
Willy Tarreau909d5172012-11-26 03:04:41 +01005316static inline const char *get_conn_ctrl_name(const struct connection *conn)
5317{
Willy Tarreau3c728722014-01-23 13:50:42 +01005318 if (!conn_ctrl_ready(conn))
Willy Tarreau909d5172012-11-26 03:04:41 +01005319 return "NONE";
5320 return conn->ctrl->name;
5321}
5322
5323static inline const char *get_conn_xprt_name(const struct connection *conn)
5324{
5325 static char ptr[17];
5326
Willy Tarreauaad69382014-01-23 14:21:42 +01005327 if (!conn_xprt_ready(conn))
Willy Tarreau909d5172012-11-26 03:04:41 +01005328 return "NONE";
5329
5330 if (conn->xprt == &raw_sock)
5331 return "RAW";
5332
5333#ifdef USE_OPENSSL
5334 if (conn->xprt == &ssl_sock)
5335 return "SSL";
5336#endif
5337 snprintf(ptr, sizeof(ptr), "%p", conn->xprt);
5338 return ptr;
5339}
5340
5341static inline const char *get_conn_data_name(const struct connection *conn)
5342{
5343 static char ptr[17];
5344
5345 if (!conn->data)
5346 return "NONE";
5347
5348 if (conn->data == &sess_conn_cb)
5349 return "SESS";
5350
5351 if (conn->data == &si_conn_cb)
5352 return "STRM";
5353
5354 if (conn->data == &check_conn_cb)
5355 return "CHCK";
5356
5357 snprintf(ptr, sizeof(ptr), "%p", conn->data);
5358 return ptr;
5359}
5360
Willy Tarreau87b09662015-04-03 00:22:06 +02005361/* This function dumps a complete stream state onto the stream interface's
5362 * read buffer. The stream has to be set in sess->target. It returns
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01005363 * 0 if the output buffer is full and it needs to be called again, otherwise
5364 * non-zero. It is designed to be called from stats_dump_sess_to_buffer() below.
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005365 */
Willy Tarreau87b09662015-04-03 00:22:06 +02005366static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct stream *sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005367{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005368 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005369 struct tm tm;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005370 extern const char *monthname[12];
5371 char pn[INET6_ADDRSTRLEN];
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005372 struct connection *conn;
Willy Tarreau284ddbf2013-12-01 20:45:00 +01005373 struct appctx *tmpctx;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005374
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005375 chunk_reset(&trash);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005376
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005377 if (appctx->ctx.sess.section > 0 && appctx->ctx.sess.uid != sess->uniq_id) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005378 /* stream changed, no need to go any further */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005379 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
Willy Tarreaubc18da12015-03-13 14:00:47 +01005380 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005381 si_applet_cant_put(si);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005382 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005383 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005384 appctx->ctx.sess.uid = 0;
5385 appctx->ctx.sess.section = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005386 return 1;
5387 }
5388
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005389 switch (appctx->ctx.sess.section) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005390 case 0: /* main status of the stream */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005391 appctx->ctx.sess.uid = sess->uniq_id;
5392 appctx->ctx.sess.section = 1;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005393 /* fall through */
5394
5395 case 1:
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005396 get_localtime(sess->logs.accept_date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005397 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005398 "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005399 sess,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005400 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
5401 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005402 sess->uniq_id,
Willy Tarreau666f5042015-06-17 19:49:52 +02005403 strm_li(sess) ? strm_li(sess)->proto->name : "?");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005404
Willy Tarreaud0d8da92015-04-04 02:10:38 +02005405 conn = objt_conn(strm_orig(sess));
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005406 switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005407 case AF_INET:
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005408 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005409 chunk_appendf(&trash, " source=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005410 pn, get_host_port(&conn->addr.from));
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005411 break;
5412 case AF_UNIX:
Willy Tarreaud0d8da92015-04-04 02:10:38 +02005413 chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid);
Emeric Brun837ca522010-10-22 16:19:01 +02005414 break;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005415 default:
5416 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005417 chunk_appendf(&trash, "\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005418 break;
5419 }
5420
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005421 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005422 " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n",
Willy Tarreauee28de02010-06-01 09:51:00 +02005423 sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005424
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005425 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07005426 " frontend=%s (id=%u mode=%s), listener=%s (id=%u)",
Willy Tarreaud0d8da92015-04-04 02:10:38 +02005427 strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp",
5428 strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?",
5429 strm_li(sess) ? strm_li(sess)->luid : 0);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005430
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005431 if (conn)
5432 conn_get_to_addr(conn);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005433
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005434 switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) {
Daniel Schultze90690c72012-03-23 10:53:36 -07005435 case AF_INET:
5436 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005437 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005438 pn, get_host_port(&conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07005439 break;
5440 case AF_UNIX:
Willy Tarreaud0d8da92015-04-04 02:10:38 +02005441 chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid);
Daniel Schultze90690c72012-03-23 10:53:36 -07005442 break;
5443 default:
5444 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005445 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07005446 break;
5447 }
5448
Willy Tarreau50943332011-09-02 17:33:05 +02005449 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005450 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07005451 " backend=%s (id=%u mode=%s)",
Willy Tarreau50943332011-09-02 17:33:05 +02005452 sess->be->id,
Daniel Schultze90690c72012-03-23 10:53:36 -07005453 sess->be->uuid, sess->be->mode ? "http" : "tcp");
5454 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005455 chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)");
Daniel Schultze90690c72012-03-23 10:53:36 -07005456
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005457 conn = objt_conn(sess->si[1].end);
5458 if (conn)
5459 conn_get_from_addr(conn);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005460
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005461 switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) {
Daniel Schultze90690c72012-03-23 10:53:36 -07005462 case AF_INET:
5463 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005464 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005465 pn, get_host_port(&conn->addr.from));
Daniel Schultze90690c72012-03-23 10:53:36 -07005466 break;
5467 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005468 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07005469 break;
5470 default:
5471 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005472 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07005473 break;
5474 }
5475
5476 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005477 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07005478 " server=%s (id=%u)",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01005479 objt_server(sess->target) ? objt_server(sess->target)->id : "<none>",
5480 objt_server(sess->target) ? objt_server(sess->target)->puid : 0);
Willy Tarreau50943332011-09-02 17:33:05 +02005481 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005482 chunk_appendf(&trash, " server=<NONE> (id=-1)");
Daniel Schultze90690c72012-03-23 10:53:36 -07005483
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005484 if (conn)
5485 conn_get_to_addr(conn);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005486
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005487 switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) {
Daniel Schultze90690c72012-03-23 10:53:36 -07005488 case AF_INET:
5489 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005490 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005491 pn, get_host_port(&conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07005492 break;
5493 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005494 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07005495 break;
5496 default:
5497 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005498 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07005499 break;
5500 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005501
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005502 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005503 " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005504 sess->task,
5505 sess->task->state,
5506 sess->task->nice, sess->task->calls,
5507 sess->task->expire ?
5508 tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" :
5509 human_time(TICKS_TO_MS(sess->task->expire - now_ms),
5510 TICKS_TO_MS(1000)) : "<NEVER>",
5511 task_in_rq(sess->task) ? ", running" : "");
5512
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005513 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005514 " age=%s)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005515 human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1));
5516
Willy Tarreaueee5b512015-04-03 23:46:31 +02005517 if (sess->txn)
5518 chunk_appendf(&trash,
Willy Tarreau98410192014-11-26 18:05:38 +01005519 " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s waiting=%d\n",
Willy Tarreaueee5b512015-04-03 23:46:31 +02005520 sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status,
5521 http_msg_state_str(sess->txn->req.msg_state), http_msg_state_str(sess->txn->rsp.msg_state), !LIST_ISEMPTY(&sess->buffer_wait));
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005522
5523 chunk_appendf(&trash,
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02005524 " si[0]=%p (state=%s flags=0x%02x endp0=%s:%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005525 &sess->si[0],
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005526 si_state_str(sess->si[0].state),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005527 sess->si[0].flags,
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005528 obj_type_name(sess->si[0].end),
5529 obj_base_ptr(sess->si[0].end),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005530 sess->si[0].exp ?
5531 tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" :
5532 human_time(TICKS_TO_MS(sess->si[0].exp - now_ms),
5533 TICKS_TO_MS(1000)) : "<NEVER>",
5534 sess->si[0].err_type);
5535
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005536 chunk_appendf(&trash,
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02005537 " si[1]=%p (state=%s flags=0x%02x endp1=%s:%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005538 &sess->si[1],
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005539 si_state_str(sess->si[1].state),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005540 sess->si[1].flags,
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005541 obj_type_name(sess->si[1].end),
5542 obj_base_ptr(sess->si[1].end),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005543 sess->si[1].exp ?
5544 tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" :
5545 human_time(TICKS_TO_MS(sess->si[1].exp - now_ms),
5546 TICKS_TO_MS(1000)) : "<NEVER>",
5547 sess->si[1].err_type);
5548
Willy Tarreau284ddbf2013-12-01 20:45:00 +01005549 if ((conn = objt_conn(sess->si[0].end)) != NULL) {
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005550 chunk_appendf(&trash,
5551 " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005552 conn,
5553 get_conn_ctrl_name(conn),
5554 get_conn_xprt_name(conn),
5555 get_conn_data_name(conn),
5556 obj_type_name(conn->target),
5557 obj_base_ptr(conn->target));
Willy Tarreau909d5172012-11-26 03:04:41 +01005558
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005559 chunk_appendf(&trash,
Willy Tarreau16f649c2014-01-25 19:10:48 +01005560 " flags=0x%08x fd=%d fd.state=%02x fd.cache=%d updt=%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005561 conn->flags,
5562 conn->t.sock.fd,
Willy Tarreau69a41fa2014-01-20 11:02:59 +01005563 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0,
Willy Tarreau15a4dec2014-01-20 11:09:39 +01005564 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005565 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005566 }
Willy Tarreau284ddbf2013-12-01 20:45:00 +01005567 else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) {
5568 chunk_appendf(&trash,
5569 " app0=%p st0=%d st1=%d st2=%d applet=%s\n",
5570 tmpctx,
5571 tmpctx->st0,
5572 tmpctx->st1,
5573 tmpctx->st2,
5574 tmpctx->applet->name);
5575 }
Willy Tarreaubc174aa2012-11-19 16:10:32 +01005576
Willy Tarreau284ddbf2013-12-01 20:45:00 +01005577 if ((conn = objt_conn(sess->si[1].end)) != NULL) {
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005578 chunk_appendf(&trash,
5579 " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005580 conn,
5581 get_conn_ctrl_name(conn),
5582 get_conn_xprt_name(conn),
5583 get_conn_data_name(conn),
5584 obj_type_name(conn->target),
5585 obj_base_ptr(conn->target));
Willy Tarreau909d5172012-11-26 03:04:41 +01005586
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005587 chunk_appendf(&trash,
5588 " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005589 conn->flags,
5590 conn->t.sock.fd,
Willy Tarreau69a41fa2014-01-20 11:02:59 +01005591 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0,
Willy Tarreau15a4dec2014-01-20 11:09:39 +01005592 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005593 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005594 }
Willy Tarreau284ddbf2013-12-01 20:45:00 +01005595 else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) {
5596 chunk_appendf(&trash,
5597 " app1=%p st0=%d st1=%d st2=%d applet=%s\n",
5598 tmpctx,
5599 tmpctx->st0,
5600 tmpctx->st1,
5601 tmpctx->st2,
5602 tmpctx->applet->name);
5603 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005604
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005605 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01005606 " req=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005607 " an_exp=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005608 &sess->req,
5609 sess->req.flags, sess->req.analysers,
5610 sess->req.pipe ? sess->req.pipe->data : 0,
5611 sess->req.to_forward, sess->req.total,
5612 sess->req.analyse_exp ?
5613 human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005614 TICKS_TO_MS(1000)) : "<NEVER>");
5615
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005616 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005617 " rex=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005618 sess->req.rex ?
5619 human_time(TICKS_TO_MS(sess->req.rex - now_ms),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005620 TICKS_TO_MS(1000)) : "<NEVER>");
5621
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005622 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005623 " wex=%s\n"
Willy Tarreau909d5172012-11-26 03:04:41 +01005624 " buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d\n",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005625 sess->req.wex ?
5626 human_time(TICKS_TO_MS(sess->req.wex - now_ms),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005627 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005628 sess->req.buf,
5629 sess->req.buf->data, sess->req.buf->o,
5630 (int)(sess->req.buf->p - sess->req.buf->data),
Willy Tarreaueee5b512015-04-03 23:46:31 +02005631 sess->txn ? sess->txn->req.next : 0, sess->req.buf->i,
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005632 sess->req.buf->size);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005633
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005634 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01005635 " res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005636 " an_exp=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005637 &sess->res,
5638 sess->res.flags, sess->res.analysers,
5639 sess->res.pipe ? sess->res.pipe->data : 0,
5640 sess->res.to_forward, sess->res.total,
5641 sess->res.analyse_exp ?
5642 human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005643 TICKS_TO_MS(1000)) : "<NEVER>");
5644
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005645 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005646 " rex=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005647 sess->res.rex ?
5648 human_time(TICKS_TO_MS(sess->res.rex - now_ms),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005649 TICKS_TO_MS(1000)) : "<NEVER>");
5650
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005651 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005652 " wex=%s\n"
Willy Tarreau909d5172012-11-26 03:04:41 +01005653 " buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d\n",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005654 sess->res.wex ?
5655 human_time(TICKS_TO_MS(sess->res.wex - now_ms),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005656 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005657 sess->res.buf,
5658 sess->res.buf->data, sess->res.buf->o,
5659 (int)(sess->res.buf->p - sess->res.buf->data),
Willy Tarreaueee5b512015-04-03 23:46:31 +02005660 sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i,
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005661 sess->res.buf->size);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005662
Willy Tarreaubc18da12015-03-13 14:00:47 +01005663 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005664 si_applet_cant_put(si);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005665 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005666 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005667
5668 /* use other states to dump the contents */
5669 }
5670 /* end of dump */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005671 appctx->ctx.sess.uid = 0;
5672 appctx->ctx.sess.section = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005673 return 1;
5674}
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005675
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +02005676#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
5677static int stats_tlskeys_list(struct stream_interface *si) {
5678 struct appctx *appctx = __objt_appctx(si->end);
5679
5680 switch (appctx->st2) {
5681 case STAT_ST_INIT:
5682 /* Display the column headers. If the message cannot be sent,
5683 * quit the fucntion with returning 0. The function is called
5684 * later and restart at the state "STAT_ST_INIT".
5685 */
5686 chunk_reset(&trash);
5687 chunk_appendf(&trash, "# id (file)\n");
5688 if (bi_putchk(si_ic(si), &trash) == -1) {
5689 si_applet_cant_put(si);
5690 return 0;
5691 }
5692
5693 /* Now, we start the browsing of the references lists.
5694 * Note that the following call to LIST_ELEM return bad pointer. The only
5695 * avalaible field of this pointer is <list>. It is used with the function
5696 * tlskeys_list_get_next() for retruning the first avalaible entry
5697 */
5698 appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list);
5699 appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference);
5700
5701 appctx->st2 = STAT_ST_LIST;
5702 /* fall through */
5703
5704 case STAT_ST_LIST:
5705 while (appctx->ctx.tlskeys.ref) {
5706 chunk_reset(&trash);
5707
5708 chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id,
5709 appctx->ctx.tlskeys.ref->filename);
5710
5711 if (bi_putchk(si_ic(si), &trash) == -1) {
5712 /* let's try again later from this stream. We add ourselves into
5713 * this stream's users so that it can remove us upon termination.
5714 */
5715 si_applet_cant_put(si);
5716 return 0;
5717 }
5718
5719 /* get next list entry and check the end of the list */
5720 appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference);
5721 }
5722
5723 appctx->st2 = STAT_ST_FIN;
5724 /* fall through */
5725
5726 default:
5727 appctx->st2 = STAT_ST_FIN;
5728 return 1;
5729 }
5730 return 0;
5731}
5732#endif
5733
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005734static int stats_pats_list(struct stream_interface *si)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005735{
5736 struct appctx *appctx = __objt_appctx(si->end);
5737
5738 switch (appctx->st2) {
5739 case STAT_ST_INIT:
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01005740 /* Display the column headers. If the message cannot be sent,
5741 * quit the fucntion with returning 0. The function is called
5742 * later and restart at the state "STAT_ST_INIT".
5743 */
5744 chunk_reset(&trash);
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01005745 chunk_appendf(&trash, "# id (file) description\n");
Willy Tarreaubc18da12015-03-13 14:00:47 +01005746 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005747 si_applet_cant_put(si);
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01005748 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005749 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005750
5751 /* Now, we start the browsing of the references lists.
5752 * Note that the following call to LIST_ELEM return bad pointer. The only
5753 * avalaible field of this pointer is <list>. It is used with the function
5754 * pat_list_get_next() for retruning the first avalaible entry
5755 */
5756 appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list);
5757 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
5758 appctx->ctx.map.display_flags);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005759 appctx->st2 = STAT_ST_LIST;
5760 /* fall through */
5761
5762 case STAT_ST_LIST:
5763 while (appctx->ctx.map.ref) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005764 chunk_reset(&trash);
5765
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005766 /* Build messages. If the reference is used by another category than
5767 * the listed categorie, display the information in the massage.
5768 */
Thierry FOURNIERf7e04e92014-03-20 11:45:47 +01005769 chunk_appendf(&trash, "%d (%s) %s\n", appctx->ctx.map.ref->unique_id,
Thierry FOURNIER0d6ba512014-02-11 03:31:34 +01005770 appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "",
5771 appctx->ctx.map.ref->display);
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01005772
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005773 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005774 /* let's try again later from this stream. We add ourselves into
5775 * this stream's users so that it can remove us upon termination.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005776 */
Willy Tarreaufe127932015-04-21 19:23:39 +02005777 si_applet_cant_put(si);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005778 return 0;
5779 }
5780
5781 /* get next list entry and check the end of the list */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005782 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
5783 appctx->ctx.map.display_flags);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005784 }
5785
5786 appctx->st2 = STAT_ST_FIN;
5787 /* fall through */
5788
5789 default:
5790 appctx->st2 = STAT_ST_FIN;
5791 return 1;
5792 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005793 return 0;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005794}
5795
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005796static int stats_map_lookup(struct stream_interface *si)
5797{
5798 struct appctx *appctx = __objt_appctx(si->end);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005799 struct sample sample;
5800 struct pattern *pat;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005801 int match_method;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005802
5803 switch (appctx->st2) {
5804 case STAT_ST_INIT:
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005805 /* Init to the first entry. The list cannot be change */
Thierry FOURNIERc5959fd2014-01-20 14:29:33 +01005806 appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005807 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005808 appctx->st2 = STAT_ST_LIST;
5809 /* fall through */
5810
5811 case STAT_ST_LIST:
5812 /* for each lookup type */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005813 while (appctx->ctx.map.expr) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005814 /* initialise chunk to build new message */
5815 chunk_reset(&trash);
5816
5817 /* execute pattern matching */
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02005818 sample.data.type = SMP_T_STR;
Thierry FOURNIER7654c9f2013-12-17 00:20:33 +01005819 sample.flags |= SMP_F_CONST;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02005820 sample.data.u.str.len = appctx->ctx.map.chunk.len;
5821 sample.data.u.str.str = appctx->ctx.map.chunk.str;
Thierry FOURNIER5d344082014-01-27 14:19:53 +01005822 if (appctx->ctx.map.expr->pat_head->match &&
5823 sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type))
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005824 pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1);
5825 else
5826 pat = NULL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005827
5828 /* build return message: set type of match */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005829 for (match_method=0; match_method<PAT_MATCH_NUM; match_method++)
5830 if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method])
5831 break;
5832 if (match_method >= PAT_MATCH_NUM)
5833 chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match);
5834 else
5835 chunk_appendf(&trash, "type=%s", pat_match_names[match_method]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005836
Thierry FOURNIERe47e4e22014-04-28 11:18:57 +02005837 /* case sensitive */
5838 if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE)
5839 chunk_appendf(&trash, ", case=insensitive");
5840 else
5841 chunk_appendf(&trash, ", case=sensitive");
5842
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005843 /* Display no match, and set default value */
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +01005844 if (!pat) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005845 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
5846 chunk_appendf(&trash, ", found=no");
5847 else
5848 chunk_appendf(&trash, ", match=no");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005849 }
5850
5851 /* Display match and match info */
5852 else {
5853 /* display match */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005854 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
5855 chunk_appendf(&trash, ", found=yes");
5856 else
5857 chunk_appendf(&trash, ", match=yes");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005858
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +01005859 /* display index mode */
Thierry FOURNIERe47e4e22014-04-28 11:18:57 +02005860 if (pat->sflags & PAT_SF_TREE)
Thierry FOURNIERb9903842014-03-11 18:48:17 +01005861 chunk_appendf(&trash, ", idx=tree");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005862 else
Thierry FOURNIERb9903842014-03-11 18:48:17 +01005863 chunk_appendf(&trash, ", idx=list");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005864
Thierry FOURNIER86db66a2014-03-11 18:37:58 +01005865 /* display pattern */
5866 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
5867 if (pat->ref && pat->ref->pattern)
5868 chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern);
5869 else
5870 chunk_appendf(&trash, ", key=unknown");
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005871 }
5872 else {
Thierry FOURNIER86db66a2014-03-11 18:37:58 +01005873 if (pat->ref && pat->ref->pattern)
5874 chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern);
5875 else
5876 chunk_appendf(&trash, ", pattern=unknown");
5877 }
5878
5879 /* display return value */
5880 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
Thierry FOURNIER503bb092015-08-19 08:35:43 +02005881 if (pat->data && pat->ref && pat->ref->sample)
Thierry FOURNIER03d0e452015-07-23 18:33:41 +02005882 chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample,
Thierry FOURNIER7d4335c2015-08-19 09:05:25 +02005883 smp_to_type[pat->data->type]);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005884 else
Thierry FOURNIER86db66a2014-03-11 18:37:58 +01005885 chunk_appendf(&trash, ", value=none");
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005886 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005887 }
5888
Thierry FOURNIERb9903842014-03-11 18:48:17 +01005889 chunk_appendf(&trash, "\n");
5890
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005891 /* display response */
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005892 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005893 /* let's try again later from this stream. We add ourselves into
5894 * this stream's users so that it can remove us upon termination.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005895 */
Willy Tarreaufe127932015-04-21 19:23:39 +02005896 si_applet_cant_put(si);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005897 return 0;
5898 }
5899
5900 /* get next entry */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005901 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr,
5902 &appctx->ctx.map.ref->pat);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005903 }
5904
5905 appctx->st2 = STAT_ST_FIN;
5906 /* fall through */
5907
5908 default:
5909 appctx->st2 = STAT_ST_FIN;
5910 free(appctx->ctx.map.chunk.str);
5911 return 1;
5912 }
5913}
5914
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005915static int stats_pat_list(struct stream_interface *si)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005916{
5917 struct appctx *appctx = __objt_appctx(si->end);
5918
5919 switch (appctx->st2) {
5920
5921 case STAT_ST_INIT:
5922 /* Init to the first entry. The list cannot be change */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005923 appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head,
5924 struct pat_ref_elt *, list);
5925 if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head)
5926 appctx->ctx.map.elt = NULL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005927 appctx->st2 = STAT_ST_LIST;
5928 /* fall through */
5929
5930 case STAT_ST_LIST:
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005931 while (appctx->ctx.map.elt) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005932 chunk_reset(&trash);
5933
5934 /* build messages */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005935 if (appctx->ctx.map.elt->sample)
Thierry FOURNIER9356c682014-01-28 15:55:37 +01005936 chunk_appendf(&trash, "%p %s %s\n",
5937 appctx->ctx.map.elt, appctx->ctx.map.elt->pattern,
5938 appctx->ctx.map.elt->sample);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005939 else
Thierry FOURNIER9356c682014-01-28 15:55:37 +01005940 chunk_appendf(&trash, "%p %s\n",
5941 appctx->ctx.map.elt, appctx->ctx.map.elt->pattern);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005942
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005943 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005944 /* let's try again later from this stream. We add ourselves into
5945 * this stream's users so that it can remove us upon termination.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005946 */
Willy Tarreaufe127932015-04-21 19:23:39 +02005947 si_applet_cant_put(si);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005948 return 0;
5949 }
5950
5951 /* get next list entry and check the end of the list */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005952 appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list,
5953 struct pat_ref_elt *, list);
5954 if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005955 break;
5956 }
5957
5958 appctx->st2 = STAT_ST_FIN;
5959 /* fall through */
5960
5961 default:
5962 appctx->st2 = STAT_ST_FIN;
5963 return 1;
5964 }
5965}
5966
Willy Tarreau87b09662015-04-03 00:22:06 +02005967/* This function dumps all streams' states onto the stream interface's
Willy Tarreau306f8302013-07-08 15:53:06 +02005968 * read buffer. It returns 0 if the output buffer is full and it needs
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01005969 * to be called again, otherwise non-zero. It is designed to be called
5970 * from stats_dump_sess_to_buffer() below.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005971 */
Simon Horman9bd2c732011-06-15 15:18:44 +09005972static int stats_dump_sess_to_buffer(struct stream_interface *si)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005973{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005974 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005975 struct connection *conn;
5976
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005977 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005978 /* If we're forced to shut down, we might have to remove our
Willy Tarreau87b09662015-04-03 00:22:06 +02005979 * reference to the last stream being dumped.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005980 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005981 if (appctx->st2 == STAT_ST_LIST) {
5982 if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) {
5983 LIST_DEL(&appctx->ctx.sess.bref.users);
5984 LIST_INIT(&appctx->ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01005985 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005986 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02005987 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005988 }
5989
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005990 chunk_reset(&trash);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005991
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005992 switch (appctx->st2) {
Willy Tarreau295a8372011-03-10 11:25:07 +01005993 case STAT_ST_INIT:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005994 /* the function had not been called yet, let's prepare the
Willy Tarreau87b09662015-04-03 00:22:06 +02005995 * buffer for a response. We initialize the current stream
Willy Tarreaufd3828e2009-02-22 15:17:24 +01005996 * pointer to the first in the global list. When a target
Willy Tarreau87b09662015-04-03 00:22:06 +02005997 * stream is being destroyed, it is responsible for updating
Willy Tarreaufd3828e2009-02-22 15:17:24 +01005998 * this pointer. We know we have reached the end when this
Willy Tarreau87b09662015-04-03 00:22:06 +02005999 * pointer points back to the head of the streams list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006000 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006001 LIST_INIT(&appctx->ctx.sess.bref.users);
Willy Tarreau87b09662015-04-03 00:22:06 +02006002 appctx->ctx.sess.bref.ref = streams.n;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006003 appctx->st2 = STAT_ST_LIST;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006004 /* fall through */
6005
Willy Tarreau295a8372011-03-10 11:25:07 +01006006 case STAT_ST_LIST:
Willy Tarreau87b09662015-04-03 00:22:06 +02006007 /* first, let's detach the back-ref from a possible previous stream */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006008 if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) {
6009 LIST_DEL(&appctx->ctx.sess.bref.users);
6010 LIST_INIT(&appctx->ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01006011 }
6012
6013 /* and start from where we stopped */
Willy Tarreau87b09662015-04-03 00:22:06 +02006014 while (appctx->ctx.sess.bref.ref != &streams) {
Cyril Bontéacd7d632010-11-01 19:26:02 +01006015 char pn[INET6_ADDRSTRLEN];
Willy Tarreau87b09662015-04-03 00:22:06 +02006016 struct stream *curr_sess;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006017
Willy Tarreau87b09662015-04-03 00:22:06 +02006018 curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006019
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006020 if (appctx->ctx.sess.target) {
6021 if (appctx->ctx.sess.target != (void *)-1 && appctx->ctx.sess.target != curr_sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006022 goto next_sess;
6023
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006024 LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006025 /* call the proper dump() function and return if we're missing space */
Willy Tarreau76153662012-11-26 01:16:39 +01006026 if (!stats_dump_full_sess_to_buffer(si, curr_sess))
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006027 return 0;
6028
Willy Tarreau87b09662015-04-03 00:22:06 +02006029 /* stream dump complete */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006030 LIST_DEL(&appctx->ctx.sess.bref.users);
6031 LIST_INIT(&appctx->ctx.sess.bref.users);
6032 if (appctx->ctx.sess.target != (void *)-1) {
6033 appctx->ctx.sess.target = NULL;
Willy Tarreau76153662012-11-26 01:16:39 +01006034 break;
6035 }
6036 else
6037 goto next_sess;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006038 }
6039
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006040 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006041 "%p: proto=%s",
6042 curr_sess,
Willy Tarreauf1e02122015-09-23 12:16:43 +02006043 strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006044
Willy Tarreaud0d8da92015-04-04 02:10:38 +02006045 conn = objt_conn(strm_orig(curr_sess));
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006046 switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02006047 case AF_INET:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006048 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006049 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006050 " src=%s:%d fe=%s be=%s srv=%s",
6051 pn,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006052 get_host_port(&conn->addr.from),
Willy Tarreaud0d8da92015-04-04 02:10:38 +02006053 strm_fe(curr_sess)->id,
Willy Tarreau50943332011-09-02 17:33:05 +02006054 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01006055 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006056 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006057 break;
6058 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006059 chunk_appendf(&trash,
Emeric Brun837ca522010-10-22 16:19:01 +02006060 " src=unix:%d fe=%s be=%s srv=%s",
Willy Tarreaud0d8da92015-04-04 02:10:38 +02006061 strm_li(curr_sess)->luid,
6062 strm_fe(curr_sess)->id,
Willy Tarreau50943332011-09-02 17:33:05 +02006063 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01006064 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Emeric Brun837ca522010-10-22 16:19:01 +02006065 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006066 break;
6067 }
6068
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006069 chunk_appendf(&trash,
Willy Tarreau65671ab2009-10-04 14:24:59 +02006070 " ts=%02x age=%s calls=%d",
6071 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01006072 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
6073 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006074
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006075 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01006076 " rq[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006077 curr_sess->req.flags,
6078 curr_sess->req.buf->i,
6079 curr_sess->req.analysers,
6080 curr_sess->req.rex ?
6081 human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms),
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006082 TICKS_TO_MS(1000)) : "");
6083
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006084 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006085 ",wx=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006086 curr_sess->req.wex ?
6087 human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms),
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006088 TICKS_TO_MS(1000)) : "");
6089
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006090 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006091 ",ax=%s]",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006092 curr_sess->req.analyse_exp ?
6093 human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms),
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006094 TICKS_TO_MS(1000)) : "");
6095
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006096 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01006097 " rp[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006098 curr_sess->res.flags,
6099 curr_sess->res.buf->i,
6100 curr_sess->res.analysers,
6101 curr_sess->res.rex ?
6102 human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms),
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006103 TICKS_TO_MS(1000)) : "");
6104
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006105 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006106 ",wx=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006107 curr_sess->res.wex ?
6108 human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms),
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006109 TICKS_TO_MS(1000)) : "");
6110
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006111 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006112 ",ax=%s]",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006113 curr_sess->res.analyse_exp ?
6114 human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms),
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006115 TICKS_TO_MS(1000)) : "");
6116
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006117 conn = objt_conn(curr_sess->si[0].end);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006118 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006119 " s0=[%d,%1xh,fd=%d,ex=%s]",
6120 curr_sess->si[0].state,
6121 curr_sess->si[0].flags,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006122 conn ? conn->t.sock.fd : -1,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006123 curr_sess->si[0].exp ?
6124 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
6125 TICKS_TO_MS(1000)) : "");
6126
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006127 conn = objt_conn(curr_sess->si[1].end);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006128 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006129 " s1=[%d,%1xh,fd=%d,ex=%s]",
6130 curr_sess->si[1].state,
6131 curr_sess->si[1].flags,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006132 conn ? conn->t.sock.fd : -1,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006133 curr_sess->si[1].exp ?
6134 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
6135 TICKS_TO_MS(1000)) : "");
6136
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006137 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006138 " exp=%s",
6139 curr_sess->task->expire ?
6140 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
6141 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01006142 if (task_in_rq(curr_sess->task))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006143 chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006144
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006145 chunk_appendf(&trash, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006146
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006147 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau87b09662015-04-03 00:22:06 +02006148 /* let's try again later from this stream. We add ourselves into
6149 * this stream's users so that it can remove us upon termination.
Willy Tarreaufd3828e2009-02-22 15:17:24 +01006150 */
Willy Tarreaufe127932015-04-21 19:23:39 +02006151 si_applet_cant_put(si);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006152 LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02006153 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006154 }
6155
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006156 next_sess:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006157 appctx->ctx.sess.bref.ref = curr_sess->list.n;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006158 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006159
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006160 if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) {
Willy Tarreau87b09662015-04-03 00:22:06 +02006161 /* specified stream not found */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006162 if (appctx->ctx.sess.section > 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006163 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006164 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006165 chunk_appendf(&trash, "Session not found.\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006166
Willy Tarreaubc18da12015-03-13 14:00:47 +01006167 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02006168 si_applet_cant_put(si);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006169 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01006170 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006171
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006172 appctx->ctx.sess.target = NULL;
6173 appctx->ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006174 return 1;
6175 }
6176
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006177 appctx->st2 = STAT_ST_FIN;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006178 /* fall through */
6179
6180 default:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006181 appctx->st2 = STAT_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02006182 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006183 }
Emeric Brun1e029aa2010-09-23 18:12:53 +02006184}
6185
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006186/* This is called when the stream interface is closed. For instance, upon an
6187 * external abort, we won't call the i/o handler anymore so we may need to
Willy Tarreau87b09662015-04-03 00:22:06 +02006188 * remove back references to the stream currently being dumped.
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006189 */
Willy Tarreau00a37f02015-04-13 12:05:19 +02006190static void cli_release_handler(struct appctx *appctx)
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006191{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006192 if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) {
6193 if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users))
6194 LIST_DEL(&appctx->ctx.sess.bref.users);
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006195 }
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01006196 else if (appctx->st0 == STAT_CLI_PRINT_FREE) {
6197 free(appctx->ctx.cli.err);
Willy Tarreau6457d0f2015-10-07 20:00:24 +02006198 appctx->ctx.cli.err = NULL;
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01006199 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01006200 else if (appctx->st0 == STAT_CLI_O_MLOOK) {
6201 free(appctx->ctx.map.chunk.str);
Willy Tarreau6457d0f2015-10-07 20:00:24 +02006202 appctx->ctx.map.chunk.str = NULL;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01006203 }
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006204}
6205
Willy Tarreau20e99322013-04-13 09:22:25 +02006206/* This function is used to either dump tables states (when action is set
6207 * to STAT_CLI_O_TAB) or clear tables (when action is STAT_CLI_O_CLR).
Willy Tarreau20e99322013-04-13 09:22:25 +02006208 * It returns 0 if the output buffer is full and it needs to be called
6209 * again, otherwise non-zero.
Willy Tarreau69f58c82010-07-12 17:55:33 +02006210 */
Willy Tarreau20e99322013-04-13 09:22:25 +02006211static int stats_table_request(struct stream_interface *si, int action)
Willy Tarreau69f58c82010-07-12 17:55:33 +02006212{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006213 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau87b09662015-04-03 00:22:06 +02006214 struct stream *s = si_strm(si);
Willy Tarreau69f58c82010-07-12 17:55:33 +02006215 struct ebmb_node *eb;
6216 int dt;
Willy Tarreau44455022012-12-05 23:01:12 +01006217 int skip_entry;
Willy Tarreau20e99322013-04-13 09:22:25 +02006218 int show = action == STAT_CLI_O_TAB;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006219
6220 /*
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006221 * We have 3 possible states in appctx->st2 :
Willy Tarreau295a8372011-03-10 11:25:07 +01006222 * - STAT_ST_INIT : the first call
6223 * - STAT_ST_INFO : the proxy pointer points to the next table to
Willy Tarreau69f58c82010-07-12 17:55:33 +02006224 * dump, the entry pointer is NULL ;
Willy Tarreau295a8372011-03-10 11:25:07 +01006225 * - STAT_ST_LIST : the proxy pointer points to the current table
Willy Tarreau69f58c82010-07-12 17:55:33 +02006226 * and the entry pointer points to the next entry to be dumped,
6227 * and the refcount on the next entry is held ;
Willy Tarreau295a8372011-03-10 11:25:07 +01006228 * - STAT_ST_END : nothing left to dump, the buffer may contain some
Willy Tarreau69f58c82010-07-12 17:55:33 +02006229 * data though.
6230 */
6231
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006232 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02006233 /* in case of abort, remove any refcount we might have set on an entry */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006234 if (appctx->st2 == STAT_ST_LIST) {
6235 appctx->ctx.table.entry->ref_cnt--;
6236 stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry);
Willy Tarreauf6efda12010-08-03 20:34:06 +02006237 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02006238 return 1;
6239 }
6240
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006241 chunk_reset(&trash);
Willy Tarreau69f58c82010-07-12 17:55:33 +02006242
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006243 while (appctx->st2 != STAT_ST_FIN) {
6244 switch (appctx->st2) {
Willy Tarreau295a8372011-03-10 11:25:07 +01006245 case STAT_ST_INIT:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006246 appctx->ctx.table.proxy = appctx->ctx.table.target;
6247 if (!appctx->ctx.table.proxy)
6248 appctx->ctx.table.proxy = proxy;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006249
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006250 appctx->ctx.table.entry = NULL;
6251 appctx->st2 = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006252 break;
6253
Willy Tarreau295a8372011-03-10 11:25:07 +01006254 case STAT_ST_INFO:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006255 if (!appctx->ctx.table.proxy ||
6256 (appctx->ctx.table.target &&
6257 appctx->ctx.table.proxy != appctx->ctx.table.target)) {
6258 appctx->st2 = STAT_ST_END;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006259 break;
6260 }
6261
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006262 if (appctx->ctx.table.proxy->table.size) {
6263 if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy,
6264 appctx->ctx.table.target))
Willy Tarreau69f58c82010-07-12 17:55:33 +02006265 return 0;
6266
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006267 if (appctx->ctx.table.target &&
Willy Tarreaud0d8da92015-04-04 02:10:38 +02006268 strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02006269 /* dump entries only if table explicitly requested */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006270 eb = ebmb_first(&appctx->ctx.table.proxy->table.keys);
Willy Tarreau69f58c82010-07-12 17:55:33 +02006271 if (eb) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006272 appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key);
6273 appctx->ctx.table.entry->ref_cnt++;
6274 appctx->st2 = STAT_ST_LIST;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006275 break;
6276 }
6277 }
6278 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006279 appctx->ctx.table.proxy = appctx->ctx.table.proxy->next;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006280 break;
6281
Willy Tarreau295a8372011-03-10 11:25:07 +01006282 case STAT_ST_LIST:
Willy Tarreau44455022012-12-05 23:01:12 +01006283 skip_entry = 0;
Simon Hormanc88b8872011-06-15 15:18:49 +09006284
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006285 if (appctx->ctx.table.data_type >= 0) {
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02006286 /* we're filtering on some data contents */
6287 void *ptr;
6288 long long data;
6289
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006290 dt = appctx->ctx.table.data_type;
6291 ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table,
6292 appctx->ctx.table.entry,
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02006293 dt);
6294
6295 data = 0;
6296 switch (stktable_data_types[dt].std_type) {
6297 case STD_T_SINT:
6298 data = stktable_data_cast(ptr, std_t_sint);
6299 break;
6300 case STD_T_UINT:
6301 data = stktable_data_cast(ptr, std_t_uint);
6302 break;
6303 case STD_T_ULL:
6304 data = stktable_data_cast(ptr, std_t_ull);
6305 break;
6306 case STD_T_FRQP:
6307 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006308 appctx->ctx.table.proxy->table.data_arg[dt].u);
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02006309 break;
6310 }
6311
6312 /* skip the entry if the data does not match the test and the value */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006313 if ((data < appctx->ctx.table.value &&
6314 (appctx->ctx.table.data_op == STD_OP_EQ ||
6315 appctx->ctx.table.data_op == STD_OP_GT ||
6316 appctx->ctx.table.data_op == STD_OP_GE)) ||
6317 (data == appctx->ctx.table.value &&
6318 (appctx->ctx.table.data_op == STD_OP_NE ||
6319 appctx->ctx.table.data_op == STD_OP_GT ||
6320 appctx->ctx.table.data_op == STD_OP_LT)) ||
6321 (data > appctx->ctx.table.value &&
6322 (appctx->ctx.table.data_op == STD_OP_EQ ||
6323 appctx->ctx.table.data_op == STD_OP_LT ||
6324 appctx->ctx.table.data_op == STD_OP_LE)))
Willy Tarreau44455022012-12-05 23:01:12 +01006325 skip_entry = 1;
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02006326 }
6327
Simon Hormanc88b8872011-06-15 15:18:49 +09006328 if (show && !skip_entry &&
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006329 !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy,
6330 appctx->ctx.table.entry))
Simon Hormand9366582011-06-15 15:18:45 +09006331 return 0;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006332
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006333 appctx->ctx.table.entry->ref_cnt--;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006334
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006335 eb = ebmb_next(&appctx->ctx.table.entry->key);
Willy Tarreau69f58c82010-07-12 17:55:33 +02006336 if (eb) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006337 struct stksess *old = appctx->ctx.table.entry;
6338 appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key);
Willy Tarreau8fa52f42012-01-09 11:50:03 +01006339 if (show)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006340 stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old);
6341 else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt)
6342 stksess_kill(&appctx->ctx.table.proxy->table, old);
6343 appctx->ctx.table.entry->ref_cnt++;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006344 break;
6345 }
6346
Simon Hormanc88b8872011-06-15 15:18:49 +09006347
6348 if (show)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006349 stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry);
6350 else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt)
6351 stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry);
Simon Hormanc88b8872011-06-15 15:18:49 +09006352
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006353 appctx->ctx.table.proxy = appctx->ctx.table.proxy->next;
6354 appctx->st2 = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006355 break;
6356
Willy Tarreau295a8372011-03-10 11:25:07 +01006357 case STAT_ST_END:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006358 appctx->st2 = STAT_ST_FIN;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006359 break;
6360 }
6361 }
6362 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006363}
6364
Willy Tarreaud426a182010-03-05 14:58:26 +01006365/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
Willy Tarreau74808cb2009-03-04 15:53:18 +01006366 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
6367 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
6368 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
6369 * lines are respected within the limit of 70 output chars. Lines that are
6370 * continuation of a previous truncated line begin with "+" instead of " "
6371 * after the offset. The new pointer is returned.
6372 */
Willy Tarreaud426a182010-03-05 14:58:26 +01006373static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
6374 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01006375{
6376 int end;
6377 unsigned char c;
6378
6379 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02006380 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01006381 return ptr;
6382
Willy Tarreau77804732012-10-29 16:14:26 +01006383 chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01006384
Willy Tarreaud426a182010-03-05 14:58:26 +01006385 while (ptr < len && ptr < bsize) {
6386 c = buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01006387 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006388 if (out->len > end - 2)
6389 break;
6390 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01006391 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006392 if (out->len > end - 3)
6393 break;
6394 out->str[out->len++] = '\\';
6395 switch (c) {
6396 case '\t': c = 't'; break;
6397 case '\n': c = 'n'; break;
6398 case '\r': c = 'r'; break;
6399 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01006400 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006401 }
6402 out->str[out->len++] = c;
6403 } else {
6404 if (out->len > end - 5)
6405 break;
6406 out->str[out->len++] = '\\';
6407 out->str[out->len++] = 'x';
6408 out->str[out->len++] = hextab[(c >> 4) & 0xF];
6409 out->str[out->len++] = hextab[c & 0xF];
6410 }
Willy Tarreaud426a182010-03-05 14:58:26 +01006411 if (buf[ptr++] == '\n') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006412 /* we had a line break, let's return now */
6413 out->str[out->len++] = '\n';
6414 *line = ptr;
6415 return ptr;
6416 }
6417 }
6418 /* we have an incomplete line, we return it as-is */
6419 out->str[out->len++] = '\n';
6420 return ptr;
6421}
6422
Baptiste Assmann3863f972015-05-17 00:33:24 +02006423/* This function dumps counters from all resolvers section and associated name servers.
6424 * It returns 0 if the output buffer is full and it needs
6425 * to be called again, otherwise non-zero.
6426 */
6427static int stats_dump_resolvers_to_buffer(struct stream_interface *si)
6428{
6429 struct appctx *appctx = __objt_appctx(si->end);
6430 struct dns_resolvers *presolvers;
6431 struct dns_nameserver *pnameserver;
6432
6433 chunk_reset(&trash);
6434
6435 switch (appctx->st2) {
6436 case STAT_ST_INIT:
6437 appctx->st2 = STAT_ST_LIST; /* let's start producing data */
6438 /* fall through */
6439
6440 case STAT_ST_LIST:
Andrew Hayworth68d05342015-10-02 20:33:01 +00006441 if (LIST_ISEMPTY(&dns_resolvers)) {
6442 chunk_appendf(&trash, "No resolvers found\n");
6443 }
6444 else {
6445 list_for_each_entry(presolvers, &dns_resolvers, list) {
6446 if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers)
6447 continue;
6448
6449 chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id);
6450 list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) {
6451 chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id);
6452 chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent);
6453 chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid);
6454 chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update);
6455 chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname);
6456 chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error);
6457 chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err);
6458 chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx);
6459 chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout);
6460 chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused);
6461 chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other);
6462 chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid);
6463 chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big);
6464 chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated);
6465 chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated);
6466 }
6467 }
Baptiste Assmann3863f972015-05-17 00:33:24 +02006468 }
6469
6470 /* display response */
6471 if (bi_putchk(si_ic(si), &trash) == -1) {
6472 /* let's try again later from this session. We add ourselves into
6473 * this session's users so that it can remove us upon termination.
6474 */
6475 si->flags |= SI_FL_WAIT_ROOM;
6476 return 0;
6477 }
6478
6479 appctx->st2 = STAT_ST_FIN;
6480 /* fall through */
6481
6482 default:
6483 appctx->st2 = STAT_ST_FIN;
6484 return 1;
6485 }
6486}
6487
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02006488/* This function dumps all captured errors onto the stream interface's
Willy Tarreau306f8302013-07-08 15:53:06 +02006489 * read buffer. It returns 0 if the output buffer is full and it needs
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01006490 * to be called again, otherwise non-zero.
Willy Tarreau74808cb2009-03-04 15:53:18 +01006491 */
Simon Horman9bd2c732011-06-15 15:18:44 +09006492static int stats_dump_errors_to_buffer(struct stream_interface *si)
Willy Tarreau74808cb2009-03-04 15:53:18 +01006493{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006494 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau74808cb2009-03-04 15:53:18 +01006495 extern const char *monthname[12];
Willy Tarreau74808cb2009-03-04 15:53:18 +01006496
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006497 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
Willy Tarreau61b34732009-10-03 23:49:35 +02006498 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006499
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006500 chunk_reset(&trash);
Willy Tarreau74808cb2009-03-04 15:53:18 +01006501
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006502 if (!appctx->ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006503 /* the function had not been called yet, let's prepare the
6504 * buffer for a response.
6505 */
Willy Tarreau10479e42010-12-12 14:00:34 +01006506 struct tm tm;
6507
6508 get_localtime(date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006509 chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n",
Willy Tarreau10479e42010-12-12 14:00:34 +01006510 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
6511 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000),
6512 error_snapshot_id);
6513
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006514 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau10479e42010-12-12 14:00:34 +01006515 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreaufe127932015-04-21 19:23:39 +02006516 si_applet_cant_put(si);
Willy Tarreau10479e42010-12-12 14:00:34 +01006517 return 0;
6518 }
6519
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006520 appctx->ctx.errors.px = proxy;
6521 appctx->ctx.errors.buf = 0;
6522 appctx->ctx.errors.bol = 0;
6523 appctx->ctx.errors.ptr = -1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006524 }
6525
6526 /* we have two inner loops here, one for the proxy, the other one for
6527 * the buffer.
6528 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006529 while (appctx->ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006530 struct error_snapshot *es;
6531
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006532 if (appctx->ctx.errors.buf == 0)
6533 es = &appctx->ctx.errors.px->invalid_req;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006534 else
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006535 es = &appctx->ctx.errors.px->invalid_rep;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006536
6537 if (!es->when.tv_sec)
6538 goto next;
6539
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006540 if (appctx->ctx.errors.iid >= 0 &&
6541 appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid &&
6542 es->oe->uuid != appctx->ctx.errors.iid)
Willy Tarreau74808cb2009-03-04 15:53:18 +01006543 goto next;
6544
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006545 if (appctx->ctx.errors.ptr < 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006546 /* just print headers now */
6547
6548 char pn[INET6_ADDRSTRLEN];
6549 struct tm tm;
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006550 int port;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006551
6552 get_localtime(es->when.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006553 chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01006554 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02006555 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01006556
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006557 switch (addr_to_str(&es->src, pn, sizeof(pn))) {
6558 case AF_INET:
6559 case AF_INET6:
6560 port = get_host_port(&es->src);
6561 break;
6562 default:
6563 port = 0;
6564 }
6565
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006566 switch (appctx->ctx.errors.buf) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006567 case 0:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006568 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01006569 " frontend %s (#%d): invalid request\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006570 " backend %s (#%d)",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006571 appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006572 (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
6573 (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1);
Willy Tarreau74808cb2009-03-04 15:53:18 +01006574 break;
6575 case 1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006576 chunk_appendf(&trash,
Olivier Doucet08afdcb2014-09-08 11:23:00 +02006577 " backend %s (#%d): invalid response\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006578 " frontend %s (#%d)",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006579 appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006580 es->oe->id, es->oe->uuid);
Willy Tarreau74808cb2009-03-04 15:53:18 +01006581 break;
6582 }
6583
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006584 chunk_appendf(&trash,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006585 ", server %s (#%d), event #%u\n"
6586 " src %s:%d, session #%d, session flags 0x%08x\n"
6587 " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n"
6588 " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n"
6589 " buffer flags 0x%08x, out %d bytes, total %lld bytes\n"
6590 " pending %d bytes, wrapping at %d, error at position %d:\n \n",
6591 es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1,
6592 es->ev_id,
6593 pn, port, es->sid, es->s_flags,
6594 es->state, es->m_flags, es->t_flags,
6595 es->m_clen, es->m_blen,
6596 es->b_flags, es->b_out, es->b_tot,
6597 es->len, es->b_wrap, es->pos);
6598
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006599 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006600 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreaufe127932015-04-21 19:23:39 +02006601 si_applet_cant_put(si);
Willy Tarreau61b34732009-10-03 23:49:35 +02006602 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006603 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006604 appctx->ctx.errors.ptr = 0;
6605 appctx->ctx.errors.sid = es->sid;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006606 }
6607
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006608 if (appctx->ctx.errors.sid != es->sid) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006609 /* the snapshot changed while we were dumping it */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006610 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01006611 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreaubc18da12015-03-13 14:00:47 +01006612 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02006613 si_applet_cant_put(si);
Willy Tarreau61b34732009-10-03 23:49:35 +02006614 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01006615 }
Willy Tarreau74808cb2009-03-04 15:53:18 +01006616 goto next;
6617 }
6618
6619 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006620 while (appctx->ctx.errors.ptr < es->len && appctx->ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006621 int newptr;
6622 int newline;
6623
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006624 newline = appctx->ctx.errors.bol;
6625 newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr);
6626 if (newptr == appctx->ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02006627 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006628
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006629 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006630 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreaufe127932015-04-21 19:23:39 +02006631 si_applet_cant_put(si);
Willy Tarreau61b34732009-10-03 23:49:35 +02006632 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006633 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006634 appctx->ctx.errors.ptr = newptr;
6635 appctx->ctx.errors.bol = newline;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006636 };
6637 next:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006638 appctx->ctx.errors.bol = 0;
6639 appctx->ctx.errors.ptr = -1;
6640 appctx->ctx.errors.buf++;
6641 if (appctx->ctx.errors.buf > 1) {
6642 appctx->ctx.errors.buf = 0;
6643 appctx->ctx.errors.px = appctx->ctx.errors.px->next;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006644 }
6645 }
6646
6647 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02006648 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006649}
6650
Willy Tarreaud5781202012-09-22 19:32:35 +02006651/* parse the "level" argument on the bind lines */
6652static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
6653{
6654 if (!*args[cur_arg + 1]) {
6655 memprintf(err, "'%s' : missing level", args[cur_arg]);
6656 return ERR_ALERT | ERR_FATAL;
6657 }
6658
6659 if (!strcmp(args[cur_arg+1], "user"))
6660 conf->level = ACCESS_LVL_USER;
6661 else if (!strcmp(args[cur_arg+1], "operator"))
6662 conf->level = ACCESS_LVL_OPER;
6663 else if (!strcmp(args[cur_arg+1], "admin"))
6664 conf->level = ACCESS_LVL_ADMIN;
6665 else {
6666 memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')",
6667 args[cur_arg], args[cur_arg+1]);
6668 return ERR_ALERT | ERR_FATAL;
6669 }
6670
6671 return 0;
6672}
6673
Willy Tarreau30576452015-04-13 13:50:30 +02006674struct applet http_stats_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01006675 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01006676 .name = "<STATS>", /* used for logging */
6677 .fct = http_stats_io_handler,
Aman Gupta9a13e842012-04-02 18:57:53 -07006678 .release = NULL,
Willy Tarreaub24281b2011-02-13 13:16:36 +01006679};
6680
Willy Tarreau30576452015-04-13 13:50:30 +02006681static struct applet cli_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01006682 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01006683 .name = "<CLI>", /* used for logging */
6684 .fct = cli_io_handler,
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006685 .release = cli_release_handler,
Willy Tarreaub24281b2011-02-13 13:16:36 +01006686};
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006687
Willy Tarreaudc13c112013-06-21 23:16:39 +02006688static struct cfg_kw_list cfg_kws = {ILH, {
Willy Tarreau10522fd2008-07-09 20:12:41 +02006689 { CFG_GLOBAL, "stats", stats_parse_global },
6690 { 0, NULL, NULL },
6691}};
6692
Willy Tarreaud5781202012-09-22 19:32:35 +02006693static struct bind_kw_list bind_kws = { "STAT", { }, {
6694 { "level", bind_parse_level, 1 }, /* set the unix socket admin level */
6695 { NULL, NULL, 0 },
6696}};
6697
Willy Tarreau10522fd2008-07-09 20:12:41 +02006698__attribute__((constructor))
6699static void __dumpstats_module_init(void)
6700{
6701 cfg_register_keywords(&cfg_kws);
Willy Tarreaud5781202012-09-22 19:32:35 +02006702 bind_register_keywords(&bind_kws);
Willy Tarreau10522fd2008-07-09 20:12:41 +02006703}
6704
Willy Tarreau91861262007-10-17 17:06:05 +02006705/*
6706 * Local variables:
6707 * c-indent-level: 8
6708 * c-basic-offset: 8
6709 * End:
6710 */