blob: 988f94c7fd71a4574721d88f0fbc991699c0cf21 [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 */
2491 chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld\"",
2492 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002493
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002494 chunk_appendf(&trash,
Willy Tarreau55058a72012-11-21 08:27:21 +01002495 /* bytes: out */
2496 ">%s%s%s</td>"
2497 "",
2498 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"",
2499 U2H0(px->fe_counters.bytes_out),
2500 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":"");
2501
2502 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002503 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002504 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002505 /* errors : request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002506 "<td>%s</td><td></td><td></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002507 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002508 "<td></td><td></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002509 /* server status : reflect frontend status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002510 "<td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002511 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002512 "<td class=ac colspan=8></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +02002513 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002514 U2H0(px->fe_counters.denied_req), U2H1(px->fe_counters.denied_resp),
2515 U2H2(px->fe_counters.failed_req),
Willy Tarreau562515c2011-07-25 08:11:52 +02002516 px->state == PR_STREADY ? "OPEN" :
2517 px->state == PR_STFULL ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002518 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002519 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002520 /* pxid, name, queue cur, queue max, */
2521 "%s,FRONTEND,,,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002522 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002523 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002524 /* bytes : in, out */
2525 "%lld,%lld,"
2526 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002527 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002528 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002529 "%lld,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002530 /* warnings: retries, redispatches */
2531 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002532 /* server status : reflect frontend status */
2533 "%s,"
2534 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002535 ",,,,,,,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002536 /* pid, iid, sid, throttle, lbtot, tracked, type */
2537 "%d,%d,0,,,,%d,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002538 /* rate, rate_lim, rate_max */
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002539 "%u,%u,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002540 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002541 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02002542 px->id,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002543 px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess,
2544 px->fe_counters.bytes_in, px->fe_counters.bytes_out,
2545 px->fe_counters.denied_req, px->fe_counters.denied_resp,
2546 px->fe_counters.failed_req,
Willy Tarreau562515c2011-07-25 08:11:52 +02002547 px->state == PR_STREADY ? "OPEN" :
2548 px->state == PR_STFULL ? "FULL" : "STOP",
Willy Tarreau7f062c42009-03-05 18:43:00 +01002549 relative_pid, px->uuid, STATS_TYPE_FE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002550 read_freq_ctr(&px->fe_sess_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002551 px->fe_sps_lim, px->fe_counters.sps_max);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002552
2553 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2554 if (px->mode == PR_MODE_HTTP) {
2555 int i;
2556
2557 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002558 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002559
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002560 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002561 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002562 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002563 }
2564
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002565 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002566 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002567
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002568 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002569 chunk_appendf(&trash, "%u,%u,%lld,",
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002570 read_freq_ctr(&px->fe_req_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002571 px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req);
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002572
Willy Tarreauae526782010-03-04 20:34:23 +01002573 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002574 chunk_appendf(&trash, ",,");
Willy Tarreauae526782010-03-04 20:34:23 +01002575
Willy Tarreau55058a72012-11-21 08:27:21 +01002576 /* compression: in, out, bypassed */
2577 chunk_appendf(&trash, "%lld,%lld,%lld,",
2578 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
2579
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002580 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002581 chunk_appendf(&trash, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002582 }
Willy Tarreau91861262007-10-17 17:06:05 +02002583
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002584 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02002585 return 0;
2586 }
2587
Willy Tarreau4348fad2012-09-20 16:48:07 +02002588 si->applet.ctx.stats.l = px->conf.listeners.n;
Willy Tarreau295a8372011-03-10 11:25:07 +01002589 si->applet.ctx.stats.px_st = STAT_PX_ST_LI;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002590 /* fall through */
2591
Willy Tarreau295a8372011-03-10 11:25:07 +01002592 case STAT_PX_ST_LI:
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002593 /* stats.l has been initialized above */
Willy Tarreau4348fad2012-09-20 16:48:07 +02002594 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 +02002595 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002596 return 0;
2597
Willy Tarreau4348fad2012-09-20 16:48:07 +02002598 l = LIST_ELEM(si->applet.ctx.stats.l, struct listener *, by_fe);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002599 if (!l->counters)
2600 continue;
2601
Willy Tarreau295a8372011-03-10 11:25:07 +01002602 if (si->applet.ctx.stats.flags & STAT_BOUND) {
2603 if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SO)))
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002604 break;
2605
Willy Tarreau295a8372011-03-10 11:25:07 +01002606 if (si->applet.ctx.stats.sid != -1 && l->luid != si->applet.ctx.stats.sid)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002607 continue;
2608 }
2609
Willy Tarreau295a8372011-03-10 11:25:07 +01002610 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002611 chunk_appendf(&trash, "<tr class=socket>");
Willy Tarreau295a8372011-03-10 11:25:07 +01002612 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002613 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002614 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002615 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002616 chunk_appendf(&trash, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002617
2618 if (uri->flags&ST_SHLGNDS) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02002619 char str[INET6_ADDRSTRLEN];
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002620 int port;
2621
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002622 chunk_appendf(&trash, " title=\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002623
Willy Tarreau631f01c2011-09-05 00:36:48 +02002624 port = get_host_port(&l->addr);
2625 switch (addr_to_str(&l->addr, str, sizeof(str))) {
2626 case AF_INET:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002627 chunk_appendf(&trash, "IPv4: %s:%d, ", str, port);
Willy Tarreau631f01c2011-09-05 00:36:48 +02002628 break;
2629 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002630 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port);
Willy Tarreau631f01c2011-09-05 00:36:48 +02002631 break;
2632 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002633 chunk_appendf(&trash, "unix, ");
Willy Tarreau631f01c2011-09-05 00:36:48 +02002634 break;
2635 case -1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002636 chunk_appendf(&trash, "(%s), ", strerror(errno));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002637 break;
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002638 }
2639
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002640 /* id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002641 chunk_appendf(&trash, "id: %d\"", l->luid);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002642 }
2643
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002644 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002645 /* name, queue */
Willy Tarreaue0454092010-02-26 12:29:07 +01002646 ">%s<a name=\"%s/+%s\"></a>"
2647 "<a class=lfsb href=\"#%s/+%s\">%s</a></td><td colspan=3>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002648 /* sessions rate: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002649 "<td colspan=3>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002650 /* sessions: current, max, limit, total, lbtot */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002651 "<td>%s</td><td>%s</td><td>%s</td>"
2652 "<td>%s</td><td>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002653 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002654 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002655 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002656 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki2ec025d2010-01-04 11:33:32 +01002657 px->id, l->name, px->id, l->name, l->name,
Willy Tarreaue0454092010-02-26 12:29:07 +01002658 (uri->flags & ST_SHLGNDS)?"</u>":"",
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002659 U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn),
2660 U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out));
2661
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002662 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002663 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002664 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002665 /* errors: request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002666 "<td>%s</td><td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002667 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002668 "<td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002669 /* server status: reflect listener status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002670 "<td class=ac>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002671 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002672 "<td class=ac colspan=8></td></tr>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002673 "",
2674 U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp),
2675 U2H2(l->counters->failed_req),
Willy Tarreaua17c2d92011-07-25 08:16:20 +02002676 (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002677 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002678 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002679 /* pxid, name, queue cur, queue max, */
2680 "%s,%s,,,"
2681 /* sessions: current, max, limit, total */
2682 "%d,%d,%d,%lld,"
2683 /* bytes: in, out */
2684 "%lld,%lld,"
2685 /* denied: req, resp */
2686 "%lld,%lld,"
2687 /* errors: request, connect, response */
2688 "%lld,,,"
2689 /* warnings: retries, redispatches */
2690 ",,"
2691 /* server status: reflect listener status */
2692 "%s,"
2693 /* rest of server: nothing */
2694 ",,,,,,,,"
2695 /* pid, iid, sid, throttle, lbtot, tracked, type */
2696 "%d,%d,%d,,,,%d,"
2697 /* rate, rate_lim, rate_max */
2698 ",,,"
2699 /* check_status, check_code, check_duration */
2700 ",,,"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002701 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2702 ",,,,,,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002703 /* failed health analyses */
2704 ","
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002705 /* requests : req_rate, req_rate_max, req_tot, */
2706 ",,,"
Willy Tarreauae526782010-03-04 20:34:23 +01002707 /* errors: cli_aborts, srv_aborts */
2708 ",,"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002709 "\n",
2710 px->id, l->name,
2711 l->nbconn, l->counters->conn_max,
2712 l->maxconn, l->counters->cum_conn,
2713 l->counters->bytes_in, l->counters->bytes_out,
2714 l->counters->denied_req, l->counters->denied_resp,
2715 l->counters->failed_req,
2716 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
2717 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
2718 }
2719
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002720 if (bi_putchk(rep, &trash) == -1)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002721 return 0;
2722 }
2723
Willy Tarreau295a8372011-03-10 11:25:07 +01002724 si->applet.ctx.stats.sv = px->srv; /* may be NULL */
2725 si->applet.ctx.stats.px_st = STAT_PX_ST_SV;
Willy Tarreau91861262007-10-17 17:06:05 +02002726 /* fall through */
2727
Willy Tarreau295a8372011-03-10 11:25:07 +01002728 case STAT_PX_ST_SV:
Willy Tarreau91861262007-10-17 17:06:05 +02002729 /* stats.sv has been initialized above */
Willy Tarreau295a8372011-03-10 11:25:07 +01002730 for (; si->applet.ctx.stats.sv != NULL; si->applet.ctx.stats.sv = sv->next) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002731 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 +02002732
Willy Tarreau9b28e032012-10-12 23:49:43 +02002733 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002734 return 0;
2735
Willy Tarreau295a8372011-03-10 11:25:07 +01002736 sv = si->applet.ctx.stats.sv;
Willy Tarreau91861262007-10-17 17:06:05 +02002737
Willy Tarreau295a8372011-03-10 11:25:07 +01002738 if (si->applet.ctx.stats.flags & STAT_BOUND) {
2739 if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SV)))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002740 break;
2741
Willy Tarreau295a8372011-03-10 11:25:07 +01002742 if (si->applet.ctx.stats.sid != -1 && sv->puid != si->applet.ctx.stats.sid)
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002743 continue;
2744 }
2745
Willy Tarreau44267702011-10-28 15:35:33 +02002746 if (sv->track)
2747 svs = sv->track;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002748 else
2749 svs = sv;
2750
Willy Tarreau91861262007-10-17 17:06:05 +02002751 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002752 if (!(svs->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +01002753 sv_state = 6;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002754 else if (svs->state & SRV_RUNNING) {
2755 if (svs->health == svs->rise + svs->fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02002756 sv_state = 3; /* UP */
2757 else
2758 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01002759
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002760 if (svs->state & SRV_GOINGDOWN)
Willy Tarreau2ea81932007-11-30 12:04:38 +01002761 sv_state += 2;
2762 }
Willy Tarreau91861262007-10-17 17:06:05 +02002763 else
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002764 if (svs->health)
Willy Tarreau91861262007-10-17 17:06:05 +02002765 sv_state = 1; /* going up */
2766 else
2767 sv_state = 0; /* DOWN */
2768
Willy Tarreau295a8372011-03-10 11:25:07 +01002769 if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (si->applet.ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02002770 /* do not report servers which are DOWN */
Willy Tarreau295a8372011-03-10 11:25:07 +01002771 si->applet.ctx.stats.sv = sv->next;
Willy Tarreau91861262007-10-17 17:06:05 +02002772 continue;
2773 }
2774
Willy Tarreau295a8372011-03-10 11:25:07 +01002775 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002776 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
2777 "UP %d/%d &darr;", "UP",
2778 "NOLB %d/%d &darr;", "NOLB",
2779 "<i>no check</i>" };
Cyril Bonté0dae5852010-02-03 00:26:28 +01002780 if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002781 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01002782 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002783 "<tr class=\"maintain\">"
Cyril Bontécd19e512010-01-31 22:34:03 +01002784 );
2785 }
2786 else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002787 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01002788 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002789 "<tr class=\"%s%d\">",
Cyril Bontécd19e512010-01-31 22:34:03 +01002790 (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state);
2791 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002792
Willy Tarreau295a8372011-03-10 11:25:07 +01002793 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002794 chunk_appendf(&trash,
Cyril Bonté474be412010-10-12 00:14:36 +02002795 "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
2796 sv->id);
2797 }
2798
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002799 chunk_appendf(&trash, "<td class=ac");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002800
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002801 if (uri->flags&ST_SHLGNDS) {
2802 char str[INET6_ADDRSTRLEN];
2803
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002804 chunk_appendf(&trash, " title=\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002805
Willy Tarreau631f01c2011-09-05 00:36:48 +02002806 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
David du Colombier6f5ccb12011-03-10 22:26:24 +01002807 case AF_INET:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002808 chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr));
David du Colombier6f5ccb12011-03-10 22:26:24 +01002809 break;
2810 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002811 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002812 break;
2813 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002814 chunk_appendf(&trash, "unix, ");
Willy Tarreau631f01c2011-09-05 00:36:48 +02002815 break;
2816 case -1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002817 chunk_appendf(&trash, "(%s), ", strerror(errno));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002818 break;
2819 default: /* address family not supported */
David du Colombier6f5ccb12011-03-10 22:26:24 +01002820 break;
2821 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002822
2823 /* id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002824 chunk_appendf(&trash, "id: %d", sv->puid);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002825
2826 /* cookie */
2827 if (sv->cookie) {
2828 struct chunk src;
2829
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002830 chunk_appendf(&trash, ", cookie: '");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002831
2832 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002833 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002834
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002835 chunk_appendf(&trash, "'");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002836 }
2837
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002838 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002839 }
2840
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002841 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002842 ">%s<a name=\"%s/%s\"></a>"
2843 "<a class=lfsb href=\"#%s/%s\">%s</a>%s</td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002844 /* queue : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002845 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002846 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002847 "<td>%s</td><td>%s</td><td></td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002848 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002849 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002850 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002851 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002852 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002853 px->id, sv->id, px->id, sv->id, sv->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01002854 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002855 U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"),
2856 U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max),
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002857 U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-"));
2858
2859 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2860 if (px->mode == PR_MODE_HTTP) {
2861 int i;
2862
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002863 chunk_appendf(&trash, " title=\"rsp codes:");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002864
2865 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002866 chunk_appendf(&trash, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002867
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002868 chunk_appendf(&trash, " other=%lld\"", sv->counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002869 }
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002870
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002871 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002872 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002873 ">%s%s%s</td><td>%s</td>",
2874 (px->mode == PR_MODE_HTTP)?"<u>":"",
2875 U2H0(sv->counters.cum_sess),
2876 (px->mode == PR_MODE_HTTP)?"</u>":"",
2877 U2H1(sv->counters.cum_lbconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002878
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002879 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002880 /* bytes : in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002881 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002882 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002883 "<td></td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01002884 /* errors : request, connect */
2885 "<td></td><td>%s</td>"
2886 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002887 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002888 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002889 "<td>%lld</td><td>%lld</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002890 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002891 U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out),
2892 U2H2(sv->counters.failed_secu),
Willy Tarreauae526782010-03-04 20:34:23 +01002893 U2H3(sv->counters.failed_conns),
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002894 sv->counters.cli_aborts,
2895 sv->counters.srv_aborts,
Willy Tarreauae526782010-03-04 20:34:23 +01002896 U2H6(sv->counters.failed_resp),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002897 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002898
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002899 /* status, lest check */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002900 chunk_appendf(&trash, "<td class=ac>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002901
Cyril Bontécd19e512010-01-31 22:34:03 +01002902 if (sv->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002903 chunk_appendf(&trash, "%s ",
Cyril Bontécd19e512010-01-31 22:34:03 +01002904 human_time(now.tv_sec - sv->last_change, 1));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002905 chunk_appendf(&trash, "MAINT");
Cyril Bontécd19e512010-01-31 22:34:03 +01002906 }
Cyril Bonté0dae5852010-02-03 00:26:28 +01002907 else if (svs != sv && svs->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002908 chunk_appendf(&trash, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01002909 human_time(now.tv_sec - svs->last_change, 1));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002910 chunk_appendf(&trash, "MAINT(via)");
Cyril Bonté0dae5852010-02-03 00:26:28 +01002911 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002912 else if (svs->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002913 chunk_appendf(&trash, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01002914 human_time(now.tv_sec - svs->last_change, 1));
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002915
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002916 chunk_appendf(&trash,
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002917 srv_hlt_st[sv_state],
2918 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
2919 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002920 }
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002921
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002922 if (sv->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002923 chunk_appendf(&trash, "</td><td class=ac title=\"%s",
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002924 get_check_status_description(sv->check.status));
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002925
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002926 if (*sv->check.desc) {
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002927 struct chunk src;
2928
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002929 chunk_appendf(&trash, ": ");
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002930
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002931 chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002932 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002933 }
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002934
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002935 chunk_appendf(&trash, "\"><u> %s%s",
Willy Tarreau5a78f362012-11-23 12:47:05 +01002936 (sv->state & SRV_CHK_RUNNING) ? "" : "* ",
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002937 get_check_status_info(sv->check.status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002938
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002939 if (sv->check.status >= HCHK_STATUS_L57DATA)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002940 chunk_appendf(&trash, "/%d", sv->check.code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002941
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002942 if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002943 chunk_appendf(&trash, " in %lums</u>", sv->check.duration);
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002944 } else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002945 chunk_appendf(&trash, "</td><td>");
Willy Tarreau91861262007-10-17 17:06:05 +02002946
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002947 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002948 /* weight */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002949 "</td><td class=ac>%d</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002950 /* act, bck */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002951 "<td class=ac>%s</td><td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002952 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01002953 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +02002954 (sv->state & SRV_BACKUP) ? "-" : "Y",
2955 (sv->state & SRV_BACKUP) ? "Y" : "-");
2956
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002957 /* check failures: unique, fatal, down time */
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002958 if (sv->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002959 chunk_appendf(&trash, "<td title=\"Failed Health Checks%s\"><u>%lld",
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002960 svs->observe?"/Health Analyses":"", svs->counters.failed_checks);
2961
2962 if (svs->observe)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002963 chunk_appendf(&trash, "/%lld", svs->counters.failed_hana);
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002964
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002965 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002966 "</u></td>"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002967 "<td>%lld</td><td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002968 "",
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002969 svs->counters.down_trans, human_time(srv_downtime(sv), 1));
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002970 } else if (sv != svs)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002971 chunk_appendf(&trash,
Krzysztof Piotr Oledzki88a14af2010-01-05 18:33:01 +01002972 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>",
2973 svs->proxy->id, svs->id, svs->proxy->id, svs->id);
Willy Tarreau55bb8452007-10-17 18:44:57 +02002974 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002975 chunk_appendf(&trash,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002976 "<td colspan=3></td>");
2977
2978 /* throttle */
2979 if ((sv->state & SRV_WARMINGUP) &&
2980 now.tv_sec < sv->last_change + sv->slowstart &&
2981 now.tv_sec >= sv->last_change) {
2982 unsigned int ratio;
2983 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002984 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002985 "<td class=ac>%d %%</td></tr>\n", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002986 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002987 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002988 "<td class=ac>-</td></tr>\n");
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002989 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02002990 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002991 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
2992 "UP %d/%d,", "UP,",
2993 "NOLB %d/%d,", "NOLB,",
2994 "no check," };
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002995 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002996 /* pxid, name */
2997 "%s,%s,"
2998 /* queue : current, max */
2999 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003000 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003001 "%d,%d,%s,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003002 /* bytes : in, out */
3003 "%lld,%lld,"
3004 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003005 ",%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003006 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003007 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003008 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003009 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003010 "",
3011 px->id, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02003012 sv->nbpend, sv->counters.nbpend_max,
3013 sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02003014 sv->counters.bytes_in, sv->counters.bytes_out,
3015 sv->counters.failed_secu,
3016 sv->counters.failed_conns, sv->counters.failed_resp,
3017 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003018
Willy Tarreau55bb8452007-10-17 18:44:57 +02003019 /* status */
Cyril Bontécd19e512010-01-31 22:34:03 +01003020 if (sv->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003021 chunk_appendf(&trash, "MAINT,");
Cyril Bonté0dae5852010-02-03 00:26:28 +01003022 }
3023 else if (svs != sv && svs->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003024 chunk_appendf(&trash, "MAINT(via),");
Cyril Bonté0dae5852010-02-03 00:26:28 +01003025 }
3026 else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003027 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01003028 srv_hlt_st[sv_state],
3029 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
3030 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
3031 }
Willy Tarreau91861262007-10-17 17:06:05 +02003032
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003033 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003034 /* weight, active, backup */
3035 "%d,%d,%d,"
3036 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01003037 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003038 (sv->state & SRV_BACKUP) ? 0 : 1,
3039 (sv->state & SRV_BACKUP) ? 1 : 0);
3040
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003041 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +02003042 if (sv->state & SRV_CHECKED)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003043 chunk_appendf(&trash,
Willy Tarreau3b88d442009-04-11 20:44:08 +02003044 "%lld,%lld,%d,%d,",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02003045 sv->counters.failed_checks, sv->counters.down_trans,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003046 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +02003047 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003048 chunk_appendf(&trash,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02003049 ",,,,");
3050
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003051 /* queue limit, pid, iid, sid, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003052 chunk_appendf(&trash,
Willy Tarreaudcd47712007-11-04 23:35:08 +01003053 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003054 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +01003055 LIM2A0(sv->maxqueue, ""),
3056 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003057
3058 /* throttle */
3059 if ((sv->state & SRV_WARMINGUP) &&
3060 now.tv_sec < sv->last_change + sv->slowstart &&
3061 now.tv_sec >= sv->last_change) {
3062 unsigned int ratio;
3063 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003064 chunk_appendf(&trash, "%d", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003065 }
3066
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003067 /* sessions: lbtot */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003068 chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003069
3070 /* tracked */
Willy Tarreau44267702011-10-28 15:35:33 +02003071 if (sv->track)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003072 chunk_appendf(&trash, "%s/%s,",
Willy Tarreau44267702011-10-28 15:35:33 +02003073 sv->track->proxy->id, sv->track->id);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003074 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003075 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003076
Willy Tarreau7f062c42009-03-05 18:43:00 +01003077 /* type */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003078 chunk_appendf(&trash, "%d,", STATS_TYPE_SV);
Willy Tarreau7f062c42009-03-05 18:43:00 +01003079
3080 /* rate */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003081 chunk_appendf(&trash, "%u,,%u,",
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003082 read_freq_ctr(&sv->sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02003083 sv->counters.sps_max);
Willy Tarreau7f062c42009-03-05 18:43:00 +01003084
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003085 if (sv->state & SRV_CHECKED) {
3086 /* check_status */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003087 chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003088
3089 /* check_code */
Willy Tarreau5b3a2022012-09-28 15:01:02 +02003090 if (sv->check.status >= HCHK_STATUS_L57DATA)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003091 chunk_appendf(&trash, "%u,", sv->check.code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003092 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003093 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003094
3095 /* check_duration */
Willy Tarreau5b3a2022012-09-28 15:01:02 +02003096 if (sv->check.status >= HCHK_STATUS_CHECKED)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003097 chunk_appendf(&trash, "%lu,", sv->check.duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003098 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003099 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003100
3101 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003102 chunk_appendf(&trash, ",,,");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003103 }
3104
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003105 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3106 if (px->mode == PR_MODE_HTTP) {
3107 int i;
3108
3109 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003110 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003111
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003112 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003113 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003114 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003115 }
3116
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003117 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003118 chunk_appendf(&trash, "%lld,", sv->counters.failed_hana);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003119
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003120 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003121 chunk_appendf(&trash, ",,,");
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003122
Willy Tarreauae526782010-03-04 20:34:23 +01003123 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003124 chunk_appendf(&trash, "%lld,%lld,",
Willy Tarreauae526782010-03-04 20:34:23 +01003125 sv->counters.cli_aborts, sv->counters.srv_aborts);
3126
Willy Tarreau7f062c42009-03-05 18:43:00 +01003127 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003128 chunk_appendf(&trash, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003129 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003130 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02003131 return 0;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003132 } /* for sv */
Willy Tarreau91861262007-10-17 17:06:05 +02003133
Willy Tarreau295a8372011-03-10 11:25:07 +01003134 si->applet.ctx.stats.px_st = STAT_PX_ST_BE;
Willy Tarreau91861262007-10-17 17:06:05 +02003135 /* fall through */
3136
Willy Tarreau295a8372011-03-10 11:25:07 +01003137 case STAT_PX_ST_BE:
Willy Tarreau91861262007-10-17 17:06:05 +02003138 /* print the backend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01003139 if ((px->cap & PR_CAP_BE) &&
Willy Tarreau295a8372011-03-10 11:25:07 +01003140 (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_BE)))) {
3141 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003142 chunk_appendf(&trash, "<tr class=\"backend\">");
Willy Tarreau295a8372011-03-10 11:25:07 +01003143 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02003144 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003145 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02003146 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003147 chunk_appendf(&trash, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003148
3149 if (uri->flags&ST_SHLGNDS) {
3150 /* balancing */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003151 chunk_appendf(&trash, " title=\"balancing: %s",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003152 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003153
3154 /* cookie */
3155 if (px->cookie_name) {
3156 struct chunk src;
3157
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003158 chunk_appendf(&trash, ", cookie: '");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003159
3160 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003161 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003162
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003163 chunk_appendf(&trash, "'");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003164 }
3165
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003166 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003167
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003168 }
3169
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003170 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02003171 /* name */
Willy Tarreaue0454092010-02-26 12:29:07 +01003172 ">%s<a name=\"%s/Backend\"></a>"
3173 "<a class=lfsb href=\"#%s/Backend\">Backend</a>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02003174 /* queue : current, max */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003175 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02003176 /* sessions rate : current, max, limit */
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 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01003179 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02003180 px->id, px->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01003181 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003182 U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->be_counters.nbpend_max),
3183 U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->be_counters.sps_max));
Willy Tarreaua3e49422009-05-10 19:19:41 +02003184
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003185 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003186 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003187 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003188 "<td"
3189 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003190 U2H2(px->beconn), U2H3(px->be_counters.conn_max), U2H4(px->fullconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003191
3192 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
3193 if (px->mode == PR_MODE_HTTP) {
3194 int i;
3195
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003196 chunk_appendf(&trash, " title=\"rsp codes:");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003197
3198 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003199 chunk_appendf(&trash, " %dxx=%lld", i, px->be_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003200
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003201 chunk_appendf(&trash, " other=%lld\"", px->be_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003202 }
3203
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003204 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003205 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01003206 ">%s%s%s</td><td>%s</td>"
Willy Tarreau55058a72012-11-21 08:27:21 +01003207 /* bytes: in */
3208 "<td>%s</td><td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003209 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01003210 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003211 U2H6(px->be_counters.cum_conn),
Willy Tarreaue0454092010-02-26 12:29:07 +01003212 (px->mode == PR_MODE_HTTP)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003213 U2H7(px->be_counters.cum_lbconn),
Willy Tarreau55058a72012-11-21 08:27:21 +01003214 U2H8(px->be_counters.bytes_in));
3215
3216 /* compression stats (via td title): comp_in, comp_out, comp_byp */
3217 chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld\"",
3218 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003219
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003220 chunk_appendf(&trash,
Willy Tarreau55058a72012-11-21 08:27:21 +01003221 /* bytes: out */
3222 ">%s%s%s</td>"
3223 "",
3224 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"",
3225 U2H0(px->be_counters.bytes_out),
3226 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":"");
3227
3228 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02003229 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003230 "<td>%s</td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01003231 /* errors : request, connect */
3232 "<td></td><td>%s</td>"
3233 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01003234 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003235 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003236 "<td>%lld</td><td>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003237 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +02003238 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003239 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +02003240 * active and backups. */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003241 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
3242 "<td class=ac>%d</td><td class=ac>%d</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003243 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003244 U2H0(px->be_counters.denied_req), U2H1(px->be_counters.denied_resp),
3245 U2H2(px->be_counters.failed_conns),
3246 px->be_counters.cli_aborts,
3247 px->be_counters.srv_aborts,
3248 U2H5(px->be_counters.failed_resp),
3249 px->be_counters.retries, px->be_counters.redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003250 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +01003251 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
3252 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5542af62007-12-03 02:04:00 +01003253 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01003254 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003255
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003256 chunk_appendf(&trash,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003257 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003258 "<td class=ac>&nbsp;</td><td>%d</td>"
3259 "<td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003260 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003261 "</tr>",
3262 px->down_trans,
3263 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003264 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003265 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003266 /* pxid, name */
3267 "%s,BACKEND,"
3268 /* queue : current, max */
3269 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003270 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003271 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003272 /* bytes : in, out */
3273 "%lld,%lld,"
3274 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003275 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003276 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003277 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003278 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003279 "%lld,%lld,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003280 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +02003281 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003282 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +02003283 * active and backups. */
3284 "%s,"
3285 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003286 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02003287 ",%d,%d,%d,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003288 /* pid, iid, sid, throttle, lbtot, tracked, type */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003289 "%d,%d,0,,%lld,,%d,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003290 /* rate, rate_lim, rate_max, */
3291 "%u,,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003292 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003293 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02003294 px->id,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003295 px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max,
3296 px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn,
3297 px->be_counters.bytes_in, px->be_counters.bytes_out,
3298 px->be_counters.denied_req, px->be_counters.denied_resp,
3299 px->be_counters.failed_conns, px->be_counters.failed_resp,
3300 px->be_counters.retries, px->be_counters.redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +01003301 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5542af62007-12-03 02:04:00 +01003302 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01003303 px->srv_act, px->srv_bck,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003304 px->down_trans, (int)(now.tv_sec - px->last_change),
Willy Tarreau20697042007-11-15 23:26:18 +01003305 px->srv?be_downtime(px):0,
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003306 relative_pid, px->uuid,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003307 px->be_counters.cum_lbconn, STATS_TYPE_BE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003308 read_freq_ctr(&px->be_sess_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003309 px->be_counters.sps_max);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003310
3311 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3312 if (px->mode == PR_MODE_HTTP) {
3313 int i;
3314
3315 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003316 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003317
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003318 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003319 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003320 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003321 }
3322
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003323 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003324 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003325
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003326 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003327 chunk_appendf(&trash, ",,,");
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003328
Willy Tarreauae526782010-03-04 20:34:23 +01003329 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003330 chunk_appendf(&trash, "%lld,%lld,",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003331 px->be_counters.cli_aborts, px->be_counters.srv_aborts);
Willy Tarreauae526782010-03-04 20:34:23 +01003332
Willy Tarreau55058a72012-11-21 08:27:21 +01003333 /* compression: in, out, bypassed */
3334 chunk_appendf(&trash, "%lld,%lld,%lld,",
3335 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
3336
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003337 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003338 chunk_appendf(&trash, "\n");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003339
Willy Tarreau55bb8452007-10-17 18:44:57 +02003340 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003341 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02003342 return 0;
3343 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003344
Willy Tarreau295a8372011-03-10 11:25:07 +01003345 si->applet.ctx.stats.px_st = STAT_PX_ST_END;
Willy Tarreau91861262007-10-17 17:06:05 +02003346 /* fall through */
3347
Willy Tarreau295a8372011-03-10 11:25:07 +01003348 case STAT_PX_ST_END:
3349 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003350 chunk_appendf(&trash, "</table>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02003351
Willy Tarreau295a8372011-03-10 11:25:07 +01003352 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02003353 /* close the form used to enable/disable this proxy servers */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003354 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02003355 "Choose the action to perform on the checked servers : "
3356 "<select name=action>"
3357 "<option value=\"\"></option>"
3358 "<option value=\"disable\">Disable</option>"
3359 "<option value=\"enable\">Enable</option>"
Willy Tarreaud7282242012-06-04 00:22:44 +02003360 "<option value=\"stop\">Soft Stop</option>"
3361 "<option value=\"start\">Soft Start</option>"
Willy Tarreau4f8a83c2012-06-04 00:26:23 +02003362 "<option value=\"shutdown\">Kill Sessions</option>"
Cyril Bonté70be45d2010-10-12 00:14:35 +02003363 "</select>"
Cyril Bontéaa0a45d2012-04-04 12:57:20 +02003364 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
Cyril Bonté70be45d2010-10-12 00:14:35 +02003365 "&nbsp;<input type=\"submit\" value=\"Apply\">"
3366 "</form>",
Cyril Bontéaa0a45d2012-04-04 12:57:20 +02003367 px->uuid);
Cyril Bonté70be45d2010-10-12 00:14:35 +02003368 }
3369
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003370 chunk_appendf(&trash, "<p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +02003371
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003372 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02003373 return 0;
3374 }
Willy Tarreau91861262007-10-17 17:06:05 +02003375
Willy Tarreau295a8372011-03-10 11:25:07 +01003376 si->applet.ctx.stats.px_st = STAT_PX_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02003377 /* fall through */
3378
Willy Tarreau295a8372011-03-10 11:25:07 +01003379 case STAT_PX_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02003380 return 1;
3381
3382 default:
3383 /* unknown state, we should put an abort() here ! */
3384 return 1;
3385 }
3386}
3387
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003388/* This function dumps a complete session state onto the stream interface's
3389 * read buffer. The xprt_ctx must have been zeroed first, and the flags
3390 * properly set. The session has to be set in xprt_ctx.sess.target. It returns
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003391 * 0 if the output buffer is full and it needs to be called again, otherwise
3392 * non-zero. It is designed to be called from stats_dump_sess_to_buffer() below.
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003393 */
Simon Horman9bd2c732011-06-15 15:18:44 +09003394static int stats_dump_full_sess_to_buffer(struct stream_interface *si)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003395{
3396 struct tm tm;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003397 struct session *sess;
3398 extern const char *monthname[12];
3399 char pn[INET6_ADDRSTRLEN];
3400
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003401 chunk_reset(&trash);
Willy Tarreau295a8372011-03-10 11:25:07 +01003402 sess = si->applet.ctx.sess.target;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003403
Willy Tarreau295a8372011-03-10 11:25:07 +01003404 if (si->applet.ctx.sess.section > 0 && si->applet.ctx.sess.uid != sess->uniq_id) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003405 /* session changed, no need to go any further */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003406 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
3407 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003408 return 0;
Willy Tarreau295a8372011-03-10 11:25:07 +01003409 si->applet.ctx.sess.target = NULL;
3410 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003411 return 1;
3412 }
3413
Willy Tarreau295a8372011-03-10 11:25:07 +01003414 switch (si->applet.ctx.sess.section) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003415 case 0: /* main status of the session */
Willy Tarreau295a8372011-03-10 11:25:07 +01003416 si->applet.ctx.sess.uid = sess->uniq_id;
3417 si->applet.ctx.sess.section = 1;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003418 /* fall through */
3419
3420 case 1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003421 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003422 "%p: id=%u, proto=%s",
3423 sess,
3424 sess->uniq_id,
3425 sess->listener->proto->name);
3426
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003427 switch (addr_to_str(&sess->si[0].conn->addr.from, pn, sizeof(pn))) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003428 case AF_INET:
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003429 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003430 chunk_appendf(&trash, " source=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003431 pn, get_host_port(&sess->si[0].conn->addr.from));
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003432 break;
3433 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003434 chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid);
Emeric Brun837ca522010-10-22 16:19:01 +02003435 break;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003436 default:
3437 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003438 chunk_appendf(&trash, "\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003439 break;
3440 }
3441
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003442 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003443 " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n",
Willy Tarreauee28de02010-06-01 09:51:00 +02003444 sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003445
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003446 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003447 " frontend=%s (id=%u mode=%s), listener=%s (id=%u)",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003448 sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp",
3449 sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?",
3450 sess->listener ? sess->listener->luid : 0);
3451
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003452 conn_get_to_addr(sess->si[0].conn);
3453 switch (addr_to_str(&sess->si[0].conn->addr.to, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003454 case AF_INET:
3455 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003456 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003457 pn, get_host_port(&sess->si[0].conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07003458 break;
3459 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003460 chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid);
Daniel Schultze90690c72012-03-23 10:53:36 -07003461 break;
3462 default:
3463 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003464 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003465 break;
3466 }
3467
Willy Tarreau50943332011-09-02 17:33:05 +02003468 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003469 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003470 " backend=%s (id=%u mode=%s)",
Willy Tarreau50943332011-09-02 17:33:05 +02003471 sess->be->id,
Daniel Schultze90690c72012-03-23 10:53:36 -07003472 sess->be->uuid, sess->be->mode ? "http" : "tcp");
3473 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003474 chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)");
Daniel Schultze90690c72012-03-23 10:53:36 -07003475
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003476 conn_get_from_addr(sess->si[1].conn);
3477 switch (addr_to_str(&sess->si[1].conn->addr.from, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003478 case AF_INET:
3479 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003480 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003481 pn, get_host_port(&sess->si[1].conn->addr.from));
Daniel Schultze90690c72012-03-23 10:53:36 -07003482 break;
3483 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003484 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003485 break;
3486 default:
3487 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003488 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003489 break;
3490 }
3491
3492 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003493 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003494 " server=%s (id=%u)",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003495 objt_server(sess->target) ? objt_server(sess->target)->id : "<none>",
3496 objt_server(sess->target) ? objt_server(sess->target)->puid : 0);
Willy Tarreau50943332011-09-02 17:33:05 +02003497 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003498 chunk_appendf(&trash, " server=<NONE> (id=-1)");
Daniel Schultze90690c72012-03-23 10:53:36 -07003499
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003500 conn_get_to_addr(sess->si[1].conn);
3501 switch (addr_to_str(&sess->si[1].conn->addr.to, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003502 case AF_INET:
3503 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003504 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003505 pn, get_host_port(&sess->si[1].conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07003506 break;
3507 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003508 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003509 break;
3510 default:
3511 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003512 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003513 break;
3514 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003515
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003516 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003517 " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s)\n",
3518 sess->task,
3519 sess->task->state,
3520 sess->task->nice, sess->task->calls,
3521 sess->task->expire ?
3522 tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" :
3523 human_time(TICKS_TO_MS(sess->task->expire - now_ms),
3524 TICKS_TO_MS(1000)) : "<NEVER>",
3525 task_in_rq(sess->task) ? ", running" : "");
3526
3527 get_localtime(sess->logs.accept_date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003528 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003529 " task created [%02d/%s/%04d:%02d:%02d:%02d.%06d] (age=%s)\n",
3530 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
3531 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec),
3532 human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1));
3533
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003534 chunk_appendf(&trash,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003535 " si[0]=%p (state=%d flags=0x%02x conn=%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003536 &sess->si[0],
3537 sess->si[0].state,
3538 sess->si[0].flags,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003539 sess->si[0].conn,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003540 sess->si[0].exp ?
3541 tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" :
3542 human_time(TICKS_TO_MS(sess->si[0].exp - now_ms),
3543 TICKS_TO_MS(1000)) : "<NEVER>",
3544 sess->si[0].err_type);
3545
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003546 chunk_appendf(&trash,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003547 " si[1]=%p (state=%d flags=0x%02x conn=%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003548 &sess->si[1],
3549 sess->si[1].state,
3550 sess->si[1].flags,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003551 sess->si[1].conn,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003552 sess->si[1].exp ?
3553 tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" :
3554 human_time(TICKS_TO_MS(sess->si[1].exp - now_ms),
3555 TICKS_TO_MS(1000)) : "<NEVER>",
3556 sess->si[1].err_type);
3557
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003558 chunk_appendf(&trash,
Willy Tarreau1feca012012-11-19 18:15:19 +01003559 " 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 +01003560 sess->si[0].conn,
3561 sess->si[0].conn->ctrl,
3562 sess->si[0].conn->ctrl ? sess->si[0].conn->ctrl->name : "NONE",
3563 sess->si[0].conn->xprt,
3564 (sess->si[0].conn->xprt == NULL) ? "NONE" :
3565 (sess->si[0].conn->xprt == &raw_sock) ? "RAW" :
3566#ifdef USE_OPENSSL
3567 (sess->si[0].conn->xprt == &ssl_sock) ? "SSL" :
3568#endif
3569 "????",
3570 sess->si[0].conn->data,
3571 (sess->si[0].conn->data == NULL) ? "NONE" :
3572 (sess->si[0].conn->data == &sess_conn_cb) ? "SESS" :
3573 (sess->si[0].conn->data == &si_conn_cb) ? "STRM" :
3574 (sess->si[0].conn->data == &check_conn_cb) ? "CHCK" : "????",
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003575 sess->si[0].conn->target ? *sess->si[0].conn->target : 0,
Willy Tarreau1feca012012-11-19 18:15:19 +01003576 sess->si[0].conn->flags,
3577 sess->si[0].conn->t.sock.fd,
3578 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 +01003579
3580 chunk_appendf(&trash,
Willy Tarreau1feca012012-11-19 18:15:19 +01003581 " 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 +01003582 sess->si[1].conn,
3583 sess->si[1].conn->ctrl,
3584 sess->si[1].conn->ctrl ? sess->si[1].conn->ctrl->name : "NONE",
3585 sess->si[1].conn->xprt,
3586 (sess->si[1].conn->xprt == NULL) ? "NONE" :
3587 (sess->si[1].conn->xprt == &raw_sock) ? "RAW" :
3588#ifdef USE_OPENSSL
3589 (sess->si[1].conn->xprt == &ssl_sock) ? "SSL" :
3590#endif
3591 "UNKNOWN",
3592 sess->si[1].conn->data,
3593 (sess->si[1].conn->data == NULL) ? "NONE" :
3594 (sess->si[1].conn->data == &sess_conn_cb) ? "SESS" :
3595 (sess->si[1].conn->data == &si_conn_cb) ? "STRM" :
3596 (sess->si[1].conn->data == &check_conn_cb) ? "CHCK" : "????",
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003597 sess->si[1].conn->target ? *sess->si[1].conn->target : 0,
Willy Tarreau1feca012012-11-19 18:15:19 +01003598 sess->si[1].conn->flags,
3599 sess->si[1].conn->t.sock.fd,
3600 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 +01003601
3602 chunk_appendf(&trash,
Willy Tarreaue6d97022012-11-23 11:19:33 +01003603 " txn=%p (flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003604 &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status,
Willy Tarreaue6d97022012-11-23 11:19:33 +01003605 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 +01003606
3607
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003608 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003609 " req=%p (f=0x%06x an=0x%x i=%d o=%d pipe=%d fwd=%d)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003610 " an_exp=%s",
3611 sess->req,
3612 sess->req->flags, sess->req->analysers,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003613 sess->req->buf->i, sess->req->buf->o,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003614 sess->req->pipe ? sess->req->pipe->data : 0,
3615 sess->req->to_forward,
3616 sess->req->analyse_exp ?
3617 human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms),
3618 TICKS_TO_MS(1000)) : "<NEVER>");
3619
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003620 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003621 " rex=%s",
3622 sess->req->rex ?
3623 human_time(TICKS_TO_MS(sess->req->rex - now_ms),
3624 TICKS_TO_MS(1000)) : "<NEVER>");
3625
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003626 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003627 " wex=%s\n"
Willy Tarreaua458b672012-03-05 11:17:50 +01003628 " data=%p p=%d next=%d total=%lld\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003629 sess->req->wex ?
3630 human_time(TICKS_TO_MS(sess->req->wex - now_ms),
3631 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau9b28e032012-10-12 23:49:43 +02003632 sess->req->buf->data,
3633 (int)(sess->req->buf->p - sess->req->buf->data),
Willy Tarreaua458b672012-03-05 11:17:50 +01003634 sess->txn.req.next,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003635 sess->req->total);
3636
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003637 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003638 " res=%p (f=0x%06x an=0x%x i=%d o=%d pipe=%d fwd=%d)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003639 " an_exp=%s",
3640 sess->rep,
3641 sess->rep->flags, sess->rep->analysers,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003642 sess->rep->buf->i, sess->rep->buf->o,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003643 sess->rep->pipe ? sess->rep->pipe->data : 0,
3644 sess->rep->to_forward,
3645 sess->rep->analyse_exp ?
3646 human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms),
3647 TICKS_TO_MS(1000)) : "<NEVER>");
3648
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003649 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003650 " rex=%s",
3651 sess->rep->rex ?
3652 human_time(TICKS_TO_MS(sess->rep->rex - now_ms),
3653 TICKS_TO_MS(1000)) : "<NEVER>");
3654
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003655 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003656 " wex=%s\n"
Willy Tarreaua458b672012-03-05 11:17:50 +01003657 " data=%p p=%d next=%d total=%lld\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003658 sess->rep->wex ?
3659 human_time(TICKS_TO_MS(sess->rep->wex - now_ms),
3660 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau9b28e032012-10-12 23:49:43 +02003661 sess->rep->buf->data,
3662 (int)(sess->rep->buf->p - sess->rep->buf->data),
Willy Tarreaua458b672012-03-05 11:17:50 +01003663 sess->txn.rsp.next,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003664 sess->rep->total);
3665
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003666 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003667 return 0;
3668
3669 /* use other states to dump the contents */
3670 }
3671 /* end of dump */
Willy Tarreau295a8372011-03-10 11:25:07 +01003672 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003673 return 1;
3674}
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003675
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003676/* This function dumps all sessions' states onto the stream interface's
3677 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003678 * properly set. It returns 0 if the output buffer is full and it needs
3679 * to be called again, otherwise non-zero. It is designed to be called
3680 * from stats_dump_sess_to_buffer() below.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003681 */
Simon Horman9bd2c732011-06-15 15:18:44 +09003682static int stats_dump_sess_to_buffer(struct stream_interface *si)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003683{
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02003684 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003685 /* If we're forced to shut down, we might have to remove our
3686 * reference to the last session being dumped.
3687 */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003688 if (si->conn->xprt_st == STAT_ST_LIST) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003689 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) {
3690 LIST_DEL(&si->applet.ctx.sess.bref.users);
3691 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003692 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003693 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003694 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003695 }
3696
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003697 chunk_reset(&trash);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003698
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003699 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003700 case STAT_ST_INIT:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003701 /* the function had not been called yet, let's prepare the
3702 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003703 * pointer to the first in the global list. When a target
3704 * session is being destroyed, it is responsible for updating
3705 * this pointer. We know we have reached the end when this
3706 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003707 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003708 LIST_INIT(&si->applet.ctx.sess.bref.users);
3709 si->applet.ctx.sess.bref.ref = sessions.n;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003710 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003711 /* fall through */
3712
Willy Tarreau295a8372011-03-10 11:25:07 +01003713 case STAT_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003714 /* first, let's detach the back-ref from a possible previous session */
Willy Tarreau295a8372011-03-10 11:25:07 +01003715 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) {
3716 LIST_DEL(&si->applet.ctx.sess.bref.users);
3717 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003718 }
3719
3720 /* and start from where we stopped */
Willy Tarreau295a8372011-03-10 11:25:07 +01003721 while (si->applet.ctx.sess.bref.ref != &sessions) {
Cyril Bontéacd7d632010-11-01 19:26:02 +01003722 char pn[INET6_ADDRSTRLEN];
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003723 struct session *curr_sess;
3724
Willy Tarreau295a8372011-03-10 11:25:07 +01003725 curr_sess = LIST_ELEM(si->applet.ctx.sess.bref.ref, struct session *, list);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003726
Willy Tarreau295a8372011-03-10 11:25:07 +01003727 if (si->applet.ctx.sess.target) {
3728 if (si->applet.ctx.sess.target != curr_sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003729 goto next_sess;
3730
Willy Tarreau295a8372011-03-10 11:25:07 +01003731 LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003732 /* call the proper dump() function and return if we're missing space */
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003733 if (!stats_dump_full_sess_to_buffer(si))
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003734 return 0;
3735
3736 /* session dump complete */
Willy Tarreau295a8372011-03-10 11:25:07 +01003737 LIST_DEL(&si->applet.ctx.sess.bref.users);
3738 LIST_INIT(&si->applet.ctx.sess.bref.users);
3739 si->applet.ctx.sess.target = NULL;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003740 break;
3741 }
3742
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003743 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003744 "%p: proto=%s",
3745 curr_sess,
3746 curr_sess->listener->proto->name);
3747
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003748
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003749 switch (addr_to_str(&curr_sess->si[0].conn->addr.from, pn, sizeof(pn))) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02003750 case AF_INET:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003751 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003752 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003753 " src=%s:%d fe=%s be=%s srv=%s",
3754 pn,
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003755 get_host_port(&curr_sess->si[0].conn->addr.from),
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003756 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02003757 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003758 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003759 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003760 break;
3761 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003762 chunk_appendf(&trash,
Emeric Brun837ca522010-10-22 16:19:01 +02003763 " src=unix:%d fe=%s be=%s srv=%s",
3764 curr_sess->listener->luid,
3765 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02003766 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003767 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Emeric Brun837ca522010-10-22 16:19:01 +02003768 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003769 break;
3770 }
3771
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003772 chunk_appendf(&trash,
Willy Tarreau65671ab2009-10-04 14:24:59 +02003773 " ts=%02x age=%s calls=%d",
3774 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01003775 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
3776 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003777
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003778 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003779 " rq[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003780 curr_sess->req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003781 curr_sess->req->buf->i,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003782 curr_sess->req->analysers,
3783 curr_sess->req->rex ?
3784 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
3785 TICKS_TO_MS(1000)) : "");
3786
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003787 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003788 ",wx=%s",
3789 curr_sess->req->wex ?
3790 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
3791 TICKS_TO_MS(1000)) : "");
3792
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003793 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003794 ",ax=%s]",
3795 curr_sess->req->analyse_exp ?
3796 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
3797 TICKS_TO_MS(1000)) : "");
3798
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003799 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003800 " rp[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003801 curr_sess->rep->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003802 curr_sess->rep->buf->i,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003803 curr_sess->rep->analysers,
3804 curr_sess->rep->rex ?
3805 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
3806 TICKS_TO_MS(1000)) : "");
3807
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003808 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003809 ",wx=%s",
3810 curr_sess->rep->wex ?
3811 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
3812 TICKS_TO_MS(1000)) : "");
3813
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003814 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003815 ",ax=%s]",
3816 curr_sess->rep->analyse_exp ?
3817 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
3818 TICKS_TO_MS(1000)) : "");
3819
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003820 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003821 " s0=[%d,%1xh,fd=%d,ex=%s]",
3822 curr_sess->si[0].state,
3823 curr_sess->si[0].flags,
Willy Tarreau7f7ad912012-11-11 19:27:15 +01003824 curr_sess->si[0].conn->t.sock.fd,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003825 curr_sess->si[0].exp ?
3826 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
3827 TICKS_TO_MS(1000)) : "");
3828
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003829 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003830 " s1=[%d,%1xh,fd=%d,ex=%s]",
3831 curr_sess->si[1].state,
3832 curr_sess->si[1].flags,
Willy Tarreau7f7ad912012-11-11 19:27:15 +01003833 curr_sess->si[1].conn->t.sock.fd,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003834 curr_sess->si[1].exp ?
3835 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
3836 TICKS_TO_MS(1000)) : "");
3837
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003838 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003839 " exp=%s",
3840 curr_sess->task->expire ?
3841 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
3842 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01003843 if (task_in_rq(curr_sess->task))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003844 chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003845
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003846 chunk_appendf(&trash, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003847
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003848 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003849 /* let's try again later from this session. We add ourselves into
3850 * this session's users so that it can remove us upon termination.
3851 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003852 LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003853 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003854 }
3855
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003856 next_sess:
Willy Tarreau295a8372011-03-10 11:25:07 +01003857 si->applet.ctx.sess.bref.ref = curr_sess->list.n;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003858 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003859
Willy Tarreau295a8372011-03-10 11:25:07 +01003860 if (si->applet.ctx.sess.target) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003861 /* specified session not found */
Willy Tarreau295a8372011-03-10 11:25:07 +01003862 if (si->applet.ctx.sess.section > 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003863 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003864 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003865 chunk_appendf(&trash, "Session not found.\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003866
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003867 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003868 return 0;
3869
Willy Tarreau295a8372011-03-10 11:25:07 +01003870 si->applet.ctx.sess.target = NULL;
3871 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003872 return 1;
3873 }
3874
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003875 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003876 /* fall through */
3877
3878 default:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003879 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003880 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003881 }
Emeric Brun1e029aa2010-09-23 18:12:53 +02003882}
3883
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003884/* This function dumps all tables' states onto the stream interface's
3885 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003886 * properly set. It returns 0 if the output buffer is full and it needs
3887 * to be called again, otherwise non-zero.
Willy Tarreau69f58c82010-07-12 17:55:33 +02003888 */
Simon Hormanc88b8872011-06-15 15:18:49 +09003889static int stats_table_request(struct stream_interface *si, bool show)
Willy Tarreau69f58c82010-07-12 17:55:33 +02003890{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003891 struct session *s = si->conn->xprt_ctx;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003892 struct ebmb_node *eb;
3893 int dt;
Simon Hormanc88b8872011-06-15 15:18:49 +09003894 bool skip_entry;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003895
3896 /*
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003897 * We have 3 possible states in si->conn->xprt_st :
Willy Tarreau295a8372011-03-10 11:25:07 +01003898 * - STAT_ST_INIT : the first call
3899 * - STAT_ST_INFO : the proxy pointer points to the next table to
Willy Tarreau69f58c82010-07-12 17:55:33 +02003900 * dump, the entry pointer is NULL ;
Willy Tarreau295a8372011-03-10 11:25:07 +01003901 * - STAT_ST_LIST : the proxy pointer points to the current table
Willy Tarreau69f58c82010-07-12 17:55:33 +02003902 * and the entry pointer points to the next entry to be dumped,
3903 * and the refcount on the next entry is held ;
Willy Tarreau295a8372011-03-10 11:25:07 +01003904 * - STAT_ST_END : nothing left to dump, the buffer may contain some
Willy Tarreau69f58c82010-07-12 17:55:33 +02003905 * data though.
3906 */
3907
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02003908 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02003909 /* in case of abort, remove any refcount we might have set on an entry */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003910 if (si->conn->xprt_st == STAT_ST_LIST) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003911 si->applet.ctx.table.entry->ref_cnt--;
3912 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
Willy Tarreauf6efda12010-08-03 20:34:06 +02003913 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02003914 return 1;
3915 }
3916
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003917 chunk_reset(&trash);
Willy Tarreau69f58c82010-07-12 17:55:33 +02003918
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003919 while (si->conn->xprt_st != STAT_ST_FIN) {
3920 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003921 case STAT_ST_INIT:
3922 si->applet.ctx.table.proxy = si->applet.ctx.table.target;
3923 if (!si->applet.ctx.table.proxy)
3924 si->applet.ctx.table.proxy = proxy;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003925
Willy Tarreau295a8372011-03-10 11:25:07 +01003926 si->applet.ctx.table.entry = NULL;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003927 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003928 break;
3929
Willy Tarreau295a8372011-03-10 11:25:07 +01003930 case STAT_ST_INFO:
3931 if (!si->applet.ctx.table.proxy ||
3932 (si->applet.ctx.table.target &&
3933 si->applet.ctx.table.proxy != si->applet.ctx.table.target)) {
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003934 si->conn->xprt_st = STAT_ST_END;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003935 break;
3936 }
3937
Willy Tarreau295a8372011-03-10 11:25:07 +01003938 if (si->applet.ctx.table.proxy->table.size) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003939 if (show && !stats_dump_table_head_to_buffer(&trash, si, si->applet.ctx.table.proxy,
Simon Hormanc88b8872011-06-15 15:18:49 +09003940 si->applet.ctx.table.target))
Willy Tarreau69f58c82010-07-12 17:55:33 +02003941 return 0;
3942
Willy Tarreau295a8372011-03-10 11:25:07 +01003943 if (si->applet.ctx.table.target &&
Willy Tarreau290e63a2012-09-20 18:07:14 +02003944 s->listener->bind_conf->level >= ACCESS_LVL_OPER) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02003945 /* dump entries only if table explicitly requested */
Willy Tarreau295a8372011-03-10 11:25:07 +01003946 eb = ebmb_first(&si->applet.ctx.table.proxy->table.keys);
Willy Tarreau69f58c82010-07-12 17:55:33 +02003947 if (eb) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003948 si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key);
3949 si->applet.ctx.table.entry->ref_cnt++;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003950 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003951 break;
3952 }
3953 }
3954 }
Willy Tarreau295a8372011-03-10 11:25:07 +01003955 si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003956 break;
3957
Willy Tarreau295a8372011-03-10 11:25:07 +01003958 case STAT_ST_LIST:
Simon Hormanc88b8872011-06-15 15:18:49 +09003959 skip_entry = false;
3960
Willy Tarreau295a8372011-03-10 11:25:07 +01003961 if (si->applet.ctx.table.data_type >= 0) {
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003962 /* we're filtering on some data contents */
3963 void *ptr;
3964 long long data;
3965
Willy Tarreau295a8372011-03-10 11:25:07 +01003966 dt = si->applet.ctx.table.data_type;
3967 ptr = stktable_data_ptr(&si->applet.ctx.table.proxy->table,
3968 si->applet.ctx.table.entry,
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003969 dt);
3970
3971 data = 0;
3972 switch (stktable_data_types[dt].std_type) {
3973 case STD_T_SINT:
3974 data = stktable_data_cast(ptr, std_t_sint);
3975 break;
3976 case STD_T_UINT:
3977 data = stktable_data_cast(ptr, std_t_uint);
3978 break;
3979 case STD_T_ULL:
3980 data = stktable_data_cast(ptr, std_t_ull);
3981 break;
3982 case STD_T_FRQP:
3983 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Willy Tarreau295a8372011-03-10 11:25:07 +01003984 si->applet.ctx.table.proxy->table.data_arg[dt].u);
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003985 break;
3986 }
3987
3988 /* skip the entry if the data does not match the test and the value */
Willy Tarreau295a8372011-03-10 11:25:07 +01003989 if ((data < si->applet.ctx.table.value &&
3990 (si->applet.ctx.table.data_op == STD_OP_EQ ||
3991 si->applet.ctx.table.data_op == STD_OP_GT ||
3992 si->applet.ctx.table.data_op == STD_OP_GE)) ||
3993 (data == si->applet.ctx.table.value &&
3994 (si->applet.ctx.table.data_op == STD_OP_NE ||
3995 si->applet.ctx.table.data_op == STD_OP_GT ||
3996 si->applet.ctx.table.data_op == STD_OP_LT)) ||
3997 (data > si->applet.ctx.table.value &&
3998 (si->applet.ctx.table.data_op == STD_OP_EQ ||
3999 si->applet.ctx.table.data_op == STD_OP_LT ||
4000 si->applet.ctx.table.data_op == STD_OP_LE)))
Simon Hormanc88b8872011-06-15 15:18:49 +09004001 skip_entry = true;
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02004002 }
4003
Simon Hormanc88b8872011-06-15 15:18:49 +09004004 if (show && !skip_entry &&
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004005 !stats_dump_table_entry_to_buffer(&trash, si, si->applet.ctx.table.proxy,
Simon Hormand9366582011-06-15 15:18:45 +09004006 si->applet.ctx.table.entry))
4007 return 0;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004008
Willy Tarreau295a8372011-03-10 11:25:07 +01004009 si->applet.ctx.table.entry->ref_cnt--;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004010
Willy Tarreau295a8372011-03-10 11:25:07 +01004011 eb = ebmb_next(&si->applet.ctx.table.entry->key);
Willy Tarreau69f58c82010-07-12 17:55:33 +02004012 if (eb) {
Willy Tarreau295a8372011-03-10 11:25:07 +01004013 struct stksess *old = si->applet.ctx.table.entry;
4014 si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key);
Willy Tarreau8fa52f42012-01-09 11:50:03 +01004015 if (show)
4016 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, old);
4017 else
4018 stksess_kill(&si->applet.ctx.table.proxy->table, old);
Willy Tarreau295a8372011-03-10 11:25:07 +01004019 si->applet.ctx.table.entry->ref_cnt++;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004020 break;
4021 }
4022
Simon Hormanc88b8872011-06-15 15:18:49 +09004023
4024 if (show)
4025 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
4026 else if (!skip_entry && !si->applet.ctx.table.entry->ref_cnt)
4027 stksess_kill(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
4028
Willy Tarreau295a8372011-03-10 11:25:07 +01004029 si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004030 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004031 break;
4032
Willy Tarreau295a8372011-03-10 11:25:07 +01004033 case STAT_ST_END:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004034 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004035 break;
4036 }
4037 }
4038 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01004039}
4040
Willy Tarreaud426a182010-03-05 14:58:26 +01004041/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
Willy Tarreau74808cb2009-03-04 15:53:18 +01004042 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
4043 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
4044 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
4045 * lines are respected within the limit of 70 output chars. Lines that are
4046 * continuation of a previous truncated line begin with "+" instead of " "
4047 * after the offset. The new pointer is returned.
4048 */
Willy Tarreaud426a182010-03-05 14:58:26 +01004049static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
4050 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004051{
4052 int end;
4053 unsigned char c;
4054
4055 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02004056 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004057 return ptr;
4058
Willy Tarreau77804732012-10-29 16:14:26 +01004059 chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01004060
Willy Tarreaud426a182010-03-05 14:58:26 +01004061 while (ptr < len && ptr < bsize) {
4062 c = buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01004063 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004064 if (out->len > end - 2)
4065 break;
4066 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01004067 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004068 if (out->len > end - 3)
4069 break;
4070 out->str[out->len++] = '\\';
4071 switch (c) {
4072 case '\t': c = 't'; break;
4073 case '\n': c = 'n'; break;
4074 case '\r': c = 'r'; break;
4075 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01004076 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004077 }
4078 out->str[out->len++] = c;
4079 } else {
4080 if (out->len > end - 5)
4081 break;
4082 out->str[out->len++] = '\\';
4083 out->str[out->len++] = 'x';
4084 out->str[out->len++] = hextab[(c >> 4) & 0xF];
4085 out->str[out->len++] = hextab[c & 0xF];
4086 }
Willy Tarreaud426a182010-03-05 14:58:26 +01004087 if (buf[ptr++] == '\n') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004088 /* we had a line break, let's return now */
4089 out->str[out->len++] = '\n';
4090 *line = ptr;
4091 return ptr;
4092 }
4093 }
4094 /* we have an incomplete line, we return it as-is */
4095 out->str[out->len++] = '\n';
4096 return ptr;
4097}
4098
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02004099/* This function dumps all captured errors onto the stream interface's
4100 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01004101 * properly set. It returns 0 if the output buffer is full and it needs
4102 * to be called again, otherwise non-zero.
Willy Tarreau74808cb2009-03-04 15:53:18 +01004103 */
Simon Horman9bd2c732011-06-15 15:18:44 +09004104static int stats_dump_errors_to_buffer(struct stream_interface *si)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004105{
4106 extern const char *monthname[12];
Willy Tarreau74808cb2009-03-04 15:53:18 +01004107
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02004108 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW)))
Willy Tarreau61b34732009-10-03 23:49:35 +02004109 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004110
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004111 chunk_reset(&trash);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004112
Willy Tarreau295a8372011-03-10 11:25:07 +01004113 if (!si->applet.ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004114 /* the function had not been called yet, let's prepare the
4115 * buffer for a response.
4116 */
Willy Tarreau10479e42010-12-12 14:00:34 +01004117 struct tm tm;
4118
4119 get_localtime(date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004120 chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n",
Willy Tarreau10479e42010-12-12 14:00:34 +01004121 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
4122 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000),
4123 error_snapshot_id);
4124
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004125 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau10479e42010-12-12 14:00:34 +01004126 /* Socket buffer full. Let's try again later from the same point */
4127 return 0;
4128 }
4129
Willy Tarreau295a8372011-03-10 11:25:07 +01004130 si->applet.ctx.errors.px = proxy;
4131 si->applet.ctx.errors.buf = 0;
4132 si->applet.ctx.errors.bol = 0;
4133 si->applet.ctx.errors.ptr = -1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004134 }
4135
4136 /* we have two inner loops here, one for the proxy, the other one for
4137 * the buffer.
4138 */
Willy Tarreau295a8372011-03-10 11:25:07 +01004139 while (si->applet.ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004140 struct error_snapshot *es;
4141
Willy Tarreau295a8372011-03-10 11:25:07 +01004142 if (si->applet.ctx.errors.buf == 0)
4143 es = &si->applet.ctx.errors.px->invalid_req;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004144 else
Willy Tarreau295a8372011-03-10 11:25:07 +01004145 es = &si->applet.ctx.errors.px->invalid_rep;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004146
4147 if (!es->when.tv_sec)
4148 goto next;
4149
Willy Tarreau295a8372011-03-10 11:25:07 +01004150 if (si->applet.ctx.errors.iid >= 0 &&
4151 si->applet.ctx.errors.px->uuid != si->applet.ctx.errors.iid &&
4152 es->oe->uuid != si->applet.ctx.errors.iid)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004153 goto next;
4154
Willy Tarreau295a8372011-03-10 11:25:07 +01004155 if (si->applet.ctx.errors.ptr < 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004156 /* just print headers now */
4157
4158 char pn[INET6_ADDRSTRLEN];
4159 struct tm tm;
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004160 int port;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004161
4162 get_localtime(es->when.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004163 chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01004164 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02004165 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01004166
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004167 switch (addr_to_str(&es->src, pn, sizeof(pn))) {
4168 case AF_INET:
4169 case AF_INET6:
4170 port = get_host_port(&es->src);
4171 break;
4172 default:
4173 port = 0;
4174 }
4175
Willy Tarreau295a8372011-03-10 11:25:07 +01004176 switch (si->applet.ctx.errors.buf) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004177 case 0:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004178 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004179 " frontend %s (#%d): invalid request\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004180 " backend %s (#%d)",
Willy Tarreau295a8372011-03-10 11:25:07 +01004181 si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004182 (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
4183 (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004184 break;
4185 case 1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004186 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004187 " backend %s (#%d) : invalid response\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004188 " frontend %s (#%d)",
Willy Tarreau295a8372011-03-10 11:25:07 +01004189 si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004190 es->oe->id, es->oe->uuid);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004191 break;
4192 }
4193
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004194 chunk_appendf(&trash,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004195 ", server %s (#%d), event #%u\n"
4196 " src %s:%d, session #%d, session flags 0x%08x\n"
4197 " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n"
4198 " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n"
4199 " buffer flags 0x%08x, out %d bytes, total %lld bytes\n"
4200 " pending %d bytes, wrapping at %d, error at position %d:\n \n",
4201 es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1,
4202 es->ev_id,
4203 pn, port, es->sid, es->s_flags,
4204 es->state, es->m_flags, es->t_flags,
4205 es->m_clen, es->m_blen,
4206 es->b_flags, es->b_out, es->b_tot,
4207 es->len, es->b_wrap, es->pos);
4208
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004209 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004210 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02004211 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004212 }
Willy Tarreau295a8372011-03-10 11:25:07 +01004213 si->applet.ctx.errors.ptr = 0;
4214 si->applet.ctx.errors.sid = es->sid;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004215 }
4216
Willy Tarreau295a8372011-03-10 11:25:07 +01004217 if (si->applet.ctx.errors.sid != es->sid) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004218 /* the snapshot changed while we were dumping it */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004219 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004220 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004221 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau61b34732009-10-03 23:49:35 +02004222 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004223 goto next;
4224 }
4225
4226 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau295a8372011-03-10 11:25:07 +01004227 while (si->applet.ctx.errors.ptr < es->len && si->applet.ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004228 int newptr;
4229 int newline;
4230
Willy Tarreau295a8372011-03-10 11:25:07 +01004231 newline = si->applet.ctx.errors.bol;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004232 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 +01004233 if (newptr == si->applet.ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02004234 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004235
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004236 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004237 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02004238 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004239 }
Willy Tarreau295a8372011-03-10 11:25:07 +01004240 si->applet.ctx.errors.ptr = newptr;
4241 si->applet.ctx.errors.bol = newline;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004242 };
4243 next:
Willy Tarreau295a8372011-03-10 11:25:07 +01004244 si->applet.ctx.errors.bol = 0;
4245 si->applet.ctx.errors.ptr = -1;
4246 si->applet.ctx.errors.buf++;
4247 if (si->applet.ctx.errors.buf > 1) {
4248 si->applet.ctx.errors.buf = 0;
4249 si->applet.ctx.errors.px = si->applet.ctx.errors.px->next;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004250 }
4251 }
4252
4253 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02004254 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004255}
4256
Willy Tarreaud5781202012-09-22 19:32:35 +02004257/* parse the "level" argument on the bind lines */
4258static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
4259{
4260 if (!*args[cur_arg + 1]) {
4261 memprintf(err, "'%s' : missing level", args[cur_arg]);
4262 return ERR_ALERT | ERR_FATAL;
4263 }
4264
4265 if (!strcmp(args[cur_arg+1], "user"))
4266 conf->level = ACCESS_LVL_USER;
4267 else if (!strcmp(args[cur_arg+1], "operator"))
4268 conf->level = ACCESS_LVL_OPER;
4269 else if (!strcmp(args[cur_arg+1], "admin"))
4270 conf->level = ACCESS_LVL_ADMIN;
4271 else {
4272 memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')",
4273 args[cur_arg], args[cur_arg+1]);
4274 return ERR_ALERT | ERR_FATAL;
4275 }
4276
4277 return 0;
4278}
4279
Willy Tarreaub24281b2011-02-13 13:16:36 +01004280struct si_applet http_stats_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01004281 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004282 .name = "<STATS>", /* used for logging */
4283 .fct = http_stats_io_handler,
Aman Gupta9a13e842012-04-02 18:57:53 -07004284 .release = NULL,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004285};
4286
Simon Horman9bd2c732011-06-15 15:18:44 +09004287static struct si_applet cli_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01004288 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004289 .name = "<CLI>", /* used for logging */
4290 .fct = cli_io_handler,
Aman Gupta9a13e842012-04-02 18:57:53 -07004291 .release = NULL,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004292};
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01004293
Willy Tarreau10522fd2008-07-09 20:12:41 +02004294static struct cfg_kw_list cfg_kws = {{ },{
4295 { CFG_GLOBAL, "stats", stats_parse_global },
4296 { 0, NULL, NULL },
4297}};
4298
Willy Tarreaud5781202012-09-22 19:32:35 +02004299static struct bind_kw_list bind_kws = { "STAT", { }, {
4300 { "level", bind_parse_level, 1 }, /* set the unix socket admin level */
4301 { NULL, NULL, 0 },
4302}};
4303
Willy Tarreau10522fd2008-07-09 20:12:41 +02004304__attribute__((constructor))
4305static void __dumpstats_module_init(void)
4306{
4307 cfg_register_keywords(&cfg_kws);
Willy Tarreaud5781202012-09-22 19:32:35 +02004308 bind_register_keywords(&bind_kws);
Willy Tarreau10522fd2008-07-09 20:12:41 +02004309}
4310
Willy Tarreau91861262007-10-17 17:06:05 +02004311/*
4312 * Local variables:
4313 * c-indent-level: 8
4314 * c-basic-offset: 8
4315 * End:
4316 */