blob: ec27db8da82ddc731db29d9bbdf14ac2c038636e [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 Tarreaueb472682010-05-28 18:46:57 +02004 * Copyright 2000-2010 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>
Simon Horman17bce342011-06-15 15:18:47 +090017#include <stdbool.h>
Willy Tarreau91861262007-10-17 17:06:05 +020018#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020021#include <pwd.h>
22#include <grp.h>
Willy Tarreau91861262007-10-17 17:06:05 +020023
24#include <sys/socket.h>
25#include <sys/stat.h>
26#include <sys/types.h>
27
Willy Tarreau10522fd2008-07-09 20:12:41 +020028#include <common/cfgparse.h>
Willy Tarreau91861262007-10-17 17:06:05 +020029#include <common/compat.h>
30#include <common/config.h>
31#include <common/debug.h>
32#include <common/memory.h>
33#include <common/mini-clist.h>
34#include <common/standard.h>
Willy Tarreau0c303ee2008-07-07 00:09:58 +020035#include <common/ticks.h>
Willy Tarreau91861262007-10-17 17:06:05 +020036#include <common/time.h>
37#include <common/uri_auth.h>
38#include <common/version.h>
39
Willy Tarreau91861262007-10-17 17:06:05 +020040#include <types/global.h>
Willy Tarreau91861262007-10-17 17:06:05 +020041
42#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020043#include <proto/channel.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020044#include <proto/checks.h>
William Lallemande3a7d992012-11-20 11:25:20 +010045#include <proto/compression.h>
Willy Tarreau91861262007-10-17 17:06:05 +020046#include <proto/dumpstats.h>
47#include <proto/fd.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010048#include <proto/freq_ctr.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020049#include <proto/log.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>
Willy Tarreaue6d97022012-11-23 11:19:33 +010052#include <proto/proto_http.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020053#include <proto/proto_uxst.h>
Willy Tarreau89a63132009-08-16 17:41:45 +020054#include <proto/proxy.h>
Willy Tarreau91861262007-10-17 17:06:05 +020055#include <proto/session.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020056#include <proto/server.h>
Willy Tarreau75bf2c92012-08-20 17:01:35 +020057#include <proto/raw_sock.h>
Willy Tarreaudded32d2008-11-30 19:48:07 +010058#include <proto/stream_interface.h>
Willy Tarreau4726f532009-03-07 17:25:21 +010059#include <proto/task.h>
Willy Tarreau91861262007-10-17 17:06:05 +020060
Willy Tarreau7a0169a2012-11-19 17:13:16 +010061#ifdef USE_OPENSSL
62#include <proto/ssl_sock.h>
63#endif
64
Simon Horman9bd2c732011-06-15 15:18:44 +090065static int stats_dump_raw_to_buffer(struct stream_interface *si);
66static int stats_dump_full_sess_to_buffer(struct stream_interface *si);
67static int stats_dump_sess_to_buffer(struct stream_interface *si);
68static int stats_dump_errors_to_buffer(struct stream_interface *si);
Simon Hormanc88b8872011-06-15 15:18:49 +090069static int stats_table_request(struct stream_interface *si, bool show);
Simon Horman9bd2c732011-06-15 15:18:44 +090070static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struct uri_auth *uri);
71static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri);
72
73static struct si_applet cli_applet;
74
75static const char stats_sock_usage_msg[] =
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020076 "Unknown command. Please enter one of the following commands only :\n"
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +020077 " clear counters : clear max statistics counters (add 'all' for all counters)\n"
Willy Tarreau88ee3972010-07-13 13:48:00 +020078 " clear table : remove an entry from a table\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020079 " help : this message\n"
80 " prompt : toggle interactive mode with prompt\n"
81 " quit : disconnect\n"
82 " show info : report information about the running process\n"
83 " show stat : report counters for each proxy and server\n"
84 " show errors : report last request and response errors for each proxy\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +010085 " show sess [id] : report the list of current sessions or dump this session\n"
Willy Tarreau69f58c82010-07-12 17:55:33 +020086 " show table [id]: report table usage stats or dump this table's contents\n"
Willy Tarreau38338fa2009-10-10 18:37:29 +020087 " get weight : report a server's current weight\n"
Willy Tarreau4483d432009-10-10 19:30:08 +020088 " set weight : change a server's weight\n"
Willy Tarreau654694e2012-06-07 01:03:16 +020089 " set table [id] : update or create a table entry's data\n"
Willy Tarreau7aabd112010-01-26 10:59:06 +010090 " set timeout : change a timeout setting\n"
Willy Tarreau2a0f4d22011-08-02 11:49:05 +020091 " set maxconn : change a maxconn setting\n"
Willy Tarreauf5b22872011-09-07 16:13:44 +020092 " set rate-limit : change a rate limiting value\n"
Willy Tarreaua295edc2011-09-07 23:21:03 +020093 " disable : put a server or frontend in maintenance mode\n"
94 " enable : re-enable a server or frontend which is in maintenance mode\n"
95 " shutdown : kill a session or a frontend (eg:to release listening ports)\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020096 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +020097
Simon Horman9bd2c732011-06-15 15:18:44 +090098static const char stats_permission_denied_msg[] =
Willy Tarreau6162db22009-10-10 17:13:00 +020099 "Permission denied\n"
100 "";
101
Willy Tarreau295a8372011-03-10 11:25:07 +0100102/* data transmission states for the stats responses */
103enum {
104 STAT_ST_INIT = 0,
105 STAT_ST_HEAD,
106 STAT_ST_INFO,
107 STAT_ST_LIST,
108 STAT_ST_END,
109 STAT_ST_FIN,
110};
111
112/* data transmission states for the stats responses inside a proxy */
113enum {
114 STAT_PX_ST_INIT = 0,
115 STAT_PX_ST_TH,
116 STAT_PX_ST_FE,
117 STAT_PX_ST_LI,
118 STAT_PX_ST_SV,
119 STAT_PX_ST_BE,
120 STAT_PX_ST_END,
121 STAT_PX_ST_FIN,
122};
123
Cyril Bonté19979e12012-04-04 12:57:21 +0200124extern const char *stat_status_codes[];
125
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200126/* This function is called from the session-level accept() in order to instanciate
Willy Tarreaueb472682010-05-28 18:46:57 +0200127 * a new stats socket. It returns a positive value upon success, 0 if the connection
128 * needs to be closed and ignored, or a negative value upon critical failure.
129 */
Simon Horman9bd2c732011-06-15 15:18:44 +0900130static int stats_accept(struct session *s)
Willy Tarreaueb472682010-05-28 18:46:57 +0200131{
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200132 /* we have a dedicated I/O handler for the stats */
Willy Tarreaub24281b2011-02-13 13:16:36 +0100133 stream_int_register_handler(&s->si[1], &cli_applet);
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100134 s->target = s->si[1].conn->target; // for logging only
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200135 s->si[1].conn->xprt_ctx = s;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100136 s->si[1].applet.st1 = 0;
137 s->si[1].applet.st0 = STAT_CLI_INIT;
Willy Tarreaueb472682010-05-28 18:46:57 +0200138
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200139 tv_zero(&s->logs.tv_request);
140 s->logs.t_queue = 0;
141 s->logs.t_connect = 0;
142 s->logs.t_data = 0;
143 s->logs.t_close = 0;
144 s->logs.bytes_in = s->logs.bytes_out = 0;
145 s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
146 s->logs.srv_queue_size = 0; /* we will get this number soon */
Willy Tarreaueb472682010-05-28 18:46:57 +0200147
Willy Tarreau03cdb7c2012-08-27 23:14:58 +0200148 s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreaueb472682010-05-28 18:46:57 +0200149
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200150 if (s->listener->timeout) {
151 s->req->rto = *s->listener->timeout;
152 s->rep->wto = *s->listener->timeout;
Willy Tarreaueb472682010-05-28 18:46:57 +0200153 }
Willy Tarreaueb472682010-05-28 18:46:57 +0200154 return 1;
Willy Tarreaueb472682010-05-28 18:46:57 +0200155}
156
Willy Tarreau07e9e642010-08-17 21:48:17 +0200157/* allocate a new stats frontend named <name>, and return it
158 * (or NULL in case of lack of memory).
159 */
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200160static struct proxy *alloc_stats_fe(const char *name, const char *file, int line)
Willy Tarreau07e9e642010-08-17 21:48:17 +0200161{
162 struct proxy *fe;
163
164 fe = (struct proxy *)calloc(1, sizeof(struct proxy));
165 if (!fe)
166 return NULL;
167
Willy Tarreau237250c2011-07-29 01:49:03 +0200168 init_new_proxy(fe);
Willy Tarreau050536d2012-10-04 08:47:34 +0200169 fe->next = proxy;
170 proxy = fe;
Willy Tarreau07e9e642010-08-17 21:48:17 +0200171 fe->last_change = now.tv_sec;
172 fe->id = strdup("GLOBAL");
173 fe->cap = PR_CAP_FE;
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200174 fe->maxconn = 10; /* default to 10 concurrent connections */
175 fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200176 fe->conf.file = strdup(file);
177 fe->conf.line = line;
Willy Tarreauc53d4222012-09-20 20:19:28 +0200178 fe->accept = stats_accept;
Willy Tarreau050536d2012-10-04 08:47:34 +0200179
180 /* the stats frontend is the only one able to assign ID #0 */
181 fe->conf.id.key = fe->uuid = 0;
182 eb32_insert(&used_proxy_id, &fe->conf.id);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200183 return fe;
184}
185
Willy Tarreaufbee7132007-10-18 13:53:22 +0200186/* This function parses a "stats" statement in the "global" section. It returns
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200187 * -1 if there is any error, otherwise zero. If it returns -1, it will write an
188 * error message into the <err> buffer which will be preallocated. The trailing
189 * '\n' must not be written. The function must be called with <args> pointing to
190 * the first word after "stats".
Willy Tarreaufbee7132007-10-18 13:53:22 +0200191 */
Willy Tarreau10522fd2008-07-09 20:12:41 +0200192static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
Willy Tarreau28a47d62012-09-18 20:02:48 +0200193 struct proxy *defpx, const char *file, int line,
194 char **err)
Willy Tarreaufbee7132007-10-18 13:53:22 +0200195{
Willy Tarreau4348fad2012-09-20 16:48:07 +0200196 struct bind_conf *bind_conf;
Willy Tarreauc53d4222012-09-20 20:19:28 +0200197 struct listener *l;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200198
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200199 if (!strcmp(args[1], "socket")) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200200 int cur_arg;
201
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200202 if (*args[2] == 0) {
Willy Tarreauc53d4222012-09-20 20:19:28 +0200203 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 +0200204 return -1;
205 }
206
Willy Tarreau89a63132009-08-16 17:41:45 +0200207 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200208 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200209 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreau89a63132009-08-16 17:41:45 +0200210 return -1;
211 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200212 }
213
Willy Tarreau4348fad2012-09-20 16:48:07 +0200214 bind_conf = bind_conf_alloc(&global.stats_fe->conf.bind, file, line, args[2]);
Willy Tarreau290e63a2012-09-20 18:07:14 +0200215 bind_conf->level = ACCESS_LVL_OPER; /* default access level */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200216
Willy Tarreauc53d4222012-09-20 20:19:28 +0200217 if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) {
218 memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n",
219 file, line, args[0], args[1], err && *err ? *err : "error");
220 return -1;
221 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200222
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200223 cur_arg = 3;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200224 while (*args[cur_arg]) {
Willy Tarreaud5781202012-09-22 19:32:35 +0200225 static int bind_dumped;
226 struct bind_kw *kw;
227
228 kw = bind_find_kw(args[cur_arg]);
229 if (kw) {
230 if (!kw->parse) {
231 memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).",
232 args[0], args[1], args[cur_arg]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200233 return -1;
234 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200235
236 if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) {
237 if (err && *err)
238 memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err);
239 else
240 memprintf(err, "'%s %s' : error encountered while processing '%s'",
241 args[0], args[1], args[cur_arg]);
Willy Tarreau6162db22009-10-10 17:13:00 +0200242 return -1;
243 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200244
245 cur_arg += 1 + kw->skip;
246 continue;
Willy Tarreau6162db22009-10-10 17:13:00 +0200247 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200248
249 if (!bind_dumped) {
250 bind_dump_kws(err);
251 indent_msg(err, 4);
252 bind_dumped = 1;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200253 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200254
255 memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s",
256 args[0], args[1], args[cur_arg],
257 err && *err ? " Registered keywords :" : "", err && *err ? *err : "");
258 return -1;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200259 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100260
Willy Tarreauc53d4222012-09-20 20:19:28 +0200261 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
262 l->maxconn = global.stats_fe->maxconn;
263 l->backlog = global.stats_fe->backlog;
264 l->timeout = &global.stats_fe->timeout.client;
265 l->accept = session_accept;
266 l->handler = process_session;
267 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
268 l->nice = -64; /* we want to boost priority for local stats */
269 global.maxsock += l->maxconn;
270 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200271 }
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200272 else if (!strcmp(args[1], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100273 unsigned timeout;
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200274 const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS);
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100275
276 if (res) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200277 memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res);
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100278 return -1;
279 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200280
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100281 if (!timeout) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200282 memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200283 return -1;
284 }
Willy Tarreau07e9e642010-08-17 21:48:17 +0200285 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200286 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200287 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200288 return -1;
289 }
290 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200291 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200292 }
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200293 else if (!strcmp(args[1], "maxconn")) {
294 int maxconn = atol(args[2]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200295
296 if (maxconn <= 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200297 memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200298 return -1;
299 }
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200300
301 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200302 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200303 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200304 return -1;
305 }
306 }
307 global.stats_fe->maxconn = maxconn;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200308 }
Willy Tarreau35b7b162012-10-22 23:17:18 +0200309 else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */
310 int cur_arg = 2;
311 unsigned int set = 0;
312
313 while (*args[cur_arg]) {
Willy Tarreau110ecc12012-11-15 17:50:01 +0100314 unsigned int low, high;
315
Willy Tarreau35b7b162012-10-22 23:17:18 +0200316 if (strcmp(args[cur_arg], "all") == 0) {
317 set = 0;
318 break;
319 }
320 else if (strcmp(args[cur_arg], "odd") == 0) {
321 set |= 0x55555555;
322 }
323 else if (strcmp(args[cur_arg], "even") == 0) {
324 set |= 0xAAAAAAAA;
325 }
Willy Tarreau83d84cf2012-11-22 01:04:31 +0100326 else if (isdigit((int)*args[cur_arg])) {
Willy Tarreau110ecc12012-11-15 17:50:01 +0100327 char *dash = strchr(args[cur_arg], '-');
328
329 low = high = str2uic(args[cur_arg]);
330 if (dash)
331 high = str2uic(dash + 1);
332
333 if (high < low) {
334 unsigned int swap = low;
335 low = high;
336 high = swap;
337 }
338
339 if (low < 1 || high > 32) {
340 memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n",
341 args[0], args[1]);
Willy Tarreau35b7b162012-10-22 23:17:18 +0200342 return -1;
343 }
Willy Tarreau110ecc12012-11-15 17:50:01 +0100344
345 while (low <= high)
346 set |= 1 << (low++ - 1);
347 }
348 else {
349 memprintf(err,
350 "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n",
351 args[0], args[1]);
352 return -1;
Willy Tarreau35b7b162012-10-22 23:17:18 +0200353 }
354 cur_arg++;
355 }
356 global.stats_fe->bind_proc = set;
357 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200358 else {
Willy Tarreau35b7b162012-10-22 23:17:18 +0200359 memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200360 return -1;
361 }
362 return 0;
363}
364
Simon Horman9bd2c732011-06-15 15:18:44 +0900365static int print_csv_header(struct chunk *msg)
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100366{
Willy Tarreau77804732012-10-29 16:14:26 +0100367 return chunk_appendf(msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100368 "# pxname,svname,"
369 "qcur,qmax,"
370 "scur,smax,slim,stot,"
371 "bin,bout,"
372 "dreq,dresp,"
373 "ereq,econ,eresp,"
374 "wretr,wredis,"
375 "status,weight,act,bck,"
376 "chkfail,chkdown,lastchg,downtime,qlimit,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +0200377 "pid,iid,sid,throttle,lbtot,tracked,type,"
378 "rate,rate_lim,rate_max,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200379 "check_status,check_code,check_duration,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100380 "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,"
Willy Tarreauae526782010-03-04 20:34:23 +0100381 "req_rate,req_rate_max,req_tot,"
382 "cli_abrt,srv_abrt,"
Willy Tarreau55058a72012-11-21 08:27:21 +0100383 "comp_in, comp_out, comp_byp,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100384 "\n");
385}
386
Simon Hormand9366582011-06-15 15:18:45 +0900387/* print a string of text buffer to <out>. The format is :
388 * Non-printable chars \t, \n, \r and \e are * encoded in C format.
389 * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped.
390 * Print stopped if null char or <bsize> is reached, or if no more place in the chunk.
391 */
392static int dump_text(struct chunk *out, const char *buf, int bsize)
393{
394 unsigned char c;
395 int ptr = 0;
396
397 while (buf[ptr] && ptr < bsize) {
398 c = buf[ptr];
399 if (isprint(c) && isascii(c) && c != '\\' && c != ' ') {
400 if (out->len > out->size - 1)
401 break;
402 out->str[out->len++] = c;
403 }
404 else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') {
405 if (out->len > out->size - 2)
406 break;
407 out->str[out->len++] = '\\';
408 switch (c) {
409 case ' ': c = ' '; break;
410 case '\t': c = 't'; break;
411 case '\n': c = 'n'; break;
412 case '\r': c = 'r'; break;
413 case '\e': c = 'e'; break;
414 case '\\': c = '\\'; break;
415 }
416 out->str[out->len++] = c;
417 }
418 else {
419 if (out->len > out->size - 4)
420 break;
421 out->str[out->len++] = '\\';
422 out->str[out->len++] = 'x';
423 out->str[out->len++] = hextab[(c >> 4) & 0xF];
424 out->str[out->len++] = hextab[c & 0xF];
425 }
426 ptr++;
427 }
428
429 return ptr;
430}
431
432/* print a buffer in hexa.
433 * Print stopped if <bsize> is reached, or if no more place in the chunk.
434 */
435static int dump_binary(struct chunk *out, const char *buf, int bsize)
436{
437 unsigned char c;
438 int ptr = 0;
439
440 while (ptr < bsize) {
441 c = buf[ptr];
442
443 if (out->len > out->size - 2)
444 break;
445 out->str[out->len++] = hextab[(c >> 4) & 0xF];
446 out->str[out->len++] = hextab[c & 0xF];
447
448 ptr++;
449 }
450 return ptr;
451}
452
453/* Dump the status of a table to a stream interface's
454 * read buffer. It returns 0 if the output buffer is full
455 * and needs to be called again, otherwise non-zero.
456 */
457static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si,
458 struct proxy *proxy, struct proxy *target)
459{
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200460 struct session *s = si->conn->xprt_ctx;
Simon Hormand9366582011-06-15 15:18:45 +0900461
Willy Tarreau77804732012-10-29 16:14:26 +0100462 chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n",
Simon Hormand9366582011-06-15 15:18:45 +0900463 proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current);
464
465 /* any other information should be dumped here */
466
Willy Tarreau290e63a2012-09-20 18:07:14 +0200467 if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER)
Willy Tarreau77804732012-10-29 16:14:26 +0100468 chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n");
Simon Hormand9366582011-06-15 15:18:45 +0900469
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200470 if (bi_putchk(si->ib, msg) == -1)
Simon Hormand9366582011-06-15 15:18:45 +0900471 return 0;
472
473 return 1;
474}
475
476/* Dump the a table entry to a stream interface's
477 * read buffer. It returns 0 if the output buffer is full
478 * and needs to be called again, otherwise non-zero.
479 */
480static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si,
481 struct proxy *proxy, struct stksess *entry)
482{
483 int dt;
484
Willy Tarreau77804732012-10-29 16:14:26 +0100485 chunk_appendf(msg, "%p:", entry);
Simon Hormand9366582011-06-15 15:18:45 +0900486
487 if (proxy->table.type == STKTABLE_TYPE_IP) {
488 char addr[INET_ADDRSTRLEN];
489 inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr));
Willy Tarreau77804732012-10-29 16:14:26 +0100490 chunk_appendf(msg, " key=%s", addr);
Simon Hormand9366582011-06-15 15:18:45 +0900491 }
492 else if (proxy->table.type == STKTABLE_TYPE_IPV6) {
493 char addr[INET6_ADDRSTRLEN];
494 inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr));
Willy Tarreau77804732012-10-29 16:14:26 +0100495 chunk_appendf(msg, " key=%s", addr);
Simon Hormand9366582011-06-15 15:18:45 +0900496 }
497 else if (proxy->table.type == STKTABLE_TYPE_INTEGER) {
Willy Tarreau77804732012-10-29 16:14:26 +0100498 chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key);
Simon Hormand9366582011-06-15 15:18:45 +0900499 }
500 else if (proxy->table.type == STKTABLE_TYPE_STRING) {
Willy Tarreau77804732012-10-29 16:14:26 +0100501 chunk_appendf(msg, " key=");
Simon Hormand9366582011-06-15 15:18:45 +0900502 dump_text(msg, (const char *)entry->key.key, proxy->table.key_size);
503 }
504 else {
Willy Tarreau77804732012-10-29 16:14:26 +0100505 chunk_appendf(msg, " key=");
Simon Hormand9366582011-06-15 15:18:45 +0900506 dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size);
507 }
508
Willy Tarreau77804732012-10-29 16:14:26 +0100509 chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire));
Simon Hormand9366582011-06-15 15:18:45 +0900510
511 for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) {
512 void *ptr;
513
514 if (proxy->table.data_ofs[dt] == 0)
515 continue;
516 if (stktable_data_types[dt].arg_type == ARG_T_DELAY)
Willy Tarreau77804732012-10-29 16:14:26 +0100517 chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u);
Simon Hormand9366582011-06-15 15:18:45 +0900518 else
Willy Tarreau77804732012-10-29 16:14:26 +0100519 chunk_appendf(msg, " %s=", stktable_data_types[dt].name);
Simon Hormand9366582011-06-15 15:18:45 +0900520
521 ptr = stktable_data_ptr(&proxy->table, entry, dt);
522 switch (stktable_data_types[dt].std_type) {
523 case STD_T_SINT:
Willy Tarreau77804732012-10-29 16:14:26 +0100524 chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint));
Simon Hormand9366582011-06-15 15:18:45 +0900525 break;
526 case STD_T_UINT:
Willy Tarreau77804732012-10-29 16:14:26 +0100527 chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint));
Simon Hormand9366582011-06-15 15:18:45 +0900528 break;
529 case STD_T_ULL:
Willy Tarreau77804732012-10-29 16:14:26 +0100530 chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull));
Simon Hormand9366582011-06-15 15:18:45 +0900531 break;
532 case STD_T_FRQP:
Willy Tarreau77804732012-10-29 16:14:26 +0100533 chunk_appendf(msg, "%d",
Simon Hormand9366582011-06-15 15:18:45 +0900534 read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
535 proxy->table.data_arg[dt].u));
536 break;
537 }
538 }
Willy Tarreau77804732012-10-29 16:14:26 +0100539 chunk_appendf(msg, "\n");
Simon Hormand9366582011-06-15 15:18:45 +0900540
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200541 if (bi_putchk(si->ib, msg) == -1)
Simon Hormand9366582011-06-15 15:18:45 +0900542 return 0;
543
544 return 1;
545}
546
Willy Tarreaudec98142012-06-06 23:37:08 +0200547static void stats_sock_table_key_request(struct stream_interface *si, char **args, int action)
Simon Horman121f3052011-06-15 15:18:46 +0900548{
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200549 struct session *s = si->conn->xprt_ctx;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900550 struct proxy *px = si->applet.ctx.table.target;
Simon Horman121f3052011-06-15 15:18:46 +0900551 struct stksess *ts;
Simon Hormancec9a222011-06-15 15:18:51 +0900552 uint32_t uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900553 unsigned char ip6_key[sizeof(struct in6_addr)];
Willy Tarreau654694e2012-06-07 01:03:16 +0200554 long long value;
555 int data_type;
556 void *ptr;
557 struct freq_ctr_period *frqp;
Simon Horman121f3052011-06-15 15:18:46 +0900558
Simon Hormand5b9fd92011-06-15 15:18:48 +0900559 si->applet.st0 = STAT_CLI_OUTPUT;
Simon Horman121f3052011-06-15 15:18:46 +0900560
561 if (!*args[4]) {
562 si->applet.ctx.cli.msg = "Key value expected\n";
563 si->applet.st0 = STAT_CLI_PRINT;
564 return;
565 }
566
Simon Hormanc5b89f62011-06-15 15:18:50 +0900567 switch (px->table.type) {
568 case STKTABLE_TYPE_IP:
Simon Hormancec9a222011-06-15 15:18:51 +0900569 uint32_key = htonl(inetaddr_host(args[4]));
Willy Tarreau07115412012-10-29 21:56:59 +0100570 static_table_key->key = &uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900571 break;
572 case STKTABLE_TYPE_IPV6:
573 inet_pton(AF_INET6, args[4], ip6_key);
Willy Tarreau07115412012-10-29 21:56:59 +0100574 static_table_key->key = &ip6_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900575 break;
Simon Hormancec9a222011-06-15 15:18:51 +0900576 case STKTABLE_TYPE_INTEGER:
577 {
578 char *endptr;
579 unsigned long val;
580 errno = 0;
581 val = strtoul(args[4], &endptr, 10);
582 if ((errno == ERANGE && val == ULONG_MAX) ||
583 (errno != 0 && val == 0) || endptr == args[4] ||
584 val > 0xffffffff) {
585 si->applet.ctx.cli.msg = "Invalid key\n";
586 si->applet.st0 = STAT_CLI_PRINT;
587 return;
588 }
589 uint32_key = (uint32_t) val;
Willy Tarreau07115412012-10-29 21:56:59 +0100590 static_table_key->key = &uint32_key;
Simon Hormancec9a222011-06-15 15:18:51 +0900591 break;
592 }
593 break;
Simon Horman619e3cc2011-06-15 15:18:52 +0900594 case STKTABLE_TYPE_STRING:
Willy Tarreau07115412012-10-29 21:56:59 +0100595 static_table_key->key = args[4];
596 static_table_key->key_len = strlen(args[4]);
Simon Horman619e3cc2011-06-15 15:18:52 +0900597 break;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900598 default:
Willy Tarreaudec98142012-06-06 23:37:08 +0200599 switch (action) {
600 case STAT_CLI_O_TAB:
601 si->applet.ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n";
602 break;
603 case STAT_CLI_O_CLR:
604 si->applet.ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6, string and integer is not supported\n";
605 break;
606 default:
607 si->applet.ctx.cli.msg = "Unknown action\n";
608 break;
609 }
Simon Horman121f3052011-06-15 15:18:46 +0900610 si->applet.st0 = STAT_CLI_PRINT;
611 return;
612 }
613
614 /* check permissions */
Willy Tarreau290e63a2012-09-20 18:07:14 +0200615 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Simon Horman121f3052011-06-15 15:18:46 +0900616 si->applet.ctx.cli.msg = stats_permission_denied_msg;
617 si->applet.st0 = STAT_CLI_PRINT;
618 return;
619 }
620
Willy Tarreau07115412012-10-29 21:56:59 +0100621 ts = stktable_lookup_key(&px->table, static_table_key);
Simon Horman17bce342011-06-15 15:18:47 +0900622
Willy Tarreaudec98142012-06-06 23:37:08 +0200623 switch (action) {
624 case STAT_CLI_O_TAB:
625 if (!ts)
626 return;
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100627 chunk_reset(&trash);
628 if (!stats_dump_table_head_to_buffer(&trash, si, px, px))
Simon Horman17bce342011-06-15 15:18:47 +0900629 return;
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100630 stats_dump_table_entry_to_buffer(&trash, si, px, ts);
Simon Horman121f3052011-06-15 15:18:46 +0900631 return;
Willy Tarreaudec98142012-06-06 23:37:08 +0200632
633 case STAT_CLI_O_CLR:
634 if (!ts)
635 return;
636 if (ts->ref_cnt) {
637 /* don't delete an entry which is currently referenced */
638 si->applet.ctx.cli.msg = "Entry currently in use, cannot remove\n";
639 si->applet.st0 = STAT_CLI_PRINT;
640 return;
641 }
642 stksess_kill(&px->table, ts);
643 break;
Simon Horman17bce342011-06-15 15:18:47 +0900644
Willy Tarreau654694e2012-06-07 01:03:16 +0200645 case STAT_CLI_O_SET:
646 if (strncmp(args[5], "data.", 5) != 0) {
647 si->applet.ctx.cli.msg = "\"data.<type>\" followed by a value expected\n";
648 si->applet.st0 = STAT_CLI_PRINT;
649 return;
650 }
651
652 data_type = stktable_get_data_type(args[5] + 5);
653 if (data_type < 0) {
654 si->applet.ctx.cli.msg = "Unknown data type\n";
655 si->applet.st0 = STAT_CLI_PRINT;
656 return;
657 }
658
659 if (!px->table.data_ofs[data_type]) {
660 si->applet.ctx.cli.msg = "Data type not stored in this table\n";
661 si->applet.st0 = STAT_CLI_PRINT;
662 return;
663 }
664
665 if (!*args[6] || strl2llrc(args[6], strlen(args[6]), &value) != 0) {
666 si->applet.ctx.cli.msg = "Require a valid integer value to store\n";
667 si->applet.st0 = STAT_CLI_PRINT;
668 return;
669 }
670
671 if (ts)
672 stktable_touch(&px->table, ts, 1);
673 else {
Willy Tarreau07115412012-10-29 21:56:59 +0100674 ts = stksess_new(&px->table, static_table_key);
Willy Tarreau654694e2012-06-07 01:03:16 +0200675 if (!ts) {
676 /* don't delete an entry which is currently referenced */
677 si->applet.ctx.cli.msg = "Unable to allocate a new entry\n";
678 si->applet.st0 = STAT_CLI_PRINT;
679 return;
680 }
681 stktable_store(&px->table, ts, 1);
682 }
683
684 ptr = stktable_data_ptr(&px->table, ts, data_type);
685 switch (stktable_data_types[data_type].std_type) {
686 case STD_T_SINT:
687 stktable_data_cast(ptr, std_t_sint) = value;
688 break;
689 case STD_T_UINT:
690 stktable_data_cast(ptr, std_t_uint) = value;
691 break;
692 case STD_T_ULL:
693 stktable_data_cast(ptr, std_t_ull) = value;
694 break;
695 case STD_T_FRQP:
696 /* We only reset the previous value so that it slowly fades out */
697 frqp = &stktable_data_cast(ptr, std_t_frqp);
698 frqp->curr_tick = now_ms;
699 frqp->prev_ctr = value;
700 frqp->curr_ctr = 0;
701 break;
702 }
703 break;
704
Willy Tarreaudec98142012-06-06 23:37:08 +0200705 default:
706 si->applet.ctx.cli.msg = "Unknown action\n";
Simon Horman121f3052011-06-15 15:18:46 +0900707 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreaudec98142012-06-06 23:37:08 +0200708 break;
Simon Horman121f3052011-06-15 15:18:46 +0900709 }
Simon Horman121f3052011-06-15 15:18:46 +0900710}
711
Willy Tarreau654694e2012-06-07 01:03:16 +0200712static void stats_sock_table_data_request(struct stream_interface *si, char **args, int action)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900713{
Willy Tarreau654694e2012-06-07 01:03:16 +0200714 if (action != STAT_CLI_O_TAB) {
715 si->applet.ctx.cli.msg = "content-based lookup is only supported with the \"show\" action";
716 si->applet.st0 = STAT_CLI_PRINT;
717 return;
718 }
719
Simon Hormand5b9fd92011-06-15 15:18:48 +0900720 /* condition on stored data value */
721 si->applet.ctx.table.data_type = stktable_get_data_type(args[3] + 5);
722 if (si->applet.ctx.table.data_type < 0) {
723 si->applet.ctx.cli.msg = "Unknown data type\n";
724 si->applet.st0 = STAT_CLI_PRINT;
725 return;
726 }
727
728 if (!((struct proxy *)si->applet.ctx.table.target)->table.data_ofs[si->applet.ctx.table.data_type]) {
729 si->applet.ctx.cli.msg = "Data type not stored in this table\n";
730 si->applet.st0 = STAT_CLI_PRINT;
731 return;
732 }
733
734 si->applet.ctx.table.data_op = get_std_op(args[4]);
735 if (si->applet.ctx.table.data_op < 0) {
736 si->applet.ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n";
737 si->applet.st0 = STAT_CLI_PRINT;
738 return;
739 }
740
741 if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &si->applet.ctx.table.value) != 0) {
742 si->applet.ctx.cli.msg = "Require a valid integer value to compare against\n";
743 si->applet.st0 = STAT_CLI_PRINT;
744 return;
745 }
746}
747
Willy Tarreaudec98142012-06-06 23:37:08 +0200748static void stats_sock_table_request(struct stream_interface *si, char **args, int action)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900749{
750 si->applet.ctx.table.data_type = -1;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200751 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaue17a8d02011-08-24 08:23:34 +0200752 si->applet.ctx.table.target = NULL;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900753 si->applet.ctx.table.proxy = NULL;
754 si->applet.ctx.table.entry = NULL;
Willy Tarreaudec98142012-06-06 23:37:08 +0200755 si->applet.st0 = action;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900756
757 if (*args[2]) {
758 si->applet.ctx.table.target = find_stktable(args[2]);
759 if (!si->applet.ctx.table.target) {
760 si->applet.ctx.cli.msg = "No such table\n";
761 si->applet.st0 = STAT_CLI_PRINT;
762 return;
763 }
764 }
765 else {
Willy Tarreaudec98142012-06-06 23:37:08 +0200766 if (action != STAT_CLI_O_TAB)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900767 goto err_args;
768 return;
769 }
770
771 if (strcmp(args[3], "key") == 0)
Willy Tarreaudec98142012-06-06 23:37:08 +0200772 stats_sock_table_key_request(si, args, action);
Simon Hormanc88b8872011-06-15 15:18:49 +0900773 else if (strncmp(args[3], "data.", 5) == 0)
Willy Tarreau654694e2012-06-07 01:03:16 +0200774 stats_sock_table_data_request(si, args, action);
Simon Hormanc88b8872011-06-15 15:18:49 +0900775 else if (*args[3])
Simon Hormand5b9fd92011-06-15 15:18:48 +0900776 goto err_args;
777
778 return;
779
780err_args:
Willy Tarreaudec98142012-06-06 23:37:08 +0200781 switch (action) {
782 case STAT_CLI_O_TAB:
Simon Hormand5b9fd92011-06-15 15:18:48 +0900783 si->applet.ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200784 break;
785 case STAT_CLI_O_CLR:
Simon Hormanc88b8872011-06-15 15:18:49 +0900786 si->applet.ctx.cli.msg = "Required arguments: <table> \"data.<store_data_type>\" <operator> <value> or <table> key <key>\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200787 break;
788 default:
789 si->applet.ctx.cli.msg = "Unknown action\n";
790 break;
791 }
Simon Hormand5b9fd92011-06-15 15:18:48 +0900792 si->applet.st0 = STAT_CLI_PRINT;
793}
794
Willy Tarreau532a4502011-09-07 22:37:44 +0200795/* Expects to find a frontend named <arg> and returns it, otherwise displays various
796 * adequate error messages and returns NULL. This function also expects the session
797 * level to be admin.
798 */
799static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg)
800{
801 struct proxy *px;
802
Willy Tarreau290e63a2012-09-20 18:07:14 +0200803 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau532a4502011-09-07 22:37:44 +0200804 si->applet.ctx.cli.msg = stats_permission_denied_msg;
805 si->applet.st0 = STAT_CLI_PRINT;
806 return NULL;
807 }
808
809 if (!*arg) {
810 si->applet.ctx.cli.msg = "A frontend name is expected.\n";
811 si->applet.st0 = STAT_CLI_PRINT;
812 return NULL;
813 }
814
815 px = findproxy(arg, PR_CAP_FE);
816 if (!px) {
817 si->applet.ctx.cli.msg = "No such frontend.\n";
818 si->applet.st0 = STAT_CLI_PRINT;
819 return NULL;
820 }
821 return px;
822}
823
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200824/* Expects to find a backend and a server in <arg> under the form <backend>/<server>,
825 * and returns the pointer to the server. Otherwise, display adequate error messages
826 * and returns NULL. This function also expects the session level to be admin. Note:
827 * the <arg> is modified to remove the '/'.
828 */
829static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg)
830{
831 struct proxy *px;
832 struct server *sv;
833 char *line;
834
Willy Tarreau290e63a2012-09-20 18:07:14 +0200835 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200836 si->applet.ctx.cli.msg = stats_permission_denied_msg;
837 si->applet.st0 = STAT_CLI_PRINT;
838 return NULL;
839 }
840
841 /* split "backend/server" and make <line> point to server */
842 for (line = arg; *line; line++)
843 if (*line == '/') {
844 *line++ = '\0';
845 break;
846 }
847
848 if (!*line || !*arg) {
849 si->applet.ctx.cli.msg = "Require 'backend/server'.\n";
850 si->applet.st0 = STAT_CLI_PRINT;
851 return NULL;
852 }
853
854 if (!get_backend_server(arg, line, &px, &sv)) {
855 si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
856 si->applet.st0 = STAT_CLI_PRINT;
857 return NULL;
858 }
859
860 if (px->state == PR_STSTOPPED) {
861 si->applet.ctx.cli.msg = "Proxy is disabled.\n";
862 si->applet.st0 = STAT_CLI_PRINT;
863 return NULL;
864 }
865
866 return sv;
867}
868
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200869/* Processes the stats interpreter on the statistics socket. This function is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200870 * called from an applet running in a stream interface. The function returns 1
Willy Tarreaubc4af052011-02-13 13:25:14 +0100871 * if the request was understood, otherwise zero. It sets si->applet.st0 to a value
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200872 * designating the function which will have to process the request, which can
873 * also be the print function to display the return message set into cli.msg.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200874 */
Simon Horman9bd2c732011-06-15 15:18:44 +0900875static int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200876{
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200877 struct session *s = si->conn->xprt_ctx;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200878 char *args[MAX_STATS_ARGS + 1];
879 int arg;
880
881 while (isspace((unsigned char)*line))
882 line++;
883
884 arg = 0;
885 args[arg] = line;
886
887 while (*line && arg < MAX_STATS_ARGS) {
888 if (isspace((unsigned char)*line)) {
889 *line++ = '\0';
890
891 while (isspace((unsigned char)*line))
892 line++;
893
894 args[++arg] = line;
895 continue;
896 }
897
898 line++;
899 }
900
901 while (++arg <= MAX_STATS_ARGS)
902 args[arg] = line;
903
Willy Tarreau295a8372011-03-10 11:25:07 +0100904 si->applet.ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200905 if (strcmp(args[0], "show") == 0) {
906 if (strcmp(args[1], "stat") == 0) {
907 if (*args[2] && *args[3] && *args[4]) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100908 si->applet.ctx.stats.flags |= STAT_BOUND;
909 si->applet.ctx.stats.iid = atoi(args[2]);
910 si->applet.ctx.stats.type = atoi(args[3]);
911 si->applet.ctx.stats.sid = atoi(args[4]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200912 }
913
Willy Tarreau295a8372011-03-10 11:25:07 +0100914 si->applet.ctx.stats.flags |= STAT_SHOW_STAT;
915 si->applet.ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200916 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100917 si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200918 }
919 else if (strcmp(args[1], "info") == 0) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100920 si->applet.ctx.stats.flags |= STAT_SHOW_INFO;
921 si->applet.ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200922 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100923 si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200924 }
925 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200926 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreau290e63a2012-09-20 18:07:14 +0200927 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100928 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100929 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200930 return 1;
931 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100932 if (*args[2])
Willy Tarreau295a8372011-03-10 11:25:07 +0100933 si->applet.ctx.sess.target = (void *)strtoul(args[2], NULL, 0);
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100934 else
Willy Tarreau295a8372011-03-10 11:25:07 +0100935 si->applet.ctx.sess.target = NULL;
936 si->applet.ctx.sess.section = 0; /* start with session status */
937 si->applet.ctx.sess.pos = 0;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100938 si->applet.st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200939 }
940 else if (strcmp(args[1], "errors") == 0) {
Willy Tarreau290e63a2012-09-20 18:07:14 +0200941 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100942 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100943 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200944 return 1;
945 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200946 if (*args[2])
Willy Tarreau295a8372011-03-10 11:25:07 +0100947 si->applet.ctx.errors.iid = atoi(args[2]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200948 else
Willy Tarreau295a8372011-03-10 11:25:07 +0100949 si->applet.ctx.errors.iid = -1;
950 si->applet.ctx.errors.px = NULL;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200951 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100952 si->applet.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200953 }
Willy Tarreau69f58c82010-07-12 17:55:33 +0200954 else if (strcmp(args[1], "table") == 0) {
Willy Tarreaudec98142012-06-06 23:37:08 +0200955 stats_sock_table_request(si, args, STAT_CLI_O_TAB);
Willy Tarreau69f58c82010-07-12 17:55:33 +0200956 }
Aman Guptaceafb4a2012-04-02 18:57:54 -0700957 else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200958 return 0;
959 }
960 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200961 else if (strcmp(args[0], "clear") == 0) {
962 if (strcmp(args[1], "counters") == 0) {
963 struct proxy *px;
964 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200965 struct listener *li;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200966 int clrall = 0;
967
968 if (strcmp(args[2], "all") == 0)
969 clrall = 1;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200970
Willy Tarreau6162db22009-10-10 17:13:00 +0200971 /* check permissions */
Willy Tarreau290e63a2012-09-20 18:07:14 +0200972 if (s->listener->bind_conf->level < ACCESS_LVL_OPER ||
973 (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100974 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100975 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200976 return 1;
977 }
978
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200979 for (px = proxy; px; px = px->next) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100980 if (clrall) {
981 memset(&px->be_counters, 0, sizeof(px->be_counters));
982 memset(&px->fe_counters, 0, sizeof(px->fe_counters));
983 }
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200984 else {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100985 px->be_counters.conn_max = 0;
986 px->be_counters.p.http.rps_max = 0;
987 px->be_counters.sps_max = 0;
988 px->be_counters.cps_max = 0;
989 px->be_counters.nbpend_max = 0;
990
991 px->fe_counters.conn_max = 0;
992 px->fe_counters.p.http.rps_max = 0;
993 px->fe_counters.sps_max = 0;
994 px->fe_counters.cps_max = 0;
995 px->fe_counters.nbpend_max = 0;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200996 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200997
998 for (sv = px->srv; sv; sv = sv->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200999 if (clrall)
1000 memset(&sv->counters, 0, sizeof(sv->counters));
1001 else {
1002 sv->counters.cur_sess_max = 0;
1003 sv->counters.nbpend_max = 0;
1004 sv->counters.sps_max = 0;
1005 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001006
Willy Tarreaua7944ad2012-09-26 21:03:11 +02001007 list_for_each_entry(li, &px->conf.listeners, by_fe)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001008 if (li->counters) {
1009 if (clrall)
1010 memset(li->counters, 0, sizeof(*li->counters));
1011 else
1012 li->counters->conn_max = 0;
1013 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001014 }
1015
Willy Tarreau81c25d02011-09-07 15:17:21 +02001016 global.cps_max = 0;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001017 return 1;
1018 }
Willy Tarreau88ee3972010-07-13 13:48:00 +02001019 else if (strcmp(args[1], "table") == 0) {
Willy Tarreaudec98142012-06-06 23:37:08 +02001020 stats_sock_table_request(si, args, STAT_CLI_O_CLR);
Willy Tarreau88ee3972010-07-13 13:48:00 +02001021 /* end of processing */
1022 return 1;
1023 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001024 else {
Willy Tarreau88ee3972010-07-13 13:48:00 +02001025 /* unknown "clear" argument */
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001026 return 0;
1027 }
1028 }
Willy Tarreau38338fa2009-10-10 18:37:29 +02001029 else if (strcmp(args[0], "get") == 0) {
1030 if (strcmp(args[1], "weight") == 0) {
1031 struct proxy *px;
1032 struct server *sv;
1033
1034 /* split "backend/server" and make <line> point to server */
1035 for (line = args[2]; *line; line++)
1036 if (*line == '/') {
1037 *line++ = '\0';
1038 break;
1039 }
1040
1041 if (!*line) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001042 si->applet.ctx.cli.msg = "Require 'backend/server'.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001043 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +02001044 return 1;
1045 }
1046
1047 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001048 si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001049 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +02001050 return 1;
1051 }
1052
1053 /* return server's effective weight at the moment */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001054 snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight);
1055 bi_putstr(si->ib, trash.str);
Willy Tarreau38338fa2009-10-10 18:37:29 +02001056 return 1;
1057 }
1058 else { /* not "get weight" */
1059 return 0;
1060 }
1061 }
Willy Tarreau4483d432009-10-10 19:30:08 +02001062 else if (strcmp(args[0], "set") == 0) {
1063 if (strcmp(args[1], "weight") == 0) {
1064 struct proxy *px;
1065 struct server *sv;
1066 int w;
1067
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001068 sv = expect_server_admin(s, si, args[2]);
1069 if (!sv)
Willy Tarreau4483d432009-10-10 19:30:08 +02001070 return 1;
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001071 px = sv->proxy;
Willy Tarreau4483d432009-10-10 19:30:08 +02001072
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001073 /* if the weight is terminated with '%', it is set relative to
1074 * the initial weight, otherwise it is absolute.
1075 */
1076 if (!*args[3]) {
1077 si->applet.ctx.cli.msg = "Require <weight> or <weight%>.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001078 si->applet.st0 = STAT_CLI_PRINT;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001079 return 1;
1080 }
1081
Willy Tarreau4483d432009-10-10 19:30:08 +02001082 w = atoi(args[3]);
1083 if (strchr(args[3], '%') != NULL) {
1084 if (w < 0 || w > 100) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001085 si->applet.ctx.cli.msg = "Relative weight can only be set between 0 and 100% inclusive.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001086 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001087 return 1;
1088 }
1089 w = sv->iweight * w / 100;
1090 }
1091 else {
1092 if (w < 0 || w > 256) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001093 si->applet.ctx.cli.msg = "Absolute weight can only be between 0 and 256 inclusive.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001094 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001095 return 1;
1096 }
1097 }
1098
1099 if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001100 si->applet.ctx.cli.msg = "Backend is using a static LB algorithm and only accepts weights '0%' and '100%'.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001101 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001102 return 1;
1103 }
1104
1105 sv->uweight = w;
1106
1107 if (px->lbprm.algo & BE_LB_PROP_DYN) {
1108 /* we must take care of not pushing the server to full throttle during slow starts */
1109 if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN))
1110 sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart;
1111 else
1112 sv->eweight = BE_WEIGHT_SCALE;
1113 sv->eweight *= sv->uweight;
1114 } else {
1115 sv->eweight = sv->uweight;
1116 }
1117
1118 /* static LB algorithms are a bit harder to update */
1119 if (px->lbprm.update_server_eweight)
1120 px->lbprm.update_server_eweight(sv);
Willy Tarreau9580d162012-05-19 19:07:40 +02001121 else if (sv->eweight) {
1122 if (px->lbprm.set_server_status_up)
1123 px->lbprm.set_server_status_up(sv);
1124 }
1125 else {
1126 if (px->lbprm.set_server_status_down)
1127 px->lbprm.set_server_status_down(sv);
1128 }
Willy Tarreau4483d432009-10-10 19:30:08 +02001129
1130 return 1;
1131 }
Willy Tarreau7aabd112010-01-26 10:59:06 +01001132 else if (strcmp(args[1], "timeout") == 0) {
1133 if (strcmp(args[2], "cli") == 0) {
1134 unsigned timeout;
1135 const char *res;
1136
1137 if (!*args[3]) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001138 si->applet.ctx.cli.msg = "Expects an integer value.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001139 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001140 return 1;
1141 }
1142
1143 res = parse_time_err(args[3], &timeout, TIME_UNIT_S);
1144 if (res || timeout < 1) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001145 si->applet.ctx.cli.msg = "Invalid timeout value.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001146 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001147 return 1;
1148 }
1149
1150 s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000);
1151 return 1;
1152 }
1153 else {
Willy Tarreau295a8372011-03-10 11:25:07 +01001154 si->applet.ctx.cli.msg = "'set timeout' only supports 'cli'.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001155 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001156 return 1;
1157 }
1158 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001159 else if (strcmp(args[1], "maxconn") == 0) {
1160 if (strcmp(args[2], "frontend") == 0) {
1161 struct proxy *px;
1162 struct listener *l;
1163 int v;
1164
Willy Tarreau532a4502011-09-07 22:37:44 +02001165 px = expect_frontend_admin(s, si, args[3]);
1166 if (!px)
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001167 return 1;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001168
1169 if (!*args[4]) {
1170 si->applet.ctx.cli.msg = "Integer value expected.\n";
1171 si->applet.st0 = STAT_CLI_PRINT;
1172 return 1;
1173 }
1174
1175 v = atoi(args[4]);
Willy Tarreau3c7a79d2012-09-26 21:07:15 +02001176 if (v < 0) {
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001177 si->applet.ctx.cli.msg = "Value out of range.\n";
1178 si->applet.st0 = STAT_CLI_PRINT;
1179 return 1;
1180 }
1181
1182 /* OK, the value is fine, so we assign it to the proxy and to all of
1183 * its listeners. The blocked ones will be dequeued.
1184 */
1185 px->maxconn = v;
Willy Tarreaua7944ad2012-09-26 21:03:11 +02001186 list_for_each_entry(l, &px->conf.listeners, by_fe) {
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001187 l->maxconn = v;
1188 if (l->state == LI_FULL)
1189 resume_listener(l);
1190 }
1191
1192 if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue))
1193 dequeue_all_listeners(&s->fe->listener_queue);
1194
1195 return 1;
1196 }
Willy Tarreau91886b62011-09-07 14:38:31 +02001197 else if (strcmp(args[2], "global") == 0) {
1198 int v;
1199
Willy Tarreau290e63a2012-09-20 18:07:14 +02001200 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau91886b62011-09-07 14:38:31 +02001201 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1202 si->applet.st0 = STAT_CLI_PRINT;
1203 return 1;
1204 }
1205
1206 if (!*args[3]) {
1207 si->applet.ctx.cli.msg = "Expects an integer value.\n";
1208 si->applet.st0 = STAT_CLI_PRINT;
1209 return 1;
1210 }
1211
1212 v = atoi(args[3]);
1213 if (v > global.hardmaxconn) {
1214 si->applet.ctx.cli.msg = "Value out of range.\n";
1215 si->applet.st0 = STAT_CLI_PRINT;
1216 return 1;
1217 }
1218
1219 /* check for unlimited values */
1220 if (v <= 0)
1221 v = global.hardmaxconn;
1222
1223 global.maxconn = v;
1224
1225 /* Dequeues all of the listeners waiting for a resource */
1226 if (!LIST_ISEMPTY(&global_listener_queue))
1227 dequeue_all_listeners(&global_listener_queue);
1228
1229 return 1;
1230 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001231 else {
Willy Tarreau91886b62011-09-07 14:38:31 +02001232 si->applet.ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n";
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001233 si->applet.st0 = STAT_CLI_PRINT;
1234 return 1;
1235 }
1236 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001237 else if (strcmp(args[1], "rate-limit") == 0) {
1238 if (strcmp(args[2], "connections") == 0) {
1239 if (strcmp(args[3], "global") == 0) {
1240 int v;
1241
Willy Tarreau290e63a2012-09-20 18:07:14 +02001242 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreauf5b22872011-09-07 16:13:44 +02001243 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1244 si->applet.st0 = STAT_CLI_PRINT;
1245 return 1;
1246 }
1247
1248 if (!*args[4]) {
1249 si->applet.ctx.cli.msg = "Expects an integer value.\n";
1250 si->applet.st0 = STAT_CLI_PRINT;
1251 return 1;
1252 }
1253
1254 v = atoi(args[4]);
1255 if (v < 0) {
1256 si->applet.ctx.cli.msg = "Value out of range.\n";
1257 si->applet.st0 = STAT_CLI_PRINT;
1258 return 1;
1259 }
1260
1261 global.cps_lim = v;
1262
1263 /* Dequeues all of the listeners waiting for a resource */
1264 if (!LIST_ISEMPTY(&global_listener_queue))
1265 dequeue_all_listeners(&global_listener_queue);
1266
1267 return 1;
1268 }
1269 else {
1270 si->applet.ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n";
1271 si->applet.st0 = STAT_CLI_PRINT;
1272 return 1;
1273 }
1274 }
William Lallemandd85f9172012-11-09 17:05:39 +01001275 else if (strcmp(args[2], "http-compression") == 0) {
1276 if (strcmp(args[3], "global") == 0) {
1277 int v;
1278
Willy Tarreau85d47f92012-11-21 00:29:50 +01001279 if (!*args[4]) {
1280 si->applet.ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n";
1281 si->applet.st0 = STAT_CLI_PRINT;
1282 return 1;
1283 }
1284
William Lallemandd85f9172012-11-09 17:05:39 +01001285 v = atoi(args[4]);
1286 global.comp_rate_lim = v * 1024; /* Kilo to bytes. */
1287 }
1288 else {
1289 si->applet.ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n";
1290 si->applet.st0 = STAT_CLI_PRINT;
1291 return 1;
1292 }
1293 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001294 else {
William Lallemandd85f9172012-11-09 17:05:39 +01001295 si->applet.ctx.cli.msg = "'set rate-limit' supports 'connections' and 'http-compression'.\n";
Willy Tarreauf5b22872011-09-07 16:13:44 +02001296 si->applet.st0 = STAT_CLI_PRINT;
1297 return 1;
1298 }
1299 }
Willy Tarreau654694e2012-06-07 01:03:16 +02001300 else if (strcmp(args[1], "table") == 0) {
1301 stats_sock_table_request(si, args, STAT_CLI_O_SET);
1302 }
Willy Tarreau7aabd112010-01-26 10:59:06 +01001303 else { /* unknown "set" parameter */
Willy Tarreau4483d432009-10-10 19:30:08 +02001304 return 0;
1305 }
1306 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001307 else if (strcmp(args[0], "enable") == 0) {
1308 if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001309 struct server *sv;
1310
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001311 sv = expect_server_admin(s, si, args[2]);
1312 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01001313 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001314
Cyril Bontécd19e512010-01-31 22:34:03 +01001315 if (sv->state & SRV_MAINTAIN) {
1316 /* The server is really in maintenance, we can change the server state */
Willy Tarreau44267702011-10-28 15:35:33 +02001317 if (sv->track) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001318 /* If this server tracks the status of another one,
1319 * we must restore the good status.
1320 */
Willy Tarreau44267702011-10-28 15:35:33 +02001321 if (sv->track->state & SRV_RUNNING) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001322 set_server_up(sv);
Willy Tarreau70461302010-10-22 14:39:02 +02001323 sv->health = sv->rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +01001324 } else {
1325 sv->state &= ~SRV_MAINTAIN;
1326 set_server_down(sv);
1327 }
1328 } else {
1329 set_server_up(sv);
Willy Tarreau70461302010-10-22 14:39:02 +02001330 sv->health = sv->rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +01001331 }
1332 }
1333
Willy Tarreau532a4502011-09-07 22:37:44 +02001334 return 1;
1335 }
1336 else if (strcmp(args[1], "frontend") == 0) {
1337 struct proxy *px;
1338
1339 px = expect_frontend_admin(s, si, args[2]);
1340 if (!px)
1341 return 1;
1342
1343 if (px->state == PR_STSTOPPED) {
1344 si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n";
1345 si->applet.st0 = STAT_CLI_PRINT;
1346 return 1;
1347 }
1348
1349 if (px->state != PR_STPAUSED) {
1350 si->applet.ctx.cli.msg = "Frontend is already enabled.\n";
1351 si->applet.st0 = STAT_CLI_PRINT;
1352 return 1;
1353 }
1354
1355 if (!resume_proxy(px)) {
1356 si->applet.ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n";
1357 si->applet.st0 = STAT_CLI_PRINT;
1358 return 1;
1359 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001360 return 1;
1361 }
1362 else { /* unknown "enable" parameter */
Willy Tarreau532a4502011-09-07 22:37:44 +02001363 si->applet.ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n";
1364 si->applet.st0 = STAT_CLI_PRINT;
1365 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01001366 }
1367 }
1368 else if (strcmp(args[0], "disable") == 0) {
1369 if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001370 struct server *sv;
1371
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001372 sv = expect_server_admin(s, si, args[2]);
1373 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01001374 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001375
Cyril Bontécd19e512010-01-31 22:34:03 +01001376 if (! (sv->state & SRV_MAINTAIN)) {
1377 /* Not already in maintenance, we can change the server state */
1378 sv->state |= SRV_MAINTAIN;
1379 set_server_down(sv);
1380 }
1381
Willy Tarreau532a4502011-09-07 22:37:44 +02001382 return 1;
1383 }
1384 else if (strcmp(args[1], "frontend") == 0) {
1385 struct proxy *px;
1386
1387 px = expect_frontend_admin(s, si, args[2]);
1388 if (!px)
1389 return 1;
1390
1391 if (px->state == PR_STSTOPPED) {
1392 si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n";
1393 si->applet.st0 = STAT_CLI_PRINT;
1394 return 1;
1395 }
1396
1397 if (px->state == PR_STPAUSED) {
1398 si->applet.ctx.cli.msg = "Frontend is already disabled.\n";
1399 si->applet.st0 = STAT_CLI_PRINT;
1400 return 1;
1401 }
1402
1403 if (!pause_proxy(px)) {
1404 si->applet.ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n";
1405 si->applet.st0 = STAT_CLI_PRINT;
1406 return 1;
1407 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001408 return 1;
1409 }
1410 else { /* unknown "disable" parameter */
Willy Tarreau532a4502011-09-07 22:37:44 +02001411 si->applet.ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n";
1412 si->applet.st0 = STAT_CLI_PRINT;
1413 return 1;
1414 }
1415 }
1416 else if (strcmp(args[0], "shutdown") == 0) {
1417 if (strcmp(args[1], "frontend") == 0) {
1418 struct proxy *px;
1419
1420 px = expect_frontend_admin(s, si, args[2]);
1421 if (!px)
1422 return 1;
1423
1424 if (px->state == PR_STSTOPPED) {
1425 si->applet.ctx.cli.msg = "Frontend was already shut down.\n";
1426 si->applet.st0 = STAT_CLI_PRINT;
1427 return 1;
1428 }
1429
1430 Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
1431 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
1432 send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
1433 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
1434 stop_proxy(px);
1435 return 1;
1436 }
Willy Tarreaua295edc2011-09-07 23:21:03 +02001437 else if (strcmp(args[1], "session") == 0) {
1438 struct session *sess, *ptr;
1439
Willy Tarreau290e63a2012-09-20 18:07:14 +02001440 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreaua295edc2011-09-07 23:21:03 +02001441 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1442 si->applet.st0 = STAT_CLI_PRINT;
1443 return 1;
1444 }
1445
1446 if (!*args[2]) {
1447 si->applet.ctx.cli.msg = "Session pointer expected (use 'show sess').\n";
1448 si->applet.st0 = STAT_CLI_PRINT;
1449 return 1;
1450 }
1451
1452 ptr = (void *)strtoul(args[2], NULL, 0);
1453
1454 /* first, look for the requested session in the session table */
1455 list_for_each_entry(sess, &sessions, list) {
1456 if (sess == ptr)
1457 break;
1458 }
1459
1460 /* do we have the session ? */
1461 if (sess != ptr) {
1462 si->applet.ctx.cli.msg = "No such session (use 'show sess').\n";
1463 si->applet.st0 = STAT_CLI_PRINT;
1464 return 1;
1465 }
1466
1467 session_shutdown(sess, SN_ERR_KILLED);
1468 return 1;
1469 }
Willy Tarreau52b2d222011-09-07 23:48:48 +02001470 else if (strcmp(args[1], "sessions") == 0) {
1471 if (strcmp(args[2], "server") == 0) {
1472 struct server *sv;
1473 struct session *sess, *sess_bck;
1474
1475 sv = expect_server_admin(s, si, args[3]);
1476 if (!sv)
1477 return 1;
1478
1479 /* kill all the session that are on this server */
1480 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
1481 if (sess->srv_conn == sv)
1482 session_shutdown(sess, SN_ERR_KILLED);
1483
1484 return 1;
1485 }
1486 else {
1487 si->applet.ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n";
1488 si->applet.st0 = STAT_CLI_PRINT;
1489 return 1;
1490 }
1491 }
Willy Tarreau532a4502011-09-07 22:37:44 +02001492 else { /* unknown "disable" parameter */
Willy Tarreau52b2d222011-09-07 23:48:48 +02001493 si->applet.ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n";
Willy Tarreau532a4502011-09-07 22:37:44 +02001494 si->applet.st0 = STAT_CLI_PRINT;
1495 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01001496 }
1497 }
1498 else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001499 return 0;
1500 }
1501 return 1;
1502}
1503
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001504/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001505 * used to processes I/O from/to the stats unix socket. The system relies on a
1506 * state machine handling requests and various responses. We read a request,
1507 * then we process it and send the response, and we possibly display a prompt.
Willy Tarreaubc4af052011-02-13 13:25:14 +01001508 * Then we can read again. The state is stored in si->applet.st0 and is one of the
1509 * STAT_CLI_* constants. si->applet.st1 is used to indicate whether prompt is enabled
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001510 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001511 */
Willy Tarreaub24281b2011-02-13 13:16:36 +01001512static void cli_io_handler(struct stream_interface *si)
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001513{
Willy Tarreau7421efb2012-07-02 15:11:27 +02001514 struct channel *req = si->ob;
1515 struct channel *res = si->ib;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001516 int reql;
1517 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001518
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001519 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
1520 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001521
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001522 while (1) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001523 if (si->applet.st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001524 /* Stats output not initialized yet */
Willy Tarreau295a8372011-03-10 11:25:07 +01001525 memset(&si->applet.ctx.stats, 0, sizeof(si->applet.ctx.stats));
Willy Tarreaubc4af052011-02-13 13:25:14 +01001526 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001527 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001528 else if (si->applet.st0 == STAT_CLI_END) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001529 /* Let's close for real now. We just close the request
1530 * side, the conditions below will complete if needed.
1531 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001532 si_shutw(si);
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001533 break;
1534 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001535 else if (si->applet.st0 == STAT_CLI_GETREQ) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02001536 /* ensure we have some output room left in the event we
1537 * would want to return some info right after parsing.
1538 */
Willy Tarreau9b28e032012-10-12 23:49:43 +02001539 if (buffer_almost_full(si->ib->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02001540 break;
1541
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001542 reql = bo_getline(si->ob, trash.str, trash.size);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001543 if (reql <= 0) { /* closed or EOL not found */
1544 if (reql == 0)
1545 break;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001546 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001547 continue;
1548 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001549
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001550 /* seek for a possible semi-colon. If we find one, we
1551 * replace it with an LF and skip only this part.
1552 */
1553 for (len = 0; len < reql; len++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001554 if (trash.str[len] == ';') {
1555 trash.str[len] = '\n';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001556 reql = len + 1;
1557 break;
1558 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001559
Willy Tarreau816fc222009-10-04 07:36:58 +02001560 /* now it is time to check that we have a full line,
1561 * remove the trailing \n and possibly \r, then cut the
1562 * line.
1563 */
1564 len = reql - 1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001565 if (trash.str[len] != '\n') {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001566 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001567 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001568 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001569
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001570 if (len && trash.str[len-1] == '\r')
Willy Tarreau816fc222009-10-04 07:36:58 +02001571 len--;
1572
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001573 trash.str[len] = '\0';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001574
Willy Tarreaubc4af052011-02-13 13:25:14 +01001575 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001576 if (len) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001577 if (strcmp(trash.str, "quit") == 0) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001578 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001579 continue;
1580 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001581 else if (strcmp(trash.str, "prompt") == 0)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001582 si->applet.st1 = !si->applet.st1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001583 else if (strcmp(trash.str, "help") == 0 ||
1584 !stats_sock_parse_request(si, trash.str)) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001585 si->applet.ctx.cli.msg = stats_sock_usage_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001586 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001587 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001588 /* NB: stats_sock_parse_request() may have put
Willy Tarreaubc4af052011-02-13 13:25:14 +01001589 * another STAT_CLI_O_* into si->applet.st0.
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001590 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001591 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001592 else if (!si->applet.st1) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001593 /* if prompt is disabled, print help on empty lines,
1594 * so that the user at least knows how to enable
1595 * prompt and find help.
1596 */
Willy Tarreau295a8372011-03-10 11:25:07 +01001597 si->applet.ctx.cli.msg = stats_sock_usage_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001598 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001599 }
1600
1601 /* re-adjust req buffer */
Willy Tarreau9dab5fc2012-05-07 11:56:55 +02001602 bo_skip(si->ob, reql);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001603 req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001604 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001605 else { /* output functions: first check if the output buffer is closed then abort */
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001606 if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001607 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001608 continue;
1609 }
1610
Willy Tarreaubc4af052011-02-13 13:25:14 +01001611 switch (si->applet.st0) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001612 case STAT_CLI_PRINT:
Willy Tarreau9dab5fc2012-05-07 11:56:55 +02001613 if (bi_putstr(si->ib, si->applet.ctx.cli.msg) != -1)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001614 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001615 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001616 case STAT_CLI_O_INFO:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001617 if (stats_dump_raw_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001618 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001619 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001620 case STAT_CLI_O_SESS:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001621 if (stats_dump_sess_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001622 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001623 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001624 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001625 if (stats_dump_errors_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001626 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001627 break;
Willy Tarreau69f58c82010-07-12 17:55:33 +02001628 case STAT_CLI_O_TAB:
Simon Hormanc88b8872011-06-15 15:18:49 +09001629 case STAT_CLI_O_CLR:
Willy Tarreaudec98142012-06-06 23:37:08 +02001630 if (stats_table_request(si, si->applet.st0))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001631 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau69f58c82010-07-12 17:55:33 +02001632 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001633 default: /* abnormal state */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001634 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001635 break;
1636 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001637
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001638 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001639 if (si->applet.st0 == STAT_CLI_PROMPT) {
Willy Tarreau9dab5fc2012-05-07 11:56:55 +02001640 if (bi_putstr(si->ib, si->applet.st1 ? "\n> " : "\n") != -1)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001641 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001642 }
1643
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001644 /* If the output functions are still there, it means they require more room. */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001645 if (si->applet.st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001646 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001647
1648 /* Now we close the output if one of the writers did so,
1649 * or if we're not in interactive mode and the request
1650 * buffer is empty. This still allows pipelined requests
1651 * to be sent in non-interactive mode.
1652 */
Willy Tarreau9b28e032012-10-12 23:49:43 +02001653 if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!si->applet.st1 && !req->buf->o)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001654 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001655 continue;
1656 }
1657
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001658 /* switch state back to GETREQ to read next requests */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001659 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001660 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001661 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001662
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001663 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST) && (si->applet.st0 != STAT_CLI_GETREQ)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001664 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
1665 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
Aman Guptaceafb4a2012-04-02 18:57:54 -07001666 /* Other side has closed, let's abort if we have no more processing to do
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001667 * and nothing more to consume. This is comparable to a broken pipe, so
1668 * we forward the close to the request side so that it flows upstream to
1669 * the client.
1670 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001671 si_shutw(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001672 }
1673
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001674 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (si->applet.st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001675 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
1676 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
1677 /* We have no more processing to do, and nothing more to send, and
1678 * the client side has closed. So we'll forward this state downstream
1679 * on the response buffer.
1680 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001681 si_shutr(si);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001682 res->flags |= CF_READ_NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001683 }
1684
1685 /* update all other flags and resync with the other side */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001686 si_update(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001687
1688 /* we don't want to expire timeouts while we're processing requests */
1689 si->ib->rex = TICK_ETERNITY;
1690 si->ob->wex = TICK_ETERNITY;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001691
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001692 out:
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01001693 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 +02001694 __FUNCTION__, __LINE__,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001695 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 +02001696
1697 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1698 /* check that we have released everything then unregister */
1699 stream_int_unregister_handler(si);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001700 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001701}
1702
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001703/* This function dumps statistics onto the stream interface's read buffer.
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02001704 * The xprt_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau24955a12009-10-04 11:54:04 +02001705 * It returns 0 as long as it does not complete, non-zero upon completion.
1706 * Some states are not used but it makes the code more similar to other
1707 * functions which handle stats too.
Willy Tarreau3e76e722007-10-17 18:57:38 +02001708 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001709static int stats_dump_raw_to_buffer(struct stream_interface *si)
Willy Tarreau3e76e722007-10-17 18:57:38 +02001710{
Willy Tarreau3e76e722007-10-17 18:57:38 +02001711 struct proxy *px;
Willy Tarreaua8efd362008-01-03 10:19:15 +01001712 unsigned int up;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001713
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001714 chunk_reset(&trash);
Willy Tarreau3e76e722007-10-17 18:57:38 +02001715
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001716 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001717 case STAT_ST_INIT:
Willy Tarreau24955a12009-10-04 11:54:04 +02001718 /* the function had not been called yet */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001719 si->conn->xprt_st = STAT_ST_HEAD;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001720 /* fall through */
1721
Willy Tarreau295a8372011-03-10 11:25:07 +01001722 case STAT_ST_HEAD:
1723 if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001724 print_csv_header(&trash);
1725 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001726 return 0;
1727 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001728
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001729 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001730 /* fall through */
1731
Willy Tarreau295a8372011-03-10 11:25:07 +01001732 case STAT_ST_INFO:
Willy Tarreaua8efd362008-01-03 10:19:15 +01001733 up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau295a8372011-03-10 11:25:07 +01001734 if (si->applet.ctx.stats.flags & STAT_SHOW_INFO) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001735 chunk_appendf(&trash,
Willy Tarreaua8efd362008-01-03 10:19:15 +01001736 "Name: " PRODUCT_NAME "\n"
1737 "Version: " HAPROXY_VERSION "\n"
1738 "Release_date: " HAPROXY_DATE "\n"
1739 "Nbproc: %d\n"
1740 "Process_num: %d\n"
1741 "Pid: %d\n"
1742 "Uptime: %dd %dh%02dm%02ds\n"
1743 "Uptime_sec: %d\n"
1744 "Memmax_MB: %d\n"
1745 "Ulimit-n: %d\n"
1746 "Maxsock: %d\n"
1747 "Maxconn: %d\n"
Willy Tarreau91886b62011-09-07 14:38:31 +02001748 "Hard_maxconn: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +01001749 "Maxpipes: %d\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001750 "CurrConns: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +01001751 "PipesUsed: %d\n"
1752 "PipesFree: %d\n"
Willy Tarreau9cd552d2011-09-07 15:26:48 +02001753 "ConnRate: %d\n"
1754 "ConnRateLimit: %d\n"
1755 "MaxConnRate: %d\n"
William Lallemandd85f9172012-11-09 17:05:39 +01001756 "CompressBpsIn: %u\n"
1757 "CompressBpsOut: %u\n"
William Lallemand096f5542012-11-19 17:26:05 +01001758 "CompressBpsRateLim: %u\n"
William Lallemande3a7d992012-11-20 11:25:20 +01001759#ifdef USE_ZLIB
1760 "ZlibMemUsage: %ld\n"
1761 "MaxZlibMemUsage: %ld\n"
1762#endif
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001763 "Tasks: %d\n"
1764 "Run_queue: %d\n"
Willy Tarreau45a12512011-09-10 16:56:42 +02001765 "Idle_pct: %d\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001766 "node: %s\n"
1767 "description: %s\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001768 "",
1769 global.nbproc,
1770 relative_pid,
1771 pid,
1772 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
1773 up,
1774 global.rlimit_memmax,
1775 global.rlimit_nofile,
Willy Tarreau91886b62011-09-07 14:38:31 +02001776 global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001777 actconn, pipes_used, pipes_free,
Willy Tarreau9cd552d2011-09-07 15:26:48 +02001778 read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max,
William Lallemandd85f9172012-11-09 17:05:39 +01001779 read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out),
William Lallemand096f5542012-11-19 17:26:05 +01001780 global.comp_rate_lim,
William Lallemande3a7d992012-11-20 11:25:20 +01001781#ifdef USE_ZLIB
1782 zlib_used_memory, global.maxzlibmem,
1783#endif
Willy Tarreau45a12512011-09-10 16:56:42 +02001784 nb_tasks_cur, run_queue_cur, idle_pct,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001785 global.node, global.desc?global.desc:""
Willy Tarreaua8efd362008-01-03 10:19:15 +01001786 );
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001787 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001788 return 0;
1789 }
1790
Willy Tarreau295a8372011-03-10 11:25:07 +01001791 si->applet.ctx.stats.px = proxy;
1792 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
1793 si->applet.ctx.stats.sv = NULL;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001794 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001795 /* fall through */
1796
Willy Tarreau295a8372011-03-10 11:25:07 +01001797 case STAT_ST_LIST:
Willy Tarreau3e76e722007-10-17 18:57:38 +02001798 /* dump proxies */
Willy Tarreau295a8372011-03-10 11:25:07 +01001799 if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) {
1800 while (si->applet.ctx.stats.px) {
1801 px = si->applet.ctx.stats.px;
Willy Tarreau050536d2012-10-04 08:47:34 +02001802 /* skip the disabled proxies, global frontend and non-networked ones */
1803 if (px->state != PR_STSTOPPED && px->uuid > 0 &&
Willy Tarreau24955a12009-10-04 11:54:04 +02001804 (px->cap & (PR_CAP_FE | PR_CAP_BE))) {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001805 if (stats_dump_proxy(si, px, NULL) == 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001806 return 0;
Willy Tarreau24955a12009-10-04 11:54:04 +02001807 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001808
Willy Tarreau295a8372011-03-10 11:25:07 +01001809 si->applet.ctx.stats.px = px->next;
1810 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreaua8efd362008-01-03 10:19:15 +01001811 }
1812 /* here, we just have reached the last proxy */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001813 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001814
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001815 si->conn->xprt_st = STAT_ST_END;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001816 /* fall through */
1817
Willy Tarreau295a8372011-03-10 11:25:07 +01001818 case STAT_ST_END:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001819 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau0a464892008-12-07 18:30:00 +01001820 /* fall through */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001821
Willy Tarreau295a8372011-03-10 11:25:07 +01001822 case STAT_ST_FIN:
Willy Tarreau3e76e722007-10-17 18:57:38 +02001823 return 1;
1824
1825 default:
1826 /* unknown state ! */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001827 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau24955a12009-10-04 11:54:04 +02001828 return 1;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001829 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001830}
1831
1832
Cyril Bonté70be45d2010-10-12 00:14:35 +02001833/* We don't want to land on the posted stats page because a refresh will
1834 * repost the data. We don't want this to happen on accident so we redirect
1835 * the browse to the stats page with a GET.
1836 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001837static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri)
Cyril Bonté70be45d2010-10-12 00:14:35 +02001838{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001839 struct session *s = si->conn->xprt_ctx;
Cyril Bonté70be45d2010-10-12 00:14:35 +02001840
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001841 chunk_reset(&trash);
Cyril Bonté70be45d2010-10-12 00:14:35 +02001842
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001843 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001844 case STAT_ST_INIT:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001845 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02001846 "HTTP/1.0 303 See Other\r\n"
1847 "Cache-Control: no-cache\r\n"
1848 "Content-Type: text/plain\r\n"
1849 "Connection: close\r\n"
1850 "Location: %s;st=%s",
Cyril Bonté19979e12012-04-04 12:57:21 +02001851 uri->uri_prefix,
1852 ((si->applet.ctx.stats.st_code > STAT_STATUS_INIT) &&
1853 (si->applet.ctx.stats.st_code < STAT_STATUS_SIZE) &&
1854 stat_status_codes[si->applet.ctx.stats.st_code]) ?
1855 stat_status_codes[si->applet.ctx.stats.st_code] :
1856 stat_status_codes[STAT_STATUS_UNKN]);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001857 chunk_appendf(&trash, "\r\n\r\n");
Cyril Bonté70be45d2010-10-12 00:14:35 +02001858
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001859 if (bi_putchk(si->ib, &trash) == -1)
Cyril Bonté70be45d2010-10-12 00:14:35 +02001860 return 0;
1861
1862 s->txn.status = 303;
1863
1864 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1865 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1866 if (!(s->flags & SN_FINST_MASK))
1867 s->flags |= SN_FINST_R;
1868
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001869 si->conn->xprt_st = STAT_ST_FIN;
Cyril Bonté70be45d2010-10-12 00:14:35 +02001870 return 1;
1871 }
1872 return 1;
1873}
1874
1875
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001876/* This I/O handler runs as an applet embedded in a stream interface. It is
1877 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
Willy Tarreaubc4af052011-02-13 13:25:14 +01001878 * si->applet.st0 becomes non-zero once the transfer is finished. The handler
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001879 * automatically unregisters itself once transfer is complete.
1880 */
Willy Tarreaub24281b2011-02-13 13:16:36 +01001881static void http_stats_io_handler(struct stream_interface *si)
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001882{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001883 struct session *s = si->conn->xprt_ctx;
Willy Tarreau7421efb2012-07-02 15:11:27 +02001884 struct channel *req = si->ob;
1885 struct channel *res = si->ib;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001886
1887 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
1888 goto out;
1889
1890 /* check that the output is not closed */
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001891 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001892 si->applet.st0 = 1;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001893
Willy Tarreaubc4af052011-02-13 13:25:14 +01001894 if (!si->applet.st0) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02001895 if (s->txn.meth == HTTP_METH_POST) {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001896 if (stats_http_redir(si, s->be->uri_auth)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001897 si->applet.st0 = 1;
Willy Tarreau73b013b2012-05-21 16:31:45 +02001898 si_shutw(si);
Cyril Bonté70be45d2010-10-12 00:14:35 +02001899 }
1900 } else {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001901 if (stats_dump_http(si, s->be->uri_auth)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001902 si->applet.st0 = 1;
Willy Tarreau73b013b2012-05-21 16:31:45 +02001903 si_shutw(si);
Cyril Bonté70be45d2010-10-12 00:14:35 +02001904 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001905 }
1906 }
1907
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001908 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST))
Willy Tarreau73b013b2012-05-21 16:31:45 +02001909 si_shutw(si);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001910
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001911 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && si->applet.st0) {
Willy Tarreau73b013b2012-05-21 16:31:45 +02001912 si_shutr(si);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001913 res->flags |= CF_READ_NULL;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001914 }
1915
1916 /* update all other flags and resync with the other side */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001917 si_update(si);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001918
1919 /* we don't want to expire timeouts while we're processing requests */
1920 si->ib->rex = TICK_ETERNITY;
1921 si->ob->wex = TICK_ETERNITY;
1922
1923 out:
1924 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1925 /* check that we have released everything then unregister */
1926 stream_int_unregister_handler(si);
1927 }
1928}
1929
1930
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001931/* This function dumps statistics in HTTP format onto the stream interface's
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02001932 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001933 * properly set. It returns 0 if it had to stop writing data and an I/O is
1934 * needed, 1 if the dump is finished and the session must be closed, or -1
1935 * in case of any error.
Willy Tarreau91861262007-10-17 17:06:05 +02001936 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001937static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001938{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001939 struct session *s = si->conn->xprt_ctx;
Willy Tarreau7421efb2012-07-02 15:11:27 +02001940 struct channel *rep = si->ib;
Willy Tarreau91861262007-10-17 17:06:05 +02001941 struct proxy *px;
Willy Tarreau91861262007-10-17 17:06:05 +02001942 unsigned int up;
1943
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001944 chunk_reset(&trash);
Willy Tarreau91861262007-10-17 17:06:05 +02001945
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001946 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001947 case STAT_ST_INIT:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001948 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02001949 "HTTP/1.0 200 OK\r\n"
1950 "Cache-Control: no-cache\r\n"
1951 "Connection: close\r\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001952 "Content-Type: %s\r\n",
Willy Tarreau295a8372011-03-10 11:25:07 +01001953 (si->applet.ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html");
Willy Tarreau91861262007-10-17 17:06:05 +02001954
Willy Tarreau295a8372011-03-10 11:25:07 +01001955 if (uri->refresh > 0 && !(si->applet.ctx.stats.flags & STAT_NO_REFRESH))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001956 chunk_appendf(&trash, "Refresh: %d\r\n",
Willy Tarreau91861262007-10-17 17:06:05 +02001957 uri->refresh);
1958
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001959 chunk_appendf(&trash, "\r\n");
Willy Tarreau91861262007-10-17 17:06:05 +02001960
1961 s->txn.status = 200;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001962 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau56a560a2009-09-22 19:27:35 +02001963 return 0;
1964
Willy Tarreau91861262007-10-17 17:06:05 +02001965 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1966 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1967 if (!(s->flags & SN_FINST_MASK))
1968 s->flags |= SN_FINST_R;
1969
1970 if (s->txn.meth == HTTP_METH_HEAD) {
1971 /* that's all we return in case of HEAD request */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001972 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001973 return 1;
1974 }
1975
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001976 si->conn->xprt_st = STAT_ST_HEAD; /* let's start producing data */
Willy Tarreau91861262007-10-17 17:06:05 +02001977 /* fall through */
1978
Willy Tarreau295a8372011-03-10 11:25:07 +01001979 case STAT_ST_HEAD:
1980 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001981 /* WARNING! This must fit in the first buffer !!! */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001982 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001983 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
1984 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001985 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001986 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
1987 "<style type=\"text/css\"><!--\n"
1988 "body {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001989 " font-family: arial, helvetica, sans-serif;"
Willy Tarreau91861262007-10-17 17:06:05 +02001990 " font-size: 12px;"
1991 " font-weight: normal;"
1992 " color: black;"
1993 " background: white;"
1994 "}\n"
1995 "th,td {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001996 " font-size: 10px;"
Willy Tarreau91861262007-10-17 17:06:05 +02001997 "}\n"
1998 "h1 {"
Willy Tarreauda6721b2009-07-15 10:07:05 +02001999 " font-size: x-large;"
Willy Tarreau91861262007-10-17 17:06:05 +02002000 " margin-bottom: 0.5em;"
2001 "}\n"
2002 "h2 {"
2003 " font-family: helvetica, arial;"
2004 " font-size: x-large;"
2005 " font-weight: bold;"
2006 " font-style: italic;"
2007 " color: #6020a0;"
2008 " margin-top: 0em;"
2009 " margin-bottom: 0em;"
2010 "}\n"
2011 "h3 {"
2012 " font-family: helvetica, arial;"
2013 " font-size: 16px;"
2014 " font-weight: bold;"
2015 " color: #b00040;"
2016 " background: #e8e8d0;"
2017 " margin-top: 0em;"
2018 " margin-bottom: 0em;"
2019 "}\n"
2020 "li {"
2021 " margin-top: 0.25em;"
2022 " margin-right: 2em;"
2023 "}\n"
2024 ".hr {margin-top: 0.25em;"
2025 " border-color: black;"
2026 " border-bottom-style: solid;"
2027 "}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002028 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002029 ".total {background: #20D0D0;color: #ffff80;}\n"
2030 ".frontend {background: #e8e8d0;}\n"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002031 ".socket {background: #d0d0d0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002032 ".backend {background: #e8e8d0;}\n"
2033 ".active0 {background: #ff9090;}\n"
2034 ".active1 {background: #ffd020;}\n"
2035 ".active2 {background: #ffffa0;}\n"
2036 ".active3 {background: #c0ffc0;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002037 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
2038 ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
2039 ".active6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002040 ".backup0 {background: #ff9090;}\n"
2041 ".backup1 {background: #ff80ff;}\n"
2042 ".backup2 {background: #c060ff;}\n"
2043 ".backup3 {background: #b0d0ff;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002044 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
2045 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
2046 ".backup6 {background: #e0e0e0;}\n"
Cyril Bontécd19e512010-01-31 22:34:03 +01002047 ".maintain {background: #c07820;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +02002048 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002049 "\n"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002050 "a.px:link {color: #ffff40; text-decoration: none;}"
2051 "a.px:visited {color: #ffff40; text-decoration: none;}"
2052 "a.px:hover {color: #ffffff; text-decoration: none;}"
2053 "a.lfsb:link {color: #000000; text-decoration: none;}"
2054 "a.lfsb:visited {color: #000000; text-decoration: none;}"
2055 "a.lfsb:hover {color: #505050; text-decoration: none;}"
2056 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002057 "table.tbl { border-collapse: collapse; border-style: none;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002058 "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"
2059 "table.tbl td.ac { text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002060 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002061 "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +02002062 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002063 "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002064 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002065 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
2066 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
2067 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
Willy Tarreaue0454092010-02-26 12:29:07 +01002068 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002069 "-->\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02002070 "</style></head>\n",
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002071 (uri->flags&ST_SHNODE) ? " on " : "",
2072 (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02002073 );
Willy Tarreau55bb8452007-10-17 18:44:57 +02002074 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002075 print_csv_header(&trash);
Willy Tarreau55bb8452007-10-17 18:44:57 +02002076 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002077 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02002078 return 0;
2079
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002080 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau91861262007-10-17 17:06:05 +02002081 /* fall through */
2082
Willy Tarreau295a8372011-03-10 11:25:07 +01002083 case STAT_ST_INFO:
Willy Tarreau91861262007-10-17 17:06:05 +02002084 up = (now.tv_sec - start_date.tv_sec);
2085
2086 /* WARNING! this has to fit the first packet too.
2087 * We are around 3.5 kB, add adding entries will
2088 * become tricky if we want to support 4kB buffers !
2089 */
Willy Tarreau295a8372011-03-10 11:25:07 +01002090 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002091 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002092 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
2093 PRODUCT_NAME "%s</a></h1>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002094 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002095 "<hr width=\"100%%\" class=\"hr\">\n"
2096 "<h3>&gt; General process information</h3>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002097 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01002098 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002099 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002100 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
2101 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
Willy Tarreau9cd552d2011-09-07 15:26:48 +02002102 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n"
Willy Tarreau45a12512011-09-10 16:56:42 +02002103 "Running tasks: %d/%d; idle = %d %%<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002104 "</td><td align=\"center\" nowrap>\n"
2105 "<table class=\"lgd\"><tr>\n"
2106 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
2107 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
2108 "</tr><tr>\n"
2109 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
2110 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
2111 "</tr><tr>\n"
2112 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
2113 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
2114 "</tr><tr>\n"
2115 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002116 "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
Cyril Bontécd19e512010-01-31 22:34:03 +01002117 "</tr><tr>\n"
2118 "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) &nbsp;</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002119 "</tr></table>\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002120 "Note: UP with load-balancing disabled is reported as \"NOLB\"."
Willy Tarreau91861262007-10-17 17:06:05 +02002121 "</td>"
2122 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2123 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
2124 "",
2125 (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002126 pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
2127 (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
2128 pid, relative_pid, global.nbproc,
Willy Tarreau91861262007-10-17 17:06:05 +02002129 up / 86400, (up % 86400) / 3600,
2130 (up % 3600) / 60, (up % 60),
2131 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
2132 global.rlimit_memmax ? " MB" : "",
2133 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +01002134 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreau9cd552d2011-09-07 15:26:48 +02002135 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
Willy Tarreau45a12512011-09-10 16:56:42 +02002136 run_queue_cur, nb_tasks_cur, idle_pct
Willy Tarreau91861262007-10-17 17:06:05 +02002137 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002138
Willy Tarreau295a8372011-03-10 11:25:07 +01002139 if (si->applet.ctx.stats.flags & STAT_HIDE_DOWN)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002140 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002141 "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
2142 uri->uri_prefix,
2143 "",
Willy Tarreau295a8372011-03-10 11:25:07 +01002144 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002145 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002146 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002147 "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
2148 uri->uri_prefix,
2149 ";up",
Willy Tarreau295a8372011-03-10 11:25:07 +01002150 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02002151
Willy Tarreau55bb8452007-10-17 18:44:57 +02002152 if (uri->refresh > 0) {
Willy Tarreau295a8372011-03-10 11:25:07 +01002153 if (si->applet.ctx.stats.flags & STAT_NO_REFRESH)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002154 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002155 "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
2156 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01002157 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02002158 "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002159 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002160 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002161 "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
2162 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01002163 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02002164 ";norefresh");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002165 }
Willy Tarreau91861262007-10-17 17:06:05 +02002166
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002167 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002168 "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
2169 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01002170 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2171 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02002172
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002173 chunk_appendf(&trash,
Willy Tarreau5031e6a2007-10-18 11:05:48 +02002174 "<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
2175 uri->uri_prefix,
2176 (uri->refresh > 0) ? ";norefresh" : "");
2177
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002178 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002179 "</ul></td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002180 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
Adrian Bridgettafdb6e52012-03-19 23:36:42 +00002181 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002182 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
2183 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
2184 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
2185 "</ul>"
2186 "</td>"
2187 "</tr></table>\n"
2188 ""
2189 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002190
Willy Tarreau295a8372011-03-10 11:25:07 +01002191 if (si->applet.ctx.stats.st_code) {
Cyril Bonté19979e12012-04-04 12:57:21 +02002192 switch (si->applet.ctx.stats.st_code) {
2193 case STAT_STATUS_DONE:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002194 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002195 "<p><div class=active3>"
2196 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2197 "Action processed successfully."
2198 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002199 break;
2200 case STAT_STATUS_NONE:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002201 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002202 "<p><div class=active2>"
2203 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2204 "Nothing has changed."
2205 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002206 break;
2207 case STAT_STATUS_PART:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002208 chunk_appendf(&trash,
Cyril Bontécf8d9ae2012-04-04 12:57:18 +02002209 "<p><div class=active2>"
2210 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2211 "Action partially processed.<br>"
2212 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
2213 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002214 break;
2215 case STAT_STATUS_ERRP:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002216 chunk_appendf(&trash,
Cyril Bontécf8d9ae2012-04-04 12:57:18 +02002217 "<p><div class=active0>"
2218 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2219 "Action not processed because of invalid parameters."
2220 "<ul>"
2221 "<li>The action is maybe unknown.</li>"
2222 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
2223 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
2224 "</ul>"
2225 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002226 break;
2227 case STAT_STATUS_EXCD:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002228 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002229 "<p><div class=active0>"
2230 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2231 "<b>Action not processed : the buffer couldn't store all the data.<br>"
2232 "You should retry with less servers at a time.</b>"
2233 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002234 break;
2235 case STAT_STATUS_DENY:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002236 chunk_appendf(&trash,
Cyril Bonté474be412010-10-12 00:14:36 +02002237 "<p><div class=active0>"
2238 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2239 "<b>Action denied.</b>"
2240 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002241 break;
2242 default:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002243 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002244 "<p><div class=active6>"
2245 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2246 "Unexpected result."
2247 "</div>\n", uri->uri_prefix);
2248 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002249 chunk_appendf(&trash,"<p>\n");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002250 }
2251
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002252 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002253 return 0;
2254 }
Willy Tarreau91861262007-10-17 17:06:05 +02002255
Willy Tarreau295a8372011-03-10 11:25:07 +01002256 si->applet.ctx.stats.px = proxy;
2257 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002258 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau91861262007-10-17 17:06:05 +02002259 /* fall through */
2260
Willy Tarreau295a8372011-03-10 11:25:07 +01002261 case STAT_ST_LIST:
Willy Tarreau91861262007-10-17 17:06:05 +02002262 /* dump proxies */
Willy Tarreau295a8372011-03-10 11:25:07 +01002263 while (si->applet.ctx.stats.px) {
Willy Tarreau9b28e032012-10-12 23:49:43 +02002264 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002265 return 0;
Willy Tarreau295a8372011-03-10 11:25:07 +01002266 px = si->applet.ctx.stats.px;
Willy Tarreau050536d2012-10-04 08:47:34 +02002267 /* skip the disabled proxies, global frontend and non-networked ones */
2268 if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002269 if (stats_dump_proxy(si, px, uri) == 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002270 return 0;
2271
Willy Tarreau295a8372011-03-10 11:25:07 +01002272 si->applet.ctx.stats.px = px->next;
2273 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreau91861262007-10-17 17:06:05 +02002274 }
2275 /* here, we just have reached the last proxy */
2276
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002277 si->conn->xprt_st = STAT_ST_END;
Willy Tarreau91861262007-10-17 17:06:05 +02002278 /* fall through */
2279
Willy Tarreau295a8372011-03-10 11:25:07 +01002280 case STAT_ST_END:
2281 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002282 chunk_appendf(&trash, "</body></html>\n");
2283 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002284 return 0;
2285 }
Willy Tarreau91861262007-10-17 17:06:05 +02002286
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002287 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02002288 /* fall through */
2289
Willy Tarreau295a8372011-03-10 11:25:07 +01002290 case STAT_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02002291 return 1;
2292
2293 default:
2294 /* unknown state ! */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002295 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02002296 return -1;
2297 }
2298}
2299
2300
2301/*
2302 * Dumps statistics for a proxy.
2303 * Returns 0 if it had to stop dumping data because of lack of buffer space,
2304 * ot non-zero if everything completed.
2305 */
Simon Horman9bd2c732011-06-15 15:18:44 +09002306static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02002307{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002308 struct session *s = si->conn->xprt_ctx;
Willy Tarreau7421efb2012-07-02 15:11:27 +02002309 struct channel *rep = si->ib;
Willy Tarreau44267702011-10-28 15:35:33 +02002310 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002311 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02002312
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002313 chunk_reset(&trash);
Willy Tarreau91861262007-10-17 17:06:05 +02002314
Willy Tarreau295a8372011-03-10 11:25:07 +01002315 switch (si->applet.ctx.stats.px_st) {
2316 case STAT_PX_ST_INIT:
Willy Tarreau91861262007-10-17 17:06:05 +02002317 /* we are on a new proxy */
2318
2319 if (uri && uri->scope) {
2320 /* we have a limited scope, we have to check the proxy name */
2321 struct stat_scope *scope;
2322 int len;
2323
2324 len = strlen(px->id);
2325 scope = uri->scope;
2326
2327 while (scope) {
2328 /* match exact proxy name */
2329 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
2330 break;
2331
2332 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02002333 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02002334 break;
2335 scope = scope->next;
2336 }
2337
2338 /* proxy name not found : don't dump anything */
2339 if (scope == NULL)
2340 return 1;
2341 }
2342
Willy Tarreau295a8372011-03-10 11:25:07 +01002343 if ((si->applet.ctx.stats.flags & STAT_BOUND) && (si->applet.ctx.stats.iid != -1) &&
2344 (px->uuid != si->applet.ctx.stats.iid))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002345 return 1;
2346
Willy Tarreau295a8372011-03-10 11:25:07 +01002347 si->applet.ctx.stats.px_st = STAT_PX_ST_TH;
Willy Tarreau91861262007-10-17 17:06:05 +02002348 /* fall through */
2349
Willy Tarreau295a8372011-03-10 11:25:07 +01002350 case STAT_PX_ST_TH:
2351 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
2352 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002353 /* A form to enable/disable this proxy servers */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002354 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002355 "<form action=\"%s\" method=\"post\">",
2356 uri->uri_prefix);
2357 }
2358
Willy Tarreau55bb8452007-10-17 18:44:57 +02002359 /* print a new table */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002360 chunk_appendf(&trash,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002361 "<table class=\"tbl\" width=\"100%%\">\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002362 "<tr class=\"titre\">"
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002363 "<th class=\"pxname\" width=\"10%%\"");
2364
2365 if (uri->flags&ST_SHLGNDS) {
2366 /* cap, mode, id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002367 chunk_appendf(&trash, " title=\"cap: %s, mode: %s, id: %d",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002368 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
2369 px->uuid);
2370
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002371 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002372 }
2373
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002374 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002375 ">%s<a name=\"%s\"></a>"
2376 "<a class=px href=\"#%s\">%s</a>%s</th>"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002377 "<th class=\"%s\" width=\"90%%\">%s</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002378 "</tr>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002379 "</table>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002380 "<table class=\"tbl\" width=\"100%%\">\n"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002381 "<tr class=\"titre\">",
2382 (uri->flags & ST_SHLGNDS)?"<u>":"",
2383 px->id, px->id, px->id,
2384 (uri->flags & ST_SHLGNDS)?"</u>":"",
2385 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
2386
Willy Tarreau295a8372011-03-10 11:25:07 +01002387 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002388 /* Column heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002389 chunk_appendf(&trash, "<th rowspan=2 width=1></th>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002390 }
2391
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002392 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002393 "<th rowspan=2></th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002394 "<th colspan=3>Queue</th>"
2395 "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002396 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002397 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002398 "<th colspan=9>Server</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002399 "</tr>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002400 "<tr class=\"titre\">"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002401 "<th>Cur</th><th>Max</th><th>Limit</th>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002402 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002403 "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002404 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002405 "<th>Resp</th><th>Retr</th><th>Redis</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002406 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002407 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
2408 "<th>Thrtle</th>\n"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002409 "</tr>");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002410
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002411 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002412 return 0;
2413 }
Willy Tarreau91861262007-10-17 17:06:05 +02002414
Willy Tarreau295a8372011-03-10 11:25:07 +01002415 si->applet.ctx.stats.px_st = STAT_PX_ST_FE;
Willy Tarreau91861262007-10-17 17:06:05 +02002416 /* fall through */
2417
Willy Tarreau295a8372011-03-10 11:25:07 +01002418 case STAT_PX_ST_FE:
Willy Tarreau91861262007-10-17 17:06:05 +02002419 /* print the frontend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002420 if ((px->cap & PR_CAP_FE) &&
Willy Tarreau295a8372011-03-10 11:25:07 +01002421 (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_FE)))) {
2422 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002423 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002424 /* name, queue */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002425 "<tr class=\"frontend\">");
2426
Willy Tarreau295a8372011-03-10 11:25:07 +01002427 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002428 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002429 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002430 }
2431
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002432 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002433 "<td class=ac>"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002434 "<a name=\"%s/Frontend\"></a>"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002435 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
2436 "<td colspan=3></td>"
Willy Tarreaub44939a2010-02-26 11:35:39 +01002437 "",
2438 px->id, px->id);
2439
2440 if (px->mode == PR_MODE_HTTP) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002441 chunk_appendf(&trash,
Willy Tarreaub44939a2010-02-26 11:35:39 +01002442 /* sessions rate : current, max, limit */
Willy Tarreaue0454092010-02-26 12:29:07 +01002443 "<td title=\"Cur: %u req/s\"><u>%s</u></td><td title=\"Max: %u req/s\"><u>%s</u></td><td>%s</td>"
Willy Tarreaub44939a2010-02-26 11:35:39 +01002444 "",
2445 read_freq_ctr(&px->fe_req_per_sec),
2446 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002447 px->fe_counters.p.http.rps_max,
2448 U2H1(px->fe_counters.sps_max),
Willy Tarreaub44939a2010-02-26 11:35:39 +01002449 LIM2A2(px->fe_sps_lim, "-"));
2450 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002451 chunk_appendf(&trash,
Willy Tarreaub44939a2010-02-26 11:35:39 +01002452 /* sessions rate : current, max, limit */
2453 "<td>%s</td><td>%s</td><td>%s</td>"
2454 "",
2455 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002456 U2H1(px->fe_counters.sps_max), LIM2A2(px->fe_sps_lim, "-"));
Willy Tarreaub44939a2010-02-26 11:35:39 +01002457 }
2458
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002459 chunk_appendf(&trash,
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002460 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002461 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002462 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002463 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002464 U2H3(px->feconn), U2H4(px->fe_counters.conn_max), U2H5(px->maxconn));
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002465
2466 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2467 if (px->mode == PR_MODE_HTTP) {
2468 int i;
2469
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002470 chunk_appendf(&trash, " title=\"%lld requests:", px->fe_counters.p.http.cum_req);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002471
2472 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002473 chunk_appendf(&trash, " %dxx=%lld,", i, px->fe_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002474
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002475 chunk_appendf(&trash, " other=%lld,", px->fe_counters.p.http.rsp[0]);
2476 chunk_appendf(&trash, " intercepted=%lld\"", px->fe_counters.intercepted_req);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002477 }
2478
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002479 chunk_appendf(&trash,
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002480 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002481 ">%s%s%s</td><td></td>"
Willy Tarreau55058a72012-11-21 08:27:21 +01002482 /* bytes : in */
2483 "<td>%s</td><td"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002484 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002485 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002486 U2H6(px->fe_counters.cum_sess),
Willy Tarreaue0454092010-02-26 12:29:07 +01002487 (px->mode == PR_MODE_HTTP)?"</u>":"",
Willy Tarreau55058a72012-11-21 08:27:21 +01002488 U2H7(px->fe_counters.bytes_in));
2489
2490 /* compression stats (via td title): comp_in, comp_out, comp_byp */
Willy Tarreauf149d8f2012-11-24 14:06:49 +01002491 chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld savings=%d%%\"",
2492 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp,
2493 px->fe_counters.comp_in ?
2494 (int)((px->fe_counters.comp_in - px->fe_counters.comp_out)*100/px->fe_counters.comp_in) : 0);
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002495
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002496 chunk_appendf(&trash,
Willy Tarreau55058a72012-11-21 08:27:21 +01002497 /* bytes: out */
2498 ">%s%s%s</td>"
2499 "",
2500 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"",
2501 U2H0(px->fe_counters.bytes_out),
2502 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":"");
2503
2504 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002505 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002506 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002507 /* errors : request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002508 "<td>%s</td><td></td><td></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002509 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002510 "<td></td><td></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002511 /* server status : reflect frontend status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002512 "<td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002513 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002514 "<td class=ac colspan=8></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +02002515 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002516 U2H0(px->fe_counters.denied_req), U2H1(px->fe_counters.denied_resp),
2517 U2H2(px->fe_counters.failed_req),
Willy Tarreau562515c2011-07-25 08:11:52 +02002518 px->state == PR_STREADY ? "OPEN" :
2519 px->state == PR_STFULL ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002520 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002521 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002522 /* pxid, name, queue cur, queue max, */
2523 "%s,FRONTEND,,,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002524 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002525 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002526 /* bytes : in, out */
2527 "%lld,%lld,"
2528 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002529 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002530 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002531 "%lld,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002532 /* warnings: retries, redispatches */
2533 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002534 /* server status : reflect frontend status */
2535 "%s,"
2536 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002537 ",,,,,,,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002538 /* pid, iid, sid, throttle, lbtot, tracked, type */
2539 "%d,%d,0,,,,%d,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002540 /* rate, rate_lim, rate_max */
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002541 "%u,%u,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002542 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002543 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02002544 px->id,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002545 px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess,
2546 px->fe_counters.bytes_in, px->fe_counters.bytes_out,
2547 px->fe_counters.denied_req, px->fe_counters.denied_resp,
2548 px->fe_counters.failed_req,
Willy Tarreau562515c2011-07-25 08:11:52 +02002549 px->state == PR_STREADY ? "OPEN" :
2550 px->state == PR_STFULL ? "FULL" : "STOP",
Willy Tarreau7f062c42009-03-05 18:43:00 +01002551 relative_pid, px->uuid, STATS_TYPE_FE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002552 read_freq_ctr(&px->fe_sess_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002553 px->fe_sps_lim, px->fe_counters.sps_max);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002554
2555 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2556 if (px->mode == PR_MODE_HTTP) {
2557 int i;
2558
2559 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002560 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002561
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002562 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002563 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002564 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002565 }
2566
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002567 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002568 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002569
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002570 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002571 chunk_appendf(&trash, "%u,%u,%lld,",
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002572 read_freq_ctr(&px->fe_req_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002573 px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req);
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002574
Willy Tarreauae526782010-03-04 20:34:23 +01002575 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002576 chunk_appendf(&trash, ",,");
Willy Tarreauae526782010-03-04 20:34:23 +01002577
Willy Tarreau55058a72012-11-21 08:27:21 +01002578 /* compression: in, out, bypassed */
2579 chunk_appendf(&trash, "%lld,%lld,%lld,",
2580 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
2581
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002582 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002583 chunk_appendf(&trash, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002584 }
Willy Tarreau91861262007-10-17 17:06:05 +02002585
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002586 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02002587 return 0;
2588 }
2589
Willy Tarreau4348fad2012-09-20 16:48:07 +02002590 si->applet.ctx.stats.l = px->conf.listeners.n;
Willy Tarreau295a8372011-03-10 11:25:07 +01002591 si->applet.ctx.stats.px_st = STAT_PX_ST_LI;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002592 /* fall through */
2593
Willy Tarreau295a8372011-03-10 11:25:07 +01002594 case STAT_PX_ST_LI:
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002595 /* stats.l has been initialized above */
Willy Tarreau4348fad2012-09-20 16:48:07 +02002596 for (; si->applet.ctx.stats.l != &px->conf.listeners; si->applet.ctx.stats.l = l->by_fe.n) {
Willy Tarreau9b28e032012-10-12 23:49:43 +02002597 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002598 return 0;
2599
Willy Tarreau4348fad2012-09-20 16:48:07 +02002600 l = LIST_ELEM(si->applet.ctx.stats.l, struct listener *, by_fe);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002601 if (!l->counters)
2602 continue;
2603
Willy Tarreau295a8372011-03-10 11:25:07 +01002604 if (si->applet.ctx.stats.flags & STAT_BOUND) {
2605 if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SO)))
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002606 break;
2607
Willy Tarreau295a8372011-03-10 11:25:07 +01002608 if (si->applet.ctx.stats.sid != -1 && l->luid != si->applet.ctx.stats.sid)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002609 continue;
2610 }
2611
Willy Tarreau295a8372011-03-10 11:25:07 +01002612 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002613 chunk_appendf(&trash, "<tr class=socket>");
Willy Tarreau295a8372011-03-10 11:25:07 +01002614 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002615 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002616 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002617 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002618 chunk_appendf(&trash, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002619
2620 if (uri->flags&ST_SHLGNDS) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02002621 char str[INET6_ADDRSTRLEN];
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002622 int port;
2623
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002624 chunk_appendf(&trash, " title=\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002625
Willy Tarreau631f01c2011-09-05 00:36:48 +02002626 port = get_host_port(&l->addr);
2627 switch (addr_to_str(&l->addr, str, sizeof(str))) {
2628 case AF_INET:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002629 chunk_appendf(&trash, "IPv4: %s:%d, ", str, port);
Willy Tarreau631f01c2011-09-05 00:36:48 +02002630 break;
2631 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002632 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port);
Willy Tarreau631f01c2011-09-05 00:36:48 +02002633 break;
2634 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002635 chunk_appendf(&trash, "unix, ");
Willy Tarreau631f01c2011-09-05 00:36:48 +02002636 break;
2637 case -1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002638 chunk_appendf(&trash, "(%s), ", strerror(errno));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002639 break;
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002640 }
2641
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002642 /* id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002643 chunk_appendf(&trash, "id: %d\"", l->luid);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002644 }
2645
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002646 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002647 /* name, queue */
Willy Tarreaue0454092010-02-26 12:29:07 +01002648 ">%s<a name=\"%s/+%s\"></a>"
2649 "<a class=lfsb href=\"#%s/+%s\">%s</a></td><td colspan=3>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002650 /* sessions rate: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002651 "<td colspan=3>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002652 /* sessions: current, max, limit, total, lbtot */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002653 "<td>%s</td><td>%s</td><td>%s</td>"
2654 "<td>%s</td><td>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002655 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002656 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002657 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002658 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki2ec025d2010-01-04 11:33:32 +01002659 px->id, l->name, px->id, l->name, l->name,
Willy Tarreaue0454092010-02-26 12:29:07 +01002660 (uri->flags & ST_SHLGNDS)?"</u>":"",
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002661 U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn),
2662 U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out));
2663
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002664 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002665 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002666 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002667 /* errors: request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002668 "<td>%s</td><td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002669 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002670 "<td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002671 /* server status: reflect listener status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002672 "<td class=ac>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002673 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002674 "<td class=ac colspan=8></td></tr>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002675 "",
2676 U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp),
2677 U2H2(l->counters->failed_req),
Willy Tarreaua17c2d92011-07-25 08:16:20 +02002678 (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002679 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002680 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002681 /* pxid, name, queue cur, queue max, */
2682 "%s,%s,,,"
2683 /* sessions: current, max, limit, total */
2684 "%d,%d,%d,%lld,"
2685 /* bytes: in, out */
2686 "%lld,%lld,"
2687 /* denied: req, resp */
2688 "%lld,%lld,"
2689 /* errors: request, connect, response */
2690 "%lld,,,"
2691 /* warnings: retries, redispatches */
2692 ",,"
2693 /* server status: reflect listener status */
2694 "%s,"
2695 /* rest of server: nothing */
2696 ",,,,,,,,"
2697 /* pid, iid, sid, throttle, lbtot, tracked, type */
2698 "%d,%d,%d,,,,%d,"
2699 /* rate, rate_lim, rate_max */
2700 ",,,"
2701 /* check_status, check_code, check_duration */
2702 ",,,"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002703 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2704 ",,,,,,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002705 /* failed health analyses */
2706 ","
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002707 /* requests : req_rate, req_rate_max, req_tot, */
2708 ",,,"
Willy Tarreauae526782010-03-04 20:34:23 +01002709 /* errors: cli_aborts, srv_aborts */
2710 ",,"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002711 "\n",
2712 px->id, l->name,
2713 l->nbconn, l->counters->conn_max,
2714 l->maxconn, l->counters->cum_conn,
2715 l->counters->bytes_in, l->counters->bytes_out,
2716 l->counters->denied_req, l->counters->denied_resp,
2717 l->counters->failed_req,
2718 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
2719 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
2720 }
2721
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002722 if (bi_putchk(rep, &trash) == -1)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002723 return 0;
2724 }
2725
Willy Tarreau295a8372011-03-10 11:25:07 +01002726 si->applet.ctx.stats.sv = px->srv; /* may be NULL */
2727 si->applet.ctx.stats.px_st = STAT_PX_ST_SV;
Willy Tarreau91861262007-10-17 17:06:05 +02002728 /* fall through */
2729
Willy Tarreau295a8372011-03-10 11:25:07 +01002730 case STAT_PX_ST_SV:
Willy Tarreau91861262007-10-17 17:06:05 +02002731 /* stats.sv has been initialized above */
Willy Tarreau295a8372011-03-10 11:25:07 +01002732 for (; si->applet.ctx.stats.sv != NULL; si->applet.ctx.stats.sv = sv->next) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002733 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 +02002734
Willy Tarreau9b28e032012-10-12 23:49:43 +02002735 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002736 return 0;
2737
Willy Tarreau295a8372011-03-10 11:25:07 +01002738 sv = si->applet.ctx.stats.sv;
Willy Tarreau91861262007-10-17 17:06:05 +02002739
Willy Tarreau295a8372011-03-10 11:25:07 +01002740 if (si->applet.ctx.stats.flags & STAT_BOUND) {
2741 if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SV)))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002742 break;
2743
Willy Tarreau295a8372011-03-10 11:25:07 +01002744 if (si->applet.ctx.stats.sid != -1 && sv->puid != si->applet.ctx.stats.sid)
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002745 continue;
2746 }
2747
Willy Tarreau44267702011-10-28 15:35:33 +02002748 if (sv->track)
2749 svs = sv->track;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002750 else
2751 svs = sv;
2752
Willy Tarreau91861262007-10-17 17:06:05 +02002753 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002754 if (!(svs->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +01002755 sv_state = 6;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002756 else if (svs->state & SRV_RUNNING) {
2757 if (svs->health == svs->rise + svs->fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02002758 sv_state = 3; /* UP */
2759 else
2760 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01002761
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002762 if (svs->state & SRV_GOINGDOWN)
Willy Tarreau2ea81932007-11-30 12:04:38 +01002763 sv_state += 2;
2764 }
Willy Tarreau91861262007-10-17 17:06:05 +02002765 else
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002766 if (svs->health)
Willy Tarreau91861262007-10-17 17:06:05 +02002767 sv_state = 1; /* going up */
2768 else
2769 sv_state = 0; /* DOWN */
2770
Willy Tarreau295a8372011-03-10 11:25:07 +01002771 if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (si->applet.ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02002772 /* do not report servers which are DOWN */
Willy Tarreau295a8372011-03-10 11:25:07 +01002773 si->applet.ctx.stats.sv = sv->next;
Willy Tarreau91861262007-10-17 17:06:05 +02002774 continue;
2775 }
2776
Willy Tarreau295a8372011-03-10 11:25:07 +01002777 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002778 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
2779 "UP %d/%d &darr;", "UP",
2780 "NOLB %d/%d &darr;", "NOLB",
2781 "<i>no check</i>" };
Cyril Bonté0dae5852010-02-03 00:26:28 +01002782 if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002783 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01002784 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002785 "<tr class=\"maintain\">"
Cyril Bontécd19e512010-01-31 22:34:03 +01002786 );
2787 }
2788 else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002789 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01002790 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002791 "<tr class=\"%s%d\">",
Cyril Bontécd19e512010-01-31 22:34:03 +01002792 (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state);
2793 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002794
Willy Tarreau295a8372011-03-10 11:25:07 +01002795 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002796 chunk_appendf(&trash,
Cyril Bonté474be412010-10-12 00:14:36 +02002797 "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
2798 sv->id);
2799 }
2800
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002801 chunk_appendf(&trash, "<td class=ac");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002802
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002803 if (uri->flags&ST_SHLGNDS) {
2804 char str[INET6_ADDRSTRLEN];
2805
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002806 chunk_appendf(&trash, " title=\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002807
Willy Tarreau631f01c2011-09-05 00:36:48 +02002808 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
David du Colombier6f5ccb12011-03-10 22:26:24 +01002809 case AF_INET:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002810 chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr));
David du Colombier6f5ccb12011-03-10 22:26:24 +01002811 break;
2812 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002813 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002814 break;
2815 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002816 chunk_appendf(&trash, "unix, ");
Willy Tarreau631f01c2011-09-05 00:36:48 +02002817 break;
2818 case -1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002819 chunk_appendf(&trash, "(%s), ", strerror(errno));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002820 break;
2821 default: /* address family not supported */
David du Colombier6f5ccb12011-03-10 22:26:24 +01002822 break;
2823 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002824
2825 /* id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002826 chunk_appendf(&trash, "id: %d", sv->puid);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002827
2828 /* cookie */
2829 if (sv->cookie) {
2830 struct chunk src;
2831
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002832 chunk_appendf(&trash, ", cookie: '");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002833
2834 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002835 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002836
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002837 chunk_appendf(&trash, "'");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002838 }
2839
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002840 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002841 }
2842
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002843 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002844 ">%s<a name=\"%s/%s\"></a>"
2845 "<a class=lfsb href=\"#%s/%s\">%s</a>%s</td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002846 /* queue : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002847 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002848 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002849 "<td>%s</td><td>%s</td><td></td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002850 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002851 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002852 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002853 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002854 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002855 px->id, sv->id, px->id, sv->id, sv->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01002856 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002857 U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"),
2858 U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max),
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002859 U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-"));
2860
2861 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2862 if (px->mode == PR_MODE_HTTP) {
2863 int i;
2864
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002865 chunk_appendf(&trash, " title=\"rsp codes:");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002866
2867 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002868 chunk_appendf(&trash, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002869
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002870 chunk_appendf(&trash, " other=%lld\"", sv->counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002871 }
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002872
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002873 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002874 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002875 ">%s%s%s</td><td>%s</td>",
2876 (px->mode == PR_MODE_HTTP)?"<u>":"",
2877 U2H0(sv->counters.cum_sess),
2878 (px->mode == PR_MODE_HTTP)?"</u>":"",
2879 U2H1(sv->counters.cum_lbconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002880
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002881 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002882 /* bytes : in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002883 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002884 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002885 "<td></td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01002886 /* errors : request, connect */
2887 "<td></td><td>%s</td>"
2888 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002889 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002890 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002891 "<td>%lld</td><td>%lld</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002892 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002893 U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out),
2894 U2H2(sv->counters.failed_secu),
Willy Tarreauae526782010-03-04 20:34:23 +01002895 U2H3(sv->counters.failed_conns),
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002896 sv->counters.cli_aborts,
2897 sv->counters.srv_aborts,
Willy Tarreauae526782010-03-04 20:34:23 +01002898 U2H6(sv->counters.failed_resp),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002899 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002900
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002901 /* status, lest check */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002902 chunk_appendf(&trash, "<td class=ac>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002903
Cyril Bontécd19e512010-01-31 22:34:03 +01002904 if (sv->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002905 chunk_appendf(&trash, "%s ",
Cyril Bontécd19e512010-01-31 22:34:03 +01002906 human_time(now.tv_sec - sv->last_change, 1));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002907 chunk_appendf(&trash, "MAINT");
Cyril Bontécd19e512010-01-31 22:34:03 +01002908 }
Cyril Bonté0dae5852010-02-03 00:26:28 +01002909 else if (svs != sv && svs->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002910 chunk_appendf(&trash, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01002911 human_time(now.tv_sec - svs->last_change, 1));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002912 chunk_appendf(&trash, "MAINT(via)");
Cyril Bonté0dae5852010-02-03 00:26:28 +01002913 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002914 else if (svs->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002915 chunk_appendf(&trash, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01002916 human_time(now.tv_sec - svs->last_change, 1));
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002917
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002918 chunk_appendf(&trash,
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002919 srv_hlt_st[sv_state],
2920 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
2921 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002922 }
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002923
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002924 if (sv->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002925 chunk_appendf(&trash, "</td><td class=ac title=\"%s",
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002926 get_check_status_description(sv->check.status));
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002927
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002928 if (*sv->check.desc) {
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002929 struct chunk src;
2930
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002931 chunk_appendf(&trash, ": ");
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002932
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002933 chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002934 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002935 }
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002936
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002937 chunk_appendf(&trash, "\"><u> %s%s",
Willy Tarreau0eb2bed2012-11-24 00:20:24 +01002938 (sv->state & SRV_CHK_RUNNING) ? "* " : "",
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002939 get_check_status_info(sv->check.status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002940
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002941 if (sv->check.status >= HCHK_STATUS_L57DATA)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002942 chunk_appendf(&trash, "/%d", sv->check.code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002943
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002944 if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002945 chunk_appendf(&trash, " in %lums</u>", sv->check.duration);
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002946 } else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002947 chunk_appendf(&trash, "</td><td>");
Willy Tarreau91861262007-10-17 17:06:05 +02002948
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002949 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002950 /* weight */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002951 "</td><td class=ac>%d</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002952 /* act, bck */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002953 "<td class=ac>%s</td><td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002954 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01002955 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +02002956 (sv->state & SRV_BACKUP) ? "-" : "Y",
2957 (sv->state & SRV_BACKUP) ? "Y" : "-");
2958
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002959 /* check failures: unique, fatal, down time */
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002960 if (sv->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002961 chunk_appendf(&trash, "<td title=\"Failed Health Checks%s\"><u>%lld",
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002962 svs->observe?"/Health Analyses":"", svs->counters.failed_checks);
2963
2964 if (svs->observe)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002965 chunk_appendf(&trash, "/%lld", svs->counters.failed_hana);
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002966
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002967 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002968 "</u></td>"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002969 "<td>%lld</td><td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002970 "",
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002971 svs->counters.down_trans, human_time(srv_downtime(sv), 1));
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002972 } else if (sv != svs)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002973 chunk_appendf(&trash,
Krzysztof Piotr Oledzki88a14af2010-01-05 18:33:01 +01002974 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>",
2975 svs->proxy->id, svs->id, svs->proxy->id, svs->id);
Willy Tarreau55bb8452007-10-17 18:44:57 +02002976 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002977 chunk_appendf(&trash,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002978 "<td colspan=3></td>");
2979
2980 /* throttle */
2981 if ((sv->state & SRV_WARMINGUP) &&
2982 now.tv_sec < sv->last_change + sv->slowstart &&
2983 now.tv_sec >= sv->last_change) {
2984 unsigned int ratio;
2985 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002986 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002987 "<td class=ac>%d %%</td></tr>\n", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002988 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002989 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002990 "<td class=ac>-</td></tr>\n");
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002991 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02002992 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002993 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
2994 "UP %d/%d,", "UP,",
2995 "NOLB %d/%d,", "NOLB,",
2996 "no check," };
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002997 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002998 /* pxid, name */
2999 "%s,%s,"
3000 /* queue : current, max */
3001 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003002 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003003 "%d,%d,%s,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003004 /* bytes : in, out */
3005 "%lld,%lld,"
3006 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003007 ",%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003008 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003009 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003010 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003011 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003012 "",
3013 px->id, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02003014 sv->nbpend, sv->counters.nbpend_max,
3015 sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02003016 sv->counters.bytes_in, sv->counters.bytes_out,
3017 sv->counters.failed_secu,
3018 sv->counters.failed_conns, sv->counters.failed_resp,
3019 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003020
Willy Tarreau55bb8452007-10-17 18:44:57 +02003021 /* status */
Cyril Bontécd19e512010-01-31 22:34:03 +01003022 if (sv->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003023 chunk_appendf(&trash, "MAINT,");
Cyril Bonté0dae5852010-02-03 00:26:28 +01003024 }
3025 else if (svs != sv && svs->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003026 chunk_appendf(&trash, "MAINT(via),");
Cyril Bonté0dae5852010-02-03 00:26:28 +01003027 }
3028 else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003029 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01003030 srv_hlt_st[sv_state],
3031 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
3032 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
3033 }
Willy Tarreau91861262007-10-17 17:06:05 +02003034
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003035 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003036 /* weight, active, backup */
3037 "%d,%d,%d,"
3038 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01003039 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003040 (sv->state & SRV_BACKUP) ? 0 : 1,
3041 (sv->state & SRV_BACKUP) ? 1 : 0);
3042
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003043 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +02003044 if (sv->state & SRV_CHECKED)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003045 chunk_appendf(&trash,
Willy Tarreau3b88d442009-04-11 20:44:08 +02003046 "%lld,%lld,%d,%d,",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02003047 sv->counters.failed_checks, sv->counters.down_trans,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003048 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +02003049 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003050 chunk_appendf(&trash,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02003051 ",,,,");
3052
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003053 /* queue limit, pid, iid, sid, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003054 chunk_appendf(&trash,
Willy Tarreaudcd47712007-11-04 23:35:08 +01003055 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003056 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +01003057 LIM2A0(sv->maxqueue, ""),
3058 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003059
3060 /* throttle */
3061 if ((sv->state & SRV_WARMINGUP) &&
3062 now.tv_sec < sv->last_change + sv->slowstart &&
3063 now.tv_sec >= sv->last_change) {
3064 unsigned int ratio;
3065 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003066 chunk_appendf(&trash, "%d", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003067 }
3068
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003069 /* sessions: lbtot */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003070 chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003071
3072 /* tracked */
Willy Tarreau44267702011-10-28 15:35:33 +02003073 if (sv->track)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003074 chunk_appendf(&trash, "%s/%s,",
Willy Tarreau44267702011-10-28 15:35:33 +02003075 sv->track->proxy->id, sv->track->id);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003076 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003077 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003078
Willy Tarreau7f062c42009-03-05 18:43:00 +01003079 /* type */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003080 chunk_appendf(&trash, "%d,", STATS_TYPE_SV);
Willy Tarreau7f062c42009-03-05 18:43:00 +01003081
3082 /* rate */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003083 chunk_appendf(&trash, "%u,,%u,",
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003084 read_freq_ctr(&sv->sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02003085 sv->counters.sps_max);
Willy Tarreau7f062c42009-03-05 18:43:00 +01003086
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003087 if (sv->state & SRV_CHECKED) {
3088 /* check_status */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003089 chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003090
3091 /* check_code */
Willy Tarreau5b3a2022012-09-28 15:01:02 +02003092 if (sv->check.status >= HCHK_STATUS_L57DATA)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003093 chunk_appendf(&trash, "%u,", sv->check.code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003094 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003095 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003096
3097 /* check_duration */
Willy Tarreau5b3a2022012-09-28 15:01:02 +02003098 if (sv->check.status >= HCHK_STATUS_CHECKED)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003099 chunk_appendf(&trash, "%lu,", sv->check.duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003100 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003101 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003102
3103 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003104 chunk_appendf(&trash, ",,,");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003105 }
3106
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003107 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3108 if (px->mode == PR_MODE_HTTP) {
3109 int i;
3110
3111 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003112 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003113
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003114 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003115 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003116 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003117 }
3118
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003119 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003120 chunk_appendf(&trash, "%lld,", sv->counters.failed_hana);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003121
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003122 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003123 chunk_appendf(&trash, ",,,");
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003124
Willy Tarreauae526782010-03-04 20:34:23 +01003125 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003126 chunk_appendf(&trash, "%lld,%lld,",
Willy Tarreauae526782010-03-04 20:34:23 +01003127 sv->counters.cli_aborts, sv->counters.srv_aborts);
3128
Willy Tarreau7f062c42009-03-05 18:43:00 +01003129 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003130 chunk_appendf(&trash, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003131 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003132 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02003133 return 0;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003134 } /* for sv */
Willy Tarreau91861262007-10-17 17:06:05 +02003135
Willy Tarreau295a8372011-03-10 11:25:07 +01003136 si->applet.ctx.stats.px_st = STAT_PX_ST_BE;
Willy Tarreau91861262007-10-17 17:06:05 +02003137 /* fall through */
3138
Willy Tarreau295a8372011-03-10 11:25:07 +01003139 case STAT_PX_ST_BE:
Willy Tarreau91861262007-10-17 17:06:05 +02003140 /* print the backend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01003141 if ((px->cap & PR_CAP_BE) &&
Willy Tarreau295a8372011-03-10 11:25:07 +01003142 (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_BE)))) {
3143 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003144 chunk_appendf(&trash, "<tr class=\"backend\">");
Willy Tarreau295a8372011-03-10 11:25:07 +01003145 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02003146 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003147 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02003148 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003149 chunk_appendf(&trash, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003150
3151 if (uri->flags&ST_SHLGNDS) {
3152 /* balancing */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003153 chunk_appendf(&trash, " title=\"balancing: %s",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003154 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003155
3156 /* cookie */
3157 if (px->cookie_name) {
3158 struct chunk src;
3159
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003160 chunk_appendf(&trash, ", cookie: '");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003161
3162 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003163 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003164
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003165 chunk_appendf(&trash, "'");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003166 }
3167
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003168 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003169
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003170 }
3171
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003172 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02003173 /* name */
Willy Tarreaue0454092010-02-26 12:29:07 +01003174 ">%s<a name=\"%s/Backend\"></a>"
3175 "<a class=lfsb href=\"#%s/Backend\">Backend</a>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02003176 /* queue : current, max */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003177 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02003178 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003179 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02003180 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01003181 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02003182 px->id, px->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01003183 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003184 U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->be_counters.nbpend_max),
3185 U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->be_counters.sps_max));
Willy Tarreaua3e49422009-05-10 19:19:41 +02003186
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003187 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003188 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003189 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003190 "<td"
3191 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003192 U2H2(px->beconn), U2H3(px->be_counters.conn_max), U2H4(px->fullconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003193
3194 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
3195 if (px->mode == PR_MODE_HTTP) {
3196 int i;
3197
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003198 chunk_appendf(&trash, " title=\"rsp codes:");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003199
3200 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003201 chunk_appendf(&trash, " %dxx=%lld", i, px->be_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003202
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003203 chunk_appendf(&trash, " other=%lld\"", px->be_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003204 }
3205
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003206 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003207 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01003208 ">%s%s%s</td><td>%s</td>"
Willy Tarreau55058a72012-11-21 08:27:21 +01003209 /* bytes: in */
3210 "<td>%s</td><td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003211 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01003212 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003213 U2H6(px->be_counters.cum_conn),
Willy Tarreaue0454092010-02-26 12:29:07 +01003214 (px->mode == PR_MODE_HTTP)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003215 U2H7(px->be_counters.cum_lbconn),
Willy Tarreau55058a72012-11-21 08:27:21 +01003216 U2H8(px->be_counters.bytes_in));
3217
3218 /* compression stats (via td title): comp_in, comp_out, comp_byp */
Willy Tarreauf149d8f2012-11-24 14:06:49 +01003219 chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld savings=%d%%\"",
3220 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp,
3221 px->be_counters.comp_in ?
3222 (int)((px->be_counters.comp_in - px->be_counters.comp_out)*100/px->be_counters.comp_in) : 0);
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003223
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003224 chunk_appendf(&trash,
Willy Tarreau55058a72012-11-21 08:27:21 +01003225 /* bytes: out */
3226 ">%s%s%s</td>"
3227 "",
3228 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"",
3229 U2H0(px->be_counters.bytes_out),
3230 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":"");
3231
3232 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02003233 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003234 "<td>%s</td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01003235 /* errors : request, connect */
3236 "<td></td><td>%s</td>"
3237 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01003238 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003239 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003240 "<td>%lld</td><td>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003241 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +02003242 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003243 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +02003244 * active and backups. */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003245 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
3246 "<td class=ac>%d</td><td class=ac>%d</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003247 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003248 U2H0(px->be_counters.denied_req), U2H1(px->be_counters.denied_resp),
3249 U2H2(px->be_counters.failed_conns),
3250 px->be_counters.cli_aborts,
3251 px->be_counters.srv_aborts,
3252 U2H5(px->be_counters.failed_resp),
3253 px->be_counters.retries, px->be_counters.redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003254 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +01003255 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
3256 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5542af62007-12-03 02:04:00 +01003257 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01003258 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003259
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003260 chunk_appendf(&trash,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003261 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003262 "<td class=ac>&nbsp;</td><td>%d</td>"
3263 "<td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003264 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003265 "</tr>",
3266 px->down_trans,
3267 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003268 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003269 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003270 /* pxid, name */
3271 "%s,BACKEND,"
3272 /* queue : current, max */
3273 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003274 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003275 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003276 /* bytes : in, out */
3277 "%lld,%lld,"
3278 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003279 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003280 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003281 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003282 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003283 "%lld,%lld,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003284 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +02003285 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003286 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +02003287 * active and backups. */
3288 "%s,"
3289 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003290 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02003291 ",%d,%d,%d,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003292 /* pid, iid, sid, throttle, lbtot, tracked, type */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003293 "%d,%d,0,,%lld,,%d,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003294 /* rate, rate_lim, rate_max, */
3295 "%u,,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003296 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003297 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02003298 px->id,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003299 px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max,
3300 px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn,
3301 px->be_counters.bytes_in, px->be_counters.bytes_out,
3302 px->be_counters.denied_req, px->be_counters.denied_resp,
3303 px->be_counters.failed_conns, px->be_counters.failed_resp,
3304 px->be_counters.retries, px->be_counters.redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +01003305 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5542af62007-12-03 02:04:00 +01003306 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01003307 px->srv_act, px->srv_bck,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003308 px->down_trans, (int)(now.tv_sec - px->last_change),
Willy Tarreau20697042007-11-15 23:26:18 +01003309 px->srv?be_downtime(px):0,
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003310 relative_pid, px->uuid,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003311 px->be_counters.cum_lbconn, STATS_TYPE_BE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003312 read_freq_ctr(&px->be_sess_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003313 px->be_counters.sps_max);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003314
3315 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3316 if (px->mode == PR_MODE_HTTP) {
3317 int i;
3318
3319 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003320 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003321
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003322 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003323 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003324 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003325 }
3326
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003327 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003328 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003329
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003330 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003331 chunk_appendf(&trash, ",,,");
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003332
Willy Tarreauae526782010-03-04 20:34:23 +01003333 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003334 chunk_appendf(&trash, "%lld,%lld,",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003335 px->be_counters.cli_aborts, px->be_counters.srv_aborts);
Willy Tarreauae526782010-03-04 20:34:23 +01003336
Willy Tarreau55058a72012-11-21 08:27:21 +01003337 /* compression: in, out, bypassed */
3338 chunk_appendf(&trash, "%lld,%lld,%lld,",
3339 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
3340
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003341 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003342 chunk_appendf(&trash, "\n");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003343
Willy Tarreau55bb8452007-10-17 18:44:57 +02003344 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003345 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02003346 return 0;
3347 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003348
Willy Tarreau295a8372011-03-10 11:25:07 +01003349 si->applet.ctx.stats.px_st = STAT_PX_ST_END;
Willy Tarreau91861262007-10-17 17:06:05 +02003350 /* fall through */
3351
Willy Tarreau295a8372011-03-10 11:25:07 +01003352 case STAT_PX_ST_END:
3353 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003354 chunk_appendf(&trash, "</table>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02003355
Willy Tarreau295a8372011-03-10 11:25:07 +01003356 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02003357 /* close the form used to enable/disable this proxy servers */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003358 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02003359 "Choose the action to perform on the checked servers : "
3360 "<select name=action>"
3361 "<option value=\"\"></option>"
3362 "<option value=\"disable\">Disable</option>"
3363 "<option value=\"enable\">Enable</option>"
Willy Tarreaud7282242012-06-04 00:22:44 +02003364 "<option value=\"stop\">Soft Stop</option>"
3365 "<option value=\"start\">Soft Start</option>"
Willy Tarreau4f8a83c2012-06-04 00:26:23 +02003366 "<option value=\"shutdown\">Kill Sessions</option>"
Cyril Bonté70be45d2010-10-12 00:14:35 +02003367 "</select>"
Cyril Bontéaa0a45d2012-04-04 12:57:20 +02003368 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
Cyril Bonté70be45d2010-10-12 00:14:35 +02003369 "&nbsp;<input type=\"submit\" value=\"Apply\">"
3370 "</form>",
Cyril Bontéaa0a45d2012-04-04 12:57:20 +02003371 px->uuid);
Cyril Bonté70be45d2010-10-12 00:14:35 +02003372 }
3373
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003374 chunk_appendf(&trash, "<p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +02003375
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003376 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02003377 return 0;
3378 }
Willy Tarreau91861262007-10-17 17:06:05 +02003379
Willy Tarreau295a8372011-03-10 11:25:07 +01003380 si->applet.ctx.stats.px_st = STAT_PX_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02003381 /* fall through */
3382
Willy Tarreau295a8372011-03-10 11:25:07 +01003383 case STAT_PX_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02003384 return 1;
3385
3386 default:
3387 /* unknown state, we should put an abort() here ! */
3388 return 1;
3389 }
3390}
3391
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003392/* This function dumps a complete session state onto the stream interface's
3393 * read buffer. The xprt_ctx must have been zeroed first, and the flags
3394 * properly set. The session has to be set in xprt_ctx.sess.target. It returns
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003395 * 0 if the output buffer is full and it needs to be called again, otherwise
3396 * non-zero. It is designed to be called from stats_dump_sess_to_buffer() below.
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003397 */
Simon Horman9bd2c732011-06-15 15:18:44 +09003398static int stats_dump_full_sess_to_buffer(struct stream_interface *si)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003399{
3400 struct tm tm;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003401 struct session *sess;
3402 extern const char *monthname[12];
3403 char pn[INET6_ADDRSTRLEN];
3404
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003405 chunk_reset(&trash);
Willy Tarreau295a8372011-03-10 11:25:07 +01003406 sess = si->applet.ctx.sess.target;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003407
Willy Tarreau295a8372011-03-10 11:25:07 +01003408 if (si->applet.ctx.sess.section > 0 && si->applet.ctx.sess.uid != sess->uniq_id) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003409 /* session changed, no need to go any further */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003410 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
3411 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003412 return 0;
Willy Tarreau295a8372011-03-10 11:25:07 +01003413 si->applet.ctx.sess.target = NULL;
3414 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003415 return 1;
3416 }
3417
Willy Tarreau295a8372011-03-10 11:25:07 +01003418 switch (si->applet.ctx.sess.section) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003419 case 0: /* main status of the session */
Willy Tarreau295a8372011-03-10 11:25:07 +01003420 si->applet.ctx.sess.uid = sess->uniq_id;
3421 si->applet.ctx.sess.section = 1;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003422 /* fall through */
3423
3424 case 1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003425 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003426 "%p: id=%u, proto=%s",
3427 sess,
3428 sess->uniq_id,
3429 sess->listener->proto->name);
3430
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003431 switch (addr_to_str(&sess->si[0].conn->addr.from, pn, sizeof(pn))) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003432 case AF_INET:
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003433 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003434 chunk_appendf(&trash, " source=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003435 pn, get_host_port(&sess->si[0].conn->addr.from));
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003436 break;
3437 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003438 chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid);
Emeric Brun837ca522010-10-22 16:19:01 +02003439 break;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003440 default:
3441 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003442 chunk_appendf(&trash, "\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003443 break;
3444 }
3445
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003446 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003447 " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n",
Willy Tarreauee28de02010-06-01 09:51:00 +02003448 sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003449
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003450 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003451 " frontend=%s (id=%u mode=%s), listener=%s (id=%u)",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003452 sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp",
3453 sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?",
3454 sess->listener ? sess->listener->luid : 0);
3455
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003456 conn_get_to_addr(sess->si[0].conn);
3457 switch (addr_to_str(&sess->si[0].conn->addr.to, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003458 case AF_INET:
3459 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003460 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003461 pn, get_host_port(&sess->si[0].conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07003462 break;
3463 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003464 chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid);
Daniel Schultze90690c72012-03-23 10:53:36 -07003465 break;
3466 default:
3467 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003468 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003469 break;
3470 }
3471
Willy Tarreau50943332011-09-02 17:33:05 +02003472 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003473 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003474 " backend=%s (id=%u mode=%s)",
Willy Tarreau50943332011-09-02 17:33:05 +02003475 sess->be->id,
Daniel Schultze90690c72012-03-23 10:53:36 -07003476 sess->be->uuid, sess->be->mode ? "http" : "tcp");
3477 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003478 chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)");
Daniel Schultze90690c72012-03-23 10:53:36 -07003479
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003480 conn_get_from_addr(sess->si[1].conn);
3481 switch (addr_to_str(&sess->si[1].conn->addr.from, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003482 case AF_INET:
3483 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003484 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003485 pn, get_host_port(&sess->si[1].conn->addr.from));
Daniel Schultze90690c72012-03-23 10:53:36 -07003486 break;
3487 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003488 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003489 break;
3490 default:
3491 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003492 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003493 break;
3494 }
3495
3496 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003497 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003498 " server=%s (id=%u)",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003499 objt_server(sess->target) ? objt_server(sess->target)->id : "<none>",
3500 objt_server(sess->target) ? objt_server(sess->target)->puid : 0);
Willy Tarreau50943332011-09-02 17:33:05 +02003501 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003502 chunk_appendf(&trash, " server=<NONE> (id=-1)");
Daniel Schultze90690c72012-03-23 10:53:36 -07003503
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003504 conn_get_to_addr(sess->si[1].conn);
3505 switch (addr_to_str(&sess->si[1].conn->addr.to, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003506 case AF_INET:
3507 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003508 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003509 pn, get_host_port(&sess->si[1].conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07003510 break;
3511 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003512 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003513 break;
3514 default:
3515 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003516 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003517 break;
3518 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003519
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003520 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003521 " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s)\n",
3522 sess->task,
3523 sess->task->state,
3524 sess->task->nice, sess->task->calls,
3525 sess->task->expire ?
3526 tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" :
3527 human_time(TICKS_TO_MS(sess->task->expire - now_ms),
3528 TICKS_TO_MS(1000)) : "<NEVER>",
3529 task_in_rq(sess->task) ? ", running" : "");
3530
3531 get_localtime(sess->logs.accept_date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003532 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003533 " task created [%02d/%s/%04d:%02d:%02d:%02d.%06d] (age=%s)\n",
3534 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
3535 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec),
3536 human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1));
3537
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003538 chunk_appendf(&trash,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003539 " si[0]=%p (state=%d flags=0x%02x conn=%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003540 &sess->si[0],
3541 sess->si[0].state,
3542 sess->si[0].flags,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003543 sess->si[0].conn,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003544 sess->si[0].exp ?
3545 tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" :
3546 human_time(TICKS_TO_MS(sess->si[0].exp - now_ms),
3547 TICKS_TO_MS(1000)) : "<NEVER>",
3548 sess->si[0].err_type);
3549
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003550 chunk_appendf(&trash,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003551 " si[1]=%p (state=%d flags=0x%02x conn=%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003552 &sess->si[1],
3553 sess->si[1].state,
3554 sess->si[1].flags,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003555 sess->si[1].conn,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003556 sess->si[1].exp ?
3557 tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" :
3558 human_time(TICKS_TO_MS(sess->si[1].exp - now_ms),
3559 TICKS_TO_MS(1000)) : "<NEVER>",
3560 sess->si[1].err_type);
3561
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003562 chunk_appendf(&trash,
Willy Tarreau1feca012012-11-19 18:15:19 +01003563 " lconn=%p (ctrl=%p(%s) xprt=%p(%s) data=%p(%s) target=%d flags=0x%08x fd=%d fd_spec=%02x)\n",
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003564 sess->si[0].conn,
3565 sess->si[0].conn->ctrl,
3566 sess->si[0].conn->ctrl ? sess->si[0].conn->ctrl->name : "NONE",
3567 sess->si[0].conn->xprt,
3568 (sess->si[0].conn->xprt == NULL) ? "NONE" :
3569 (sess->si[0].conn->xprt == &raw_sock) ? "RAW" :
3570#ifdef USE_OPENSSL
3571 (sess->si[0].conn->xprt == &ssl_sock) ? "SSL" :
3572#endif
3573 "????",
3574 sess->si[0].conn->data,
3575 (sess->si[0].conn->data == NULL) ? "NONE" :
3576 (sess->si[0].conn->data == &sess_conn_cb) ? "SESS" :
3577 (sess->si[0].conn->data == &si_conn_cb) ? "STRM" :
3578 (sess->si[0].conn->data == &check_conn_cb) ? "CHCK" : "????",
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003579 sess->si[0].conn->target ? *sess->si[0].conn->target : 0,
Willy Tarreau1feca012012-11-19 18:15:19 +01003580 sess->si[0].conn->flags,
3581 sess->si[0].conn->t.sock.fd,
3582 sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_e : 0);
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003583
3584 chunk_appendf(&trash,
Willy Tarreau1feca012012-11-19 18:15:19 +01003585 " rconn=%p (ctrl=%p(%s) xprt=%p(%s) data=%p(%s) target=%d flags=0x%08x fd=%d fd_spec=%02x)\n",
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003586 sess->si[1].conn,
3587 sess->si[1].conn->ctrl,
3588 sess->si[1].conn->ctrl ? sess->si[1].conn->ctrl->name : "NONE",
3589 sess->si[1].conn->xprt,
3590 (sess->si[1].conn->xprt == NULL) ? "NONE" :
3591 (sess->si[1].conn->xprt == &raw_sock) ? "RAW" :
3592#ifdef USE_OPENSSL
3593 (sess->si[1].conn->xprt == &ssl_sock) ? "SSL" :
3594#endif
3595 "UNKNOWN",
3596 sess->si[1].conn->data,
3597 (sess->si[1].conn->data == NULL) ? "NONE" :
3598 (sess->si[1].conn->data == &sess_conn_cb) ? "SESS" :
3599 (sess->si[1].conn->data == &si_conn_cb) ? "STRM" :
3600 (sess->si[1].conn->data == &check_conn_cb) ? "CHCK" : "????",
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003601 sess->si[1].conn->target ? *sess->si[1].conn->target : 0,
Willy Tarreau1feca012012-11-19 18:15:19 +01003602 sess->si[1].conn->flags,
3603 sess->si[1].conn->t.sock.fd,
3604 sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_e : 0);
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003605
3606 chunk_appendf(&trash,
Willy Tarreaue6d97022012-11-23 11:19:33 +01003607 " txn=%p (flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003608 &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status,
Willy Tarreaue6d97022012-11-23 11:19:33 +01003609 http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state));
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003610
3611
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003612 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003613 " req=%p (f=0x%06x an=0x%x i=%d o=%d pipe=%d fwd=%d)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003614 " an_exp=%s",
3615 sess->req,
3616 sess->req->flags, sess->req->analysers,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003617 sess->req->buf->i, sess->req->buf->o,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003618 sess->req->pipe ? sess->req->pipe->data : 0,
3619 sess->req->to_forward,
3620 sess->req->analyse_exp ?
3621 human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms),
3622 TICKS_TO_MS(1000)) : "<NEVER>");
3623
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003624 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003625 " rex=%s",
3626 sess->req->rex ?
3627 human_time(TICKS_TO_MS(sess->req->rex - now_ms),
3628 TICKS_TO_MS(1000)) : "<NEVER>");
3629
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003630 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003631 " wex=%s\n"
Willy Tarreaua458b672012-03-05 11:17:50 +01003632 " data=%p p=%d next=%d total=%lld\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003633 sess->req->wex ?
3634 human_time(TICKS_TO_MS(sess->req->wex - now_ms),
3635 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau9b28e032012-10-12 23:49:43 +02003636 sess->req->buf->data,
3637 (int)(sess->req->buf->p - sess->req->buf->data),
Willy Tarreaua458b672012-03-05 11:17:50 +01003638 sess->txn.req.next,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003639 sess->req->total);
3640
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003641 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003642 " res=%p (f=0x%06x an=0x%x i=%d o=%d pipe=%d fwd=%d)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003643 " an_exp=%s",
3644 sess->rep,
3645 sess->rep->flags, sess->rep->analysers,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003646 sess->rep->buf->i, sess->rep->buf->o,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003647 sess->rep->pipe ? sess->rep->pipe->data : 0,
3648 sess->rep->to_forward,
3649 sess->rep->analyse_exp ?
3650 human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms),
3651 TICKS_TO_MS(1000)) : "<NEVER>");
3652
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003653 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003654 " rex=%s",
3655 sess->rep->rex ?
3656 human_time(TICKS_TO_MS(sess->rep->rex - now_ms),
3657 TICKS_TO_MS(1000)) : "<NEVER>");
3658
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003659 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003660 " wex=%s\n"
Willy Tarreaua458b672012-03-05 11:17:50 +01003661 " data=%p p=%d next=%d total=%lld\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003662 sess->rep->wex ?
3663 human_time(TICKS_TO_MS(sess->rep->wex - now_ms),
3664 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau9b28e032012-10-12 23:49:43 +02003665 sess->rep->buf->data,
3666 (int)(sess->rep->buf->p - sess->rep->buf->data),
Willy Tarreaua458b672012-03-05 11:17:50 +01003667 sess->txn.rsp.next,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003668 sess->rep->total);
3669
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003670 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003671 return 0;
3672
3673 /* use other states to dump the contents */
3674 }
3675 /* end of dump */
Willy Tarreau295a8372011-03-10 11:25:07 +01003676 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003677 return 1;
3678}
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003679
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003680/* This function dumps all sessions' states onto the stream interface's
3681 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003682 * properly set. It returns 0 if the output buffer is full and it needs
3683 * to be called again, otherwise non-zero. It is designed to be called
3684 * from stats_dump_sess_to_buffer() below.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003685 */
Simon Horman9bd2c732011-06-15 15:18:44 +09003686static int stats_dump_sess_to_buffer(struct stream_interface *si)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003687{
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02003688 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003689 /* If we're forced to shut down, we might have to remove our
3690 * reference to the last session being dumped.
3691 */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003692 if (si->conn->xprt_st == STAT_ST_LIST) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003693 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) {
3694 LIST_DEL(&si->applet.ctx.sess.bref.users);
3695 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003696 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003697 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003698 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003699 }
3700
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003701 chunk_reset(&trash);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003702
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003703 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003704 case STAT_ST_INIT:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003705 /* the function had not been called yet, let's prepare the
3706 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003707 * pointer to the first in the global list. When a target
3708 * session is being destroyed, it is responsible for updating
3709 * this pointer. We know we have reached the end when this
3710 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003711 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003712 LIST_INIT(&si->applet.ctx.sess.bref.users);
3713 si->applet.ctx.sess.bref.ref = sessions.n;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003714 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003715 /* fall through */
3716
Willy Tarreau295a8372011-03-10 11:25:07 +01003717 case STAT_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003718 /* first, let's detach the back-ref from a possible previous session */
Willy Tarreau295a8372011-03-10 11:25:07 +01003719 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) {
3720 LIST_DEL(&si->applet.ctx.sess.bref.users);
3721 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003722 }
3723
3724 /* and start from where we stopped */
Willy Tarreau295a8372011-03-10 11:25:07 +01003725 while (si->applet.ctx.sess.bref.ref != &sessions) {
Cyril Bontéacd7d632010-11-01 19:26:02 +01003726 char pn[INET6_ADDRSTRLEN];
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003727 struct session *curr_sess;
3728
Willy Tarreau295a8372011-03-10 11:25:07 +01003729 curr_sess = LIST_ELEM(si->applet.ctx.sess.bref.ref, struct session *, list);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003730
Willy Tarreau295a8372011-03-10 11:25:07 +01003731 if (si->applet.ctx.sess.target) {
3732 if (si->applet.ctx.sess.target != curr_sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003733 goto next_sess;
3734
Willy Tarreau295a8372011-03-10 11:25:07 +01003735 LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003736 /* call the proper dump() function and return if we're missing space */
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003737 if (!stats_dump_full_sess_to_buffer(si))
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003738 return 0;
3739
3740 /* session dump complete */
Willy Tarreau295a8372011-03-10 11:25:07 +01003741 LIST_DEL(&si->applet.ctx.sess.bref.users);
3742 LIST_INIT(&si->applet.ctx.sess.bref.users);
3743 si->applet.ctx.sess.target = NULL;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003744 break;
3745 }
3746
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003747 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003748 "%p: proto=%s",
3749 curr_sess,
3750 curr_sess->listener->proto->name);
3751
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003752
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003753 switch (addr_to_str(&curr_sess->si[0].conn->addr.from, pn, sizeof(pn))) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02003754 case AF_INET:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003755 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003756 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003757 " src=%s:%d fe=%s be=%s srv=%s",
3758 pn,
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003759 get_host_port(&curr_sess->si[0].conn->addr.from),
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003760 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02003761 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003762 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003763 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003764 break;
3765 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003766 chunk_appendf(&trash,
Emeric Brun837ca522010-10-22 16:19:01 +02003767 " src=unix:%d fe=%s be=%s srv=%s",
3768 curr_sess->listener->luid,
3769 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02003770 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003771 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Emeric Brun837ca522010-10-22 16:19:01 +02003772 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003773 break;
3774 }
3775
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003776 chunk_appendf(&trash,
Willy Tarreau65671ab2009-10-04 14:24:59 +02003777 " ts=%02x age=%s calls=%d",
3778 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01003779 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
3780 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003781
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003782 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003783 " rq[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003784 curr_sess->req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003785 curr_sess->req->buf->i,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003786 curr_sess->req->analysers,
3787 curr_sess->req->rex ?
3788 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
3789 TICKS_TO_MS(1000)) : "");
3790
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003791 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003792 ",wx=%s",
3793 curr_sess->req->wex ?
3794 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
3795 TICKS_TO_MS(1000)) : "");
3796
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003797 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003798 ",ax=%s]",
3799 curr_sess->req->analyse_exp ?
3800 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
3801 TICKS_TO_MS(1000)) : "");
3802
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003803 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003804 " rp[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003805 curr_sess->rep->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003806 curr_sess->rep->buf->i,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003807 curr_sess->rep->analysers,
3808 curr_sess->rep->rex ?
3809 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
3810 TICKS_TO_MS(1000)) : "");
3811
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003812 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003813 ",wx=%s",
3814 curr_sess->rep->wex ?
3815 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
3816 TICKS_TO_MS(1000)) : "");
3817
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003818 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003819 ",ax=%s]",
3820 curr_sess->rep->analyse_exp ?
3821 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
3822 TICKS_TO_MS(1000)) : "");
3823
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003824 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003825 " s0=[%d,%1xh,fd=%d,ex=%s]",
3826 curr_sess->si[0].state,
3827 curr_sess->si[0].flags,
Willy Tarreau7f7ad912012-11-11 19:27:15 +01003828 curr_sess->si[0].conn->t.sock.fd,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003829 curr_sess->si[0].exp ?
3830 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
3831 TICKS_TO_MS(1000)) : "");
3832
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003833 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003834 " s1=[%d,%1xh,fd=%d,ex=%s]",
3835 curr_sess->si[1].state,
3836 curr_sess->si[1].flags,
Willy Tarreau7f7ad912012-11-11 19:27:15 +01003837 curr_sess->si[1].conn->t.sock.fd,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003838 curr_sess->si[1].exp ?
3839 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
3840 TICKS_TO_MS(1000)) : "");
3841
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003842 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003843 " exp=%s",
3844 curr_sess->task->expire ?
3845 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
3846 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01003847 if (task_in_rq(curr_sess->task))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003848 chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003849
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003850 chunk_appendf(&trash, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003851
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003852 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003853 /* let's try again later from this session. We add ourselves into
3854 * this session's users so that it can remove us upon termination.
3855 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003856 LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003857 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003858 }
3859
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003860 next_sess:
Willy Tarreau295a8372011-03-10 11:25:07 +01003861 si->applet.ctx.sess.bref.ref = curr_sess->list.n;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003862 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003863
Willy Tarreau295a8372011-03-10 11:25:07 +01003864 if (si->applet.ctx.sess.target) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003865 /* specified session not found */
Willy Tarreau295a8372011-03-10 11:25:07 +01003866 if (si->applet.ctx.sess.section > 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003867 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003868 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003869 chunk_appendf(&trash, "Session not found.\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003870
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003871 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003872 return 0;
3873
Willy Tarreau295a8372011-03-10 11:25:07 +01003874 si->applet.ctx.sess.target = NULL;
3875 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003876 return 1;
3877 }
3878
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003879 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003880 /* fall through */
3881
3882 default:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003883 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003884 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003885 }
Emeric Brun1e029aa2010-09-23 18:12:53 +02003886}
3887
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003888/* This function dumps all tables' states onto the stream interface's
3889 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003890 * properly set. It returns 0 if the output buffer is full and it needs
3891 * to be called again, otherwise non-zero.
Willy Tarreau69f58c82010-07-12 17:55:33 +02003892 */
Simon Hormanc88b8872011-06-15 15:18:49 +09003893static int stats_table_request(struct stream_interface *si, bool show)
Willy Tarreau69f58c82010-07-12 17:55:33 +02003894{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003895 struct session *s = si->conn->xprt_ctx;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003896 struct ebmb_node *eb;
3897 int dt;
Simon Hormanc88b8872011-06-15 15:18:49 +09003898 bool skip_entry;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003899
3900 /*
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003901 * We have 3 possible states in si->conn->xprt_st :
Willy Tarreau295a8372011-03-10 11:25:07 +01003902 * - STAT_ST_INIT : the first call
3903 * - STAT_ST_INFO : the proxy pointer points to the next table to
Willy Tarreau69f58c82010-07-12 17:55:33 +02003904 * dump, the entry pointer is NULL ;
Willy Tarreau295a8372011-03-10 11:25:07 +01003905 * - STAT_ST_LIST : the proxy pointer points to the current table
Willy Tarreau69f58c82010-07-12 17:55:33 +02003906 * and the entry pointer points to the next entry to be dumped,
3907 * and the refcount on the next entry is held ;
Willy Tarreau295a8372011-03-10 11:25:07 +01003908 * - STAT_ST_END : nothing left to dump, the buffer may contain some
Willy Tarreau69f58c82010-07-12 17:55:33 +02003909 * data though.
3910 */
3911
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02003912 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02003913 /* in case of abort, remove any refcount we might have set on an entry */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003914 if (si->conn->xprt_st == STAT_ST_LIST) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003915 si->applet.ctx.table.entry->ref_cnt--;
3916 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
Willy Tarreauf6efda12010-08-03 20:34:06 +02003917 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02003918 return 1;
3919 }
3920
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003921 chunk_reset(&trash);
Willy Tarreau69f58c82010-07-12 17:55:33 +02003922
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003923 while (si->conn->xprt_st != STAT_ST_FIN) {
3924 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003925 case STAT_ST_INIT:
3926 si->applet.ctx.table.proxy = si->applet.ctx.table.target;
3927 if (!si->applet.ctx.table.proxy)
3928 si->applet.ctx.table.proxy = proxy;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003929
Willy Tarreau295a8372011-03-10 11:25:07 +01003930 si->applet.ctx.table.entry = NULL;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003931 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003932 break;
3933
Willy Tarreau295a8372011-03-10 11:25:07 +01003934 case STAT_ST_INFO:
3935 if (!si->applet.ctx.table.proxy ||
3936 (si->applet.ctx.table.target &&
3937 si->applet.ctx.table.proxy != si->applet.ctx.table.target)) {
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003938 si->conn->xprt_st = STAT_ST_END;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003939 break;
3940 }
3941
Willy Tarreau295a8372011-03-10 11:25:07 +01003942 if (si->applet.ctx.table.proxy->table.size) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003943 if (show && !stats_dump_table_head_to_buffer(&trash, si, si->applet.ctx.table.proxy,
Simon Hormanc88b8872011-06-15 15:18:49 +09003944 si->applet.ctx.table.target))
Willy Tarreau69f58c82010-07-12 17:55:33 +02003945 return 0;
3946
Willy Tarreau295a8372011-03-10 11:25:07 +01003947 if (si->applet.ctx.table.target &&
Willy Tarreau290e63a2012-09-20 18:07:14 +02003948 s->listener->bind_conf->level >= ACCESS_LVL_OPER) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02003949 /* dump entries only if table explicitly requested */
Willy Tarreau295a8372011-03-10 11:25:07 +01003950 eb = ebmb_first(&si->applet.ctx.table.proxy->table.keys);
Willy Tarreau69f58c82010-07-12 17:55:33 +02003951 if (eb) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003952 si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key);
3953 si->applet.ctx.table.entry->ref_cnt++;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003954 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003955 break;
3956 }
3957 }
3958 }
Willy Tarreau295a8372011-03-10 11:25:07 +01003959 si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003960 break;
3961
Willy Tarreau295a8372011-03-10 11:25:07 +01003962 case STAT_ST_LIST:
Simon Hormanc88b8872011-06-15 15:18:49 +09003963 skip_entry = false;
3964
Willy Tarreau295a8372011-03-10 11:25:07 +01003965 if (si->applet.ctx.table.data_type >= 0) {
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003966 /* we're filtering on some data contents */
3967 void *ptr;
3968 long long data;
3969
Willy Tarreau295a8372011-03-10 11:25:07 +01003970 dt = si->applet.ctx.table.data_type;
3971 ptr = stktable_data_ptr(&si->applet.ctx.table.proxy->table,
3972 si->applet.ctx.table.entry,
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003973 dt);
3974
3975 data = 0;
3976 switch (stktable_data_types[dt].std_type) {
3977 case STD_T_SINT:
3978 data = stktable_data_cast(ptr, std_t_sint);
3979 break;
3980 case STD_T_UINT:
3981 data = stktable_data_cast(ptr, std_t_uint);
3982 break;
3983 case STD_T_ULL:
3984 data = stktable_data_cast(ptr, std_t_ull);
3985 break;
3986 case STD_T_FRQP:
3987 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Willy Tarreau295a8372011-03-10 11:25:07 +01003988 si->applet.ctx.table.proxy->table.data_arg[dt].u);
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003989 break;
3990 }
3991
3992 /* skip the entry if the data does not match the test and the value */
Willy Tarreau295a8372011-03-10 11:25:07 +01003993 if ((data < si->applet.ctx.table.value &&
3994 (si->applet.ctx.table.data_op == STD_OP_EQ ||
3995 si->applet.ctx.table.data_op == STD_OP_GT ||
3996 si->applet.ctx.table.data_op == STD_OP_GE)) ||
3997 (data == si->applet.ctx.table.value &&
3998 (si->applet.ctx.table.data_op == STD_OP_NE ||
3999 si->applet.ctx.table.data_op == STD_OP_GT ||
4000 si->applet.ctx.table.data_op == STD_OP_LT)) ||
4001 (data > si->applet.ctx.table.value &&
4002 (si->applet.ctx.table.data_op == STD_OP_EQ ||
4003 si->applet.ctx.table.data_op == STD_OP_LT ||
4004 si->applet.ctx.table.data_op == STD_OP_LE)))
Simon Hormanc88b8872011-06-15 15:18:49 +09004005 skip_entry = true;
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02004006 }
4007
Simon Hormanc88b8872011-06-15 15:18:49 +09004008 if (show && !skip_entry &&
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004009 !stats_dump_table_entry_to_buffer(&trash, si, si->applet.ctx.table.proxy,
Simon Hormand9366582011-06-15 15:18:45 +09004010 si->applet.ctx.table.entry))
4011 return 0;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004012
Willy Tarreau295a8372011-03-10 11:25:07 +01004013 si->applet.ctx.table.entry->ref_cnt--;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004014
Willy Tarreau295a8372011-03-10 11:25:07 +01004015 eb = ebmb_next(&si->applet.ctx.table.entry->key);
Willy Tarreau69f58c82010-07-12 17:55:33 +02004016 if (eb) {
Willy Tarreau295a8372011-03-10 11:25:07 +01004017 struct stksess *old = si->applet.ctx.table.entry;
4018 si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key);
Willy Tarreau8fa52f42012-01-09 11:50:03 +01004019 if (show)
4020 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, old);
4021 else
4022 stksess_kill(&si->applet.ctx.table.proxy->table, old);
Willy Tarreau295a8372011-03-10 11:25:07 +01004023 si->applet.ctx.table.entry->ref_cnt++;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004024 break;
4025 }
4026
Simon Hormanc88b8872011-06-15 15:18:49 +09004027
4028 if (show)
4029 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
4030 else if (!skip_entry && !si->applet.ctx.table.entry->ref_cnt)
4031 stksess_kill(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
4032
Willy Tarreau295a8372011-03-10 11:25:07 +01004033 si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004034 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004035 break;
4036
Willy Tarreau295a8372011-03-10 11:25:07 +01004037 case STAT_ST_END:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004038 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004039 break;
4040 }
4041 }
4042 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01004043}
4044
Willy Tarreaud426a182010-03-05 14:58:26 +01004045/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
Willy Tarreau74808cb2009-03-04 15:53:18 +01004046 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
4047 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
4048 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
4049 * lines are respected within the limit of 70 output chars. Lines that are
4050 * continuation of a previous truncated line begin with "+" instead of " "
4051 * after the offset. The new pointer is returned.
4052 */
Willy Tarreaud426a182010-03-05 14:58:26 +01004053static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
4054 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004055{
4056 int end;
4057 unsigned char c;
4058
4059 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02004060 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004061 return ptr;
4062
Willy Tarreau77804732012-10-29 16:14:26 +01004063 chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01004064
Willy Tarreaud426a182010-03-05 14:58:26 +01004065 while (ptr < len && ptr < bsize) {
4066 c = buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01004067 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004068 if (out->len > end - 2)
4069 break;
4070 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01004071 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004072 if (out->len > end - 3)
4073 break;
4074 out->str[out->len++] = '\\';
4075 switch (c) {
4076 case '\t': c = 't'; break;
4077 case '\n': c = 'n'; break;
4078 case '\r': c = 'r'; break;
4079 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01004080 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004081 }
4082 out->str[out->len++] = c;
4083 } else {
4084 if (out->len > end - 5)
4085 break;
4086 out->str[out->len++] = '\\';
4087 out->str[out->len++] = 'x';
4088 out->str[out->len++] = hextab[(c >> 4) & 0xF];
4089 out->str[out->len++] = hextab[c & 0xF];
4090 }
Willy Tarreaud426a182010-03-05 14:58:26 +01004091 if (buf[ptr++] == '\n') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004092 /* we had a line break, let's return now */
4093 out->str[out->len++] = '\n';
4094 *line = ptr;
4095 return ptr;
4096 }
4097 }
4098 /* we have an incomplete line, we return it as-is */
4099 out->str[out->len++] = '\n';
4100 return ptr;
4101}
4102
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02004103/* This function dumps all captured errors onto the stream interface's
4104 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01004105 * properly set. It returns 0 if the output buffer is full and it needs
4106 * to be called again, otherwise non-zero.
Willy Tarreau74808cb2009-03-04 15:53:18 +01004107 */
Simon Horman9bd2c732011-06-15 15:18:44 +09004108static int stats_dump_errors_to_buffer(struct stream_interface *si)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004109{
4110 extern const char *monthname[12];
Willy Tarreau74808cb2009-03-04 15:53:18 +01004111
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02004112 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW)))
Willy Tarreau61b34732009-10-03 23:49:35 +02004113 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004114
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004115 chunk_reset(&trash);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004116
Willy Tarreau295a8372011-03-10 11:25:07 +01004117 if (!si->applet.ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004118 /* the function had not been called yet, let's prepare the
4119 * buffer for a response.
4120 */
Willy Tarreau10479e42010-12-12 14:00:34 +01004121 struct tm tm;
4122
4123 get_localtime(date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004124 chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n",
Willy Tarreau10479e42010-12-12 14:00:34 +01004125 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
4126 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000),
4127 error_snapshot_id);
4128
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004129 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau10479e42010-12-12 14:00:34 +01004130 /* Socket buffer full. Let's try again later from the same point */
4131 return 0;
4132 }
4133
Willy Tarreau295a8372011-03-10 11:25:07 +01004134 si->applet.ctx.errors.px = proxy;
4135 si->applet.ctx.errors.buf = 0;
4136 si->applet.ctx.errors.bol = 0;
4137 si->applet.ctx.errors.ptr = -1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004138 }
4139
4140 /* we have two inner loops here, one for the proxy, the other one for
4141 * the buffer.
4142 */
Willy Tarreau295a8372011-03-10 11:25:07 +01004143 while (si->applet.ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004144 struct error_snapshot *es;
4145
Willy Tarreau295a8372011-03-10 11:25:07 +01004146 if (si->applet.ctx.errors.buf == 0)
4147 es = &si->applet.ctx.errors.px->invalid_req;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004148 else
Willy Tarreau295a8372011-03-10 11:25:07 +01004149 es = &si->applet.ctx.errors.px->invalid_rep;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004150
4151 if (!es->when.tv_sec)
4152 goto next;
4153
Willy Tarreau295a8372011-03-10 11:25:07 +01004154 if (si->applet.ctx.errors.iid >= 0 &&
4155 si->applet.ctx.errors.px->uuid != si->applet.ctx.errors.iid &&
4156 es->oe->uuid != si->applet.ctx.errors.iid)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004157 goto next;
4158
Willy Tarreau295a8372011-03-10 11:25:07 +01004159 if (si->applet.ctx.errors.ptr < 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004160 /* just print headers now */
4161
4162 char pn[INET6_ADDRSTRLEN];
4163 struct tm tm;
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004164 int port;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004165
4166 get_localtime(es->when.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004167 chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01004168 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02004169 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01004170
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004171 switch (addr_to_str(&es->src, pn, sizeof(pn))) {
4172 case AF_INET:
4173 case AF_INET6:
4174 port = get_host_port(&es->src);
4175 break;
4176 default:
4177 port = 0;
4178 }
4179
Willy Tarreau295a8372011-03-10 11:25:07 +01004180 switch (si->applet.ctx.errors.buf) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004181 case 0:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004182 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004183 " frontend %s (#%d): invalid request\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004184 " backend %s (#%d)",
Willy Tarreau295a8372011-03-10 11:25:07 +01004185 si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004186 (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
4187 (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004188 break;
4189 case 1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004190 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004191 " backend %s (#%d) : invalid response\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004192 " frontend %s (#%d)",
Willy Tarreau295a8372011-03-10 11:25:07 +01004193 si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004194 es->oe->id, es->oe->uuid);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004195 break;
4196 }
4197
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004198 chunk_appendf(&trash,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004199 ", server %s (#%d), event #%u\n"
4200 " src %s:%d, session #%d, session flags 0x%08x\n"
4201 " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n"
4202 " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n"
4203 " buffer flags 0x%08x, out %d bytes, total %lld bytes\n"
4204 " pending %d bytes, wrapping at %d, error at position %d:\n \n",
4205 es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1,
4206 es->ev_id,
4207 pn, port, es->sid, es->s_flags,
4208 es->state, es->m_flags, es->t_flags,
4209 es->m_clen, es->m_blen,
4210 es->b_flags, es->b_out, es->b_tot,
4211 es->len, es->b_wrap, es->pos);
4212
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004213 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004214 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02004215 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004216 }
Willy Tarreau295a8372011-03-10 11:25:07 +01004217 si->applet.ctx.errors.ptr = 0;
4218 si->applet.ctx.errors.sid = es->sid;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004219 }
4220
Willy Tarreau295a8372011-03-10 11:25:07 +01004221 if (si->applet.ctx.errors.sid != es->sid) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004222 /* the snapshot changed while we were dumping it */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004223 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004224 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004225 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau61b34732009-10-03 23:49:35 +02004226 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004227 goto next;
4228 }
4229
4230 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau295a8372011-03-10 11:25:07 +01004231 while (si->applet.ctx.errors.ptr < es->len && si->applet.ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004232 int newptr;
4233 int newline;
4234
Willy Tarreau295a8372011-03-10 11:25:07 +01004235 newline = si->applet.ctx.errors.bol;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004236 newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, si->applet.ctx.errors.ptr);
Willy Tarreau295a8372011-03-10 11:25:07 +01004237 if (newptr == si->applet.ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02004238 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004239
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004240 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004241 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02004242 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004243 }
Willy Tarreau295a8372011-03-10 11:25:07 +01004244 si->applet.ctx.errors.ptr = newptr;
4245 si->applet.ctx.errors.bol = newline;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004246 };
4247 next:
Willy Tarreau295a8372011-03-10 11:25:07 +01004248 si->applet.ctx.errors.bol = 0;
4249 si->applet.ctx.errors.ptr = -1;
4250 si->applet.ctx.errors.buf++;
4251 if (si->applet.ctx.errors.buf > 1) {
4252 si->applet.ctx.errors.buf = 0;
4253 si->applet.ctx.errors.px = si->applet.ctx.errors.px->next;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004254 }
4255 }
4256
4257 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02004258 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004259}
4260
Willy Tarreaud5781202012-09-22 19:32:35 +02004261/* parse the "level" argument on the bind lines */
4262static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
4263{
4264 if (!*args[cur_arg + 1]) {
4265 memprintf(err, "'%s' : missing level", args[cur_arg]);
4266 return ERR_ALERT | ERR_FATAL;
4267 }
4268
4269 if (!strcmp(args[cur_arg+1], "user"))
4270 conf->level = ACCESS_LVL_USER;
4271 else if (!strcmp(args[cur_arg+1], "operator"))
4272 conf->level = ACCESS_LVL_OPER;
4273 else if (!strcmp(args[cur_arg+1], "admin"))
4274 conf->level = ACCESS_LVL_ADMIN;
4275 else {
4276 memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')",
4277 args[cur_arg], args[cur_arg+1]);
4278 return ERR_ALERT | ERR_FATAL;
4279 }
4280
4281 return 0;
4282}
4283
Willy Tarreaub24281b2011-02-13 13:16:36 +01004284struct si_applet http_stats_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01004285 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004286 .name = "<STATS>", /* used for logging */
4287 .fct = http_stats_io_handler,
Aman Gupta9a13e842012-04-02 18:57:53 -07004288 .release = NULL,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004289};
4290
Simon Horman9bd2c732011-06-15 15:18:44 +09004291static struct si_applet cli_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01004292 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004293 .name = "<CLI>", /* used for logging */
4294 .fct = cli_io_handler,
Aman Gupta9a13e842012-04-02 18:57:53 -07004295 .release = NULL,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004296};
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01004297
Willy Tarreau10522fd2008-07-09 20:12:41 +02004298static struct cfg_kw_list cfg_kws = {{ },{
4299 { CFG_GLOBAL, "stats", stats_parse_global },
4300 { 0, NULL, NULL },
4301}};
4302
Willy Tarreaud5781202012-09-22 19:32:35 +02004303static struct bind_kw_list bind_kws = { "STAT", { }, {
4304 { "level", bind_parse_level, 1 }, /* set the unix socket admin level */
4305 { NULL, NULL, 0 },
4306}};
4307
Willy Tarreau10522fd2008-07-09 20:12:41 +02004308__attribute__((constructor))
4309static void __dumpstats_module_init(void)
4310{
4311 cfg_register_keywords(&cfg_kws);
Willy Tarreaud5781202012-09-22 19:32:35 +02004312 bind_register_keywords(&bind_kws);
Willy Tarreau10522fd2008-07-09 20:12:41 +02004313}
4314
Willy Tarreau91861262007-10-17 17:06:05 +02004315/*
4316 * Local variables:
4317 * c-indent-level: 8
4318 * c-basic-offset: 8
4319 * End:
4320 */