blob: d20682ee8ed205fb00312572c9d07ed2a0633e38 [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>
38
Willy Tarreau91861262007-10-17 17:06:05 +020039#include <types/global.h>
Willy Tarreau91861262007-10-17 17:06:05 +020040
41#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020042#include <proto/channel.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020043#include <proto/checks.h>
William Lallemande3a7d992012-11-20 11:25:20 +010044#include <proto/compression.h>
Willy Tarreau91861262007-10-17 17:06:05 +020045#include <proto/dumpstats.h>
46#include <proto/fd.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010047#include <proto/freq_ctr.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020048#include <proto/log.h>
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010049#include <proto/pattern.h>
Willy Tarreaua206fa92009-01-25 14:02:00 +010050#include <proto/pipe.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020051#include <proto/listener.h>
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010052#include <proto/map.h>
Willy Tarreaue6d97022012-11-23 11:19:33 +010053#include <proto/proto_http.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020054#include <proto/proto_uxst.h>
Willy Tarreau89a63132009-08-16 17:41:45 +020055#include <proto/proxy.h>
Willy Tarreau1cf8f082014-02-07 12:14:54 +010056#include <proto/sample.h>
Willy Tarreau91861262007-10-17 17:06:05 +020057#include <proto/session.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020058#include <proto/server.h>
Willy Tarreau75bf2c92012-08-20 17:01:35 +020059#include <proto/raw_sock.h>
Willy Tarreaudded32d2008-11-30 19:48:07 +010060#include <proto/stream_interface.h>
Willy Tarreau4726f532009-03-07 17:25:21 +010061#include <proto/task.h>
Willy Tarreau91861262007-10-17 17:06:05 +020062
Willy Tarreau7a0169a2012-11-19 17:13:16 +010063#ifdef USE_OPENSSL
64#include <proto/ssl_sock.h>
65#endif
66
Willy Tarreau91b843d2014-01-28 16:27:17 +010067/* stats socket states */
68enum {
69 STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */
70 STAT_CLI_END, /* final state, let's close */
71 STAT_CLI_GETREQ, /* wait for a request */
72 STAT_CLI_OUTPUT, /* all states after this one are responses */
73 STAT_CLI_PROMPT, /* display the prompt (first output, same code) */
74 STAT_CLI_PRINT, /* display message in cli->msg */
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +010075 STAT_CLI_PRINT_FREE, /* display message in cli->msg. After the display, free the pointer */
Willy Tarreau91b843d2014-01-28 16:27:17 +010076 STAT_CLI_O_INFO, /* dump info */
77 STAT_CLI_O_SESS, /* dump sessions */
78 STAT_CLI_O_ERR, /* dump errors */
79 STAT_CLI_O_TAB, /* dump tables */
80 STAT_CLI_O_CLR, /* clear tables */
81 STAT_CLI_O_SET, /* set entries in tables */
82 STAT_CLI_O_STAT, /* dump stats */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +010083 STAT_CLI_O_PATS, /* list all pattern reference avalaible */
84 STAT_CLI_O_PAT, /* list all entries of a pattern */
Willy Tarreau91b843d2014-01-28 16:27:17 +010085 STAT_CLI_O_MLOOK, /* lookup a map entry */
Willy Tarreau12833bb2014-01-28 16:49:56 +010086 STAT_CLI_O_POOLS, /* dump memory pools */
Willy Tarreau91b843d2014-01-28 16:27:17 +010087};
88
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +010089static int stats_dump_info_to_buffer(struct stream_interface *si);
Willy Tarreau12833bb2014-01-28 16:49:56 +010090static int stats_dump_pools_to_buffer(struct stream_interface *si);
Willy Tarreau76153662012-11-26 01:16:39 +010091static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess);
Simon Horman9bd2c732011-06-15 15:18:44 +090092static int stats_dump_sess_to_buffer(struct stream_interface *si);
93static int stats_dump_errors_to_buffer(struct stream_interface *si);
Willy Tarreau44455022012-12-05 23:01:12 +010094static int stats_table_request(struct stream_interface *si, int show);
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +010095static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri);
96static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +010097static int stats_pats_list(struct stream_interface *si);
98static int stats_pat_list(struct stream_interface *si);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010099static int stats_map_lookup(struct stream_interface *si);
Simon Horman9bd2c732011-06-15 15:18:44 +0900100
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100101/*
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +0100102 * cli_io_handler()
103 * -> stats_dump_sess_to_buffer() // "show sess"
104 * -> stats_dump_errors_to_buffer() // "show errors"
105 * -> stats_dump_info_to_buffer() // "show info"
106 * -> stats_dump_stat_to_buffer() // "show stat"
107 * -> stats_dump_csv_header()
108 * -> stats_dump_proxy_to_buffer()
109 * -> stats_dump_fe_stats()
110 * -> stats_dump_li_stats()
111 * -> stats_dump_sv_stats()
112 * -> stats_dump_be_stats()
113 *
114 * http_stats_io_handler()
115 * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML
116 * -> stats_dump_csv_header() // emits the CSV headers (same as above)
117 * -> stats_dump_html_head() // emits the HTML headers
118 * -> stats_dump_html_info() // emits the equivalent of "show info" at the top
119 * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML
120 * -> stats_dump_html_px_hdr()
121 * -> stats_dump_fe_stats()
122 * -> stats_dump_li_stats()
123 * -> stats_dump_sv_stats()
124 * -> stats_dump_be_stats()
125 * -> stats_dump_html_px_end()
126 * -> stats_dump_html_end() // emits HTML trailer
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100127 */
128
Simon Horman9bd2c732011-06-15 15:18:44 +0900129static struct si_applet cli_applet;
130
131static const char stats_sock_usage_msg[] =
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200132 "Unknown command. Please enter one of the following commands only :\n"
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200133 " clear counters : clear max statistics counters (add 'all' for all counters)\n"
Willy Tarreau88ee3972010-07-13 13:48:00 +0200134 " clear table : remove an entry from a table\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200135 " help : this message\n"
136 " prompt : toggle interactive mode with prompt\n"
137 " quit : disconnect\n"
138 " show info : report information about the running process\n"
Willy Tarreau12833bb2014-01-28 16:49:56 +0100139 " show pools : report information about the memory pools usage\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200140 " show stat : report counters for each proxy and server\n"
141 " show errors : report last request and response errors for each proxy\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100142 " show sess [id] : report the list of current sessions or dump this session\n"
Willy Tarreau69f58c82010-07-12 17:55:33 +0200143 " show table [id]: report table usage stats or dump this table's contents\n"
Willy Tarreau38338fa2009-10-10 18:37:29 +0200144 " get weight : report a server's current weight\n"
Willy Tarreau4483d432009-10-10 19:30:08 +0200145 " set weight : change a server's weight\n"
Willy Tarreau654694e2012-06-07 01:03:16 +0200146 " set table [id] : update or create a table entry's data\n"
Willy Tarreau7aabd112010-01-26 10:59:06 +0100147 " set timeout : change a timeout setting\n"
Willy Tarreau2a0f4d22011-08-02 11:49:05 +0200148 " set maxconn : change a maxconn setting\n"
Willy Tarreauf5b22872011-09-07 16:13:44 +0200149 " set rate-limit : change a rate limiting value\n"
Willy Tarreaua295edc2011-09-07 23:21:03 +0200150 " disable : put a server or frontend in maintenance mode\n"
151 " enable : re-enable a server or frontend which is in maintenance mode\n"
152 " shutdown : kill a session or a frontend (eg:to release listening ports)\n"
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100153 " show acl [id] : report avalaible acls or dump an acl's contents\n"
154 " get acl : reports the patterns matching a sample for an ACL\n"
155 " add acl : add acl entry\n"
156 " del acl : delete acl entry\n"
157 " clear acl <id> : clear the content of this acl\n"
Thierry FOURNIER1432a0c2014-03-11 13:42:38 +0100158 " show map [id] : report avalaible maps or dump a map's contents\n"
159 " get map : reports the keys and values matching a sample for a map\n"
160 " set map : modify map entry\n"
161 " add map : add map entry\n"
162 " del map : delete map entry\n"
163 " clear map <id> : clear the content of this map\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200164 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200165
Simon Horman9bd2c732011-06-15 15:18:44 +0900166static const char stats_permission_denied_msg[] =
Willy Tarreau6162db22009-10-10 17:13:00 +0200167 "Permission denied\n"
168 "";
169
Willy Tarreau295a8372011-03-10 11:25:07 +0100170/* data transmission states for the stats responses */
171enum {
172 STAT_ST_INIT = 0,
173 STAT_ST_HEAD,
174 STAT_ST_INFO,
175 STAT_ST_LIST,
176 STAT_ST_END,
177 STAT_ST_FIN,
178};
179
180/* data transmission states for the stats responses inside a proxy */
181enum {
182 STAT_PX_ST_INIT = 0,
183 STAT_PX_ST_TH,
184 STAT_PX_ST_FE,
185 STAT_PX_ST_LI,
186 STAT_PX_ST_SV,
187 STAT_PX_ST_BE,
188 STAT_PX_ST_END,
189 STAT_PX_ST_FIN,
190};
191
Cyril Bonté19979e12012-04-04 12:57:21 +0200192extern const char *stat_status_codes[];
193
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200194/* This function is called from the session-level accept() in order to instanciate
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200195 * a new stats socket. It returns a positive value upon success, 0 if the session
Willy Tarreaueb472682010-05-28 18:46:57 +0200196 * needs to be closed and ignored, or a negative value upon critical failure.
197 */
Simon Horman9bd2c732011-06-15 15:18:44 +0900198static int stats_accept(struct session *s)
Willy Tarreaueb472682010-05-28 18:46:57 +0200199{
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100200 s->target = &cli_applet.obj_type;
Willy Tarreau4171e9e2013-12-01 12:32:30 +0100201 /* no need to initialize the applet, it will start with st0=st1 = 0 */
Willy Tarreaueb472682010-05-28 18:46:57 +0200202
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200203 tv_zero(&s->logs.tv_request);
204 s->logs.t_queue = 0;
205 s->logs.t_connect = 0;
206 s->logs.t_data = 0;
207 s->logs.t_close = 0;
208 s->logs.bytes_in = s->logs.bytes_out = 0;
209 s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
210 s->logs.srv_queue_size = 0; /* we will get this number soon */
Willy Tarreaueb472682010-05-28 18:46:57 +0200211
Willy Tarreau03cdb7c2012-08-27 23:14:58 +0200212 s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreaueb472682010-05-28 18:46:57 +0200213
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200214 if (s->listener->timeout) {
215 s->req->rto = *s->listener->timeout;
216 s->rep->wto = *s->listener->timeout;
Willy Tarreaueb472682010-05-28 18:46:57 +0200217 }
Willy Tarreaueb472682010-05-28 18:46:57 +0200218 return 1;
Willy Tarreaueb472682010-05-28 18:46:57 +0200219}
220
Willy Tarreau07e9e642010-08-17 21:48:17 +0200221/* allocate a new stats frontend named <name>, and return it
222 * (or NULL in case of lack of memory).
223 */
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200224static struct proxy *alloc_stats_fe(const char *name, const char *file, int line)
Willy Tarreau07e9e642010-08-17 21:48:17 +0200225{
226 struct proxy *fe;
227
228 fe = (struct proxy *)calloc(1, sizeof(struct proxy));
229 if (!fe)
230 return NULL;
231
Willy Tarreau237250c2011-07-29 01:49:03 +0200232 init_new_proxy(fe);
Willy Tarreau050536d2012-10-04 08:47:34 +0200233 fe->next = proxy;
234 proxy = fe;
Willy Tarreau07e9e642010-08-17 21:48:17 +0200235 fe->last_change = now.tv_sec;
236 fe->id = strdup("GLOBAL");
237 fe->cap = PR_CAP_FE;
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200238 fe->maxconn = 10; /* default to 10 concurrent connections */
239 fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200240 fe->conf.file = strdup(file);
241 fe->conf.line = line;
Willy Tarreauc53d4222012-09-20 20:19:28 +0200242 fe->accept = stats_accept;
Willy Tarreau050536d2012-10-04 08:47:34 +0200243
244 /* the stats frontend is the only one able to assign ID #0 */
245 fe->conf.id.key = fe->uuid = 0;
246 eb32_insert(&used_proxy_id, &fe->conf.id);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200247 return fe;
248}
249
Willy Tarreaufbee7132007-10-18 13:53:22 +0200250/* This function parses a "stats" statement in the "global" section. It returns
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200251 * -1 if there is any error, otherwise zero. If it returns -1, it will write an
252 * error message into the <err> buffer which will be preallocated. The trailing
253 * '\n' must not be written. The function must be called with <args> pointing to
254 * the first word after "stats".
Willy Tarreaufbee7132007-10-18 13:53:22 +0200255 */
Willy Tarreau10522fd2008-07-09 20:12:41 +0200256static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
Willy Tarreau28a47d62012-09-18 20:02:48 +0200257 struct proxy *defpx, const char *file, int line,
258 char **err)
Willy Tarreaufbee7132007-10-18 13:53:22 +0200259{
Willy Tarreau4348fad2012-09-20 16:48:07 +0200260 struct bind_conf *bind_conf;
Willy Tarreauc53d4222012-09-20 20:19:28 +0200261 struct listener *l;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200262
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200263 if (!strcmp(args[1], "socket")) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200264 int cur_arg;
265
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200266 if (*args[2] == 0) {
Willy Tarreauc53d4222012-09-20 20:19:28 +0200267 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 +0200268 return -1;
269 }
270
Willy Tarreau89a63132009-08-16 17:41:45 +0200271 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200272 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200273 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreau89a63132009-08-16 17:41:45 +0200274 return -1;
275 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200276 }
277
Willy Tarreau4348fad2012-09-20 16:48:07 +0200278 bind_conf = bind_conf_alloc(&global.stats_fe->conf.bind, file, line, args[2]);
Willy Tarreau290e63a2012-09-20 18:07:14 +0200279 bind_conf->level = ACCESS_LVL_OPER; /* default access level */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200280
Willy Tarreauc53d4222012-09-20 20:19:28 +0200281 if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) {
282 memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n",
283 file, line, args[0], args[1], err && *err ? *err : "error");
284 return -1;
285 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200286
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200287 cur_arg = 3;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200288 while (*args[cur_arg]) {
Willy Tarreaud5781202012-09-22 19:32:35 +0200289 static int bind_dumped;
290 struct bind_kw *kw;
291
292 kw = bind_find_kw(args[cur_arg]);
293 if (kw) {
294 if (!kw->parse) {
295 memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).",
296 args[0], args[1], args[cur_arg]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200297 return -1;
298 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200299
300 if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) {
301 if (err && *err)
302 memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err);
303 else
304 memprintf(err, "'%s %s' : error encountered while processing '%s'",
305 args[0], args[1], args[cur_arg]);
Willy Tarreau6162db22009-10-10 17:13:00 +0200306 return -1;
307 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200308
309 cur_arg += 1 + kw->skip;
310 continue;
Willy Tarreau6162db22009-10-10 17:13:00 +0200311 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200312
313 if (!bind_dumped) {
314 bind_dump_kws(err);
315 indent_msg(err, 4);
316 bind_dumped = 1;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200317 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200318
319 memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s",
320 args[0], args[1], args[cur_arg],
321 err && *err ? " Registered keywords :" : "", err && *err ? *err : "");
322 return -1;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200323 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100324
Willy Tarreauc53d4222012-09-20 20:19:28 +0200325 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
326 l->maxconn = global.stats_fe->maxconn;
327 l->backlog = global.stats_fe->backlog;
328 l->timeout = &global.stats_fe->timeout.client;
329 l->accept = session_accept;
330 l->handler = process_session;
331 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
332 l->nice = -64; /* we want to boost priority for local stats */
333 global.maxsock += l->maxconn;
334 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200335 }
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200336 else if (!strcmp(args[1], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100337 unsigned timeout;
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200338 const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS);
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100339
340 if (res) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200341 memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res);
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100342 return -1;
343 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200344
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100345 if (!timeout) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200346 memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200347 return -1;
348 }
Willy Tarreau07e9e642010-08-17 21:48:17 +0200349 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200350 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200351 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200352 return -1;
353 }
354 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200355 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200356 }
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200357 else if (!strcmp(args[1], "maxconn")) {
358 int maxconn = atol(args[2]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200359
360 if (maxconn <= 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200361 memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200362 return -1;
363 }
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200364
365 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200366 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200367 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200368 return -1;
369 }
370 }
371 global.stats_fe->maxconn = maxconn;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200372 }
Willy Tarreau35b7b162012-10-22 23:17:18 +0200373 else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */
374 int cur_arg = 2;
375 unsigned int set = 0;
376
Willy Tarreau91319572013-04-20 09:48:50 +0200377 if (!global.stats_fe) {
378 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
379 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
380 return -1;
381 }
382 }
383
Willy Tarreau35b7b162012-10-22 23:17:18 +0200384 while (*args[cur_arg]) {
Willy Tarreau110ecc12012-11-15 17:50:01 +0100385 unsigned int low, high;
386
Willy Tarreau35b7b162012-10-22 23:17:18 +0200387 if (strcmp(args[cur_arg], "all") == 0) {
388 set = 0;
389 break;
390 }
391 else if (strcmp(args[cur_arg], "odd") == 0) {
392 set |= 0x55555555;
393 }
394 else if (strcmp(args[cur_arg], "even") == 0) {
395 set |= 0xAAAAAAAA;
396 }
Willy Tarreau83d84cf2012-11-22 01:04:31 +0100397 else if (isdigit((int)*args[cur_arg])) {
Willy Tarreau110ecc12012-11-15 17:50:01 +0100398 char *dash = strchr(args[cur_arg], '-');
399
400 low = high = str2uic(args[cur_arg]);
401 if (dash)
402 high = str2uic(dash + 1);
403
404 if (high < low) {
405 unsigned int swap = low;
406 low = high;
407 high = swap;
408 }
409
410 if (low < 1 || high > 32) {
411 memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n",
412 args[0], args[1]);
Willy Tarreau35b7b162012-10-22 23:17:18 +0200413 return -1;
414 }
Willy Tarreau110ecc12012-11-15 17:50:01 +0100415
416 while (low <= high)
417 set |= 1 << (low++ - 1);
418 }
419 else {
420 memprintf(err,
421 "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n",
422 args[0], args[1]);
423 return -1;
Willy Tarreau35b7b162012-10-22 23:17:18 +0200424 }
425 cur_arg++;
426 }
427 global.stats_fe->bind_proc = set;
428 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200429 else {
Willy Tarreau35b7b162012-10-22 23:17:18 +0200430 memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200431 return -1;
432 }
433 return 0;
434}
435
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100436/* Dumps the stats CSV header to the trash buffer which. The caller is responsible
437 * for clearing it if needed.
Willy Tarreauf522f3d2014-02-10 22:22:49 +0100438 * NOTE: Some tools happen to rely on the field position instead of its name,
439 * so please only append new fields at the end, never in the middle.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100440 */
441static void stats_dump_csv_header()
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100442{
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100443 chunk_appendf(&trash,
444 "# pxname,svname,"
445 "qcur,qmax,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +0100446 "scur,smax,slim,stot,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100447 "bin,bout,"
448 "dreq,dresp,"
449 "ereq,econ,eresp,"
450 "wretr,wredis,"
451 "status,weight,act,bck,"
452 "chkfail,chkdown,lastchg,downtime,qlimit,"
453 "pid,iid,sid,throttle,lbtot,tracked,type,"
454 "rate,rate_lim,rate_max,"
455 "check_status,check_code,check_duration,"
456 "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,"
457 "req_rate,req_rate_max,req_tot,"
458 "cli_abrt,srv_abrt,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +0100459 "comp_in,comp_out,comp_byp,comp_rsp,lastsess,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +0100460 "\n");
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100461}
462
Simon Hormand9366582011-06-15 15:18:45 +0900463/* print a string of text buffer to <out>. The format is :
464 * Non-printable chars \t, \n, \r and \e are * encoded in C format.
465 * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped.
466 * Print stopped if null char or <bsize> is reached, or if no more place in the chunk.
467 */
468static int dump_text(struct chunk *out, const char *buf, int bsize)
469{
470 unsigned char c;
471 int ptr = 0;
472
473 while (buf[ptr] && ptr < bsize) {
474 c = buf[ptr];
475 if (isprint(c) && isascii(c) && c != '\\' && c != ' ') {
476 if (out->len > out->size - 1)
477 break;
478 out->str[out->len++] = c;
479 }
480 else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') {
481 if (out->len > out->size - 2)
482 break;
483 out->str[out->len++] = '\\';
484 switch (c) {
485 case ' ': c = ' '; break;
486 case '\t': c = 't'; break;
487 case '\n': c = 'n'; break;
488 case '\r': c = 'r'; break;
489 case '\e': c = 'e'; break;
490 case '\\': c = '\\'; break;
491 }
492 out->str[out->len++] = c;
493 }
494 else {
495 if (out->len > out->size - 4)
496 break;
497 out->str[out->len++] = '\\';
498 out->str[out->len++] = 'x';
499 out->str[out->len++] = hextab[(c >> 4) & 0xF];
500 out->str[out->len++] = hextab[c & 0xF];
501 }
502 ptr++;
503 }
504
505 return ptr;
506}
507
508/* print a buffer in hexa.
509 * Print stopped if <bsize> is reached, or if no more place in the chunk.
510 */
511static int dump_binary(struct chunk *out, const char *buf, int bsize)
512{
513 unsigned char c;
514 int ptr = 0;
515
516 while (ptr < bsize) {
517 c = buf[ptr];
518
519 if (out->len > out->size - 2)
520 break;
521 out->str[out->len++] = hextab[(c >> 4) & 0xF];
522 out->str[out->len++] = hextab[c & 0xF];
523
524 ptr++;
525 }
526 return ptr;
527}
528
529/* Dump the status of a table to a stream interface's
530 * read buffer. It returns 0 if the output buffer is full
531 * and needs to be called again, otherwise non-zero.
532 */
533static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si,
534 struct proxy *proxy, struct proxy *target)
535{
Willy Tarreau306f8302013-07-08 15:53:06 +0200536 struct session *s = session_from_task(si->owner);
Simon Hormand9366582011-06-15 15:18:45 +0900537
Willy Tarreau77804732012-10-29 16:14:26 +0100538 chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n",
Simon Hormand9366582011-06-15 15:18:45 +0900539 proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current);
540
541 /* any other information should be dumped here */
542
Willy Tarreau290e63a2012-09-20 18:07:14 +0200543 if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER)
Willy Tarreau77804732012-10-29 16:14:26 +0100544 chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n");
Simon Hormand9366582011-06-15 15:18:45 +0900545
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200546 if (bi_putchk(si->ib, msg) == -1)
Simon Hormand9366582011-06-15 15:18:45 +0900547 return 0;
548
549 return 1;
550}
551
552/* Dump the a table entry to a stream interface's
553 * read buffer. It returns 0 if the output buffer is full
554 * and needs to be called again, otherwise non-zero.
555 */
556static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si,
557 struct proxy *proxy, struct stksess *entry)
558{
559 int dt;
560
Willy Tarreau77804732012-10-29 16:14:26 +0100561 chunk_appendf(msg, "%p:", entry);
Simon Hormand9366582011-06-15 15:18:45 +0900562
563 if (proxy->table.type == STKTABLE_TYPE_IP) {
564 char addr[INET_ADDRSTRLEN];
565 inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr));
Willy Tarreau77804732012-10-29 16:14:26 +0100566 chunk_appendf(msg, " key=%s", addr);
Simon Hormand9366582011-06-15 15:18:45 +0900567 }
568 else if (proxy->table.type == STKTABLE_TYPE_IPV6) {
569 char addr[INET6_ADDRSTRLEN];
570 inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr));
Willy Tarreau77804732012-10-29 16:14:26 +0100571 chunk_appendf(msg, " key=%s", addr);
Simon Hormand9366582011-06-15 15:18:45 +0900572 }
573 else if (proxy->table.type == STKTABLE_TYPE_INTEGER) {
Willy Tarreau77804732012-10-29 16:14:26 +0100574 chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key);
Simon Hormand9366582011-06-15 15:18:45 +0900575 }
576 else if (proxy->table.type == STKTABLE_TYPE_STRING) {
Willy Tarreau77804732012-10-29 16:14:26 +0100577 chunk_appendf(msg, " key=");
Simon Hormand9366582011-06-15 15:18:45 +0900578 dump_text(msg, (const char *)entry->key.key, proxy->table.key_size);
579 }
580 else {
Willy Tarreau77804732012-10-29 16:14:26 +0100581 chunk_appendf(msg, " key=");
Simon Hormand9366582011-06-15 15:18:45 +0900582 dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size);
583 }
584
Willy Tarreau77804732012-10-29 16:14:26 +0100585 chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire));
Simon Hormand9366582011-06-15 15:18:45 +0900586
587 for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) {
588 void *ptr;
589
590 if (proxy->table.data_ofs[dt] == 0)
591 continue;
592 if (stktable_data_types[dt].arg_type == ARG_T_DELAY)
Willy Tarreau77804732012-10-29 16:14:26 +0100593 chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u);
Simon Hormand9366582011-06-15 15:18:45 +0900594 else
Willy Tarreau77804732012-10-29 16:14:26 +0100595 chunk_appendf(msg, " %s=", stktable_data_types[dt].name);
Simon Hormand9366582011-06-15 15:18:45 +0900596
597 ptr = stktable_data_ptr(&proxy->table, entry, dt);
598 switch (stktable_data_types[dt].std_type) {
599 case STD_T_SINT:
Willy Tarreau77804732012-10-29 16:14:26 +0100600 chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint));
Simon Hormand9366582011-06-15 15:18:45 +0900601 break;
602 case STD_T_UINT:
Willy Tarreau77804732012-10-29 16:14:26 +0100603 chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint));
Simon Hormand9366582011-06-15 15:18:45 +0900604 break;
605 case STD_T_ULL:
Willy Tarreau77804732012-10-29 16:14:26 +0100606 chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull));
Simon Hormand9366582011-06-15 15:18:45 +0900607 break;
608 case STD_T_FRQP:
Willy Tarreau77804732012-10-29 16:14:26 +0100609 chunk_appendf(msg, "%d",
Simon Hormand9366582011-06-15 15:18:45 +0900610 read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
611 proxy->table.data_arg[dt].u));
612 break;
613 }
614 }
Willy Tarreau77804732012-10-29 16:14:26 +0100615 chunk_appendf(msg, "\n");
Simon Hormand9366582011-06-15 15:18:45 +0900616
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200617 if (bi_putchk(si->ib, msg) == -1)
Simon Hormand9366582011-06-15 15:18:45 +0900618 return 0;
619
620 return 1;
621}
622
Willy Tarreaudec98142012-06-06 23:37:08 +0200623static void stats_sock_table_key_request(struct stream_interface *si, char **args, int action)
Simon Horman121f3052011-06-15 15:18:46 +0900624{
Willy Tarreau306f8302013-07-08 15:53:06 +0200625 struct session *s = session_from_task(si->owner);
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100626 struct appctx *appctx = __objt_appctx(si->end);
627 struct proxy *px = appctx->ctx.table.target;
Simon Horman121f3052011-06-15 15:18:46 +0900628 struct stksess *ts;
Simon Hormancec9a222011-06-15 15:18:51 +0900629 uint32_t uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900630 unsigned char ip6_key[sizeof(struct in6_addr)];
Willy Tarreau654694e2012-06-07 01:03:16 +0200631 long long value;
632 int data_type;
Willy Tarreau47060b62013-08-01 21:11:42 +0200633 int cur_arg;
Willy Tarreau654694e2012-06-07 01:03:16 +0200634 void *ptr;
635 struct freq_ctr_period *frqp;
Simon Horman121f3052011-06-15 15:18:46 +0900636
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100637 appctx->st0 = STAT_CLI_OUTPUT;
Simon Horman121f3052011-06-15 15:18:46 +0900638
639 if (!*args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100640 appctx->ctx.cli.msg = "Key value expected\n";
641 appctx->st0 = STAT_CLI_PRINT;
Simon Horman121f3052011-06-15 15:18:46 +0900642 return;
643 }
644
Simon Hormanc5b89f62011-06-15 15:18:50 +0900645 switch (px->table.type) {
646 case STKTABLE_TYPE_IP:
Simon Hormancec9a222011-06-15 15:18:51 +0900647 uint32_key = htonl(inetaddr_host(args[4]));
Willy Tarreau07115412012-10-29 21:56:59 +0100648 static_table_key->key = &uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900649 break;
650 case STKTABLE_TYPE_IPV6:
651 inet_pton(AF_INET6, args[4], ip6_key);
Willy Tarreau07115412012-10-29 21:56:59 +0100652 static_table_key->key = &ip6_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900653 break;
Simon Hormancec9a222011-06-15 15:18:51 +0900654 case STKTABLE_TYPE_INTEGER:
655 {
656 char *endptr;
657 unsigned long val;
658 errno = 0;
659 val = strtoul(args[4], &endptr, 10);
660 if ((errno == ERANGE && val == ULONG_MAX) ||
661 (errno != 0 && val == 0) || endptr == args[4] ||
662 val > 0xffffffff) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100663 appctx->ctx.cli.msg = "Invalid key\n";
664 appctx->st0 = STAT_CLI_PRINT;
Simon Hormancec9a222011-06-15 15:18:51 +0900665 return;
666 }
667 uint32_key = (uint32_t) val;
Willy Tarreau07115412012-10-29 21:56:59 +0100668 static_table_key->key = &uint32_key;
Simon Hormancec9a222011-06-15 15:18:51 +0900669 break;
670 }
671 break;
Simon Horman619e3cc2011-06-15 15:18:52 +0900672 case STKTABLE_TYPE_STRING:
Willy Tarreau07115412012-10-29 21:56:59 +0100673 static_table_key->key = args[4];
674 static_table_key->key_len = strlen(args[4]);
Simon Horman619e3cc2011-06-15 15:18:52 +0900675 break;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900676 default:
Willy Tarreaudec98142012-06-06 23:37:08 +0200677 switch (action) {
678 case STAT_CLI_O_TAB:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100679 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 +0200680 break;
681 case STAT_CLI_O_CLR:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100682 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 +0200683 break;
684 default:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100685 appctx->ctx.cli.msg = "Unknown action\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200686 break;
687 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100688 appctx->st0 = STAT_CLI_PRINT;
Simon Horman121f3052011-06-15 15:18:46 +0900689 return;
690 }
691
692 /* check permissions */
Willy Tarreau290e63a2012-09-20 18:07:14 +0200693 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100694 appctx->ctx.cli.msg = stats_permission_denied_msg;
695 appctx->st0 = STAT_CLI_PRINT;
Simon Horman121f3052011-06-15 15:18:46 +0900696 return;
697 }
698
Willy Tarreau07115412012-10-29 21:56:59 +0100699 ts = stktable_lookup_key(&px->table, static_table_key);
Simon Horman17bce342011-06-15 15:18:47 +0900700
Willy Tarreaudec98142012-06-06 23:37:08 +0200701 switch (action) {
702 case STAT_CLI_O_TAB:
703 if (!ts)
704 return;
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100705 chunk_reset(&trash);
706 if (!stats_dump_table_head_to_buffer(&trash, si, px, px))
Simon Horman17bce342011-06-15 15:18:47 +0900707 return;
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100708 stats_dump_table_entry_to_buffer(&trash, si, px, ts);
Simon Horman121f3052011-06-15 15:18:46 +0900709 return;
Willy Tarreaudec98142012-06-06 23:37:08 +0200710
711 case STAT_CLI_O_CLR:
712 if (!ts)
713 return;
714 if (ts->ref_cnt) {
715 /* don't delete an entry which is currently referenced */
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100716 appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n";
717 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaudec98142012-06-06 23:37:08 +0200718 return;
719 }
720 stksess_kill(&px->table, ts);
721 break;
Simon Horman17bce342011-06-15 15:18:47 +0900722
Willy Tarreau654694e2012-06-07 01:03:16 +0200723 case STAT_CLI_O_SET:
Willy Tarreau654694e2012-06-07 01:03:16 +0200724 if (ts)
725 stktable_touch(&px->table, ts, 1);
726 else {
Willy Tarreau07115412012-10-29 21:56:59 +0100727 ts = stksess_new(&px->table, static_table_key);
Willy Tarreau654694e2012-06-07 01:03:16 +0200728 if (!ts) {
729 /* don't delete an entry which is currently referenced */
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100730 appctx->ctx.cli.msg = "Unable to allocate a new entry\n";
731 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau654694e2012-06-07 01:03:16 +0200732 return;
733 }
734 stktable_store(&px->table, ts, 1);
735 }
736
Willy Tarreau47060b62013-08-01 21:11:42 +0200737 for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) {
738 if (strncmp(args[cur_arg], "data.", 5) != 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100739 appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n";
740 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau47060b62013-08-01 21:11:42 +0200741 return;
742 }
743
744 data_type = stktable_get_data_type(args[cur_arg] + 5);
745 if (data_type < 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100746 appctx->ctx.cli.msg = "Unknown data type\n";
747 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau47060b62013-08-01 21:11:42 +0200748 return;
749 }
750
751 if (!px->table.data_ofs[data_type]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100752 appctx->ctx.cli.msg = "Data type not stored in this table\n";
753 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau47060b62013-08-01 21:11:42 +0200754 return;
755 }
756
757 if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100758 appctx->ctx.cli.msg = "Require a valid integer value to store\n";
759 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau47060b62013-08-01 21:11:42 +0200760 return;
761 }
762
763 ptr = stktable_data_ptr(&px->table, ts, data_type);
764
765 switch (stktable_data_types[data_type].std_type) {
766 case STD_T_SINT:
767 stktable_data_cast(ptr, std_t_sint) = value;
768 break;
769 case STD_T_UINT:
770 stktable_data_cast(ptr, std_t_uint) = value;
771 break;
772 case STD_T_ULL:
773 stktable_data_cast(ptr, std_t_ull) = value;
774 break;
775 case STD_T_FRQP:
776 /* We set both the current and previous values. That way
777 * the reported frequency is stable during all the period
778 * then slowly fades out. This allows external tools to
779 * push measures without having to update them too often.
780 */
781 frqp = &stktable_data_cast(ptr, std_t_frqp);
782 frqp->curr_tick = now_ms;
783 frqp->prev_ctr = 0;
784 frqp->curr_ctr = value;
785 break;
786 }
Willy Tarreau654694e2012-06-07 01:03:16 +0200787 }
788 break;
789
Willy Tarreaudec98142012-06-06 23:37:08 +0200790 default:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100791 appctx->ctx.cli.msg = "Unknown action\n";
792 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaudec98142012-06-06 23:37:08 +0200793 break;
Simon Horman121f3052011-06-15 15:18:46 +0900794 }
Simon Horman121f3052011-06-15 15:18:46 +0900795}
796
Willy Tarreau654694e2012-06-07 01:03:16 +0200797static void stats_sock_table_data_request(struct stream_interface *si, char **args, int action)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900798{
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100799 struct appctx *appctx = __objt_appctx(si->end);
800
Willy Tarreau04b3a192013-04-13 09:41:37 +0200801 if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100802 appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions";
803 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau654694e2012-06-07 01:03:16 +0200804 return;
805 }
806
Simon Hormand5b9fd92011-06-15 15:18:48 +0900807 /* condition on stored data value */
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100808 appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5);
809 if (appctx->ctx.table.data_type < 0) {
810 appctx->ctx.cli.msg = "Unknown data type\n";
811 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900812 return;
813 }
814
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100815 if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) {
816 appctx->ctx.cli.msg = "Data type not stored in this table\n";
817 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900818 return;
819 }
820
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100821 appctx->ctx.table.data_op = get_std_op(args[4]);
822 if (appctx->ctx.table.data_op < 0) {
823 appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n";
824 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900825 return;
826 }
827
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100828 if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) {
829 appctx->ctx.cli.msg = "Require a valid integer value to compare against\n";
830 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900831 return;
832 }
833}
834
Willy Tarreaudec98142012-06-06 23:37:08 +0200835static void stats_sock_table_request(struct stream_interface *si, char **args, int action)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900836{
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100837 struct appctx *appctx = __objt_appctx(si->end);
838
839 appctx->ctx.table.data_type = -1;
840 appctx->st2 = STAT_ST_INIT;
841 appctx->ctx.table.target = NULL;
842 appctx->ctx.table.proxy = NULL;
843 appctx->ctx.table.entry = NULL;
844 appctx->st0 = action;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900845
846 if (*args[2]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100847 appctx->ctx.table.target = find_stktable(args[2]);
848 if (!appctx->ctx.table.target) {
849 appctx->ctx.cli.msg = "No such table\n";
850 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900851 return;
852 }
853 }
854 else {
Willy Tarreaudec98142012-06-06 23:37:08 +0200855 if (action != STAT_CLI_O_TAB)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900856 goto err_args;
857 return;
858 }
859
860 if (strcmp(args[3], "key") == 0)
Willy Tarreaudec98142012-06-06 23:37:08 +0200861 stats_sock_table_key_request(si, args, action);
Simon Hormanc88b8872011-06-15 15:18:49 +0900862 else if (strncmp(args[3], "data.", 5) == 0)
Willy Tarreau654694e2012-06-07 01:03:16 +0200863 stats_sock_table_data_request(si, args, action);
Simon Hormanc88b8872011-06-15 15:18:49 +0900864 else if (*args[3])
Simon Hormand5b9fd92011-06-15 15:18:48 +0900865 goto err_args;
866
867 return;
868
869err_args:
Willy Tarreaudec98142012-06-06 23:37:08 +0200870 switch (action) {
871 case STAT_CLI_O_TAB:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100872 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 +0200873 break;
874 case STAT_CLI_O_CLR:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100875 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 +0200876 break;
877 default:
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100878 appctx->ctx.cli.msg = "Unknown action\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200879 break;
880 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100881 appctx->st0 = STAT_CLI_PRINT;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900882}
883
Willy Tarreau532a4502011-09-07 22:37:44 +0200884/* Expects to find a frontend named <arg> and returns it, otherwise displays various
885 * adequate error messages and returns NULL. This function also expects the session
886 * level to be admin.
887 */
888static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg)
889{
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100890 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau532a4502011-09-07 22:37:44 +0200891 struct proxy *px;
892
Willy Tarreau290e63a2012-09-20 18:07:14 +0200893 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100894 appctx->ctx.cli.msg = stats_permission_denied_msg;
895 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +0200896 return NULL;
897 }
898
899 if (!*arg) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100900 appctx->ctx.cli.msg = "A frontend name is expected.\n";
901 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +0200902 return NULL;
903 }
904
905 px = findproxy(arg, PR_CAP_FE);
906 if (!px) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100907 appctx->ctx.cli.msg = "No such frontend.\n";
908 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +0200909 return NULL;
910 }
911 return px;
912}
913
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200914/* Expects to find a backend and a server in <arg> under the form <backend>/<server>,
915 * and returns the pointer to the server. Otherwise, display adequate error messages
916 * and returns NULL. This function also expects the session level to be admin. Note:
917 * the <arg> is modified to remove the '/'.
918 */
919static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg)
920{
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100921 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200922 struct proxy *px;
923 struct server *sv;
924 char *line;
925
Willy Tarreau290e63a2012-09-20 18:07:14 +0200926 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100927 appctx->ctx.cli.msg = stats_permission_denied_msg;
928 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200929 return NULL;
930 }
931
932 /* split "backend/server" and make <line> point to server */
933 for (line = arg; *line; line++)
934 if (*line == '/') {
935 *line++ = '\0';
936 break;
937 }
938
939 if (!*line || !*arg) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100940 appctx->ctx.cli.msg = "Require 'backend/server'.\n";
941 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200942 return NULL;
943 }
944
945 if (!get_backend_server(arg, line, &px, &sv)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100946 appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
947 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200948 return NULL;
949 }
950
951 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +0100952 appctx->ctx.cli.msg = "Proxy is disabled.\n";
953 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200954 return NULL;
955 }
956
957 return sv;
958}
959
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100960/* This function is used with map and acl management. It permits to browse
961 * each reference. The variable <getnext> must contain the current node,
962 * <end> point to the root node and the <flags> permit to filter required
963 * nodes.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +0100964 */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100965static inline
966struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end,
967 unsigned int flags)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +0100968{
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100969 struct pat_ref *ref = getnext;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +0100970
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +0100971 while (1) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +0100972
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100973 /* Get next list entry. */
974 ref = LIST_NEXT(&ref->list, struct pat_ref *, list);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +0100975
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100976 /* If the entry is the last of the list, return NULL. */
977 if (&ref->list == end)
978 return NULL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +0100979
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100980 /* If the entry match the flag, return it. */
981 if (ref->flags & flags)
982 return ref;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +0100983 }
984}
985
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +0100986static inline
987struct pat_ref *pat_ref_lookup_ref(const char *reference)
988{
989 int id;
990 char *error;
991
992 /* If the reference starts by a '#', this is numeric id. */
993 if (reference[0] == '#') {
994 /* Try to convert the numeric id. If the conversion fails, the lookup fails. */
995 id = strtol(reference + 1, &error, 10);
996 if (*error != '\0')
997 return NULL;
998
999 /* Perform the unique id lookup. */
1000 return pat_ref_lookupid(id);
1001 }
1002
1003 /* Perform the string lookup. */
1004 return pat_ref_lookup(reference);
1005}
1006
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001007/* This function is used with map and acl management. It permits to browse
1008 * each reference.
1009 */
1010static inline
1011struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end)
1012{
1013 struct pattern_expr *expr;
Thierry FOURNIERc5959fd2014-01-20 14:29:33 +01001014 expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list);
1015 if (&expr->list == end)
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001016 return NULL;
1017 return expr;
1018}
1019
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001020/* Processes the stats interpreter on the statistics socket. This function is
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001021 * called from an applet running in a stream interface. The function returns 1
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001022 * if the request was understood, otherwise zero. It sets appctx->st0 to a value
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001023 * designating the function which will have to process the request, which can
1024 * also be the print function to display the return message set into cli.msg.
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001025 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001026static int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001027{
Willy Tarreau306f8302013-07-08 15:53:06 +02001028 struct session *s = session_from_task(si->owner);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001029 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001030 char *args[MAX_STATS_ARGS + 1];
1031 int arg;
Thierry FOURNIER48bcfda2013-12-10 18:54:58 +01001032 int i, j;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001033
1034 while (isspace((unsigned char)*line))
1035 line++;
1036
1037 arg = 0;
1038 args[arg] = line;
1039
1040 while (*line && arg < MAX_STATS_ARGS) {
Thierry FOURNIER48bcfda2013-12-10 18:54:58 +01001041 if (*line == '\\') {
1042 line++;
1043 if (*line == '\0')
1044 break;
1045 }
1046 else if (isspace((unsigned char)*line)) {
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001047 *line++ = '\0';
1048
1049 while (isspace((unsigned char)*line))
1050 line++;
1051
1052 args[++arg] = line;
1053 continue;
1054 }
1055
1056 line++;
1057 }
1058
1059 while (++arg <= MAX_STATS_ARGS)
1060 args[arg] = line;
1061
Thierry FOURNIER48bcfda2013-12-10 18:54:58 +01001062 /* remove \ */
1063 arg = 0;
1064 while (*args[arg] != '\0') {
1065 j = 0;
1066 for (i=0; args[arg][i] != '\0'; i++) {
1067 if (args[arg][i] == '\\')
1068 continue;
1069 args[arg][j] = args[arg][i];
1070 j++;
1071 }
1072 args[arg][j] = '\0';
1073 arg++;
1074 }
1075
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001076 appctx->ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001077 if (strcmp(args[0], "show") == 0) {
1078 if (strcmp(args[1], "stat") == 0) {
1079 if (*args[2] && *args[3] && *args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001080 appctx->ctx.stats.flags |= STAT_BOUND;
1081 appctx->ctx.stats.iid = atoi(args[2]);
1082 appctx->ctx.stats.type = atoi(args[3]);
1083 appctx->ctx.stats.sid = atoi(args[4]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001084 }
1085
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001086 appctx->st2 = STAT_ST_INIT;
1087 appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001088 }
1089 else if (strcmp(args[1], "info") == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001090 appctx->st2 = STAT_ST_INIT;
1091 appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001092 }
Willy Tarreau12833bb2014-01-28 16:49:56 +01001093 else if (strcmp(args[1], "pools") == 0) {
1094 appctx->st2 = STAT_ST_INIT;
1095 appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer
1096 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001097 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001098 appctx->st2 = STAT_ST_INIT;
Willy Tarreau290e63a2012-09-20 18:07:14 +02001099 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001100 appctx->ctx.cli.msg = stats_permission_denied_msg;
1101 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +02001102 return 1;
1103 }
Willy Tarreau76153662012-11-26 01:16:39 +01001104 if (*args[2] && strcmp(args[2], "all") == 0)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001105 appctx->ctx.sess.target = (void *)-1;
Willy Tarreau76153662012-11-26 01:16:39 +01001106 else if (*args[2])
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001107 appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01001108 else
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001109 appctx->ctx.sess.target = NULL;
1110 appctx->ctx.sess.section = 0; /* start with session status */
1111 appctx->ctx.sess.pos = 0;
1112 appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001113 }
1114 else if (strcmp(args[1], "errors") == 0) {
Willy Tarreau290e63a2012-09-20 18:07:14 +02001115 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001116 appctx->ctx.cli.msg = stats_permission_denied_msg;
1117 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +02001118 return 1;
1119 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001120 if (*args[2])
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001121 appctx->ctx.errors.iid = atoi(args[2]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001122 else
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001123 appctx->ctx.errors.iid = -1;
1124 appctx->ctx.errors.px = NULL;
1125 appctx->st2 = STAT_ST_INIT;
1126 appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001127 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02001128 else if (strcmp(args[1], "table") == 0) {
Willy Tarreaudec98142012-06-06 23:37:08 +02001129 stats_sock_table_request(si, args, STAT_CLI_O_TAB);
Willy Tarreau69f58c82010-07-12 17:55:33 +02001130 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001131 else if (strcmp(args[1], "map") == 0 ||
1132 strcmp(args[1], "acl") == 0) {
1133
1134 /* Set ACL or MAP flags. */
1135 if (args[1][0] == 'm')
1136 appctx->ctx.map.display_flags = PAT_REF_MAP;
1137 else
1138 appctx->ctx.map.display_flags = PAT_REF_ACL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001139
1140 /* no parameter: display all map avalaible */
1141 if (!*args[2]) {
1142 appctx->st2 = STAT_ST_INIT;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001143 appctx->st0 = STAT_CLI_O_PATS;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001144 return 1;
1145 }
1146
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001147 /* lookup into the refs and check the map flag */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001148 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001149 if (!appctx->ctx.map.ref ||
1150 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
1151 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001152 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001153 else
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001154 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001155 appctx->st0 = STAT_CLI_PRINT;
1156 return 1;
1157 }
1158 appctx->st2 = STAT_ST_INIT;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001159 appctx->st0 = STAT_CLI_O_PAT;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001160 }
Aman Guptaceafb4a2012-04-02 18:57:54 -07001161 else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001162 return 0;
1163 }
1164 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001165 else if (strcmp(args[0], "clear") == 0) {
1166 if (strcmp(args[1], "counters") == 0) {
1167 struct proxy *px;
1168 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001169 struct listener *li;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001170 int clrall = 0;
1171
1172 if (strcmp(args[2], "all") == 0)
1173 clrall = 1;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001174
Willy Tarreau6162db22009-10-10 17:13:00 +02001175 /* check permissions */
Willy Tarreau290e63a2012-09-20 18:07:14 +02001176 if (s->listener->bind_conf->level < ACCESS_LVL_OPER ||
1177 (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001178 appctx->ctx.cli.msg = stats_permission_denied_msg;
1179 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +02001180 return 1;
1181 }
1182
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001183 for (px = proxy; px; px = px->next) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001184 if (clrall) {
1185 memset(&px->be_counters, 0, sizeof(px->be_counters));
1186 memset(&px->fe_counters, 0, sizeof(px->fe_counters));
1187 }
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001188 else {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001189 px->be_counters.conn_max = 0;
1190 px->be_counters.p.http.rps_max = 0;
1191 px->be_counters.sps_max = 0;
1192 px->be_counters.cps_max = 0;
1193 px->be_counters.nbpend_max = 0;
1194
1195 px->fe_counters.conn_max = 0;
1196 px->fe_counters.p.http.rps_max = 0;
1197 px->fe_counters.sps_max = 0;
1198 px->fe_counters.cps_max = 0;
1199 px->fe_counters.nbpend_max = 0;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001200 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001201
1202 for (sv = px->srv; sv; sv = sv->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001203 if (clrall)
1204 memset(&sv->counters, 0, sizeof(sv->counters));
1205 else {
1206 sv->counters.cur_sess_max = 0;
1207 sv->counters.nbpend_max = 0;
1208 sv->counters.sps_max = 0;
1209 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001210
Willy Tarreaua7944ad2012-09-26 21:03:11 +02001211 list_for_each_entry(li, &px->conf.listeners, by_fe)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001212 if (li->counters) {
1213 if (clrall)
1214 memset(li->counters, 0, sizeof(*li->counters));
1215 else
1216 li->counters->conn_max = 0;
1217 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001218 }
1219
Willy Tarreau81c25d02011-09-07 15:17:21 +02001220 global.cps_max = 0;
Willy Tarreau93e7c002013-10-07 18:51:07 +02001221 global.sps_max = 0;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001222 return 1;
1223 }
Willy Tarreau88ee3972010-07-13 13:48:00 +02001224 else if (strcmp(args[1], "table") == 0) {
Willy Tarreaudec98142012-06-06 23:37:08 +02001225 stats_sock_table_request(si, args, STAT_CLI_O_CLR);
Willy Tarreau88ee3972010-07-13 13:48:00 +02001226 /* end of processing */
1227 return 1;
1228 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001229 else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
1230 /* Set ACL or MAP flags. */
1231 if (args[1][0] == 'm')
1232 appctx->ctx.map.display_flags = PAT_REF_MAP;
1233 else
1234 appctx->ctx.map.display_flags = PAT_REF_ACL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001235
1236 /* no parameter */
1237 if (!*args[2]) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001238 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
1239 appctx->ctx.cli.msg = "Missing map identifier.\n";
1240 else
1241 appctx->ctx.cli.msg = "Missing ACL identifier.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001242 appctx->st0 = STAT_CLI_PRINT;
1243 return 1;
1244 }
1245
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001246 /* lookup into the refs and check the map flag */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001247 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001248 if (!appctx->ctx.map.ref ||
1249 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
1250 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001251 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001252 else
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001253 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001254 appctx->st0 = STAT_CLI_PRINT;
1255 return 1;
1256 }
1257
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001258 /* Clear all. */
1259 pat_ref_prune(appctx->ctx.map.ref);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001260
1261 /* return response */
1262 appctx->ctx.cli.msg = "Done.\n";
1263 appctx->st0 = STAT_CLI_PRINT;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001264 return 1;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001265 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001266 else {
Willy Tarreau88ee3972010-07-13 13:48:00 +02001267 /* unknown "clear" argument */
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001268 return 0;
1269 }
1270 }
Willy Tarreau38338fa2009-10-10 18:37:29 +02001271 else if (strcmp(args[0], "get") == 0) {
1272 if (strcmp(args[1], "weight") == 0) {
1273 struct proxy *px;
1274 struct server *sv;
1275
1276 /* split "backend/server" and make <line> point to server */
1277 for (line = args[2]; *line; line++)
1278 if (*line == '/') {
1279 *line++ = '\0';
1280 break;
1281 }
1282
1283 if (!*line) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001284 appctx->ctx.cli.msg = "Require 'backend/server'.\n";
1285 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +02001286 return 1;
1287 }
1288
1289 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001290 appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
1291 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +02001292 return 1;
1293 }
1294
1295 /* return server's effective weight at the moment */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001296 snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight);
1297 bi_putstr(si->ib, trash.str);
Willy Tarreau38338fa2009-10-10 18:37:29 +02001298 return 1;
1299 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001300 else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
1301 /* Set flags. */
1302 if (args[1][0] == 'm')
1303 appctx->ctx.map.display_flags = PAT_REF_MAP;
1304 else
1305 appctx->ctx.map.display_flags = PAT_REF_ACL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001306
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001307 /* No parameter. */
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001308 if (!*args[2] || !*args[3]) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001309 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
1310 appctx->ctx.cli.msg = "Missing map identifier and/or key.\n";
1311 else
1312 appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001313 appctx->st0 = STAT_CLI_PRINT;
1314 return 1;
1315 }
1316
1317 /* lookup into the maps */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001318 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001319 if (!appctx->ctx.map.ref) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001320 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001321 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001322 else
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001323 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001324 appctx->st0 = STAT_CLI_PRINT;
1325 return 1;
1326 }
1327
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001328 /* copy input string. The string must be allocated because
1329 * it may be used over multiple iterations. It's released
1330 * at the end and upon abort anyway.
1331 */
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001332 appctx->ctx.map.chunk.len = strlen(args[3]);
1333 appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1;
1334 appctx->ctx.map.chunk.str = strdup(args[3]);
1335 if (!appctx->ctx.map.chunk.str) {
1336 appctx->ctx.cli.msg = "Out of memory error.\n";
1337 appctx->st0 = STAT_CLI_PRINT;
1338 return 1;
1339 }
1340
1341 /* prepare response */
1342 appctx->st2 = STAT_ST_INIT;
1343 appctx->st0 = STAT_CLI_O_MLOOK;
1344 }
Willy Tarreau38338fa2009-10-10 18:37:29 +02001345 else { /* not "get weight" */
1346 return 0;
1347 }
1348 }
Willy Tarreau4483d432009-10-10 19:30:08 +02001349 else if (strcmp(args[0], "set") == 0) {
1350 if (strcmp(args[1], "weight") == 0) {
Willy Tarreau4483d432009-10-10 19:30:08 +02001351 struct server *sv;
Simon Horman7d09b9a2013-02-12 10:45:51 +09001352 const char *warning;
Willy Tarreau4483d432009-10-10 19:30:08 +02001353
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001354 sv = expect_server_admin(s, si, args[2]);
1355 if (!sv)
Willy Tarreau4483d432009-10-10 19:30:08 +02001356 return 1;
Willy Tarreau4483d432009-10-10 19:30:08 +02001357
Simon Horman7d09b9a2013-02-12 10:45:51 +09001358 warning = server_parse_weight_change_request(sv, args[3]);
Simon Horman8c3d0be2013-11-25 10:46:40 +09001359 /*
1360 * The user-weight may now be zero and thus
1361 * the server considered to be draining.
1362 * Update the server's drain state as necessary.
1363 */
1364 set_server_drain_state(sv);
Simon Horman7d09b9a2013-02-12 10:45:51 +09001365 if (warning) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001366 appctx->ctx.cli.msg = warning;
1367 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001368 }
Willy Tarreau4483d432009-10-10 19:30:08 +02001369 return 1;
1370 }
Willy Tarreau7aabd112010-01-26 10:59:06 +01001371 else if (strcmp(args[1], "timeout") == 0) {
1372 if (strcmp(args[2], "cli") == 0) {
1373 unsigned timeout;
1374 const char *res;
1375
1376 if (!*args[3]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001377 appctx->ctx.cli.msg = "Expects an integer value.\n";
1378 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001379 return 1;
1380 }
1381
1382 res = parse_time_err(args[3], &timeout, TIME_UNIT_S);
1383 if (res || timeout < 1) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001384 appctx->ctx.cli.msg = "Invalid timeout value.\n";
1385 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001386 return 1;
1387 }
1388
1389 s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000);
1390 return 1;
1391 }
1392 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001393 appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n";
1394 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001395 return 1;
1396 }
1397 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001398 else if (strcmp(args[1], "maxconn") == 0) {
1399 if (strcmp(args[2], "frontend") == 0) {
1400 struct proxy *px;
1401 struct listener *l;
1402 int v;
1403
Willy Tarreau532a4502011-09-07 22:37:44 +02001404 px = expect_frontend_admin(s, si, args[3]);
1405 if (!px)
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001406 return 1;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001407
1408 if (!*args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001409 appctx->ctx.cli.msg = "Integer value expected.\n";
1410 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001411 return 1;
1412 }
1413
1414 v = atoi(args[4]);
Willy Tarreau3c7a79d2012-09-26 21:07:15 +02001415 if (v < 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001416 appctx->ctx.cli.msg = "Value out of range.\n";
1417 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001418 return 1;
1419 }
1420
1421 /* OK, the value is fine, so we assign it to the proxy and to all of
1422 * its listeners. The blocked ones will be dequeued.
1423 */
1424 px->maxconn = v;
Willy Tarreaua7944ad2012-09-26 21:03:11 +02001425 list_for_each_entry(l, &px->conf.listeners, by_fe) {
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001426 l->maxconn = v;
1427 if (l->state == LI_FULL)
1428 resume_listener(l);
1429 }
1430
1431 if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue))
1432 dequeue_all_listeners(&s->fe->listener_queue);
1433
1434 return 1;
1435 }
Willy Tarreau91886b62011-09-07 14:38:31 +02001436 else if (strcmp(args[2], "global") == 0) {
1437 int v;
1438
Willy Tarreau290e63a2012-09-20 18:07:14 +02001439 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001440 appctx->ctx.cli.msg = stats_permission_denied_msg;
1441 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau91886b62011-09-07 14:38:31 +02001442 return 1;
1443 }
1444
1445 if (!*args[3]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001446 appctx->ctx.cli.msg = "Expects an integer value.\n";
1447 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau91886b62011-09-07 14:38:31 +02001448 return 1;
1449 }
1450
1451 v = atoi(args[3]);
1452 if (v > global.hardmaxconn) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001453 appctx->ctx.cli.msg = "Value out of range.\n";
1454 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau91886b62011-09-07 14:38:31 +02001455 return 1;
1456 }
1457
1458 /* check for unlimited values */
1459 if (v <= 0)
1460 v = global.hardmaxconn;
1461
1462 global.maxconn = v;
1463
1464 /* Dequeues all of the listeners waiting for a resource */
1465 if (!LIST_ISEMPTY(&global_listener_queue))
1466 dequeue_all_listeners(&global_listener_queue);
1467
1468 return 1;
1469 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001470 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001471 appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n";
1472 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001473 return 1;
1474 }
1475 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001476 else if (strcmp(args[1], "rate-limit") == 0) {
1477 if (strcmp(args[2], "connections") == 0) {
1478 if (strcmp(args[3], "global") == 0) {
1479 int v;
1480
Willy Tarreau290e63a2012-09-20 18:07:14 +02001481 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001482 appctx->ctx.cli.msg = stats_permission_denied_msg;
1483 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001484 return 1;
1485 }
1486
1487 if (!*args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001488 appctx->ctx.cli.msg = "Expects an integer value.\n";
1489 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001490 return 1;
1491 }
1492
1493 v = atoi(args[4]);
1494 if (v < 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001495 appctx->ctx.cli.msg = "Value out of range.\n";
1496 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001497 return 1;
1498 }
1499
1500 global.cps_lim = v;
1501
1502 /* Dequeues all of the listeners waiting for a resource */
1503 if (!LIST_ISEMPTY(&global_listener_queue))
1504 dequeue_all_listeners(&global_listener_queue);
1505
1506 return 1;
1507 }
1508 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001509 appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n";
1510 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001511 return 1;
1512 }
1513 }
Willy Tarreau93e7c002013-10-07 18:51:07 +02001514 else if (strcmp(args[2], "sessions") == 0) {
1515 if (strcmp(args[3], "global") == 0) {
1516 int v;
1517
1518 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
1519 appctx->ctx.cli.msg = stats_permission_denied_msg;
1520 appctx->st0 = STAT_CLI_PRINT;
1521 return 1;
1522 }
1523
1524 if (!*args[4]) {
1525 appctx->ctx.cli.msg = "Expects an integer value.\n";
1526 appctx->st0 = STAT_CLI_PRINT;
1527 return 1;
1528 }
1529
1530 v = atoi(args[4]);
1531 if (v < 0) {
1532 appctx->ctx.cli.msg = "Value out of range.\n";
1533 appctx->st0 = STAT_CLI_PRINT;
1534 return 1;
1535 }
1536
1537 global.sps_lim = v;
1538
1539 /* Dequeues all of the listeners waiting for a resource */
1540 if (!LIST_ISEMPTY(&global_listener_queue))
1541 dequeue_all_listeners(&global_listener_queue);
1542
1543 return 1;
1544 }
1545 else {
1546 appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n";
1547 appctx->st0 = STAT_CLI_PRINT;
1548 return 1;
1549 }
1550 }
Willy Tarreaue43d5322013-10-07 20:01:52 +02001551#ifdef USE_OPENSSL
1552 else if (strcmp(args[2], "ssl-sessions") == 0) {
1553 if (strcmp(args[3], "global") == 0) {
1554 int v;
1555
1556 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
1557 appctx->ctx.cli.msg = stats_permission_denied_msg;
1558 appctx->st0 = STAT_CLI_PRINT;
1559 return 1;
1560 }
1561
1562 if (!*args[4]) {
1563 appctx->ctx.cli.msg = "Expects an integer value.\n";
1564 appctx->st0 = STAT_CLI_PRINT;
1565 return 1;
1566 }
1567
1568 v = atoi(args[4]);
1569 if (v < 0) {
1570 appctx->ctx.cli.msg = "Value out of range.\n";
1571 appctx->st0 = STAT_CLI_PRINT;
1572 return 1;
1573 }
1574
1575 global.ssl_lim = v;
1576
1577 /* Dequeues all of the listeners waiting for a resource */
1578 if (!LIST_ISEMPTY(&global_listener_queue))
1579 dequeue_all_listeners(&global_listener_queue);
1580
1581 return 1;
1582 }
1583 else {
1584 appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n";
1585 appctx->st0 = STAT_CLI_PRINT;
1586 return 1;
1587 }
1588 }
1589#endif
William Lallemandd85f9172012-11-09 17:05:39 +01001590 else if (strcmp(args[2], "http-compression") == 0) {
1591 if (strcmp(args[3], "global") == 0) {
1592 int v;
1593
Willy Tarreau85d47f92012-11-21 00:29:50 +01001594 if (!*args[4]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001595 appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n";
1596 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau85d47f92012-11-21 00:29:50 +01001597 return 1;
1598 }
1599
William Lallemandd85f9172012-11-09 17:05:39 +01001600 v = atoi(args[4]);
1601 global.comp_rate_lim = v * 1024; /* Kilo to bytes. */
1602 }
1603 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001604 appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n";
1605 appctx->st0 = STAT_CLI_PRINT;
William Lallemandd85f9172012-11-09 17:05:39 +01001606 return 1;
1607 }
1608 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001609 else {
Willy Tarreaue43d5322013-10-07 20:01:52 +02001610 appctx->ctx.cli.msg = "'set rate-limit' supports 'connections', 'sessions', 'ssl-sessions', and 'http-compression'.\n";
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001611 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauf5b22872011-09-07 16:13:44 +02001612 return 1;
1613 }
1614 }
Willy Tarreau654694e2012-06-07 01:03:16 +02001615 else if (strcmp(args[1], "table") == 0) {
1616 stats_sock_table_request(si, args, STAT_CLI_O_SET);
1617 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001618 else if (strcmp(args[1], "map") == 0) {
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01001619 char *err;
1620
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001621 /* Set flags. */
1622 appctx->ctx.map.display_flags = PAT_REF_MAP;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001623
1624 /* Expect three parameters: map name, key and new value. */
1625 if (!*args[2] || !*args[3] || !*args[4]) {
Thierry FOURNIERd5723432014-03-11 13:52:44 +01001626 appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001627 appctx->st0 = STAT_CLI_PRINT;
1628 return 1;
1629 }
1630
1631 /* Lookup the reference in the maps. */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001632 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001633 if (!appctx->ctx.map.ref) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001634 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001635 appctx->st0 = STAT_CLI_PRINT;
1636 return 1;
1637 }
1638
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001639 /* If the entry identifier start with a '#', it is considered as
1640 * pointer id
1641 */
1642 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
1643 struct pat_ref_elt *ref;
1644 long long int conv;
1645 char *error;
1646
1647 /* Convert argument to integer value. */
1648 conv = strtoll(&args[3][1], &error, 16);
1649 if (*error != '\0') {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001650 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001651 appctx->st0 = STAT_CLI_PRINT;
1652 return 1;
1653 }
1654
1655 /* Convert and check integer to pointer. */
1656 ref = (struct pat_ref_elt *)(long)conv;
1657 if ((long long int)(long)ref != conv) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001658 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001659 appctx->st0 = STAT_CLI_PRINT;
1660 return 1;
1661 }
1662
1663 /* Try to delete the entry. */
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01001664 err = NULL;
1665 if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) {
1666 if (err)
1667 memprintf(&err, "%s.\n", err);
1668 appctx->ctx.cli.err = err;
1669 appctx->st0 = STAT_CLI_PRINT_FREE;
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001670 return 1;
1671 }
1672 }
1673 else {
1674 /* Else, use the entry identifier as pattern
1675 * string, and update the value.
1676 */
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01001677 err = NULL;
1678 if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) {
1679 if (err)
1680 memprintf(&err, "%s.\n", err);
1681 appctx->ctx.cli.err = err;
1682 appctx->st0 = STAT_CLI_PRINT_FREE;
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001683 return 1;
1684 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001685 }
1686
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001687 /* The set is done, send message. */
1688 appctx->ctx.cli.msg = "Done.\n";
1689 appctx->st0 = STAT_CLI_PRINT;
1690 return 1;
1691 }
Willy Tarreau7aabd112010-01-26 10:59:06 +01001692 else { /* unknown "set" parameter */
Willy Tarreau4483d432009-10-10 19:30:08 +02001693 return 0;
1694 }
1695 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001696 else if (strcmp(args[0], "enable") == 0) {
Simon Horman671b6f02013-11-25 10:46:39 +09001697 if (strcmp(args[1], "agent") == 0) {
1698 struct server *sv;
1699
1700 sv = expect_server_admin(s, si, args[2]);
1701 if (!sv)
1702 return 1;
1703
Willy Tarreau2e10f5a2013-12-11 20:11:55 +01001704 if (!(sv->agent.state & CHK_ST_CONFIGURED)) {
1705 appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n";
1706 appctx->st0 = STAT_CLI_PRINT;
1707 return 1;
1708 }
1709
1710 sv->agent.state |= CHK_ST_ENABLED;
Simon Horman671b6f02013-11-25 10:46:39 +09001711 return 1;
1712 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001713 if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001714 struct server *sv;
1715
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001716 sv = expect_server_admin(s, si, args[2]);
1717 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01001718 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001719
Cyril Bontécd19e512010-01-31 22:34:03 +01001720 if (sv->state & SRV_MAINTAIN) {
1721 /* The server is really in maintenance, we can change the server state */
Willy Tarreau44267702011-10-28 15:35:33 +02001722 if (sv->track) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001723 /* If this server tracks the status of another one,
1724 * we must restore the good status.
1725 */
Willy Tarreau44267702011-10-28 15:35:33 +02001726 if (sv->track->state & SRV_RUNNING) {
Simon Horman4a741432013-02-23 15:35:38 +09001727 set_server_up(&sv->check);
Simon Horman58c32972013-11-25 10:46:38 +09001728 sv->check.health = sv->check.rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +01001729 } else {
1730 sv->state &= ~SRV_MAINTAIN;
Willy Tarreau33a08db2013-12-11 21:03:31 +01001731 sv->check.state &= ~CHK_ST_PAUSED;
Simon Horman4a741432013-02-23 15:35:38 +09001732 set_server_down(&sv->check);
Cyril Bontécd19e512010-01-31 22:34:03 +01001733 }
1734 } else {
Simon Horman4a741432013-02-23 15:35:38 +09001735 set_server_up(&sv->check);
Simon Horman58c32972013-11-25 10:46:38 +09001736 sv->check.health = sv->check.rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +01001737 }
1738 }
1739
Willy Tarreau532a4502011-09-07 22:37:44 +02001740 return 1;
1741 }
1742 else if (strcmp(args[1], "frontend") == 0) {
1743 struct proxy *px;
1744
1745 px = expect_frontend_admin(s, si, args[2]);
1746 if (!px)
1747 return 1;
1748
1749 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001750 appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n";
1751 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02001752 return 1;
1753 }
1754
1755 if (px->state != PR_STPAUSED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001756 appctx->ctx.cli.msg = "Frontend is already enabled.\n";
1757 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02001758 return 1;
1759 }
1760
1761 if (!resume_proxy(px)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001762 appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n";
1763 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02001764 return 1;
1765 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001766 return 1;
1767 }
1768 else { /* unknown "enable" parameter */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001769 appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n";
1770 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02001771 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01001772 }
1773 }
1774 else if (strcmp(args[0], "disable") == 0) {
Simon Horman671b6f02013-11-25 10:46:39 +09001775 if (strcmp(args[1], "agent") == 0) {
1776 struct server *sv;
1777
1778 sv = expect_server_admin(s, si, args[2]);
1779 if (!sv)
1780 return 1;
1781
Willy Tarreau2e10f5a2013-12-11 20:11:55 +01001782 sv->agent.state &= ~CHK_ST_ENABLED;
Simon Horman671b6f02013-11-25 10:46:39 +09001783 return 1;
1784 }
1785 else if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001786 struct server *sv;
1787
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001788 sv = expect_server_admin(s, si, args[2]);
1789 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01001790 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001791
Cyril Bontécd19e512010-01-31 22:34:03 +01001792 if (! (sv->state & SRV_MAINTAIN)) {
1793 /* Not already in maintenance, we can change the server state */
1794 sv->state |= SRV_MAINTAIN;
Willy Tarreau33a08db2013-12-11 21:03:31 +01001795 sv->check.state |= CHK_ST_PAUSED;
Simon Horman4a741432013-02-23 15:35:38 +09001796 set_server_down(&sv->check);
Cyril Bontécd19e512010-01-31 22:34:03 +01001797 }
1798
Willy Tarreau532a4502011-09-07 22:37:44 +02001799 return 1;
1800 }
1801 else if (strcmp(args[1], "frontend") == 0) {
1802 struct proxy *px;
1803
1804 px = expect_frontend_admin(s, si, args[2]);
1805 if (!px)
1806 return 1;
1807
1808 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001809 appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n";
1810 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02001811 return 1;
1812 }
1813
1814 if (px->state == PR_STPAUSED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001815 appctx->ctx.cli.msg = "Frontend is already disabled.\n";
1816 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02001817 return 1;
1818 }
1819
1820 if (!pause_proxy(px)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001821 appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n";
1822 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02001823 return 1;
1824 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001825 return 1;
1826 }
1827 else { /* unknown "disable" parameter */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001828 appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n";
1829 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02001830 return 1;
1831 }
1832 }
1833 else if (strcmp(args[0], "shutdown") == 0) {
1834 if (strcmp(args[1], "frontend") == 0) {
1835 struct proxy *px;
1836
1837 px = expect_frontend_admin(s, si, args[2]);
1838 if (!px)
1839 return 1;
1840
1841 if (px->state == PR_STSTOPPED) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001842 appctx->ctx.cli.msg = "Frontend was already shut down.\n";
1843 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02001844 return 1;
1845 }
1846
1847 Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
1848 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
1849 send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
1850 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
1851 stop_proxy(px);
1852 return 1;
1853 }
Willy Tarreaua295edc2011-09-07 23:21:03 +02001854 else if (strcmp(args[1], "session") == 0) {
1855 struct session *sess, *ptr;
1856
Willy Tarreau290e63a2012-09-20 18:07:14 +02001857 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001858 appctx->ctx.cli.msg = stats_permission_denied_msg;
1859 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaua295edc2011-09-07 23:21:03 +02001860 return 1;
1861 }
1862
1863 if (!*args[2]) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001864 appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n";
1865 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaua295edc2011-09-07 23:21:03 +02001866 return 1;
1867 }
1868
1869 ptr = (void *)strtoul(args[2], NULL, 0);
1870
1871 /* first, look for the requested session in the session table */
1872 list_for_each_entry(sess, &sessions, list) {
1873 if (sess == ptr)
1874 break;
1875 }
1876
1877 /* do we have the session ? */
1878 if (sess != ptr) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001879 appctx->ctx.cli.msg = "No such session (use 'show sess').\n";
1880 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreaua295edc2011-09-07 23:21:03 +02001881 return 1;
1882 }
1883
1884 session_shutdown(sess, SN_ERR_KILLED);
1885 return 1;
1886 }
Willy Tarreau52b2d222011-09-07 23:48:48 +02001887 else if (strcmp(args[1], "sessions") == 0) {
1888 if (strcmp(args[2], "server") == 0) {
1889 struct server *sv;
1890 struct session *sess, *sess_bck;
1891
1892 sv = expect_server_admin(s, si, args[3]);
1893 if (!sv)
1894 return 1;
1895
1896 /* kill all the session that are on this server */
1897 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
1898 if (sess->srv_conn == sv)
1899 session_shutdown(sess, SN_ERR_KILLED);
1900
1901 return 1;
1902 }
1903 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001904 appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n";
1905 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau52b2d222011-09-07 23:48:48 +02001906 return 1;
1907 }
1908 }
Willy Tarreau532a4502011-09-07 22:37:44 +02001909 else { /* unknown "disable" parameter */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01001910 appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n";
1911 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau532a4502011-09-07 22:37:44 +02001912 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01001913 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001914 }
1915 else if (strcmp(args[0], "del") == 0) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001916 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
1917 if (args[1][0] == 'm')
1918 appctx->ctx.map.display_flags = PAT_REF_MAP;
1919 else
1920 appctx->ctx.map.display_flags = PAT_REF_ACL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001921
1922 /* Expect two parameters: map name and key. */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001923 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
1924 if (!*args[2] || !*args[3]) {
1925 appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n";
1926 appctx->st0 = STAT_CLI_PRINT;
1927 return 1;
1928 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001929 }
1930
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001931 else {
1932 if (!*args[2] || !*args[3]) {
1933 appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n";
1934 appctx->st0 = STAT_CLI_PRINT;
1935 return 1;
1936 }
1937 }
1938
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001939 /* Lookup the reference in the maps. */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01001940 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001941 if (!appctx->ctx.map.ref ||
1942 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001943 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001944 appctx->st0 = STAT_CLI_PRINT;
1945 return 1;
1946 }
1947
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001948 /* If the entry identifier start with a '#', it is considered as
1949 * pointer id
1950 */
1951 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
1952 struct pat_ref_elt *ref;
1953 long long int conv;
1954 char *error;
1955
1956 /* Convert argument to integer value. */
1957 conv = strtoll(&args[3][1], &error, 16);
1958 if (*error != '\0') {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001959 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001960 appctx->st0 = STAT_CLI_PRINT;
1961 return 1;
1962 }
1963
1964 /* Convert and check integer to pointer. */
1965 ref = (struct pat_ref_elt *)(long)conv;
1966 if ((long long int)(long)ref != conv) {
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01001967 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER9356c682014-01-28 15:55:37 +01001968 appctx->st0 = STAT_CLI_PRINT;
1969 return 1;
1970 }
1971
1972 /* Try to delete the entry. */
1973 if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) {
1974 /* The entry is not found, send message. */
1975 appctx->ctx.cli.msg = "Key not found.\n";
1976 appctx->st0 = STAT_CLI_PRINT;
1977 return 1;
1978 }
1979 }
1980 else {
1981 /* Else, use the entry identifier as pattern
1982 * string and try to delete the entry.
1983 */
1984 if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) {
1985 /* The entry is not found, send message. */
1986 appctx->ctx.cli.msg = "Key not found.\n";
1987 appctx->st0 = STAT_CLI_PRINT;
1988 return 1;
1989 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001990 }
1991
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001992 /* The deletion is done, send message. */
1993 appctx->ctx.cli.msg = "Done.\n";
1994 appctx->st0 = STAT_CLI_PRINT;
1995 return 1;
1996 }
1997 else { /* unknown "del" parameter */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01001998 appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01001999 appctx->st0 = STAT_CLI_PRINT;
2000 return 1;
2001 }
2002 }
2003 else if (strcmp(args[0], "add") == 0) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002004 if (strcmp(args[1], "map") == 0 ||
2005 strcmp(args[1], "acl") == 0) {
2006 int ret;
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002007 char *err;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002008
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002009 /* Set flags. */
2010 if (args[1][0] == 'm')
2011 appctx->ctx.map.display_flags = PAT_REF_MAP;
2012 else
2013 appctx->ctx.map.display_flags = PAT_REF_ACL;
2014
2015 /* If the keywork is "map", we expect three parameters, if it
2016 * is "acl", we expect only two parameters
2017 */
2018 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
2019 if (!*args[2] || !*args[3] || !*args[4]) {
2020 appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n";
2021 appctx->st0 = STAT_CLI_PRINT;
2022 return 1;
2023 }
2024 }
2025 else {
2026 if (!*args[2] || !*args[3]) {
2027 appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n";
2028 appctx->st0 = STAT_CLI_PRINT;
2029 return 1;
2030 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002031 }
2032
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002033 /* Lookup for the reference. */
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01002034 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002035 if (!appctx->ctx.map.ref) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002036 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002037 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002038 else
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01002039 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002040 appctx->st0 = STAT_CLI_PRINT;
2041 return 1;
2042 }
2043
Thierry FOURNIER64c585f2014-01-29 20:02:36 +01002044 /* The command "add acl" is prohibited if the reference
2045 * use samples.
2046 */
2047 if ((appctx->ctx.map.display_flags & PAT_REF_ACL) &&
2048 (appctx->ctx.map.ref->flags & PAT_REF_SMP)) {
2049 appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. "
2050 "You must use the command 'add map' to add values.\n";
2051 appctx->st0 = STAT_CLI_PRINT;
2052 return 1;
2053 }
2054
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002055 /* Add value. */
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002056 err = NULL;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002057 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002058 ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], &err);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002059 else
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002060 ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002061 if (!ret) {
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002062 if (err)
2063 memprintf(&err, "%s.\n", err);
2064 appctx->ctx.cli.err = err;
2065 appctx->st0 = STAT_CLI_PRINT_FREE;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002066 return 1;
2067 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002068
2069 /* The add is done, send message. */
2070 appctx->ctx.cli.msg = "Done.\n";
2071 appctx->st0 = STAT_CLI_PRINT;
2072 return 1;
2073 }
2074 else { /* unknown "del" parameter */
2075 appctx->ctx.cli.msg = "'add' only supports 'map'.\n";
2076 appctx->st0 = STAT_CLI_PRINT;
2077 return 1;
2078 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002079 }
2080 else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002081 return 0;
2082 }
2083 return 1;
2084}
2085
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002086/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002087 * used to processes I/O from/to the stats unix socket. The system relies on a
2088 * state machine handling requests and various responses. We read a request,
2089 * then we process it and send the response, and we possibly display a prompt.
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002090 * Then we can read again. The state is stored in appctx->st0 and is one of the
2091 * STAT_CLI_* constants. appctx->st1 is used to indicate whether prompt is enabled
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002092 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002093 */
Willy Tarreaub24281b2011-02-13 13:16:36 +01002094static void cli_io_handler(struct stream_interface *si)
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002095{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002096 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau7421efb2012-07-02 15:11:27 +02002097 struct channel *req = si->ob;
2098 struct channel *res = si->ib;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002099 int reql;
2100 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002101
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002102 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2103 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002104
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002105 while (1) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002106 if (appctx->st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002107 /* Stats output not initialized yet */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002108 memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats));
2109 appctx->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002110 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002111 else if (appctx->st0 == STAT_CLI_END) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002112 /* Let's close for real now. We just close the request
2113 * side, the conditions below will complete if needed.
2114 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02002115 si_shutw(si);
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002116 break;
2117 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002118 else if (appctx->st0 == STAT_CLI_GETREQ) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02002119 /* ensure we have some output room left in the event we
2120 * would want to return some info right after parsing.
2121 */
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01002122 if (buffer_almost_full(si->ib->buf)) {
2123 si->ib->flags |= CF_WAKE_WRITE;
Willy Tarreau4e33d862009-10-11 23:35:10 +02002124 break;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01002125 }
Willy Tarreau4e33d862009-10-11 23:35:10 +02002126
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002127 reql = bo_getline(si->ob, trash.str, trash.size);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002128 if (reql <= 0) { /* closed or EOL not found */
2129 if (reql == 0)
2130 break;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002131 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002132 continue;
2133 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002134
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002135 /* seek for a possible semi-colon. If we find one, we
2136 * replace it with an LF and skip only this part.
2137 */
2138 for (len = 0; len < reql; len++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002139 if (trash.str[len] == ';') {
2140 trash.str[len] = '\n';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002141 reql = len + 1;
2142 break;
2143 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002144
Willy Tarreau816fc222009-10-04 07:36:58 +02002145 /* now it is time to check that we have a full line,
2146 * remove the trailing \n and possibly \r, then cut the
2147 * line.
2148 */
2149 len = reql - 1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002150 if (trash.str[len] != '\n') {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002151 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002152 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002153 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002154
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002155 if (len && trash.str[len-1] == '\r')
Willy Tarreau816fc222009-10-04 07:36:58 +02002156 len--;
2157
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002158 trash.str[len] = '\0';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002159
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002160 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002161 if (len) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002162 if (strcmp(trash.str, "quit") == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002163 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002164 continue;
2165 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002166 else if (strcmp(trash.str, "prompt") == 0)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002167 appctx->st1 = !appctx->st1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002168 else if (strcmp(trash.str, "help") == 0 ||
2169 !stats_sock_parse_request(si, trash.str)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002170 appctx->ctx.cli.msg = stats_sock_usage_msg;
2171 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02002172 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002173 /* NB: stats_sock_parse_request() may have put
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002174 * another STAT_CLI_O_* into appctx->st0.
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002175 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002176 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002177 else if (!appctx->st1) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002178 /* if prompt is disabled, print help on empty lines,
2179 * so that the user at least knows how to enable
2180 * prompt and find help.
2181 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002182 appctx->ctx.cli.msg = stats_sock_usage_msg;
2183 appctx->st0 = STAT_CLI_PRINT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002184 }
2185
2186 /* re-adjust req buffer */
Willy Tarreau9dab5fc2012-05-07 11:56:55 +02002187 bo_skip(si->ob, reql);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002188 req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002189 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002190 else { /* output functions: first check if the output buffer is closed then abort */
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002191 if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002192 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002193 continue;
2194 }
2195
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002196 switch (appctx->st0) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02002197 case STAT_CLI_PRINT:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002198 if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1)
2199 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002200 break;
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01002201 case STAT_CLI_PRINT_FREE:
2202 if (bi_putstr(si->ib, appctx->ctx.cli.err) != -1) {
2203 free(appctx->ctx.cli.err);
2204 appctx->st0 = STAT_CLI_PROMPT;
2205 }
2206 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002207 case STAT_CLI_O_INFO:
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002208 if (stats_dump_info_to_buffer(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002209 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002210 break;
2211 case STAT_CLI_O_STAT:
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002212 if (stats_dump_stat_to_buffer(si, NULL))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002213 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002214 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002215 case STAT_CLI_O_SESS:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002216 if (stats_dump_sess_to_buffer(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002217 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002218 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002219 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002220 if (stats_dump_errors_to_buffer(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002221 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002222 break;
Willy Tarreau69f58c82010-07-12 17:55:33 +02002223 case STAT_CLI_O_TAB:
Simon Hormanc88b8872011-06-15 15:18:49 +09002224 case STAT_CLI_O_CLR:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002225 if (stats_table_request(si, appctx->st0))
2226 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau69f58c82010-07-12 17:55:33 +02002227 break;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002228 case STAT_CLI_O_PATS:
2229 if (stats_pats_list(si))
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002230 appctx->st0 = STAT_CLI_PROMPT;
2231 break;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01002232 case STAT_CLI_O_PAT:
2233 if (stats_pat_list(si))
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01002234 appctx->st0 = STAT_CLI_PROMPT;
2235 break;
2236 case STAT_CLI_O_MLOOK:
2237 if (stats_map_lookup(si))
2238 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau4efb3532014-01-29 12:13:39 +01002239 break;
Willy Tarreau12833bb2014-01-28 16:49:56 +01002240 case STAT_CLI_O_POOLS:
2241 if (stats_dump_pools_to_buffer(si))
2242 appctx->st0 = STAT_CLI_PROMPT;
2243 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002244 default: /* abnormal state */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002245 appctx->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002246 break;
2247 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002248
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002249 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002250 if (appctx->st0 == STAT_CLI_PROMPT) {
2251 if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1)
2252 appctx->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002253 }
2254
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002255 /* If the output functions are still there, it means they require more room. */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002256 if (appctx->st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002257 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002258
2259 /* Now we close the output if one of the writers did so,
2260 * or if we're not in interactive mode and the request
2261 * buffer is empty. This still allows pipelined requests
2262 * to be sent in non-interactive mode.
2263 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002264 if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) {
2265 appctx->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002266 continue;
2267 }
2268
Willy Tarreauf5a885f2009-10-04 14:22:18 +02002269 /* switch state back to GETREQ to read next requests */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002270 appctx->st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002271 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002272 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002273
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002274 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST) && (appctx->st0 != STAT_CLI_GETREQ)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002275 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
2276 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
Aman Guptaceafb4a2012-04-02 18:57:54 -07002277 /* Other side has closed, let's abort if we have no more processing to do
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002278 * and nothing more to consume. This is comparable to a broken pipe, so
2279 * we forward the close to the request side so that it flows upstream to
2280 * the client.
2281 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02002282 si_shutw(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002283 }
2284
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002285 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (appctx->st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002286 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
2287 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
2288 /* We have no more processing to do, and nothing more to send, and
2289 * the client side has closed. So we'll forward this state downstream
2290 * on the response buffer.
2291 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02002292 si_shutr(si);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002293 res->flags |= CF_READ_NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002294 }
2295
2296 /* update all other flags and resync with the other side */
Willy Tarreau73b013b2012-05-21 16:31:45 +02002297 si_update(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002298
2299 /* we don't want to expire timeouts while we're processing requests */
2300 si->ib->rex = TICK_ETERNITY;
2301 si->ob->wex = TICK_ETERNITY;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002302
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002303 out:
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01002304 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 +02002305 __FUNCTION__, __LINE__,
Willy Tarreau9b28e032012-10-12 23:49:43 +02002306 si->state, req->flags, res->flags, req->buf->i, req->buf->o, res->buf->i, res->buf->o);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02002307
2308 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
2309 /* check that we have released everything then unregister */
2310 stream_int_unregister_handler(si);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002311 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02002312}
2313
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002314/* This function dumps information onto the stream interface's read buffer.
2315 * It returns 0 as long as it does not complete, non-zero upon completion.
2316 * No state is used.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002317 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002318static int stats_dump_info_to_buffer(struct stream_interface *si)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002319{
2320 unsigned int up = (now.tv_sec - start_date.tv_sec);
2321
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002322 chunk_printf(&trash,
2323 "Name: " PRODUCT_NAME "\n"
2324 "Version: " HAPROXY_VERSION "\n"
2325 "Release_date: " HAPROXY_DATE "\n"
2326 "Nbproc: %d\n"
2327 "Process_num: %d\n"
2328 "Pid: %d\n"
2329 "Uptime: %dd %dh%02dm%02ds\n"
2330 "Uptime_sec: %d\n"
2331 "Memmax_MB: %d\n"
2332 "Ulimit-n: %d\n"
2333 "Maxsock: %d\n"
2334 "Maxconn: %d\n"
2335 "Hard_maxconn: %d\n"
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002336 "CurrConns: %d\n"
Willy Tarreau71b734c2014-01-28 15:19:44 +01002337 "CumConns: %d\n"
2338 "CumReq: %d\n"
2339#ifdef USE_OPENSSL
2340 "MaxSslConns: %d\n"
2341 "CurrSslConns: %d\n"
2342 "CumSslConns: %d\n"
2343#endif
2344 "Maxpipes: %d\n"
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002345 "PipesUsed: %d\n"
2346 "PipesFree: %d\n"
2347 "ConnRate: %d\n"
2348 "ConnRateLimit: %d\n"
2349 "MaxConnRate: %d\n"
Willy Tarreau93e7c002013-10-07 18:51:07 +02002350 "SessRate: %d\n"
2351 "SessRateLimit: %d\n"
2352 "MaxSessRate: %d\n"
Willy Tarreaue43d5322013-10-07 20:01:52 +02002353#ifdef USE_OPENSSL
2354 "SslRate: %d\n"
2355 "SslRateLimit: %d\n"
2356 "MaxSslRate: %d\n"
2357#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002358 "CompressBpsIn: %u\n"
2359 "CompressBpsOut: %u\n"
2360 "CompressBpsRateLim: %u\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002361#ifdef USE_ZLIB
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002362 "ZlibMemUsage: %ld\n"
2363 "MaxZlibMemUsage: %ld\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002364#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002365 "Tasks: %d\n"
2366 "Run_queue: %d\n"
2367 "Idle_pct: %d\n"
2368 "node: %s\n"
2369 "description: %s\n"
2370 "",
2371 global.nbproc,
2372 relative_pid,
2373 pid,
2374 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
2375 up,
2376 global.rlimit_memmax,
2377 global.rlimit_nofile,
Willy Tarreau71b734c2014-01-28 15:19:44 +01002378 global.maxsock, global.maxconn, global.hardmaxconn,
2379 actconn, totalconn, global.req_count,
2380#ifdef USE_OPENSSL
2381 global.maxsslconn, sslconns, totalsslconns,
2382#endif
2383 global.maxpipes, pipes_used, pipes_free,
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002384 read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max,
Willy Tarreau93e7c002013-10-07 18:51:07 +02002385 read_freq_ctr(&global.sess_per_sec), global.sps_lim, global.sps_max,
Willy Tarreaue43d5322013-10-07 20:01:52 +02002386#ifdef USE_OPENSSL
2387 read_freq_ctr(&global.ssl_per_sec), global.ssl_lim, global.ssl_max,
2388#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002389 read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out),
2390 global.comp_rate_lim,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002391#ifdef USE_ZLIB
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002392 zlib_used_memory, global.maxzlibmem,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002393#endif
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01002394 nb_tasks_cur, run_queue_cur, idle_pct,
2395 global.node, global.desc ? global.desc : ""
2396 );
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002397
2398 if (bi_putchk(si->ib, &trash) == -1)
2399 return 0;
2400
2401 return 1;
2402}
2403
Willy Tarreau12833bb2014-01-28 16:49:56 +01002404/* This function dumps memory usage information onto the stream interface's
2405 * read buffer. It returns 0 as long as it does not complete, non-zero upon
2406 * completion. No state is used.
2407 */
2408static int stats_dump_pools_to_buffer(struct stream_interface *si)
2409{
2410 dump_pools_to_trash();
2411 if (bi_putchk(si->ib, &trash) == -1)
2412 return 0;
2413 return 1;
2414}
2415
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002416/* Dumps a frontend's line to the trash for the current proxy <px> and uses
2417 * the state from stream interface <si>. The caller is responsible for clearing
2418 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
Cyril Bonté70be45d2010-10-12 00:14:35 +02002419 */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002420static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
Cyril Bonté70be45d2010-10-12 00:14:35 +02002421{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002422 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002423 int i;
Cyril Bonté70be45d2010-10-12 00:14:35 +02002424
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002425 if (!(px->cap & PR_CAP_FE))
2426 return 0;
Cyril Bonté70be45d2010-10-12 00:14:35 +02002427
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002428 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE)))
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002429 return 0;
2430
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002431 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002432 chunk_appendf(&trash,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002433 /* name, queue */
2434 "<tr class=\"frontend\">");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002435
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002436 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002437 /* Column sub-heading for Enable or Disable server */
2438 chunk_appendf(&trash, "<td></td>");
2439 }
Cyril Bonté70be45d2010-10-12 00:14:35 +02002440
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002441 chunk_appendf(&trash,
2442 "<td class=ac>"
2443 "<a name=\"%s/Frontend\"></a>"
2444 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
2445 "<td colspan=3></td>"
2446 "",
2447 px->id, px->id);
Cyril Bonté70be45d2010-10-12 00:14:35 +02002448
Willy Tarreau466c9b52012-12-23 02:25:03 +01002449 chunk_appendf(&trash,
2450 /* sessions rate : current */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002451 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01002452 "<tr><th>Current connection rate:</th><td>%s/s</td></tr>"
2453 "<tr><th>Current session rate:</th><td>%s/s</td></tr>"
2454 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002455 U2H(read_freq_ctr(&px->fe_sess_per_sec)),
2456 U2H(read_freq_ctr(&px->fe_conn_per_sec)),
2457 U2H(read_freq_ctr(&px->fe_sess_per_sec)));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002458
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002459 if (px->mode == PR_MODE_HTTP)
2460 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01002461 "<tr><th>Current request rate:</th><td>%s/s</td></tr>",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002462 U2H(read_freq_ctr(&px->fe_req_per_sec)));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002463
2464 chunk_appendf(&trash,
2465 "</table></div></u></td>"
2466 /* sessions rate : max */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002467 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01002468 "<tr><th>Max connection rate:</th><td>%s/s</td></tr>"
2469 "<tr><th>Max session rate:</th><td>%s/s</td></tr>"
2470 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002471 U2H(px->fe_counters.sps_max),
2472 U2H(px->fe_counters.cps_max),
2473 U2H(px->fe_counters.sps_max));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002474
2475 if (px->mode == PR_MODE_HTTP)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002476 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01002477 "<tr><th>Max request rate:</th><td>%s/s</td></tr>",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002478 U2H(px->fe_counters.p.http.rps_max));
Willy Tarreau466c9b52012-12-23 02:25:03 +01002479
2480 chunk_appendf(&trash,
2481 "</table></div></u></td>"
2482 /* sessions rate : limit */
2483 "<td>%s</td>",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002484 LIM2A(px->fe_sps_lim, "-"));
Cyril Bonté70be45d2010-10-12 00:14:35 +02002485
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002486 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002487 /* sessions: current, max, limit, total */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002488 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002489 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01002490 "<tr><th>Cum. connections:</th><td>%s</td></tr>"
2491 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002492 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002493 U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn),
2494 U2H(px->fe_counters.cum_sess),
2495 U2H(px->fe_counters.cum_conn),
2496 U2H(px->fe_counters.cum_sess));
Cyril Bonté70be45d2010-10-12 00:14:35 +02002497
Willy Tarreau466c9b52012-12-23 02:25:03 +01002498 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002499 if (px->mode == PR_MODE_HTTP) {
Willy Tarreau466c9b52012-12-23 02:25:03 +01002500 chunk_appendf(&trash,
2501 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
2502 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
2503 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
2504 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
2505 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
2506 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
2507 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
2508 "<tr><th>- other responses:</th><td>%s</td></tr>"
2509 "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
2510 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002511 U2H(px->fe_counters.p.http.cum_req),
2512 U2H(px->fe_counters.p.http.rsp[1]),
2513 U2H(px->fe_counters.p.http.rsp[2]),
2514 U2H(px->fe_counters.p.http.comp_rsp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002515 px->fe_counters.p.http.rsp[2] ?
Willy Tarreau466c9b52012-12-23 02:25:03 +01002516 (int)(100*px->fe_counters.p.http.comp_rsp/px->fe_counters.p.http.rsp[2]) : 0,
Willy Tarreau56adcf22012-12-23 18:00:29 +01002517 U2H(px->fe_counters.p.http.rsp[3]),
2518 U2H(px->fe_counters.p.http.rsp[4]),
2519 U2H(px->fe_counters.p.http.rsp[5]),
2520 U2H(px->fe_counters.p.http.rsp[0]),
2521 U2H(px->fe_counters.intercepted_req));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002522 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002523
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002524 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01002525 "</table></div></u></td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05002526 /* sessions: lbtot, lastsess */
2527 "<td></td><td></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002528 /* bytes : in */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002529 "<td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002530 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002531 U2H(px->fe_counters.bytes_in));
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002532
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002533 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002534 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002535 "<td>%s%s<div class=tips>compression: in=%lld out=%lld bypassed=%lld savings=%d%%</div>%s</td>",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002536 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002537 U2H(px->fe_counters.bytes_out),
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002538 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp,
2539 px->fe_counters.comp_in ?
2540 (int)((px->fe_counters.comp_in - px->fe_counters.comp_out)*100/px->fe_counters.comp_in) : 0,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002541 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":"");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002542
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002543 chunk_appendf(&trash,
2544 /* denied: req, resp */
2545 "<td>%s</td><td>%s</td>"
2546 /* errors : request, connect, response */
2547 "<td>%s</td><td></td><td></td>"
2548 /* warnings: retries, redispatches */
2549 "<td></td><td></td>"
2550 /* server status : reflect frontend status */
2551 "<td class=ac>%s</td>"
2552 /* rest of server: nothing */
2553 "<td class=ac colspan=8></td></tr>"
2554 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002555 U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp),
2556 U2H(px->fe_counters.failed_req),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002557 px->state == PR_STREADY ? "OPEN" :
2558 px->state == PR_STFULL ? "FULL" : "STOP");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002559 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002560 else { /* CSV mode */
2561 chunk_appendf(&trash,
2562 /* pxid, name, queue cur, queue max, */
2563 "%s,FRONTEND,,,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01002564 /* sessions : current, max, limit, total */
2565 "%d,%d,%d,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002566 /* bytes : in, out */
2567 "%lld,%lld,"
2568 /* denied: req, resp */
2569 "%lld,%lld,"
2570 /* errors : request, connect, response */
2571 "%lld,,,"
2572 /* warnings: retries, redispatches */
2573 ",,"
2574 /* server status : reflect frontend status */
2575 "%s,"
2576 /* rest of server: nothing */
2577 ",,,,,,,,"
2578 /* pid, iid, sid, throttle, lbtot, tracked, type */
2579 "%d,%d,0,,,,%d,"
2580 /* rate, rate_lim, rate_max */
2581 "%u,%u,%u,"
2582 /* check_status, check_code, check_duration */
2583 ",,,",
2584 px->id,
2585 px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess,
2586 px->fe_counters.bytes_in, px->fe_counters.bytes_out,
2587 px->fe_counters.denied_req, px->fe_counters.denied_resp,
2588 px->fe_counters.failed_req,
2589 px->state == PR_STREADY ? "OPEN" :
2590 px->state == PR_STFULL ? "FULL" : "STOP",
2591 relative_pid, px->uuid, STATS_TYPE_FE,
2592 read_freq_ctr(&px->fe_sess_per_sec),
2593 px->fe_sps_lim, px->fe_counters.sps_max);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002594
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002595 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2596 if (px->mode == PR_MODE_HTTP) {
2597 for (i=1; i<6; i++)
2598 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]);
2599 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]);
2600 }
2601 else
2602 chunk_appendf(&trash, ",,,,,,");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002603
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002604 /* failed health analyses */
2605 chunk_appendf(&trash, ",");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002606
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002607 /* requests : req_rate, req_rate_max, req_tot, */
2608 chunk_appendf(&trash, "%u,%u,%lld,",
2609 read_freq_ctr(&px->fe_req_per_sec),
2610 px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req);
2611
2612 /* errors: cli_aborts, srv_aborts */
2613 chunk_appendf(&trash, ",,");
2614
2615 /* compression: in, out, bypassed */
2616 chunk_appendf(&trash, "%lld,%lld,%lld,",
2617 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
2618
2619 /* compression: comp_rsp */
2620 chunk_appendf(&trash, "%lld,",
2621 px->fe_counters.p.http.comp_rsp);
2622
Willy Tarreauf522f3d2014-02-10 22:22:49 +01002623 /* lastsess */
2624 chunk_appendf(&trash, ",");
2625
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002626 /* finish with EOL */
2627 chunk_appendf(&trash, "\n");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002628 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002629 return 1;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002630}
2631
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002632/* Dumps a line for listener <l> and proxy <px> to the trash and uses the state
2633 * from stream interface <si>, and stats flags <flags>. The caller is responsible
2634 * for clearing the trash if needed. Returns non-zero if it emits anything, zero
2635 * otherwise.
Willy Tarreau91861262007-10-17 17:06:05 +02002636 */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002637static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags)
Willy Tarreau91861262007-10-17 17:06:05 +02002638{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002639 struct appctx *appctx = __objt_appctx(si->end);
2640
2641 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002642 chunk_appendf(&trash, "<tr class=socket>");
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002643 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002644 /* Column sub-heading for Enable or Disable server */
2645 chunk_appendf(&trash, "<td></td>");
2646 }
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002647 chunk_appendf(&trash,
2648 /* frontend name, listener name */
2649 "<td class=ac><a name=\"%s/+%s\"></a>%s"
2650 "<a class=lfsb href=\"#%s/+%s\">%s</a>"
2651 "",
2652 px->id, l->name,
2653 (flags & ST_SHLGNDS)?"<u>":"",
2654 px->id, l->name, l->name);
Willy Tarreau91861262007-10-17 17:06:05 +02002655
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002656 if (flags & ST_SHLGNDS) {
2657 char str[INET6_ADDRSTRLEN];
2658 int port;
Willy Tarreau91861262007-10-17 17:06:05 +02002659
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002660 chunk_appendf(&trash, "<div class=tips>");
Willy Tarreau91861262007-10-17 17:06:05 +02002661
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002662 port = get_host_port(&l->addr);
2663 switch (addr_to_str(&l->addr, str, sizeof(str))) {
2664 case AF_INET:
2665 chunk_appendf(&trash, "IPv4: %s:%d, ", str, port);
2666 break;
2667 case AF_INET6:
2668 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port);
2669 break;
2670 case AF_UNIX:
2671 chunk_appendf(&trash, "unix, ");
2672 break;
2673 case -1:
2674 chunk_appendf(&trash, "(%s), ", strerror(errno));
2675 break;
2676 }
Willy Tarreau91861262007-10-17 17:06:05 +02002677
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002678 /* id */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002679 chunk_appendf(&trash, "id: %d</div>", l->luid);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002680 }
Willy Tarreau91861262007-10-17 17:06:05 +02002681
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002682 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002683 /* queue */
2684 "%s</td><td colspan=3></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002685 /* sessions rate: current, max, limit */
2686 "<td colspan=3>&nbsp;</td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05002687 /* sessions: current, max, limit, total, lbtot, lastsess */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002688 "<td>%s</td><td>%s</td><td>%s</td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05002689 "<td>%s</td><td>&nbsp;</td><td>&nbsp;</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002690 /* bytes: in, out */
2691 "<td>%s</td><td>%s</td>"
2692 "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002693 (flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002694 U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn),
2695 U2H(l->counters->cum_conn), U2H(l->counters->bytes_in), U2H(l->counters->bytes_out));
Willy Tarreau56a560a2009-09-22 19:27:35 +02002696
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002697 chunk_appendf(&trash,
2698 /* denied: req, resp */
2699 "<td>%s</td><td>%s</td>"
2700 /* errors: request, connect, response */
2701 "<td>%s</td><td></td><td></td>"
2702 /* warnings: retries, redispatches */
2703 "<td></td><td></td>"
2704 /* server status: reflect listener status */
2705 "<td class=ac>%s</td>"
2706 /* rest of server: nothing */
2707 "<td class=ac colspan=8></td></tr>"
2708 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002709 U2H(l->counters->denied_req), U2H(l->counters->denied_resp),
2710 U2H(l->counters->failed_req),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002711 (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
2712 }
2713 else { /* CSV mode */
2714 chunk_appendf(&trash,
2715 /* pxid, name, queue cur, queue max, */
2716 "%s,%s,,,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01002717 /* sessions: current, max, limit, total */
2718 "%d,%d,%d,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002719 /* bytes: in, out */
2720 "%lld,%lld,"
2721 /* denied: req, resp */
2722 "%lld,%lld,"
2723 /* errors: request, connect, response */
2724 "%lld,,,"
2725 /* warnings: retries, redispatches */
2726 ",,"
2727 /* server status: reflect listener status */
2728 "%s,"
2729 /* rest of server: nothing */
2730 ",,,,,,,,"
2731 /* pid, iid, sid, throttle, lbtot, tracked, type */
2732 "%d,%d,%d,,,,%d,"
2733 /* rate, rate_lim, rate_max */
2734 ",,,"
2735 /* check_status, check_code, check_duration */
2736 ",,,"
2737 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2738 ",,,,,,"
2739 /* failed health analyses */
2740 ","
2741 /* requests : req_rate, req_rate_max, req_tot, */
2742 ",,,"
2743 /* errors: cli_aborts, srv_aborts */
2744 ",,"
2745 /* compression: in, out, bypassed, comp_rsp */
2746 ",,,,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01002747 /* lastsess */
2748 ","
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002749 "\n",
2750 px->id, l->name,
2751 l->nbconn, l->counters->conn_max,
2752 l->maxconn, l->counters->cum_conn,
2753 l->counters->bytes_in, l->counters->bytes_out,
2754 l->counters->denied_req, l->counters->denied_resp,
2755 l->counters->failed_req,
2756 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
2757 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
2758 }
2759 return 1;
2760}
Willy Tarreau91861262007-10-17 17:06:05 +02002761
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002762/* Dumps a line for server <sv> and proxy <px> to the trash and uses the state
2763 * from stream interface <si>, stats flags <flags>, and server state <state>.
2764 * The caller is responsible for clearing the trash if needed. Returns non-zero
2765 * if it emits anything, zero otherwise. The <state> parameter can take the
Simon Horman8c3d0be2013-11-25 10:46:40 +09002766 * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB,
2767 * 6,7=DRAIN, 8=unchecked.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002768 */
2769static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state)
2770{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002771 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002772 struct server *ref = sv->track ? sv->track : sv;
2773 char str[INET6_ADDRSTRLEN];
2774 struct chunk src;
2775 int i;
Willy Tarreau91861262007-10-17 17:06:05 +02002776
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002777 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Simon Horman8c3d0be2013-11-25 10:46:40 +09002778 static char *srv_hlt_st[9] = {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002779 "DOWN",
2780 "DN %d/%d &uarr;",
2781 "UP %d/%d &darr;",
2782 "UP",
2783 "NOLB %d/%d &darr;",
2784 "NOLB",
Simon Horman8c3d0be2013-11-25 10:46:40 +09002785 "DRAIN %d/%d &darr;",
2786 "DRAIN",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002787 "<i>no check</i>"
2788 };
Willy Tarreau91861262007-10-17 17:06:05 +02002789
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002790 if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN))
2791 chunk_appendf(&trash, "<tr class=\"maintain\">");
2792 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002793 chunk_appendf(&trash,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002794 "<tr class=\"%s%d\">",
2795 (sv->state & SRV_BACKUP) ? "backup" : "active", state);
Willy Tarreau91861262007-10-17 17:06:05 +02002796
Willy Tarreau7b4b4992013-12-01 09:15:12 +01002797 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002798 chunk_appendf(&trash,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002799 "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
2800 sv->id);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002801
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002802 chunk_appendf(&trash,
2803 "<td class=ac><a name=\"%s/%s\"></a>%s"
2804 "<a class=lfsb href=\"#%s/%s\">%s</a>"
2805 "",
2806 px->id, sv->id,
2807 (flags & ST_SHLGNDS) ? "<u>" : "",
2808 px->id, sv->id, sv->id);
Willy Tarreau91861262007-10-17 17:06:05 +02002809
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002810 if (flags & ST_SHLGNDS) {
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002811 chunk_appendf(&trash, "<div class=tips>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002812
2813 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
2814 case AF_INET:
2815 chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr));
2816 break;
2817 case AF_INET6:
2818 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr));
2819 break;
2820 case AF_UNIX:
2821 chunk_appendf(&trash, "unix, ");
2822 break;
2823 case -1:
2824 chunk_appendf(&trash, "(%s), ", strerror(errno));
2825 break;
2826 default: /* address family not supported */
2827 break;
Willy Tarreau55bb8452007-10-17 18:44:57 +02002828 }
Willy Tarreau91861262007-10-17 17:06:05 +02002829
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002830 /* id */
2831 chunk_appendf(&trash, "id: %d", sv->puid);
Willy Tarreau91861262007-10-17 17:06:05 +02002832
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002833 /* cookie */
2834 if (sv->cookie) {
2835 chunk_appendf(&trash, ", cookie: '");
Willy Tarreau5031e6a2007-10-18 11:05:48 +02002836
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002837 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
2838 chunk_htmlencode(&trash, &src);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002839
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002840 chunk_appendf(&trash, "'");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002841 }
2842
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002843 chunk_appendf(&trash, "</div>");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002844 }
Willy Tarreau91861262007-10-17 17:06:05 +02002845
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002846 chunk_appendf(&trash,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002847 /* queue : current, max, limit */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002848 "%s</td><td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002849 /* sessions rate : current, max, limit */
2850 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002851 "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002852 (flags & ST_SHLGNDS) ? "</u>" : "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002853 U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"),
2854 U2H(read_freq_ctr(&sv->sess_per_sec)), U2H(sv->counters.sps_max));
Willy Tarreau91861262007-10-17 17:06:05 +02002855
Willy Tarreau466c9b52012-12-23 02:25:03 +01002856
2857 chunk_appendf(&trash,
2858 /* sessions: current, max, limit, total */
2859 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002860 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01002861 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
2862 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002863 U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"),
2864 U2H(sv->counters.cum_sess),
2865 U2H(sv->counters.cum_sess));
Willy Tarreau91861262007-10-17 17:06:05 +02002866
Willy Tarreau466c9b52012-12-23 02:25:03 +01002867 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2868 if (px->mode == PR_MODE_HTTP) {
2869 unsigned long long tot;
2870 for (tot = i = 0; i < 6; i++)
2871 tot += sv->counters.p.http.rsp[i];
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002872
Willy Tarreau466c9b52012-12-23 02:25:03 +01002873 chunk_appendf(&trash,
2874 "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>"
2875 "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
2876 "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
2877 "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
2878 "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
2879 "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
2880 "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>"
2881 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002882 U2H(tot),
2883 U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0,
2884 U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0,
2885 U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0,
2886 U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0,
2887 U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0,
2888 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 +02002889 }
Willy Tarreau91861262007-10-17 17:06:05 +02002890
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002891 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01002892 "</table></div></u></td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05002893 /* sessions: lbtot, last */
2894 "<td>%s</td><td>%s</td>",
2895 U2H(sv->counters.cum_lbconn),
2896 human_time(srv_lastsession(sv), 1));
Willy Tarreau91861262007-10-17 17:06:05 +02002897
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002898 chunk_appendf(&trash,
2899 /* bytes : in, out */
2900 "<td>%s</td><td>%s</td>"
2901 /* denied: req, resp */
2902 "<td></td><td>%s</td>"
2903 /* errors : request, connect */
2904 "<td></td><td>%s</td>"
2905 /* errors : response */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002906 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002907 /* warnings: retries, redispatches */
2908 "<td>%lld</td><td>%lld</td>"
2909 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01002910 U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out),
2911 U2H(sv->counters.failed_secu),
2912 U2H(sv->counters.failed_conns),
2913 U2H(sv->counters.failed_resp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002914 sv->counters.cli_aborts,
2915 sv->counters.srv_aborts,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002916 sv->counters.retries, sv->counters.redispatches);
2917
2918 /* status, lest check */
2919 chunk_appendf(&trash, "<td class=ac>");
2920
2921 if (sv->state & SRV_MAINTAIN) {
2922 chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1));
2923 chunk_appendf(&trash, "MAINT");
2924 }
2925 else if (ref != sv && ref->state & SRV_MAINTAIN) {
2926 chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1));
2927 chunk_appendf(&trash, "MAINT(via)");
2928 }
Willy Tarreauff5ae352013-12-11 20:36:34 +01002929 else if (ref->check.state & CHK_ST_ENABLED) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002930 chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1));
2931 chunk_appendf(&trash,
2932 srv_hlt_st[state],
Simon Horman58c32972013-11-25 10:46:38 +09002933 (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health),
2934 (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise));
Willy Tarreau55bb8452007-10-17 18:44:57 +02002935 }
Willy Tarreau91861262007-10-17 17:06:05 +02002936
Willy Tarreauff5ae352013-12-11 20:36:34 +01002937 if (sv->check.state & CHK_ST_ENABLED) {
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002938 chunk_appendf(&trash,
2939 "</td><td class=ac><u> %s%s",
Willy Tarreau2c115e52013-12-11 19:41:16 +01002940 (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002941 get_check_status_info(sv->check.status));
2942
2943 if (sv->check.status >= HCHK_STATUS_L57DATA)
2944 chunk_appendf(&trash, "/%d", sv->check.code);
2945
2946 if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0)
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002947 chunk_appendf(&trash, " in %lums", sv->check.duration);
2948
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002949 chunk_appendf(&trash, "<div class=tips>%s",
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002950 get_check_status_description(sv->check.status));
2951 if (*sv->check.desc) {
2952 chunk_appendf(&trash, ": ");
2953 chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc));
2954 chunk_htmlencode(&trash, &src);
2955 }
2956 chunk_appendf(&trash, "</div></u>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002957 }
2958 else
2959 chunk_appendf(&trash, "</td><td>");
2960
2961 chunk_appendf(&trash,
2962 /* weight */
2963 "</td><td class=ac>%d</td>"
2964 /* act, bck */
2965 "<td class=ac>%s</td><td class=ac>%s</td>"
2966 "",
2967 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
2968 (sv->state & SRV_BACKUP) ? "-" : "Y",
2969 (sv->state & SRV_BACKUP) ? "Y" : "-");
2970
2971 /* check failures: unique, fatal, down time */
Willy Tarreauff5ae352013-12-11 20:36:34 +01002972 if (sv->check.state & CHK_ST_ENABLED) {
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002973 chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002974
2975 if (ref->observe)
2976 chunk_appendf(&trash, "/%lld", ref->counters.failed_hana);
2977
2978 chunk_appendf(&trash,
Willy Tarreau656a9ce2013-04-19 14:41:29 +02002979 "<div class=tips>Failed Health Checks%s</div></u></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002980 "<td>%lld</td><td>%s</td>"
2981 "",
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01002982 ref->observe ? "/Health Analyses" : "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002983 ref->counters.down_trans, human_time(srv_downtime(sv), 1));
2984 }
Willy Tarreauf4659942013-11-28 10:50:06 +01002985 else if (sv != ref) {
2986 if (sv->state & SRV_MAINTAIN)
2987 chunk_appendf(&trash,
2988 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>",
2989 ref->proxy->id, ref->id);
2990 else
2991 chunk_appendf(&trash,
2992 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>",
2993 ref->proxy->id, ref->id, ref->proxy->id, ref->id);
2994 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01002995 else
2996 chunk_appendf(&trash, "<td colspan=3></td>");
2997
2998 /* throttle */
Willy Tarreaud32c3992013-11-21 15:30:45 +01002999 if (sv->state & SRV_WARMINGUP)
3000 chunk_appendf(&trash, "<td class=ac>%d %%</td></tr>\n", server_throttle_rate(sv));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003001 else
3002 chunk_appendf(&trash, "<td class=ac>-</td></tr>\n");
3003 }
3004 else { /* CSV mode */
Simon Horman8c3d0be2013-11-25 10:46:40 +09003005 static char *srv_hlt_st[9] = {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003006 "DOWN,",
3007 "DOWN %d/%d,",
3008 "UP %d/%d,",
3009 "UP,",
3010 "NOLB %d/%d,",
3011 "NOLB,",
Simon Horman8c3d0be2013-11-25 10:46:40 +09003012 "DRAIN %d/%d,",
3013 "DRAIN,",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003014 "no check,"
3015 };
3016
3017 chunk_appendf(&trash,
3018 /* pxid, name */
3019 "%s,%s,"
3020 /* queue : current, max */
3021 "%d,%d,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003022 /* sessions : current, max, limit, total */
3023 "%d,%d,%s,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003024 /* bytes : in, out */
3025 "%lld,%lld,"
3026 /* denied: req, resp */
3027 ",%lld,"
3028 /* errors : request, connect, response */
3029 ",%lld,%lld,"
3030 /* warnings: retries, redispatches */
3031 "%lld,%lld,"
3032 "",
3033 px->id, sv->id,
3034 sv->nbpend, sv->counters.nbpend_max,
Willy Tarreau56adcf22012-12-23 18:00:29 +01003035 sv->cur_sess, sv->counters.cur_sess_max, LIM2A(sv->maxconn, ""), sv->counters.cum_sess,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003036 sv->counters.bytes_in, sv->counters.bytes_out,
3037 sv->counters.failed_secu,
3038 sv->counters.failed_conns, sv->counters.failed_resp,
3039 sv->counters.retries, sv->counters.redispatches);
3040
3041 /* status */
3042 if (sv->state & SRV_MAINTAIN)
3043 chunk_appendf(&trash, "MAINT,");
3044 else if (ref != sv && ref->state & SRV_MAINTAIN)
3045 chunk_appendf(&trash, "MAINT(via),");
3046 else
3047 chunk_appendf(&trash,
3048 srv_hlt_st[state],
Simon Horman58c32972013-11-25 10:46:38 +09003049 (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health),
3050 (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003051
3052 chunk_appendf(&trash,
3053 /* weight, active, backup */
3054 "%d,%d,%d,"
3055 "",
3056 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
3057 (sv->state & SRV_BACKUP) ? 0 : 1,
3058 (sv->state & SRV_BACKUP) ? 1 : 0);
3059
3060 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreauff5ae352013-12-11 20:36:34 +01003061 if (sv->check.state & CHK_ST_ENABLED)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003062 chunk_appendf(&trash,
3063 "%lld,%lld,%d,%d,",
3064 sv->counters.failed_checks, sv->counters.down_trans,
3065 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
3066 else
3067 chunk_appendf(&trash, ",,,,");
3068
3069 /* queue limit, pid, iid, sid, */
3070 chunk_appendf(&trash,
3071 "%s,"
3072 "%d,%d,%d,",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003073 LIM2A(sv->maxqueue, ""),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003074 relative_pid, px->uuid, sv->puid);
3075
3076 /* throttle */
Willy Tarreaud32c3992013-11-21 15:30:45 +01003077 if (sv->state & SRV_WARMINGUP)
3078 chunk_appendf(&trash, "%d", server_throttle_rate(sv));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003079
3080 /* sessions: lbtot */
3081 chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn);
3082
3083 /* tracked */
3084 if (sv->track)
3085 chunk_appendf(&trash, "%s/%s,",
3086 sv->track->proxy->id, sv->track->id);
3087 else
3088 chunk_appendf(&trash, ",");
3089
3090 /* type */
3091 chunk_appendf(&trash, "%d,", STATS_TYPE_SV);
3092
3093 /* rate */
3094 chunk_appendf(&trash, "%u,,%u,",
3095 read_freq_ctr(&sv->sess_per_sec),
3096 sv->counters.sps_max);
3097
Willy Tarreauff5ae352013-12-11 20:36:34 +01003098 if (sv->check.state & CHK_ST_ENABLED) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003099 /* check_status */
3100 chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status));
3101
3102 /* check_code */
3103 if (sv->check.status >= HCHK_STATUS_L57DATA)
3104 chunk_appendf(&trash, "%u,", sv->check.code);
3105 else
3106 chunk_appendf(&trash, ",");
3107
3108 /* check_duration */
3109 if (sv->check.status >= HCHK_STATUS_CHECKED)
3110 chunk_appendf(&trash, "%lu,", sv->check.duration);
3111 else
3112 chunk_appendf(&trash, ",");
3113
3114 }
3115 else
3116 chunk_appendf(&trash, ",,,");
3117
3118 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3119 if (px->mode == PR_MODE_HTTP) {
3120 for (i=1; i<6; i++)
3121 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]);
3122
3123 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]);
3124 }
3125 else
3126 chunk_appendf(&trash, ",,,,,,");
3127
3128 /* failed health analyses */
3129 chunk_appendf(&trash, "%lld,", sv->counters.failed_hana);
3130
3131 /* requests : req_rate, req_rate_max, req_tot, */
3132 chunk_appendf(&trash, ",,,");
3133
3134 /* errors: cli_aborts, srv_aborts */
3135 chunk_appendf(&trash, "%lld,%lld,",
3136 sv->counters.cli_aborts, sv->counters.srv_aborts);
3137
3138 /* compression: in, out, bypassed, comp_rsp */
3139 chunk_appendf(&trash, ",,,,");
3140
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003141 /* lastsess */
3142 chunk_appendf(&trash, "%d,", srv_lastsession(sv));
3143
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003144 /* finish with EOL */
3145 chunk_appendf(&trash, "\n");
3146 }
3147 return 1;
3148}
3149
3150/* Dumps a line for backend <px> to the trash for and uses the state from stream
3151 * interface <si> and stats flags <flags>. The caller is responsible for clearing
3152 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
3153 */
3154static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags)
3155{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003156 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003157 struct chunk src;
3158 int i;
3159
3160 if (!(px->cap & PR_CAP_BE))
3161 return 0;
3162
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003163 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE)))
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003164 return 0;
3165
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003166 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003167 chunk_appendf(&trash, "<tr class=\"backend\">");
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003168 if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003169 /* Column sub-heading for Enable or Disable server */
3170 chunk_appendf(&trash, "<td></td>");
3171 }
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003172 chunk_appendf(&trash,
3173 "<td class=ac>"
3174 /* name */
3175 "%s<a name=\"%s/Backend\"></a>"
3176 "<a class=lfsb href=\"#%s/Backend\">Backend</a>"
3177 "",
3178 (flags & ST_SHLGNDS)?"<u>":"",
3179 px->id, px->id);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003180
3181 if (flags & ST_SHLGNDS) {
3182 /* balancing */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003183 chunk_appendf(&trash, "<div class=tips>balancing: %s",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003184 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
3185
3186 /* cookie */
3187 if (px->cookie_name) {
3188 chunk_appendf(&trash, ", cookie: '");
3189 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
3190 chunk_htmlencode(&trash, &src);
3191 chunk_appendf(&trash, "'");
3192 }
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003193 chunk_appendf(&trash, "</div>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003194 }
3195
3196 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003197 "%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003198 /* queue : current, max */
3199 "<td>%s</td><td>%s</td><td></td>"
3200 /* sessions rate : current, max, limit */
3201 "<td>%s</td><td>%s</td><td></td>"
3202 "",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003203 (flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003204 U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max),
3205 U2H(read_freq_ctr(&px->be_sess_per_sec)), U2H(px->be_counters.sps_max));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003206
3207 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003208 /* sessions: current, max, limit, total */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003209 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003210 "<td><u>%s<div class=tips><table class=det>"
Willy Tarreau466c9b52012-12-23 02:25:03 +01003211 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003212 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003213 U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn),
3214 U2H(px->be_counters.cum_conn),
3215 U2H(px->be_counters.cum_conn));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003216
Willy Tarreau466c9b52012-12-23 02:25:03 +01003217 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003218 if (px->mode == PR_MODE_HTTP) {
Willy Tarreau466c9b52012-12-23 02:25:03 +01003219 chunk_appendf(&trash,
3220 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
3221 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
3222 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
3223 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
3224 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
3225 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
3226 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
3227 "<tr><th>- other responses:</th><td>%s</td></tr>"
3228 "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
3229 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003230 U2H(px->be_counters.p.http.cum_req),
3231 U2H(px->be_counters.p.http.rsp[1]),
3232 U2H(px->be_counters.p.http.rsp[2]),
3233 U2H(px->be_counters.p.http.comp_rsp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003234 px->be_counters.p.http.rsp[2] ?
Willy Tarreau466c9b52012-12-23 02:25:03 +01003235 (int)(100*px->be_counters.p.http.comp_rsp/px->be_counters.p.http.rsp[2]) : 0,
Willy Tarreau56adcf22012-12-23 18:00:29 +01003236 U2H(px->be_counters.p.http.rsp[3]),
3237 U2H(px->be_counters.p.http.rsp[4]),
3238 U2H(px->be_counters.p.http.rsp[5]),
3239 U2H(px->be_counters.p.http.rsp[0]),
3240 U2H(px->be_counters.intercepted_req));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003241 }
3242
3243 chunk_appendf(&trash,
Willy Tarreau466c9b52012-12-23 02:25:03 +01003244 "</table></div></u></td>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003245 /* sessions: lbtot, last */
3246 "<td>%s</td><td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003247 /* bytes: in */
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003248 "<td>%s</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003249 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003250 U2H(px->be_counters.cum_lbconn),
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003251 human_time(be_lastsession(px), 1),
Willy Tarreau56adcf22012-12-23 18:00:29 +01003252 U2H(px->be_counters.bytes_in));
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003253
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003254 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003255 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003256 "<td>%s%s<div class=tips>compression: in=%lld out=%lld bypassed=%lld savings=%d%%</div>%s</td>",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003257 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003258 U2H(px->be_counters.bytes_out),
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003259 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp,
3260 px->be_counters.comp_in ?
3261 (int)((px->be_counters.comp_in - px->be_counters.comp_out)*100/px->be_counters.comp_in) : 0,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003262 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":"");
3263
3264 chunk_appendf(&trash,
3265 /* denied: req, resp */
3266 "<td>%s</td><td>%s</td>"
3267 /* errors : request, connect */
3268 "<td></td><td>%s</td>"
3269 /* errors : response */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003270 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003271 /* warnings: retries, redispatches */
3272 "<td>%lld</td><td>%lld</td>"
3273 /* backend status: reflect backend status (up/down): we display UP
3274 * if the backend has known working servers or if it has no server at
3275 * all (eg: for stats). Then we display the total weight, number of
3276 * active and backups. */
3277 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
3278 "<td class=ac>%d</td><td class=ac>%d</td>"
3279 "",
Willy Tarreau56adcf22012-12-23 18:00:29 +01003280 U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp),
3281 U2H(px->be_counters.failed_conns),
3282 U2H(px->be_counters.failed_resp),
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003283 px->be_counters.cli_aborts,
3284 px->be_counters.srv_aborts,
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003285 px->be_counters.retries, px->be_counters.redispatches,
3286 human_time(now.tv_sec - px->last_change, 1),
3287 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
3288 "<font color=\"red\"><b>DOWN</b></font>",
3289 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
3290 px->srv_act, px->srv_bck);
3291
3292 chunk_appendf(&trash,
3293 /* rest of backend: nothing, down transitions, total downtime, throttle */
3294 "<td class=ac>&nbsp;</td><td>%d</td>"
3295 "<td>%s</td>"
3296 "<td></td>"
3297 "</tr>",
3298 px->down_trans,
3299 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
3300 }
3301 else { /* CSV mode */
3302 chunk_appendf(&trash,
3303 /* pxid, name */
3304 "%s,BACKEND,"
3305 /* queue : current, max */
3306 "%d,%d,"
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003307 /* sessions : current, max, limit, total */
3308 "%d,%d,%d,%lld,"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003309 /* bytes : in, out */
3310 "%lld,%lld,"
3311 /* denied: req, resp */
3312 "%lld,%lld,"
3313 /* errors : request, connect, response */
3314 ",%lld,%lld,"
3315 /* warnings: retries, redispatches */
3316 "%lld,%lld,"
3317 /* backend status: reflect backend status (up/down): we display UP
3318 * if the backend has known working servers or if it has no server at
3319 * all (eg: for stats). Then we display the total weight, number of
3320 * active and backups. */
3321 "%s,"
3322 "%d,%d,%d,"
3323 /* rest of backend: nothing, down transitions, last change, total downtime */
3324 ",%d,%d,%d,,"
3325 /* pid, iid, sid, throttle, lbtot, tracked, type */
3326 "%d,%d,0,,%lld,,%d,"
3327 /* rate, rate_lim, rate_max, */
3328 "%u,,%u,"
3329 /* check_status, check_code, check_duration */
3330 ",,,",
3331 px->id,
3332 px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max,
3333 px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn,
3334 px->be_counters.bytes_in, px->be_counters.bytes_out,
3335 px->be_counters.denied_req, px->be_counters.denied_resp,
3336 px->be_counters.failed_conns, px->be_counters.failed_resp,
3337 px->be_counters.retries, px->be_counters.redispatches,
3338 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
3339 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
3340 px->srv_act, px->srv_bck,
3341 px->down_trans, (int)(now.tv_sec - px->last_change),
3342 px->srv?be_downtime(px):0,
3343 relative_pid, px->uuid,
3344 px->be_counters.cum_lbconn, STATS_TYPE_BE,
3345 read_freq_ctr(&px->be_sess_per_sec),
3346 px->be_counters.sps_max);
3347
3348 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3349 if (px->mode == PR_MODE_HTTP) {
3350 for (i=1; i<6; i++)
3351 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]);
3352 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]);
3353 }
3354 else
3355 chunk_appendf(&trash, ",,,,,,");
3356
3357 /* failed health analyses */
3358 chunk_appendf(&trash, ",");
3359
3360 /* requests : req_rate, req_rate_max, req_tot, */
3361 chunk_appendf(&trash, ",,,");
3362
3363 /* errors: cli_aborts, srv_aborts */
3364 chunk_appendf(&trash, "%lld,%lld,",
3365 px->be_counters.cli_aborts, px->be_counters.srv_aborts);
3366
3367 /* compression: in, out, bypassed */
3368 chunk_appendf(&trash, "%lld,%lld,%lld,",
3369 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
3370
3371 /* compression: comp_rsp */
3372 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp);
3373
Willy Tarreauf522f3d2014-02-10 22:22:49 +01003374 /* lastsess */
3375 chunk_appendf(&trash, "%d,", be_lastsession(px));
3376
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003377 /* finish with EOL */
3378 chunk_appendf(&trash, "\n");
3379 }
3380 return 1;
3381}
3382
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003383/* Dumps the HTML table header for proxy <px> to the trash for and uses the state from
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003384 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003385 * for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003386 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003387static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003388{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003389 struct appctx *appctx = __objt_appctx(si->end);
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003390 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
3391
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003392 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003393 /* A form to enable/disable this proxy servers */
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003394
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003395 /* 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 +02003396 scope_txt[0] = 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003397 if (appctx->ctx.stats.scope_len) {
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003398 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003399 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
3400 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003401 }
3402
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003403 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003404 "<form action=\"%s%s%s%s\" method=\"post\">",
3405 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003406 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
3407 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003408 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003409 }
3410
3411 /* print a new table */
3412 chunk_appendf(&trash,
3413 "<table class=\"tbl\" width=\"100%%\">\n"
3414 "<tr class=\"titre\">"
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003415 "<th class=\"pxname\" width=\"10%%\">");
3416
3417 chunk_appendf(&trash,
3418 "<a name=\"%s\"></a>%s"
3419 "<a class=px href=\"#%s\">%s</a>",
3420 px->id,
3421 (uri->flags & ST_SHLGNDS) ? "<u>":"",
3422 px->id, px->id);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003423
3424 if (uri->flags & ST_SHLGNDS) {
3425 /* cap, mode, id */
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003426 chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003427 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
3428 px->uuid);
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003429 chunk_appendf(&trash, "</div>");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003430 }
3431
3432 chunk_appendf(&trash,
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003433 "%s</th>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003434 "<th class=\"%s\" width=\"90%%\">%s</th>"
3435 "</tr>\n"
3436 "</table>\n"
3437 "<table class=\"tbl\" width=\"100%%\">\n"
3438 "<tr class=\"titre\">",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003439 (uri->flags & ST_SHLGNDS) ? "</u>":"",
3440 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
3441
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003442 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003443 /* Column heading for Enable or Disable server */
3444 chunk_appendf(&trash, "<th rowspan=2 width=1></th>");
Willy Tarreau91861262007-10-17 17:06:05 +02003445 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003446
3447 chunk_appendf(&trash,
3448 "<th rowspan=2></th>"
3449 "<th colspan=3>Queue</th>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003450 "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003451 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
3452 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
3453 "<th colspan=9>Server</th>"
3454 "</tr>\n"
3455 "<tr class=\"titre\">"
3456 "<th>Cur</th><th>Max</th><th>Limit</th>"
3457 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05003458 "<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 +01003459 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
3460 "<th>Resp</th><th>Retr</th><th>Redis</th>"
3461 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
3462 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
3463 "<th>Thrtle</th>\n"
3464 "</tr>");
Willy Tarreau91861262007-10-17 17:06:05 +02003465}
3466
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003467/* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003468 * stream interface <si>. The caller is responsible for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003469 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003470static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003471{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003472 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003473 chunk_appendf(&trash, "</table>");
3474
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003475 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003476 /* close the form used to enable/disable this proxy servers */
3477 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003478 "Choose the action to perform on the checked servers : "
3479 "<select name=action>"
3480 "<option value=\"\"></option>"
3481 "<option value=\"disable\">Disable</option>"
3482 "<option value=\"enable\">Enable</option>"
3483 "<option value=\"stop\">Soft Stop</option>"
3484 "<option value=\"start\">Soft Start</option>"
3485 "<option value=\"shutdown\">Kill Sessions</option>"
3486 "</select>"
3487 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
3488 "&nbsp;<input type=\"submit\" value=\"Apply\">"
3489 "</form>",
3490 px->uuid);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003491 }
3492
3493 chunk_appendf(&trash, "<p>\n");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003494}
Willy Tarreau91861262007-10-17 17:06:05 +02003495
3496/*
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003497 * Dumps statistics for a proxy. The output is sent to the stream interface's
3498 * input buffer. Returns 0 if it had to stop dumping data because of lack of
3499 * buffer space, or non-zero if everything completed. This function is used
3500 * both by the CLI and the HTTP entry points, and is able to dump the output
3501 * in HTML or CSV formats. If the later, <uri> must be NULL.
Willy Tarreau91861262007-10-17 17:06:05 +02003502 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003503static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02003504{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003505 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau306f8302013-07-08 15:53:06 +02003506 struct session *s = session_from_task(si->owner);
Willy Tarreau7421efb2012-07-02 15:11:27 +02003507 struct channel *rep = si->ib;
Willy Tarreau44267702011-10-28 15:35:33 +02003508 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003509 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02003510
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003511 chunk_reset(&trash);
Willy Tarreau91861262007-10-17 17:06:05 +02003512
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003513 switch (appctx->ctx.stats.px_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003514 case STAT_PX_ST_INIT:
Willy Tarreau91861262007-10-17 17:06:05 +02003515 /* we are on a new proxy */
Willy Tarreau91861262007-10-17 17:06:05 +02003516 if (uri && uri->scope) {
3517 /* we have a limited scope, we have to check the proxy name */
3518 struct stat_scope *scope;
3519 int len;
3520
3521 len = strlen(px->id);
3522 scope = uri->scope;
3523
3524 while (scope) {
3525 /* match exact proxy name */
3526 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
3527 break;
3528
3529 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02003530 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02003531 break;
3532 scope = scope->next;
3533 }
3534
3535 /* proxy name not found : don't dump anything */
3536 if (scope == NULL)
3537 return 1;
3538 }
3539
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003540 /* if the user has requested a limited output and the proxy
3541 * name does not match, skip it.
3542 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003543 if (appctx->ctx.stats.scope_len &&
3544 strnistr(px->id, strlen(px->id), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL)
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003545 return 1;
3546
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003547 if ((appctx->ctx.stats.flags & STAT_BOUND) &&
3548 (appctx->ctx.stats.iid != -1) &&
3549 (px->uuid != appctx->ctx.stats.iid))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003550 return 1;
3551
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003552 appctx->ctx.stats.px_st = STAT_PX_ST_TH;
Willy Tarreau91861262007-10-17 17:06:05 +02003553 /* fall through */
3554
Willy Tarreau295a8372011-03-10 11:25:07 +01003555 case STAT_PX_ST_TH:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003556 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003557 stats_dump_html_px_hdr(si, px, uri);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003558 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02003559 return 0;
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003560 }
Willy Tarreau91861262007-10-17 17:06:05 +02003561
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003562 appctx->ctx.stats.px_st = STAT_PX_ST_FE;
Willy Tarreau91861262007-10-17 17:06:05 +02003563 /* fall through */
3564
Willy Tarreau295a8372011-03-10 11:25:07 +01003565 case STAT_PX_ST_FE:
Willy Tarreau91861262007-10-17 17:06:05 +02003566 /* print the frontend */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003567 if (stats_dump_fe_stats(si, px))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003568 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02003569 return 0;
Willy Tarreau91861262007-10-17 17:06:05 +02003570
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003571 appctx->ctx.stats.l = px->conf.listeners.n;
3572 appctx->ctx.stats.px_st = STAT_PX_ST_LI;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003573 /* fall through */
3574
Willy Tarreau295a8372011-03-10 11:25:07 +01003575 case STAT_PX_ST_LI:
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003576 /* stats.l has been initialized above */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003577 for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) {
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01003578 if (buffer_almost_full(rep->buf)) {
3579 rep->flags |= CF_WAKE_WRITE;
Willy Tarreau4e33d862009-10-11 23:35:10 +02003580 return 0;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01003581 }
Willy Tarreau4e33d862009-10-11 23:35:10 +02003582
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003583 l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003584 if (!l->counters)
3585 continue;
3586
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003587 if (appctx->ctx.stats.flags & STAT_BOUND) {
3588 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO)))
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003589 break;
3590
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003591 if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003592 continue;
3593 }
3594
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003595 /* print the frontend */
3596 if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0))
3597 if (bi_putchk(rep, &trash) == -1)
3598 return 0;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003599 }
3600
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003601 appctx->ctx.stats.sv = px->srv; /* may be NULL */
3602 appctx->ctx.stats.px_st = STAT_PX_ST_SV;
Willy Tarreau91861262007-10-17 17:06:05 +02003603 /* fall through */
3604
Willy Tarreau295a8372011-03-10 11:25:07 +01003605 case STAT_PX_ST_SV:
Willy Tarreau91861262007-10-17 17:06:05 +02003606 /* stats.sv has been initialized above */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003607 for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01003608 int sv_state; /* 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, 6=unchecked */
Willy Tarreau91861262007-10-17 17:06:05 +02003609
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01003610 if (buffer_almost_full(rep->buf)) {
3611 rep->flags |= CF_WAKE_WRITE;
Willy Tarreau4e33d862009-10-11 23:35:10 +02003612 return 0;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01003613 }
Willy Tarreau4e33d862009-10-11 23:35:10 +02003614
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003615 sv = appctx->ctx.stats.sv;
Willy Tarreau91861262007-10-17 17:06:05 +02003616
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003617 if (appctx->ctx.stats.flags & STAT_BOUND) {
3618 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV)))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003619 break;
3620
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003621 if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid)
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003622 continue;
3623 }
3624
Willy Tarreau44267702011-10-28 15:35:33 +02003625 if (sv->track)
3626 svs = sv->track;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003627 else
3628 svs = sv;
3629
Willy Tarreau91861262007-10-17 17:06:05 +02003630 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Willy Tarreauff5ae352013-12-11 20:36:34 +01003631 if (!(svs->check.state & CHK_ST_ENABLED))
Simon Horman8c3d0be2013-11-25 10:46:40 +09003632 sv_state = 8;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003633 else if (svs->state & SRV_RUNNING) {
Simon Horman58c32972013-11-25 10:46:38 +09003634 if (svs->check.health == svs->check.rise + svs->check.fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02003635 sv_state = 3; /* UP */
3636 else
3637 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01003638
Willy Tarreau6b7764a2013-12-04 00:43:21 +01003639 if (svs->state & SRV_DRAIN)
Simon Horman8c3d0be2013-11-25 10:46:40 +09003640 sv_state += 4;
Willy Tarreau6b7764a2013-12-04 00:43:21 +01003641 else if (svs->state & SRV_GOINGDOWN)
3642 sv_state += 2;
Willy Tarreau2ea81932007-11-30 12:04:38 +01003643 }
Willy Tarreau91861262007-10-17 17:06:05 +02003644 else
Simon Horman125d0992013-02-24 17:23:38 +09003645 if (svs->check.health)
Willy Tarreau91861262007-10-17 17:06:05 +02003646 sv_state = 1; /* going up */
3647 else
3648 sv_state = 0; /* DOWN */
3649
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003650 if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (appctx->ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02003651 /* do not report servers which are DOWN */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003652 appctx->ctx.stats.sv = sv->next;
Willy Tarreau91861262007-10-17 17:06:05 +02003653 continue;
3654 }
3655
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003656 if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state))
3657 if (bi_putchk(rep, &trash) == -1)
3658 return 0;
3659 } /* for sv */
Cyril Bonté474be412010-10-12 00:14:36 +02003660
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003661 appctx->ctx.stats.px_st = STAT_PX_ST_BE;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003662 /* fall through */
Cyril Bonté70be45d2010-10-12 00:14:35 +02003663
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003664 case STAT_PX_ST_BE:
3665 /* print the backend */
3666 if (stats_dump_be_stats(si, px, uri ? uri->flags : 0))
3667 if (bi_putchk(rep, &trash) == -1)
3668 return 0;
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003669
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003670 appctx->ctx.stats.px_st = STAT_PX_ST_END;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003671 /* fall through */
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003672
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003673 case STAT_PX_ST_END:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003674 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003675 stats_dump_html_px_end(si, px);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003676 if (bi_putchk(rep, &trash) == -1)
3677 return 0;
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003678 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003679
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003680 appctx->ctx.stats.px_st = STAT_PX_ST_FIN;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003681 /* fall through */
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003682
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003683 case STAT_PX_ST_FIN:
3684 return 1;
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003685
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003686 default:
3687 /* unknown state, we should put an abort() here ! */
3688 return 1;
3689 }
3690}
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003691
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003692/* Dumps the HTTP stats head block to the trash for and uses the per-uri
3693 * parameters <uri>. The caller is responsible for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003694 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003695static void stats_dump_html_head(struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003696{
3697 /* WARNING! This must fit in the first buffer !!! */
3698 chunk_appendf(&trash,
3699 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
3700 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
3701 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
3702 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
3703 "<style type=\"text/css\"><!--\n"
3704 "body {"
3705 " font-family: arial, helvetica, sans-serif;"
3706 " font-size: 12px;"
3707 " font-weight: normal;"
3708 " color: black;"
3709 " background: white;"
3710 "}\n"
3711 "th,td {"
3712 " font-size: 10px;"
3713 "}\n"
3714 "h1 {"
3715 " font-size: x-large;"
3716 " margin-bottom: 0.5em;"
3717 "}\n"
3718 "h2 {"
3719 " font-family: helvetica, arial;"
3720 " font-size: x-large;"
3721 " font-weight: bold;"
3722 " font-style: italic;"
3723 " color: #6020a0;"
3724 " margin-top: 0em;"
3725 " margin-bottom: 0em;"
3726 "}\n"
3727 "h3 {"
3728 " font-family: helvetica, arial;"
3729 " font-size: 16px;"
3730 " font-weight: bold;"
3731 " color: #b00040;"
3732 " background: #e8e8d0;"
3733 " margin-top: 0em;"
3734 " margin-bottom: 0em;"
3735 "}\n"
3736 "li {"
3737 " margin-top: 0.25em;"
3738 " margin-right: 2em;"
3739 "}\n"
3740 ".hr {margin-top: 0.25em;"
3741 " border-color: black;"
3742 " border-bottom-style: solid;"
3743 "}\n"
3744 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
3745 ".total {background: #20D0D0;color: #ffff80;}\n"
3746 ".frontend {background: #e8e8d0;}\n"
3747 ".socket {background: #d0d0d0;}\n"
3748 ".backend {background: #e8e8d0;}\n"
3749 ".active0 {background: #ff9090;}\n"
3750 ".active1 {background: #ffd020;}\n"
3751 ".active2 {background: #ffffa0;}\n"
3752 ".active3 {background: #c0ffc0;}\n"
3753 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
Willy Tarreau6b7764a2013-12-04 00:43:21 +01003754 ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */
3755 ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */
3756 ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */
Simon Horman8c3d0be2013-11-25 10:46:40 +09003757 ".active8 {background: #e0e0e0;}\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003758 ".backup0 {background: #ff9090;}\n"
3759 ".backup1 {background: #ff80ff;}\n"
3760 ".backup2 {background: #c060ff;}\n"
3761 ".backup3 {background: #b0d0ff;}\n"
3762 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
3763 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
Simon Horman8c3d0be2013-11-25 10:46:40 +09003764 ".backup6 {background: #c060ff;}\n"
3765 ".backup7 {background: #cc9900;}\n"
3766 ".backup8 {background: #e0e0e0;}\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003767 ".maintain {background: #c07820;}\n"
3768 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
3769 "\n"
3770 "a.px:link {color: #ffff40; text-decoration: none;}"
3771 "a.px:visited {color: #ffff40; text-decoration: none;}"
3772 "a.px:hover {color: #ffffff; text-decoration: none;}"
3773 "a.lfsb:link {color: #000000; text-decoration: none;}"
3774 "a.lfsb:visited {color: #000000; text-decoration: none;}"
3775 "a.lfsb:hover {color: #505050; text-decoration: none;}"
3776 "\n"
3777 "table.tbl { border-collapse: collapse; border-style: none;}\n"
3778 "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"
3779 "table.tbl td.ac { text-align: center;}\n"
3780 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
3781 "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n"
3782 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
3783 "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n"
3784 "\n"
3785 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
3786 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
3787 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
Willy Tarreau466c9b52012-12-23 02:25:03 +01003788 "table.det { border-collapse: collapse; border-style: none; }\n"
3789 "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 +01003790 "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 +01003791 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003792 "div.tips {\n"
Willy Tarreaue7dbfc62012-12-23 01:59:23 +01003793 " display:block;\n"
3794 " visibility:hidden;\n"
3795 " z-index:2147483647;\n"
3796 " position:absolute;\n"
3797 " padding:2px 4px 3px;\n"
3798 " background:#f0f060; color:#000000;\n"
3799 " border:1px solid #7040c0;\n"
3800 " white-space:nowrap;\n"
3801 " font-style:normal;font-size:11px;font-weight:normal;\n"
3802 " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n"
3803 " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n"
3804 "}\n"
Willy Tarreau656a9ce2013-04-19 14:41:29 +02003805 "u:hover div.tips {visibility:visible;}\n"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003806 "-->\n"
3807 "</style></head>\n",
3808 (uri->flags & ST_SHNODE) ? " on " : "",
3809 (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
3810 );
3811}
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003812
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003813/* Dumps the HTML stats information block to the trash for and uses the state from
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003814 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003815 * for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003816 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01003817static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003818{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003819 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003820 unsigned int up = (now.tv_sec - start_date.tv_sec);
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003821 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003822
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003823 /* WARNING! this has to fit the first packet too.
3824 * We are around 3.5 kB, add adding entries will
3825 * become tricky if we want to support 4kB buffers !
3826 */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003827 chunk_appendf(&trash,
3828 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
3829 PRODUCT_NAME "%s</a></h1>\n"
3830 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
3831 "<hr width=\"100%%\" class=\"hr\">\n"
3832 "<h3>&gt; General process information</h3>\n"
3833 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
3834 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
3835 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
3836 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
3837 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
3838 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n"
3839 "Running tasks: %d/%d; idle = %d %%<br>\n"
3840 "</td><td align=\"center\" nowrap>\n"
3841 "<table class=\"lgd\"><tr>\n"
3842 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
3843 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
3844 "</tr><tr>\n"
3845 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
3846 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
3847 "</tr><tr>\n"
3848 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
3849 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
3850 "</tr><tr>\n"
3851 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Simon Horman8c3d0be2013-11-25 10:46:40 +09003852 "</tr><tr>\n"
3853 "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003854 "</tr><tr>\n"
3855 "<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 -07003856 "</tr><tr>\n"
Willy Tarreau6b7764a2013-12-04 00:43:21 +01003857 "<td class=\"active7\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance &nbsp;</td>"
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003858 "</tr></table>\n"
Willy Tarreau6b7764a2013-12-04 00:43:21 +01003859 "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled."
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003860 "</td>"
3861 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
3862 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
3863 "",
3864 (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING),
3865 pid, (uri->flags & ST_SHNODE) ? " on " : "",
3866 (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
3867 (uri->flags & ST_SHDESC) ? ": " : "",
3868 (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
3869 pid, relative_pid, global.nbproc,
3870 up / 86400, (up % 86400) / 3600,
3871 (up % 3600) / 60, (up % 60),
3872 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
3873 global.rlimit_memmax ? " MB" : "",
3874 global.rlimit_nofile,
3875 global.maxsock, global.maxconn, global.maxpipes,
3876 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
3877 run_queue_cur, nb_tasks_cur, idle_pct
3878 );
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003879
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003880 /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
3881 memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
3882 scope_txt[appctx->ctx.stats.scope_len] = '\0';
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003883
3884 chunk_appendf(&trash,
Cyril Bonté54656842013-04-18 22:38:35 +02003885 "<li><form method=\"GET\" action=\"%s%s%s\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003886 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003887 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
3888 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
3889 (appctx->ctx.stats.scope_len > 0) ? scope_txt : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003890 STAT_SCOPE_TXT_MAXLEN);
3891
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003892 /* 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 +02003893 scope_txt[0] = 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003894 if (appctx->ctx.stats.scope_len) {
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003895 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003896 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
3897 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003898 }
3899
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003900 if (appctx->ctx.stats.flags & STAT_HIDE_DOWN)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003901 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003902 "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003903 uri->uri_prefix,
3904 "",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003905 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003906 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003907 else
3908 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003909 "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003910 uri->uri_prefix,
3911 ";up",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003912 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003913 scope_txt);
Willy Tarreau91861262007-10-17 17:06:05 +02003914
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003915 if (uri->refresh > 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003916 if (appctx->ctx.stats.flags & STAT_NO_REFRESH)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003917 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003918 "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003919 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003920 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003921 "",
3922 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003923 else
3924 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003925 "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003926 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003927 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003928 ";norefresh",
3929 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003930 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02003931
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003932 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003933 "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003934 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003935 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
3936 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003937 scope_txt);
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02003938
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003939 chunk_appendf(&trash,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003940 "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n",
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003941 uri->uri_prefix,
de Lafond Guillaume88c278f2013-04-15 19:27:10 +02003942 (uri->refresh > 0) ? ";norefresh" : "",
3943 scope_txt);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003944
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003945 chunk_appendf(&trash,
3946 "</ul></td>"
3947 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
3948 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
3949 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
3950 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
3951 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
3952 "</ul>"
3953 "</td>"
3954 "</tr></table>\n"
3955 ""
3956 );
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003957
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003958 if (appctx->ctx.stats.st_code) {
3959 switch (appctx->ctx.stats.st_code) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003960 case STAT_STATUS_DONE:
3961 chunk_appendf(&trash,
3962 "<p><div class=active3>"
Willy Tarreauba6be982013-04-19 12:16:55 +02003963 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003964 "Action processed successfully."
Willy Tarreauba6be982013-04-19 12:16:55 +02003965 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003966 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
3967 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02003968 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003969 break;
3970 case STAT_STATUS_NONE:
3971 chunk_appendf(&trash,
3972 "<p><div class=active2>"
Willy Tarreauba6be982013-04-19 12:16:55 +02003973 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003974 "Nothing has changed."
Willy Tarreauba6be982013-04-19 12:16:55 +02003975 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003976 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
3977 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02003978 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003979 break;
3980 case STAT_STATUS_PART:
3981 chunk_appendf(&trash,
3982 "<p><div class=active2>"
Willy Tarreauba6be982013-04-19 12:16:55 +02003983 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003984 "Action partially processed.<br>"
3985 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
Willy Tarreauba6be982013-04-19 12:16:55 +02003986 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01003987 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
3988 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02003989 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003990 break;
3991 case STAT_STATUS_ERRP:
3992 chunk_appendf(&trash,
3993 "<p><div class=active0>"
Willy Tarreauba6be982013-04-19 12:16:55 +02003994 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01003995 "Action not processed because of invalid parameters."
3996 "<ul>"
3997 "<li>The action is maybe unknown.</li>"
3998 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
3999 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
4000 "</ul>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004001 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004002 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4003 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004004 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004005 break;
4006 case STAT_STATUS_EXCD:
4007 chunk_appendf(&trash,
4008 "<p><div class=active0>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004009 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004010 "<b>Action not processed : the buffer couldn't store all the data.<br>"
4011 "You should retry with less servers at a time.</b>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004012 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004013 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4014 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004015 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004016 break;
4017 case STAT_STATUS_DENY:
4018 chunk_appendf(&trash,
4019 "<p><div class=active0>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004020 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004021 "<b>Action denied.</b>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004022 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004023 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4024 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004025 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004026 break;
4027 default:
4028 chunk_appendf(&trash,
Simon Horman8c3d0be2013-11-25 10:46:40 +09004029 "<p><div class=active8>"
Willy Tarreauba6be982013-04-19 12:16:55 +02004030 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004031 "Unexpected result."
Willy Tarreauba6be982013-04-19 12:16:55 +02004032 "</div>\n", uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004033 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4034 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreauba6be982013-04-19 12:16:55 +02004035 scope_txt);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004036 }
4037 chunk_appendf(&trash, "<p>\n");
4038 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004039}
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01004040
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004041/* Dumps the HTML stats trailer block to the trash. The caller is responsible
4042 * for clearing the trash if needed.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004043 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004044static void stats_dump_html_end()
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004045{
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004046 chunk_appendf(&trash, "</body></html>\n");
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004047}
Willy Tarreau7f062c42009-03-05 18:43:00 +01004048
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004049/* This function dumps statistics onto the stream interface's read buffer in
4050 * either CSV or HTML format. <uri> contains some HTML-specific parameters that
Willy Tarreau306f8302013-07-08 15:53:06 +02004051 * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if
4052 * it had to stop writing data and an I/O is needed, 1 if the dump is finished
4053 * and the session must be closed, or -1 in case of any error. This function is
4054 * used by both the CLI and the HTTP handlers.
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004055 */
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004056static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004057{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004058 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004059 struct channel *rep = si->ib;
4060 struct proxy *px;
Willy Tarreau7f062c42009-03-05 18:43:00 +01004061
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004062 chunk_reset(&trash);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02004063
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004064 switch (appctx->st2) {
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004065 case STAT_ST_INIT:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004066 appctx->st2 = STAT_ST_HEAD; /* let's start producing data */
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004067 /* fall through */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01004068
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004069 case STAT_ST_HEAD:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004070 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004071 stats_dump_html_head(uri);
Willy Tarreau354898b2012-12-23 18:15:23 +01004072 else
4073 stats_dump_csv_header();
Willy Tarreaud9b587f2010-02-26 10:05:55 +01004074
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004075 if (bi_putchk(rep, &trash) == -1)
4076 return 0;
Willy Tarreauae526782010-03-04 20:34:23 +01004077
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004078 appctx->st2 = STAT_ST_INFO;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004079 /* fall through */
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01004080
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004081 case STAT_ST_INFO:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004082 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004083 stats_dump_html_info(si, uri);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004084 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02004085 return 0;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004086 }
Willy Tarreau91861262007-10-17 17:06:05 +02004087
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004088 appctx->ctx.stats.px = proxy;
4089 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
4090 appctx->st2 = STAT_ST_LIST;
Willy Tarreau91861262007-10-17 17:06:05 +02004091 /* fall through */
4092
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004093 case STAT_ST_LIST:
4094 /* dump proxies */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004095 while (appctx->ctx.stats.px) {
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004096 if (buffer_almost_full(rep->buf)) {
4097 rep->flags |= CF_WAKE_WRITE;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004098 return 0;
Willy Tarreaud7ad9f52013-12-31 17:26:25 +01004099 }
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004100
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004101 px = appctx->ctx.stats.px;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004102 /* skip the disabled proxies, global frontend and non-networked ones */
4103 if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004104 if (stats_dump_proxy_to_buffer(si, px, uri) == 0)
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004105 return 0;
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004106
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004107 appctx->ctx.stats.px = px->next;
4108 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004109 }
4110 /* here, we just have reached the last proxy */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004111
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004112 appctx->st2 = STAT_ST_END;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004113 /* fall through */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004114
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004115 case STAT_ST_END:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004116 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreaub5ba4ec2012-12-22 23:20:30 +01004117 stats_dump_html_end();
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004118 if (bi_putchk(rep, &trash) == -1)
4119 return 0;
4120 }
Willy Tarreau55058a72012-11-21 08:27:21 +01004121
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004122 appctx->st2 = STAT_ST_FIN;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004123 /* fall through */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02004124
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004125 case STAT_ST_FIN:
4126 return 1;
Willy Tarreau55058a72012-11-21 08:27:21 +01004127
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004128 default:
4129 /* unknown state ! */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004130 appctx->st2 = STAT_ST_FIN;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004131 return -1;
4132 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004133}
Willy Tarreauae526782010-03-04 20:34:23 +01004134
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004135/* We reached the stats page through a POST request. The appctx is
4136 * expected to have already been allocated by the caller.
Willy Tarreau347a35d2013-11-22 17:51:09 +01004137 * Parse the posted data and enable/disable servers if necessary.
4138 * Returns 1 if request was parsed or zero if it needs more data.
4139 */
4140static int stats_process_http_post(struct stream_interface *si)
4141{
4142 struct session *s = session_from_task(si->owner);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004143 struct appctx *appctx = objt_appctx(si->end);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004144
4145 struct proxy *px = NULL;
4146 struct server *sv = NULL;
4147
4148 char key[LINESIZE];
4149 int action = ST_ADM_ACTION_NONE;
4150 int reprocess = 0;
4151
4152 int total_servers = 0;
4153 int altered_servers = 0;
4154
4155 char *first_param, *cur_param, *next_param, *end_params;
4156 char *st_cur_param = NULL;
4157 char *st_next_param = NULL;
4158
4159 struct chunk *temp;
4160 int reql;
4161
4162 temp = get_trash_chunk();
4163 if (temp->size < s->txn.req.body_len) {
4164 /* too large request */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004165 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004166 goto out;
4167 }
4168
4169 reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2);
4170 if (reql <= 0) {
4171 /* we need more data */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004172 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004173 return 0;
4174 }
4175
4176 first_param = temp->str;
4177 end_params = temp->str + reql;
4178 cur_param = next_param = end_params;
4179 *end_params = '\0';
4180
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004181 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004182
4183 /*
4184 * Parse the parameters in reverse order to only store the last value.
4185 * From the html form, the backend and the action are at the end.
4186 */
4187 while (cur_param > first_param) {
4188 char *value;
4189 int poffset, plen;
4190
4191 cur_param--;
4192
4193 if ((*cur_param == '&') || (cur_param == first_param)) {
4194 reprocess_servers:
4195 /* Parse the key */
4196 poffset = (cur_param != first_param ? 1 : 0);
4197 plen = next_param - cur_param + (cur_param == first_param ? 1 : 0);
4198 if ((plen > 0) && (plen <= sizeof(key))) {
4199 strncpy(key, cur_param + poffset, plen);
4200 key[plen - 1] = '\0';
4201 } else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004202 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004203 goto out;
4204 }
4205
4206 /* Parse the value */
4207 value = key;
4208 while (*value != '\0' && *value != '=') {
4209 value++;
4210 }
4211 if (*value == '=') {
4212 /* Ok, a value is found, we can mark the end of the key */
4213 *value++ = '\0';
4214 }
4215 if (url_decode(key) < 0 || url_decode(value) < 0)
4216 break;
4217
4218 /* Now we can check the key to see what to do */
4219 if (!px && (strcmp(key, "b") == 0)) {
4220 if ((px = findproxy(value, PR_CAP_BE)) == NULL) {
4221 /* the backend name is unknown or ambiguous (duplicate names) */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004222 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004223 goto out;
4224 }
4225 }
4226 else if (!action && (strcmp(key, "action") == 0)) {
4227 if (strcmp(value, "disable") == 0) {
4228 action = ST_ADM_ACTION_DISABLE;
4229 }
4230 else if (strcmp(value, "enable") == 0) {
4231 action = ST_ADM_ACTION_ENABLE;
4232 }
4233 else if (strcmp(value, "stop") == 0) {
4234 action = ST_ADM_ACTION_STOP;
4235 }
4236 else if (strcmp(value, "start") == 0) {
4237 action = ST_ADM_ACTION_START;
4238 }
4239 else if (strcmp(value, "shutdown") == 0) {
4240 action = ST_ADM_ACTION_SHUTDOWN;
4241 }
4242 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004243 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004244 goto out;
4245 }
4246 }
4247 else if (strcmp(key, "s") == 0) {
4248 if (!(px && action)) {
4249 /*
4250 * Indicates that we'll need to reprocess the parameters
4251 * as soon as backend and action are known
4252 */
4253 if (!reprocess) {
4254 st_cur_param = cur_param;
4255 st_next_param = next_param;
4256 }
4257 reprocess = 1;
4258 }
4259 else if ((sv = findserver(px, value)) != NULL) {
4260 switch (action) {
4261 case ST_ADM_ACTION_DISABLE:
4262 if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) {
4263 /* Not already in maintenance, we can change the server state */
4264 sv->state |= SRV_MAINTAIN;
Willy Tarreau33a08db2013-12-11 21:03:31 +01004265 sv->check.state |= CHK_ST_PAUSED;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004266 set_server_down(&sv->check);
4267 altered_servers++;
4268 total_servers++;
4269 }
4270 break;
4271 case ST_ADM_ACTION_ENABLE:
4272 if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) {
Willy Tarreaua3ae9322013-12-28 21:28:49 +01004273 /* Already in maintenance, we can change the server state.
4274 * If this server tracks the status of another one,
4275 * we must restore the good status.
4276 */
4277 if (!sv->track || (sv->track->state & SRV_RUNNING)) {
4278 set_server_up(&sv->check);
4279 sv->check.health = sv->check.rise; /* up, but will fall down at first failure */
4280 }
4281 else {
4282 sv->state &= ~SRV_MAINTAIN;
4283 sv->check.state &= ~CHK_ST_PAUSED;
4284 set_server_down(&sv->check);
4285 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01004286 altered_servers++;
4287 total_servers++;
4288 }
4289 break;
4290 case ST_ADM_ACTION_STOP:
4291 case ST_ADM_ACTION_START:
4292 if (action == ST_ADM_ACTION_START)
4293 sv->uweight = sv->iweight;
4294 else
4295 sv->uweight = 0;
4296
4297 server_recalc_eweight(sv);
4298 set_server_drain_state(sv);
4299
4300 altered_servers++;
4301 total_servers++;
4302 break;
4303 case ST_ADM_ACTION_SHUTDOWN:
4304 if (px->state != PR_STSTOPPED) {
4305 struct session *sess, *sess_bck;
4306
4307 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
4308 if (sess->srv_conn == sv)
4309 session_shutdown(sess, SN_ERR_KILLED);
4310
4311 altered_servers++;
4312 total_servers++;
4313 }
4314 break;
4315 }
4316 } else {
4317 /* the server name is unknown or ambiguous (duplicate names) */
4318 total_servers++;
4319 }
4320 }
4321 if (reprocess && px && action) {
4322 /* Now, we know the backend and the action chosen by the user.
4323 * We can safely restart from the first server parameter
4324 * to reprocess them
4325 */
4326 cur_param = st_cur_param;
4327 next_param = st_next_param;
4328 reprocess = 0;
4329 goto reprocess_servers;
4330 }
4331
4332 next_param = cur_param;
4333 }
4334 }
4335
4336 if (total_servers == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004337 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004338 }
4339 else if (altered_servers == 0) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004340 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004341 }
4342 else if (altered_servers == total_servers) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004343 appctx->ctx.stats.st_code = STAT_STATUS_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004344 }
4345 else {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004346 appctx->ctx.stats.st_code = STAT_STATUS_PART;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004347 }
4348 out:
4349 return 1;
4350}
4351
4352
4353static int stats_send_http_headers(struct stream_interface *si)
4354{
4355 struct session *s = session_from_task(si->owner);
4356 struct uri_auth *uri = s->be->uri_auth;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004357 struct appctx *appctx = objt_appctx(si->end);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004358
4359 chunk_printf(&trash,
Willy Tarreau51437d22013-12-29 00:43:40 +01004360 "HTTP/1.0 200 OK\r\n"
Willy Tarreau347a35d2013-11-22 17:51:09 +01004361 "Cache-Control: no-cache\r\n"
4362 "Connection: close\r\n"
4363 "Content-Type: %s\r\n",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004364 (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain");
Willy Tarreau347a35d2013-11-22 17:51:09 +01004365
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004366 if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH))
Willy Tarreau347a35d2013-11-22 17:51:09 +01004367 chunk_appendf(&trash, "Refresh: %d\r\n",
4368 uri->refresh);
4369
Willy Tarreau51437d22013-12-29 00:43:40 +01004370 chunk_appendf(&trash, "\r\n");
Willy Tarreau347a35d2013-11-22 17:51:09 +01004371
4372 s->txn.status = 200;
4373 s->logs.tv_request = now;
4374
4375 if (bi_putchk(si->ib, &trash) == -1)
4376 return 0;
4377
4378 return 1;
4379}
4380
4381static int stats_send_http_redirect(struct stream_interface *si)
4382{
4383 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
4384 struct session *s = session_from_task(si->owner);
4385 struct uri_auth *uri = s->be->uri_auth;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004386 struct appctx *appctx = objt_appctx(si->end);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004387
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004388 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
Willy Tarreau347a35d2013-11-22 17:51:09 +01004389 scope_txt[0] = 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004390 if (appctx->ctx.stats.scope_len) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004391 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004392 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
4393 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004394 }
4395
4396 /* We don't want to land on the posted stats page because a refresh will
4397 * repost the data. We don't want this to happen on accident so we redirect
4398 * the browse to the stats page with a GET.
4399 */
4400 chunk_printf(&trash,
4401 "HTTP/1.1 303 See Other\r\n"
4402 "Cache-Control: no-cache\r\n"
4403 "Content-Type: text/plain\r\n"
4404 "Connection: close\r\n"
4405 "Location: %s;st=%s%s%s%s\r\n"
4406 "\r\n",
4407 uri->uri_prefix,
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004408 ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) &&
4409 (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) &&
4410 stat_status_codes[appctx->ctx.stats.st_code]) ?
4411 stat_status_codes[appctx->ctx.stats.st_code] :
Willy Tarreau347a35d2013-11-22 17:51:09 +01004412 stat_status_codes[STAT_STATUS_UNKN],
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004413 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
4414 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
Willy Tarreau347a35d2013-11-22 17:51:09 +01004415 scope_txt);
4416
4417 s->txn.status = 303;
4418 s->logs.tv_request = now;
4419
4420 if (bi_putchk(si->ib, &trash) == -1)
4421 return 0;
4422
4423 return 1;
4424}
4425
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004426/* This I/O handler runs as an applet embedded in a stream interface. It is
4427 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004428 * appctx->st0 contains the operation in progress (dump, done). The handler
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004429 * automatically unregisters itself once transfer is complete.
4430 */
4431static void http_stats_io_handler(struct stream_interface *si)
4432{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004433 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau306f8302013-07-08 15:53:06 +02004434 struct session *s = session_from_task(si->owner);
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004435 struct channel *req = si->ob;
4436 struct channel *res = si->ib;
Willy Tarreau55058a72012-11-21 08:27:21 +01004437
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004438 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
4439 goto out;
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01004440
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004441 /* check that the output is not closed */
4442 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004443 appctx->st0 = STAT_HTTP_DONE;
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02004444
Willy Tarreau347a35d2013-11-22 17:51:09 +01004445 /* all states are processed in sequence */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004446 if (appctx->st0 == STAT_HTTP_HEAD) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004447 if (stats_send_http_headers(si)) {
4448 if (s->txn.meth == HTTP_METH_HEAD)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004449 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004450 else
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004451 appctx->st0 = STAT_HTTP_DUMP;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004452 }
Willy Tarreau347a35d2013-11-22 17:51:09 +01004453 }
4454
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004455 if (appctx->st0 == STAT_HTTP_DUMP) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004456 if (stats_dump_stat_to_buffer(si, s->be->uri_auth))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004457 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004458 }
Cyril Bonté70be45d2010-10-12 00:14:35 +02004459
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004460 if (appctx->st0 == STAT_HTTP_POST) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004461 if (stats_process_http_post(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004462 appctx->st0 = STAT_HTTP_LAST;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004463 else if (si->ob->flags & CF_SHUTR)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004464 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004465 }
4466
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004467 if (appctx->st0 == STAT_HTTP_LAST) {
Willy Tarreau347a35d2013-11-22 17:51:09 +01004468 if (stats_send_http_redirect(si))
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004469 appctx->st0 = STAT_HTTP_DONE;
Willy Tarreau347a35d2013-11-22 17:51:09 +01004470 }
4471
Willy Tarreau51437d22013-12-29 00:43:40 +01004472 if (appctx->st0 == STAT_HTTP_DONE)
4473 si_shutw(si);
Willy Tarreau347a35d2013-11-22 17:51:09 +01004474
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004475 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST))
4476 si_shutw(si);
Willy Tarreau91861262007-10-17 17:06:05 +02004477
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004478 if (appctx->st0 == STAT_HTTP_DONE) {
Willy Tarreau96d44912013-11-22 12:25:24 +01004479 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) {
4480 si_shutr(si);
4481 res->flags |= CF_READ_NULL;
4482 }
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004483 }
Willy Tarreau91861262007-10-17 17:06:05 +02004484
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004485 /* update all other flags and resync with the other side */
4486 si_update(si);
Willy Tarreau91861262007-10-17 17:06:05 +02004487
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004488 /* we don't want to expire timeouts while we're processing requests */
4489 si->ib->rex = TICK_ETERNITY;
4490 si->ob->wex = TICK_ETERNITY;
Willy Tarreau91861262007-10-17 17:06:05 +02004491
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004492 out:
4493 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
4494 /* check that we have released everything then unregister */
4495 stream_int_unregister_handler(si);
Willy Tarreau91861262007-10-17 17:06:05 +02004496 }
4497}
4498
Willy Tarreaud9bdcd52012-12-22 20:31:10 +01004499
Willy Tarreau909d5172012-11-26 03:04:41 +01004500static inline const char *get_conn_ctrl_name(const struct connection *conn)
4501{
Willy Tarreau3c728722014-01-23 13:50:42 +01004502 if (!conn_ctrl_ready(conn))
Willy Tarreau909d5172012-11-26 03:04:41 +01004503 return "NONE";
4504 return conn->ctrl->name;
4505}
4506
4507static inline const char *get_conn_xprt_name(const struct connection *conn)
4508{
4509 static char ptr[17];
4510
Willy Tarreauaad69382014-01-23 14:21:42 +01004511 if (!conn_xprt_ready(conn))
Willy Tarreau909d5172012-11-26 03:04:41 +01004512 return "NONE";
4513
4514 if (conn->xprt == &raw_sock)
4515 return "RAW";
4516
4517#ifdef USE_OPENSSL
4518 if (conn->xprt == &ssl_sock)
4519 return "SSL";
4520#endif
4521 snprintf(ptr, sizeof(ptr), "%p", conn->xprt);
4522 return ptr;
4523}
4524
4525static inline const char *get_conn_data_name(const struct connection *conn)
4526{
4527 static char ptr[17];
4528
4529 if (!conn->data)
4530 return "NONE";
4531
4532 if (conn->data == &sess_conn_cb)
4533 return "SESS";
4534
4535 if (conn->data == &si_conn_cb)
4536 return "STRM";
4537
4538 if (conn->data == &check_conn_cb)
4539 return "CHCK";
4540
4541 snprintf(ptr, sizeof(ptr), "%p", conn->data);
4542 return ptr;
4543}
4544
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02004545/* This function dumps a complete session state onto the stream interface's
Willy Tarreau306f8302013-07-08 15:53:06 +02004546 * read buffer. The session has to be set in sess->target. It returns
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01004547 * 0 if the output buffer is full and it needs to be called again, otherwise
4548 * non-zero. It is designed to be called from stats_dump_sess_to_buffer() below.
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004549 */
Willy Tarreau76153662012-11-26 01:16:39 +01004550static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004551{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004552 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004553 struct tm tm;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004554 extern const char *monthname[12];
4555 char pn[INET6_ADDRSTRLEN];
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004556 struct connection *conn;
Willy Tarreau284ddbf2013-12-01 20:45:00 +01004557 struct appctx *tmpctx;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004558
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004559 chunk_reset(&trash);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004560
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004561 if (appctx->ctx.sess.section > 0 && appctx->ctx.sess.uid != sess->uniq_id) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004562 /* session changed, no need to go any further */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004563 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
4564 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004565 return 0;
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004566 appctx->ctx.sess.uid = 0;
4567 appctx->ctx.sess.section = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004568 return 1;
4569 }
4570
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004571 switch (appctx->ctx.sess.section) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004572 case 0: /* main status of the session */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004573 appctx->ctx.sess.uid = sess->uniq_id;
4574 appctx->ctx.sess.section = 1;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004575 /* fall through */
4576
4577 case 1:
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01004578 get_localtime(sess->logs.accept_date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004579 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01004580 "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004581 sess,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01004582 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
4583 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004584 sess->uniq_id,
Willy Tarreaue95c4ce2013-01-24 00:48:39 +01004585 sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004586
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004587 conn = objt_conn(sess->si[0].end);
4588 switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004589 case AF_INET:
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004590 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004591 chunk_appendf(&trash, " source=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004592 pn, get_host_port(&conn->addr.from));
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004593 break;
4594 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004595 chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid);
Emeric Brun837ca522010-10-22 16:19:01 +02004596 break;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004597 default:
4598 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004599 chunk_appendf(&trash, "\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004600 break;
4601 }
4602
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004603 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004604 " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n",
Willy Tarreauee28de02010-06-01 09:51:00 +02004605 sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004606
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004607 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07004608 " frontend=%s (id=%u mode=%s), listener=%s (id=%u)",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004609 sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp",
4610 sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?",
4611 sess->listener ? sess->listener->luid : 0);
4612
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004613 if (conn)
4614 conn_get_to_addr(conn);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004615
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004616 switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) {
Daniel Schultze90690c72012-03-23 10:53:36 -07004617 case AF_INET:
4618 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004619 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004620 pn, get_host_port(&conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07004621 break;
4622 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004623 chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid);
Daniel Schultze90690c72012-03-23 10:53:36 -07004624 break;
4625 default:
4626 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004627 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07004628 break;
4629 }
4630
Willy Tarreau50943332011-09-02 17:33:05 +02004631 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004632 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07004633 " backend=%s (id=%u mode=%s)",
Willy Tarreau50943332011-09-02 17:33:05 +02004634 sess->be->id,
Daniel Schultze90690c72012-03-23 10:53:36 -07004635 sess->be->uuid, sess->be->mode ? "http" : "tcp");
4636 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004637 chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)");
Daniel Schultze90690c72012-03-23 10:53:36 -07004638
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004639 conn = objt_conn(sess->si[1].end);
4640 if (conn)
4641 conn_get_from_addr(conn);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004642
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004643 switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) {
Daniel Schultze90690c72012-03-23 10:53:36 -07004644 case AF_INET:
4645 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004646 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004647 pn, get_host_port(&conn->addr.from));
Daniel Schultze90690c72012-03-23 10:53:36 -07004648 break;
4649 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004650 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07004651 break;
4652 default:
4653 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004654 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07004655 break;
4656 }
4657
4658 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004659 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07004660 " server=%s (id=%u)",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01004661 objt_server(sess->target) ? objt_server(sess->target)->id : "<none>",
4662 objt_server(sess->target) ? objt_server(sess->target)->puid : 0);
Willy Tarreau50943332011-09-02 17:33:05 +02004663 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004664 chunk_appendf(&trash, " server=<NONE> (id=-1)");
Daniel Schultze90690c72012-03-23 10:53:36 -07004665
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004666 if (conn)
4667 conn_get_to_addr(conn);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004668
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004669 switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) {
Daniel Schultze90690c72012-03-23 10:53:36 -07004670 case AF_INET:
4671 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004672 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004673 pn, get_host_port(&conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07004674 break;
4675 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004676 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07004677 break;
4678 default:
4679 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004680 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07004681 break;
4682 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004683
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004684 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01004685 " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004686 sess->task,
4687 sess->task->state,
4688 sess->task->nice, sess->task->calls,
4689 sess->task->expire ?
4690 tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" :
4691 human_time(TICKS_TO_MS(sess->task->expire - now_ms),
4692 TICKS_TO_MS(1000)) : "<NEVER>",
4693 task_in_rq(sess->task) ? ", running" : "");
4694
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004695 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01004696 " age=%s)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004697 human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1));
4698
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004699 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01004700 " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n",
4701 &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status,
4702 http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state));
4703
4704 chunk_appendf(&trash,
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02004705 " si[0]=%p (state=%s flags=0x%02x endp0=%s:%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004706 &sess->si[0],
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01004707 si_state_str(sess->si[0].state),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004708 sess->si[0].flags,
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004709 obj_type_name(sess->si[0].end),
4710 obj_base_ptr(sess->si[0].end),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004711 sess->si[0].exp ?
4712 tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" :
4713 human_time(TICKS_TO_MS(sess->si[0].exp - now_ms),
4714 TICKS_TO_MS(1000)) : "<NEVER>",
4715 sess->si[0].err_type);
4716
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004717 chunk_appendf(&trash,
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02004718 " si[1]=%p (state=%s flags=0x%02x endp1=%s:%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004719 &sess->si[1],
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01004720 si_state_str(sess->si[1].state),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004721 sess->si[1].flags,
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004722 obj_type_name(sess->si[1].end),
4723 obj_base_ptr(sess->si[1].end),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004724 sess->si[1].exp ?
4725 tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" :
4726 human_time(TICKS_TO_MS(sess->si[1].exp - now_ms),
4727 TICKS_TO_MS(1000)) : "<NEVER>",
4728 sess->si[1].err_type);
4729
Willy Tarreau284ddbf2013-12-01 20:45:00 +01004730 if ((conn = objt_conn(sess->si[0].end)) != NULL) {
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004731 chunk_appendf(&trash,
4732 " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004733 conn,
4734 get_conn_ctrl_name(conn),
4735 get_conn_xprt_name(conn),
4736 get_conn_data_name(conn),
4737 obj_type_name(conn->target),
4738 obj_base_ptr(conn->target));
Willy Tarreau909d5172012-11-26 03:04:41 +01004739
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004740 chunk_appendf(&trash,
Willy Tarreau16f649c2014-01-25 19:10:48 +01004741 " flags=0x%08x fd=%d fd.state=%02x fd.cache=%d updt=%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004742 conn->flags,
4743 conn->t.sock.fd,
Willy Tarreau69a41fa2014-01-20 11:02:59 +01004744 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0,
Willy Tarreau15a4dec2014-01-20 11:09:39 +01004745 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004746 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004747 }
Willy Tarreau284ddbf2013-12-01 20:45:00 +01004748 else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) {
4749 chunk_appendf(&trash,
4750 " app0=%p st0=%d st1=%d st2=%d applet=%s\n",
4751 tmpctx,
4752 tmpctx->st0,
4753 tmpctx->st1,
4754 tmpctx->st2,
4755 tmpctx->applet->name);
4756 }
Willy Tarreaubc174aa2012-11-19 16:10:32 +01004757
Willy Tarreau284ddbf2013-12-01 20:45:00 +01004758 if ((conn = objt_conn(sess->si[1].end)) != NULL) {
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004759 chunk_appendf(&trash,
4760 " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004761 conn,
4762 get_conn_ctrl_name(conn),
4763 get_conn_xprt_name(conn),
4764 get_conn_data_name(conn),
4765 obj_type_name(conn->target),
4766 obj_base_ptr(conn->target));
Willy Tarreau909d5172012-11-26 03:04:41 +01004767
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004768 chunk_appendf(&trash,
4769 " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n",
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004770 conn->flags,
4771 conn->t.sock.fd,
Willy Tarreau69a41fa2014-01-20 11:02:59 +01004772 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0,
Willy Tarreau15a4dec2014-01-20 11:09:39 +01004773 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02004774 conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0);
Willy Tarreaucf644ed2013-09-29 17:19:56 +02004775 }
Willy Tarreau284ddbf2013-12-01 20:45:00 +01004776 else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) {
4777 chunk_appendf(&trash,
4778 " app1=%p st0=%d st1=%d st2=%d applet=%s\n",
4779 tmpctx,
4780 tmpctx->st0,
4781 tmpctx->st1,
4782 tmpctx->st2,
4783 tmpctx->applet->name);
4784 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004785
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004786 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01004787 " req=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004788 " an_exp=%s",
4789 sess->req,
4790 sess->req->flags, sess->req->analysers,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004791 sess->req->pipe ? sess->req->pipe->data : 0,
Willy Tarreau909d5172012-11-26 03:04:41 +01004792 sess->req->to_forward, sess->req->total,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004793 sess->req->analyse_exp ?
4794 human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms),
4795 TICKS_TO_MS(1000)) : "<NEVER>");
4796
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004797 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004798 " rex=%s",
4799 sess->req->rex ?
4800 human_time(TICKS_TO_MS(sess->req->rex - now_ms),
4801 TICKS_TO_MS(1000)) : "<NEVER>");
4802
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004803 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004804 " wex=%s\n"
Willy Tarreau909d5172012-11-26 03:04:41 +01004805 " buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004806 sess->req->wex ?
4807 human_time(TICKS_TO_MS(sess->req->wex - now_ms),
4808 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau909d5172012-11-26 03:04:41 +01004809 sess->req->buf,
4810 sess->req->buf->data, sess->req->buf->o,
Willy Tarreau9b28e032012-10-12 23:49:43 +02004811 (int)(sess->req->buf->p - sess->req->buf->data),
Willy Tarreau909d5172012-11-26 03:04:41 +01004812 sess->txn.req.next, sess->req->buf->i,
4813 sess->req->buf->size);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004814
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004815 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01004816 " res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004817 " an_exp=%s",
4818 sess->rep,
4819 sess->rep->flags, sess->rep->analysers,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004820 sess->rep->pipe ? sess->rep->pipe->data : 0,
Willy Tarreau909d5172012-11-26 03:04:41 +01004821 sess->rep->to_forward, sess->rep->total,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004822 sess->rep->analyse_exp ?
4823 human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms),
4824 TICKS_TO_MS(1000)) : "<NEVER>");
4825
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004826 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004827 " rex=%s",
4828 sess->rep->rex ?
4829 human_time(TICKS_TO_MS(sess->rep->rex - now_ms),
4830 TICKS_TO_MS(1000)) : "<NEVER>");
4831
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004832 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004833 " wex=%s\n"
Willy Tarreau909d5172012-11-26 03:04:41 +01004834 " buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004835 sess->rep->wex ?
4836 human_time(TICKS_TO_MS(sess->rep->wex - now_ms),
4837 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau909d5172012-11-26 03:04:41 +01004838 sess->rep->buf,
4839 sess->rep->buf->data, sess->rep->buf->o,
Willy Tarreau9b28e032012-10-12 23:49:43 +02004840 (int)(sess->rep->buf->p - sess->rep->buf->data),
Willy Tarreau909d5172012-11-26 03:04:41 +01004841 sess->txn.rsp.next, sess->rep->buf->i,
4842 sess->rep->buf->size);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004843
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004844 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004845 return 0;
4846
4847 /* use other states to dump the contents */
4848 }
4849 /* end of dump */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01004850 appctx->ctx.sess.uid = 0;
4851 appctx->ctx.sess.section = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01004852 return 1;
4853}
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01004854
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004855static int stats_pats_list(struct stream_interface *si)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004856{
4857 struct appctx *appctx = __objt_appctx(si->end);
4858
4859 switch (appctx->st2) {
4860 case STAT_ST_INIT:
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01004861 /* Display the column headers. If the message cannot be sent,
4862 * quit the fucntion with returning 0. The function is called
4863 * later and restart at the state "STAT_ST_INIT".
4864 */
4865 chunk_reset(&trash);
Thierry FOURNIER65ce6132014-03-20 11:42:45 +01004866 chunk_appendf(&trash, "# id (file) description\n");
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01004867 if (bi_putchk(si->ib, &trash) == -1)
4868 return 0;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004869
4870 /* Now, we start the browsing of the references lists.
4871 * Note that the following call to LIST_ELEM return bad pointer. The only
4872 * avalaible field of this pointer is <list>. It is used with the function
4873 * pat_list_get_next() for retruning the first avalaible entry
4874 */
4875 appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list);
4876 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
4877 appctx->ctx.map.display_flags);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004878 appctx->st2 = STAT_ST_LIST;
4879 /* fall through */
4880
4881 case STAT_ST_LIST:
4882 while (appctx->ctx.map.ref) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004883 chunk_reset(&trash);
4884
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004885 /* Build messages. If the reference is used by another category than
4886 * the listed categorie, display the information in the massage.
4887 */
Thierry FOURNIERf7e04e92014-03-20 11:45:47 +01004888 chunk_appendf(&trash, "%d (%s) %s\n", appctx->ctx.map.ref->unique_id,
Thierry FOURNIER0d6ba512014-02-11 03:31:34 +01004889 appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "",
4890 appctx->ctx.map.ref->display);
Thierry FOURNIERaf5a29d2014-03-11 14:29:22 +01004891
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004892 if (bi_putchk(si->ib, &trash) == -1) {
4893 /* let's try again later from this session. We add ourselves into
4894 * this session's users so that it can remove us upon termination.
4895 */
4896 return 0;
4897 }
4898
4899 /* get next list entry and check the end of the list */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004900 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
4901 appctx->ctx.map.display_flags);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004902 }
4903
4904 appctx->st2 = STAT_ST_FIN;
4905 /* fall through */
4906
4907 default:
4908 appctx->st2 = STAT_ST_FIN;
4909 return 1;
4910 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004911 return 0;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004912}
4913
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004914static int stats_map_lookup(struct stream_interface *si)
4915{
4916 struct appctx *appctx = __objt_appctx(si->end);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004917 struct sample sample;
4918 struct pattern *pat;
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004919 int match_method;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004920
4921 switch (appctx->st2) {
4922 case STAT_ST_INIT:
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004923 /* Init to the first entry. The list cannot be change */
Thierry FOURNIERc5959fd2014-01-20 14:29:33 +01004924 appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004925 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004926 appctx->st2 = STAT_ST_LIST;
4927 /* fall through */
4928
4929 case STAT_ST_LIST:
4930 /* for each lookup type */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004931 while (appctx->ctx.map.expr) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004932 /* initialise chunk to build new message */
4933 chunk_reset(&trash);
4934
4935 /* execute pattern matching */
Thierry FOURNIER7654c9f2013-12-17 00:20:33 +01004936 sample.type = SMP_T_STR;
4937 sample.flags |= SMP_F_CONST;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004938 sample.data.str.len = appctx->ctx.map.chunk.len;
4939 sample.data.str.str = appctx->ctx.map.chunk.str;
Thierry FOURNIER5d344082014-01-27 14:19:53 +01004940 if (appctx->ctx.map.expr->pat_head->match &&
4941 sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type))
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004942 pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1);
4943 else
4944 pat = NULL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004945
4946 /* build return message: set type of match */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004947 for (match_method=0; match_method<PAT_MATCH_NUM; match_method++)
4948 if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method])
4949 break;
4950 if (match_method >= PAT_MATCH_NUM)
4951 chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match);
4952 else
4953 chunk_appendf(&trash, "type=%s", pat_match_names[match_method]);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004954
4955 /* Display no match, and set default value */
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +01004956 if (!pat) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004957 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
4958 chunk_appendf(&trash, ", found=no");
4959 else
4960 chunk_appendf(&trash, ", match=no");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004961 }
4962
4963 /* Display match and match info */
4964 else {
4965 /* display match */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004966 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
4967 chunk_appendf(&trash, ", found=yes");
4968 else
4969 chunk_appendf(&trash, ", match=yes");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004970
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +01004971 /* display index mode */
4972 if (pat->flags & PAT_F_TREE)
Thierry FOURNIERb9903842014-03-11 18:48:17 +01004973 chunk_appendf(&trash, ", idx=tree");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004974 else
Thierry FOURNIERb9903842014-03-11 18:48:17 +01004975 chunk_appendf(&trash, ", idx=list");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004976
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +01004977 /* case sensitive */
4978 if (pat->flags & PAT_F_IGNORE_CASE)
Thierry FOURNIERb9903842014-03-11 18:48:17 +01004979 chunk_appendf(&trash, ", case=insensitive");
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +01004980 else
Thierry FOURNIERb9903842014-03-11 18:48:17 +01004981 chunk_appendf(&trash, ", case=sensitive");
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01004982
Thierry FOURNIER86db66a2014-03-11 18:37:58 +01004983 /* display pattern */
4984 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
4985 if (pat->ref && pat->ref->pattern)
4986 chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern);
4987 else
4988 chunk_appendf(&trash, ", key=unknown");
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01004989 }
4990 else {
Thierry FOURNIER86db66a2014-03-11 18:37:58 +01004991 if (pat->ref && pat->ref->pattern)
4992 chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern);
4993 else
4994 chunk_appendf(&trash, ", pattern=unknown");
4995 }
4996
4997 /* display return value */
4998 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
4999 if (pat->smp && pat->ref && pat->ref->sample)
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005000 chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"",
Thierry FOURNIER86db66a2014-03-11 18:37:58 +01005001 pat->ref->sample, smp_to_type[pat->smp->type]);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005002 else
Thierry FOURNIER86db66a2014-03-11 18:37:58 +01005003 chunk_appendf(&trash, ", value=none");
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005004 }
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005005 }
5006
Thierry FOURNIERb9903842014-03-11 18:48:17 +01005007 chunk_appendf(&trash, "\n");
5008
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005009 /* display response */
5010 if (bi_putchk(si->ib, &trash) == -1) {
5011 /* let's try again later from this session. We add ourselves into
5012 * this session's users so that it can remove us upon termination.
5013 */
5014 return 0;
5015 }
5016
5017 /* get next entry */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005018 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr,
5019 &appctx->ctx.map.ref->pat);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005020 }
5021
5022 appctx->st2 = STAT_ST_FIN;
5023 /* fall through */
5024
5025 default:
5026 appctx->st2 = STAT_ST_FIN;
5027 free(appctx->ctx.map.chunk.str);
5028 return 1;
5029 }
5030}
5031
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005032static int stats_pat_list(struct stream_interface *si)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005033{
5034 struct appctx *appctx = __objt_appctx(si->end);
5035
5036 switch (appctx->st2) {
5037
5038 case STAT_ST_INIT:
5039 /* Init to the first entry. The list cannot be change */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005040 appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head,
5041 struct pat_ref_elt *, list);
5042 if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head)
5043 appctx->ctx.map.elt = NULL;
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005044 appctx->st2 = STAT_ST_LIST;
5045 /* fall through */
5046
5047 case STAT_ST_LIST:
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005048 while (appctx->ctx.map.elt) {
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005049 chunk_reset(&trash);
5050
5051 /* build messages */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005052 if (appctx->ctx.map.elt->sample)
Thierry FOURNIER9356c682014-01-28 15:55:37 +01005053 chunk_appendf(&trash, "%p %s %s\n",
5054 appctx->ctx.map.elt, appctx->ctx.map.elt->pattern,
5055 appctx->ctx.map.elt->sample);
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005056 else
Thierry FOURNIER9356c682014-01-28 15:55:37 +01005057 chunk_appendf(&trash, "%p %s\n",
5058 appctx->ctx.map.elt, appctx->ctx.map.elt->pattern);
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005059
5060 if (bi_putchk(si->ib, &trash) == -1) {
5061 /* let's try again later from this session. We add ourselves into
5062 * this session's users so that it can remove us upon termination.
5063 */
5064 return 0;
5065 }
5066
5067 /* get next list entry and check the end of the list */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005068 appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list,
5069 struct pat_ref_elt *, list);
5070 if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head)
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +01005071 break;
5072 }
5073
5074 appctx->st2 = STAT_ST_FIN;
5075 /* fall through */
5076
5077 default:
5078 appctx->st2 = STAT_ST_FIN;
5079 return 1;
5080 }
5081}
5082
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02005083/* This function dumps all sessions' states onto the stream interface's
Willy Tarreau306f8302013-07-08 15:53:06 +02005084 * read buffer. It returns 0 if the output buffer is full and it needs
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01005085 * to be called again, otherwise non-zero. It is designed to be called
5086 * from stats_dump_sess_to_buffer() below.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005087 */
Simon Horman9bd2c732011-06-15 15:18:44 +09005088static int stats_dump_sess_to_buffer(struct stream_interface *si)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005089{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005090 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005091 struct connection *conn;
5092
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02005093 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005094 /* If we're forced to shut down, we might have to remove our
5095 * reference to the last session being dumped.
5096 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005097 if (appctx->st2 == STAT_ST_LIST) {
5098 if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) {
5099 LIST_DEL(&appctx->ctx.sess.bref.users);
5100 LIST_INIT(&appctx->ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01005101 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005102 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02005103 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005104 }
5105
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005106 chunk_reset(&trash);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005107
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005108 switch (appctx->st2) {
Willy Tarreau295a8372011-03-10 11:25:07 +01005109 case STAT_ST_INIT:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005110 /* the function had not been called yet, let's prepare the
5111 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01005112 * pointer to the first in the global list. When a target
5113 * session is being destroyed, it is responsible for updating
5114 * this pointer. We know we have reached the end when this
5115 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005116 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005117 LIST_INIT(&appctx->ctx.sess.bref.users);
5118 appctx->ctx.sess.bref.ref = sessions.n;
5119 appctx->st2 = STAT_ST_LIST;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005120 /* fall through */
5121
Willy Tarreau295a8372011-03-10 11:25:07 +01005122 case STAT_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01005123 /* first, let's detach the back-ref from a possible previous session */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005124 if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) {
5125 LIST_DEL(&appctx->ctx.sess.bref.users);
5126 LIST_INIT(&appctx->ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01005127 }
5128
5129 /* and start from where we stopped */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005130 while (appctx->ctx.sess.bref.ref != &sessions) {
Cyril Bontéacd7d632010-11-01 19:26:02 +01005131 char pn[INET6_ADDRSTRLEN];
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005132 struct session *curr_sess;
5133
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005134 curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005135
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005136 if (appctx->ctx.sess.target) {
5137 if (appctx->ctx.sess.target != (void *)-1 && appctx->ctx.sess.target != curr_sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005138 goto next_sess;
5139
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005140 LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005141 /* call the proper dump() function and return if we're missing space */
Willy Tarreau76153662012-11-26 01:16:39 +01005142 if (!stats_dump_full_sess_to_buffer(si, curr_sess))
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005143 return 0;
5144
5145 /* session dump complete */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005146 LIST_DEL(&appctx->ctx.sess.bref.users);
5147 LIST_INIT(&appctx->ctx.sess.bref.users);
5148 if (appctx->ctx.sess.target != (void *)-1) {
5149 appctx->ctx.sess.target = NULL;
Willy Tarreau76153662012-11-26 01:16:39 +01005150 break;
5151 }
5152 else
5153 goto next_sess;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005154 }
5155
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005156 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005157 "%p: proto=%s",
5158 curr_sess,
5159 curr_sess->listener->proto->name);
5160
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005161
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005162 conn = objt_conn(curr_sess->si[0].end);
5163 switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02005164 case AF_INET:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005165 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005166 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005167 " src=%s:%d fe=%s be=%s srv=%s",
5168 pn,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005169 get_host_port(&conn->addr.from),
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005170 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02005171 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01005172 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005173 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005174 break;
5175 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005176 chunk_appendf(&trash,
Emeric Brun837ca522010-10-22 16:19:01 +02005177 " src=unix:%d fe=%s be=%s srv=%s",
5178 curr_sess->listener->luid,
5179 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02005180 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01005181 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Emeric Brun837ca522010-10-22 16:19:01 +02005182 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005183 break;
5184 }
5185
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005186 chunk_appendf(&trash,
Willy Tarreau65671ab2009-10-04 14:24:59 +02005187 " ts=%02x age=%s calls=%d",
5188 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01005189 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
5190 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005191
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005192 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01005193 " rq[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005194 curr_sess->req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02005195 curr_sess->req->buf->i,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005196 curr_sess->req->analysers,
5197 curr_sess->req->rex ?
5198 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
5199 TICKS_TO_MS(1000)) : "");
5200
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005201 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005202 ",wx=%s",
5203 curr_sess->req->wex ?
5204 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
5205 TICKS_TO_MS(1000)) : "");
5206
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005207 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005208 ",ax=%s]",
5209 curr_sess->req->analyse_exp ?
5210 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
5211 TICKS_TO_MS(1000)) : "");
5212
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005213 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01005214 " rp[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005215 curr_sess->rep->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02005216 curr_sess->rep->buf->i,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005217 curr_sess->rep->analysers,
5218 curr_sess->rep->rex ?
5219 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
5220 TICKS_TO_MS(1000)) : "");
5221
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005222 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005223 ",wx=%s",
5224 curr_sess->rep->wex ?
5225 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
5226 TICKS_TO_MS(1000)) : "");
5227
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005228 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005229 ",ax=%s]",
5230 curr_sess->rep->analyse_exp ?
5231 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
5232 TICKS_TO_MS(1000)) : "");
5233
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005234 conn = objt_conn(curr_sess->si[0].end);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005235 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005236 " s0=[%d,%1xh,fd=%d,ex=%s]",
5237 curr_sess->si[0].state,
5238 curr_sess->si[0].flags,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005239 conn ? conn->t.sock.fd : -1,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005240 curr_sess->si[0].exp ?
5241 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
5242 TICKS_TO_MS(1000)) : "");
5243
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005244 conn = objt_conn(curr_sess->si[1].end);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005245 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005246 " s1=[%d,%1xh,fd=%d,ex=%s]",
5247 curr_sess->si[1].state,
5248 curr_sess->si[1].flags,
Willy Tarreaub363a1f2013-10-01 10:45:07 +02005249 conn ? conn->t.sock.fd : -1,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005250 curr_sess->si[1].exp ?
5251 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
5252 TICKS_TO_MS(1000)) : "");
5253
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005254 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005255 " exp=%s",
5256 curr_sess->task->expire ?
5257 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
5258 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01005259 if (task_in_rq(curr_sess->task))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005260 chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01005261
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005262 chunk_appendf(&trash, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005263
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005264 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01005265 /* let's try again later from this session. We add ourselves into
5266 * this session's users so that it can remove us upon termination.
5267 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005268 LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02005269 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005270 }
5271
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005272 next_sess:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005273 appctx->ctx.sess.bref.ref = curr_sess->list.n;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005274 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005275
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005276 if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005277 /* specified session not found */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005278 if (appctx->ctx.sess.section > 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005279 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005280 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005281 chunk_appendf(&trash, "Session not found.\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005282
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005283 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005284 return 0;
5285
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005286 appctx->ctx.sess.target = NULL;
5287 appctx->ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01005288 return 1;
5289 }
5290
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005291 appctx->st2 = STAT_ST_FIN;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005292 /* fall through */
5293
5294 default:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005295 appctx->st2 = STAT_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02005296 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005297 }
Emeric Brun1e029aa2010-09-23 18:12:53 +02005298}
5299
Willy Tarreau5f9a8772012-11-26 02:22:40 +01005300/* This is called when the stream interface is closed. For instance, upon an
5301 * external abort, we won't call the i/o handler anymore so we may need to
5302 * remove back references to the session currently being dumped.
5303 */
Simon Horman74d88312013-02-12 10:45:50 +09005304static void cli_release_handler(struct stream_interface *si)
Willy Tarreau5f9a8772012-11-26 02:22:40 +01005305{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005306 struct appctx *appctx = __objt_appctx(si->end);
5307
5308 if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) {
5309 if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users))
5310 LIST_DEL(&appctx->ctx.sess.bref.users);
Willy Tarreau5f9a8772012-11-26 02:22:40 +01005311 }
Thierry FOURNIER364cfdf2014-01-29 19:08:49 +01005312 else if (appctx->st0 == STAT_CLI_PRINT_FREE) {
5313 free(appctx->ctx.cli.err);
5314 }
Thierry FOURNIER1e00d382014-02-11 11:31:40 +01005315 else if (appctx->st0 == STAT_CLI_O_MLOOK) {
5316 free(appctx->ctx.map.chunk.str);
5317 }
Willy Tarreau5f9a8772012-11-26 02:22:40 +01005318}
5319
Willy Tarreau20e99322013-04-13 09:22:25 +02005320/* This function is used to either dump tables states (when action is set
5321 * to STAT_CLI_O_TAB) or clear tables (when action is STAT_CLI_O_CLR).
Willy Tarreau20e99322013-04-13 09:22:25 +02005322 * It returns 0 if the output buffer is full and it needs to be called
5323 * again, otherwise non-zero.
Willy Tarreau69f58c82010-07-12 17:55:33 +02005324 */
Willy Tarreau20e99322013-04-13 09:22:25 +02005325static int stats_table_request(struct stream_interface *si, int action)
Willy Tarreau69f58c82010-07-12 17:55:33 +02005326{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005327 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau306f8302013-07-08 15:53:06 +02005328 struct session *s = session_from_task(si->owner);
Willy Tarreau69f58c82010-07-12 17:55:33 +02005329 struct ebmb_node *eb;
5330 int dt;
Willy Tarreau44455022012-12-05 23:01:12 +01005331 int skip_entry;
Willy Tarreau20e99322013-04-13 09:22:25 +02005332 int show = action == STAT_CLI_O_TAB;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005333
5334 /*
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005335 * We have 3 possible states in appctx->st2 :
Willy Tarreau295a8372011-03-10 11:25:07 +01005336 * - STAT_ST_INIT : the first call
5337 * - STAT_ST_INFO : the proxy pointer points to the next table to
Willy Tarreau69f58c82010-07-12 17:55:33 +02005338 * dump, the entry pointer is NULL ;
Willy Tarreau295a8372011-03-10 11:25:07 +01005339 * - STAT_ST_LIST : the proxy pointer points to the current table
Willy Tarreau69f58c82010-07-12 17:55:33 +02005340 * and the entry pointer points to the next entry to be dumped,
5341 * and the refcount on the next entry is held ;
Willy Tarreau295a8372011-03-10 11:25:07 +01005342 * - STAT_ST_END : nothing left to dump, the buffer may contain some
Willy Tarreau69f58c82010-07-12 17:55:33 +02005343 * data though.
5344 */
5345
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02005346 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02005347 /* in case of abort, remove any refcount we might have set on an entry */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005348 if (appctx->st2 == STAT_ST_LIST) {
5349 appctx->ctx.table.entry->ref_cnt--;
5350 stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry);
Willy Tarreauf6efda12010-08-03 20:34:06 +02005351 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02005352 return 1;
5353 }
5354
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005355 chunk_reset(&trash);
Willy Tarreau69f58c82010-07-12 17:55:33 +02005356
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005357 while (appctx->st2 != STAT_ST_FIN) {
5358 switch (appctx->st2) {
Willy Tarreau295a8372011-03-10 11:25:07 +01005359 case STAT_ST_INIT:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005360 appctx->ctx.table.proxy = appctx->ctx.table.target;
5361 if (!appctx->ctx.table.proxy)
5362 appctx->ctx.table.proxy = proxy;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005363
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005364 appctx->ctx.table.entry = NULL;
5365 appctx->st2 = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005366 break;
5367
Willy Tarreau295a8372011-03-10 11:25:07 +01005368 case STAT_ST_INFO:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005369 if (!appctx->ctx.table.proxy ||
5370 (appctx->ctx.table.target &&
5371 appctx->ctx.table.proxy != appctx->ctx.table.target)) {
5372 appctx->st2 = STAT_ST_END;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005373 break;
5374 }
5375
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005376 if (appctx->ctx.table.proxy->table.size) {
5377 if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy,
5378 appctx->ctx.table.target))
Willy Tarreau69f58c82010-07-12 17:55:33 +02005379 return 0;
5380
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005381 if (appctx->ctx.table.target &&
Willy Tarreau290e63a2012-09-20 18:07:14 +02005382 s->listener->bind_conf->level >= ACCESS_LVL_OPER) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02005383 /* dump entries only if table explicitly requested */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005384 eb = ebmb_first(&appctx->ctx.table.proxy->table.keys);
Willy Tarreau69f58c82010-07-12 17:55:33 +02005385 if (eb) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005386 appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key);
5387 appctx->ctx.table.entry->ref_cnt++;
5388 appctx->st2 = STAT_ST_LIST;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005389 break;
5390 }
5391 }
5392 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005393 appctx->ctx.table.proxy = appctx->ctx.table.proxy->next;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005394 break;
5395
Willy Tarreau295a8372011-03-10 11:25:07 +01005396 case STAT_ST_LIST:
Willy Tarreau44455022012-12-05 23:01:12 +01005397 skip_entry = 0;
Simon Hormanc88b8872011-06-15 15:18:49 +09005398
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005399 if (appctx->ctx.table.data_type >= 0) {
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02005400 /* we're filtering on some data contents */
5401 void *ptr;
5402 long long data;
5403
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005404 dt = appctx->ctx.table.data_type;
5405 ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table,
5406 appctx->ctx.table.entry,
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02005407 dt);
5408
5409 data = 0;
5410 switch (stktable_data_types[dt].std_type) {
5411 case STD_T_SINT:
5412 data = stktable_data_cast(ptr, std_t_sint);
5413 break;
5414 case STD_T_UINT:
5415 data = stktable_data_cast(ptr, std_t_uint);
5416 break;
5417 case STD_T_ULL:
5418 data = stktable_data_cast(ptr, std_t_ull);
5419 break;
5420 case STD_T_FRQP:
5421 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005422 appctx->ctx.table.proxy->table.data_arg[dt].u);
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02005423 break;
5424 }
5425
5426 /* skip the entry if the data does not match the test and the value */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005427 if ((data < appctx->ctx.table.value &&
5428 (appctx->ctx.table.data_op == STD_OP_EQ ||
5429 appctx->ctx.table.data_op == STD_OP_GT ||
5430 appctx->ctx.table.data_op == STD_OP_GE)) ||
5431 (data == appctx->ctx.table.value &&
5432 (appctx->ctx.table.data_op == STD_OP_NE ||
5433 appctx->ctx.table.data_op == STD_OP_GT ||
5434 appctx->ctx.table.data_op == STD_OP_LT)) ||
5435 (data > appctx->ctx.table.value &&
5436 (appctx->ctx.table.data_op == STD_OP_EQ ||
5437 appctx->ctx.table.data_op == STD_OP_LT ||
5438 appctx->ctx.table.data_op == STD_OP_LE)))
Willy Tarreau44455022012-12-05 23:01:12 +01005439 skip_entry = 1;
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02005440 }
5441
Simon Hormanc88b8872011-06-15 15:18:49 +09005442 if (show && !skip_entry &&
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005443 !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy,
5444 appctx->ctx.table.entry))
Simon Hormand9366582011-06-15 15:18:45 +09005445 return 0;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005446
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005447 appctx->ctx.table.entry->ref_cnt--;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005448
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005449 eb = ebmb_next(&appctx->ctx.table.entry->key);
Willy Tarreau69f58c82010-07-12 17:55:33 +02005450 if (eb) {
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005451 struct stksess *old = appctx->ctx.table.entry;
5452 appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key);
Willy Tarreau8fa52f42012-01-09 11:50:03 +01005453 if (show)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005454 stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old);
5455 else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt)
5456 stksess_kill(&appctx->ctx.table.proxy->table, old);
5457 appctx->ctx.table.entry->ref_cnt++;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005458 break;
5459 }
5460
Simon Hormanc88b8872011-06-15 15:18:49 +09005461
5462 if (show)
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005463 stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry);
5464 else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt)
5465 stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry);
Simon Hormanc88b8872011-06-15 15:18:49 +09005466
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005467 appctx->ctx.table.proxy = appctx->ctx.table.proxy->next;
5468 appctx->st2 = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005469 break;
5470
Willy Tarreau295a8372011-03-10 11:25:07 +01005471 case STAT_ST_END:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005472 appctx->st2 = STAT_ST_FIN;
Willy Tarreau69f58c82010-07-12 17:55:33 +02005473 break;
5474 }
5475 }
5476 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005477}
5478
Willy Tarreaud426a182010-03-05 14:58:26 +01005479/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
Willy Tarreau74808cb2009-03-04 15:53:18 +01005480 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
5481 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
5482 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
5483 * lines are respected within the limit of 70 output chars. Lines that are
5484 * continuation of a previous truncated line begin with "+" instead of " "
5485 * after the offset. The new pointer is returned.
5486 */
Willy Tarreaud426a182010-03-05 14:58:26 +01005487static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
5488 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01005489{
5490 int end;
5491 unsigned char c;
5492
5493 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02005494 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01005495 return ptr;
5496
Willy Tarreau77804732012-10-29 16:14:26 +01005497 chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01005498
Willy Tarreaud426a182010-03-05 14:58:26 +01005499 while (ptr < len && ptr < bsize) {
5500 c = buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01005501 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005502 if (out->len > end - 2)
5503 break;
5504 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01005505 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005506 if (out->len > end - 3)
5507 break;
5508 out->str[out->len++] = '\\';
5509 switch (c) {
5510 case '\t': c = 't'; break;
5511 case '\n': c = 'n'; break;
5512 case '\r': c = 'r'; break;
5513 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01005514 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005515 }
5516 out->str[out->len++] = c;
5517 } else {
5518 if (out->len > end - 5)
5519 break;
5520 out->str[out->len++] = '\\';
5521 out->str[out->len++] = 'x';
5522 out->str[out->len++] = hextab[(c >> 4) & 0xF];
5523 out->str[out->len++] = hextab[c & 0xF];
5524 }
Willy Tarreaud426a182010-03-05 14:58:26 +01005525 if (buf[ptr++] == '\n') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005526 /* we had a line break, let's return now */
5527 out->str[out->len++] = '\n';
5528 *line = ptr;
5529 return ptr;
5530 }
5531 }
5532 /* we have an incomplete line, we return it as-is */
5533 out->str[out->len++] = '\n';
5534 return ptr;
5535}
5536
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02005537/* This function dumps all captured errors onto the stream interface's
Willy Tarreau306f8302013-07-08 15:53:06 +02005538 * read buffer. It returns 0 if the output buffer is full and it needs
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01005539 * to be called again, otherwise non-zero.
Willy Tarreau74808cb2009-03-04 15:53:18 +01005540 */
Simon Horman9bd2c732011-06-15 15:18:44 +09005541static int stats_dump_errors_to_buffer(struct stream_interface *si)
Willy Tarreau74808cb2009-03-04 15:53:18 +01005542{
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005543 struct appctx *appctx = __objt_appctx(si->end);
Willy Tarreau74808cb2009-03-04 15:53:18 +01005544 extern const char *monthname[12];
Willy Tarreau74808cb2009-03-04 15:53:18 +01005545
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02005546 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW)))
Willy Tarreau61b34732009-10-03 23:49:35 +02005547 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005548
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005549 chunk_reset(&trash);
Willy Tarreau74808cb2009-03-04 15:53:18 +01005550
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005551 if (!appctx->ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005552 /* the function had not been called yet, let's prepare the
5553 * buffer for a response.
5554 */
Willy Tarreau10479e42010-12-12 14:00:34 +01005555 struct tm tm;
5556
5557 get_localtime(date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005558 chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n",
Willy Tarreau10479e42010-12-12 14:00:34 +01005559 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
5560 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000),
5561 error_snapshot_id);
5562
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005563 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau10479e42010-12-12 14:00:34 +01005564 /* Socket buffer full. Let's try again later from the same point */
5565 return 0;
5566 }
5567
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005568 appctx->ctx.errors.px = proxy;
5569 appctx->ctx.errors.buf = 0;
5570 appctx->ctx.errors.bol = 0;
5571 appctx->ctx.errors.ptr = -1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005572 }
5573
5574 /* we have two inner loops here, one for the proxy, the other one for
5575 * the buffer.
5576 */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005577 while (appctx->ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005578 struct error_snapshot *es;
5579
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005580 if (appctx->ctx.errors.buf == 0)
5581 es = &appctx->ctx.errors.px->invalid_req;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005582 else
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005583 es = &appctx->ctx.errors.px->invalid_rep;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005584
5585 if (!es->when.tv_sec)
5586 goto next;
5587
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005588 if (appctx->ctx.errors.iid >= 0 &&
5589 appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid &&
5590 es->oe->uuid != appctx->ctx.errors.iid)
Willy Tarreau74808cb2009-03-04 15:53:18 +01005591 goto next;
5592
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005593 if (appctx->ctx.errors.ptr < 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005594 /* just print headers now */
5595
5596 char pn[INET6_ADDRSTRLEN];
5597 struct tm tm;
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02005598 int port;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005599
5600 get_localtime(es->when.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005601 chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01005602 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02005603 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01005604
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02005605 switch (addr_to_str(&es->src, pn, sizeof(pn))) {
5606 case AF_INET:
5607 case AF_INET6:
5608 port = get_host_port(&es->src);
5609 break;
5610 default:
5611 port = 0;
5612 }
5613
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005614 switch (appctx->ctx.errors.buf) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005615 case 0:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005616 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01005617 " frontend %s (#%d): invalid request\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02005618 " backend %s (#%d)",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005619 appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02005620 (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
5621 (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1);
Willy Tarreau74808cb2009-03-04 15:53:18 +01005622 break;
5623 case 1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005624 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01005625 " backend %s (#%d) : invalid response\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02005626 " frontend %s (#%d)",
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005627 appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02005628 es->oe->id, es->oe->uuid);
Willy Tarreau74808cb2009-03-04 15:53:18 +01005629 break;
5630 }
5631
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005632 chunk_appendf(&trash,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02005633 ", server %s (#%d), event #%u\n"
5634 " src %s:%d, session #%d, session flags 0x%08x\n"
5635 " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n"
5636 " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n"
5637 " buffer flags 0x%08x, out %d bytes, total %lld bytes\n"
5638 " pending %d bytes, wrapping at %d, error at position %d:\n \n",
5639 es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1,
5640 es->ev_id,
5641 pn, port, es->sid, es->s_flags,
5642 es->state, es->m_flags, es->t_flags,
5643 es->m_clen, es->m_blen,
5644 es->b_flags, es->b_out, es->b_tot,
5645 es->len, es->b_wrap, es->pos);
5646
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005647 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005648 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02005649 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005650 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005651 appctx->ctx.errors.ptr = 0;
5652 appctx->ctx.errors.sid = es->sid;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005653 }
5654
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005655 if (appctx->ctx.errors.sid != es->sid) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005656 /* the snapshot changed while we were dumping it */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005657 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01005658 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005659 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau61b34732009-10-03 23:49:35 +02005660 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005661 goto next;
5662 }
5663
5664 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005665 while (appctx->ctx.errors.ptr < es->len && appctx->ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005666 int newptr;
5667 int newline;
5668
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005669 newline = appctx->ctx.errors.bol;
5670 newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr);
5671 if (newptr == appctx->ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02005672 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005673
Willy Tarreau19d14ef2012-10-29 16:51:55 +01005674 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01005675 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02005676 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005677 }
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005678 appctx->ctx.errors.ptr = newptr;
5679 appctx->ctx.errors.bol = newline;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005680 };
5681 next:
Willy Tarreau7b4b4992013-12-01 09:15:12 +01005682 appctx->ctx.errors.bol = 0;
5683 appctx->ctx.errors.ptr = -1;
5684 appctx->ctx.errors.buf++;
5685 if (appctx->ctx.errors.buf > 1) {
5686 appctx->ctx.errors.buf = 0;
5687 appctx->ctx.errors.px = appctx->ctx.errors.px->next;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005688 }
5689 }
5690
5691 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02005692 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01005693}
5694
Willy Tarreaud5781202012-09-22 19:32:35 +02005695/* parse the "level" argument on the bind lines */
5696static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
5697{
5698 if (!*args[cur_arg + 1]) {
5699 memprintf(err, "'%s' : missing level", args[cur_arg]);
5700 return ERR_ALERT | ERR_FATAL;
5701 }
5702
5703 if (!strcmp(args[cur_arg+1], "user"))
5704 conf->level = ACCESS_LVL_USER;
5705 else if (!strcmp(args[cur_arg+1], "operator"))
5706 conf->level = ACCESS_LVL_OPER;
5707 else if (!strcmp(args[cur_arg+1], "admin"))
5708 conf->level = ACCESS_LVL_ADMIN;
5709 else {
5710 memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')",
5711 args[cur_arg], args[cur_arg+1]);
5712 return ERR_ALERT | ERR_FATAL;
5713 }
5714
5715 return 0;
5716}
5717
Willy Tarreaub24281b2011-02-13 13:16:36 +01005718struct si_applet http_stats_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01005719 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01005720 .name = "<STATS>", /* used for logging */
5721 .fct = http_stats_io_handler,
Aman Gupta9a13e842012-04-02 18:57:53 -07005722 .release = NULL,
Willy Tarreaub24281b2011-02-13 13:16:36 +01005723};
5724
Simon Horman9bd2c732011-06-15 15:18:44 +09005725static struct si_applet cli_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01005726 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01005727 .name = "<CLI>", /* used for logging */
5728 .fct = cli_io_handler,
Willy Tarreau5f9a8772012-11-26 02:22:40 +01005729 .release = cli_release_handler,
Willy Tarreaub24281b2011-02-13 13:16:36 +01005730};
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01005731
Willy Tarreaudc13c112013-06-21 23:16:39 +02005732static struct cfg_kw_list cfg_kws = {ILH, {
Willy Tarreau10522fd2008-07-09 20:12:41 +02005733 { CFG_GLOBAL, "stats", stats_parse_global },
5734 { 0, NULL, NULL },
5735}};
5736
Willy Tarreaud5781202012-09-22 19:32:35 +02005737static struct bind_kw_list bind_kws = { "STAT", { }, {
5738 { "level", bind_parse_level, 1 }, /* set the unix socket admin level */
5739 { NULL, NULL, 0 },
5740}};
5741
Willy Tarreau10522fd2008-07-09 20:12:41 +02005742__attribute__((constructor))
5743static void __dumpstats_module_init(void)
5744{
5745 cfg_register_keywords(&cfg_kws);
Willy Tarreaud5781202012-09-22 19:32:35 +02005746 bind_register_keywords(&bind_kws);
Willy Tarreau10522fd2008-07-09 20:12:41 +02005747}
5748
Willy Tarreau91861262007-10-17 17:06:05 +02005749/*
5750 * Local variables:
5751 * c-indent-level: 8
5752 * c-basic-offset: 8
5753 * End:
5754 */