blob: 2cfaded6f956666a32c881a048168b9925b5a999 [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 Tarreaua1c2b2c2015-11-26 18:32:39 +01001839 if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) {
1840 appctx->ctx.cli.msg = stats_permission_denied_msg;
1841 appctx->st0 = STAT_CLI_PRINT;
1842 return 1;
1843 }
1844
Willy Tarreau85d47f92012-11-21 00:29:50 +01001845 if (!*args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001846 appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n";
1847 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau85d47f92012-11-21 00:29:50 +01001848 return 1;
1849 }
1850
William Lallemandd85f9172012-11-09 17:05:39 +01001851 v = atoi(args[4]);
1852 global.comp_rate_lim = v * 1024; /* Kilo to bytes. */
1853 }
1854 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001855 appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n";
1856 appctx->st0 = STAT_CLI_PRINT;
William Lallemandd85f9172012-11-09 17:05:39 +01001857 return 1;
1858 }
1859 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001860 else {
Willy Tarreaue43d5322013-10-07 20:01:52 +02001861 appctx->ctx.cli.msg = "'set rate-limit' supports 'connections', 'sessions', 'ssl-sessions', and 'http-compression'.\n";
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001862 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001863 return 1;
1864 }
1865 }
Willy Tarreau654694e2012-06-07 01:03:16 +02001866 else if (strcmp(args[1], "table") == 0) {
1867 stats_sock_table_request(si, args, STAT_CLI_O_SET);
1868 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001869 else if (strcmp(args[1], "map") == 0) {
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01001870 char *err;
1871
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001872 /* Set flags. */
1873 appctx->ctx.map.display_flags = PAT_REF_MAP;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001874
1875 /* Expect three parameters: map name, key and new value. */
1876 if (!*args[2] || !*args[3] || !*args[4]) {
Thierry FOURNIERd5723432014-03-11 13:52:44 +01001877 appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001878 appctx->st0 = STAT_CLI_PRINT;
1879 return 1;
1880 }
1881
1882 /* Lookup the reference in the maps. */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001883 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001884 if (!appctx->ctx.map.ref) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001885 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001886 appctx->st0 = STAT_CLI_PRINT;
1887 return 1;
1888 }
1889
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001890 /* If the entry identifier start with a '#', it is considered as
1891 * pointer id
1892 */
1893 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
1894 struct pat_ref_elt *ref;
1895 long long int conv;
1896 char *error;
1897
1898 /* Convert argument to integer value. */
1899 conv = strtoll(&args[3][1], &error, 16);
1900 if (*error != '\0') {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001901 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001902 appctx->st0 = STAT_CLI_PRINT;
1903 return 1;
1904 }
1905
1906 /* Convert and check integer to pointer. */
1907 ref = (struct pat_ref_elt *)(long)conv;
1908 if ((long long int)(long)ref != conv) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001909 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001910 appctx->st0 = STAT_CLI_PRINT;
1911 return 1;
1912 }
1913
1914 /* Try to delete the entry. */
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01001915 err = NULL;
1916 if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) {
1917 if (err)
1918 memprintf(&err, "%s.\n", err);
1919 appctx->ctx.cli.err = err;
1920 appctx->st0 = STAT_CLI_PRINT_FREE;
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001921 return 1;
1922 }
1923 }
1924 else {
1925 /* Else, use the entry identifier as pattern
1926 * string, and update the value.
1927 */
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01001928 err = NULL;
1929 if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) {
1930 if (err)
1931 memprintf(&err, "%s.\n", err);
1932 appctx->ctx.cli.err = err;
1933 appctx->st0 = STAT_CLI_PRINT_FREE;
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001934 return 1;
1935 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001936 }
1937
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001938 /* The set is done, send message. */
Thierry FOURNIER07e78c52014-12-18 15:28:01 +01001939 appctx->st0 = STAT_CLI_PROMPT;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001940 return 1;
1941 }
Emeric Brun4147b2e2014-06-16 18:36:30 +02001942#ifdef USE_OPENSSL
1943 else if (strcmp(args[1], "ssl") == 0) {
1944 if (strcmp(args[2], "ocsp-response") == 0) {
Lukas Tribuse4e30f72014-12-09 16:32:51 +01001945#if (defined SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB && !defined OPENSSL_NO_OCSP)
Emeric Brun4147b2e2014-06-16 18:36:30 +02001946 char *err = NULL;
1947
Emeric Brunaf4ef742014-06-19 14:10:45 +02001948 /* Expect one parameter: the new response in base64 encoding */
Emeric Brun4147b2e2014-06-16 18:36:30 +02001949 if (!*args[3]) {
1950 appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n";
1951 appctx->st0 = STAT_CLI_PRINT;
1952 return 1;
1953 }
1954
1955 trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size);
1956 if (trash.len < 0) {
1957 appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n";
1958 appctx->st0 = STAT_CLI_PRINT;
1959 return 1;
1960 }
1961
1962 if (ssl_sock_update_ocsp_response(&trash, &err)) {
1963 if (err) {
1964 memprintf(&err, "%s.\n", err);
1965 appctx->ctx.cli.err = err;
1966 appctx->st0 = STAT_CLI_PRINT_FREE;
1967 }
1968 return 1;
1969 }
1970 appctx->ctx.cli.msg = "OCSP Response updated!";
1971 appctx->st0 = STAT_CLI_PRINT;
1972 return 1;
1973#else
1974 appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n";
1975 appctx->st0 = STAT_CLI_PRINT;
1976 return 1;
1977#endif
1978 }
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +02001979 else if (strcmp(args[2], "tls-key") == 0) {
1980#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
1981 /* Expect two parameters: the filename and the new new TLS key in encoding */
1982 if (!*args[3] || !*args[4]) {
1983 appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n";
1984 appctx->st0 = STAT_CLI_PRINT;
1985 return 1;
1986 }
1987
1988 appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]);
1989 if(!appctx->ctx.tlskeys.ref) {
1990 appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n";
1991 appctx->st0 = STAT_CLI_PRINT;
1992 return 1;
1993 }
1994
1995 trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size);
1996 if (trash.len != sizeof(struct tls_sess_key)) {
1997 appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n";
1998 appctx->st0 = STAT_CLI_PRINT;
1999 return 1;
2000 }
2001
Pradeep Jindalcc79b002015-08-20 18:25:17 +05302002 memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len);
2003 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 +02002004
2005 appctx->ctx.cli.msg = "TLS ticket key updated!";
2006 appctx->st0 = STAT_CLI_PRINT;
2007 return 1;
2008#else
2009 appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL "
2010 "that doesn't support specifying TLS ticket keys\n";
2011 appctx->st0 = STAT_CLI_PRINT;
2012 return 1;
2013#endif
2014 }
Emeric Brun4147b2e2014-06-16 18:36:30 +02002015 else {
2016 appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n";
2017 appctx->st0 = STAT_CLI_PRINT;
2018 return 1;
2019 }
2020 }
2021#endif
Willy Tarreau7aabd112010-01-26 10:59:06 +01002022 else { /* unknown "set" parameter */
Willy Tarreau4483d432009-10-10 19:30:08 +02002023 return 0;
2024 }
2025 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002026 else if (strcmp(args[0], "enable") == 0) {
Simon Horman671b6f02013-11-25 10:46:39 +09002027 if (strcmp(args[1], "agent") == 0) {
2028 struct server *sv;
2029
2030 sv = expect_server_admin(s, si, args[2]);
2031 if (!sv)
2032 return 1;
2033
Willy Tarreau2e10f5a2013-12-11 20:11:55 +01002034 if (!(sv->agent.state & CHK_ST_CONFIGURED)) {
2035 appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n";
2036 appctx->st0 = STAT_CLI_PRINT;
2037 return 1;
2038 }
2039
2040 sv->agent.state |= CHK_ST_ENABLED;
Simon Horman671b6f02013-11-25 10:46:39 +09002041 return 1;
2042 }
Willy Tarreau9b5aecd2014-05-23 11:53:10 +02002043 else if (strcmp(args[1], "health") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01002044 struct server *sv;
2045
Willy Tarreaud52c41e2011-09-07 23:41:01 +02002046 sv = expect_server_admin(s, si, args[2]);
2047 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01002048 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01002049
Willy Tarreau9b5aecd2014-05-23 11:53:10 +02002050 if (!(sv->check.state & CHK_ST_CONFIGURED)) {
2051 appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n";
2052 appctx->st0 = STAT_CLI_PRINT;
2053 return 1;
2054 }
2055
2056 sv->check.state |= CHK_ST_ENABLED;
2057 return 1;
2058 }
2059 else if (strcmp(args[1], "server") == 0) {
2060 struct server *sv;
2061
2062 sv = expect_server_admin(s, si, args[2]);
2063 if (!sv)
2064 return 1;
2065
Willy Tarreaubfc7b7a2014-05-22 16:14:34 +02002066 srv_adm_set_ready(sv);
Willy Tarreau532a4502011-09-07 22:37:44 +02002067 return 1;
2068 }
2069 else if (strcmp(args[1], "frontend") == 0) {
2070 struct proxy *px;
2071
2072 px = expect_frontend_admin(s, si, args[2]);
2073 if (!px)
2074 return 1;
2075
2076 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002077 appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n";
2078 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002079 return 1;
2080 }
2081
2082 if (px->state != PR_STPAUSED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002083 appctx->ctx.cli.msg = "Frontend is already enabled.\n";
2084 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002085 return 1;
2086 }
2087
2088 if (!resume_proxy(px)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002089 appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n";
2090 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002091 return 1;
2092 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002093 return 1;
2094 }
2095 else { /* unknown "enable" parameter */
Willy Tarreau9b5aecd2014-05-23 11:53:10 +02002096 appctx->ctx.cli.msg = "'enable' only supports 'agent', 'frontend', 'health', and 'server'.\n";
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002097 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002098 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01002099 }
2100 }
2101 else if (strcmp(args[0], "disable") == 0) {
Simon Horman671b6f02013-11-25 10:46:39 +09002102 if (strcmp(args[1], "agent") == 0) {
2103 struct server *sv;
2104
2105 sv = expect_server_admin(s, si, args[2]);
2106 if (!sv)
2107 return 1;
2108
Willy Tarreau2e10f5a2013-12-11 20:11:55 +01002109 sv->agent.state &= ~CHK_ST_ENABLED;
Simon Horman671b6f02013-11-25 10:46:39 +09002110 return 1;
2111 }
Willy Tarreau9b5aecd2014-05-23 11:53:10 +02002112 else if (strcmp(args[1], "health") == 0) {
2113 struct server *sv;
2114
2115 sv = expect_server_admin(s, si, args[2]);
2116 if (!sv)
2117 return 1;
2118
2119 sv->check.state &= ~CHK_ST_ENABLED;
2120 return 1;
2121 }
Simon Horman671b6f02013-11-25 10:46:39 +09002122 else if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01002123 struct server *sv;
2124
Willy Tarreaud52c41e2011-09-07 23:41:01 +02002125 sv = expect_server_admin(s, si, args[2]);
2126 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01002127 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01002128
Willy Tarreaubfc7b7a2014-05-22 16:14:34 +02002129 srv_adm_set_maint(sv);
Willy Tarreau532a4502011-09-07 22:37:44 +02002130 return 1;
2131 }
2132 else if (strcmp(args[1], "frontend") == 0) {
2133 struct proxy *px;
2134
2135 px = expect_frontend_admin(s, si, args[2]);
2136 if (!px)
2137 return 1;
2138
2139 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002140 appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n";
2141 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002142 return 1;
2143 }
2144
2145 if (px->state == PR_STPAUSED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002146 appctx->ctx.cli.msg = "Frontend is already disabled.\n";
2147 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002148 return 1;
2149 }
2150
2151 if (!pause_proxy(px)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002152 appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n";
2153 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002154 return 1;
2155 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002156 return 1;
2157 }
2158 else { /* unknown "disable" parameter */
Willy Tarreau9b5aecd2014-05-23 11:53:10 +02002159 appctx->ctx.cli.msg = "'disable' only supports 'agent', 'frontend', 'health', and 'server'.\n";
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002160 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002161 return 1;
2162 }
2163 }
2164 else if (strcmp(args[0], "shutdown") == 0) {
2165 if (strcmp(args[1], "frontend") == 0) {
2166 struct proxy *px;
2167
2168 px = expect_frontend_admin(s, si, args[2]);
2169 if (!px)
2170 return 1;
2171
2172 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002173 appctx->ctx.cli.msg = "Frontend was already shut down.\n";
2174 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002175 return 1;
2176 }
2177
2178 Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
2179 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
2180 send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
2181 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
2182 stop_proxy(px);
2183 return 1;
2184 }
Willy Tarreaua295edc2011-09-07 23:21:03 +02002185 else if (strcmp(args[1], "session") == 0) {
Willy Tarreau87b09662015-04-03 00:22:06 +02002186 struct stream *sess, *ptr;
Willy Tarreaua295edc2011-09-07 23:21:03 +02002187
Willy Tarreaud0d8da92015-04-04 02:10:38 +02002188 if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002189 appctx->ctx.cli.msg = stats_permission_denied_msg;
2190 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaua295edc2011-09-07 23:21:03 +02002191 return 1;
2192 }
2193
2194 if (!*args[2]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002195 appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n";
2196 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaua295edc2011-09-07 23:21:03 +02002197 return 1;
2198 }
2199
2200 ptr = (void *)strtoul(args[2], NULL, 0);
2201
Willy Tarreau87b09662015-04-03 00:22:06 +02002202 /* first, look for the requested stream in the stream table */
2203 list_for_each_entry(sess, &streams, list) {
Willy Tarreaua295edc2011-09-07 23:21:03 +02002204 if (sess == ptr)
2205 break;
2206 }
2207
Willy Tarreau87b09662015-04-03 00:22:06 +02002208 /* do we have the stream ? */
Willy Tarreaua295edc2011-09-07 23:21:03 +02002209 if (sess != ptr) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002210 appctx->ctx.cli.msg = "No such session (use 'show sess').\n";
2211 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaua295edc2011-09-07 23:21:03 +02002212 return 1;
2213 }
2214
Willy Tarreaue7dff022015-04-03 01:14:29 +02002215 stream_shutdown(sess, SF_ERR_KILLED);
Willy Tarreaua295edc2011-09-07 23:21:03 +02002216 return 1;
2217 }
Willy Tarreau52b2d222011-09-07 23:48:48 +02002218 else if (strcmp(args[1], "sessions") == 0) {
2219 if (strcmp(args[2], "server") == 0) {
2220 struct server *sv;
Willy Tarreau87b09662015-04-03 00:22:06 +02002221 struct stream *sess, *sess_bck;
Willy Tarreau52b2d222011-09-07 23:48:48 +02002222
2223 sv = expect_server_admin(s, si, args[3]);
2224 if (!sv)
2225 return 1;
2226
Willy Tarreau87b09662015-04-03 00:22:06 +02002227 /* kill all the stream that are on this server */
Willy Tarreau52b2d222011-09-07 23:48:48 +02002228 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
2229 if (sess->srv_conn == sv)
Willy Tarreaue7dff022015-04-03 01:14:29 +02002230 stream_shutdown(sess, SF_ERR_KILLED);
Willy Tarreau52b2d222011-09-07 23:48:48 +02002231
2232 return 1;
2233 }
2234 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002235 appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n";
2236 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau52b2d222011-09-07 23:48:48 +02002237 return 1;
2238 }
2239 }
Willy Tarreau532a4502011-09-07 22:37:44 +02002240 else { /* unknown "disable" parameter */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002241 appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n";
2242 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02002243 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01002244 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002245 }
2246 else if (strcmp(args[0], "del") == 0) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002247 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
2248 if (args[1][0] == 'm')
2249 appctx->ctx.map.display_flags = PAT_REF_MAP;
2250 else
2251 appctx->ctx.map.display_flags = PAT_REF_ACL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002252
2253 /* Expect two parameters: map name and key. */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002254 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
2255 if (!*args[2] || !*args[3]) {
2256 appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n";
2257 appctx->st0 = STAT_CLI_PRINT;
2258 return 1;
2259 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002260 }
2261
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002262 else {
2263 if (!*args[2] || !*args[3]) {
2264 appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n";
2265 appctx->st0 = STAT_CLI_PRINT;
2266 return 1;
2267 }
2268 }
2269
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002270 /* Lookup the reference in the maps. */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01002271 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002272 if (!appctx->ctx.map.ref ||
2273 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002274 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002275 appctx->st0 = STAT_CLI_PRINT;
2276 return 1;
2277 }
2278
Thierry FOURNIER9356c682014-01-28 15:55:37 +01002279 /* If the entry identifier start with a '#', it is considered as
2280 * pointer id
2281 */
2282 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
2283 struct pat_ref_elt *ref;
2284 long long int conv;
2285 char *error;
2286
2287 /* Convert argument to integer value. */
2288 conv = strtoll(&args[3][1], &error, 16);
2289 if (*error != '\0') {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002290 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01002291 appctx->st0 = STAT_CLI_PRINT;
2292 return 1;
2293 }
2294
2295 /* Convert and check integer to pointer. */
2296 ref = (struct pat_ref_elt *)(long)conv;
2297 if ((long long int)(long)ref != conv) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002298 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01002299 appctx->st0 = STAT_CLI_PRINT;
2300 return 1;
2301 }
2302
2303 /* Try to delete the entry. */
2304 if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) {
2305 /* The entry is not found, send message. */
2306 appctx->ctx.cli.msg = "Key not found.\n";
2307 appctx->st0 = STAT_CLI_PRINT;
2308 return 1;
2309 }
2310 }
2311 else {
2312 /* Else, use the entry identifier as pattern
2313 * string and try to delete the entry.
2314 */
2315 if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) {
2316 /* The entry is not found, send message. */
2317 appctx->ctx.cli.msg = "Key not found.\n";
2318 appctx->st0 = STAT_CLI_PRINT;
2319 return 1;
2320 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002321 }
2322
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002323 /* The deletion is done, send message. */
Thierry FOURNIER07e78c52014-12-18 15:28:01 +01002324 appctx->st0 = STAT_CLI_PROMPT;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002325 return 1;
2326 }
2327 else { /* unknown "del" parameter */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002328 appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002329 appctx->st0 = STAT_CLI_PRINT;
2330 return 1;
2331 }
2332 }
2333 else if (strcmp(args[0], "add") == 0) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002334 if (strcmp(args[1], "map") == 0 ||
2335 strcmp(args[1], "acl") == 0) {
2336 int ret;
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002337 char *err;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002338
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002339 /* Set flags. */
2340 if (args[1][0] == 'm')
2341 appctx->ctx.map.display_flags = PAT_REF_MAP;
2342 else
2343 appctx->ctx.map.display_flags = PAT_REF_ACL;
2344
2345 /* If the keywork is "map", we expect three parameters, if it
2346 * is "acl", we expect only two parameters
2347 */
2348 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
2349 if (!*args[2] || !*args[3] || !*args[4]) {
2350 appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n";
2351 appctx->st0 = STAT_CLI_PRINT;
2352 return 1;
2353 }
2354 }
2355 else {
2356 if (!*args[2] || !*args[3]) {
2357 appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n";
2358 appctx->st0 = STAT_CLI_PRINT;
2359 return 1;
2360 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002361 }
2362
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002363 /* Lookup for the reference. */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01002364 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002365 if (!appctx->ctx.map.ref) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002366 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002367 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002368 else
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002369 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002370 appctx->st0 = STAT_CLI_PRINT;
2371 return 1;
2372 }
2373
Thierry FOURNIER64c585f2014-01-29 20:02:36 +01002374 /* The command "add acl" is prohibited if the reference
2375 * use samples.
2376 */
2377 if ((appctx->ctx.map.display_flags & PAT_REF_ACL) &&
2378 (appctx->ctx.map.ref->flags & PAT_REF_SMP)) {
2379 appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. "
2380 "You must use the command 'add map' to add values.\n";
2381 appctx->st0 = STAT_CLI_PRINT;
2382 return 1;
2383 }
2384
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002385 /* Add value. */
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002386 err = NULL;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002387 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIERe47e4e22014-04-28 11:18:57 +02002388 ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], &err);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002389 else
Thierry FOURNIERe47e4e22014-04-28 11:18:57 +02002390 ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002391 if (!ret) {
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002392 if (err)
2393 memprintf(&err, "%s.\n", err);
2394 appctx->ctx.cli.err = err;
2395 appctx->st0 = STAT_CLI_PRINT_FREE;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002396 return 1;
2397 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002398
2399 /* The add is done, send message. */
Thierry FOURNIER07e78c52014-12-18 15:28:01 +01002400 appctx->st0 = STAT_CLI_PROMPT;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002401 return 1;
2402 }
2403 else { /* unknown "del" parameter */
2404 appctx->ctx.cli.msg = "'add' only supports 'map'.\n";
2405 appctx->st0 = STAT_CLI_PRINT;
2406 return 1;
2407 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002408 }
2409 else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002410 return 0;
2411 }
2412 return 1;
2413}
2414
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002415/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002416 * used to processes I/O from/to the stats unix socket. The system relies on a
2417 * state machine handling requests and various responses. We read a request,
2418 * then we process it and send the response, and we possibly display a prompt.
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002419 * Then we can read again. The state is stored in appctx->st0 and is one of the
2420 * STAT_CLI_* constants. appctx->st1 is used to indicate whether prompt is enabled
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002421 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002422 */
Willy Tarreau00a37f02015-04-13 12:05:19 +02002423static void cli_io_handler(struct appctx *appctx)
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002424{
Willy Tarreau00a37f02015-04-13 12:05:19 +02002425 struct stream_interface *si = appctx->owner;
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002426 struct channel *req = si_oc(si);
2427 struct channel *res = si_ic(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002428 int reql;
2429 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002430
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002431 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2432 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002433
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002434 while (1) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002435 if (appctx->st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002436 /* Stats output not initialized yet */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002437 memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats));
2438 appctx->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002439 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002440 else if (appctx->st0 == STAT_CLI_END) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002441 /* Let's close for real now. We just close the request
2442 * side, the conditions below will complete if needed.
2443 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02002444 si_shutw(si);
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002445 break;
2446 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002447 else if (appctx->st0 == STAT_CLI_GETREQ) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02002448 /* ensure we have some output room left in the event we
2449 * would want to return some info right after parsing.
2450 */
Willy Tarreau4e4292b2014-11-28 12:18:45 +01002451 if (buffer_almost_full(si_ib(si))) {
Willy Tarreaufe127932015-04-21 19:23:39 +02002452 si_applet_cant_put(si);
Willy Tarreau4e33d862009-10-11 23:35:10 +02002453 break;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01002454 }
Willy Tarreau4e33d862009-10-11 23:35:10 +02002455
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002456 reql = bo_getline(si_oc(si), trash.str, trash.size);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002457 if (reql <= 0) { /* closed or EOL not found */
2458 if (reql == 0)
2459 break;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002460 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002461 continue;
2462 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002463
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002464 /* seek for a possible semi-colon. If we find one, we
2465 * replace it with an LF and skip only this part.
2466 */
2467 for (len = 0; len < reql; len++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002468 if (trash.str[len] == ';') {
2469 trash.str[len] = '\n';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002470 reql = len + 1;
2471 break;
2472 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002473
Willy Tarreau816fc222009-10-04 07:36:58 +02002474 /* now it is time to check that we have a full line,
2475 * remove the trailing \n and possibly \r, then cut the
2476 * line.
2477 */
2478 len = reql - 1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002479 if (trash.str[len] != '\n') {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002480 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002481 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002482 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002483
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002484 if (len && trash.str[len-1] == '\r')
Willy Tarreau816fc222009-10-04 07:36:58 +02002485 len--;
2486
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002487 trash.str[len] = '\0';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002488
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002489 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002490 if (len) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002491 if (strcmp(trash.str, "quit") == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002492 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002493 continue;
2494 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002495 else if (strcmp(trash.str, "prompt") == 0)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002496 appctx->st1 = !appctx->st1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002497 else if (strcmp(trash.str, "help") == 0 ||
2498 !stats_sock_parse_request(si, trash.str)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002499 appctx->ctx.cli.msg = stats_sock_usage_msg;
2500 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02002501 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002502 /* NB: stats_sock_parse_request() may have put
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002503 * another STAT_CLI_O_* into appctx->st0.
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002504 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002505 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002506 else if (!appctx->st1) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002507 /* if prompt is disabled, print help on empty lines,
2508 * so that the user at least knows how to enable
2509 * prompt and find help.
2510 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002511 appctx->ctx.cli.msg = stats_sock_usage_msg;
2512 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002513 }
2514
2515 /* re-adjust req buffer */
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002516 bo_skip(si_oc(si), reql);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002517 req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002518 }
Willy Tarreau68c00c72015-09-25 19:21:19 +02002519 else { /* output functions */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002520 switch (appctx->st0) {
Andrew Hayworthe32d1862015-10-02 15:08:10 +00002521 case STAT_CLI_PROMPT:
2522 break;
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02002523 case STAT_CLI_PRINT:
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002524 if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002525 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreaubc18da12015-03-13 14:00:47 +01002526 else
Willy Tarreaufe127932015-04-21 19:23:39 +02002527 si_applet_cant_put(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002528 break;
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002529 case STAT_CLI_PRINT_FREE:
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002530 if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) {
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002531 free(appctx->ctx.cli.err);
2532 appctx->st0 = STAT_CLI_PROMPT;
2533 }
Willy Tarreaubc18da12015-03-13 14:00:47 +01002534 else
Willy Tarreaufe127932015-04-21 19:23:39 +02002535 si_applet_cant_put(si);
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002536 break;
Baptiste Assmann9b6857e2015-09-18 14:49:12 +02002537 case STAT_CLI_O_BACKEND:
2538 if (stats_dump_backend_to_buffer(si))
2539 appctx->st0 = STAT_CLI_PROMPT;
2540 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002541 case STAT_CLI_O_INFO:
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002542 if (stats_dump_info_to_buffer(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002543 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002544 break;
Baptiste Assmann28289462015-07-03 08:01:20 +02002545 case STAT_CLI_O_SERVERS_STATE:
2546 if (stats_dump_servers_state_to_buffer(si))
2547 appctx->st0 = STAT_CLI_PROMPT;
2548 break;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002549 case STAT_CLI_O_STAT:
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002550 if (stats_dump_stat_to_buffer(si, NULL))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002551 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002552 break;
Baptiste Assmann3863f972015-05-17 00:33:24 +02002553 case STAT_CLI_O_RESOLVERS:
2554 if (stats_dump_resolvers_to_buffer(si))
2555 appctx->st0 = STAT_CLI_PROMPT;
2556 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002557 case STAT_CLI_O_SESS:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002558 if (stats_dump_sess_to_buffer(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002559 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002560 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002561 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002562 if (stats_dump_errors_to_buffer(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002563 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002564 break;
Willy Tarreau69f58c82010-07-12 17:55:33 +02002565 case STAT_CLI_O_TAB:
Simon Hormanc88b8872011-06-15 15:18:49 +09002566 case STAT_CLI_O_CLR:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002567 if (stats_table_request(si, appctx->st0))
2568 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau69f58c82010-07-12 17:55:33 +02002569 break;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002570 case STAT_CLI_O_PATS:
2571 if (stats_pats_list(si))
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002572 appctx->st0 = STAT_CLI_PROMPT;
2573 break;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002574 case STAT_CLI_O_PAT:
2575 if (stats_pat_list(si))
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002576 appctx->st0 = STAT_CLI_PROMPT;
2577 break;
2578 case STAT_CLI_O_MLOOK:
2579 if (stats_map_lookup(si))
2580 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau4efb3532014-01-29 12:13:39 +01002581 break;
Willy Tarreau12833bb2014-01-28 16:49:56 +01002582 case STAT_CLI_O_POOLS:
2583 if (stats_dump_pools_to_buffer(si))
2584 appctx->st0 = STAT_CLI_PROMPT;
2585 break;
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +02002586#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
2587 case STAT_CLI_O_TLSK:
2588 if (stats_tlskeys_list(si))
2589 appctx->st0 = STAT_CLI_PROMPT;
2590 break;
2591#endif
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002592 default: /* abnormal state */
Willy Tarreau5cfa3bc2015-09-25 20:08:51 +02002593 si->flags |= SI_FL_ERR;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002594 break;
2595 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002596
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002597 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002598 if (appctx->st0 == STAT_CLI_PROMPT) {
Willy Tarreau2bb4a962014-11-28 11:11:05 +01002599 if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002600 appctx->st0 = STAT_CLI_GETREQ;
Willy Tarreaubc18da12015-03-13 14:00:47 +01002601 else
Willy Tarreaufe127932015-04-21 19:23:39 +02002602 si_applet_cant_put(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002603 }
2604
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002605 /* If the output functions are still there, it means they require more room. */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002606 if (appctx->st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002607 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002608
2609 /* Now we close the output if one of the writers did so,
2610 * or if we're not in interactive mode and the request
2611 * buffer is empty. This still allows pipelined requests
2612 * to be sent in non-interactive mode.
2613 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002614 if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) {
2615 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002616 continue;
2617 }
2618
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002619 /* switch state back to GETREQ to read next requests */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002620 appctx->st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002621 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002622 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002623
Willy Tarreauc9e930a2015-09-25 20:06:08 +02002624 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002625 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
2626 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
Aman Guptaceafb4a2012-04-02 18:57:54 -07002627 /* Other side has closed, let's abort if we have no more processing to do
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002628 * and nothing more to consume. This is comparable to a broken pipe, so
2629 * we forward the close to the request side so that it flows upstream to
2630 * the client.
2631 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02002632 si_shutw(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002633 }
2634
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002635 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (appctx->st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002636 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
2637 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
2638 /* We have no more processing to do, and nothing more to send, and
2639 * the client side has closed. So we'll forward this state downstream
2640 * on the response buffer.
2641 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02002642 si_shutr(si);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002643 res->flags |= CF_READ_NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002644 }
2645
Willy Tarreau828824a2015-04-19 17:20:03 +02002646 out:
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01002647 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 +02002648 __FUNCTION__, __LINE__,
Willy Tarreau9b28e032012-10-12 23:49:43 +02002649 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 +02002650}
2651
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002652/* This function dumps information onto the stream interface's read buffer.
2653 * It returns 0 as long as it does not complete, non-zero upon completion.
2654 * No state is used.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002655 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002656static int stats_dump_info_to_buffer(struct stream_interface *si)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002657{
2658 unsigned int up = (now.tv_sec - start_date.tv_sec);
2659
Willy Tarreau0c9c2722014-05-28 12:28:58 +02002660#ifdef USE_OPENSSL
2661 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
2662 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
2663 int ssl_reuse = 0;
2664
2665 if (ssl_key_rate < ssl_sess_rate) {
2666 /* count the ssl reuse ratio and avoid overflows in both directions */
2667 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
2668 }
2669#endif
2670
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002671 chunk_printf(&trash,
2672 "Name: " PRODUCT_NAME "\n"
2673 "Version: " HAPROXY_VERSION "\n"
2674 "Release_date: " HAPROXY_DATE "\n"
2675 "Nbproc: %d\n"
2676 "Process_num: %d\n"
2677 "Pid: %d\n"
2678 "Uptime: %dd %dh%02dm%02ds\n"
2679 "Uptime_sec: %d\n"
2680 "Memmax_MB: %d\n"
Willy Tarreau58102cf2015-10-28 16:24:21 +01002681 "PoolAlloc_MB: %d\n"
2682 "PoolUsed_MB: %d\n"
2683 "PoolFailed: %d\n"
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002684 "Ulimit-n: %d\n"
2685 "Maxsock: %d\n"
2686 "Maxconn: %d\n"
2687 "Hard_maxconn: %d\n"
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002688 "CurrConns: %d\n"
Willy Tarreau71b734c2014-01-28 15:19:44 +01002689 "CumConns: %d\n"
Warren Turkalb197d7f2015-01-27 15:04:16 -08002690 "CumReq: %u\n"
Willy Tarreau71b734c2014-01-28 15:19:44 +01002691#ifdef USE_OPENSSL
2692 "MaxSslConns: %d\n"
2693 "CurrSslConns: %d\n"
2694 "CumSslConns: %d\n"
2695#endif
2696 "Maxpipes: %d\n"
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002697 "PipesUsed: %d\n"
2698 "PipesFree: %d\n"
2699 "ConnRate: %d\n"
2700 "ConnRateLimit: %d\n"
2701 "MaxConnRate: %d\n"
Willy Tarreau93e7c002013-10-07 18:51:07 +02002702 "SessRate: %d\n"
2703 "SessRateLimit: %d\n"
2704 "MaxSessRate: %d\n"
Willy Tarreaue43d5322013-10-07 20:01:52 +02002705#ifdef USE_OPENSSL
2706 "SslRate: %d\n"
2707 "SslRateLimit: %d\n"
2708 "MaxSslRate: %d\n"
Willy Tarreau0c9c2722014-05-28 12:28:58 +02002709 "SslFrontendKeyRate: %d\n"
2710 "SslFrontendMaxKeyRate: %d\n"
2711 "SslFrontendSessionReuse_pct: %d\n"
2712 "SslBackendKeyRate: %d\n"
2713 "SslBackendMaxKeyRate: %d\n"
Willy Tarreauce3f9132014-05-28 16:47:01 +02002714 "SslCacheLookups: %u\n"
2715 "SslCacheMisses: %u\n"
Willy Tarreaue43d5322013-10-07 20:01:52 +02002716#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002717 "CompressBpsIn: %u\n"
2718 "CompressBpsOut: %u\n"
2719 "CompressBpsRateLim: %u\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002720#ifdef USE_ZLIB
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002721 "ZlibMemUsage: %ld\n"
2722 "MaxZlibMemUsage: %ld\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002723#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002724 "Tasks: %d\n"
2725 "Run_queue: %d\n"
2726 "Idle_pct: %d\n"
2727 "node: %s\n"
2728 "description: %s\n"
2729 "",
2730 global.nbproc,
2731 relative_pid,
2732 pid,
2733 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
2734 up,
2735 global.rlimit_memmax,
Willy Tarreau58102cf2015-10-28 16:24:21 +01002736 (int)(pool_total_allocated() / 1048576L),
2737 (int)(pool_total_used() / 1048576L),
2738 pool_total_failures(),
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002739 global.rlimit_nofile,
Willy Tarreau71b734c2014-01-28 15:19:44 +01002740 global.maxsock, global.maxconn, global.hardmaxconn,
2741 actconn, totalconn, global.req_count,
2742#ifdef USE_OPENSSL
2743 global.maxsslconn, sslconns, totalsslconns,
2744#endif
2745 global.maxpipes, pipes_used, pipes_free,
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002746 read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max,
Willy Tarreau93e7c002013-10-07 18:51:07 +02002747 read_freq_ctr(&global.sess_per_sec), global.sps_lim, global.sps_max,
Willy Tarreaue43d5322013-10-07 20:01:52 +02002748#ifdef USE_OPENSSL
Willy Tarreau0c9c2722014-05-28 12:28:58 +02002749 ssl_sess_rate, global.ssl_lim, global.ssl_max,
2750 ssl_key_rate, global.ssl_fe_keys_max,
2751 ssl_reuse,
2752 read_freq_ctr(&global.ssl_be_keys_per_sec), global.ssl_be_keys_max,
Willy Tarreauce3f9132014-05-28 16:47:01 +02002753 global.shctx_lookups, global.shctx_misses,
Willy Tarreaue43d5322013-10-07 20:01:52 +02002754#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002755 read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out),
2756 global.comp_rate_lim,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002757#ifdef USE_ZLIB
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002758 zlib_used_memory, global.maxzlibmem,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002759#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002760 nb_tasks_cur, run_queue_cur, idle_pct,
2761 global.node, global.desc ? global.desc : ""
2762 );
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002763
Willy Tarreaubc18da12015-03-13 14:00:47 +01002764 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02002765 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002766 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01002767 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002768
2769 return 1;
2770}
2771
Baptiste Assmann28289462015-07-03 08:01:20 +02002772/* dumps server state information into <buf> for all the servers found in <backend>
2773 * These information are all the parameters which may change during HAProxy runtime.
2774 * By default, we only export to the last known server state file format.
2775 * These information can be used at next startup to recover same level of server state.
2776 */
2777static void dump_servers_state(struct proxy *backend, struct chunk *buf)
2778{
2779 struct server *srv;
2780 char srv_addr[INET6_ADDRSTRLEN + 1];
2781 time_t srv_time_since_last_change;
2782 int bk_f_forced_id, srv_f_forced_id;
2783
2784 /* we don't want to report any state if the backend is not enabled on this process */
2785 if (backend->bind_proc && !(backend->bind_proc & (1UL << (relative_pid - 1))))
2786 return;
2787
2788 srv = backend->srv;
2789
2790 while (srv) {
2791 srv_addr[0] = '\0';
2792 srv_time_since_last_change = 0;
2793 bk_f_forced_id = 0;
2794 srv_f_forced_id = 0;
2795
2796 switch (srv->addr.ss_family) {
2797 case AF_INET:
2798 inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr,
2799 srv_addr, INET_ADDRSTRLEN + 1);
2800 break;
2801 case AF_INET6:
2802 inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr,
2803 srv_addr, INET6_ADDRSTRLEN + 1);
2804 break;
2805 }
2806 srv_time_since_last_change = now.tv_sec - srv->last_change;
2807 bk_f_forced_id = backend->options & PR_O_FORCED_ID ? 1 : 0;
2808 srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0;
2809
2810 chunk_appendf(buf,
2811 "%d %s "
2812 "%d %s %s "
2813 "%d %d %d %d %ld "
2814 "%d %d %d %d %d "
2815 "%d %d"
2816 "\n",
2817 backend->uuid, backend->id,
2818 srv->puid, srv->id, srv_addr,
David Carlier081b3362015-11-18 06:10:22 +00002819 srv->state, srv->admin, srv->uweight, srv->iweight, (long int)srv_time_since_last_change,
Baptiste Assmann28289462015-07-03 08:01:20 +02002820 srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state,
2821 bk_f_forced_id, srv_f_forced_id);
2822
2823 srv = srv->next;
2824 }
2825}
2826
Baptiste Assmann9b6857e2015-09-18 14:49:12 +02002827/* Parses backend list and simply report backend names */
2828static int stats_dump_backend_to_buffer(struct stream_interface *si)
2829{
2830 extern struct proxy *proxy;
2831 struct proxy *curproxy;
2832
2833 chunk_reset(&trash);
2834 chunk_printf(&trash, "# name\n");
2835
2836 for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) {
2837 /* looking for backends only */
2838 if (!(curproxy->cap & PR_CAP_BE))
2839 continue;
2840
2841 /* we don't want to list a backend which is bound to this process */
2842 if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1))))
2843 continue;
2844
2845 chunk_appendf(&trash, "%s\n", curproxy->id);
2846 }
2847
2848 if (bi_putchk(si_ic(si), &trash) == -1) {
2849 si_applet_cant_put(si);
2850 return 0;
2851 }
2852
2853 return 1;
2854}
2855
Baptiste Assmann28289462015-07-03 08:01:20 +02002856/* Parses backend list or simply use backend name provided by the user to return
2857 * states of servers to stdout.
2858 */
2859static int stats_dump_servers_state_to_buffer(struct stream_interface *si)
2860{
2861 struct appctx *appctx = __objt_appctx(si->end);
2862 extern struct proxy *proxy;
2863 struct proxy *curproxy;
2864
2865 chunk_reset(&trash);
2866
2867 chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES);
2868
2869 if (appctx->ctx.server_state.backend) {
2870 dump_servers_state(appctx->ctx.server_state.backend, &trash);
2871 }
2872 else {
2873 for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) {
2874 /* servers are only in backends */
2875 if (!(curproxy->cap & PR_CAP_BE))
2876 continue;
2877
2878 dump_servers_state(curproxy, &trash);
2879 }
2880 }
2881
2882 if (bi_putchk(si_ic(si), &trash) == -1) {
2883 si_applet_cant_put(si);
2884 return 0;
2885 }
2886
2887 return 1;
2888}
2889
Willy Tarreau12833bb2014-01-28 16:49:56 +01002890/* This function dumps memory usage information onto the stream interface's
2891 * read buffer. It returns 0 as long as it does not complete, non-zero upon
2892 * completion. No state is used.
2893 */
2894static int stats_dump_pools_to_buffer(struct stream_interface *si)
2895{
2896 dump_pools_to_trash();
Willy Tarreaubc18da12015-03-13 14:00:47 +01002897 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02002898 si_applet_cant_put(si);
Willy Tarreau12833bb2014-01-28 16:49:56 +01002899 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01002900 }
Willy Tarreau12833bb2014-01-28 16:49:56 +01002901 return 1;
2902}
2903
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002904/* Dumps a frontend's line to the trash for the current proxy <px> and uses
2905 * the state from stream interface <si>. The caller is responsible for clearing
2906 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
Cyril Bonté70be45d2010-10-12 00:14:35 +02002907 */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002908static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
Cyril Bonté70be45d2010-10-12 00:14:35 +02002909{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002910 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002911 int i;
Cyril Bonté70be45d2010-10-12 00:14:35 +02002912
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002913 if (!(px->cap & PR_CAP_FE))
2914 return 0;
Cyril Bonté70be45d2010-10-12 00:14:35 +02002915
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002916 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE)))
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002917 return 0;
2918
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002919 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002920 chunk_appendf(&trash,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002921 /* name, queue */
2922 "<tr class=\"frontend\">");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002923
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002924 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002925 /* Column sub-heading for Enable or Disable server */
2926 chunk_appendf(&trash, "<td></td>");
2927 }
Cyril Bonté70be45d2010-10-12 00:14:35 +02002928
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002929 chunk_appendf(&trash,
2930 "<td class=ac>"
2931 "<a name=\"%s/Frontend\"></a>"
2932 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
2933 "<td colspan=3></td>"
2934 "",
2935 px->id, px->id);
Cyril Bonté70be45d2010-10-12 00:14:35 +02002936
Willy Tarreau466c9b52012-12-23 02:25:03 +01002937 chunk_appendf(&trash,
2938 /* sessions rate : current */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002939 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01002940 "<tr><th>Current connection rate:</th><td>%s/s</td></tr>"
2941 "<tr><th>Current session rate:</th><td>%s/s</td></tr>"
2942 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002943 U2H(read_freq_ctr(&px->fe_sess_per_sec)),
2944 U2H(read_freq_ctr(&px->fe_conn_per_sec)),
2945 U2H(read_freq_ctr(&px->fe_sess_per_sec)));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002946
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002947 if (px->mode == PR_MODE_HTTP)
2948 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01002949 "<tr><th>Current request rate:</th><td>%s/s</td></tr>",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002950 U2H(read_freq_ctr(&px->fe_req_per_sec)));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002951
2952 chunk_appendf(&trash,
2953 "</table></div></u></td>"
2954 /* sessions rate : max */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002955 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01002956 "<tr><th>Max connection rate:</th><td>%s/s</td></tr>"
2957 "<tr><th>Max session rate:</th><td>%s/s</td></tr>"
2958 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002959 U2H(px->fe_counters.sps_max),
2960 U2H(px->fe_counters.cps_max),
2961 U2H(px->fe_counters.sps_max));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002962
2963 if (px->mode == PR_MODE_HTTP)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002964 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01002965 "<tr><th>Max request rate:</th><td>%s/s</td></tr>",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002966 U2H(px->fe_counters.p.http.rps_max));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002967
2968 chunk_appendf(&trash,
2969 "</table></div></u></td>"
2970 /* sessions rate : limit */
2971 "<td>%s</td>",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002972 LIM2A(px->fe_sps_lim, "-"));
Cyril Bonté70be45d2010-10-12 00:14:35 +02002973
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002974 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002975 /* sessions: current, max, limit, total */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002976 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002977 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01002978 "<tr><th>Cum. connections:</th><td>%s</td></tr>"
2979 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002980 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002981 U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn),
2982 U2H(px->fe_counters.cum_sess),
2983 U2H(px->fe_counters.cum_conn),
2984 U2H(px->fe_counters.cum_sess));
Cyril Bonté70be45d2010-10-12 00:14:35 +02002985
Willy Tarreau466c9b52012-12-23 02:25:03 +01002986 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002987 if (px->mode == PR_MODE_HTTP) {
Willy Tarreau466c9b52012-12-23 02:25:03 +01002988 chunk_appendf(&trash,
2989 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
2990 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
2991 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
2992 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
2993 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
2994 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
2995 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
2996 "<tr><th>- other responses:</th><td>%s</td></tr>"
2997 "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
2998 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002999 U2H(px->fe_counters.p.http.cum_req),
3000 U2H(px->fe_counters.p.http.rsp[1]),
3001 U2H(px->fe_counters.p.http.rsp[2]),
3002 U2H(px->fe_counters.p.http.comp_rsp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003003 px->fe_counters.p.http.rsp[2] ?
Willy Tarreau466c9b52012-12-23 02:25:03 +01003004 (int)(100*px->fe_counters.p.http.comp_rsp/px->fe_counters.p.http.rsp[2]) : 0,
Willy Tarreau56adcf22012-12-23 18:00:29 +01003005 U2H(px->fe_counters.p.http.rsp[3]),
3006 U2H(px->fe_counters.p.http.rsp[4]),
3007 U2H(px->fe_counters.p.http.rsp[5]),
3008 U2H(px->fe_counters.p.http.rsp[0]),
3009 U2H(px->fe_counters.intercepted_req));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003010 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003011
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003012 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01003013 "</table></div></u></td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003014 /* sessions: lbtot, lastsess */
3015 "<td></td><td></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003016 /* bytes : in */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003017 "<td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003018 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003019 U2H(px->fe_counters.bytes_in));
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003020
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003021 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003022 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
Willy Tarreau4e5d58e2015-07-04 14:35:15 +02003023 "<td>%s%s<div class=tips><table class=det>"
3024 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
3025 "<tr><th>Compression in:</th><td>%s</td></tr>"
3026 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
3027 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
3028 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
3029 "</table></div>%s</td>",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003030 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003031 U2H(px->fe_counters.bytes_out),
Willy Tarreau4e5d58e2015-07-04 14:35:15 +02003032 U2H(px->fe_counters.bytes_out),
3033 U2H(px->fe_counters.comp_in),
3034 U2H(px->fe_counters.comp_out),
3035 px->fe_counters.comp_in ? (int)(px->fe_counters.comp_out * 100 / px->fe_counters.comp_in) : 0,
3036 U2H(px->fe_counters.comp_byp),
3037 U2H(px->fe_counters.comp_in - px->fe_counters.comp_out),
3038 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 +01003039 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":"");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003040
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003041 chunk_appendf(&trash,
3042 /* denied: req, resp */
3043 "<td>%s</td><td>%s</td>"
3044 /* errors : request, connect, response */
3045 "<td>%s</td><td></td><td></td>"
3046 /* warnings: retries, redispatches */
3047 "<td></td><td></td>"
3048 /* server status : reflect frontend status */
3049 "<td class=ac>%s</td>"
3050 /* rest of server: nothing */
3051 "<td class=ac colspan=8></td></tr>"
3052 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003053 U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp),
3054 U2H(px->fe_counters.failed_req),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003055 px->state == PR_STREADY ? "OPEN" :
3056 px->state == PR_STFULL ? "FULL" : "STOP");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003057 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003058 else { /* CSV mode */
3059 chunk_appendf(&trash,
3060 /* pxid, name, queue cur, queue max, */
3061 "%s,FRONTEND,,,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003062 /* sessions : current, max, limit, total */
3063 "%d,%d,%d,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003064 /* bytes : in, out */
3065 "%lld,%lld,"
3066 /* denied: req, resp */
3067 "%lld,%lld,"
3068 /* errors : request, connect, response */
3069 "%lld,,,"
3070 /* warnings: retries, redispatches */
3071 ",,"
3072 /* server status : reflect frontend status */
3073 "%s,"
3074 /* rest of server: nothing */
3075 ",,,,,,,,"
3076 /* pid, iid, sid, throttle, lbtot, tracked, type */
3077 "%d,%d,0,,,,%d,"
3078 /* rate, rate_lim, rate_max */
3079 "%u,%u,%u,"
3080 /* check_status, check_code, check_duration */
3081 ",,,",
3082 px->id,
3083 px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess,
3084 px->fe_counters.bytes_in, px->fe_counters.bytes_out,
3085 px->fe_counters.denied_req, px->fe_counters.denied_resp,
3086 px->fe_counters.failed_req,
3087 px->state == PR_STREADY ? "OPEN" :
3088 px->state == PR_STFULL ? "FULL" : "STOP",
3089 relative_pid, px->uuid, STATS_TYPE_FE,
3090 read_freq_ctr(&px->fe_sess_per_sec),
3091 px->fe_sps_lim, px->fe_counters.sps_max);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003092
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003093 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3094 if (px->mode == PR_MODE_HTTP) {
3095 for (i=1; i<6; i++)
3096 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]);
3097 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]);
3098 }
3099 else
3100 chunk_appendf(&trash, ",,,,,,");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003101
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003102 /* failed health analyses */
3103 chunk_appendf(&trash, ",");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003104
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003105 /* requests : req_rate, req_rate_max, req_tot, */
3106 chunk_appendf(&trash, "%u,%u,%lld,",
3107 read_freq_ctr(&px->fe_req_per_sec),
3108 px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req);
3109
3110 /* errors: cli_aborts, srv_aborts */
3111 chunk_appendf(&trash, ",,");
3112
3113 /* compression: in, out, bypassed */
3114 chunk_appendf(&trash, "%lld,%lld,%lld,",
3115 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
3116
3117 /* compression: comp_rsp */
3118 chunk_appendf(&trash, "%lld,",
3119 px->fe_counters.p.http.comp_rsp);
3120
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003121 /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */
3122 chunk_appendf(&trash, ",,,,,,,");
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003123
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003124 /* finish with EOL */
3125 chunk_appendf(&trash, "\n");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003126 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003127 return 1;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003128}
3129
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003130/* Dumps a line for listener <l> and proxy <px> to the trash and uses the state
3131 * from stream interface <si>, and stats flags <flags>. The caller is responsible
3132 * for clearing the trash if needed. Returns non-zero if it emits anything, zero
3133 * otherwise.
Willy Tarreau91861262007-10-17 17:06:05 +02003134 */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003135static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags)
Willy Tarreau91861262007-10-17 17:06:05 +02003136{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003137 struct appctx *appctx = __objt_appctx(si->end);
3138
3139 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003140 chunk_appendf(&trash, "<tr class=socket>");
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003141 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003142 /* Column sub-heading for Enable or Disable server */
3143 chunk_appendf(&trash, "<td></td>");
3144 }
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003145 chunk_appendf(&trash,
3146 /* frontend name, listener name */
3147 "<td class=ac><a name=\"%s/+%s\"></a>%s"
3148 "<a class=lfsb href=\"#%s/+%s\">%s</a>"
3149 "",
3150 px->id, l->name,
3151 (flags & ST_SHLGNDS)?"<u>":"",
3152 px->id, l->name, l->name);
Willy Tarreau91861262007-10-17 17:06:05 +02003153
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003154 if (flags & ST_SHLGNDS) {
3155 char str[INET6_ADDRSTRLEN];
3156 int port;
Willy Tarreau91861262007-10-17 17:06:05 +02003157
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003158 chunk_appendf(&trash, "<div class=tips>");
Willy Tarreau91861262007-10-17 17:06:05 +02003159
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003160 port = get_host_port(&l->addr);
3161 switch (addr_to_str(&l->addr, str, sizeof(str))) {
3162 case AF_INET:
3163 chunk_appendf(&trash, "IPv4: %s:%d, ", str, port);
3164 break;
3165 case AF_INET6:
3166 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port);
3167 break;
3168 case AF_UNIX:
3169 chunk_appendf(&trash, "unix, ");
3170 break;
3171 case -1:
3172 chunk_appendf(&trash, "(%s), ", strerror(errno));
3173 break;
3174 }
Willy Tarreau91861262007-10-17 17:06:05 +02003175
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003176 /* id */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003177 chunk_appendf(&trash, "id: %d</div>", l->luid);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003178 }
Willy Tarreau91861262007-10-17 17:06:05 +02003179
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003180 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003181 /* queue */
3182 "%s</td><td colspan=3></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003183 /* sessions rate: current, max, limit */
3184 "<td colspan=3>&nbsp;</td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003185 /* sessions: current, max, limit, total, lbtot, lastsess */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003186 "<td>%s</td><td>%s</td><td>%s</td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003187 "<td>%s</td><td>&nbsp;</td><td>&nbsp;</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003188 /* bytes: in, out */
3189 "<td>%s</td><td>%s</td>"
3190 "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003191 (flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003192 U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn),
3193 U2H(l->counters->cum_conn), U2H(l->counters->bytes_in), U2H(l->counters->bytes_out));
Willy Tarreau56a560a2009-09-22 19:27:35 +02003194
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003195 chunk_appendf(&trash,
3196 /* denied: req, resp */
3197 "<td>%s</td><td>%s</td>"
3198 /* errors: request, connect, response */
3199 "<td>%s</td><td></td><td></td>"
3200 /* warnings: retries, redispatches */
3201 "<td></td><td></td>"
3202 /* server status: reflect listener status */
3203 "<td class=ac>%s</td>"
3204 /* rest of server: nothing */
3205 "<td class=ac colspan=8></td></tr>"
3206 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003207 U2H(l->counters->denied_req), U2H(l->counters->denied_resp),
3208 U2H(l->counters->failed_req),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003209 (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
3210 }
3211 else { /* CSV mode */
3212 chunk_appendf(&trash,
3213 /* pxid, name, queue cur, queue max, */
3214 "%s,%s,,,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003215 /* sessions: current, max, limit, total */
3216 "%d,%d,%d,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003217 /* bytes: in, out */
3218 "%lld,%lld,"
3219 /* denied: req, resp */
3220 "%lld,%lld,"
3221 /* errors: request, connect, response */
3222 "%lld,,,"
3223 /* warnings: retries, redispatches */
3224 ",,"
3225 /* server status: reflect listener status */
3226 "%s,"
3227 /* rest of server: nothing */
3228 ",,,,,,,,"
3229 /* pid, iid, sid, throttle, lbtot, tracked, type */
3230 "%d,%d,%d,,,,%d,"
3231 /* rate, rate_lim, rate_max */
3232 ",,,"
3233 /* check_status, check_code, check_duration */
3234 ",,,"
3235 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3236 ",,,,,,"
3237 /* failed health analyses */
3238 ","
3239 /* requests : req_rate, req_rate_max, req_tot, */
3240 ",,,"
3241 /* errors: cli_aborts, srv_aborts */
3242 ",,"
3243 /* compression: in, out, bypassed, comp_rsp */
3244 ",,,,"
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003245 /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */
3246 ",,,,,,,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003247 "\n",
3248 px->id, l->name,
3249 l->nbconn, l->counters->conn_max,
3250 l->maxconn, l->counters->cum_conn,
3251 l->counters->bytes_in, l->counters->bytes_out,
3252 l->counters->denied_req, l->counters->denied_resp,
3253 l->counters->failed_req,
3254 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
3255 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
3256 }
3257 return 1;
3258}
Willy Tarreau91861262007-10-17 17:06:05 +02003259
Simon Horman4d2eab62015-04-23 14:51:26 +09003260enum srv_stats_state {
3261 SRV_STATS_STATE_DOWN = 0,
3262 SRV_STATS_STATE_DOWN_AGENT,
3263 SRV_STATS_STATE_GOING_UP,
3264 SRV_STATS_STATE_UP_GOING_DOWN,
3265 SRV_STATS_STATE_UP,
3266 SRV_STATS_STATE_NOLB_GOING_DOWN,
3267 SRV_STATS_STATE_NOLB,
3268 SRV_STATS_STATE_DRAIN_GOING_DOWN,
3269 SRV_STATS_STATE_DRAIN,
Simon Hormanb167b6b2015-04-23 14:51:29 +09003270 SRV_STATS_STATE_DRAIN_AGENT,
Simon Horman4d2eab62015-04-23 14:51:26 +09003271 SRV_STATS_STATE_NO_CHECK,
3272
3273 SRV_STATS_STATE_COUNT, /* Must be last */
3274};
3275
Simon Horman837bfa72015-04-23 14:51:27 +09003276enum srv_stats_colour {
3277 SRV_STATS_COLOUR_DOWN = 0,
3278 SRV_STATS_COLOUR_GOING_UP,
3279 SRV_STATS_COLOUR_GOING_DOWN,
3280 SRV_STATS_COLOUR_UP,
3281 SRV_STATS_COLOUR_NOLB,
3282 SRV_STATS_COLOUR_DRAINING,
3283 SRV_STATS_COLOUR_NO_CHECK,
3284
3285 SRV_STATS_COLOUR_COUNT, /* Must be last */
3286};
3287
3288static const char *srv_stats_colour_st[SRV_STATS_COLOUR_COUNT] = {
3289 [SRV_STATS_COLOUR_DOWN] = "down",
3290 [SRV_STATS_COLOUR_GOING_UP] = "going_up",
3291 [SRV_STATS_COLOUR_GOING_DOWN] = "going_down",
3292 [SRV_STATS_COLOUR_UP] = "up",
3293 [SRV_STATS_COLOUR_NOLB] = "nolb",
3294 [SRV_STATS_COLOUR_DRAINING] = "draining",
3295 [SRV_STATS_COLOUR_NO_CHECK] = "no_check",
3296};
3297
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003298/* Dumps a line for server <sv> and proxy <px> to the trash and uses the state
3299 * from stream interface <si>, stats flags <flags>, and server state <state>.
3300 * The caller is responsible for clearing the trash if needed. Returns non-zero
Simon Horman4d2eab62015-04-23 14:51:26 +09003301 * if it emits anything, zero otherwise.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003302 */
Simon Horman4d2eab62015-04-23 14:51:26 +09003303static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv,
Simon Horman837bfa72015-04-23 14:51:27 +09003304 enum srv_stats_state state, enum srv_stats_colour colour)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003305{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003306 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau32091232014-05-16 13:52:00 +02003307 struct server *via, *ref;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003308 char str[INET6_ADDRSTRLEN];
3309 struct chunk src;
3310 int i;
Willy Tarreau91861262007-10-17 17:06:05 +02003311
Willy Tarreau32091232014-05-16 13:52:00 +02003312 /* we have "via" which is the tracked server as described in the configuration,
3313 * and "ref" which is the checked server and the end of the chain.
3314 */
3315 via = sv->track ? sv->track : sv;
3316 ref = via;
3317 while (ref->track)
3318 ref = ref->track;
3319
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003320 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Simon Horman4d2eab62015-04-23 14:51:26 +09003321 static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = {
3322 [SRV_STATS_STATE_DOWN] = "DOWN",
3323 [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)",
3324 [SRV_STATS_STATE_GOING_UP] = "DN %d/%d &uarr;",
3325 [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d &darr;",
3326 [SRV_STATS_STATE_UP] = "UP",
3327 [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d &darr;",
3328 [SRV_STATS_STATE_NOLB] = "NOLB",
3329 [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d &darr;",
3330 [SRV_STATS_STATE_DRAIN] = "DRAIN",
Simon Hormanb167b6b2015-04-23 14:51:29 +09003331 [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)",
Simon Horman4d2eab62015-04-23 14:51:26 +09003332 [SRV_STATS_STATE_NO_CHECK] = "<i>no check</i>",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003333 };
Willy Tarreau91861262007-10-17 17:06:05 +02003334
Willy Tarreaua0066dd2014-05-16 11:25:16 +02003335 if (sv->admin & SRV_ADMF_MAINT)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003336 chunk_appendf(&trash, "<tr class=\"maintain\">");
3337 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003338 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09003339 "<tr class=\"%s_%s\">",
3340 (sv->flags & SRV_F_BACKUP) ? "backup" : "active", srv_stats_colour_st[colour]);
Willy Tarreau91861262007-10-17 17:06:05 +02003341
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003342 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003343 chunk_appendf(&trash,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003344 "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
3345 sv->id);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003346
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003347 chunk_appendf(&trash,
3348 "<td class=ac><a name=\"%s/%s\"></a>%s"
3349 "<a class=lfsb href=\"#%s/%s\">%s</a>"
3350 "",
3351 px->id, sv->id,
3352 (flags & ST_SHLGNDS) ? "<u>" : "",
3353 px->id, sv->id, sv->id);
Willy Tarreau91861262007-10-17 17:06:05 +02003354
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003355 if (flags & ST_SHLGNDS) {
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003356 chunk_appendf(&trash, "<div class=tips>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003357
3358 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
3359 case AF_INET:
3360 chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr));
3361 break;
3362 case AF_INET6:
3363 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr));
3364 break;
3365 case AF_UNIX:
3366 chunk_appendf(&trash, "unix, ");
3367 break;
3368 case -1:
3369 chunk_appendf(&trash, "(%s), ", strerror(errno));
3370 break;
3371 default: /* address family not supported */
3372 break;
Willy Tarreau55bb8452007-10-17 18:44:57 +02003373 }
Willy Tarreau91861262007-10-17 17:06:05 +02003374
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003375 /* id */
3376 chunk_appendf(&trash, "id: %d", sv->puid);
Willy Tarreau91861262007-10-17 17:06:05 +02003377
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003378 /* cookie */
3379 if (sv->cookie) {
3380 chunk_appendf(&trash, ", cookie: '");
Willy Tarreau5031e6a2007-10-18 11:05:48 +02003381
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003382 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
3383 chunk_htmlencode(&trash, &src);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003384
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003385 chunk_appendf(&trash, "'");
Cyril Bonté70be45d2010-10-12 00:14:35 +02003386 }
3387
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003388 chunk_appendf(&trash, "</div>");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003389 }
Willy Tarreau91861262007-10-17 17:06:05 +02003390
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003391 chunk_appendf(&trash,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003392 /* queue : current, max, limit */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003393 "%s</td><td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003394 /* sessions rate : current, max, limit */
3395 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003396 "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003397 (flags & ST_SHLGNDS) ? "</u>" : "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003398 U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"),
3399 U2H(read_freq_ctr(&sv->sess_per_sec)), U2H(sv->counters.sps_max));
Willy Tarreau91861262007-10-17 17:06:05 +02003400
Willy Tarreau466c9b52012-12-23 02:25:03 +01003401
3402 chunk_appendf(&trash,
3403 /* sessions: current, max, limit, total */
3404 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003405 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01003406 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
3407 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003408 U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"),
3409 U2H(sv->counters.cum_sess),
3410 U2H(sv->counters.cum_sess));
Willy Tarreau91861262007-10-17 17:06:05 +02003411
Willy Tarreau466c9b52012-12-23 02:25:03 +01003412 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
3413 if (px->mode == PR_MODE_HTTP) {
3414 unsigned long long tot;
3415 for (tot = i = 0; i < 6; i++)
3416 tot += sv->counters.p.http.rsp[i];
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003417
Willy Tarreau466c9b52012-12-23 02:25:03 +01003418 chunk_appendf(&trash,
3419 "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>"
3420 "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3421 "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3422 "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3423 "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3424 "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3425 "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>"
3426 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003427 U2H(tot),
3428 U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0,
3429 U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0,
3430 U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0,
3431 U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0,
3432 U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0,
3433 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 +02003434 }
Willy Tarreau91861262007-10-17 17:06:05 +02003435
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003436 chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>");
3437 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)));
3438 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)));
3439 if (px->mode == PR_MODE_HTTP)
3440 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)));
3441 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)));
3442
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003443 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01003444 "</table></div></u></td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003445 /* sessions: lbtot, last */
3446 "<td>%s</td><td>%s</td>",
3447 U2H(sv->counters.cum_lbconn),
3448 human_time(srv_lastsession(sv), 1));
Willy Tarreau91861262007-10-17 17:06:05 +02003449
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003450 chunk_appendf(&trash,
3451 /* bytes : in, out */
3452 "<td>%s</td><td>%s</td>"
3453 /* denied: req, resp */
3454 "<td></td><td>%s</td>"
3455 /* errors : request, connect */
3456 "<td></td><td>%s</td>"
3457 /* errors : response */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003458 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003459 /* warnings: retries, redispatches */
3460 "<td>%lld</td><td>%lld</td>"
3461 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003462 U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out),
3463 U2H(sv->counters.failed_secu),
3464 U2H(sv->counters.failed_conns),
3465 U2H(sv->counters.failed_resp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003466 sv->counters.cli_aborts,
3467 sv->counters.srv_aborts,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003468 sv->counters.retries, sv->counters.redispatches);
3469
3470 /* status, lest check */
3471 chunk_appendf(&trash, "<td class=ac>");
3472
Willy Tarreau20125212014-05-13 19:44:56 +02003473 if (sv->admin & SRV_ADMF_MAINT) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003474 chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1));
3475 chunk_appendf(&trash, "MAINT");
3476 }
Simon Horman0766e442014-11-12 15:55:54 +09003477 else if ((ref->agent.state & CHK_ST_ENABLED) && !(sv->agent.health) && (ref->state == SRV_ST_STOPPED)) {
Willy Tarreaucf2924b2014-05-23 12:15:15 +02003478 chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1));
Willy Tarreauac497072014-05-29 01:04:35 +02003479 /* DOWN (agent) */
3480 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 +02003481 }
Willy Tarreauff5ae352013-12-11 20:36:34 +01003482 else if (ref->check.state & CHK_ST_ENABLED) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003483 chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1));
3484 chunk_appendf(&trash,
3485 srv_hlt_st[state],
Willy Tarreau892337c2014-05-13 23:41:20 +02003486 (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health),
3487 (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise));
Willy Tarreau55bb8452007-10-17 18:44:57 +02003488 }
Willy Tarreau91861262007-10-17 17:06:05 +02003489
Willy Tarreaucf2924b2014-05-23 12:15:15 +02003490 if ((sv->state == SRV_ST_STOPPED) &&
3491 ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) {
3492 chunk_appendf(&trash,
3493 "</td><td class=ac><u> %s%s",
3494 (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "",
3495 get_check_status_info(sv->agent.status));
3496
3497 if (sv->agent.status >= HCHK_STATUS_L57DATA)
3498 chunk_appendf(&trash, "/%d", sv->agent.code);
3499
3500 if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0)
3501 chunk_appendf(&trash, " in %lums", sv->agent.duration);
3502
3503 chunk_appendf(&trash, "<div class=tips>%s",
3504 get_check_status_description(sv->agent.status));
3505 if (*sv->agent.desc) {
3506 chunk_appendf(&trash, ": ");
3507 chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc));
3508 chunk_htmlencode(&trash, &src);
3509 }
3510 chunk_appendf(&trash, "</div></u>");
3511 }
3512 else if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) {
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003513 chunk_appendf(&trash,
3514 "</td><td class=ac><u> %s%s",
Willy Tarreau2c115e52013-12-11 19:41:16 +01003515 (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003516 get_check_status_info(sv->check.status));
3517
3518 if (sv->check.status >= HCHK_STATUS_L57DATA)
3519 chunk_appendf(&trash, "/%d", sv->check.code);
3520
3521 if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0)
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003522 chunk_appendf(&trash, " in %lums", sv->check.duration);
3523
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003524 chunk_appendf(&trash, "<div class=tips>%s",
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003525 get_check_status_description(sv->check.status));
3526 if (*sv->check.desc) {
3527 chunk_appendf(&trash, ": ");
3528 chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc));
3529 chunk_htmlencode(&trash, &src);
3530 }
3531 chunk_appendf(&trash, "</div></u>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003532 }
3533 else
3534 chunk_appendf(&trash, "</td><td>");
3535
3536 chunk_appendf(&trash,
3537 /* weight */
3538 "</td><td class=ac>%d</td>"
3539 /* act, bck */
3540 "<td class=ac>%s</td><td class=ac>%s</td>"
3541 "",
3542 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreauc93cd162014-05-13 15:54:22 +02003543 (sv->flags & SRV_F_BACKUP) ? "-" : "Y",
3544 (sv->flags & SRV_F_BACKUP) ? "Y" : "-");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003545
3546 /* check failures: unique, fatal, down time */
Willy Tarreauff5ae352013-12-11 20:36:34 +01003547 if (sv->check.state & CHK_ST_ENABLED) {
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003548 chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003549
3550 if (ref->observe)
3551 chunk_appendf(&trash, "/%lld", ref->counters.failed_hana);
3552
3553 chunk_appendf(&trash,
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003554 "<div class=tips>Failed Health Checks%s</div></u></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003555 "<td>%lld</td><td>%s</td>"
3556 "",
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003557 ref->observe ? "/Health Analyses" : "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003558 ref->counters.down_trans, human_time(srv_downtime(sv), 1));
3559 }
Willy Tarreaua0066dd2014-05-16 11:25:16 +02003560 else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) {
3561 /* tracking a server */
3562 chunk_appendf(&trash,
3563 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s</a></td>",
Willy Tarreau32091232014-05-16 13:52:00 +02003564 via->proxy->id, via->id, via->proxy->id, via->id);
Willy Tarreauf4659942013-11-28 10:50:06 +01003565 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003566 else
3567 chunk_appendf(&trash, "<td colspan=3></td>");
3568
3569 /* throttle */
Willy Tarreau892337c2014-05-13 23:41:20 +02003570 if (sv->state == SRV_ST_STARTING && !server_is_draining(sv))
Willy Tarreaud32c3992013-11-21 15:30:45 +01003571 chunk_appendf(&trash, "<td class=ac>%d %%</td></tr>\n", server_throttle_rate(sv));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003572 else
3573 chunk_appendf(&trash, "<td class=ac>-</td></tr>\n");
3574 }
3575 else { /* CSV mode */
Thierry FOURNIERbe1ccae2015-05-28 16:02:01 +02003576 struct chunk *out = get_trash_chunk();
Simon Horman4d2eab62015-04-23 14:51:26 +09003577 static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = {
3578 [SRV_STATS_STATE_DOWN] = "DOWN,",
3579 [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent),",
3580 [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d,",
3581 [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d,",
3582 [SRV_STATS_STATE_UP] = "UP,",
3583 [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d,",
3584 [SRV_STATS_STATE_NOLB] = "NOLB,",
3585 [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d,",
3586 [SRV_STATS_STATE_DRAIN] = "DRAIN,",
Simon Hormanb167b6b2015-04-23 14:51:29 +09003587 [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)",
Simon Horman4d2eab62015-04-23 14:51:26 +09003588 [SRV_STATS_STATE_NO_CHECK] = "no check,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003589 };
3590
3591 chunk_appendf(&trash,
3592 /* pxid, name */
3593 "%s,%s,"
3594 /* queue : current, max */
3595 "%d,%d,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003596 /* sessions : current, max, limit, total */
3597 "%d,%d,%s,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003598 /* bytes : in, out */
3599 "%lld,%lld,"
3600 /* denied: req, resp */
3601 ",%lld,"
3602 /* errors : request, connect, response */
3603 ",%lld,%lld,"
3604 /* warnings: retries, redispatches */
3605 "%lld,%lld,"
3606 "",
3607 px->id, sv->id,
3608 sv->nbpend, sv->counters.nbpend_max,
Willy Tarreau56adcf22012-12-23 18:00:29 +01003609 sv->cur_sess, sv->counters.cur_sess_max, LIM2A(sv->maxconn, ""), sv->counters.cum_sess,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003610 sv->counters.bytes_in, sv->counters.bytes_out,
3611 sv->counters.failed_secu,
3612 sv->counters.failed_conns, sv->counters.failed_resp,
3613 sv->counters.retries, sv->counters.redispatches);
3614
3615 /* status */
Willy Tarreaua0066dd2014-05-16 11:25:16 +02003616 if (sv->admin & SRV_ADMF_IMAINT)
Willy Tarreau32091232014-05-16 13:52:00 +02003617 chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id);
Willy Tarreaua0066dd2014-05-16 11:25:16 +02003618 else if (sv->admin & SRV_ADMF_MAINT)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003619 chunk_appendf(&trash, "MAINT,");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003620 else
3621 chunk_appendf(&trash,
3622 srv_hlt_st[state],
Willy Tarreau892337c2014-05-13 23:41:20 +02003623 (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health),
3624 (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003625
3626 chunk_appendf(&trash,
3627 /* weight, active, backup */
3628 "%d,%d,%d,"
3629 "",
3630 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreauc93cd162014-05-13 15:54:22 +02003631 (sv->flags & SRV_F_BACKUP) ? 0 : 1,
3632 (sv->flags & SRV_F_BACKUP) ? 1 : 0);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003633
3634 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreauff5ae352013-12-11 20:36:34 +01003635 if (sv->check.state & CHK_ST_ENABLED)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003636 chunk_appendf(&trash,
3637 "%lld,%lld,%d,%d,",
3638 sv->counters.failed_checks, sv->counters.down_trans,
3639 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
3640 else
3641 chunk_appendf(&trash, ",,,,");
3642
3643 /* queue limit, pid, iid, sid, */
3644 chunk_appendf(&trash,
3645 "%s,"
3646 "%d,%d,%d,",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003647 LIM2A(sv->maxqueue, ""),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003648 relative_pid, px->uuid, sv->puid);
3649
3650 /* throttle */
Willy Tarreau892337c2014-05-13 23:41:20 +02003651 if (sv->state == SRV_ST_STARTING && !server_is_draining(sv))
Willy Tarreaud32c3992013-11-21 15:30:45 +01003652 chunk_appendf(&trash, "%d", server_throttle_rate(sv));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003653
3654 /* sessions: lbtot */
3655 chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn);
3656
3657 /* tracked */
3658 if (sv->track)
3659 chunk_appendf(&trash, "%s/%s,",
3660 sv->track->proxy->id, sv->track->id);
3661 else
3662 chunk_appendf(&trash, ",");
3663
3664 /* type */
3665 chunk_appendf(&trash, "%d,", STATS_TYPE_SV);
3666
3667 /* rate */
3668 chunk_appendf(&trash, "%u,,%u,",
3669 read_freq_ctr(&sv->sess_per_sec),
3670 sv->counters.sps_max);
3671
Willy Tarreauff5ae352013-12-11 20:36:34 +01003672 if (sv->check.state & CHK_ST_ENABLED) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003673 /* check_status */
Thierry FOURNIERbe1ccae2015-05-28 16:02:01 +02003674 chunk_appendf(&trash, "%s,", csv_enc(get_check_status_info(sv->check.status), 1, out));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003675
3676 /* check_code */
3677 if (sv->check.status >= HCHK_STATUS_L57DATA)
3678 chunk_appendf(&trash, "%u,", sv->check.code);
3679 else
3680 chunk_appendf(&trash, ",");
3681
3682 /* check_duration */
3683 if (sv->check.status >= HCHK_STATUS_CHECKED)
3684 chunk_appendf(&trash, "%lu,", sv->check.duration);
3685 else
3686 chunk_appendf(&trash, ",");
3687
3688 }
3689 else
3690 chunk_appendf(&trash, ",,,");
3691
3692 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3693 if (px->mode == PR_MODE_HTTP) {
3694 for (i=1; i<6; i++)
3695 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]);
3696
3697 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]);
3698 }
3699 else
3700 chunk_appendf(&trash, ",,,,,,");
3701
3702 /* failed health analyses */
3703 chunk_appendf(&trash, "%lld,", sv->counters.failed_hana);
3704
3705 /* requests : req_rate, req_rate_max, req_tot, */
3706 chunk_appendf(&trash, ",,,");
3707
3708 /* errors: cli_aborts, srv_aborts */
3709 chunk_appendf(&trash, "%lld,%lld,",
3710 sv->counters.cli_aborts, sv->counters.srv_aborts);
3711
3712 /* compression: in, out, bypassed, comp_rsp */
3713 chunk_appendf(&trash, ",,,,");
3714
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003715 /* lastsess */
3716 chunk_appendf(&trash, "%d,", srv_lastsession(sv));
3717
Willy Tarreaua28df3e2014-06-16 16:40:14 +02003718 /* capture of last check and agent statuses */
Thierry FOURNIERbe1ccae2015-05-28 16:02:01 +02003719 chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->check.desc), 1, out) : "");
3720 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 +02003721
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003722 /* qtime, ctime, rtime, ttime, */
3723 chunk_appendf(&trash, "%u,%u,%u,%u,",
3724 swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES),
3725 swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES),
3726 swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES),
3727 swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES));
3728
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003729 /* finish with EOL */
3730 chunk_appendf(&trash, "\n");
3731 }
3732 return 1;
3733}
3734
3735/* Dumps a line for backend <px> to the trash for and uses the state from stream
3736 * interface <si> and stats flags <flags>. The caller is responsible for clearing
3737 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
3738 */
3739static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags)
3740{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003741 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003742 struct chunk src;
3743 int i;
3744
3745 if (!(px->cap & PR_CAP_BE))
3746 return 0;
3747
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003748 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE)))
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003749 return 0;
3750
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003751 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003752 chunk_appendf(&trash, "<tr class=\"backend\">");
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003753 if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003754 /* Column sub-heading for Enable or Disable server */
3755 chunk_appendf(&trash, "<td></td>");
3756 }
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003757 chunk_appendf(&trash,
3758 "<td class=ac>"
3759 /* name */
3760 "%s<a name=\"%s/Backend\"></a>"
3761 "<a class=lfsb href=\"#%s/Backend\">Backend</a>"
3762 "",
3763 (flags & ST_SHLGNDS)?"<u>":"",
3764 px->id, px->id);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003765
3766 if (flags & ST_SHLGNDS) {
3767 /* balancing */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003768 chunk_appendf(&trash, "<div class=tips>balancing: %s",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003769 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
3770
3771 /* cookie */
3772 if (px->cookie_name) {
3773 chunk_appendf(&trash, ", cookie: '");
3774 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
3775 chunk_htmlencode(&trash, &src);
3776 chunk_appendf(&trash, "'");
3777 }
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003778 chunk_appendf(&trash, "</div>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003779 }
3780
3781 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003782 "%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003783 /* queue : current, max */
3784 "<td>%s</td><td>%s</td><td></td>"
3785 /* sessions rate : current, max, limit */
3786 "<td>%s</td><td>%s</td><td></td>"
3787 "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003788 (flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003789 U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max),
3790 U2H(read_freq_ctr(&px->be_sess_per_sec)), U2H(px->be_counters.sps_max));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003791
3792 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003793 /* sessions: current, max, limit, total */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003794 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003795 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01003796 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003797 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003798 U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn),
3799 U2H(px->be_counters.cum_conn),
3800 U2H(px->be_counters.cum_conn));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003801
Willy Tarreau466c9b52012-12-23 02:25:03 +01003802 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003803 if (px->mode == PR_MODE_HTTP) {
Willy Tarreau466c9b52012-12-23 02:25:03 +01003804 chunk_appendf(&trash,
3805 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
3806 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
3807 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
3808 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
3809 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
3810 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
3811 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
3812 "<tr><th>- other responses:</th><td>%s</td></tr>"
3813 "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003814 "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01003815 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003816 U2H(px->be_counters.p.http.cum_req),
3817 U2H(px->be_counters.p.http.rsp[1]),
3818 U2H(px->be_counters.p.http.rsp[2]),
3819 U2H(px->be_counters.p.http.comp_rsp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003820 px->be_counters.p.http.rsp[2] ?
Willy Tarreau466c9b52012-12-23 02:25:03 +01003821 (int)(100*px->be_counters.p.http.comp_rsp/px->be_counters.p.http.rsp[2]) : 0,
Willy Tarreau56adcf22012-12-23 18:00:29 +01003822 U2H(px->be_counters.p.http.rsp[3]),
3823 U2H(px->be_counters.p.http.rsp[4]),
3824 U2H(px->be_counters.p.http.rsp[5]),
3825 U2H(px->be_counters.p.http.rsp[0]),
3826 U2H(px->be_counters.intercepted_req));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003827 }
3828
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003829 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)));
3830 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)));
3831 if (px->mode == PR_MODE_HTTP)
3832 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)));
3833 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)));
3834
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003835 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01003836 "</table></div></u></td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003837 /* sessions: lbtot, last */
3838 "<td>%s</td><td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003839 /* bytes: in */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003840 "<td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003841 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003842 U2H(px->be_counters.cum_lbconn),
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003843 human_time(be_lastsession(px), 1),
Willy Tarreau56adcf22012-12-23 18:00:29 +01003844 U2H(px->be_counters.bytes_in));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003845
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003846 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003847 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
Willy Tarreau4e5d58e2015-07-04 14:35:15 +02003848 "<td>%s%s<div class=tips><table class=det>"
3849 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
3850 "<tr><th>Compression in:</th><td>%s</td></tr>"
3851 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
3852 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
3853 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
3854 "</table></div>%s</td>",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003855 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003856 U2H(px->be_counters.bytes_out),
Willy Tarreau4e5d58e2015-07-04 14:35:15 +02003857 U2H(px->be_counters.bytes_out),
3858 U2H(px->be_counters.comp_in),
3859 U2H(px->be_counters.comp_out),
3860 px->be_counters.comp_in ? (int)(px->be_counters.comp_out * 100 / px->be_counters.comp_in) : 0,
3861 U2H(px->be_counters.comp_byp),
3862 U2H(px->be_counters.comp_in - px->be_counters.comp_out),
3863 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 +01003864 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":"");
3865
3866 chunk_appendf(&trash,
3867 /* denied: req, resp */
3868 "<td>%s</td><td>%s</td>"
3869 /* errors : request, connect */
3870 "<td></td><td>%s</td>"
3871 /* errors : response */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003872 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003873 /* warnings: retries, redispatches */
3874 "<td>%lld</td><td>%lld</td>"
3875 /* backend status: reflect backend status (up/down): we display UP
3876 * if the backend has known working servers or if it has no server at
3877 * all (eg: for stats). Then we display the total weight, number of
3878 * active and backups. */
3879 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
3880 "<td class=ac>%d</td><td class=ac>%d</td>"
3881 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003882 U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp),
3883 U2H(px->be_counters.failed_conns),
3884 U2H(px->be_counters.failed_resp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003885 px->be_counters.cli_aborts,
3886 px->be_counters.srv_aborts,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003887 px->be_counters.retries, px->be_counters.redispatches,
3888 human_time(now.tv_sec - px->last_change, 1),
3889 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
3890 "<font color=\"red\"><b>DOWN</b></font>",
3891 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
3892 px->srv_act, px->srv_bck);
3893
3894 chunk_appendf(&trash,
3895 /* rest of backend: nothing, down transitions, total downtime, throttle */
3896 "<td class=ac>&nbsp;</td><td>%d</td>"
3897 "<td>%s</td>"
3898 "<td></td>"
3899 "</tr>",
3900 px->down_trans,
3901 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
3902 }
3903 else { /* CSV mode */
3904 chunk_appendf(&trash,
3905 /* pxid, name */
3906 "%s,BACKEND,"
3907 /* queue : current, max */
3908 "%d,%d,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003909 /* sessions : current, max, limit, total */
3910 "%d,%d,%d,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003911 /* bytes : in, out */
3912 "%lld,%lld,"
3913 /* denied: req, resp */
3914 "%lld,%lld,"
3915 /* errors : request, connect, response */
3916 ",%lld,%lld,"
3917 /* warnings: retries, redispatches */
3918 "%lld,%lld,"
3919 /* backend status: reflect backend status (up/down): we display UP
3920 * if the backend has known working servers or if it has no server at
3921 * all (eg: for stats). Then we display the total weight, number of
3922 * active and backups. */
3923 "%s,"
3924 "%d,%d,%d,"
3925 /* rest of backend: nothing, down transitions, last change, total downtime */
3926 ",%d,%d,%d,,"
3927 /* pid, iid, sid, throttle, lbtot, tracked, type */
3928 "%d,%d,0,,%lld,,%d,"
3929 /* rate, rate_lim, rate_max, */
3930 "%u,,%u,"
3931 /* check_status, check_code, check_duration */
3932 ",,,",
3933 px->id,
3934 px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max,
3935 px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn,
3936 px->be_counters.bytes_in, px->be_counters.bytes_out,
3937 px->be_counters.denied_req, px->be_counters.denied_resp,
3938 px->be_counters.failed_conns, px->be_counters.failed_resp,
3939 px->be_counters.retries, px->be_counters.redispatches,
3940 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
3941 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
3942 px->srv_act, px->srv_bck,
3943 px->down_trans, (int)(now.tv_sec - px->last_change),
3944 px->srv?be_downtime(px):0,
3945 relative_pid, px->uuid,
3946 px->be_counters.cum_lbconn, STATS_TYPE_BE,
3947 read_freq_ctr(&px->be_sess_per_sec),
3948 px->be_counters.sps_max);
3949
3950 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3951 if (px->mode == PR_MODE_HTTP) {
3952 for (i=1; i<6; i++)
3953 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]);
3954 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]);
3955 }
3956 else
3957 chunk_appendf(&trash, ",,,,,,");
3958
3959 /* failed health analyses */
3960 chunk_appendf(&trash, ",");
3961
3962 /* requests : req_rate, req_rate_max, req_tot, */
3963 chunk_appendf(&trash, ",,,");
3964
3965 /* errors: cli_aborts, srv_aborts */
3966 chunk_appendf(&trash, "%lld,%lld,",
3967 px->be_counters.cli_aborts, px->be_counters.srv_aborts);
3968
3969 /* compression: in, out, bypassed */
3970 chunk_appendf(&trash, "%lld,%lld,%lld,",
3971 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
3972
3973 /* compression: comp_rsp */
3974 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp);
3975
Willy Tarreaua28df3e2014-06-16 16:40:14 +02003976 /* lastsess, last_chk, last_agt, */
3977 chunk_appendf(&trash, "%d,,,", be_lastsession(px));
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003978
Willy Tarreauf5b1cc32014-06-17 12:20:59 +02003979 /* qtime, ctime, rtime, ttime, */
3980 chunk_appendf(&trash, "%u,%u,%u,%u,",
3981 swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES),
3982 swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES),
3983 swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES),
3984 swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES));
3985
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003986 /* finish with EOL */
3987 chunk_appendf(&trash, "\n");
3988 }
3989 return 1;
3990}
3991
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003992/* Dumps the HTML table header for proxy <px> to the trash for and uses the state from
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003993 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003994 * for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003995 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003996static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003997{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003998 struct appctx *appctx = __objt_appctx(si->end);
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003999 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
4000
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004001 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004002 /* A form to enable/disable this proxy servers */
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004003
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004004 /* 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 +02004005 scope_txt[0] = 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004006 if (appctx->ctx.stats.scope_len) {
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004007 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau4e4292b2014-11-28 12:18:45 +01004008 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 +01004009 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004010 }
4011
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004012 chunk_appendf(&trash,
Jeff Buchbinder2dbbf4d2014-08-29 15:10:08 -05004013 "<form method=\"post\">");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004014 }
4015
4016 /* print a new table */
4017 chunk_appendf(&trash,
4018 "<table class=\"tbl\" width=\"100%%\">\n"
4019 "<tr class=\"titre\">"
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01004020 "<th class=\"pxname\" width=\"10%%\">");
4021
4022 chunk_appendf(&trash,
4023 "<a name=\"%s\"></a>%s"
4024 "<a class=px href=\"#%s\">%s</a>",
4025 px->id,
4026 (uri->flags & ST_SHLGNDS) ? "<u>":"",
4027 px->id, px->id);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004028
4029 if (uri->flags & ST_SHLGNDS) {
4030 /* cap, mode, id */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02004031 chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004032 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
4033 px->uuid);
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01004034 chunk_appendf(&trash, "</div>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004035 }
4036
4037 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01004038 "%s</th>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004039 "<th class=\"%s\" width=\"90%%\">%s</th>"
4040 "</tr>\n"
4041 "</table>\n"
4042 "<table class=\"tbl\" width=\"100%%\">\n"
4043 "<tr class=\"titre\">",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004044 (uri->flags & ST_SHLGNDS) ? "</u>":"",
4045 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
4046
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004047 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004048 /* Column heading for Enable or Disable server */
4049 chunk_appendf(&trash, "<th rowspan=2 width=1></th>");
Willy Tarreau91861262007-10-17 17:06:05 +02004050 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004051
4052 chunk_appendf(&trash,
4053 "<th rowspan=2></th>"
4054 "<th colspan=3>Queue</th>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05004055 "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004056 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
4057 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
4058 "<th colspan=9>Server</th>"
4059 "</tr>\n"
4060 "<tr class=\"titre\">"
4061 "<th>Cur</th><th>Max</th><th>Limit</th>"
4062 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05004063 "<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 +01004064 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
4065 "<th>Resp</th><th>Retr</th><th>Redis</th>"
4066 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
4067 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
4068 "<th>Thrtle</th>\n"
4069 "</tr>");
Willy Tarreau91861262007-10-17 17:06:05 +02004070}
4071
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004072/* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004073 * stream interface <si>. The caller is responsible for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004074 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004075static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004076{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004077 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004078 chunk_appendf(&trash, "</table>");
4079
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004080 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004081 /* close the form used to enable/disable this proxy servers */
4082 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004083 "Choose the action to perform on the checked servers : "
4084 "<select name=action>"
4085 "<option value=\"\"></option>"
Willy Tarreaued7df902014-05-22 18:04:49 +02004086 "<option value=\"ready\">Set state to READY</option>"
4087 "<option value=\"drain\">Set state to DRAIN</option>"
Marco Corte8c27bca2014-07-02 17:49:34 +02004088 "<option value=\"maint\">Set state to MAINT</option>"
Willy Tarreau248a60e2014-05-23 14:59:48 +02004089 "<option value=\"dhlth\">Health: disable checks</option>"
4090 "<option value=\"ehlth\">Health: enable checks</option>"
4091 "<option value=\"hrunn\">Health: force UP</option>"
4092 "<option value=\"hnolb\">Health: force NOLB</option>"
4093 "<option value=\"hdown\">Health: force DOWN</option>"
4094 "<option value=\"dagent\">Agent: disable checks</option>"
4095 "<option value=\"eagent\">Agent: enable checks</option>"
4096 "<option value=\"arunn\">Agent: force UP</option>"
4097 "<option value=\"adown\">Agent: force DOWN</option>"
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004098 "<option value=\"shutdown\">Kill Sessions</option>"
4099 "</select>"
4100 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
4101 "&nbsp;<input type=\"submit\" value=\"Apply\">"
4102 "</form>",
4103 px->uuid);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004104 }
4105
4106 chunk_appendf(&trash, "<p>\n");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004107}
Willy Tarreau91861262007-10-17 17:06:05 +02004108
4109/*
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004110 * Dumps statistics for a proxy. The output is sent to the stream interface's
4111 * input buffer. Returns 0 if it had to stop dumping data because of lack of
4112 * buffer space, or non-zero if everything completed. This function is used
4113 * both by the CLI and the HTTP entry points, and is able to dump the output
4114 * in HTML or CSV formats. If the later, <uri> must be NULL.
Willy Tarreau91861262007-10-17 17:06:05 +02004115 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004116static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02004117{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004118 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau87b09662015-04-03 00:22:06 +02004119 struct stream *s = si_strm(si);
Willy Tarreau2bb4a962014-11-28 11:11:05 +01004120 struct channel *rep = si_ic(si);
Willy Tarreau44267702011-10-28 15:35:33 +02004121 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004122 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02004123
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004124 chunk_reset(&trash);
Willy Tarreau91861262007-10-17 17:06:05 +02004125
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004126 switch (appctx->ctx.stats.px_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01004127 case STAT_PX_ST_INIT:
Willy Tarreau91861262007-10-17 17:06:05 +02004128 /* we are on a new proxy */
Willy Tarreau91861262007-10-17 17:06:05 +02004129 if (uri && uri->scope) {
4130 /* we have a limited scope, we have to check the proxy name */
4131 struct stat_scope *scope;
4132 int len;
4133
4134 len = strlen(px->id);
4135 scope = uri->scope;
4136
4137 while (scope) {
4138 /* match exact proxy name */
4139 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
4140 break;
4141
4142 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02004143 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02004144 break;
4145 scope = scope->next;
4146 }
4147
4148 /* proxy name not found : don't dump anything */
4149 if (scope == NULL)
4150 return 1;
4151 }
4152
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004153 /* if the user has requested a limited output and the proxy
4154 * name does not match, skip it.
4155 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004156 if (appctx->ctx.stats.scope_len &&
Willy Tarreau4e4292b2014-11-28 12:18:45 +01004157 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 +02004158 return 1;
4159
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004160 if ((appctx->ctx.stats.flags & STAT_BOUND) &&
4161 (appctx->ctx.stats.iid != -1) &&
4162 (px->uuid != appctx->ctx.stats.iid))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01004163 return 1;
4164
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004165 appctx->ctx.stats.px_st = STAT_PX_ST_TH;
Willy Tarreau91861262007-10-17 17:06:05 +02004166 /* fall through */
4167
Willy Tarreau295a8372011-03-10 11:25:07 +01004168 case STAT_PX_ST_TH:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004169 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004170 stats_dump_html_px_hdr(si, px, uri);
Willy Tarreaubc18da12015-03-13 14:00:47 +01004171 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004172 si_applet_cant_put(si);
Willy Tarreau55bb8452007-10-17 18:44:57 +02004173 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004174 }
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004175 }
Willy Tarreau91861262007-10-17 17:06:05 +02004176
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004177 appctx->ctx.stats.px_st = STAT_PX_ST_FE;
Willy Tarreau91861262007-10-17 17:06:05 +02004178 /* fall through */
4179
Willy Tarreau295a8372011-03-10 11:25:07 +01004180 case STAT_PX_ST_FE:
Willy Tarreau91861262007-10-17 17:06:05 +02004181 /* print the frontend */
Willy Tarreaubc18da12015-03-13 14:00:47 +01004182 if (stats_dump_fe_stats(si, px)) {
4183 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004184 si_applet_cant_put(si);
Willy Tarreau91861262007-10-17 17:06:05 +02004185 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004186 }
4187 }
Willy Tarreau91861262007-10-17 17:06:05 +02004188
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004189 appctx->ctx.stats.l = px->conf.listeners.n;
4190 appctx->ctx.stats.px_st = STAT_PX_ST_LI;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004191 /* fall through */
4192
Willy Tarreau295a8372011-03-10 11:25:07 +01004193 case STAT_PX_ST_LI:
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004194 /* stats.l has been initialized above */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004195 for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) {
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004196 if (buffer_almost_full(rep->buf)) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004197 si_applet_cant_put(si);
Willy Tarreau4e33d862009-10-11 23:35:10 +02004198 return 0;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004199 }
Willy Tarreau4e33d862009-10-11 23:35:10 +02004200
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004201 l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004202 if (!l->counters)
4203 continue;
4204
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004205 if (appctx->ctx.stats.flags & STAT_BOUND) {
4206 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO)))
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004207 break;
4208
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004209 if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004210 continue;
4211 }
4212
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004213 /* print the frontend */
Willy Tarreaubc18da12015-03-13 14:00:47 +01004214 if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) {
4215 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004216 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004217 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004218 }
4219 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02004220 }
4221
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004222 appctx->ctx.stats.sv = px->srv; /* may be NULL */
4223 appctx->ctx.stats.px_st = STAT_PX_ST_SV;
Willy Tarreau91861262007-10-17 17:06:05 +02004224 /* fall through */
4225
Willy Tarreau295a8372011-03-10 11:25:07 +01004226 case STAT_PX_ST_SV:
Willy Tarreau91861262007-10-17 17:06:05 +02004227 /* stats.sv has been initialized above */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004228 for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004229 enum srv_stats_state sv_state;
Simon Horman837bfa72015-04-23 14:51:27 +09004230 enum srv_stats_colour sv_colour;
Willy Tarreau91861262007-10-17 17:06:05 +02004231
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004232 if (buffer_almost_full(rep->buf)) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004233 si_applet_cant_put(si);
Willy Tarreau4e33d862009-10-11 23:35:10 +02004234 return 0;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004235 }
Willy Tarreau4e33d862009-10-11 23:35:10 +02004236
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004237 sv = appctx->ctx.stats.sv;
Willy Tarreau91861262007-10-17 17:06:05 +02004238
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004239 if (appctx->ctx.stats.flags & STAT_BOUND) {
4240 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV)))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01004241 break;
4242
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004243 if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid)
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01004244 continue;
4245 }
4246
Willy Tarreau32091232014-05-16 13:52:00 +02004247 svs = sv;
4248 while (svs->track)
4249 svs = svs->track;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01004250
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004251 if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) {
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004252 if ((svs->check.state & CHK_ST_ENABLED) &&
Simon Horman837bfa72015-04-23 14:51:27 +09004253 (svs->check.health < svs->check.rise + svs->check.fall - 1)) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004254 sv_state = SRV_STATS_STATE_UP_GOING_DOWN;
Simon Horman837bfa72015-04-23 14:51:27 +09004255 sv_colour = SRV_STATS_COLOUR_GOING_DOWN;
4256 } else {
Simon Horman4d2eab62015-04-23 14:51:26 +09004257 sv_state = SRV_STATS_STATE_UP;
Simon Horman837bfa72015-04-23 14:51:27 +09004258 sv_colour = SRV_STATS_COLOUR_UP;
4259 }
Willy Tarreau2ea81932007-11-30 12:04:38 +01004260
Simon Horman4463d192015-04-23 14:51:28 +09004261 if (sv_state == SRV_STATS_STATE_UP && !svs->uweight)
4262 sv_colour = SRV_STATS_COLOUR_DRAINING;
4263
4264 if (sv->admin & SRV_ADMF_DRAIN) {
Simon Hormanb167b6b2015-04-23 14:51:29 +09004265 if (svs->agent.state & CHK_ST_ENABLED)
4266 sv_state = SRV_STATS_STATE_DRAIN_AGENT;
4267 else if (sv_state == SRV_STATS_STATE_UP_GOING_DOWN)
Simon Horman4d2eab62015-04-23 14:51:26 +09004268 sv_state = SRV_STATS_STATE_DRAIN_GOING_DOWN;
Simon Horman4463d192015-04-23 14:51:28 +09004269 else
Simon Horman4d2eab62015-04-23 14:51:26 +09004270 sv_state = SRV_STATS_STATE_DRAIN;
4271 }
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004272
Simon Horman837bfa72015-04-23 14:51:27 +09004273 if (sv_state == SRV_STATS_STATE_UP && !(svs->check.state & CHK_ST_ENABLED)) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004274 sv_state = SRV_STATS_STATE_NO_CHECK;
Simon Horman837bfa72015-04-23 14:51:27 +09004275 sv_colour = SRV_STATS_COLOUR_NO_CHECK;
4276 }
Willy Tarreau2ea81932007-11-30 12:04:38 +01004277 }
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004278 else if (sv->state == SRV_ST_STOPPING) {
4279 if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) ||
Simon Horman837bfa72015-04-23 14:51:27 +09004280 (svs->check.health == svs->check.rise + svs->check.fall - 1)) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004281 sv_state = SRV_STATS_STATE_NOLB;
Simon Horman837bfa72015-04-23 14:51:27 +09004282 sv_colour = SRV_STATS_COLOUR_NOLB;
4283 } else {
Simon Horman4d2eab62015-04-23 14:51:26 +09004284 sv_state = SRV_STATS_STATE_NOLB_GOING_DOWN;
Simon Horman837bfa72015-04-23 14:51:27 +09004285 sv_colour = SRV_STATS_COLOUR_GOING_DOWN;
4286 }
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004287 }
4288 else { /* stopped */
Simon Horman837bfa72015-04-23 14:51:27 +09004289 if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004290 sv_state = SRV_STATS_STATE_DOWN_AGENT;
Simon Horman837bfa72015-04-23 14:51:27 +09004291 sv_colour = SRV_STATS_COLOUR_DOWN;
4292 } else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004293 sv_state = SRV_STATS_STATE_DOWN; /* DOWN */
Simon Horman837bfa72015-04-23 14:51:27 +09004294 sv_colour = SRV_STATS_COLOUR_DOWN;
4295 } else if ((svs->agent.state & CHK_ST_ENABLED) || (svs->check.state & CHK_ST_ENABLED)) {
Simon Horman4d2eab62015-04-23 14:51:26 +09004296 sv_state = SRV_STATS_STATE_GOING_UP;
Simon Horman837bfa72015-04-23 14:51:27 +09004297 sv_colour = SRV_STATS_COLOUR_GOING_UP;
4298 } else {
Simon Horman4d2eab62015-04-23 14:51:26 +09004299 sv_state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */
Simon Horman837bfa72015-04-23 14:51:27 +09004300 sv_colour = SRV_STATS_COLOUR_DOWN;
4301 }
Willy Tarreauf4e38b32014-05-21 15:04:05 +02004302 }
Willy Tarreau91861262007-10-17 17:06:05 +02004303
Willy Tarreau9638efa2014-05-23 11:19:57 +02004304 if (((sv_state <= 1) || (sv->admin & SRV_ADMF_MAINT)) && (appctx->ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02004305 /* do not report servers which are DOWN */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004306 appctx->ctx.stats.sv = sv->next;
Willy Tarreau91861262007-10-17 17:06:05 +02004307 continue;
4308 }
4309
Simon Horman837bfa72015-04-23 14:51:27 +09004310 if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state, sv_colour)) {
Willy Tarreaubc18da12015-03-13 14:00:47 +01004311 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004312 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004313 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004314 }
4315 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004316 } /* for sv */
Cyril Bonté474be412010-10-12 00:14:36 +02004317
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004318 appctx->ctx.stats.px_st = STAT_PX_ST_BE;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004319 /* fall through */
Cyril Bonté70be45d2010-10-12 00:14:35 +02004320
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004321 case STAT_PX_ST_BE:
4322 /* print the backend */
Willy Tarreaubc18da12015-03-13 14:00:47 +01004323 if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) {
4324 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004325 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004326 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004327 }
4328 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004329
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004330 appctx->ctx.stats.px_st = STAT_PX_ST_END;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004331 /* fall through */
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004332
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004333 case STAT_PX_ST_END:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004334 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004335 stats_dump_html_px_end(si, px);
Willy Tarreaubc18da12015-03-13 14:00:47 +01004336 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004337 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004338 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004339 }
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004340 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004341
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004342 appctx->ctx.stats.px_st = STAT_PX_ST_FIN;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004343 /* fall through */
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004344
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004345 case STAT_PX_ST_FIN:
4346 return 1;
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004347
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004348 default:
4349 /* unknown state, we should put an abort() here ! */
4350 return 1;
4351 }
4352}
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004353
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004354/* Dumps the HTTP stats head block to the trash for and uses the per-uri
4355 * parameters <uri>. The caller is responsible for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004356 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004357static void stats_dump_html_head(struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004358{
4359 /* WARNING! This must fit in the first buffer !!! */
4360 chunk_appendf(&trash,
4361 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
4362 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
4363 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
4364 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
4365 "<style type=\"text/css\"><!--\n"
4366 "body {"
4367 " font-family: arial, helvetica, sans-serif;"
4368 " font-size: 12px;"
4369 " font-weight: normal;"
4370 " color: black;"
4371 " background: white;"
4372 "}\n"
4373 "th,td {"
4374 " font-size: 10px;"
4375 "}\n"
4376 "h1 {"
4377 " font-size: x-large;"
4378 " margin-bottom: 0.5em;"
4379 "}\n"
4380 "h2 {"
4381 " font-family: helvetica, arial;"
4382 " font-size: x-large;"
4383 " font-weight: bold;"
4384 " font-style: italic;"
4385 " color: #6020a0;"
4386 " margin-top: 0em;"
4387 " margin-bottom: 0em;"
4388 "}\n"
4389 "h3 {"
4390 " font-family: helvetica, arial;"
4391 " font-size: 16px;"
4392 " font-weight: bold;"
4393 " color: #b00040;"
4394 " background: #e8e8d0;"
4395 " margin-top: 0em;"
4396 " margin-bottom: 0em;"
4397 "}\n"
4398 "li {"
4399 " margin-top: 0.25em;"
4400 " margin-right: 2em;"
4401 "}\n"
4402 ".hr {margin-top: 0.25em;"
4403 " border-color: black;"
4404 " border-bottom-style: solid;"
4405 "}\n"
4406 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
4407 ".total {background: #20D0D0;color: #ffff80;}\n"
4408 ".frontend {background: #e8e8d0;}\n"
4409 ".socket {background: #d0d0d0;}\n"
4410 ".backend {background: #e8e8d0;}\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004411 ".active_down {background: #ff9090;}\n"
4412 ".active_going_up {background: #ffd020;}\n"
4413 ".active_going_down {background: #ffffa0;}\n"
4414 ".active_up {background: #c0ffc0;}\n"
4415 ".active_nolb {background: #20a0ff;}\n"
4416 ".active_draining {background: #20a0FF;}\n"
4417 ".active_no_check {background: #e0e0e0;}\n"
4418 ".backup_down {background: #ff9090;}\n"
4419 ".backup_going_up {background: #ff80ff;}\n"
4420 ".backup_going_down {background: #c060ff;}\n"
4421 ".backup_up {background: #b0d0ff;}\n"
4422 ".backup_nolb {background: #90b0e0;}\n"
4423 ".backup_draining {background: #cc9900;}\n"
4424 ".backup_no_check {background: #e0e0e0;}\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004425 ".maintain {background: #c07820;}\n"
4426 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
4427 "\n"
4428 "a.px:link {color: #ffff40; text-decoration: none;}"
4429 "a.px:visited {color: #ffff40; text-decoration: none;}"
4430 "a.px:hover {color: #ffffff; text-decoration: none;}"
4431 "a.lfsb:link {color: #000000; text-decoration: none;}"
4432 "a.lfsb:visited {color: #000000; text-decoration: none;}"
4433 "a.lfsb:hover {color: #505050; text-decoration: none;}"
4434 "\n"
4435 "table.tbl { border-collapse: collapse; border-style: none;}\n"
4436 "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"
4437 "table.tbl td.ac { text-align: center;}\n"
4438 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
4439 "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n"
4440 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
4441 "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n"
4442 "\n"
4443 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
4444 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
4445 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
Willy Tarreau466c9b52012-12-23 02:25:03 +01004446 "table.det { border-collapse: collapse; border-style: none; }\n"
4447 "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 +01004448 "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 +01004449 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02004450 "div.tips {\n"
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01004451 " display:block;\n"
4452 " visibility:hidden;\n"
4453 " z-index:2147483647;\n"
4454 " position:absolute;\n"
4455 " padding:2px 4px 3px;\n"
4456 " background:#f0f060; color:#000000;\n"
4457 " border:1px solid #7040c0;\n"
4458 " white-space:nowrap;\n"
4459 " font-style:normal;font-size:11px;font-weight:normal;\n"
4460 " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n"
4461 " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n"
4462 "}\n"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02004463 "u:hover div.tips {visibility:visible;}\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004464 "-->\n"
4465 "</style></head>\n",
4466 (uri->flags & ST_SHNODE) ? " on " : "",
4467 (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
4468 );
4469}
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004470
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004471/* Dumps the HTML stats information block to the trash for and uses the state from
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004472 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004473 * for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004474 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004475static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004476{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004477 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004478 unsigned int up = (now.tv_sec - start_date.tv_sec);
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004479 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004480
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004481 /* WARNING! this has to fit the first packet too.
4482 * We are around 3.5 kB, add adding entries will
4483 * become tricky if we want to support 4kB buffers !
4484 */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004485 chunk_appendf(&trash,
4486 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
4487 PRODUCT_NAME "%s</a></h1>\n"
4488 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
4489 "<hr width=\"100%%\" class=\"hr\">\n"
4490 "<h3>&gt; General process information</h3>\n"
4491 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
4492 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
4493 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
4494 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
4495 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
4496 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n"
4497 "Running tasks: %d/%d; idle = %d %%<br>\n"
4498 "</td><td align=\"center\" nowrap>\n"
4499 "<table class=\"lgd\"><tr>\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004500 "<td class=\"active_up\">&nbsp;</td><td class=\"noborder\">active UP </td>"
4501 "<td class=\"backup_up\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004502 "</tr><tr>\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004503 "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>"
4504 "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004505 "</tr><tr>\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004506 "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>"
4507 "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004508 "</tr><tr>\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004509 "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
4510 "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004511 "</tr><tr>\n"
4512 "<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 -07004513 "</tr><tr>\n"
Simon Horman837bfa72015-04-23 14:51:27 +09004514 "<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 +01004515 "</tr></table>\n"
Willy Tarreau6b7764a2013-12-04 00:43:21 +01004516 "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled."
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004517 "</td>"
4518 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
4519 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
4520 "",
4521 (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING),
4522 pid, (uri->flags & ST_SHNODE) ? " on " : "",
4523 (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
4524 (uri->flags & ST_SHDESC) ? ": " : "",
4525 (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
4526 pid, relative_pid, global.nbproc,
4527 up / 86400, (up % 86400) / 3600,
4528 (up % 3600) / 60, (up % 60),
4529 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
4530 global.rlimit_memmax ? " MB" : "",
4531 global.rlimit_nofile,
4532 global.maxsock, global.maxconn, global.maxpipes,
4533 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
4534 run_queue_cur, nb_tasks_cur, idle_pct
4535 );
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004536
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004537 /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
Willy Tarreau4e4292b2014-11-28 12:18:45 +01004538 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 +01004539 scope_txt[appctx->ctx.stats.scope_len] = '\0';
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004540
4541 chunk_appendf(&trash,
Jeff Buchbinder2dbbf4d2014-08-29 15:10:08 -05004542 "<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 +01004543 (appctx->ctx.stats.scope_len > 0) ? scope_txt : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004544 STAT_SCOPE_TXT_MAXLEN);
4545
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004546 /* 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 +02004547 scope_txt[0] = 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004548 if (appctx->ctx.stats.scope_len) {
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004549 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau4e4292b2014-11-28 12:18:45 +01004550 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 +01004551 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004552 }
4553
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004554 if (appctx->ctx.stats.flags & STAT_HIDE_DOWN)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004555 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004556 "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004557 uri->uri_prefix,
4558 "",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004559 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004560 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004561 else
4562 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004563 "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004564 uri->uri_prefix,
4565 ";up",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004566 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004567 scope_txt);
Willy Tarreau91861262007-10-17 17:06:05 +02004568
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004569 if (uri->refresh > 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004570 if (appctx->ctx.stats.flags & STAT_NO_REFRESH)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004571 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004572 "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004573 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004574 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004575 "",
4576 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004577 else
4578 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004579 "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004580 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004581 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004582 ";norefresh",
4583 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004584 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02004585
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004586 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004587 "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004588 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004589 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4590 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004591 scope_txt);
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02004592
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004593 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004594 "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004595 uri->uri_prefix,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02004596 (uri->refresh > 0) ? ";norefresh" : "",
4597 scope_txt);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01004598
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004599 chunk_appendf(&trash,
4600 "</ul></td>"
4601 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
4602 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
4603 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
4604 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
4605 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
4606 "</ul>"
4607 "</td>"
4608 "</tr></table>\n"
4609 ""
4610 );
Willy Tarreau4bab24d2007-11-30 18:16:29 +01004611
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004612 if (appctx->ctx.stats.st_code) {
4613 switch (appctx->ctx.stats.st_code) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004614 case STAT_STATUS_DONE:
4615 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004616 "<p><div class=active_up>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004617 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004618 "Action processed successfully."
Willy Tarreauba6be982013-04-19 12:16:55 +02004619 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004620 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4621 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004622 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004623 break;
4624 case STAT_STATUS_NONE:
4625 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004626 "<p><div class=active_going_down>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004627 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004628 "Nothing has changed."
Willy Tarreauba6be982013-04-19 12:16:55 +02004629 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004630 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4631 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004632 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004633 break;
4634 case STAT_STATUS_PART:
4635 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004636 "<p><div class=active_going_down>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004637 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004638 "Action partially processed.<br>"
4639 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
Willy Tarreauba6be982013-04-19 12:16:55 +02004640 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004641 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4642 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004643 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004644 break;
4645 case STAT_STATUS_ERRP:
4646 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004647 "<p><div class=active_down>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004648 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004649 "Action not processed because of invalid parameters."
4650 "<ul>"
4651 "<li>The action is maybe unknown.</li>"
4652 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
4653 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
4654 "</ul>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004655 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004656 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4657 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004658 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004659 break;
4660 case STAT_STATUS_EXCD:
4661 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004662 "<p><div class=active_down>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004663 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004664 "<b>Action not processed : the buffer couldn't store all the data.<br>"
4665 "You should retry with less servers at a time.</b>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004666 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004667 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4668 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004669 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004670 break;
4671 case STAT_STATUS_DENY:
4672 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004673 "<p><div class=active_down>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004674 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004675 "<b>Action denied.</b>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004676 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004677 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4678 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004679 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004680 break;
4681 default:
4682 chunk_appendf(&trash,
Simon Horman837bfa72015-04-23 14:51:27 +09004683 "<p><div class=active_no_check>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004684 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004685 "Unexpected result."
Willy Tarreauba6be982013-04-19 12:16:55 +02004686 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004687 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4688 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004689 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004690 }
4691 chunk_appendf(&trash, "<p>\n");
4692 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004693}
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01004694
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004695/* Dumps the HTML stats trailer block to the trash. The caller is responsible
4696 * for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004697 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004698static void stats_dump_html_end()
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004699{
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004700 chunk_appendf(&trash, "</body></html>\n");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004701}
Willy Tarreau7f062c42009-03-05 18:43:00 +01004702
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004703/* This function dumps statistics onto the stream interface's read buffer in
4704 * either CSV or HTML format. <uri> contains some HTML-specific parameters that
Willy Tarreau306f8302013-07-08 15:53:06 +02004705 * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if
4706 * 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 +02004707 * and the stream must be closed, or -1 in case of any error. This function is
Willy Tarreau306f8302013-07-08 15:53:06 +02004708 * used by both the CLI and the HTTP handlers.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004709 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004710static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004711{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004712 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau2bb4a962014-11-28 11:11:05 +01004713 struct channel *rep = si_ic(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004714 struct proxy *px;
Willy Tarreau7f062c42009-03-05 18:43:00 +01004715
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004716 chunk_reset(&trash);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02004717
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004718 switch (appctx->st2) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004719 case STAT_ST_INIT:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004720 appctx->st2 = STAT_ST_HEAD; /* let's start producing data */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004721 /* fall through */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01004722
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004723 case STAT_ST_HEAD:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004724 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004725 stats_dump_html_head(uri);
Willy Tarreau354898b2012-12-23 18:15:23 +01004726 else
4727 stats_dump_csv_header();
Willy Tarreaud9b587f2010-02-26 10:05:55 +01004728
Willy Tarreaubc18da12015-03-13 14:00:47 +01004729 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004730 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004731 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004732 }
Willy Tarreauae526782010-03-04 20:34:23 +01004733
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004734 appctx->st2 = STAT_ST_INFO;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004735 /* fall through */
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01004736
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004737 case STAT_ST_INFO:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004738 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004739 stats_dump_html_info(si, uri);
Willy Tarreaubc18da12015-03-13 14:00:47 +01004740 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004741 si_applet_cant_put(si);
Willy Tarreau91861262007-10-17 17:06:05 +02004742 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004743 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004744 }
Willy Tarreau91861262007-10-17 17:06:05 +02004745
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004746 appctx->ctx.stats.px = proxy;
4747 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
4748 appctx->st2 = STAT_ST_LIST;
Willy Tarreau91861262007-10-17 17:06:05 +02004749 /* fall through */
4750
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004751 case STAT_ST_LIST:
4752 /* dump proxies */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004753 while (appctx->ctx.stats.px) {
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004754 if (buffer_almost_full(rep->buf)) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004755 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004756 return 0;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004757 }
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004758
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004759 px = appctx->ctx.stats.px;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004760 /* skip the disabled proxies, global frontend and non-networked ones */
4761 if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004762 if (stats_dump_proxy_to_buffer(si, px, uri) == 0)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004763 return 0;
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004764
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004765 appctx->ctx.stats.px = px->next;
4766 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004767 }
4768 /* here, we just have reached the last proxy */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004769
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004770 appctx->st2 = STAT_ST_END;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004771 /* fall through */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004772
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004773 case STAT_ST_END:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004774 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004775 stats_dump_html_end();
Willy Tarreaubc18da12015-03-13 14:00:47 +01004776 if (bi_putchk(rep, &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02004777 si_applet_cant_put(si);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004778 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01004779 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004780 }
Willy Tarreau55058a72012-11-21 08:27:21 +01004781
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004782 appctx->st2 = STAT_ST_FIN;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004783 /* fall through */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02004784
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004785 case STAT_ST_FIN:
4786 return 1;
Willy Tarreau55058a72012-11-21 08:27:21 +01004787
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004788 default:
4789 /* unknown state ! */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004790 appctx->st2 = STAT_ST_FIN;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004791 return -1;
4792 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004793}
Willy Tarreauae526782010-03-04 20:34:23 +01004794
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004795/* We reached the stats page through a POST request. The appctx is
4796 * expected to have already been allocated by the caller.
Willy Tarreau347a35d2013-11-22 17:51:09 +01004797 * Parse the posted data and enable/disable servers if necessary.
4798 * Returns 1 if request was parsed or zero if it needs more data.
4799 */
4800static int stats_process_http_post(struct stream_interface *si)
4801{
Willy Tarreau87b09662015-04-03 00:22:06 +02004802 struct stream *s = si_strm(si);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004803 struct appctx *appctx = objt_appctx(si->end);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004804
4805 struct proxy *px = NULL;
4806 struct server *sv = NULL;
4807
4808 char key[LINESIZE];
4809 int action = ST_ADM_ACTION_NONE;
4810 int reprocess = 0;
4811
4812 int total_servers = 0;
4813 int altered_servers = 0;
4814
4815 char *first_param, *cur_param, *next_param, *end_params;
4816 char *st_cur_param = NULL;
4817 char *st_next_param = NULL;
4818
4819 struct chunk *temp;
4820 int reql;
4821
4822 temp = get_trash_chunk();
Willy Tarreaueee5b512015-04-03 23:46:31 +02004823 if (temp->size < s->txn->req.body_len) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004824 /* too large request */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004825 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004826 goto out;
4827 }
4828
Willy Tarreaueee5b512015-04-03 23:46:31 +02004829 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 +01004830 if (reql <= 0) {
4831 /* we need more data */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004832 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004833 return 0;
4834 }
4835
4836 first_param = temp->str;
4837 end_params = temp->str + reql;
4838 cur_param = next_param = end_params;
4839 *end_params = '\0';
4840
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004841 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004842
4843 /*
4844 * Parse the parameters in reverse order to only store the last value.
4845 * From the html form, the backend and the action are at the end.
4846 */
4847 while (cur_param > first_param) {
4848 char *value;
4849 int poffset, plen;
4850
4851 cur_param--;
4852
4853 if ((*cur_param == '&') || (cur_param == first_param)) {
4854 reprocess_servers:
4855 /* Parse the key */
4856 poffset = (cur_param != first_param ? 1 : 0);
4857 plen = next_param - cur_param + (cur_param == first_param ? 1 : 0);
4858 if ((plen > 0) && (plen <= sizeof(key))) {
4859 strncpy(key, cur_param + poffset, plen);
4860 key[plen - 1] = '\0';
4861 } else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004862 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004863 goto out;
4864 }
4865
4866 /* Parse the value */
4867 value = key;
4868 while (*value != '\0' && *value != '=') {
4869 value++;
4870 }
4871 if (*value == '=') {
4872 /* Ok, a value is found, we can mark the end of the key */
4873 *value++ = '\0';
4874 }
4875 if (url_decode(key) < 0 || url_decode(value) < 0)
4876 break;
4877
4878 /* Now we can check the key to see what to do */
4879 if (!px && (strcmp(key, "b") == 0)) {
Willy Tarreau9e0bb102015-05-26 11:24:42 +02004880 if ((px = proxy_be_by_name(value)) == NULL) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004881 /* the backend name is unknown or ambiguous (duplicate names) */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004882 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004883 goto out;
4884 }
4885 }
4886 else if (!action && (strcmp(key, "action") == 0)) {
Willy Tarreaued7df902014-05-22 18:04:49 +02004887 if (strcmp(value, "ready") == 0) {
4888 action = ST_ADM_ACTION_READY;
4889 }
4890 else if (strcmp(value, "drain") == 0) {
4891 action = ST_ADM_ACTION_DRAIN;
4892 }
4893 else if (strcmp(value, "maint") == 0) {
4894 action = ST_ADM_ACTION_MAINT;
4895 }
4896 else if (strcmp(value, "shutdown") == 0) {
4897 action = ST_ADM_ACTION_SHUTDOWN;
4898 }
Willy Tarreau248a60e2014-05-23 14:59:48 +02004899 else if (strcmp(value, "dhlth") == 0) {
4900 action = ST_ADM_ACTION_DHLTH;
4901 }
4902 else if (strcmp(value, "ehlth") == 0) {
4903 action = ST_ADM_ACTION_EHLTH;
4904 }
4905 else if (strcmp(value, "hrunn") == 0) {
4906 action = ST_ADM_ACTION_HRUNN;
4907 }
4908 else if (strcmp(value, "hnolb") == 0) {
4909 action = ST_ADM_ACTION_HNOLB;
4910 }
4911 else if (strcmp(value, "hdown") == 0) {
4912 action = ST_ADM_ACTION_HDOWN;
4913 }
4914 else if (strcmp(value, "dagent") == 0) {
4915 action = ST_ADM_ACTION_DAGENT;
4916 }
4917 else if (strcmp(value, "eagent") == 0) {
4918 action = ST_ADM_ACTION_EAGENT;
4919 }
4920 else if (strcmp(value, "arunn") == 0) {
4921 action = ST_ADM_ACTION_ARUNN;
4922 }
4923 else if (strcmp(value, "adown") == 0) {
4924 action = ST_ADM_ACTION_ADOWN;
4925 }
Willy Tarreaued7df902014-05-22 18:04:49 +02004926 /* else these are the old supported methods */
4927 else if (strcmp(value, "disable") == 0) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004928 action = ST_ADM_ACTION_DISABLE;
4929 }
4930 else if (strcmp(value, "enable") == 0) {
4931 action = ST_ADM_ACTION_ENABLE;
4932 }
4933 else if (strcmp(value, "stop") == 0) {
4934 action = ST_ADM_ACTION_STOP;
4935 }
4936 else if (strcmp(value, "start") == 0) {
4937 action = ST_ADM_ACTION_START;
4938 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01004939 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004940 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004941 goto out;
4942 }
4943 }
4944 else if (strcmp(key, "s") == 0) {
4945 if (!(px && action)) {
4946 /*
4947 * Indicates that we'll need to reprocess the parameters
4948 * as soon as backend and action are known
4949 */
4950 if (!reprocess) {
4951 st_cur_param = cur_param;
4952 st_next_param = next_param;
4953 }
4954 reprocess = 1;
4955 }
4956 else if ((sv = findserver(px, value)) != NULL) {
4957 switch (action) {
4958 case ST_ADM_ACTION_DISABLE:
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004959 if (!(sv->admin & SRV_ADMF_FMAINT)) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004960 altered_servers++;
4961 total_servers++;
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004962 srv_set_admin_flag(sv, SRV_ADMF_FMAINT);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004963 }
4964 break;
4965 case ST_ADM_ACTION_ENABLE:
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004966 if (sv->admin & SRV_ADMF_FMAINT) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004967 altered_servers++;
4968 total_servers++;
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004969 srv_clr_admin_flag(sv, SRV_ADMF_FMAINT);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004970 }
4971 break;
4972 case ST_ADM_ACTION_STOP:
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004973 if (!(sv->admin & SRV_ADMF_FDRAIN)) {
4974 srv_set_admin_flag(sv, SRV_ADMF_FDRAIN);
4975 altered_servers++;
4976 total_servers++;
4977 }
4978 break;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004979 case ST_ADM_ACTION_START:
Willy Tarreaufae3a7e2014-05-22 17:22:34 +02004980 if (sv->admin & SRV_ADMF_FDRAIN) {
4981 srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN);
4982 altered_servers++;
4983 total_servers++;
4984 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01004985 break;
Willy Tarreau248a60e2014-05-23 14:59:48 +02004986 case ST_ADM_ACTION_DHLTH:
4987 if (sv->check.state & CHK_ST_CONFIGURED) {
4988 sv->check.state &= ~CHK_ST_ENABLED;
4989 altered_servers++;
4990 total_servers++;
4991 }
4992 break;
4993 case ST_ADM_ACTION_EHLTH:
4994 if (sv->check.state & CHK_ST_CONFIGURED) {
4995 sv->check.state |= CHK_ST_ENABLED;
4996 altered_servers++;
4997 total_servers++;
4998 }
4999 break;
5000 case ST_ADM_ACTION_HRUNN:
5001 if (!(sv->track)) {
5002 sv->check.health = sv->check.rise + sv->check.fall - 1;
5003 srv_set_running(sv, "changed from Web interface");
5004 altered_servers++;
5005 total_servers++;
5006 }
5007 break;
5008 case ST_ADM_ACTION_HNOLB:
5009 if (!(sv->track)) {
5010 sv->check.health = sv->check.rise + sv->check.fall - 1;
5011 srv_set_stopping(sv, "changed from Web interface");
5012 altered_servers++;
5013 total_servers++;
5014 }
5015 break;
5016 case ST_ADM_ACTION_HDOWN:
5017 if (!(sv->track)) {
5018 sv->check.health = 0;
5019 srv_set_stopped(sv, "changed from Web interface");
5020 altered_servers++;
5021 total_servers++;
5022 }
5023 break;
5024 case ST_ADM_ACTION_DAGENT:
5025 if (sv->agent.state & CHK_ST_CONFIGURED) {
5026 sv->agent.state &= ~CHK_ST_ENABLED;
5027 altered_servers++;
5028 total_servers++;
5029 }
5030 break;
5031 case ST_ADM_ACTION_EAGENT:
5032 if (sv->agent.state & CHK_ST_CONFIGURED) {
5033 sv->agent.state |= CHK_ST_ENABLED;
5034 altered_servers++;
5035 total_servers++;
5036 }
5037 break;
5038 case ST_ADM_ACTION_ARUNN:
5039 if (sv->agent.state & CHK_ST_ENABLED) {
5040 sv->agent.health = sv->agent.rise + sv->agent.fall - 1;
5041 srv_set_running(sv, "changed from Web interface");
5042 altered_servers++;
5043 total_servers++;
5044 }
5045 break;
5046 case ST_ADM_ACTION_ADOWN:
5047 if (sv->agent.state & CHK_ST_ENABLED) {
5048 sv->agent.health = 0;
5049 srv_set_stopped(sv, "changed from Web interface");
5050 altered_servers++;
5051 total_servers++;
5052 }
5053 break;
Willy Tarreaued7df902014-05-22 18:04:49 +02005054 case ST_ADM_ACTION_READY:
5055 srv_adm_set_ready(sv);
5056 altered_servers++;
5057 total_servers++;
5058 break;
5059 case ST_ADM_ACTION_DRAIN:
5060 srv_adm_set_drain(sv);
5061 altered_servers++;
5062 total_servers++;
5063 break;
5064 case ST_ADM_ACTION_MAINT:
5065 srv_adm_set_maint(sv);
5066 altered_servers++;
5067 total_servers++;
5068 break;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005069 case ST_ADM_ACTION_SHUTDOWN:
5070 if (px->state != PR_STSTOPPED) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005071 struct stream *sess, *sess_bck;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005072
5073 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
5074 if (sess->srv_conn == sv)
Willy Tarreaue7dff022015-04-03 01:14:29 +02005075 stream_shutdown(sess, SF_ERR_KILLED);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005076
5077 altered_servers++;
5078 total_servers++;
5079 }
5080 break;
5081 }
5082 } else {
5083 /* the server name is unknown or ambiguous (duplicate names) */
5084 total_servers++;
5085 }
5086 }
5087 if (reprocess && px && action) {
5088 /* Now, we know the backend and the action chosen by the user.
5089 * We can safely restart from the first server parameter
5090 * to reprocess them
5091 */
5092 cur_param = st_cur_param;
5093 next_param = st_next_param;
5094 reprocess = 0;
5095 goto reprocess_servers;
5096 }
5097
5098 next_param = cur_param;
5099 }
5100 }
5101
5102 if (total_servers == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005103 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005104 }
5105 else if (altered_servers == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005106 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005107 }
5108 else if (altered_servers == total_servers) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005109 appctx->ctx.stats.st_code = STAT_STATUS_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005110 }
5111 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005112 appctx->ctx.stats.st_code = STAT_STATUS_PART;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005113 }
5114 out:
5115 return 1;
5116}
5117
5118
5119static int stats_send_http_headers(struct stream_interface *si)
5120{
Willy Tarreau87b09662015-04-03 00:22:06 +02005121 struct stream *s = si_strm(si);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005122 struct uri_auth *uri = s->be->uri_auth;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005123 struct appctx *appctx = objt_appctx(si->end);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005124
5125 chunk_printf(&trash,
Willy Tarreau8b8995f2014-04-24 22:51:54 +02005126 "HTTP/1.1 200 OK\r\n"
Willy Tarreau347a35d2013-11-22 17:51:09 +01005127 "Cache-Control: no-cache\r\n"
5128 "Connection: close\r\n"
5129 "Content-Type: %s\r\n",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005130 (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain");
Willy Tarreau347a35d2013-11-22 17:51:09 +01005131
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005132 if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH))
Willy Tarreau347a35d2013-11-22 17:51:09 +01005133 chunk_appendf(&trash, "Refresh: %d\r\n",
5134 uri->refresh);
5135
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005136 /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */
5137
5138 if (appctx->ctx.stats.flags & STAT_CHUNKED)
5139 chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n");
5140 else
5141 chunk_appendf(&trash, "\r\n");
Willy Tarreau347a35d2013-11-22 17:51:09 +01005142
Willy Tarreaueee5b512015-04-03 23:46:31 +02005143 s->txn->status = 200;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005144 s->logs.tv_request = now;
5145
Willy Tarreaubc18da12015-03-13 14:00:47 +01005146 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005147 si_applet_cant_put(si);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005148 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005149 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01005150
5151 return 1;
5152}
5153
5154static int stats_send_http_redirect(struct stream_interface *si)
5155{
5156 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
Willy Tarreau87b09662015-04-03 00:22:06 +02005157 struct stream *s = si_strm(si);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005158 struct uri_auth *uri = s->be->uri_auth;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005159 struct appctx *appctx = objt_appctx(si->end);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005160
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005161 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
Willy Tarreau347a35d2013-11-22 17:51:09 +01005162 scope_txt[0] = 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005163 if (appctx->ctx.stats.scope_len) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01005164 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005165 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 +01005166 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005167 }
5168
5169 /* We don't want to land on the posted stats page because a refresh will
5170 * repost the data. We don't want this to happen on accident so we redirect
5171 * the browse to the stats page with a GET.
5172 */
5173 chunk_printf(&trash,
5174 "HTTP/1.1 303 See Other\r\n"
5175 "Cache-Control: no-cache\r\n"
5176 "Content-Type: text/plain\r\n"
5177 "Connection: close\r\n"
5178 "Location: %s;st=%s%s%s%s\r\n"
5179 "\r\n",
5180 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005181 ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) &&
5182 (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) &&
5183 stat_status_codes[appctx->ctx.stats.st_code]) ?
5184 stat_status_codes[appctx->ctx.stats.st_code] :
Willy Tarreau347a35d2013-11-22 17:51:09 +01005185 stat_status_codes[STAT_STATUS_UNKN],
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005186 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
5187 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreau347a35d2013-11-22 17:51:09 +01005188 scope_txt);
5189
Willy Tarreaueee5b512015-04-03 23:46:31 +02005190 s->txn->status = 303;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005191 s->logs.tv_request = now;
5192
Willy Tarreaubc18da12015-03-13 14:00:47 +01005193 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005194 si_applet_cant_put(si);
Willy Tarreau347a35d2013-11-22 17:51:09 +01005195 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005196 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01005197
5198 return 1;
5199}
5200
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005201/* This I/O handler runs as an applet embedded in a stream interface. It is
5202 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005203 * appctx->st0 contains the operation in progress (dump, done). The handler
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005204 * automatically unregisters itself once transfer is complete.
5205 */
Willy Tarreau00a37f02015-04-13 12:05:19 +02005206static void http_stats_io_handler(struct appctx *appctx)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005207{
Willy Tarreau00a37f02015-04-13 12:05:19 +02005208 struct stream_interface *si = appctx->owner;
Willy Tarreau87b09662015-04-03 00:22:06 +02005209 struct stream *s = si_strm(si);
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005210 struct channel *req = si_oc(si);
5211 struct channel *res = si_ic(si);
Willy Tarreau55058a72012-11-21 08:27:21 +01005212
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005213 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
5214 goto out;
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01005215
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005216 /* check that the output is not closed */
5217 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005218 appctx->st0 = STAT_HTTP_DONE;
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02005219
Willy Tarreau347a35d2013-11-22 17:51:09 +01005220 /* all states are processed in sequence */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005221 if (appctx->st0 == STAT_HTTP_HEAD) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01005222 if (stats_send_http_headers(si)) {
Willy Tarreaueee5b512015-04-03 23:46:31 +02005223 if (s->txn->meth == HTTP_METH_HEAD)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005224 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005225 else
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005226 appctx->st0 = STAT_HTTP_DUMP;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005227 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01005228 }
5229
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005230 if (appctx->st0 == STAT_HTTP_DUMP) {
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005231 unsigned int prev_len = si_ib(si)->i;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005232 unsigned int data_len;
5233 unsigned int last_len;
Willy Tarreaucce36482014-04-24 20:26:41 +02005234 unsigned int last_fwd = 0;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005235
5236 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
5237 /* One difficulty we're facing is that we must prevent
5238 * the input data from being automatically forwarded to
5239 * the output area. For this, we temporarily disable
5240 * forwarding on the channel.
5241 */
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005242 last_fwd = si_ic(si)->to_forward;
5243 si_ic(si)->to_forward = 0;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005244 chunk_printf(&trash, "\r\n000000\r\n");
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005245 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005246 si_applet_cant_put(si);
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005247 si_ic(si)->to_forward = last_fwd;
Willy Tarreau828824a2015-04-19 17:20:03 +02005248 goto out;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005249 }
5250 }
5251
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005252 data_len = si_ib(si)->i;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005253 if (stats_dump_stat_to_buffer(si, s->be->uri_auth))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005254 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005255
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005256 last_len = si_ib(si)->i;
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005257
5258 /* Now we must either adjust or remove the chunk size. This is
5259 * not easy because the chunk size might wrap at the end of the
5260 * buffer, so we pretend we have nothing in the buffer, we write
5261 * the size, then restore the buffer's contents. Note that we can
5262 * only do that because no forwarding is scheduled on the stats
5263 * applet.
5264 */
5265 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005266 si_ic(si)->total -= (last_len - prev_len);
5267 si_ib(si)->i -= (last_len - prev_len);
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005268
5269 if (last_len != data_len) {
5270 chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len));
Willy Tarreaubc18da12015-03-13 14:00:47 +01005271 if (bi_putchk(si_ic(si), &trash) == -1)
Willy Tarreaufe127932015-04-21 19:23:39 +02005272 si_applet_cant_put(si);
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005273
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005274 si_ic(si)->total += (last_len - data_len);
5275 si_ib(si)->i += (last_len - data_len);
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005276 }
5277 /* now re-enable forwarding */
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005278 channel_forward(si_ic(si), last_fwd);
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005279 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005280 }
Cyril Bonté70be45d2010-10-12 00:14:35 +02005281
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005282 if (appctx->st0 == STAT_HTTP_POST) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01005283 if (stats_process_http_post(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005284 appctx->st0 = STAT_HTTP_LAST;
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005285 else if (si_oc(si)->flags & CF_SHUTR)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005286 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005287 }
5288
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005289 if (appctx->st0 == STAT_HTTP_LAST) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01005290 if (stats_send_http_redirect(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005291 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01005292 }
5293
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005294 if (appctx->st0 == STAT_HTTP_DONE) {
5295 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
5296 chunk_printf(&trash, "\r\n0\r\n\r\n");
Willy Tarreaubc18da12015-03-13 14:00:47 +01005297 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005298 si_applet_cant_put(si);
Willy Tarreau828824a2015-04-19 17:20:03 +02005299 goto out;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005300 }
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005301 }
5302 /* eat the whole request */
Willy Tarreau4e4292b2014-11-28 12:18:45 +01005303 bo_skip(si_oc(si), si_ob(si)->o);
Willy Tarreauaf3cf702014-04-22 22:19:53 +02005304 res->flags |= CF_READ_NULL;
5305 si_shutr(si);
5306 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01005307
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005308 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST))
5309 si_shutw(si);
Willy Tarreau91861262007-10-17 17:06:05 +02005310
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005311 if (appctx->st0 == STAT_HTTP_DONE) {
Willy Tarreau96d44912013-11-22 12:25:24 +01005312 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) {
5313 si_shutr(si);
5314 res->flags |= CF_READ_NULL;
5315 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005316 }
Willy Tarreau828824a2015-04-19 17:20:03 +02005317 out:
Willy Tarreaud4da1962015-04-20 01:31:23 +02005318 /* just to make gcc happy */ ;
Willy Tarreau91861262007-10-17 17:06:05 +02005319}
5320
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01005321
Willy Tarreau909d5172012-11-26 03:04:41 +01005322static inline const char *get_conn_ctrl_name(const struct connection *conn)
5323{
Willy Tarreau3c728722014-01-23 13:50:42 +01005324 if (!conn_ctrl_ready(conn))
Willy Tarreau909d5172012-11-26 03:04:41 +01005325 return "NONE";
5326 return conn->ctrl->name;
5327}
5328
5329static inline const char *get_conn_xprt_name(const struct connection *conn)
5330{
5331 static char ptr[17];
5332
Willy Tarreauaad69382014-01-23 14:21:42 +01005333 if (!conn_xprt_ready(conn))
Willy Tarreau909d5172012-11-26 03:04:41 +01005334 return "NONE";
5335
5336 if (conn->xprt == &raw_sock)
5337 return "RAW";
5338
5339#ifdef USE_OPENSSL
5340 if (conn->xprt == &ssl_sock)
5341 return "SSL";
5342#endif
5343 snprintf(ptr, sizeof(ptr), "%p", conn->xprt);
5344 return ptr;
5345}
5346
5347static inline const char *get_conn_data_name(const struct connection *conn)
5348{
5349 static char ptr[17];
5350
5351 if (!conn->data)
5352 return "NONE";
5353
5354 if (conn->data == &sess_conn_cb)
5355 return "SESS";
5356
5357 if (conn->data == &si_conn_cb)
5358 return "STRM";
5359
5360 if (conn->data == &check_conn_cb)
5361 return "CHCK";
5362
5363 snprintf(ptr, sizeof(ptr), "%p", conn->data);
5364 return ptr;
5365}
5366
Willy Tarreau87b09662015-04-03 00:22:06 +02005367/* This function dumps a complete stream state onto the stream interface's
5368 * read buffer. The stream has to be set in sess->target. It returns
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01005369 * 0 if the output buffer is full and it needs to be called again, otherwise
5370 * non-zero. It is designed to be called from stats_dump_sess_to_buffer() below.
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005371 */
Willy Tarreau87b09662015-04-03 00:22:06 +02005372static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct stream *sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005373{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005374 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005375 struct tm tm;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005376 extern const char *monthname[12];
5377 char pn[INET6_ADDRSTRLEN];
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005378 struct connection *conn;
Willy Tarreau284ddbf2013-12-01 20:45:00 +01005379 struct appctx *tmpctx;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005380
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005381 chunk_reset(&trash);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005382
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005383 if (appctx->ctx.sess.section > 0 && appctx->ctx.sess.uid != sess->uniq_id) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005384 /* stream changed, no need to go any further */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005385 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
Willy Tarreaubc18da12015-03-13 14:00:47 +01005386 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005387 si_applet_cant_put(si);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005388 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005389 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005390 appctx->ctx.sess.uid = 0;
5391 appctx->ctx.sess.section = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005392 return 1;
5393 }
5394
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005395 switch (appctx->ctx.sess.section) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005396 case 0: /* main status of the stream */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005397 appctx->ctx.sess.uid = sess->uniq_id;
5398 appctx->ctx.sess.section = 1;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005399 /* fall through */
5400
5401 case 1:
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005402 get_localtime(sess->logs.accept_date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005403 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005404 "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005405 sess,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005406 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
5407 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005408 sess->uniq_id,
Willy Tarreau666f5042015-06-17 19:49:52 +02005409 strm_li(sess) ? strm_li(sess)->proto->name : "?");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005410
Willy Tarreaud0d8da92015-04-04 02:10:38 +02005411 conn = objt_conn(strm_orig(sess));
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005412 switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005413 case AF_INET:
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005414 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005415 chunk_appendf(&trash, " source=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005416 pn, get_host_port(&conn->addr.from));
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005417 break;
5418 case AF_UNIX:
Willy Tarreaud0d8da92015-04-04 02:10:38 +02005419 chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid);
Emeric Brun837ca522010-10-22 16:19:01 +02005420 break;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005421 default:
5422 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005423 chunk_appendf(&trash, "\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005424 break;
5425 }
5426
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005427 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005428 " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n",
Willy Tarreauee28de02010-06-01 09:51:00 +02005429 sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005430
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005431 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07005432 " frontend=%s (id=%u mode=%s), listener=%s (id=%u)",
Willy Tarreaud0d8da92015-04-04 02:10:38 +02005433 strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp",
5434 strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?",
5435 strm_li(sess) ? strm_li(sess)->luid : 0);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005436
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005437 if (conn)
5438 conn_get_to_addr(conn);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005439
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005440 switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) {
Daniel Schultze90690c72012-03-23 10:53:36 -07005441 case AF_INET:
5442 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005443 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005444 pn, get_host_port(&conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07005445 break;
5446 case AF_UNIX:
Willy Tarreaud0d8da92015-04-04 02:10:38 +02005447 chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid);
Daniel Schultze90690c72012-03-23 10:53:36 -07005448 break;
5449 default:
5450 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005451 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07005452 break;
5453 }
5454
Willy Tarreau50943332011-09-02 17:33:05 +02005455 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005456 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07005457 " backend=%s (id=%u mode=%s)",
Willy Tarreau50943332011-09-02 17:33:05 +02005458 sess->be->id,
Daniel Schultze90690c72012-03-23 10:53:36 -07005459 sess->be->uuid, sess->be->mode ? "http" : "tcp");
5460 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005461 chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)");
Daniel Schultze90690c72012-03-23 10:53:36 -07005462
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005463 conn = objt_conn(sess->si[1].end);
5464 if (conn)
5465 conn_get_from_addr(conn);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005466
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005467 switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) {
Daniel Schultze90690c72012-03-23 10:53:36 -07005468 case AF_INET:
5469 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005470 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005471 pn, get_host_port(&conn->addr.from));
Daniel Schultze90690c72012-03-23 10:53:36 -07005472 break;
5473 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005474 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07005475 break;
5476 default:
5477 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005478 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07005479 break;
5480 }
5481
5482 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005483 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07005484 " server=%s (id=%u)",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01005485 objt_server(sess->target) ? objt_server(sess->target)->id : "<none>",
5486 objt_server(sess->target) ? objt_server(sess->target)->puid : 0);
Willy Tarreau50943332011-09-02 17:33:05 +02005487 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005488 chunk_appendf(&trash, " server=<NONE> (id=-1)");
Daniel Schultze90690c72012-03-23 10:53:36 -07005489
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005490 if (conn)
5491 conn_get_to_addr(conn);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005492
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005493 switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) {
Daniel Schultze90690c72012-03-23 10:53:36 -07005494 case AF_INET:
5495 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005496 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005497 pn, get_host_port(&conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07005498 break;
5499 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005500 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07005501 break;
5502 default:
5503 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005504 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07005505 break;
5506 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005507
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005508 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005509 " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005510 sess->task,
5511 sess->task->state,
5512 sess->task->nice, sess->task->calls,
5513 sess->task->expire ?
5514 tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" :
5515 human_time(TICKS_TO_MS(sess->task->expire - now_ms),
5516 TICKS_TO_MS(1000)) : "<NEVER>",
5517 task_in_rq(sess->task) ? ", running" : "");
5518
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005519 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005520 " age=%s)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005521 human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1));
5522
Willy Tarreaueee5b512015-04-03 23:46:31 +02005523 if (sess->txn)
5524 chunk_appendf(&trash,
Willy Tarreau98410192014-11-26 18:05:38 +01005525 " 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 +02005526 sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status,
5527 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 +01005528
5529 chunk_appendf(&trash,
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02005530 " si[0]=%p (state=%s flags=0x%02x endp0=%s:%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005531 &sess->si[0],
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005532 si_state_str(sess->si[0].state),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005533 sess->si[0].flags,
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005534 obj_type_name(sess->si[0].end),
5535 obj_base_ptr(sess->si[0].end),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005536 sess->si[0].exp ?
5537 tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" :
5538 human_time(TICKS_TO_MS(sess->si[0].exp - now_ms),
5539 TICKS_TO_MS(1000)) : "<NEVER>",
5540 sess->si[0].err_type);
5541
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005542 chunk_appendf(&trash,
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02005543 " si[1]=%p (state=%s flags=0x%02x endp1=%s:%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005544 &sess->si[1],
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01005545 si_state_str(sess->si[1].state),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005546 sess->si[1].flags,
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005547 obj_type_name(sess->si[1].end),
5548 obj_base_ptr(sess->si[1].end),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005549 sess->si[1].exp ?
5550 tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" :
5551 human_time(TICKS_TO_MS(sess->si[1].exp - now_ms),
5552 TICKS_TO_MS(1000)) : "<NEVER>",
5553 sess->si[1].err_type);
5554
Willy Tarreau284ddbf2013-12-01 20:45:00 +01005555 if ((conn = objt_conn(sess->si[0].end)) != NULL) {
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005556 chunk_appendf(&trash,
5557 " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005558 conn,
5559 get_conn_ctrl_name(conn),
5560 get_conn_xprt_name(conn),
5561 get_conn_data_name(conn),
5562 obj_type_name(conn->target),
5563 obj_base_ptr(conn->target));
Willy Tarreau909d5172012-11-26 03:04:41 +01005564
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005565 chunk_appendf(&trash,
Willy Tarreau16f649c2014-01-25 19:10:48 +01005566 " flags=0x%08x fd=%d fd.state=%02x fd.cache=%d updt=%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005567 conn->flags,
5568 conn->t.sock.fd,
Willy Tarreau69a41fa2014-01-20 11:02:59 +01005569 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0,
Willy Tarreau15a4dec2014-01-20 11:09:39 +01005570 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005571 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005572 }
Willy Tarreau284ddbf2013-12-01 20:45:00 +01005573 else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) {
5574 chunk_appendf(&trash,
5575 " app0=%p st0=%d st1=%d st2=%d applet=%s\n",
5576 tmpctx,
5577 tmpctx->st0,
5578 tmpctx->st1,
5579 tmpctx->st2,
5580 tmpctx->applet->name);
5581 }
Willy Tarreaubc174aa2012-11-19 16:10:32 +01005582
Willy Tarreau284ddbf2013-12-01 20:45:00 +01005583 if ((conn = objt_conn(sess->si[1].end)) != NULL) {
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005584 chunk_appendf(&trash,
5585 " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005586 conn,
5587 get_conn_ctrl_name(conn),
5588 get_conn_xprt_name(conn),
5589 get_conn_data_name(conn),
5590 obj_type_name(conn->target),
5591 obj_base_ptr(conn->target));
Willy Tarreau909d5172012-11-26 03:04:41 +01005592
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005593 chunk_appendf(&trash,
5594 " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005595 conn->flags,
5596 conn->t.sock.fd,
Willy Tarreau69a41fa2014-01-20 11:02:59 +01005597 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0,
Willy Tarreau15a4dec2014-01-20 11:09:39 +01005598 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005599 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02005600 }
Willy Tarreau284ddbf2013-12-01 20:45:00 +01005601 else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) {
5602 chunk_appendf(&trash,
5603 " app1=%p st0=%d st1=%d st2=%d applet=%s\n",
5604 tmpctx,
5605 tmpctx->st0,
5606 tmpctx->st1,
5607 tmpctx->st2,
5608 tmpctx->applet->name);
5609 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005610
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005611 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01005612 " req=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005613 " an_exp=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005614 &sess->req,
5615 sess->req.flags, sess->req.analysers,
5616 sess->req.pipe ? sess->req.pipe->data : 0,
5617 sess->req.to_forward, sess->req.total,
5618 sess->req.analyse_exp ?
5619 human_time(TICKS_TO_MS(sess->req.analyse_exp - 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 " rex=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005624 sess->req.rex ?
5625 human_time(TICKS_TO_MS(sess->req.rex - now_ms),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005626 TICKS_TO_MS(1000)) : "<NEVER>");
5627
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005628 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005629 " wex=%s\n"
Willy Tarreau909d5172012-11-26 03:04:41 +01005630 " buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d\n",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005631 sess->req.wex ?
5632 human_time(TICKS_TO_MS(sess->req.wex - now_ms),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005633 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005634 sess->req.buf,
5635 sess->req.buf->data, sess->req.buf->o,
5636 (int)(sess->req.buf->p - sess->req.buf->data),
Willy Tarreaueee5b512015-04-03 23:46:31 +02005637 sess->txn ? sess->txn->req.next : 0, sess->req.buf->i,
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005638 sess->req.buf->size);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005639
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005640 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01005641 " res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005642 " an_exp=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005643 &sess->res,
5644 sess->res.flags, sess->res.analysers,
5645 sess->res.pipe ? sess->res.pipe->data : 0,
5646 sess->res.to_forward, sess->res.total,
5647 sess->res.analyse_exp ?
5648 human_time(TICKS_TO_MS(sess->res.analyse_exp - 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 " rex=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005653 sess->res.rex ?
5654 human_time(TICKS_TO_MS(sess->res.rex - now_ms),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005655 TICKS_TO_MS(1000)) : "<NEVER>");
5656
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005657 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005658 " wex=%s\n"
Willy Tarreau909d5172012-11-26 03:04:41 +01005659 " buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d\n",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005660 sess->res.wex ?
5661 human_time(TICKS_TO_MS(sess->res.wex - now_ms),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005662 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005663 sess->res.buf,
5664 sess->res.buf->data, sess->res.buf->o,
5665 (int)(sess->res.buf->p - sess->res.buf->data),
Willy Tarreaueee5b512015-04-03 23:46:31 +02005666 sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i,
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01005667 sess->res.buf->size);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005668
Willy Tarreaubc18da12015-03-13 14:00:47 +01005669 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005670 si_applet_cant_put(si);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005671 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005672 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005673
5674 /* use other states to dump the contents */
5675 }
5676 /* end of dump */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005677 appctx->ctx.sess.uid = 0;
5678 appctx->ctx.sess.section = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005679 return 1;
5680}
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005681
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +02005682#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
5683static int stats_tlskeys_list(struct stream_interface *si) {
5684 struct appctx *appctx = __objt_appctx(si->end);
5685
5686 switch (appctx->st2) {
5687 case STAT_ST_INIT:
5688 /* Display the column headers. If the message cannot be sent,
5689 * quit the fucntion with returning 0. The function is called
5690 * later and restart at the state "STAT_ST_INIT".
5691 */
5692 chunk_reset(&trash);
5693 chunk_appendf(&trash, "# id (file)\n");
5694 if (bi_putchk(si_ic(si), &trash) == -1) {
5695 si_applet_cant_put(si);
5696 return 0;
5697 }
5698
5699 /* Now, we start the browsing of the references lists.
5700 * Note that the following call to LIST_ELEM return bad pointer. The only
5701 * avalaible field of this pointer is <list>. It is used with the function
5702 * tlskeys_list_get_next() for retruning the first avalaible entry
5703 */
5704 appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list);
5705 appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference);
5706
5707 appctx->st2 = STAT_ST_LIST;
5708 /* fall through */
5709
5710 case STAT_ST_LIST:
5711 while (appctx->ctx.tlskeys.ref) {
5712 chunk_reset(&trash);
5713
5714 chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id,
5715 appctx->ctx.tlskeys.ref->filename);
5716
5717 if (bi_putchk(si_ic(si), &trash) == -1) {
5718 /* let's try again later from this stream. We add ourselves into
5719 * this stream's users so that it can remove us upon termination.
5720 */
5721 si_applet_cant_put(si);
5722 return 0;
5723 }
5724
5725 /* get next list entry and check the end of the list */
5726 appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference);
5727 }
5728
5729 appctx->st2 = STAT_ST_FIN;
5730 /* fall through */
5731
5732 default:
5733 appctx->st2 = STAT_ST_FIN;
5734 return 1;
5735 }
5736 return 0;
5737}
5738#endif
5739
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005740static int stats_pats_list(struct stream_interface *si)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005741{
5742 struct appctx *appctx = __objt_appctx(si->end);
5743
5744 switch (appctx->st2) {
5745 case STAT_ST_INIT:
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01005746 /* Display the column headers. If the message cannot be sent,
5747 * quit the fucntion with returning 0. The function is called
5748 * later and restart at the state "STAT_ST_INIT".
5749 */
5750 chunk_reset(&trash);
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01005751 chunk_appendf(&trash, "# id (file) description\n");
Willy Tarreaubc18da12015-03-13 14:00:47 +01005752 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02005753 si_applet_cant_put(si);
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01005754 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01005755 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005756
5757 /* Now, we start the browsing of the references lists.
5758 * Note that the following call to LIST_ELEM return bad pointer. The only
5759 * avalaible field of this pointer is <list>. It is used with the function
5760 * pat_list_get_next() for retruning the first avalaible entry
5761 */
5762 appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list);
5763 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
5764 appctx->ctx.map.display_flags);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005765 appctx->st2 = STAT_ST_LIST;
5766 /* fall through */
5767
5768 case STAT_ST_LIST:
5769 while (appctx->ctx.map.ref) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005770 chunk_reset(&trash);
5771
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005772 /* Build messages. If the reference is used by another category than
5773 * the listed categorie, display the information in the massage.
5774 */
Thierry FOURNIERf7e04e92014-03-20 11:45:47 +01005775 chunk_appendf(&trash, "%d (%s) %s\n", appctx->ctx.map.ref->unique_id,
Thierry FOURNIER0d6ba512014-02-11 03:31:34 +01005776 appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "",
5777 appctx->ctx.map.ref->display);
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01005778
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005779 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005780 /* let's try again later from this stream. We add ourselves into
5781 * this stream's users so that it can remove us upon termination.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005782 */
Willy Tarreaufe127932015-04-21 19:23:39 +02005783 si_applet_cant_put(si);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005784 return 0;
5785 }
5786
5787 /* get next list entry and check the end of the list */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005788 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
5789 appctx->ctx.map.display_flags);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005790 }
5791
5792 appctx->st2 = STAT_ST_FIN;
5793 /* fall through */
5794
5795 default:
5796 appctx->st2 = STAT_ST_FIN;
5797 return 1;
5798 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005799 return 0;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005800}
5801
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005802static int stats_map_lookup(struct stream_interface *si)
5803{
5804 struct appctx *appctx = __objt_appctx(si->end);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005805 struct sample sample;
5806 struct pattern *pat;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005807 int match_method;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005808
5809 switch (appctx->st2) {
5810 case STAT_ST_INIT:
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005811 /* Init to the first entry. The list cannot be change */
Thierry FOURNIERc5959fd2014-01-20 14:29:33 +01005812 appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005813 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005814 appctx->st2 = STAT_ST_LIST;
5815 /* fall through */
5816
5817 case STAT_ST_LIST:
5818 /* for each lookup type */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005819 while (appctx->ctx.map.expr) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005820 /* initialise chunk to build new message */
5821 chunk_reset(&trash);
5822
5823 /* execute pattern matching */
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02005824 sample.data.type = SMP_T_STR;
Thierry FOURNIER7654c9f2013-12-17 00:20:33 +01005825 sample.flags |= SMP_F_CONST;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02005826 sample.data.u.str.len = appctx->ctx.map.chunk.len;
5827 sample.data.u.str.str = appctx->ctx.map.chunk.str;
Thierry FOURNIER5d344082014-01-27 14:19:53 +01005828 if (appctx->ctx.map.expr->pat_head->match &&
5829 sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type))
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005830 pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1);
5831 else
5832 pat = NULL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005833
5834 /* build return message: set type of match */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005835 for (match_method=0; match_method<PAT_MATCH_NUM; match_method++)
5836 if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method])
5837 break;
5838 if (match_method >= PAT_MATCH_NUM)
5839 chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match);
5840 else
5841 chunk_appendf(&trash, "type=%s", pat_match_names[match_method]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005842
Thierry FOURNIERe47e4e22014-04-28 11:18:57 +02005843 /* case sensitive */
5844 if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE)
5845 chunk_appendf(&trash, ", case=insensitive");
5846 else
5847 chunk_appendf(&trash, ", case=sensitive");
5848
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005849 /* Display no match, and set default value */
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +01005850 if (!pat) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005851 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
5852 chunk_appendf(&trash, ", found=no");
5853 else
5854 chunk_appendf(&trash, ", match=no");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005855 }
5856
5857 /* Display match and match info */
5858 else {
5859 /* display match */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005860 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
5861 chunk_appendf(&trash, ", found=yes");
5862 else
5863 chunk_appendf(&trash, ", match=yes");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005864
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +01005865 /* display index mode */
Thierry FOURNIERe47e4e22014-04-28 11:18:57 +02005866 if (pat->sflags & PAT_SF_TREE)
Thierry FOURNIERb9903842014-03-11 18:48:17 +01005867 chunk_appendf(&trash, ", idx=tree");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005868 else
Thierry FOURNIERb9903842014-03-11 18:48:17 +01005869 chunk_appendf(&trash, ", idx=list");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005870
Thierry FOURNIER86db66a2014-03-11 18:37:58 +01005871 /* display pattern */
5872 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
5873 if (pat->ref && pat->ref->pattern)
5874 chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern);
5875 else
5876 chunk_appendf(&trash, ", key=unknown");
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005877 }
5878 else {
Thierry FOURNIER86db66a2014-03-11 18:37:58 +01005879 if (pat->ref && pat->ref->pattern)
5880 chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern);
5881 else
5882 chunk_appendf(&trash, ", pattern=unknown");
5883 }
5884
5885 /* display return value */
5886 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
Thierry FOURNIER503bb092015-08-19 08:35:43 +02005887 if (pat->data && pat->ref && pat->ref->sample)
Thierry FOURNIER03d0e452015-07-23 18:33:41 +02005888 chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample,
Thierry FOURNIER7d4335c2015-08-19 09:05:25 +02005889 smp_to_type[pat->data->type]);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005890 else
Thierry FOURNIER86db66a2014-03-11 18:37:58 +01005891 chunk_appendf(&trash, ", value=none");
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005892 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005893 }
5894
Thierry FOURNIERb9903842014-03-11 18:48:17 +01005895 chunk_appendf(&trash, "\n");
5896
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005897 /* display response */
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005898 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005899 /* let's try again later from this stream. We add ourselves into
5900 * this stream's users so that it can remove us upon termination.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005901 */
Willy Tarreaufe127932015-04-21 19:23:39 +02005902 si_applet_cant_put(si);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005903 return 0;
5904 }
5905
5906 /* get next entry */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005907 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr,
5908 &appctx->ctx.map.ref->pat);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005909 }
5910
5911 appctx->st2 = STAT_ST_FIN;
5912 /* fall through */
5913
5914 default:
5915 appctx->st2 = STAT_ST_FIN;
5916 free(appctx->ctx.map.chunk.str);
5917 return 1;
5918 }
5919}
5920
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005921static int stats_pat_list(struct stream_interface *si)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005922{
5923 struct appctx *appctx = __objt_appctx(si->end);
5924
5925 switch (appctx->st2) {
5926
5927 case STAT_ST_INIT:
5928 /* Init to the first entry. The list cannot be change */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005929 appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head,
5930 struct pat_ref_elt *, list);
5931 if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head)
5932 appctx->ctx.map.elt = NULL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005933 appctx->st2 = STAT_ST_LIST;
5934 /* fall through */
5935
5936 case STAT_ST_LIST:
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005937 while (appctx->ctx.map.elt) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005938 chunk_reset(&trash);
5939
5940 /* build messages */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005941 if (appctx->ctx.map.elt->sample)
Thierry FOURNIER9356c682014-01-28 15:55:37 +01005942 chunk_appendf(&trash, "%p %s %s\n",
5943 appctx->ctx.map.elt, appctx->ctx.map.elt->pattern,
5944 appctx->ctx.map.elt->sample);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005945 else
Thierry FOURNIER9356c682014-01-28 15:55:37 +01005946 chunk_appendf(&trash, "%p %s\n",
5947 appctx->ctx.map.elt, appctx->ctx.map.elt->pattern);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005948
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005949 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau87b09662015-04-03 00:22:06 +02005950 /* let's try again later from this stream. We add ourselves into
5951 * this stream's users so that it can remove us upon termination.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005952 */
Willy Tarreaufe127932015-04-21 19:23:39 +02005953 si_applet_cant_put(si);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005954 return 0;
5955 }
5956
5957 /* get next list entry and check the end of the list */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005958 appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list,
5959 struct pat_ref_elt *, list);
5960 if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005961 break;
5962 }
5963
5964 appctx->st2 = STAT_ST_FIN;
5965 /* fall through */
5966
5967 default:
5968 appctx->st2 = STAT_ST_FIN;
5969 return 1;
5970 }
5971}
5972
Willy Tarreau87b09662015-04-03 00:22:06 +02005973/* This function dumps all streams' states onto the stream interface's
Willy Tarreau306f8302013-07-08 15:53:06 +02005974 * read buffer. It returns 0 if the output buffer is full and it needs
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01005975 * to be called again, otherwise non-zero. It is designed to be called
5976 * from stats_dump_sess_to_buffer() below.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005977 */
Simon Horman9bd2c732011-06-15 15:18:44 +09005978static int stats_dump_sess_to_buffer(struct stream_interface *si)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005979{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005980 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005981 struct connection *conn;
5982
Willy Tarreau2bb4a962014-11-28 11:11:05 +01005983 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005984 /* If we're forced to shut down, we might have to remove our
Willy Tarreau87b09662015-04-03 00:22:06 +02005985 * reference to the last stream being dumped.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005986 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005987 if (appctx->st2 == STAT_ST_LIST) {
5988 if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) {
5989 LIST_DEL(&appctx->ctx.sess.bref.users);
5990 LIST_INIT(&appctx->ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01005991 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005992 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02005993 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005994 }
5995
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005996 chunk_reset(&trash);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005997
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005998 switch (appctx->st2) {
Willy Tarreau295a8372011-03-10 11:25:07 +01005999 case STAT_ST_INIT:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006000 /* the function had not been called yet, let's prepare the
Willy Tarreau87b09662015-04-03 00:22:06 +02006001 * buffer for a response. We initialize the current stream
Willy Tarreaufd3828e2009-02-22 15:17:24 +01006002 * pointer to the first in the global list. When a target
Willy Tarreau87b09662015-04-03 00:22:06 +02006003 * stream is being destroyed, it is responsible for updating
Willy Tarreaufd3828e2009-02-22 15:17:24 +01006004 * this pointer. We know we have reached the end when this
Willy Tarreau87b09662015-04-03 00:22:06 +02006005 * pointer points back to the head of the streams list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006006 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006007 LIST_INIT(&appctx->ctx.sess.bref.users);
Willy Tarreau87b09662015-04-03 00:22:06 +02006008 appctx->ctx.sess.bref.ref = streams.n;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006009 appctx->st2 = STAT_ST_LIST;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006010 /* fall through */
6011
Willy Tarreau295a8372011-03-10 11:25:07 +01006012 case STAT_ST_LIST:
Willy Tarreau87b09662015-04-03 00:22:06 +02006013 /* first, let's detach the back-ref from a possible previous stream */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006014 if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) {
6015 LIST_DEL(&appctx->ctx.sess.bref.users);
6016 LIST_INIT(&appctx->ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01006017 }
6018
6019 /* and start from where we stopped */
Willy Tarreau87b09662015-04-03 00:22:06 +02006020 while (appctx->ctx.sess.bref.ref != &streams) {
Cyril Bontéacd7d632010-11-01 19:26:02 +01006021 char pn[INET6_ADDRSTRLEN];
Willy Tarreau87b09662015-04-03 00:22:06 +02006022 struct stream *curr_sess;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006023
Willy Tarreau87b09662015-04-03 00:22:06 +02006024 curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006025
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006026 if (appctx->ctx.sess.target) {
6027 if (appctx->ctx.sess.target != (void *)-1 && appctx->ctx.sess.target != curr_sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006028 goto next_sess;
6029
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006030 LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006031 /* call the proper dump() function and return if we're missing space */
Willy Tarreau76153662012-11-26 01:16:39 +01006032 if (!stats_dump_full_sess_to_buffer(si, curr_sess))
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006033 return 0;
6034
Willy Tarreau87b09662015-04-03 00:22:06 +02006035 /* stream dump complete */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006036 LIST_DEL(&appctx->ctx.sess.bref.users);
6037 LIST_INIT(&appctx->ctx.sess.bref.users);
6038 if (appctx->ctx.sess.target != (void *)-1) {
6039 appctx->ctx.sess.target = NULL;
Willy Tarreau76153662012-11-26 01:16:39 +01006040 break;
6041 }
6042 else
6043 goto next_sess;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006044 }
6045
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006046 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006047 "%p: proto=%s",
6048 curr_sess,
Willy Tarreauf1e02122015-09-23 12:16:43 +02006049 strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006050
Willy Tarreaud0d8da92015-04-04 02:10:38 +02006051 conn = objt_conn(strm_orig(curr_sess));
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006052 switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02006053 case AF_INET:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006054 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006055 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006056 " src=%s:%d fe=%s be=%s srv=%s",
6057 pn,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006058 get_host_port(&conn->addr.from),
Willy Tarreaud0d8da92015-04-04 02:10:38 +02006059 strm_fe(curr_sess)->id,
Willy Tarreau50943332011-09-02 17:33:05 +02006060 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01006061 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006062 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006063 break;
6064 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006065 chunk_appendf(&trash,
Emeric Brun837ca522010-10-22 16:19:01 +02006066 " src=unix:%d fe=%s be=%s srv=%s",
Willy Tarreaud0d8da92015-04-04 02:10:38 +02006067 strm_li(curr_sess)->luid,
6068 strm_fe(curr_sess)->id,
Willy Tarreau50943332011-09-02 17:33:05 +02006069 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01006070 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Emeric Brun837ca522010-10-22 16:19:01 +02006071 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006072 break;
6073 }
6074
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006075 chunk_appendf(&trash,
Willy Tarreau65671ab2009-10-04 14:24:59 +02006076 " ts=%02x age=%s calls=%d",
6077 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01006078 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
6079 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006080
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006081 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01006082 " rq[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006083 curr_sess->req.flags,
6084 curr_sess->req.buf->i,
6085 curr_sess->req.analysers,
6086 curr_sess->req.rex ?
6087 human_time(TICKS_TO_MS(curr_sess->req.rex - 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 ",wx=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006092 curr_sess->req.wex ?
6093 human_time(TICKS_TO_MS(curr_sess->req.wex - 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 Tarreauc6dcad62009-03-29 00:18:14 +01006097 ",ax=%s]",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006098 curr_sess->req.analyse_exp ?
6099 human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms),
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006100 TICKS_TO_MS(1000)) : "");
6101
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006102 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01006103 " rp[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006104 curr_sess->res.flags,
6105 curr_sess->res.buf->i,
6106 curr_sess->res.analysers,
6107 curr_sess->res.rex ?
6108 human_time(TICKS_TO_MS(curr_sess->res.rex - 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 ",wx=%s",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006113 curr_sess->res.wex ?
6114 human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms),
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006115 TICKS_TO_MS(1000)) : "");
6116
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006117 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006118 ",ax=%s]",
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01006119 curr_sess->res.analyse_exp ?
6120 human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms),
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006121 TICKS_TO_MS(1000)) : "");
6122
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006123 conn = objt_conn(curr_sess->si[0].end);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006124 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006125 " s0=[%d,%1xh,fd=%d,ex=%s]",
6126 curr_sess->si[0].state,
6127 curr_sess->si[0].flags,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006128 conn ? conn->t.sock.fd : -1,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006129 curr_sess->si[0].exp ?
6130 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
6131 TICKS_TO_MS(1000)) : "");
6132
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006133 conn = objt_conn(curr_sess->si[1].end);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006134 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006135 " s1=[%d,%1xh,fd=%d,ex=%s]",
6136 curr_sess->si[1].state,
6137 curr_sess->si[1].flags,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02006138 conn ? conn->t.sock.fd : -1,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006139 curr_sess->si[1].exp ?
6140 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
6141 TICKS_TO_MS(1000)) : "");
6142
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006143 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006144 " exp=%s",
6145 curr_sess->task->expire ?
6146 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
6147 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01006148 if (task_in_rq(curr_sess->task))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006149 chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01006150
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006151 chunk_appendf(&trash, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006152
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006153 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau87b09662015-04-03 00:22:06 +02006154 /* let's try again later from this stream. We add ourselves into
6155 * this stream's users so that it can remove us upon termination.
Willy Tarreaufd3828e2009-02-22 15:17:24 +01006156 */
Willy Tarreaufe127932015-04-21 19:23:39 +02006157 si_applet_cant_put(si);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006158 LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02006159 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006160 }
6161
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006162 next_sess:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006163 appctx->ctx.sess.bref.ref = curr_sess->list.n;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006164 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006165
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006166 if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) {
Willy Tarreau87b09662015-04-03 00:22:06 +02006167 /* specified stream not found */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006168 if (appctx->ctx.sess.section > 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006169 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006170 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006171 chunk_appendf(&trash, "Session not found.\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006172
Willy Tarreaubc18da12015-03-13 14:00:47 +01006173 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02006174 si_applet_cant_put(si);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006175 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01006176 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006177
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006178 appctx->ctx.sess.target = NULL;
6179 appctx->ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01006180 return 1;
6181 }
6182
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006183 appctx->st2 = STAT_ST_FIN;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006184 /* fall through */
6185
6186 default:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006187 appctx->st2 = STAT_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02006188 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006189 }
Emeric Brun1e029aa2010-09-23 18:12:53 +02006190}
6191
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006192/* This is called when the stream interface is closed. For instance, upon an
6193 * external abort, we won't call the i/o handler anymore so we may need to
Willy Tarreau87b09662015-04-03 00:22:06 +02006194 * remove back references to the stream currently being dumped.
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006195 */
Willy Tarreau00a37f02015-04-13 12:05:19 +02006196static void cli_release_handler(struct appctx *appctx)
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006197{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006198 if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) {
6199 if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users))
6200 LIST_DEL(&appctx->ctx.sess.bref.users);
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006201 }
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01006202 else if (appctx->st0 == STAT_CLI_PRINT_FREE) {
6203 free(appctx->ctx.cli.err);
Willy Tarreau6457d0f2015-10-07 20:00:24 +02006204 appctx->ctx.cli.err = NULL;
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01006205 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01006206 else if (appctx->st0 == STAT_CLI_O_MLOOK) {
6207 free(appctx->ctx.map.chunk.str);
Willy Tarreau6457d0f2015-10-07 20:00:24 +02006208 appctx->ctx.map.chunk.str = NULL;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01006209 }
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006210}
6211
Willy Tarreau20e99322013-04-13 09:22:25 +02006212/* This function is used to either dump tables states (when action is set
6213 * to STAT_CLI_O_TAB) or clear tables (when action is STAT_CLI_O_CLR).
Willy Tarreau20e99322013-04-13 09:22:25 +02006214 * It returns 0 if the output buffer is full and it needs to be called
6215 * again, otherwise non-zero.
Willy Tarreau69f58c82010-07-12 17:55:33 +02006216 */
Willy Tarreau20e99322013-04-13 09:22:25 +02006217static int stats_table_request(struct stream_interface *si, int action)
Willy Tarreau69f58c82010-07-12 17:55:33 +02006218{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006219 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau87b09662015-04-03 00:22:06 +02006220 struct stream *s = si_strm(si);
Willy Tarreau69f58c82010-07-12 17:55:33 +02006221 struct ebmb_node *eb;
6222 int dt;
Willy Tarreau44455022012-12-05 23:01:12 +01006223 int skip_entry;
Willy Tarreau20e99322013-04-13 09:22:25 +02006224 int show = action == STAT_CLI_O_TAB;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006225
6226 /*
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006227 * We have 3 possible states in appctx->st2 :
Willy Tarreau295a8372011-03-10 11:25:07 +01006228 * - STAT_ST_INIT : the first call
6229 * - STAT_ST_INFO : the proxy pointer points to the next table to
Willy Tarreau69f58c82010-07-12 17:55:33 +02006230 * dump, the entry pointer is NULL ;
Willy Tarreau295a8372011-03-10 11:25:07 +01006231 * - STAT_ST_LIST : the proxy pointer points to the current table
Willy Tarreau69f58c82010-07-12 17:55:33 +02006232 * and the entry pointer points to the next entry to be dumped,
6233 * and the refcount on the next entry is held ;
Willy Tarreau295a8372011-03-10 11:25:07 +01006234 * - STAT_ST_END : nothing left to dump, the buffer may contain some
Willy Tarreau69f58c82010-07-12 17:55:33 +02006235 * data though.
6236 */
6237
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006238 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02006239 /* in case of abort, remove any refcount we might have set on an entry */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006240 if (appctx->st2 == STAT_ST_LIST) {
6241 appctx->ctx.table.entry->ref_cnt--;
6242 stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry);
Willy Tarreauf6efda12010-08-03 20:34:06 +02006243 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02006244 return 1;
6245 }
6246
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006247 chunk_reset(&trash);
Willy Tarreau69f58c82010-07-12 17:55:33 +02006248
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006249 while (appctx->st2 != STAT_ST_FIN) {
6250 switch (appctx->st2) {
Willy Tarreau295a8372011-03-10 11:25:07 +01006251 case STAT_ST_INIT:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006252 appctx->ctx.table.proxy = appctx->ctx.table.target;
6253 if (!appctx->ctx.table.proxy)
6254 appctx->ctx.table.proxy = proxy;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006255
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006256 appctx->ctx.table.entry = NULL;
6257 appctx->st2 = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006258 break;
6259
Willy Tarreau295a8372011-03-10 11:25:07 +01006260 case STAT_ST_INFO:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006261 if (!appctx->ctx.table.proxy ||
6262 (appctx->ctx.table.target &&
6263 appctx->ctx.table.proxy != appctx->ctx.table.target)) {
6264 appctx->st2 = STAT_ST_END;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006265 break;
6266 }
6267
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006268 if (appctx->ctx.table.proxy->table.size) {
6269 if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy,
6270 appctx->ctx.table.target))
Willy Tarreau69f58c82010-07-12 17:55:33 +02006271 return 0;
6272
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006273 if (appctx->ctx.table.target &&
Willy Tarreaud0d8da92015-04-04 02:10:38 +02006274 strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02006275 /* dump entries only if table explicitly requested */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006276 eb = ebmb_first(&appctx->ctx.table.proxy->table.keys);
Willy Tarreau69f58c82010-07-12 17:55:33 +02006277 if (eb) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006278 appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key);
6279 appctx->ctx.table.entry->ref_cnt++;
6280 appctx->st2 = STAT_ST_LIST;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006281 break;
6282 }
6283 }
6284 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006285 appctx->ctx.table.proxy = appctx->ctx.table.proxy->next;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006286 break;
6287
Willy Tarreau295a8372011-03-10 11:25:07 +01006288 case STAT_ST_LIST:
Willy Tarreau44455022012-12-05 23:01:12 +01006289 skip_entry = 0;
Simon Hormanc88b8872011-06-15 15:18:49 +09006290
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006291 if (appctx->ctx.table.data_type >= 0) {
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02006292 /* we're filtering on some data contents */
6293 void *ptr;
6294 long long data;
6295
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006296 dt = appctx->ctx.table.data_type;
6297 ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table,
6298 appctx->ctx.table.entry,
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02006299 dt);
6300
6301 data = 0;
6302 switch (stktable_data_types[dt].std_type) {
6303 case STD_T_SINT:
6304 data = stktable_data_cast(ptr, std_t_sint);
6305 break;
6306 case STD_T_UINT:
6307 data = stktable_data_cast(ptr, std_t_uint);
6308 break;
6309 case STD_T_ULL:
6310 data = stktable_data_cast(ptr, std_t_ull);
6311 break;
6312 case STD_T_FRQP:
6313 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006314 appctx->ctx.table.proxy->table.data_arg[dt].u);
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02006315 break;
6316 }
6317
6318 /* skip the entry if the data does not match the test and the value */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006319 if ((data < appctx->ctx.table.value &&
6320 (appctx->ctx.table.data_op == STD_OP_EQ ||
6321 appctx->ctx.table.data_op == STD_OP_GT ||
6322 appctx->ctx.table.data_op == STD_OP_GE)) ||
6323 (data == appctx->ctx.table.value &&
6324 (appctx->ctx.table.data_op == STD_OP_NE ||
6325 appctx->ctx.table.data_op == STD_OP_GT ||
6326 appctx->ctx.table.data_op == STD_OP_LT)) ||
6327 (data > appctx->ctx.table.value &&
6328 (appctx->ctx.table.data_op == STD_OP_EQ ||
6329 appctx->ctx.table.data_op == STD_OP_LT ||
6330 appctx->ctx.table.data_op == STD_OP_LE)))
Willy Tarreau44455022012-12-05 23:01:12 +01006331 skip_entry = 1;
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02006332 }
6333
Simon Hormanc88b8872011-06-15 15:18:49 +09006334 if (show && !skip_entry &&
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006335 !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy,
6336 appctx->ctx.table.entry))
Simon Hormand9366582011-06-15 15:18:45 +09006337 return 0;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006338
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006339 appctx->ctx.table.entry->ref_cnt--;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006340
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006341 eb = ebmb_next(&appctx->ctx.table.entry->key);
Willy Tarreau69f58c82010-07-12 17:55:33 +02006342 if (eb) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006343 struct stksess *old = appctx->ctx.table.entry;
6344 appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key);
Willy Tarreau8fa52f42012-01-09 11:50:03 +01006345 if (show)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006346 stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old);
6347 else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt)
6348 stksess_kill(&appctx->ctx.table.proxy->table, old);
6349 appctx->ctx.table.entry->ref_cnt++;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006350 break;
6351 }
6352
Simon Hormanc88b8872011-06-15 15:18:49 +09006353
6354 if (show)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006355 stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry);
6356 else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt)
6357 stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry);
Simon Hormanc88b8872011-06-15 15:18:49 +09006358
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006359 appctx->ctx.table.proxy = appctx->ctx.table.proxy->next;
6360 appctx->st2 = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006361 break;
6362
Willy Tarreau295a8372011-03-10 11:25:07 +01006363 case STAT_ST_END:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006364 appctx->st2 = STAT_ST_FIN;
Willy Tarreau69f58c82010-07-12 17:55:33 +02006365 break;
6366 }
6367 }
6368 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006369}
6370
Willy Tarreaud426a182010-03-05 14:58:26 +01006371/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
Willy Tarreau74808cb2009-03-04 15:53:18 +01006372 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
6373 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
6374 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
6375 * lines are respected within the limit of 70 output chars. Lines that are
6376 * continuation of a previous truncated line begin with "+" instead of " "
6377 * after the offset. The new pointer is returned.
6378 */
Willy Tarreaud426a182010-03-05 14:58:26 +01006379static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
6380 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01006381{
6382 int end;
6383 unsigned char c;
6384
6385 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02006386 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01006387 return ptr;
6388
Willy Tarreau77804732012-10-29 16:14:26 +01006389 chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01006390
Willy Tarreaud426a182010-03-05 14:58:26 +01006391 while (ptr < len && ptr < bsize) {
6392 c = buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01006393 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006394 if (out->len > end - 2)
6395 break;
6396 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01006397 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006398 if (out->len > end - 3)
6399 break;
6400 out->str[out->len++] = '\\';
6401 switch (c) {
6402 case '\t': c = 't'; break;
6403 case '\n': c = 'n'; break;
6404 case '\r': c = 'r'; break;
6405 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01006406 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006407 }
6408 out->str[out->len++] = c;
6409 } else {
6410 if (out->len > end - 5)
6411 break;
6412 out->str[out->len++] = '\\';
6413 out->str[out->len++] = 'x';
6414 out->str[out->len++] = hextab[(c >> 4) & 0xF];
6415 out->str[out->len++] = hextab[c & 0xF];
6416 }
Willy Tarreaud426a182010-03-05 14:58:26 +01006417 if (buf[ptr++] == '\n') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006418 /* we had a line break, let's return now */
6419 out->str[out->len++] = '\n';
6420 *line = ptr;
6421 return ptr;
6422 }
6423 }
6424 /* we have an incomplete line, we return it as-is */
6425 out->str[out->len++] = '\n';
6426 return ptr;
6427}
6428
Baptiste Assmann3863f972015-05-17 00:33:24 +02006429/* This function dumps counters from all resolvers section and associated name servers.
6430 * It returns 0 if the output buffer is full and it needs
6431 * to be called again, otherwise non-zero.
6432 */
6433static int stats_dump_resolvers_to_buffer(struct stream_interface *si)
6434{
6435 struct appctx *appctx = __objt_appctx(si->end);
6436 struct dns_resolvers *presolvers;
6437 struct dns_nameserver *pnameserver;
6438
6439 chunk_reset(&trash);
6440
6441 switch (appctx->st2) {
6442 case STAT_ST_INIT:
6443 appctx->st2 = STAT_ST_LIST; /* let's start producing data */
6444 /* fall through */
6445
6446 case STAT_ST_LIST:
Andrew Hayworth68d05342015-10-02 20:33:01 +00006447 if (LIST_ISEMPTY(&dns_resolvers)) {
6448 chunk_appendf(&trash, "No resolvers found\n");
6449 }
6450 else {
6451 list_for_each_entry(presolvers, &dns_resolvers, list) {
6452 if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers)
6453 continue;
6454
6455 chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id);
6456 list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) {
6457 chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id);
6458 chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent);
6459 chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid);
6460 chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update);
6461 chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname);
6462 chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error);
6463 chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err);
6464 chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx);
6465 chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout);
6466 chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused);
6467 chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other);
6468 chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid);
6469 chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big);
6470 chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated);
6471 chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated);
6472 }
6473 }
Baptiste Assmann3863f972015-05-17 00:33:24 +02006474 }
6475
6476 /* display response */
6477 if (bi_putchk(si_ic(si), &trash) == -1) {
6478 /* let's try again later from this session. We add ourselves into
6479 * this session's users so that it can remove us upon termination.
6480 */
6481 si->flags |= SI_FL_WAIT_ROOM;
6482 return 0;
6483 }
6484
6485 appctx->st2 = STAT_ST_FIN;
6486 /* fall through */
6487
6488 default:
6489 appctx->st2 = STAT_ST_FIN;
6490 return 1;
6491 }
6492}
6493
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02006494/* This function dumps all captured errors onto the stream interface's
Willy Tarreau306f8302013-07-08 15:53:06 +02006495 * read buffer. It returns 0 if the output buffer is full and it needs
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01006496 * to be called again, otherwise non-zero.
Willy Tarreau74808cb2009-03-04 15:53:18 +01006497 */
Simon Horman9bd2c732011-06-15 15:18:44 +09006498static int stats_dump_errors_to_buffer(struct stream_interface *si)
Willy Tarreau74808cb2009-03-04 15:53:18 +01006499{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006500 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau74808cb2009-03-04 15:53:18 +01006501 extern const char *monthname[12];
Willy Tarreau74808cb2009-03-04 15:53:18 +01006502
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006503 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
Willy Tarreau61b34732009-10-03 23:49:35 +02006504 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006505
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006506 chunk_reset(&trash);
Willy Tarreau74808cb2009-03-04 15:53:18 +01006507
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006508 if (!appctx->ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006509 /* the function had not been called yet, let's prepare the
6510 * buffer for a response.
6511 */
Willy Tarreau10479e42010-12-12 14:00:34 +01006512 struct tm tm;
6513
6514 get_localtime(date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006515 chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n",
Willy Tarreau10479e42010-12-12 14:00:34 +01006516 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
6517 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000),
6518 error_snapshot_id);
6519
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006520 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau10479e42010-12-12 14:00:34 +01006521 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreaufe127932015-04-21 19:23:39 +02006522 si_applet_cant_put(si);
Willy Tarreau10479e42010-12-12 14:00:34 +01006523 return 0;
6524 }
6525
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006526 appctx->ctx.errors.px = proxy;
6527 appctx->ctx.errors.buf = 0;
6528 appctx->ctx.errors.bol = 0;
6529 appctx->ctx.errors.ptr = -1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006530 }
6531
6532 /* we have two inner loops here, one for the proxy, the other one for
6533 * the buffer.
6534 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006535 while (appctx->ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006536 struct error_snapshot *es;
6537
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006538 if (appctx->ctx.errors.buf == 0)
6539 es = &appctx->ctx.errors.px->invalid_req;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006540 else
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006541 es = &appctx->ctx.errors.px->invalid_rep;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006542
6543 if (!es->when.tv_sec)
6544 goto next;
6545
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006546 if (appctx->ctx.errors.iid >= 0 &&
6547 appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid &&
6548 es->oe->uuid != appctx->ctx.errors.iid)
Willy Tarreau74808cb2009-03-04 15:53:18 +01006549 goto next;
6550
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006551 if (appctx->ctx.errors.ptr < 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006552 /* just print headers now */
6553
6554 char pn[INET6_ADDRSTRLEN];
6555 struct tm tm;
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006556 int port;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006557
6558 get_localtime(es->when.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006559 chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01006560 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02006561 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01006562
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006563 switch (addr_to_str(&es->src, pn, sizeof(pn))) {
6564 case AF_INET:
6565 case AF_INET6:
6566 port = get_host_port(&es->src);
6567 break;
6568 default:
6569 port = 0;
6570 }
6571
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006572 switch (appctx->ctx.errors.buf) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006573 case 0:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006574 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01006575 " frontend %s (#%d): invalid request\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006576 " backend %s (#%d)",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006577 appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006578 (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
6579 (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1);
Willy Tarreau74808cb2009-03-04 15:53:18 +01006580 break;
6581 case 1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006582 chunk_appendf(&trash,
Olivier Doucet08afdcb2014-09-08 11:23:00 +02006583 " backend %s (#%d): invalid response\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006584 " frontend %s (#%d)",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006585 appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006586 es->oe->id, es->oe->uuid);
Willy Tarreau74808cb2009-03-04 15:53:18 +01006587 break;
6588 }
6589
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006590 chunk_appendf(&trash,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02006591 ", server %s (#%d), event #%u\n"
6592 " src %s:%d, session #%d, session flags 0x%08x\n"
6593 " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n"
6594 " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n"
6595 " buffer flags 0x%08x, out %d bytes, total %lld bytes\n"
6596 " pending %d bytes, wrapping at %d, error at position %d:\n \n",
6597 es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1,
6598 es->ev_id,
6599 pn, port, es->sid, es->s_flags,
6600 es->state, es->m_flags, es->t_flags,
6601 es->m_clen, es->m_blen,
6602 es->b_flags, es->b_out, es->b_tot,
6603 es->len, es->b_wrap, es->pos);
6604
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006605 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006606 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreaufe127932015-04-21 19:23:39 +02006607 si_applet_cant_put(si);
Willy Tarreau61b34732009-10-03 23:49:35 +02006608 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006609 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006610 appctx->ctx.errors.ptr = 0;
6611 appctx->ctx.errors.sid = es->sid;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006612 }
6613
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006614 if (appctx->ctx.errors.sid != es->sid) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006615 /* the snapshot changed while we were dumping it */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01006616 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01006617 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreaubc18da12015-03-13 14:00:47 +01006618 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaufe127932015-04-21 19:23:39 +02006619 si_applet_cant_put(si);
Willy Tarreau61b34732009-10-03 23:49:35 +02006620 return 0;
Willy Tarreaubc18da12015-03-13 14:00:47 +01006621 }
Willy Tarreau74808cb2009-03-04 15:53:18 +01006622 goto next;
6623 }
6624
6625 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006626 while (appctx->ctx.errors.ptr < es->len && appctx->ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006627 int newptr;
6628 int newline;
6629
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006630 newline = appctx->ctx.errors.bol;
6631 newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr);
6632 if (newptr == appctx->ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02006633 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006634
Willy Tarreau2bb4a962014-11-28 11:11:05 +01006635 if (bi_putchk(si_ic(si), &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01006636 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreaufe127932015-04-21 19:23:39 +02006637 si_applet_cant_put(si);
Willy Tarreau61b34732009-10-03 23:49:35 +02006638 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006639 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006640 appctx->ctx.errors.ptr = newptr;
6641 appctx->ctx.errors.bol = newline;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006642 };
6643 next:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01006644 appctx->ctx.errors.bol = 0;
6645 appctx->ctx.errors.ptr = -1;
6646 appctx->ctx.errors.buf++;
6647 if (appctx->ctx.errors.buf > 1) {
6648 appctx->ctx.errors.buf = 0;
6649 appctx->ctx.errors.px = appctx->ctx.errors.px->next;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006650 }
6651 }
6652
6653 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02006654 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01006655}
6656
Willy Tarreaud5781202012-09-22 19:32:35 +02006657/* parse the "level" argument on the bind lines */
6658static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
6659{
6660 if (!*args[cur_arg + 1]) {
6661 memprintf(err, "'%s' : missing level", args[cur_arg]);
6662 return ERR_ALERT | ERR_FATAL;
6663 }
6664
6665 if (!strcmp(args[cur_arg+1], "user"))
6666 conf->level = ACCESS_LVL_USER;
6667 else if (!strcmp(args[cur_arg+1], "operator"))
6668 conf->level = ACCESS_LVL_OPER;
6669 else if (!strcmp(args[cur_arg+1], "admin"))
6670 conf->level = ACCESS_LVL_ADMIN;
6671 else {
6672 memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')",
6673 args[cur_arg], args[cur_arg+1]);
6674 return ERR_ALERT | ERR_FATAL;
6675 }
6676
6677 return 0;
6678}
6679
Willy Tarreau30576452015-04-13 13:50:30 +02006680struct applet http_stats_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01006681 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01006682 .name = "<STATS>", /* used for logging */
6683 .fct = http_stats_io_handler,
Aman Gupta9a13e842012-04-02 18:57:53 -07006684 .release = NULL,
Willy Tarreaub24281b2011-02-13 13:16:36 +01006685};
6686
Willy Tarreau30576452015-04-13 13:50:30 +02006687static struct applet cli_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01006688 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01006689 .name = "<CLI>", /* used for logging */
6690 .fct = cli_io_handler,
Willy Tarreau5f9a8772012-11-26 02:22:40 +01006691 .release = cli_release_handler,
Willy Tarreaub24281b2011-02-13 13:16:36 +01006692};
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01006693
Willy Tarreaudc13c112013-06-21 23:16:39 +02006694static struct cfg_kw_list cfg_kws = {ILH, {
Willy Tarreau10522fd2008-07-09 20:12:41 +02006695 { CFG_GLOBAL, "stats", stats_parse_global },
6696 { 0, NULL, NULL },
6697}};
6698
Willy Tarreaud5781202012-09-22 19:32:35 +02006699static struct bind_kw_list bind_kws = { "STAT", { }, {
6700 { "level", bind_parse_level, 1 }, /* set the unix socket admin level */
6701 { NULL, NULL, 0 },
6702}};
6703
Willy Tarreau10522fd2008-07-09 20:12:41 +02006704__attribute__((constructor))
6705static void __dumpstats_module_init(void)
6706{
6707 cfg_register_keywords(&cfg_kws);
Willy Tarreaud5781202012-09-22 19:32:35 +02006708 bind_register_keywords(&bind_kws);
Willy Tarreau10522fd2008-07-09 20:12:41 +02006709}
6710
Willy Tarreau91861262007-10-17 17:06:05 +02006711/*
6712 * Local variables:
6713 * c-indent-level: 8
6714 * c-basic-offset: 8
6715 * End:
6716 */