blob: 31d24b0db554d9f84efd7d0a7482af1359a87316 [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>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020020#include <pwd.h>
21#include <grp.h>
Willy Tarreau91861262007-10-17 17:06:05 +020022
23#include <sys/socket.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26
Willy Tarreau10522fd2008-07-09 20:12:41 +020027#include <common/cfgparse.h>
Willy Tarreau91861262007-10-17 17:06:05 +020028#include <common/compat.h>
29#include <common/config.h>
30#include <common/debug.h>
31#include <common/memory.h>
32#include <common/mini-clist.h>
33#include <common/standard.h>
Willy Tarreau0c303ee2008-07-07 00:09:58 +020034#include <common/ticks.h>
Willy Tarreau91861262007-10-17 17:06:05 +020035#include <common/time.h>
36#include <common/uri_auth.h>
37#include <common/version.h>
38
Willy Tarreau91861262007-10-17 17:06:05 +020039#include <types/global.h>
Willy Tarreau91861262007-10-17 17:06:05 +020040
41#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020042#include <proto/channel.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020043#include <proto/checks.h>
William Lallemande3a7d992012-11-20 11:25:20 +010044#include <proto/compression.h>
Willy Tarreau91861262007-10-17 17:06:05 +020045#include <proto/dumpstats.h>
46#include <proto/fd.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010047#include <proto/freq_ctr.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020048#include <proto/log.h>
Willy Tarreaua206fa92009-01-25 14:02:00 +010049#include <proto/pipe.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020050#include <proto/listener.h>
Willy Tarreaue6d97022012-11-23 11:19:33 +010051#include <proto/proto_http.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020052#include <proto/proto_uxst.h>
Willy Tarreau89a63132009-08-16 17:41:45 +020053#include <proto/proxy.h>
Willy Tarreau91861262007-10-17 17:06:05 +020054#include <proto/session.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020055#include <proto/server.h>
Willy Tarreau75bf2c92012-08-20 17:01:35 +020056#include <proto/raw_sock.h>
Willy Tarreaudded32d2008-11-30 19:48:07 +010057#include <proto/stream_interface.h>
Willy Tarreau4726f532009-03-07 17:25:21 +010058#include <proto/task.h>
Willy Tarreau91861262007-10-17 17:06:05 +020059
Willy Tarreau7a0169a2012-11-19 17:13:16 +010060#ifdef USE_OPENSSL
61#include <proto/ssl_sock.h>
62#endif
63
Simon Horman9bd2c732011-06-15 15:18:44 +090064static int stats_dump_raw_to_buffer(struct stream_interface *si);
Willy Tarreau76153662012-11-26 01:16:39 +010065static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess);
Simon Horman9bd2c732011-06-15 15:18:44 +090066static int stats_dump_sess_to_buffer(struct stream_interface *si);
67static int stats_dump_errors_to_buffer(struct stream_interface *si);
Willy Tarreau44455022012-12-05 23:01:12 +010068static int stats_table_request(struct stream_interface *si, int show);
Simon Horman9bd2c732011-06-15 15:18:44 +090069static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struct uri_auth *uri);
70static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri);
71
72static struct si_applet cli_applet;
73
74static const char stats_sock_usage_msg[] =
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020075 "Unknown command. Please enter one of the following commands only :\n"
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +020076 " clear counters : clear max statistics counters (add 'all' for all counters)\n"
Willy Tarreau88ee3972010-07-13 13:48:00 +020077 " clear table : remove an entry from a table\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020078 " help : this message\n"
79 " prompt : toggle interactive mode with prompt\n"
80 " quit : disconnect\n"
81 " show info : report information about the running process\n"
82 " show stat : report counters for each proxy and server\n"
83 " show errors : report last request and response errors for each proxy\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +010084 " show sess [id] : report the list of current sessions or dump this session\n"
Willy Tarreau69f58c82010-07-12 17:55:33 +020085 " show table [id]: report table usage stats or dump this table's contents\n"
Willy Tarreau38338fa2009-10-10 18:37:29 +020086 " get weight : report a server's current weight\n"
Willy Tarreau4483d432009-10-10 19:30:08 +020087 " set weight : change a server's weight\n"
Willy Tarreau654694e2012-06-07 01:03:16 +020088 " set table [id] : update or create a table entry's data\n"
Willy Tarreau7aabd112010-01-26 10:59:06 +010089 " set timeout : change a timeout setting\n"
Willy Tarreau2a0f4d22011-08-02 11:49:05 +020090 " set maxconn : change a maxconn setting\n"
Willy Tarreauf5b22872011-09-07 16:13:44 +020091 " set rate-limit : change a rate limiting value\n"
Willy Tarreaua295edc2011-09-07 23:21:03 +020092 " disable : put a server or frontend in maintenance mode\n"
93 " enable : re-enable a server or frontend which is in maintenance mode\n"
94 " shutdown : kill a session or a frontend (eg:to release listening ports)\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020095 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +020096
Simon Horman9bd2c732011-06-15 15:18:44 +090097static const char stats_permission_denied_msg[] =
Willy Tarreau6162db22009-10-10 17:13:00 +020098 "Permission denied\n"
99 "";
100
Willy Tarreau295a8372011-03-10 11:25:07 +0100101/* data transmission states for the stats responses */
102enum {
103 STAT_ST_INIT = 0,
104 STAT_ST_HEAD,
105 STAT_ST_INFO,
106 STAT_ST_LIST,
107 STAT_ST_END,
108 STAT_ST_FIN,
109};
110
111/* data transmission states for the stats responses inside a proxy */
112enum {
113 STAT_PX_ST_INIT = 0,
114 STAT_PX_ST_TH,
115 STAT_PX_ST_FE,
116 STAT_PX_ST_LI,
117 STAT_PX_ST_SV,
118 STAT_PX_ST_BE,
119 STAT_PX_ST_END,
120 STAT_PX_ST_FIN,
121};
122
Cyril Bonté19979e12012-04-04 12:57:21 +0200123extern const char *stat_status_codes[];
124
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200125/* This function is called from the session-level accept() in order to instanciate
Willy Tarreaueb472682010-05-28 18:46:57 +0200126 * a new stats socket. It returns a positive value upon success, 0 if the connection
127 * needs to be closed and ignored, or a negative value upon critical failure.
128 */
Simon Horman9bd2c732011-06-15 15:18:44 +0900129static int stats_accept(struct session *s)
Willy Tarreaueb472682010-05-28 18:46:57 +0200130{
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200131 /* we have a dedicated I/O handler for the stats */
Willy Tarreaub24281b2011-02-13 13:16:36 +0100132 stream_int_register_handler(&s->si[1], &cli_applet);
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100133 s->target = s->si[1].conn->target; // for logging only
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200134 s->si[1].conn->xprt_ctx = s;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100135 s->si[1].applet.st1 = 0;
136 s->si[1].applet.st0 = STAT_CLI_INIT;
Willy Tarreaueb472682010-05-28 18:46:57 +0200137
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200138 tv_zero(&s->logs.tv_request);
139 s->logs.t_queue = 0;
140 s->logs.t_connect = 0;
141 s->logs.t_data = 0;
142 s->logs.t_close = 0;
143 s->logs.bytes_in = s->logs.bytes_out = 0;
144 s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
145 s->logs.srv_queue_size = 0; /* we will get this number soon */
Willy Tarreaueb472682010-05-28 18:46:57 +0200146
Willy Tarreau03cdb7c2012-08-27 23:14:58 +0200147 s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreaueb472682010-05-28 18:46:57 +0200148
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200149 if (s->listener->timeout) {
150 s->req->rto = *s->listener->timeout;
151 s->rep->wto = *s->listener->timeout;
Willy Tarreaueb472682010-05-28 18:46:57 +0200152 }
Willy Tarreaueb472682010-05-28 18:46:57 +0200153 return 1;
Willy Tarreaueb472682010-05-28 18:46:57 +0200154}
155
Willy Tarreau07e9e642010-08-17 21:48:17 +0200156/* allocate a new stats frontend named <name>, and return it
157 * (or NULL in case of lack of memory).
158 */
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200159static struct proxy *alloc_stats_fe(const char *name, const char *file, int line)
Willy Tarreau07e9e642010-08-17 21:48:17 +0200160{
161 struct proxy *fe;
162
163 fe = (struct proxy *)calloc(1, sizeof(struct proxy));
164 if (!fe)
165 return NULL;
166
Willy Tarreau237250c2011-07-29 01:49:03 +0200167 init_new_proxy(fe);
Willy Tarreau050536d2012-10-04 08:47:34 +0200168 fe->next = proxy;
169 proxy = fe;
Willy Tarreau07e9e642010-08-17 21:48:17 +0200170 fe->last_change = now.tv_sec;
171 fe->id = strdup("GLOBAL");
172 fe->cap = PR_CAP_FE;
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200173 fe->maxconn = 10; /* default to 10 concurrent connections */
174 fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200175 fe->conf.file = strdup(file);
176 fe->conf.line = line;
Willy Tarreauc53d4222012-09-20 20:19:28 +0200177 fe->accept = stats_accept;
Willy Tarreau050536d2012-10-04 08:47:34 +0200178
179 /* the stats frontend is the only one able to assign ID #0 */
180 fe->conf.id.key = fe->uuid = 0;
181 eb32_insert(&used_proxy_id, &fe->conf.id);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200182 return fe;
183}
184
Willy Tarreaufbee7132007-10-18 13:53:22 +0200185/* This function parses a "stats" statement in the "global" section. It returns
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200186 * -1 if there is any error, otherwise zero. If it returns -1, it will write an
187 * error message into the <err> buffer which will be preallocated. The trailing
188 * '\n' must not be written. The function must be called with <args> pointing to
189 * the first word after "stats".
Willy Tarreaufbee7132007-10-18 13:53:22 +0200190 */
Willy Tarreau10522fd2008-07-09 20:12:41 +0200191static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
Willy Tarreau28a47d62012-09-18 20:02:48 +0200192 struct proxy *defpx, const char *file, int line,
193 char **err)
Willy Tarreaufbee7132007-10-18 13:53:22 +0200194{
Willy Tarreau4348fad2012-09-20 16:48:07 +0200195 struct bind_conf *bind_conf;
Willy Tarreauc53d4222012-09-20 20:19:28 +0200196 struct listener *l;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200197
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200198 if (!strcmp(args[1], "socket")) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200199 int cur_arg;
200
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200201 if (*args[2] == 0) {
Willy Tarreauc53d4222012-09-20 20:19:28 +0200202 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 +0200203 return -1;
204 }
205
Willy Tarreau89a63132009-08-16 17:41:45 +0200206 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200207 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200208 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreau89a63132009-08-16 17:41:45 +0200209 return -1;
210 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200211 }
212
Willy Tarreau4348fad2012-09-20 16:48:07 +0200213 bind_conf = bind_conf_alloc(&global.stats_fe->conf.bind, file, line, args[2]);
Willy Tarreau290e63a2012-09-20 18:07:14 +0200214 bind_conf->level = ACCESS_LVL_OPER; /* default access level */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200215
Willy Tarreauc53d4222012-09-20 20:19:28 +0200216 if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) {
217 memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n",
218 file, line, args[0], args[1], err && *err ? *err : "error");
219 return -1;
220 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200221
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200222 cur_arg = 3;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200223 while (*args[cur_arg]) {
Willy Tarreaud5781202012-09-22 19:32:35 +0200224 static int bind_dumped;
225 struct bind_kw *kw;
226
227 kw = bind_find_kw(args[cur_arg]);
228 if (kw) {
229 if (!kw->parse) {
230 memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).",
231 args[0], args[1], args[cur_arg]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200232 return -1;
233 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200234
235 if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) {
236 if (err && *err)
237 memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err);
238 else
239 memprintf(err, "'%s %s' : error encountered while processing '%s'",
240 args[0], args[1], args[cur_arg]);
Willy Tarreau6162db22009-10-10 17:13:00 +0200241 return -1;
242 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200243
244 cur_arg += 1 + kw->skip;
245 continue;
Willy Tarreau6162db22009-10-10 17:13:00 +0200246 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200247
248 if (!bind_dumped) {
249 bind_dump_kws(err);
250 indent_msg(err, 4);
251 bind_dumped = 1;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200252 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200253
254 memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s",
255 args[0], args[1], args[cur_arg],
256 err && *err ? " Registered keywords :" : "", err && *err ? *err : "");
257 return -1;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200258 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100259
Willy Tarreauc53d4222012-09-20 20:19:28 +0200260 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
261 l->maxconn = global.stats_fe->maxconn;
262 l->backlog = global.stats_fe->backlog;
263 l->timeout = &global.stats_fe->timeout.client;
264 l->accept = session_accept;
265 l->handler = process_session;
266 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
267 l->nice = -64; /* we want to boost priority for local stats */
268 global.maxsock += l->maxconn;
269 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200270 }
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200271 else if (!strcmp(args[1], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100272 unsigned timeout;
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200273 const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS);
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100274
275 if (res) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200276 memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res);
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100277 return -1;
278 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200279
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100280 if (!timeout) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200281 memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200282 return -1;
283 }
Willy Tarreau07e9e642010-08-17 21:48:17 +0200284 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200285 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200286 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200287 return -1;
288 }
289 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200290 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200291 }
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200292 else if (!strcmp(args[1], "maxconn")) {
293 int maxconn = atol(args[2]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200294
295 if (maxconn <= 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200296 memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200297 return -1;
298 }
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200299
300 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200301 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200302 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200303 return -1;
304 }
305 }
306 global.stats_fe->maxconn = maxconn;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200307 }
Willy Tarreau35b7b162012-10-22 23:17:18 +0200308 else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */
309 int cur_arg = 2;
310 unsigned int set = 0;
311
312 while (*args[cur_arg]) {
Willy Tarreau110ecc12012-11-15 17:50:01 +0100313 unsigned int low, high;
314
Willy Tarreau35b7b162012-10-22 23:17:18 +0200315 if (strcmp(args[cur_arg], "all") == 0) {
316 set = 0;
317 break;
318 }
319 else if (strcmp(args[cur_arg], "odd") == 0) {
320 set |= 0x55555555;
321 }
322 else if (strcmp(args[cur_arg], "even") == 0) {
323 set |= 0xAAAAAAAA;
324 }
Willy Tarreau83d84cf2012-11-22 01:04:31 +0100325 else if (isdigit((int)*args[cur_arg])) {
Willy Tarreau110ecc12012-11-15 17:50:01 +0100326 char *dash = strchr(args[cur_arg], '-');
327
328 low = high = str2uic(args[cur_arg]);
329 if (dash)
330 high = str2uic(dash + 1);
331
332 if (high < low) {
333 unsigned int swap = low;
334 low = high;
335 high = swap;
336 }
337
338 if (low < 1 || high > 32) {
339 memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n",
340 args[0], args[1]);
Willy Tarreau35b7b162012-10-22 23:17:18 +0200341 return -1;
342 }
Willy Tarreau110ecc12012-11-15 17:50:01 +0100343
344 while (low <= high)
345 set |= 1 << (low++ - 1);
346 }
347 else {
348 memprintf(err,
349 "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n",
350 args[0], args[1]);
351 return -1;
Willy Tarreau35b7b162012-10-22 23:17:18 +0200352 }
353 cur_arg++;
354 }
355 global.stats_fe->bind_proc = set;
356 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200357 else {
Willy Tarreau35b7b162012-10-22 23:17:18 +0200358 memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200359 return -1;
360 }
361 return 0;
362}
363
Simon Horman9bd2c732011-06-15 15:18:44 +0900364static int print_csv_header(struct chunk *msg)
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100365{
Willy Tarreau77804732012-10-29 16:14:26 +0100366 return chunk_appendf(msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100367 "# pxname,svname,"
368 "qcur,qmax,"
369 "scur,smax,slim,stot,"
370 "bin,bout,"
371 "dreq,dresp,"
372 "ereq,econ,eresp,"
373 "wretr,wredis,"
374 "status,weight,act,bck,"
375 "chkfail,chkdown,lastchg,downtime,qlimit,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +0200376 "pid,iid,sid,throttle,lbtot,tracked,type,"
377 "rate,rate_lim,rate_max,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200378 "check_status,check_code,check_duration,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100379 "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,"
Willy Tarreauae526782010-03-04 20:34:23 +0100380 "req_rate,req_rate_max,req_tot,"
381 "cli_abrt,srv_abrt,"
Willy Tarreau5e16cbc2012-11-24 14:54:13 +0100382 "comp_in,comp_out,comp_byp,comp_rsp,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100383 "\n");
384}
385
Simon Hormand9366582011-06-15 15:18:45 +0900386/* print a string of text buffer to <out>. The format is :
387 * Non-printable chars \t, \n, \r and \e are * encoded in C format.
388 * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped.
389 * Print stopped if null char or <bsize> is reached, or if no more place in the chunk.
390 */
391static int dump_text(struct chunk *out, const char *buf, int bsize)
392{
393 unsigned char c;
394 int ptr = 0;
395
396 while (buf[ptr] && ptr < bsize) {
397 c = buf[ptr];
398 if (isprint(c) && isascii(c) && c != '\\' && c != ' ') {
399 if (out->len > out->size - 1)
400 break;
401 out->str[out->len++] = c;
402 }
403 else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') {
404 if (out->len > out->size - 2)
405 break;
406 out->str[out->len++] = '\\';
407 switch (c) {
408 case ' ': c = ' '; break;
409 case '\t': c = 't'; break;
410 case '\n': c = 'n'; break;
411 case '\r': c = 'r'; break;
412 case '\e': c = 'e'; break;
413 case '\\': c = '\\'; break;
414 }
415 out->str[out->len++] = c;
416 }
417 else {
418 if (out->len > out->size - 4)
419 break;
420 out->str[out->len++] = '\\';
421 out->str[out->len++] = 'x';
422 out->str[out->len++] = hextab[(c >> 4) & 0xF];
423 out->str[out->len++] = hextab[c & 0xF];
424 }
425 ptr++;
426 }
427
428 return ptr;
429}
430
431/* print a buffer in hexa.
432 * Print stopped if <bsize> is reached, or if no more place in the chunk.
433 */
434static int dump_binary(struct chunk *out, const char *buf, int bsize)
435{
436 unsigned char c;
437 int ptr = 0;
438
439 while (ptr < bsize) {
440 c = buf[ptr];
441
442 if (out->len > out->size - 2)
443 break;
444 out->str[out->len++] = hextab[(c >> 4) & 0xF];
445 out->str[out->len++] = hextab[c & 0xF];
446
447 ptr++;
448 }
449 return ptr;
450}
451
452/* Dump the status of a table to a stream interface's
453 * read buffer. It returns 0 if the output buffer is full
454 * and needs to be called again, otherwise non-zero.
455 */
456static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si,
457 struct proxy *proxy, struct proxy *target)
458{
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200459 struct session *s = si->conn->xprt_ctx;
Simon Hormand9366582011-06-15 15:18:45 +0900460
Willy Tarreau77804732012-10-29 16:14:26 +0100461 chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n",
Simon Hormand9366582011-06-15 15:18:45 +0900462 proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current);
463
464 /* any other information should be dumped here */
465
Willy Tarreau290e63a2012-09-20 18:07:14 +0200466 if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER)
Willy Tarreau77804732012-10-29 16:14:26 +0100467 chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n");
Simon Hormand9366582011-06-15 15:18:45 +0900468
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200469 if (bi_putchk(si->ib, msg) == -1)
Simon Hormand9366582011-06-15 15:18:45 +0900470 return 0;
471
472 return 1;
473}
474
475/* Dump the a table entry to a stream interface's
476 * read buffer. It returns 0 if the output buffer is full
477 * and needs to be called again, otherwise non-zero.
478 */
479static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si,
480 struct proxy *proxy, struct stksess *entry)
481{
482 int dt;
483
Willy Tarreau77804732012-10-29 16:14:26 +0100484 chunk_appendf(msg, "%p:", entry);
Simon Hormand9366582011-06-15 15:18:45 +0900485
486 if (proxy->table.type == STKTABLE_TYPE_IP) {
487 char addr[INET_ADDRSTRLEN];
488 inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr));
Willy Tarreau77804732012-10-29 16:14:26 +0100489 chunk_appendf(msg, " key=%s", addr);
Simon Hormand9366582011-06-15 15:18:45 +0900490 }
491 else if (proxy->table.type == STKTABLE_TYPE_IPV6) {
492 char addr[INET6_ADDRSTRLEN];
493 inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr));
Willy Tarreau77804732012-10-29 16:14:26 +0100494 chunk_appendf(msg, " key=%s", addr);
Simon Hormand9366582011-06-15 15:18:45 +0900495 }
496 else if (proxy->table.type == STKTABLE_TYPE_INTEGER) {
Willy Tarreau77804732012-10-29 16:14:26 +0100497 chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key);
Simon Hormand9366582011-06-15 15:18:45 +0900498 }
499 else if (proxy->table.type == STKTABLE_TYPE_STRING) {
Willy Tarreau77804732012-10-29 16:14:26 +0100500 chunk_appendf(msg, " key=");
Simon Hormand9366582011-06-15 15:18:45 +0900501 dump_text(msg, (const char *)entry->key.key, proxy->table.key_size);
502 }
503 else {
Willy Tarreau77804732012-10-29 16:14:26 +0100504 chunk_appendf(msg, " key=");
Simon Hormand9366582011-06-15 15:18:45 +0900505 dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size);
506 }
507
Willy Tarreau77804732012-10-29 16:14:26 +0100508 chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire));
Simon Hormand9366582011-06-15 15:18:45 +0900509
510 for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) {
511 void *ptr;
512
513 if (proxy->table.data_ofs[dt] == 0)
514 continue;
515 if (stktable_data_types[dt].arg_type == ARG_T_DELAY)
Willy Tarreau77804732012-10-29 16:14:26 +0100516 chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u);
Simon Hormand9366582011-06-15 15:18:45 +0900517 else
Willy Tarreau77804732012-10-29 16:14:26 +0100518 chunk_appendf(msg, " %s=", stktable_data_types[dt].name);
Simon Hormand9366582011-06-15 15:18:45 +0900519
520 ptr = stktable_data_ptr(&proxy->table, entry, dt);
521 switch (stktable_data_types[dt].std_type) {
522 case STD_T_SINT:
Willy Tarreau77804732012-10-29 16:14:26 +0100523 chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint));
Simon Hormand9366582011-06-15 15:18:45 +0900524 break;
525 case STD_T_UINT:
Willy Tarreau77804732012-10-29 16:14:26 +0100526 chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint));
Simon Hormand9366582011-06-15 15:18:45 +0900527 break;
528 case STD_T_ULL:
Willy Tarreau77804732012-10-29 16:14:26 +0100529 chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull));
Simon Hormand9366582011-06-15 15:18:45 +0900530 break;
531 case STD_T_FRQP:
Willy Tarreau77804732012-10-29 16:14:26 +0100532 chunk_appendf(msg, "%d",
Simon Hormand9366582011-06-15 15:18:45 +0900533 read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
534 proxy->table.data_arg[dt].u));
535 break;
536 }
537 }
Willy Tarreau77804732012-10-29 16:14:26 +0100538 chunk_appendf(msg, "\n");
Simon Hormand9366582011-06-15 15:18:45 +0900539
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200540 if (bi_putchk(si->ib, msg) == -1)
Simon Hormand9366582011-06-15 15:18:45 +0900541 return 0;
542
543 return 1;
544}
545
Willy Tarreaudec98142012-06-06 23:37:08 +0200546static void stats_sock_table_key_request(struct stream_interface *si, char **args, int action)
Simon Horman121f3052011-06-15 15:18:46 +0900547{
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200548 struct session *s = si->conn->xprt_ctx;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900549 struct proxy *px = si->applet.ctx.table.target;
Simon Horman121f3052011-06-15 15:18:46 +0900550 struct stksess *ts;
Simon Hormancec9a222011-06-15 15:18:51 +0900551 uint32_t uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900552 unsigned char ip6_key[sizeof(struct in6_addr)];
Willy Tarreau654694e2012-06-07 01:03:16 +0200553 long long value;
554 int data_type;
555 void *ptr;
556 struct freq_ctr_period *frqp;
Simon Horman121f3052011-06-15 15:18:46 +0900557
Simon Hormand5b9fd92011-06-15 15:18:48 +0900558 si->applet.st0 = STAT_CLI_OUTPUT;
Simon Horman121f3052011-06-15 15:18:46 +0900559
560 if (!*args[4]) {
561 si->applet.ctx.cli.msg = "Key value expected\n";
562 si->applet.st0 = STAT_CLI_PRINT;
563 return;
564 }
565
Simon Hormanc5b89f62011-06-15 15:18:50 +0900566 switch (px->table.type) {
567 case STKTABLE_TYPE_IP:
Simon Hormancec9a222011-06-15 15:18:51 +0900568 uint32_key = htonl(inetaddr_host(args[4]));
Willy Tarreau07115412012-10-29 21:56:59 +0100569 static_table_key->key = &uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900570 break;
571 case STKTABLE_TYPE_IPV6:
572 inet_pton(AF_INET6, args[4], ip6_key);
Willy Tarreau07115412012-10-29 21:56:59 +0100573 static_table_key->key = &ip6_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900574 break;
Simon Hormancec9a222011-06-15 15:18:51 +0900575 case STKTABLE_TYPE_INTEGER:
576 {
577 char *endptr;
578 unsigned long val;
579 errno = 0;
580 val = strtoul(args[4], &endptr, 10);
581 if ((errno == ERANGE && val == ULONG_MAX) ||
582 (errno != 0 && val == 0) || endptr == args[4] ||
583 val > 0xffffffff) {
584 si->applet.ctx.cli.msg = "Invalid key\n";
585 si->applet.st0 = STAT_CLI_PRINT;
586 return;
587 }
588 uint32_key = (uint32_t) val;
Willy Tarreau07115412012-10-29 21:56:59 +0100589 static_table_key->key = &uint32_key;
Simon Hormancec9a222011-06-15 15:18:51 +0900590 break;
591 }
592 break;
Simon Horman619e3cc2011-06-15 15:18:52 +0900593 case STKTABLE_TYPE_STRING:
Willy Tarreau07115412012-10-29 21:56:59 +0100594 static_table_key->key = args[4];
595 static_table_key->key_len = strlen(args[4]);
Simon Horman619e3cc2011-06-15 15:18:52 +0900596 break;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900597 default:
Willy Tarreaudec98142012-06-06 23:37:08 +0200598 switch (action) {
599 case STAT_CLI_O_TAB:
600 si->applet.ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n";
601 break;
602 case STAT_CLI_O_CLR:
603 si->applet.ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6, string and integer is not supported\n";
604 break;
605 default:
606 si->applet.ctx.cli.msg = "Unknown action\n";
607 break;
608 }
Simon Horman121f3052011-06-15 15:18:46 +0900609 si->applet.st0 = STAT_CLI_PRINT;
610 return;
611 }
612
613 /* check permissions */
Willy Tarreau290e63a2012-09-20 18:07:14 +0200614 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Simon Horman121f3052011-06-15 15:18:46 +0900615 si->applet.ctx.cli.msg = stats_permission_denied_msg;
616 si->applet.st0 = STAT_CLI_PRINT;
617 return;
618 }
619
Willy Tarreau07115412012-10-29 21:56:59 +0100620 ts = stktable_lookup_key(&px->table, static_table_key);
Simon Horman17bce342011-06-15 15:18:47 +0900621
Willy Tarreaudec98142012-06-06 23:37:08 +0200622 switch (action) {
623 case STAT_CLI_O_TAB:
624 if (!ts)
625 return;
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100626 chunk_reset(&trash);
627 if (!stats_dump_table_head_to_buffer(&trash, si, px, px))
Simon Horman17bce342011-06-15 15:18:47 +0900628 return;
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100629 stats_dump_table_entry_to_buffer(&trash, si, px, ts);
Simon Horman121f3052011-06-15 15:18:46 +0900630 return;
Willy Tarreaudec98142012-06-06 23:37:08 +0200631
632 case STAT_CLI_O_CLR:
633 if (!ts)
634 return;
635 if (ts->ref_cnt) {
636 /* don't delete an entry which is currently referenced */
637 si->applet.ctx.cli.msg = "Entry currently in use, cannot remove\n";
638 si->applet.st0 = STAT_CLI_PRINT;
639 return;
640 }
641 stksess_kill(&px->table, ts);
642 break;
Simon Horman17bce342011-06-15 15:18:47 +0900643
Willy Tarreau654694e2012-06-07 01:03:16 +0200644 case STAT_CLI_O_SET:
645 if (strncmp(args[5], "data.", 5) != 0) {
646 si->applet.ctx.cli.msg = "\"data.<type>\" followed by a value expected\n";
647 si->applet.st0 = STAT_CLI_PRINT;
648 return;
649 }
650
651 data_type = stktable_get_data_type(args[5] + 5);
652 if (data_type < 0) {
653 si->applet.ctx.cli.msg = "Unknown data type\n";
654 si->applet.st0 = STAT_CLI_PRINT;
655 return;
656 }
657
658 if (!px->table.data_ofs[data_type]) {
659 si->applet.ctx.cli.msg = "Data type not stored in this table\n";
660 si->applet.st0 = STAT_CLI_PRINT;
661 return;
662 }
663
664 if (!*args[6] || strl2llrc(args[6], strlen(args[6]), &value) != 0) {
665 si->applet.ctx.cli.msg = "Require a valid integer value to store\n";
666 si->applet.st0 = STAT_CLI_PRINT;
667 return;
668 }
669
670 if (ts)
671 stktable_touch(&px->table, ts, 1);
672 else {
Willy Tarreau07115412012-10-29 21:56:59 +0100673 ts = stksess_new(&px->table, static_table_key);
Willy Tarreau654694e2012-06-07 01:03:16 +0200674 if (!ts) {
675 /* don't delete an entry which is currently referenced */
676 si->applet.ctx.cli.msg = "Unable to allocate a new entry\n";
677 si->applet.st0 = STAT_CLI_PRINT;
678 return;
679 }
680 stktable_store(&px->table, ts, 1);
681 }
682
683 ptr = stktable_data_ptr(&px->table, ts, data_type);
684 switch (stktable_data_types[data_type].std_type) {
685 case STD_T_SINT:
686 stktable_data_cast(ptr, std_t_sint) = value;
687 break;
688 case STD_T_UINT:
689 stktable_data_cast(ptr, std_t_uint) = value;
690 break;
691 case STD_T_ULL:
692 stktable_data_cast(ptr, std_t_ull) = value;
693 break;
694 case STD_T_FRQP:
695 /* We only reset the previous value so that it slowly fades out */
696 frqp = &stktable_data_cast(ptr, std_t_frqp);
697 frqp->curr_tick = now_ms;
698 frqp->prev_ctr = value;
699 frqp->curr_ctr = 0;
700 break;
701 }
702 break;
703
Willy Tarreaudec98142012-06-06 23:37:08 +0200704 default:
705 si->applet.ctx.cli.msg = "Unknown action\n";
Simon Horman121f3052011-06-15 15:18:46 +0900706 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreaudec98142012-06-06 23:37:08 +0200707 break;
Simon Horman121f3052011-06-15 15:18:46 +0900708 }
Simon Horman121f3052011-06-15 15:18:46 +0900709}
710
Willy Tarreau654694e2012-06-07 01:03:16 +0200711static void stats_sock_table_data_request(struct stream_interface *si, char **args, int action)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900712{
Willy Tarreau654694e2012-06-07 01:03:16 +0200713 if (action != STAT_CLI_O_TAB) {
714 si->applet.ctx.cli.msg = "content-based lookup is only supported with the \"show\" action";
715 si->applet.st0 = STAT_CLI_PRINT;
716 return;
717 }
718
Simon Hormand5b9fd92011-06-15 15:18:48 +0900719 /* condition on stored data value */
720 si->applet.ctx.table.data_type = stktable_get_data_type(args[3] + 5);
721 if (si->applet.ctx.table.data_type < 0) {
722 si->applet.ctx.cli.msg = "Unknown data type\n";
723 si->applet.st0 = STAT_CLI_PRINT;
724 return;
725 }
726
727 if (!((struct proxy *)si->applet.ctx.table.target)->table.data_ofs[si->applet.ctx.table.data_type]) {
728 si->applet.ctx.cli.msg = "Data type not stored in this table\n";
729 si->applet.st0 = STAT_CLI_PRINT;
730 return;
731 }
732
733 si->applet.ctx.table.data_op = get_std_op(args[4]);
734 if (si->applet.ctx.table.data_op < 0) {
735 si->applet.ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n";
736 si->applet.st0 = STAT_CLI_PRINT;
737 return;
738 }
739
740 if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &si->applet.ctx.table.value) != 0) {
741 si->applet.ctx.cli.msg = "Require a valid integer value to compare against\n";
742 si->applet.st0 = STAT_CLI_PRINT;
743 return;
744 }
745}
746
Willy Tarreaudec98142012-06-06 23:37:08 +0200747static void stats_sock_table_request(struct stream_interface *si, char **args, int action)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900748{
749 si->applet.ctx.table.data_type = -1;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200750 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaue17a8d02011-08-24 08:23:34 +0200751 si->applet.ctx.table.target = NULL;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900752 si->applet.ctx.table.proxy = NULL;
753 si->applet.ctx.table.entry = NULL;
Willy Tarreaudec98142012-06-06 23:37:08 +0200754 si->applet.st0 = action;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900755
756 if (*args[2]) {
757 si->applet.ctx.table.target = find_stktable(args[2]);
758 if (!si->applet.ctx.table.target) {
759 si->applet.ctx.cli.msg = "No such table\n";
760 si->applet.st0 = STAT_CLI_PRINT;
761 return;
762 }
763 }
764 else {
Willy Tarreaudec98142012-06-06 23:37:08 +0200765 if (action != STAT_CLI_O_TAB)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900766 goto err_args;
767 return;
768 }
769
770 if (strcmp(args[3], "key") == 0)
Willy Tarreaudec98142012-06-06 23:37:08 +0200771 stats_sock_table_key_request(si, args, action);
Simon Hormanc88b8872011-06-15 15:18:49 +0900772 else if (strncmp(args[3], "data.", 5) == 0)
Willy Tarreau654694e2012-06-07 01:03:16 +0200773 stats_sock_table_data_request(si, args, action);
Simon Hormanc88b8872011-06-15 15:18:49 +0900774 else if (*args[3])
Simon Hormand5b9fd92011-06-15 15:18:48 +0900775 goto err_args;
776
777 return;
778
779err_args:
Willy Tarreaudec98142012-06-06 23:37:08 +0200780 switch (action) {
781 case STAT_CLI_O_TAB:
Simon Hormand5b9fd92011-06-15 15:18:48 +0900782 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 +0200783 break;
784 case STAT_CLI_O_CLR:
Simon Hormanc88b8872011-06-15 15:18:49 +0900785 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 +0200786 break;
787 default:
788 si->applet.ctx.cli.msg = "Unknown action\n";
789 break;
790 }
Simon Hormand5b9fd92011-06-15 15:18:48 +0900791 si->applet.st0 = STAT_CLI_PRINT;
792}
793
Willy Tarreau532a4502011-09-07 22:37:44 +0200794/* Expects to find a frontend named <arg> and returns it, otherwise displays various
795 * adequate error messages and returns NULL. This function also expects the session
796 * level to be admin.
797 */
798static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg)
799{
800 struct proxy *px;
801
Willy Tarreau290e63a2012-09-20 18:07:14 +0200802 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau532a4502011-09-07 22:37:44 +0200803 si->applet.ctx.cli.msg = stats_permission_denied_msg;
804 si->applet.st0 = STAT_CLI_PRINT;
805 return NULL;
806 }
807
808 if (!*arg) {
809 si->applet.ctx.cli.msg = "A frontend name is expected.\n";
810 si->applet.st0 = STAT_CLI_PRINT;
811 return NULL;
812 }
813
814 px = findproxy(arg, PR_CAP_FE);
815 if (!px) {
816 si->applet.ctx.cli.msg = "No such frontend.\n";
817 si->applet.st0 = STAT_CLI_PRINT;
818 return NULL;
819 }
820 return px;
821}
822
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200823/* Expects to find a backend and a server in <arg> under the form <backend>/<server>,
824 * and returns the pointer to the server. Otherwise, display adequate error messages
825 * and returns NULL. This function also expects the session level to be admin. Note:
826 * the <arg> is modified to remove the '/'.
827 */
828static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg)
829{
830 struct proxy *px;
831 struct server *sv;
832 char *line;
833
Willy Tarreau290e63a2012-09-20 18:07:14 +0200834 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200835 si->applet.ctx.cli.msg = stats_permission_denied_msg;
836 si->applet.st0 = STAT_CLI_PRINT;
837 return NULL;
838 }
839
840 /* split "backend/server" and make <line> point to server */
841 for (line = arg; *line; line++)
842 if (*line == '/') {
843 *line++ = '\0';
844 break;
845 }
846
847 if (!*line || !*arg) {
848 si->applet.ctx.cli.msg = "Require 'backend/server'.\n";
849 si->applet.st0 = STAT_CLI_PRINT;
850 return NULL;
851 }
852
853 if (!get_backend_server(arg, line, &px, &sv)) {
854 si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
855 si->applet.st0 = STAT_CLI_PRINT;
856 return NULL;
857 }
858
859 if (px->state == PR_STSTOPPED) {
860 si->applet.ctx.cli.msg = "Proxy is disabled.\n";
861 si->applet.st0 = STAT_CLI_PRINT;
862 return NULL;
863 }
864
865 return sv;
866}
867
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200868/* Processes the stats interpreter on the statistics socket. This function is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200869 * called from an applet running in a stream interface. The function returns 1
Willy Tarreaubc4af052011-02-13 13:25:14 +0100870 * if the request was understood, otherwise zero. It sets si->applet.st0 to a value
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200871 * designating the function which will have to process the request, which can
872 * also be the print function to display the return message set into cli.msg.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200873 */
Simon Horman9bd2c732011-06-15 15:18:44 +0900874static int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200875{
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200876 struct session *s = si->conn->xprt_ctx;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200877 char *args[MAX_STATS_ARGS + 1];
878 int arg;
879
880 while (isspace((unsigned char)*line))
881 line++;
882
883 arg = 0;
884 args[arg] = line;
885
886 while (*line && arg < MAX_STATS_ARGS) {
887 if (isspace((unsigned char)*line)) {
888 *line++ = '\0';
889
890 while (isspace((unsigned char)*line))
891 line++;
892
893 args[++arg] = line;
894 continue;
895 }
896
897 line++;
898 }
899
900 while (++arg <= MAX_STATS_ARGS)
901 args[arg] = line;
902
Willy Tarreau295a8372011-03-10 11:25:07 +0100903 si->applet.ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200904 if (strcmp(args[0], "show") == 0) {
905 if (strcmp(args[1], "stat") == 0) {
906 if (*args[2] && *args[3] && *args[4]) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100907 si->applet.ctx.stats.flags |= STAT_BOUND;
908 si->applet.ctx.stats.iid = atoi(args[2]);
909 si->applet.ctx.stats.type = atoi(args[3]);
910 si->applet.ctx.stats.sid = atoi(args[4]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200911 }
912
Willy Tarreau295a8372011-03-10 11:25:07 +0100913 si->applet.ctx.stats.flags |= STAT_SHOW_STAT;
914 si->applet.ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200915 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100916 si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200917 }
918 else if (strcmp(args[1], "info") == 0) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100919 si->applet.ctx.stats.flags |= STAT_SHOW_INFO;
920 si->applet.ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200921 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100922 si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200923 }
924 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200925 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreau290e63a2012-09-20 18:07:14 +0200926 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100927 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100928 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200929 return 1;
930 }
Willy Tarreau76153662012-11-26 01:16:39 +0100931 if (*args[2] && strcmp(args[2], "all") == 0)
932 si->applet.ctx.sess.target = (void *)-1;
933 else if (*args[2])
Willy Tarreau295a8372011-03-10 11:25:07 +0100934 si->applet.ctx.sess.target = (void *)strtoul(args[2], NULL, 0);
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100935 else
Willy Tarreau295a8372011-03-10 11:25:07 +0100936 si->applet.ctx.sess.target = NULL;
937 si->applet.ctx.sess.section = 0; /* start with session status */
938 si->applet.ctx.sess.pos = 0;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100939 si->applet.st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200940 }
941 else if (strcmp(args[1], "errors") == 0) {
Willy Tarreau290e63a2012-09-20 18:07:14 +0200942 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100943 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100944 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200945 return 1;
946 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200947 if (*args[2])
Willy Tarreau295a8372011-03-10 11:25:07 +0100948 si->applet.ctx.errors.iid = atoi(args[2]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200949 else
Willy Tarreau295a8372011-03-10 11:25:07 +0100950 si->applet.ctx.errors.iid = -1;
951 si->applet.ctx.errors.px = NULL;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200952 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100953 si->applet.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200954 }
Willy Tarreau69f58c82010-07-12 17:55:33 +0200955 else if (strcmp(args[1], "table") == 0) {
Willy Tarreaudec98142012-06-06 23:37:08 +0200956 stats_sock_table_request(si, args, STAT_CLI_O_TAB);
Willy Tarreau69f58c82010-07-12 17:55:33 +0200957 }
Aman Guptaceafb4a2012-04-02 18:57:54 -0700958 else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200959 return 0;
960 }
961 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200962 else if (strcmp(args[0], "clear") == 0) {
963 if (strcmp(args[1], "counters") == 0) {
964 struct proxy *px;
965 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200966 struct listener *li;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200967 int clrall = 0;
968
969 if (strcmp(args[2], "all") == 0)
970 clrall = 1;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200971
Willy Tarreau6162db22009-10-10 17:13:00 +0200972 /* check permissions */
Willy Tarreau290e63a2012-09-20 18:07:14 +0200973 if (s->listener->bind_conf->level < ACCESS_LVL_OPER ||
974 (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100975 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100976 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200977 return 1;
978 }
979
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200980 for (px = proxy; px; px = px->next) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100981 if (clrall) {
982 memset(&px->be_counters, 0, sizeof(px->be_counters));
983 memset(&px->fe_counters, 0, sizeof(px->fe_counters));
984 }
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200985 else {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100986 px->be_counters.conn_max = 0;
987 px->be_counters.p.http.rps_max = 0;
988 px->be_counters.sps_max = 0;
989 px->be_counters.cps_max = 0;
990 px->be_counters.nbpend_max = 0;
991
992 px->fe_counters.conn_max = 0;
993 px->fe_counters.p.http.rps_max = 0;
994 px->fe_counters.sps_max = 0;
995 px->fe_counters.cps_max = 0;
996 px->fe_counters.nbpend_max = 0;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200997 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200998
999 for (sv = px->srv; sv; sv = sv->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001000 if (clrall)
1001 memset(&sv->counters, 0, sizeof(sv->counters));
1002 else {
1003 sv->counters.cur_sess_max = 0;
1004 sv->counters.nbpend_max = 0;
1005 sv->counters.sps_max = 0;
1006 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001007
Willy Tarreaua7944ad2012-09-26 21:03:11 +02001008 list_for_each_entry(li, &px->conf.listeners, by_fe)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001009 if (li->counters) {
1010 if (clrall)
1011 memset(li->counters, 0, sizeof(*li->counters));
1012 else
1013 li->counters->conn_max = 0;
1014 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001015 }
1016
Willy Tarreau81c25d02011-09-07 15:17:21 +02001017 global.cps_max = 0;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001018 return 1;
1019 }
Willy Tarreau88ee3972010-07-13 13:48:00 +02001020 else if (strcmp(args[1], "table") == 0) {
Willy Tarreaudec98142012-06-06 23:37:08 +02001021 stats_sock_table_request(si, args, STAT_CLI_O_CLR);
Willy Tarreau88ee3972010-07-13 13:48:00 +02001022 /* end of processing */
1023 return 1;
1024 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001025 else {
Willy Tarreau88ee3972010-07-13 13:48:00 +02001026 /* unknown "clear" argument */
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001027 return 0;
1028 }
1029 }
Willy Tarreau38338fa2009-10-10 18:37:29 +02001030 else if (strcmp(args[0], "get") == 0) {
1031 if (strcmp(args[1], "weight") == 0) {
1032 struct proxy *px;
1033 struct server *sv;
1034
1035 /* split "backend/server" and make <line> point to server */
1036 for (line = args[2]; *line; line++)
1037 if (*line == '/') {
1038 *line++ = '\0';
1039 break;
1040 }
1041
1042 if (!*line) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001043 si->applet.ctx.cli.msg = "Require 'backend/server'.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001044 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +02001045 return 1;
1046 }
1047
1048 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001049 si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001050 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +02001051 return 1;
1052 }
1053
1054 /* return server's effective weight at the moment */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001055 snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight);
1056 bi_putstr(si->ib, trash.str);
Willy Tarreau38338fa2009-10-10 18:37:29 +02001057 return 1;
1058 }
1059 else { /* not "get weight" */
1060 return 0;
1061 }
1062 }
Willy Tarreau4483d432009-10-10 19:30:08 +02001063 else if (strcmp(args[0], "set") == 0) {
1064 if (strcmp(args[1], "weight") == 0) {
1065 struct proxy *px;
1066 struct server *sv;
1067 int w;
1068
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001069 sv = expect_server_admin(s, si, args[2]);
1070 if (!sv)
Willy Tarreau4483d432009-10-10 19:30:08 +02001071 return 1;
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001072 px = sv->proxy;
Willy Tarreau4483d432009-10-10 19:30:08 +02001073
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001074 /* if the weight is terminated with '%', it is set relative to
1075 * the initial weight, otherwise it is absolute.
1076 */
1077 if (!*args[3]) {
1078 si->applet.ctx.cli.msg = "Require <weight> or <weight%>.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001079 si->applet.st0 = STAT_CLI_PRINT;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001080 return 1;
1081 }
1082
Willy Tarreau4483d432009-10-10 19:30:08 +02001083 w = atoi(args[3]);
1084 if (strchr(args[3], '%') != NULL) {
1085 if (w < 0 || w > 100) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001086 si->applet.ctx.cli.msg = "Relative weight can only be set between 0 and 100% inclusive.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001087 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001088 return 1;
1089 }
1090 w = sv->iweight * w / 100;
1091 }
1092 else {
1093 if (w < 0 || w > 256) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001094 si->applet.ctx.cli.msg = "Absolute weight can only be between 0 and 256 inclusive.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001095 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001096 return 1;
1097 }
1098 }
1099
1100 if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001101 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 +01001102 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001103 return 1;
1104 }
1105
1106 sv->uweight = w;
1107
1108 if (px->lbprm.algo & BE_LB_PROP_DYN) {
1109 /* we must take care of not pushing the server to full throttle during slow starts */
1110 if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN))
1111 sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart;
1112 else
1113 sv->eweight = BE_WEIGHT_SCALE;
1114 sv->eweight *= sv->uweight;
1115 } else {
1116 sv->eweight = sv->uweight;
1117 }
1118
1119 /* static LB algorithms are a bit harder to update */
1120 if (px->lbprm.update_server_eweight)
1121 px->lbprm.update_server_eweight(sv);
Willy Tarreau9580d162012-05-19 19:07:40 +02001122 else if (sv->eweight) {
1123 if (px->lbprm.set_server_status_up)
1124 px->lbprm.set_server_status_up(sv);
1125 }
1126 else {
1127 if (px->lbprm.set_server_status_down)
1128 px->lbprm.set_server_status_down(sv);
1129 }
Willy Tarreau4483d432009-10-10 19:30:08 +02001130
1131 return 1;
1132 }
Willy Tarreau7aabd112010-01-26 10:59:06 +01001133 else if (strcmp(args[1], "timeout") == 0) {
1134 if (strcmp(args[2], "cli") == 0) {
1135 unsigned timeout;
1136 const char *res;
1137
1138 if (!*args[3]) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001139 si->applet.ctx.cli.msg = "Expects an integer value.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001140 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001141 return 1;
1142 }
1143
1144 res = parse_time_err(args[3], &timeout, TIME_UNIT_S);
1145 if (res || timeout < 1) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001146 si->applet.ctx.cli.msg = "Invalid timeout value.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001147 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001148 return 1;
1149 }
1150
1151 s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000);
1152 return 1;
1153 }
1154 else {
Willy Tarreau295a8372011-03-10 11:25:07 +01001155 si->applet.ctx.cli.msg = "'set timeout' only supports 'cli'.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001156 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001157 return 1;
1158 }
1159 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001160 else if (strcmp(args[1], "maxconn") == 0) {
1161 if (strcmp(args[2], "frontend") == 0) {
1162 struct proxy *px;
1163 struct listener *l;
1164 int v;
1165
Willy Tarreau532a4502011-09-07 22:37:44 +02001166 px = expect_frontend_admin(s, si, args[3]);
1167 if (!px)
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001168 return 1;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001169
1170 if (!*args[4]) {
1171 si->applet.ctx.cli.msg = "Integer value expected.\n";
1172 si->applet.st0 = STAT_CLI_PRINT;
1173 return 1;
1174 }
1175
1176 v = atoi(args[4]);
Willy Tarreau3c7a79d2012-09-26 21:07:15 +02001177 if (v < 0) {
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001178 si->applet.ctx.cli.msg = "Value out of range.\n";
1179 si->applet.st0 = STAT_CLI_PRINT;
1180 return 1;
1181 }
1182
1183 /* OK, the value is fine, so we assign it to the proxy and to all of
1184 * its listeners. The blocked ones will be dequeued.
1185 */
1186 px->maxconn = v;
Willy Tarreaua7944ad2012-09-26 21:03:11 +02001187 list_for_each_entry(l, &px->conf.listeners, by_fe) {
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001188 l->maxconn = v;
1189 if (l->state == LI_FULL)
1190 resume_listener(l);
1191 }
1192
1193 if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue))
1194 dequeue_all_listeners(&s->fe->listener_queue);
1195
1196 return 1;
1197 }
Willy Tarreau91886b62011-09-07 14:38:31 +02001198 else if (strcmp(args[2], "global") == 0) {
1199 int v;
1200
Willy Tarreau290e63a2012-09-20 18:07:14 +02001201 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau91886b62011-09-07 14:38:31 +02001202 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1203 si->applet.st0 = STAT_CLI_PRINT;
1204 return 1;
1205 }
1206
1207 if (!*args[3]) {
1208 si->applet.ctx.cli.msg = "Expects an integer value.\n";
1209 si->applet.st0 = STAT_CLI_PRINT;
1210 return 1;
1211 }
1212
1213 v = atoi(args[3]);
1214 if (v > global.hardmaxconn) {
1215 si->applet.ctx.cli.msg = "Value out of range.\n";
1216 si->applet.st0 = STAT_CLI_PRINT;
1217 return 1;
1218 }
1219
1220 /* check for unlimited values */
1221 if (v <= 0)
1222 v = global.hardmaxconn;
1223
1224 global.maxconn = v;
1225
1226 /* Dequeues all of the listeners waiting for a resource */
1227 if (!LIST_ISEMPTY(&global_listener_queue))
1228 dequeue_all_listeners(&global_listener_queue);
1229
1230 return 1;
1231 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001232 else {
Willy Tarreau91886b62011-09-07 14:38:31 +02001233 si->applet.ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n";
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001234 si->applet.st0 = STAT_CLI_PRINT;
1235 return 1;
1236 }
1237 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001238 else if (strcmp(args[1], "rate-limit") == 0) {
1239 if (strcmp(args[2], "connections") == 0) {
1240 if (strcmp(args[3], "global") == 0) {
1241 int v;
1242
Willy Tarreau290e63a2012-09-20 18:07:14 +02001243 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreauf5b22872011-09-07 16:13:44 +02001244 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1245 si->applet.st0 = STAT_CLI_PRINT;
1246 return 1;
1247 }
1248
1249 if (!*args[4]) {
1250 si->applet.ctx.cli.msg = "Expects an integer value.\n";
1251 si->applet.st0 = STAT_CLI_PRINT;
1252 return 1;
1253 }
1254
1255 v = atoi(args[4]);
1256 if (v < 0) {
1257 si->applet.ctx.cli.msg = "Value out of range.\n";
1258 si->applet.st0 = STAT_CLI_PRINT;
1259 return 1;
1260 }
1261
1262 global.cps_lim = v;
1263
1264 /* Dequeues all of the listeners waiting for a resource */
1265 if (!LIST_ISEMPTY(&global_listener_queue))
1266 dequeue_all_listeners(&global_listener_queue);
1267
1268 return 1;
1269 }
1270 else {
1271 si->applet.ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n";
1272 si->applet.st0 = STAT_CLI_PRINT;
1273 return 1;
1274 }
1275 }
William Lallemandd85f9172012-11-09 17:05:39 +01001276 else if (strcmp(args[2], "http-compression") == 0) {
1277 if (strcmp(args[3], "global") == 0) {
1278 int v;
1279
Willy Tarreau85d47f92012-11-21 00:29:50 +01001280 if (!*args[4]) {
1281 si->applet.ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n";
1282 si->applet.st0 = STAT_CLI_PRINT;
1283 return 1;
1284 }
1285
William Lallemandd85f9172012-11-09 17:05:39 +01001286 v = atoi(args[4]);
1287 global.comp_rate_lim = v * 1024; /* Kilo to bytes. */
1288 }
1289 else {
1290 si->applet.ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n";
1291 si->applet.st0 = STAT_CLI_PRINT;
1292 return 1;
1293 }
1294 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001295 else {
William Lallemandd85f9172012-11-09 17:05:39 +01001296 si->applet.ctx.cli.msg = "'set rate-limit' supports 'connections' and 'http-compression'.\n";
Willy Tarreauf5b22872011-09-07 16:13:44 +02001297 si->applet.st0 = STAT_CLI_PRINT;
1298 return 1;
1299 }
1300 }
Willy Tarreau654694e2012-06-07 01:03:16 +02001301 else if (strcmp(args[1], "table") == 0) {
1302 stats_sock_table_request(si, args, STAT_CLI_O_SET);
1303 }
Willy Tarreau7aabd112010-01-26 10:59:06 +01001304 else { /* unknown "set" parameter */
Willy Tarreau4483d432009-10-10 19:30:08 +02001305 return 0;
1306 }
1307 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001308 else if (strcmp(args[0], "enable") == 0) {
1309 if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001310 struct server *sv;
1311
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001312 sv = expect_server_admin(s, si, args[2]);
1313 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01001314 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001315
Cyril Bontécd19e512010-01-31 22:34:03 +01001316 if (sv->state & SRV_MAINTAIN) {
1317 /* The server is really in maintenance, we can change the server state */
Willy Tarreau44267702011-10-28 15:35:33 +02001318 if (sv->track) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001319 /* If this server tracks the status of another one,
1320 * we must restore the good status.
1321 */
Willy Tarreau44267702011-10-28 15:35:33 +02001322 if (sv->track->state & SRV_RUNNING) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001323 set_server_up(sv);
Willy Tarreau70461302010-10-22 14:39:02 +02001324 sv->health = sv->rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +01001325 } else {
1326 sv->state &= ~SRV_MAINTAIN;
1327 set_server_down(sv);
1328 }
1329 } else {
1330 set_server_up(sv);
Willy Tarreau70461302010-10-22 14:39:02 +02001331 sv->health = sv->rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +01001332 }
1333 }
1334
Willy Tarreau532a4502011-09-07 22:37:44 +02001335 return 1;
1336 }
1337 else if (strcmp(args[1], "frontend") == 0) {
1338 struct proxy *px;
1339
1340 px = expect_frontend_admin(s, si, args[2]);
1341 if (!px)
1342 return 1;
1343
1344 if (px->state == PR_STSTOPPED) {
1345 si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n";
1346 si->applet.st0 = STAT_CLI_PRINT;
1347 return 1;
1348 }
1349
1350 if (px->state != PR_STPAUSED) {
1351 si->applet.ctx.cli.msg = "Frontend is already enabled.\n";
1352 si->applet.st0 = STAT_CLI_PRINT;
1353 return 1;
1354 }
1355
1356 if (!resume_proxy(px)) {
1357 si->applet.ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n";
1358 si->applet.st0 = STAT_CLI_PRINT;
1359 return 1;
1360 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001361 return 1;
1362 }
1363 else { /* unknown "enable" parameter */
Willy Tarreau532a4502011-09-07 22:37:44 +02001364 si->applet.ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n";
1365 si->applet.st0 = STAT_CLI_PRINT;
1366 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01001367 }
1368 }
1369 else if (strcmp(args[0], "disable") == 0) {
1370 if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001371 struct server *sv;
1372
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001373 sv = expect_server_admin(s, si, args[2]);
1374 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01001375 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001376
Cyril Bontécd19e512010-01-31 22:34:03 +01001377 if (! (sv->state & SRV_MAINTAIN)) {
1378 /* Not already in maintenance, we can change the server state */
1379 sv->state |= SRV_MAINTAIN;
1380 set_server_down(sv);
1381 }
1382
Willy Tarreau532a4502011-09-07 22:37:44 +02001383 return 1;
1384 }
1385 else if (strcmp(args[1], "frontend") == 0) {
1386 struct proxy *px;
1387
1388 px = expect_frontend_admin(s, si, args[2]);
1389 if (!px)
1390 return 1;
1391
1392 if (px->state == PR_STSTOPPED) {
1393 si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n";
1394 si->applet.st0 = STAT_CLI_PRINT;
1395 return 1;
1396 }
1397
1398 if (px->state == PR_STPAUSED) {
1399 si->applet.ctx.cli.msg = "Frontend is already disabled.\n";
1400 si->applet.st0 = STAT_CLI_PRINT;
1401 return 1;
1402 }
1403
1404 if (!pause_proxy(px)) {
1405 si->applet.ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n";
1406 si->applet.st0 = STAT_CLI_PRINT;
1407 return 1;
1408 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001409 return 1;
1410 }
1411 else { /* unknown "disable" parameter */
Willy Tarreau532a4502011-09-07 22:37:44 +02001412 si->applet.ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n";
1413 si->applet.st0 = STAT_CLI_PRINT;
1414 return 1;
1415 }
1416 }
1417 else if (strcmp(args[0], "shutdown") == 0) {
1418 if (strcmp(args[1], "frontend") == 0) {
1419 struct proxy *px;
1420
1421 px = expect_frontend_admin(s, si, args[2]);
1422 if (!px)
1423 return 1;
1424
1425 if (px->state == PR_STSTOPPED) {
1426 si->applet.ctx.cli.msg = "Frontend was already shut down.\n";
1427 si->applet.st0 = STAT_CLI_PRINT;
1428 return 1;
1429 }
1430
1431 Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
1432 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
1433 send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
1434 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
1435 stop_proxy(px);
1436 return 1;
1437 }
Willy Tarreaua295edc2011-09-07 23:21:03 +02001438 else if (strcmp(args[1], "session") == 0) {
1439 struct session *sess, *ptr;
1440
Willy Tarreau290e63a2012-09-20 18:07:14 +02001441 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreaua295edc2011-09-07 23:21:03 +02001442 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1443 si->applet.st0 = STAT_CLI_PRINT;
1444 return 1;
1445 }
1446
1447 if (!*args[2]) {
1448 si->applet.ctx.cli.msg = "Session pointer expected (use 'show sess').\n";
1449 si->applet.st0 = STAT_CLI_PRINT;
1450 return 1;
1451 }
1452
1453 ptr = (void *)strtoul(args[2], NULL, 0);
1454
1455 /* first, look for the requested session in the session table */
1456 list_for_each_entry(sess, &sessions, list) {
1457 if (sess == ptr)
1458 break;
1459 }
1460
1461 /* do we have the session ? */
1462 if (sess != ptr) {
1463 si->applet.ctx.cli.msg = "No such session (use 'show sess').\n";
1464 si->applet.st0 = STAT_CLI_PRINT;
1465 return 1;
1466 }
1467
1468 session_shutdown(sess, SN_ERR_KILLED);
1469 return 1;
1470 }
Willy Tarreau52b2d222011-09-07 23:48:48 +02001471 else if (strcmp(args[1], "sessions") == 0) {
1472 if (strcmp(args[2], "server") == 0) {
1473 struct server *sv;
1474 struct session *sess, *sess_bck;
1475
1476 sv = expect_server_admin(s, si, args[3]);
1477 if (!sv)
1478 return 1;
1479
1480 /* kill all the session that are on this server */
1481 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
1482 if (sess->srv_conn == sv)
1483 session_shutdown(sess, SN_ERR_KILLED);
1484
1485 return 1;
1486 }
1487 else {
1488 si->applet.ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n";
1489 si->applet.st0 = STAT_CLI_PRINT;
1490 return 1;
1491 }
1492 }
Willy Tarreau532a4502011-09-07 22:37:44 +02001493 else { /* unknown "disable" parameter */
Willy Tarreau52b2d222011-09-07 23:48:48 +02001494 si->applet.ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n";
Willy Tarreau532a4502011-09-07 22:37:44 +02001495 si->applet.st0 = STAT_CLI_PRINT;
1496 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01001497 }
1498 }
1499 else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001500 return 0;
1501 }
1502 return 1;
1503}
1504
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001505/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001506 * used to processes I/O from/to the stats unix socket. The system relies on a
1507 * state machine handling requests and various responses. We read a request,
1508 * then we process it and send the response, and we possibly display a prompt.
Willy Tarreaubc4af052011-02-13 13:25:14 +01001509 * Then we can read again. The state is stored in si->applet.st0 and is one of the
1510 * STAT_CLI_* constants. si->applet.st1 is used to indicate whether prompt is enabled
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001511 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001512 */
Willy Tarreaub24281b2011-02-13 13:16:36 +01001513static void cli_io_handler(struct stream_interface *si)
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001514{
Willy Tarreau7421efb2012-07-02 15:11:27 +02001515 struct channel *req = si->ob;
1516 struct channel *res = si->ib;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001517 int reql;
1518 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001519
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001520 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
1521 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001522
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001523 while (1) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001524 if (si->applet.st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001525 /* Stats output not initialized yet */
Willy Tarreau295a8372011-03-10 11:25:07 +01001526 memset(&si->applet.ctx.stats, 0, sizeof(si->applet.ctx.stats));
Willy Tarreaubc4af052011-02-13 13:25:14 +01001527 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001528 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001529 else if (si->applet.st0 == STAT_CLI_END) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001530 /* Let's close for real now. We just close the request
1531 * side, the conditions below will complete if needed.
1532 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001533 si_shutw(si);
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001534 break;
1535 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001536 else if (si->applet.st0 == STAT_CLI_GETREQ) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02001537 /* ensure we have some output room left in the event we
1538 * would want to return some info right after parsing.
1539 */
Willy Tarreau9b28e032012-10-12 23:49:43 +02001540 if (buffer_almost_full(si->ib->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02001541 break;
1542
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001543 reql = bo_getline(si->ob, trash.str, trash.size);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001544 if (reql <= 0) { /* closed or EOL not found */
1545 if (reql == 0)
1546 break;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001547 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001548 continue;
1549 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001550
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001551 /* seek for a possible semi-colon. If we find one, we
1552 * replace it with an LF and skip only this part.
1553 */
1554 for (len = 0; len < reql; len++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001555 if (trash.str[len] == ';') {
1556 trash.str[len] = '\n';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001557 reql = len + 1;
1558 break;
1559 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001560
Willy Tarreau816fc222009-10-04 07:36:58 +02001561 /* now it is time to check that we have a full line,
1562 * remove the trailing \n and possibly \r, then cut the
1563 * line.
1564 */
1565 len = reql - 1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001566 if (trash.str[len] != '\n') {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001567 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001568 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001569 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001570
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001571 if (len && trash.str[len-1] == '\r')
Willy Tarreau816fc222009-10-04 07:36:58 +02001572 len--;
1573
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001574 trash.str[len] = '\0';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001575
Willy Tarreaubc4af052011-02-13 13:25:14 +01001576 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001577 if (len) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001578 if (strcmp(trash.str, "quit") == 0) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001579 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001580 continue;
1581 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001582 else if (strcmp(trash.str, "prompt") == 0)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001583 si->applet.st1 = !si->applet.st1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001584 else if (strcmp(trash.str, "help") == 0 ||
1585 !stats_sock_parse_request(si, trash.str)) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001586 si->applet.ctx.cli.msg = stats_sock_usage_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001587 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001588 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001589 /* NB: stats_sock_parse_request() may have put
Willy Tarreaubc4af052011-02-13 13:25:14 +01001590 * another STAT_CLI_O_* into si->applet.st0.
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001591 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001592 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001593 else if (!si->applet.st1) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001594 /* if prompt is disabled, print help on empty lines,
1595 * so that the user at least knows how to enable
1596 * prompt and find help.
1597 */
Willy Tarreau295a8372011-03-10 11:25:07 +01001598 si->applet.ctx.cli.msg = stats_sock_usage_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001599 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001600 }
1601
1602 /* re-adjust req buffer */
Willy Tarreau9dab5fc2012-05-07 11:56:55 +02001603 bo_skip(si->ob, reql);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001604 req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001605 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001606 else { /* output functions: first check if the output buffer is closed then abort */
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001607 if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001608 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001609 continue;
1610 }
1611
Willy Tarreaubc4af052011-02-13 13:25:14 +01001612 switch (si->applet.st0) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001613 case STAT_CLI_PRINT:
Willy Tarreau9dab5fc2012-05-07 11:56:55 +02001614 if (bi_putstr(si->ib, si->applet.ctx.cli.msg) != -1)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001615 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001616 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001617 case STAT_CLI_O_INFO:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001618 if (stats_dump_raw_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001619 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001620 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001621 case STAT_CLI_O_SESS:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001622 if (stats_dump_sess_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001623 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001624 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001625 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001626 if (stats_dump_errors_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001627 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001628 break;
Willy Tarreau69f58c82010-07-12 17:55:33 +02001629 case STAT_CLI_O_TAB:
Simon Hormanc88b8872011-06-15 15:18:49 +09001630 case STAT_CLI_O_CLR:
Willy Tarreaudec98142012-06-06 23:37:08 +02001631 if (stats_table_request(si, si->applet.st0))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001632 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau69f58c82010-07-12 17:55:33 +02001633 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001634 default: /* abnormal state */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001635 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001636 break;
1637 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001638
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001639 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001640 if (si->applet.st0 == STAT_CLI_PROMPT) {
Willy Tarreau9dab5fc2012-05-07 11:56:55 +02001641 if (bi_putstr(si->ib, si->applet.st1 ? "\n> " : "\n") != -1)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001642 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001643 }
1644
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001645 /* If the output functions are still there, it means they require more room. */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001646 if (si->applet.st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001647 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001648
1649 /* Now we close the output if one of the writers did so,
1650 * or if we're not in interactive mode and the request
1651 * buffer is empty. This still allows pipelined requests
1652 * to be sent in non-interactive mode.
1653 */
Willy Tarreau9b28e032012-10-12 23:49:43 +02001654 if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!si->applet.st1 && !req->buf->o)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001655 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001656 continue;
1657 }
1658
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001659 /* switch state back to GETREQ to read next requests */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001660 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001661 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001662 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001663
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001664 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST) && (si->applet.st0 != STAT_CLI_GETREQ)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001665 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
1666 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
Aman Guptaceafb4a2012-04-02 18:57:54 -07001667 /* Other side has closed, let's abort if we have no more processing to do
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001668 * and nothing more to consume. This is comparable to a broken pipe, so
1669 * we forward the close to the request side so that it flows upstream to
1670 * the client.
1671 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001672 si_shutw(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001673 }
1674
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001675 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (si->applet.st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001676 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
1677 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
1678 /* We have no more processing to do, and nothing more to send, and
1679 * the client side has closed. So we'll forward this state downstream
1680 * on the response buffer.
1681 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001682 si_shutr(si);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001683 res->flags |= CF_READ_NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001684 }
1685
1686 /* update all other flags and resync with the other side */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001687 si_update(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001688
1689 /* we don't want to expire timeouts while we're processing requests */
1690 si->ib->rex = TICK_ETERNITY;
1691 si->ob->wex = TICK_ETERNITY;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001692
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001693 out:
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01001694 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 +02001695 __FUNCTION__, __LINE__,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001696 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 +02001697
1698 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1699 /* check that we have released everything then unregister */
1700 stream_int_unregister_handler(si);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001701 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001702}
1703
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001704/* This function dumps statistics onto the stream interface's read buffer.
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02001705 * The xprt_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau24955a12009-10-04 11:54:04 +02001706 * It returns 0 as long as it does not complete, non-zero upon completion.
1707 * Some states are not used but it makes the code more similar to other
1708 * functions which handle stats too.
Willy Tarreau3e76e722007-10-17 18:57:38 +02001709 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001710static int stats_dump_raw_to_buffer(struct stream_interface *si)
Willy Tarreau3e76e722007-10-17 18:57:38 +02001711{
Willy Tarreau3e76e722007-10-17 18:57:38 +02001712 struct proxy *px;
Willy Tarreaua8efd362008-01-03 10:19:15 +01001713 unsigned int up;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001714
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001715 chunk_reset(&trash);
Willy Tarreau3e76e722007-10-17 18:57:38 +02001716
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001717 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001718 case STAT_ST_INIT:
Willy Tarreau24955a12009-10-04 11:54:04 +02001719 /* the function had not been called yet */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001720 si->conn->xprt_st = STAT_ST_HEAD;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001721 /* fall through */
1722
Willy Tarreau295a8372011-03-10 11:25:07 +01001723 case STAT_ST_HEAD:
1724 if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001725 print_csv_header(&trash);
1726 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001727 return 0;
1728 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001729
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001730 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001731 /* fall through */
1732
Willy Tarreau295a8372011-03-10 11:25:07 +01001733 case STAT_ST_INFO:
Willy Tarreaua8efd362008-01-03 10:19:15 +01001734 up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau295a8372011-03-10 11:25:07 +01001735 if (si->applet.ctx.stats.flags & STAT_SHOW_INFO) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001736 chunk_appendf(&trash,
Willy Tarreaua8efd362008-01-03 10:19:15 +01001737 "Name: " PRODUCT_NAME "\n"
1738 "Version: " HAPROXY_VERSION "\n"
1739 "Release_date: " HAPROXY_DATE "\n"
1740 "Nbproc: %d\n"
1741 "Process_num: %d\n"
1742 "Pid: %d\n"
1743 "Uptime: %dd %dh%02dm%02ds\n"
1744 "Uptime_sec: %d\n"
1745 "Memmax_MB: %d\n"
1746 "Ulimit-n: %d\n"
1747 "Maxsock: %d\n"
1748 "Maxconn: %d\n"
Willy Tarreau91886b62011-09-07 14:38:31 +02001749 "Hard_maxconn: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +01001750 "Maxpipes: %d\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001751 "CurrConns: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +01001752 "PipesUsed: %d\n"
1753 "PipesFree: %d\n"
Willy Tarreau9cd552d2011-09-07 15:26:48 +02001754 "ConnRate: %d\n"
1755 "ConnRateLimit: %d\n"
1756 "MaxConnRate: %d\n"
William Lallemandd85f9172012-11-09 17:05:39 +01001757 "CompressBpsIn: %u\n"
1758 "CompressBpsOut: %u\n"
William Lallemand096f5542012-11-19 17:26:05 +01001759 "CompressBpsRateLim: %u\n"
William Lallemande3a7d992012-11-20 11:25:20 +01001760#ifdef USE_ZLIB
1761 "ZlibMemUsage: %ld\n"
1762 "MaxZlibMemUsage: %ld\n"
1763#endif
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001764 "Tasks: %d\n"
1765 "Run_queue: %d\n"
Willy Tarreau45a12512011-09-10 16:56:42 +02001766 "Idle_pct: %d\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001767 "node: %s\n"
1768 "description: %s\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001769 "",
1770 global.nbproc,
1771 relative_pid,
1772 pid,
1773 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
1774 up,
1775 global.rlimit_memmax,
1776 global.rlimit_nofile,
Willy Tarreau91886b62011-09-07 14:38:31 +02001777 global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001778 actconn, pipes_used, pipes_free,
Willy Tarreau9cd552d2011-09-07 15:26:48 +02001779 read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max,
William Lallemandd85f9172012-11-09 17:05:39 +01001780 read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out),
William Lallemand096f5542012-11-19 17:26:05 +01001781 global.comp_rate_lim,
William Lallemande3a7d992012-11-20 11:25:20 +01001782#ifdef USE_ZLIB
1783 zlib_used_memory, global.maxzlibmem,
1784#endif
Willy Tarreau45a12512011-09-10 16:56:42 +02001785 nb_tasks_cur, run_queue_cur, idle_pct,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001786 global.node, global.desc?global.desc:""
Willy Tarreaua8efd362008-01-03 10:19:15 +01001787 );
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001788 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001789 return 0;
1790 }
1791
Willy Tarreau295a8372011-03-10 11:25:07 +01001792 si->applet.ctx.stats.px = proxy;
1793 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
1794 si->applet.ctx.stats.sv = NULL;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001795 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001796 /* fall through */
1797
Willy Tarreau295a8372011-03-10 11:25:07 +01001798 case STAT_ST_LIST:
Willy Tarreau3e76e722007-10-17 18:57:38 +02001799 /* dump proxies */
Willy Tarreau295a8372011-03-10 11:25:07 +01001800 if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) {
1801 while (si->applet.ctx.stats.px) {
1802 px = si->applet.ctx.stats.px;
Willy Tarreau050536d2012-10-04 08:47:34 +02001803 /* skip the disabled proxies, global frontend and non-networked ones */
1804 if (px->state != PR_STSTOPPED && px->uuid > 0 &&
Willy Tarreau24955a12009-10-04 11:54:04 +02001805 (px->cap & (PR_CAP_FE | PR_CAP_BE))) {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001806 if (stats_dump_proxy(si, px, NULL) == 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001807 return 0;
Willy Tarreau24955a12009-10-04 11:54:04 +02001808 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001809
Willy Tarreau295a8372011-03-10 11:25:07 +01001810 si->applet.ctx.stats.px = px->next;
1811 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreaua8efd362008-01-03 10:19:15 +01001812 }
1813 /* here, we just have reached the last proxy */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001814 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001815
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001816 si->conn->xprt_st = STAT_ST_END;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001817 /* fall through */
1818
Willy Tarreau295a8372011-03-10 11:25:07 +01001819 case STAT_ST_END:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001820 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau0a464892008-12-07 18:30:00 +01001821 /* fall through */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001822
Willy Tarreau295a8372011-03-10 11:25:07 +01001823 case STAT_ST_FIN:
Willy Tarreau3e76e722007-10-17 18:57:38 +02001824 return 1;
1825
1826 default:
1827 /* unknown state ! */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001828 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau24955a12009-10-04 11:54:04 +02001829 return 1;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001830 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001831}
1832
1833
Cyril Bonté70be45d2010-10-12 00:14:35 +02001834/* We don't want to land on the posted stats page because a refresh will
1835 * repost the data. We don't want this to happen on accident so we redirect
1836 * the browse to the stats page with a GET.
1837 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001838static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri)
Cyril Bonté70be45d2010-10-12 00:14:35 +02001839{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001840 struct session *s = si->conn->xprt_ctx;
Cyril Bonté70be45d2010-10-12 00:14:35 +02001841
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001842 chunk_reset(&trash);
Cyril Bonté70be45d2010-10-12 00:14:35 +02001843
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001844 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001845 case STAT_ST_INIT:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001846 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02001847 "HTTP/1.0 303 See Other\r\n"
1848 "Cache-Control: no-cache\r\n"
1849 "Content-Type: text/plain\r\n"
1850 "Connection: close\r\n"
1851 "Location: %s;st=%s",
Cyril Bonté19979e12012-04-04 12:57:21 +02001852 uri->uri_prefix,
1853 ((si->applet.ctx.stats.st_code > STAT_STATUS_INIT) &&
1854 (si->applet.ctx.stats.st_code < STAT_STATUS_SIZE) &&
1855 stat_status_codes[si->applet.ctx.stats.st_code]) ?
1856 stat_status_codes[si->applet.ctx.stats.st_code] :
1857 stat_status_codes[STAT_STATUS_UNKN]);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001858 chunk_appendf(&trash, "\r\n\r\n");
Cyril Bonté70be45d2010-10-12 00:14:35 +02001859
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001860 if (bi_putchk(si->ib, &trash) == -1)
Cyril Bonté70be45d2010-10-12 00:14:35 +02001861 return 0;
1862
1863 s->txn.status = 303;
1864
1865 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1866 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1867 if (!(s->flags & SN_FINST_MASK))
1868 s->flags |= SN_FINST_R;
1869
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001870 si->conn->xprt_st = STAT_ST_FIN;
Cyril Bonté70be45d2010-10-12 00:14:35 +02001871 return 1;
1872 }
1873 return 1;
1874}
1875
1876
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001877/* This I/O handler runs as an applet embedded in a stream interface. It is
1878 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
Willy Tarreaubc4af052011-02-13 13:25:14 +01001879 * si->applet.st0 becomes non-zero once the transfer is finished. The handler
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001880 * automatically unregisters itself once transfer is complete.
1881 */
Willy Tarreaub24281b2011-02-13 13:16:36 +01001882static void http_stats_io_handler(struct stream_interface *si)
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001883{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001884 struct session *s = si->conn->xprt_ctx;
Willy Tarreau7421efb2012-07-02 15:11:27 +02001885 struct channel *req = si->ob;
1886 struct channel *res = si->ib;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001887
1888 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
1889 goto out;
1890
1891 /* check that the output is not closed */
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001892 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001893 si->applet.st0 = 1;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001894
Willy Tarreaubc4af052011-02-13 13:25:14 +01001895 if (!si->applet.st0) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02001896 if (s->txn.meth == HTTP_METH_POST) {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001897 if (stats_http_redir(si, s->be->uri_auth)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001898 si->applet.st0 = 1;
Willy Tarreau73b013b2012-05-21 16:31:45 +02001899 si_shutw(si);
Cyril Bonté70be45d2010-10-12 00:14:35 +02001900 }
1901 } else {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001902 if (stats_dump_http(si, s->be->uri_auth)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001903 si->applet.st0 = 1;
Willy Tarreau73b013b2012-05-21 16:31:45 +02001904 si_shutw(si);
Cyril Bonté70be45d2010-10-12 00:14:35 +02001905 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001906 }
1907 }
1908
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001909 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST))
Willy Tarreau73b013b2012-05-21 16:31:45 +02001910 si_shutw(si);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001911
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001912 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && si->applet.st0) {
Willy Tarreau73b013b2012-05-21 16:31:45 +02001913 si_shutr(si);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001914 res->flags |= CF_READ_NULL;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001915 }
1916
1917 /* update all other flags and resync with the other side */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001918 si_update(si);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001919
1920 /* we don't want to expire timeouts while we're processing requests */
1921 si->ib->rex = TICK_ETERNITY;
1922 si->ob->wex = TICK_ETERNITY;
1923
1924 out:
1925 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1926 /* check that we have released everything then unregister */
1927 stream_int_unregister_handler(si);
1928 }
1929}
1930
1931
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001932/* This function dumps statistics in HTTP format onto the stream interface's
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02001933 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001934 * properly set. It returns 0 if it had to stop writing data and an I/O is
1935 * needed, 1 if the dump is finished and the session must be closed, or -1
1936 * in case of any error.
Willy Tarreau91861262007-10-17 17:06:05 +02001937 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001938static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001939{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001940 struct session *s = si->conn->xprt_ctx;
Willy Tarreau7421efb2012-07-02 15:11:27 +02001941 struct channel *rep = si->ib;
Willy Tarreau91861262007-10-17 17:06:05 +02001942 struct proxy *px;
Willy Tarreau91861262007-10-17 17:06:05 +02001943 unsigned int up;
1944
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001945 chunk_reset(&trash);
Willy Tarreau91861262007-10-17 17:06:05 +02001946
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001947 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001948 case STAT_ST_INIT:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001949 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02001950 "HTTP/1.0 200 OK\r\n"
1951 "Cache-Control: no-cache\r\n"
1952 "Connection: close\r\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001953 "Content-Type: %s\r\n",
Willy Tarreau295a8372011-03-10 11:25:07 +01001954 (si->applet.ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html");
Willy Tarreau91861262007-10-17 17:06:05 +02001955
Willy Tarreau295a8372011-03-10 11:25:07 +01001956 if (uri->refresh > 0 && !(si->applet.ctx.stats.flags & STAT_NO_REFRESH))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001957 chunk_appendf(&trash, "Refresh: %d\r\n",
Willy Tarreau91861262007-10-17 17:06:05 +02001958 uri->refresh);
1959
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001960 chunk_appendf(&trash, "\r\n");
Willy Tarreau91861262007-10-17 17:06:05 +02001961
1962 s->txn.status = 200;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001963 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau56a560a2009-09-22 19:27:35 +02001964 return 0;
1965
Willy Tarreau91861262007-10-17 17:06:05 +02001966 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1967 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1968 if (!(s->flags & SN_FINST_MASK))
1969 s->flags |= SN_FINST_R;
1970
1971 if (s->txn.meth == HTTP_METH_HEAD) {
1972 /* that's all we return in case of HEAD request */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001973 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001974 return 1;
1975 }
1976
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001977 si->conn->xprt_st = STAT_ST_HEAD; /* let's start producing data */
Willy Tarreau91861262007-10-17 17:06:05 +02001978 /* fall through */
1979
Willy Tarreau295a8372011-03-10 11:25:07 +01001980 case STAT_ST_HEAD:
1981 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001982 /* WARNING! This must fit in the first buffer !!! */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001983 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001984 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
1985 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001986 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001987 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
1988 "<style type=\"text/css\"><!--\n"
1989 "body {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001990 " font-family: arial, helvetica, sans-serif;"
Willy Tarreau91861262007-10-17 17:06:05 +02001991 " font-size: 12px;"
1992 " font-weight: normal;"
1993 " color: black;"
1994 " background: white;"
1995 "}\n"
1996 "th,td {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001997 " font-size: 10px;"
Willy Tarreau91861262007-10-17 17:06:05 +02001998 "}\n"
1999 "h1 {"
Willy Tarreauda6721b2009-07-15 10:07:05 +02002000 " font-size: x-large;"
Willy Tarreau91861262007-10-17 17:06:05 +02002001 " margin-bottom: 0.5em;"
2002 "}\n"
2003 "h2 {"
2004 " font-family: helvetica, arial;"
2005 " font-size: x-large;"
2006 " font-weight: bold;"
2007 " font-style: italic;"
2008 " color: #6020a0;"
2009 " margin-top: 0em;"
2010 " margin-bottom: 0em;"
2011 "}\n"
2012 "h3 {"
2013 " font-family: helvetica, arial;"
2014 " font-size: 16px;"
2015 " font-weight: bold;"
2016 " color: #b00040;"
2017 " background: #e8e8d0;"
2018 " margin-top: 0em;"
2019 " margin-bottom: 0em;"
2020 "}\n"
2021 "li {"
2022 " margin-top: 0.25em;"
2023 " margin-right: 2em;"
2024 "}\n"
2025 ".hr {margin-top: 0.25em;"
2026 " border-color: black;"
2027 " border-bottom-style: solid;"
2028 "}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002029 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002030 ".total {background: #20D0D0;color: #ffff80;}\n"
2031 ".frontend {background: #e8e8d0;}\n"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002032 ".socket {background: #d0d0d0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002033 ".backend {background: #e8e8d0;}\n"
2034 ".active0 {background: #ff9090;}\n"
2035 ".active1 {background: #ffd020;}\n"
2036 ".active2 {background: #ffffa0;}\n"
2037 ".active3 {background: #c0ffc0;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002038 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
2039 ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
2040 ".active6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002041 ".backup0 {background: #ff9090;}\n"
2042 ".backup1 {background: #ff80ff;}\n"
2043 ".backup2 {background: #c060ff;}\n"
2044 ".backup3 {background: #b0d0ff;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002045 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
2046 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
2047 ".backup6 {background: #e0e0e0;}\n"
Cyril Bontécd19e512010-01-31 22:34:03 +01002048 ".maintain {background: #c07820;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +02002049 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002050 "\n"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002051 "a.px:link {color: #ffff40; text-decoration: none;}"
2052 "a.px:visited {color: #ffff40; text-decoration: none;}"
2053 "a.px:hover {color: #ffffff; text-decoration: none;}"
2054 "a.lfsb:link {color: #000000; text-decoration: none;}"
2055 "a.lfsb:visited {color: #000000; text-decoration: none;}"
2056 "a.lfsb:hover {color: #505050; text-decoration: none;}"
2057 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002058 "table.tbl { border-collapse: collapse; border-style: none;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002059 "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"
2060 "table.tbl td.ac { text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002061 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002062 "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 +02002063 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002064 "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 +02002065 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002066 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
2067 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
2068 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
Willy Tarreaue0454092010-02-26 12:29:07 +01002069 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002070 "-->\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02002071 "</style></head>\n",
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002072 (uri->flags&ST_SHNODE) ? " on " : "",
2073 (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02002074 );
Willy Tarreau55bb8452007-10-17 18:44:57 +02002075 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002076 print_csv_header(&trash);
Willy Tarreau55bb8452007-10-17 18:44:57 +02002077 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002078 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02002079 return 0;
2080
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002081 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau91861262007-10-17 17:06:05 +02002082 /* fall through */
2083
Willy Tarreau295a8372011-03-10 11:25:07 +01002084 case STAT_ST_INFO:
Willy Tarreau91861262007-10-17 17:06:05 +02002085 up = (now.tv_sec - start_date.tv_sec);
2086
2087 /* WARNING! this has to fit the first packet too.
2088 * We are around 3.5 kB, add adding entries will
2089 * become tricky if we want to support 4kB buffers !
2090 */
Willy Tarreau295a8372011-03-10 11:25:07 +01002091 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002092 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002093 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
2094 PRODUCT_NAME "%s</a></h1>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002095 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002096 "<hr width=\"100%%\" class=\"hr\">\n"
2097 "<h3>&gt; General process information</h3>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002098 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01002099 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002100 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002101 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
2102 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
Willy Tarreau9cd552d2011-09-07 15:26:48 +02002103 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n"
Willy Tarreau45a12512011-09-10 16:56:42 +02002104 "Running tasks: %d/%d; idle = %d %%<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002105 "</td><td align=\"center\" nowrap>\n"
2106 "<table class=\"lgd\"><tr>\n"
2107 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
2108 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
2109 "</tr><tr>\n"
2110 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
2111 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
2112 "</tr><tr>\n"
2113 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
2114 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
2115 "</tr><tr>\n"
2116 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002117 "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
Cyril Bontécd19e512010-01-31 22:34:03 +01002118 "</tr><tr>\n"
2119 "<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 +02002120 "</tr></table>\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002121 "Note: UP with load-balancing disabled is reported as \"NOLB\"."
Willy Tarreau91861262007-10-17 17:06:05 +02002122 "</td>"
2123 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2124 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
2125 "",
2126 (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002127 pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
2128 (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
2129 pid, relative_pid, global.nbproc,
Willy Tarreau91861262007-10-17 17:06:05 +02002130 up / 86400, (up % 86400) / 3600,
2131 (up % 3600) / 60, (up % 60),
2132 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
2133 global.rlimit_memmax ? " MB" : "",
2134 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +01002135 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreau9cd552d2011-09-07 15:26:48 +02002136 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
Willy Tarreau45a12512011-09-10 16:56:42 +02002137 run_queue_cur, nb_tasks_cur, idle_pct
Willy Tarreau91861262007-10-17 17:06:05 +02002138 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002139
Willy Tarreau295a8372011-03-10 11:25:07 +01002140 if (si->applet.ctx.stats.flags & STAT_HIDE_DOWN)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002141 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002142 "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
2143 uri->uri_prefix,
2144 "",
Willy Tarreau295a8372011-03-10 11:25:07 +01002145 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002146 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002147 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002148 "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
2149 uri->uri_prefix,
2150 ";up",
Willy Tarreau295a8372011-03-10 11:25:07 +01002151 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02002152
Willy Tarreau55bb8452007-10-17 18:44:57 +02002153 if (uri->refresh > 0) {
Willy Tarreau295a8372011-03-10 11:25:07 +01002154 if (si->applet.ctx.stats.flags & STAT_NO_REFRESH)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002155 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002156 "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
2157 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01002158 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02002159 "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002160 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002161 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002162 "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
2163 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01002164 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02002165 ";norefresh");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002166 }
Willy Tarreau91861262007-10-17 17:06:05 +02002167
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002168 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002169 "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
2170 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01002171 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2172 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02002173
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002174 chunk_appendf(&trash,
Willy Tarreau5031e6a2007-10-18 11:05:48 +02002175 "<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
2176 uri->uri_prefix,
2177 (uri->refresh > 0) ? ";norefresh" : "");
2178
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002179 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002180 "</ul></td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002181 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
Adrian Bridgettafdb6e52012-03-19 23:36:42 +00002182 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002183 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
2184 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
2185 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
2186 "</ul>"
2187 "</td>"
2188 "</tr></table>\n"
2189 ""
2190 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002191
Willy Tarreau295a8372011-03-10 11:25:07 +01002192 if (si->applet.ctx.stats.st_code) {
Cyril Bonté19979e12012-04-04 12:57:21 +02002193 switch (si->applet.ctx.stats.st_code) {
2194 case STAT_STATUS_DONE:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002195 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002196 "<p><div class=active3>"
2197 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2198 "Action processed successfully."
2199 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002200 break;
2201 case STAT_STATUS_NONE:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002202 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002203 "<p><div class=active2>"
2204 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2205 "Nothing has changed."
2206 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002207 break;
2208 case STAT_STATUS_PART:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002209 chunk_appendf(&trash,
Cyril Bontécf8d9ae2012-04-04 12:57:18 +02002210 "<p><div class=active2>"
2211 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2212 "Action partially processed.<br>"
2213 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
2214 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002215 break;
2216 case STAT_STATUS_ERRP:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002217 chunk_appendf(&trash,
Cyril Bontécf8d9ae2012-04-04 12:57:18 +02002218 "<p><div class=active0>"
2219 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2220 "Action not processed because of invalid parameters."
2221 "<ul>"
2222 "<li>The action is maybe unknown.</li>"
2223 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
2224 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
2225 "</ul>"
2226 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002227 break;
2228 case STAT_STATUS_EXCD:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002229 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002230 "<p><div class=active0>"
2231 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2232 "<b>Action not processed : the buffer couldn't store all the data.<br>"
2233 "You should retry with less servers at a time.</b>"
2234 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002235 break;
2236 case STAT_STATUS_DENY:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002237 chunk_appendf(&trash,
Cyril Bonté474be412010-10-12 00:14:36 +02002238 "<p><div class=active0>"
2239 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2240 "<b>Action denied.</b>"
2241 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002242 break;
2243 default:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002244 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002245 "<p><div class=active6>"
2246 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2247 "Unexpected result."
2248 "</div>\n", uri->uri_prefix);
2249 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002250 chunk_appendf(&trash,"<p>\n");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002251 }
2252
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002253 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002254 return 0;
2255 }
Willy Tarreau91861262007-10-17 17:06:05 +02002256
Willy Tarreau295a8372011-03-10 11:25:07 +01002257 si->applet.ctx.stats.px = proxy;
2258 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002259 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau91861262007-10-17 17:06:05 +02002260 /* fall through */
2261
Willy Tarreau295a8372011-03-10 11:25:07 +01002262 case STAT_ST_LIST:
Willy Tarreau91861262007-10-17 17:06:05 +02002263 /* dump proxies */
Willy Tarreau295a8372011-03-10 11:25:07 +01002264 while (si->applet.ctx.stats.px) {
Willy Tarreau9b28e032012-10-12 23:49:43 +02002265 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002266 return 0;
Willy Tarreau295a8372011-03-10 11:25:07 +01002267 px = si->applet.ctx.stats.px;
Willy Tarreau050536d2012-10-04 08:47:34 +02002268 /* skip the disabled proxies, global frontend and non-networked ones */
2269 if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002270 if (stats_dump_proxy(si, px, uri) == 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002271 return 0;
2272
Willy Tarreau295a8372011-03-10 11:25:07 +01002273 si->applet.ctx.stats.px = px->next;
2274 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreau91861262007-10-17 17:06:05 +02002275 }
2276 /* here, we just have reached the last proxy */
2277
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002278 si->conn->xprt_st = STAT_ST_END;
Willy Tarreau91861262007-10-17 17:06:05 +02002279 /* fall through */
2280
Willy Tarreau295a8372011-03-10 11:25:07 +01002281 case STAT_ST_END:
2282 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002283 chunk_appendf(&trash, "</body></html>\n");
2284 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002285 return 0;
2286 }
Willy Tarreau91861262007-10-17 17:06:05 +02002287
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002288 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02002289 /* fall through */
2290
Willy Tarreau295a8372011-03-10 11:25:07 +01002291 case STAT_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02002292 return 1;
2293
2294 default:
2295 /* unknown state ! */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002296 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02002297 return -1;
2298 }
2299}
2300
2301
2302/*
2303 * Dumps statistics for a proxy.
2304 * Returns 0 if it had to stop dumping data because of lack of buffer space,
2305 * ot non-zero if everything completed.
2306 */
Simon Horman9bd2c732011-06-15 15:18:44 +09002307static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02002308{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002309 struct session *s = si->conn->xprt_ctx;
Willy Tarreau7421efb2012-07-02 15:11:27 +02002310 struct channel *rep = si->ib;
Willy Tarreau44267702011-10-28 15:35:33 +02002311 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002312 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02002313
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002314 chunk_reset(&trash);
Willy Tarreau91861262007-10-17 17:06:05 +02002315
Willy Tarreau295a8372011-03-10 11:25:07 +01002316 switch (si->applet.ctx.stats.px_st) {
2317 case STAT_PX_ST_INIT:
Willy Tarreau91861262007-10-17 17:06:05 +02002318 /* we are on a new proxy */
2319
2320 if (uri && uri->scope) {
2321 /* we have a limited scope, we have to check the proxy name */
2322 struct stat_scope *scope;
2323 int len;
2324
2325 len = strlen(px->id);
2326 scope = uri->scope;
2327
2328 while (scope) {
2329 /* match exact proxy name */
2330 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
2331 break;
2332
2333 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02002334 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02002335 break;
2336 scope = scope->next;
2337 }
2338
2339 /* proxy name not found : don't dump anything */
2340 if (scope == NULL)
2341 return 1;
2342 }
2343
Willy Tarreau295a8372011-03-10 11:25:07 +01002344 if ((si->applet.ctx.stats.flags & STAT_BOUND) && (si->applet.ctx.stats.iid != -1) &&
2345 (px->uuid != si->applet.ctx.stats.iid))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002346 return 1;
2347
Willy Tarreau295a8372011-03-10 11:25:07 +01002348 si->applet.ctx.stats.px_st = STAT_PX_ST_TH;
Willy Tarreau91861262007-10-17 17:06:05 +02002349 /* fall through */
2350
Willy Tarreau295a8372011-03-10 11:25:07 +01002351 case STAT_PX_ST_TH:
2352 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
2353 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002354 /* A form to enable/disable this proxy servers */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002355 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002356 "<form action=\"%s\" method=\"post\">",
2357 uri->uri_prefix);
2358 }
2359
Willy Tarreau55bb8452007-10-17 18:44:57 +02002360 /* print a new table */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002361 chunk_appendf(&trash,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002362 "<table class=\"tbl\" width=\"100%%\">\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002363 "<tr class=\"titre\">"
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002364 "<th class=\"pxname\" width=\"10%%\"");
2365
2366 if (uri->flags&ST_SHLGNDS) {
2367 /* cap, mode, id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002368 chunk_appendf(&trash, " title=\"cap: %s, mode: %s, id: %d",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002369 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
2370 px->uuid);
2371
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002372 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002373 }
2374
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002375 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002376 ">%s<a name=\"%s\"></a>"
2377 "<a class=px href=\"#%s\">%s</a>%s</th>"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002378 "<th class=\"%s\" width=\"90%%\">%s</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002379 "</tr>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002380 "</table>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002381 "<table class=\"tbl\" width=\"100%%\">\n"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002382 "<tr class=\"titre\">",
2383 (uri->flags & ST_SHLGNDS)?"<u>":"",
2384 px->id, px->id, px->id,
2385 (uri->flags & ST_SHLGNDS)?"</u>":"",
2386 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
2387
Willy Tarreau295a8372011-03-10 11:25:07 +01002388 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002389 /* Column heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002390 chunk_appendf(&trash, "<th rowspan=2 width=1></th>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002391 }
2392
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002393 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002394 "<th rowspan=2></th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002395 "<th colspan=3>Queue</th>"
2396 "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002397 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002398 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002399 "<th colspan=9>Server</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002400 "</tr>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002401 "<tr class=\"titre\">"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002402 "<th>Cur</th><th>Max</th><th>Limit</th>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002403 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002404 "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002405 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002406 "<th>Resp</th><th>Retr</th><th>Redis</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002407 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002408 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
2409 "<th>Thrtle</th>\n"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002410 "</tr>");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002411
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002412 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002413 return 0;
2414 }
Willy Tarreau91861262007-10-17 17:06:05 +02002415
Willy Tarreau295a8372011-03-10 11:25:07 +01002416 si->applet.ctx.stats.px_st = STAT_PX_ST_FE;
Willy Tarreau91861262007-10-17 17:06:05 +02002417 /* fall through */
2418
Willy Tarreau295a8372011-03-10 11:25:07 +01002419 case STAT_PX_ST_FE:
Willy Tarreau91861262007-10-17 17:06:05 +02002420 /* print the frontend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002421 if ((px->cap & PR_CAP_FE) &&
Willy Tarreau295a8372011-03-10 11:25:07 +01002422 (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_FE)))) {
2423 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002424 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002425 /* name, queue */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002426 "<tr class=\"frontend\">");
2427
Willy Tarreau295a8372011-03-10 11:25:07 +01002428 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002429 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002430 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002431 }
2432
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002433 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002434 "<td class=ac>"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002435 "<a name=\"%s/Frontend\"></a>"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002436 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
2437 "<td colspan=3></td>"
Willy Tarreaub44939a2010-02-26 11:35:39 +01002438 "",
2439 px->id, px->id);
2440
2441 if (px->mode == PR_MODE_HTTP) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002442 chunk_appendf(&trash,
Willy Tarreaub44939a2010-02-26 11:35:39 +01002443 /* sessions rate : current, max, limit */
Willy Tarreaue0454092010-02-26 12:29:07 +01002444 "<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 +01002445 "",
2446 read_freq_ctr(&px->fe_req_per_sec),
2447 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002448 px->fe_counters.p.http.rps_max,
2449 U2H1(px->fe_counters.sps_max),
Willy Tarreaub44939a2010-02-26 11:35:39 +01002450 LIM2A2(px->fe_sps_lim, "-"));
2451 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002452 chunk_appendf(&trash,
Willy Tarreaub44939a2010-02-26 11:35:39 +01002453 /* sessions rate : current, max, limit */
2454 "<td>%s</td><td>%s</td><td>%s</td>"
2455 "",
2456 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002457 U2H1(px->fe_counters.sps_max), LIM2A2(px->fe_sps_lim, "-"));
Willy Tarreaub44939a2010-02-26 11:35:39 +01002458 }
2459
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002460 chunk_appendf(&trash,
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002461 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002462 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002463 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002464 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002465 U2H3(px->feconn), U2H4(px->fe_counters.conn_max), U2H5(px->maxconn));
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002466
2467 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2468 if (px->mode == PR_MODE_HTTP) {
2469 int i;
2470
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002471 chunk_appendf(&trash, " title=\"%lld requests:", px->fe_counters.p.http.cum_req);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002472
2473 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002474 chunk_appendf(&trash, " %dxx=%lld,", i, px->fe_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002475
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002476 chunk_appendf(&trash, " other=%lld,", px->fe_counters.p.http.rsp[0]);
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002477 chunk_appendf(&trash, " compressed=%lld (%d%%)",
2478 px->fe_counters.p.http.comp_rsp,
Willy Tarreau78bbeb42012-11-26 16:44:48 +01002479 px->fe_counters.p.http.rsp[2] ?
Willy Tarreau5730c682012-11-26 14:13:09 +01002480 (int)(100*px->fe_counters.p.http.comp_rsp/px->fe_counters.p.http.rsp[2]) : 0);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002481 chunk_appendf(&trash, " intercepted=%lld\"", px->fe_counters.intercepted_req);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002482 }
2483
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002484 chunk_appendf(&trash,
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002485 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002486 ">%s%s%s</td><td></td>"
Willy Tarreau55058a72012-11-21 08:27:21 +01002487 /* bytes : in */
2488 "<td>%s</td><td"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002489 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002490 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002491 U2H6(px->fe_counters.cum_sess),
Willy Tarreaue0454092010-02-26 12:29:07 +01002492 (px->mode == PR_MODE_HTTP)?"</u>":"",
Willy Tarreau55058a72012-11-21 08:27:21 +01002493 U2H7(px->fe_counters.bytes_in));
2494
2495 /* compression stats (via td title): comp_in, comp_out, comp_byp */
Willy Tarreauf149d8f2012-11-24 14:06:49 +01002496 chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld savings=%d%%\"",
2497 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp,
2498 px->fe_counters.comp_in ?
2499 (int)((px->fe_counters.comp_in - px->fe_counters.comp_out)*100/px->fe_counters.comp_in) : 0);
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002500
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002501 chunk_appendf(&trash,
Willy Tarreau55058a72012-11-21 08:27:21 +01002502 /* bytes: out */
2503 ">%s%s%s</td>"
2504 "",
2505 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"",
2506 U2H0(px->fe_counters.bytes_out),
2507 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":"");
2508
2509 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002510 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002511 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002512 /* errors : request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002513 "<td>%s</td><td></td><td></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002514 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002515 "<td></td><td></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002516 /* server status : reflect frontend status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002517 "<td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002518 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002519 "<td class=ac colspan=8></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +02002520 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002521 U2H0(px->fe_counters.denied_req), U2H1(px->fe_counters.denied_resp),
2522 U2H2(px->fe_counters.failed_req),
Willy Tarreau562515c2011-07-25 08:11:52 +02002523 px->state == PR_STREADY ? "OPEN" :
2524 px->state == PR_STFULL ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002525 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002526 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002527 /* pxid, name, queue cur, queue max, */
2528 "%s,FRONTEND,,,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002529 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002530 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002531 /* bytes : in, out */
2532 "%lld,%lld,"
2533 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002534 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002535 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002536 "%lld,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002537 /* warnings: retries, redispatches */
2538 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002539 /* server status : reflect frontend status */
2540 "%s,"
2541 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002542 ",,,,,,,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002543 /* pid, iid, sid, throttle, lbtot, tracked, type */
2544 "%d,%d,0,,,,%d,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002545 /* rate, rate_lim, rate_max */
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002546 "%u,%u,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002547 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002548 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02002549 px->id,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002550 px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess,
2551 px->fe_counters.bytes_in, px->fe_counters.bytes_out,
2552 px->fe_counters.denied_req, px->fe_counters.denied_resp,
2553 px->fe_counters.failed_req,
Willy Tarreau562515c2011-07-25 08:11:52 +02002554 px->state == PR_STREADY ? "OPEN" :
2555 px->state == PR_STFULL ? "FULL" : "STOP",
Willy Tarreau7f062c42009-03-05 18:43:00 +01002556 relative_pid, px->uuid, STATS_TYPE_FE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002557 read_freq_ctr(&px->fe_sess_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002558 px->fe_sps_lim, px->fe_counters.sps_max);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002559
2560 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2561 if (px->mode == PR_MODE_HTTP) {
2562 int i;
2563
2564 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002565 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002566
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002567 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002568 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002569 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002570 }
2571
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002572 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002573 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002574
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002575 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002576 chunk_appendf(&trash, "%u,%u,%lld,",
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002577 read_freq_ctr(&px->fe_req_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002578 px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req);
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002579
Willy Tarreauae526782010-03-04 20:34:23 +01002580 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002581 chunk_appendf(&trash, ",,");
Willy Tarreauae526782010-03-04 20:34:23 +01002582
Willy Tarreau55058a72012-11-21 08:27:21 +01002583 /* compression: in, out, bypassed */
2584 chunk_appendf(&trash, "%lld,%lld,%lld,",
2585 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
2586
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002587 /* compression: comp_rsp */
2588 chunk_appendf(&trash, "%lld,",
2589 px->fe_counters.p.http.comp_rsp);
2590
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002591 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002592 chunk_appendf(&trash, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002593 }
Willy Tarreau91861262007-10-17 17:06:05 +02002594
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002595 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02002596 return 0;
2597 }
2598
Willy Tarreau4348fad2012-09-20 16:48:07 +02002599 si->applet.ctx.stats.l = px->conf.listeners.n;
Willy Tarreau295a8372011-03-10 11:25:07 +01002600 si->applet.ctx.stats.px_st = STAT_PX_ST_LI;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002601 /* fall through */
2602
Willy Tarreau295a8372011-03-10 11:25:07 +01002603 case STAT_PX_ST_LI:
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002604 /* stats.l has been initialized above */
Willy Tarreau4348fad2012-09-20 16:48:07 +02002605 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 +02002606 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002607 return 0;
2608
Willy Tarreau4348fad2012-09-20 16:48:07 +02002609 l = LIST_ELEM(si->applet.ctx.stats.l, struct listener *, by_fe);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002610 if (!l->counters)
2611 continue;
2612
Willy Tarreau295a8372011-03-10 11:25:07 +01002613 if (si->applet.ctx.stats.flags & STAT_BOUND) {
2614 if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SO)))
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002615 break;
2616
Willy Tarreau295a8372011-03-10 11:25:07 +01002617 if (si->applet.ctx.stats.sid != -1 && l->luid != si->applet.ctx.stats.sid)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002618 continue;
2619 }
2620
Willy Tarreau295a8372011-03-10 11:25:07 +01002621 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002622 chunk_appendf(&trash, "<tr class=socket>");
Willy Tarreau295a8372011-03-10 11:25:07 +01002623 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002624 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002625 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002626 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002627 chunk_appendf(&trash, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002628
2629 if (uri->flags&ST_SHLGNDS) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02002630 char str[INET6_ADDRSTRLEN];
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002631 int port;
2632
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002633 chunk_appendf(&trash, " title=\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002634
Willy Tarreau631f01c2011-09-05 00:36:48 +02002635 port = get_host_port(&l->addr);
2636 switch (addr_to_str(&l->addr, str, sizeof(str))) {
2637 case AF_INET:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002638 chunk_appendf(&trash, "IPv4: %s:%d, ", str, port);
Willy Tarreau631f01c2011-09-05 00:36:48 +02002639 break;
2640 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002641 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port);
Willy Tarreau631f01c2011-09-05 00:36:48 +02002642 break;
2643 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002644 chunk_appendf(&trash, "unix, ");
Willy Tarreau631f01c2011-09-05 00:36:48 +02002645 break;
2646 case -1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002647 chunk_appendf(&trash, "(%s), ", strerror(errno));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002648 break;
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002649 }
2650
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002651 /* id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002652 chunk_appendf(&trash, "id: %d\"", l->luid);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002653 }
2654
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002655 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002656 /* name, queue */
Willy Tarreaue0454092010-02-26 12:29:07 +01002657 ">%s<a name=\"%s/+%s\"></a>"
2658 "<a class=lfsb href=\"#%s/+%s\">%s</a></td><td colspan=3>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002659 /* sessions rate: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002660 "<td colspan=3>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002661 /* sessions: current, max, limit, total, lbtot */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002662 "<td>%s</td><td>%s</td><td>%s</td>"
2663 "<td>%s</td><td>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002664 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002665 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002666 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002667 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki2ec025d2010-01-04 11:33:32 +01002668 px->id, l->name, px->id, l->name, l->name,
Willy Tarreaue0454092010-02-26 12:29:07 +01002669 (uri->flags & ST_SHLGNDS)?"</u>":"",
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002670 U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn),
2671 U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out));
2672
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002673 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002674 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002675 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002676 /* errors: request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002677 "<td>%s</td><td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002678 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002679 "<td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002680 /* server status: reflect listener status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002681 "<td class=ac>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002682 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002683 "<td class=ac colspan=8></td></tr>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002684 "",
2685 U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp),
2686 U2H2(l->counters->failed_req),
Willy Tarreaua17c2d92011-07-25 08:16:20 +02002687 (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002688 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002689 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002690 /* pxid, name, queue cur, queue max, */
2691 "%s,%s,,,"
2692 /* sessions: current, max, limit, total */
2693 "%d,%d,%d,%lld,"
2694 /* bytes: in, out */
2695 "%lld,%lld,"
2696 /* denied: req, resp */
2697 "%lld,%lld,"
2698 /* errors: request, connect, response */
2699 "%lld,,,"
2700 /* warnings: retries, redispatches */
2701 ",,"
2702 /* server status: reflect listener status */
2703 "%s,"
2704 /* rest of server: nothing */
2705 ",,,,,,,,"
2706 /* pid, iid, sid, throttle, lbtot, tracked, type */
2707 "%d,%d,%d,,,,%d,"
2708 /* rate, rate_lim, rate_max */
2709 ",,,"
2710 /* check_status, check_code, check_duration */
2711 ",,,"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002712 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2713 ",,,,,,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002714 /* failed health analyses */
2715 ","
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002716 /* requests : req_rate, req_rate_max, req_tot, */
2717 ",,,"
Willy Tarreauae526782010-03-04 20:34:23 +01002718 /* errors: cli_aborts, srv_aborts */
2719 ",,"
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002720 /* compression: in, out, bypassed, comp_rsp */
2721 ",,,,"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002722 "\n",
2723 px->id, l->name,
2724 l->nbconn, l->counters->conn_max,
2725 l->maxconn, l->counters->cum_conn,
2726 l->counters->bytes_in, l->counters->bytes_out,
2727 l->counters->denied_req, l->counters->denied_resp,
2728 l->counters->failed_req,
2729 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
2730 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
2731 }
2732
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002733 if (bi_putchk(rep, &trash) == -1)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002734 return 0;
2735 }
2736
Willy Tarreau295a8372011-03-10 11:25:07 +01002737 si->applet.ctx.stats.sv = px->srv; /* may be NULL */
2738 si->applet.ctx.stats.px_st = STAT_PX_ST_SV;
Willy Tarreau91861262007-10-17 17:06:05 +02002739 /* fall through */
2740
Willy Tarreau295a8372011-03-10 11:25:07 +01002741 case STAT_PX_ST_SV:
Willy Tarreau91861262007-10-17 17:06:05 +02002742 /* stats.sv has been initialized above */
Willy Tarreau295a8372011-03-10 11:25:07 +01002743 for (; si->applet.ctx.stats.sv != NULL; si->applet.ctx.stats.sv = sv->next) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002744 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 +02002745
Willy Tarreau9b28e032012-10-12 23:49:43 +02002746 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002747 return 0;
2748
Willy Tarreau295a8372011-03-10 11:25:07 +01002749 sv = si->applet.ctx.stats.sv;
Willy Tarreau91861262007-10-17 17:06:05 +02002750
Willy Tarreau295a8372011-03-10 11:25:07 +01002751 if (si->applet.ctx.stats.flags & STAT_BOUND) {
2752 if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SV)))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002753 break;
2754
Willy Tarreau295a8372011-03-10 11:25:07 +01002755 if (si->applet.ctx.stats.sid != -1 && sv->puid != si->applet.ctx.stats.sid)
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002756 continue;
2757 }
2758
Willy Tarreau44267702011-10-28 15:35:33 +02002759 if (sv->track)
2760 svs = sv->track;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002761 else
2762 svs = sv;
2763
Willy Tarreau91861262007-10-17 17:06:05 +02002764 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002765 if (!(svs->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +01002766 sv_state = 6;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002767 else if (svs->state & SRV_RUNNING) {
2768 if (svs->health == svs->rise + svs->fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02002769 sv_state = 3; /* UP */
2770 else
2771 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01002772
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002773 if (svs->state & SRV_GOINGDOWN)
Willy Tarreau2ea81932007-11-30 12:04:38 +01002774 sv_state += 2;
2775 }
Willy Tarreau91861262007-10-17 17:06:05 +02002776 else
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002777 if (svs->health)
Willy Tarreau91861262007-10-17 17:06:05 +02002778 sv_state = 1; /* going up */
2779 else
2780 sv_state = 0; /* DOWN */
2781
Willy Tarreau295a8372011-03-10 11:25:07 +01002782 if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (si->applet.ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02002783 /* do not report servers which are DOWN */
Willy Tarreau295a8372011-03-10 11:25:07 +01002784 si->applet.ctx.stats.sv = sv->next;
Willy Tarreau91861262007-10-17 17:06:05 +02002785 continue;
2786 }
2787
Willy Tarreau295a8372011-03-10 11:25:07 +01002788 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002789 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
2790 "UP %d/%d &darr;", "UP",
2791 "NOLB %d/%d &darr;", "NOLB",
2792 "<i>no check</i>" };
Cyril Bonté0dae5852010-02-03 00:26:28 +01002793 if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002794 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01002795 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002796 "<tr class=\"maintain\">"
Cyril Bontécd19e512010-01-31 22:34:03 +01002797 );
2798 }
2799 else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002800 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01002801 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002802 "<tr class=\"%s%d\">",
Cyril Bontécd19e512010-01-31 22:34:03 +01002803 (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state);
2804 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002805
Willy Tarreau295a8372011-03-10 11:25:07 +01002806 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002807 chunk_appendf(&trash,
Cyril Bonté474be412010-10-12 00:14:36 +02002808 "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
2809 sv->id);
2810 }
2811
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002812 chunk_appendf(&trash, "<td class=ac");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002813
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002814 if (uri->flags&ST_SHLGNDS) {
2815 char str[INET6_ADDRSTRLEN];
2816
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002817 chunk_appendf(&trash, " title=\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002818
Willy Tarreau631f01c2011-09-05 00:36:48 +02002819 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
David du Colombier6f5ccb12011-03-10 22:26:24 +01002820 case AF_INET:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002821 chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr));
David du Colombier6f5ccb12011-03-10 22:26:24 +01002822 break;
2823 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002824 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002825 break;
2826 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002827 chunk_appendf(&trash, "unix, ");
Willy Tarreau631f01c2011-09-05 00:36:48 +02002828 break;
2829 case -1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002830 chunk_appendf(&trash, "(%s), ", strerror(errno));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002831 break;
2832 default: /* address family not supported */
David du Colombier6f5ccb12011-03-10 22:26:24 +01002833 break;
2834 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002835
2836 /* id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002837 chunk_appendf(&trash, "id: %d", sv->puid);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002838
2839 /* cookie */
2840 if (sv->cookie) {
2841 struct chunk src;
2842
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002843 chunk_appendf(&trash, ", cookie: '");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002844
2845 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002846 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002847
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002848 chunk_appendf(&trash, "'");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002849 }
2850
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002851 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002852 }
2853
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002854 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002855 ">%s<a name=\"%s/%s\"></a>"
2856 "<a class=lfsb href=\"#%s/%s\">%s</a>%s</td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002857 /* queue : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002858 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002859 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002860 "<td>%s</td><td>%s</td><td></td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002861 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002862 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002863 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002864 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002865 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002866 px->id, sv->id, px->id, sv->id, sv->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01002867 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002868 U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"),
2869 U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max),
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002870 U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-"));
2871
2872 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2873 if (px->mode == PR_MODE_HTTP) {
2874 int i;
2875
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002876 chunk_appendf(&trash, " title=\"rsp codes:");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002877
2878 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002879 chunk_appendf(&trash, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002880
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002881 chunk_appendf(&trash, " other=%lld\"", sv->counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002882 }
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002883
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002884 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002885 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002886 ">%s%s%s</td><td>%s</td>",
2887 (px->mode == PR_MODE_HTTP)?"<u>":"",
2888 U2H0(sv->counters.cum_sess),
2889 (px->mode == PR_MODE_HTTP)?"</u>":"",
2890 U2H1(sv->counters.cum_lbconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002891
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002892 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002893 /* bytes : in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002894 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002895 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002896 "<td></td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01002897 /* errors : request, connect */
2898 "<td></td><td>%s</td>"
2899 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002900 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002901 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002902 "<td>%lld</td><td>%lld</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002903 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002904 U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out),
2905 U2H2(sv->counters.failed_secu),
Willy Tarreauae526782010-03-04 20:34:23 +01002906 U2H3(sv->counters.failed_conns),
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002907 sv->counters.cli_aborts,
2908 sv->counters.srv_aborts,
Willy Tarreauae526782010-03-04 20:34:23 +01002909 U2H6(sv->counters.failed_resp),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002910 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002911
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002912 /* status, lest check */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002913 chunk_appendf(&trash, "<td class=ac>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002914
Cyril Bontécd19e512010-01-31 22:34:03 +01002915 if (sv->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002916 chunk_appendf(&trash, "%s ",
Cyril Bontécd19e512010-01-31 22:34:03 +01002917 human_time(now.tv_sec - sv->last_change, 1));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002918 chunk_appendf(&trash, "MAINT");
Cyril Bontécd19e512010-01-31 22:34:03 +01002919 }
Cyril Bonté0dae5852010-02-03 00:26:28 +01002920 else if (svs != sv && svs->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002921 chunk_appendf(&trash, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01002922 human_time(now.tv_sec - svs->last_change, 1));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002923 chunk_appendf(&trash, "MAINT(via)");
Cyril Bonté0dae5852010-02-03 00:26:28 +01002924 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002925 else if (svs->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002926 chunk_appendf(&trash, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01002927 human_time(now.tv_sec - svs->last_change, 1));
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002928
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002929 chunk_appendf(&trash,
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002930 srv_hlt_st[sv_state],
2931 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
2932 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002933 }
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002934
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002935 if (sv->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002936 chunk_appendf(&trash, "</td><td class=ac title=\"%s",
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002937 get_check_status_description(sv->check.status));
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002938
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002939 if (*sv->check.desc) {
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002940 struct chunk src;
2941
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002942 chunk_appendf(&trash, ": ");
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002943
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002944 chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002945 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002946 }
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002947
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002948 chunk_appendf(&trash, "\"><u> %s%s",
Willy Tarreau0eb2bed2012-11-24 00:20:24 +01002949 (sv->state & SRV_CHK_RUNNING) ? "* " : "",
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002950 get_check_status_info(sv->check.status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002951
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002952 if (sv->check.status >= HCHK_STATUS_L57DATA)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002953 chunk_appendf(&trash, "/%d", sv->check.code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002954
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002955 if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002956 chunk_appendf(&trash, " in %lums</u>", sv->check.duration);
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002957 } else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002958 chunk_appendf(&trash, "</td><td>");
Willy Tarreau91861262007-10-17 17:06:05 +02002959
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002960 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002961 /* weight */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002962 "</td><td class=ac>%d</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002963 /* act, bck */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002964 "<td class=ac>%s</td><td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002965 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01002966 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +02002967 (sv->state & SRV_BACKUP) ? "-" : "Y",
2968 (sv->state & SRV_BACKUP) ? "Y" : "-");
2969
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002970 /* check failures: unique, fatal, down time */
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002971 if (sv->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002972 chunk_appendf(&trash, "<td title=\"Failed Health Checks%s\"><u>%lld",
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002973 svs->observe?"/Health Analyses":"", svs->counters.failed_checks);
2974
2975 if (svs->observe)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002976 chunk_appendf(&trash, "/%lld", svs->counters.failed_hana);
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002977
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002978 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002979 "</u></td>"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002980 "<td>%lld</td><td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002981 "",
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002982 svs->counters.down_trans, human_time(srv_downtime(sv), 1));
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002983 } else if (sv != svs)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002984 chunk_appendf(&trash,
Krzysztof Piotr Oledzki88a14af2010-01-05 18:33:01 +01002985 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>",
2986 svs->proxy->id, svs->id, svs->proxy->id, svs->id);
Willy Tarreau55bb8452007-10-17 18:44:57 +02002987 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002988 chunk_appendf(&trash,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002989 "<td colspan=3></td>");
2990
2991 /* throttle */
2992 if ((sv->state & SRV_WARMINGUP) &&
2993 now.tv_sec < sv->last_change + sv->slowstart &&
2994 now.tv_sec >= sv->last_change) {
2995 unsigned int ratio;
2996 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002997 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002998 "<td class=ac>%d %%</td></tr>\n", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002999 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003000 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003001 "<td class=ac>-</td></tr>\n");
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003002 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02003003 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +01003004 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
3005 "UP %d/%d,", "UP,",
3006 "NOLB %d/%d,", "NOLB,",
3007 "no check," };
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003008 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003009 /* pxid, name */
3010 "%s,%s,"
3011 /* queue : current, max */
3012 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003013 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003014 "%d,%d,%s,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003015 /* bytes : in, out */
3016 "%lld,%lld,"
3017 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003018 ",%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003019 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003020 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003021 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003022 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003023 "",
3024 px->id, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02003025 sv->nbpend, sv->counters.nbpend_max,
3026 sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02003027 sv->counters.bytes_in, sv->counters.bytes_out,
3028 sv->counters.failed_secu,
3029 sv->counters.failed_conns, sv->counters.failed_resp,
3030 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003031
Willy Tarreau55bb8452007-10-17 18:44:57 +02003032 /* status */
Cyril Bontécd19e512010-01-31 22:34:03 +01003033 if (sv->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003034 chunk_appendf(&trash, "MAINT,");
Cyril Bonté0dae5852010-02-03 00:26:28 +01003035 }
3036 else if (svs != sv && svs->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003037 chunk_appendf(&trash, "MAINT(via),");
Cyril Bonté0dae5852010-02-03 00:26:28 +01003038 }
3039 else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003040 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01003041 srv_hlt_st[sv_state],
3042 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
3043 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
3044 }
Willy Tarreau91861262007-10-17 17:06:05 +02003045
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003046 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003047 /* weight, active, backup */
3048 "%d,%d,%d,"
3049 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01003050 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003051 (sv->state & SRV_BACKUP) ? 0 : 1,
3052 (sv->state & SRV_BACKUP) ? 1 : 0);
3053
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003054 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +02003055 if (sv->state & SRV_CHECKED)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003056 chunk_appendf(&trash,
Willy Tarreau3b88d442009-04-11 20:44:08 +02003057 "%lld,%lld,%d,%d,",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02003058 sv->counters.failed_checks, sv->counters.down_trans,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003059 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +02003060 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003061 chunk_appendf(&trash,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02003062 ",,,,");
3063
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003064 /* queue limit, pid, iid, sid, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003065 chunk_appendf(&trash,
Willy Tarreaudcd47712007-11-04 23:35:08 +01003066 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003067 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +01003068 LIM2A0(sv->maxqueue, ""),
3069 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003070
3071 /* throttle */
3072 if ((sv->state & SRV_WARMINGUP) &&
3073 now.tv_sec < sv->last_change + sv->slowstart &&
3074 now.tv_sec >= sv->last_change) {
3075 unsigned int ratio;
3076 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003077 chunk_appendf(&trash, "%d", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003078 }
3079
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003080 /* sessions: lbtot */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003081 chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003082
3083 /* tracked */
Willy Tarreau44267702011-10-28 15:35:33 +02003084 if (sv->track)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003085 chunk_appendf(&trash, "%s/%s,",
Willy Tarreau44267702011-10-28 15:35:33 +02003086 sv->track->proxy->id, sv->track->id);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003087 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003088 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003089
Willy Tarreau7f062c42009-03-05 18:43:00 +01003090 /* type */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003091 chunk_appendf(&trash, "%d,", STATS_TYPE_SV);
Willy Tarreau7f062c42009-03-05 18:43:00 +01003092
3093 /* rate */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003094 chunk_appendf(&trash, "%u,,%u,",
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003095 read_freq_ctr(&sv->sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02003096 sv->counters.sps_max);
Willy Tarreau7f062c42009-03-05 18:43:00 +01003097
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003098 if (sv->state & SRV_CHECKED) {
3099 /* check_status */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003100 chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003101
3102 /* check_code */
Willy Tarreau5b3a2022012-09-28 15:01:02 +02003103 if (sv->check.status >= HCHK_STATUS_L57DATA)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003104 chunk_appendf(&trash, "%u,", sv->check.code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003105 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003106 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003107
3108 /* check_duration */
Willy Tarreau5b3a2022012-09-28 15:01:02 +02003109 if (sv->check.status >= HCHK_STATUS_CHECKED)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003110 chunk_appendf(&trash, "%lu,", sv->check.duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003111 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003112 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003113
3114 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003115 chunk_appendf(&trash, ",,,");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003116 }
3117
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003118 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3119 if (px->mode == PR_MODE_HTTP) {
3120 int i;
3121
3122 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003123 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003124
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003125 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003126 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003127 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003128 }
3129
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003130 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003131 chunk_appendf(&trash, "%lld,", sv->counters.failed_hana);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003132
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003133 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003134 chunk_appendf(&trash, ",,,");
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003135
Willy Tarreauae526782010-03-04 20:34:23 +01003136 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003137 chunk_appendf(&trash, "%lld,%lld,",
Willy Tarreauae526782010-03-04 20:34:23 +01003138 sv->counters.cli_aborts, sv->counters.srv_aborts);
3139
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01003140 /* compression: in, out, bypassed, comp_rsp */
3141 chunk_appendf(&trash, ",,,,");
3142
Willy Tarreau7f062c42009-03-05 18:43:00 +01003143 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003144 chunk_appendf(&trash, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003145 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003146 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02003147 return 0;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003148 } /* for sv */
Willy Tarreau91861262007-10-17 17:06:05 +02003149
Willy Tarreau295a8372011-03-10 11:25:07 +01003150 si->applet.ctx.stats.px_st = STAT_PX_ST_BE;
Willy Tarreau91861262007-10-17 17:06:05 +02003151 /* fall through */
3152
Willy Tarreau295a8372011-03-10 11:25:07 +01003153 case STAT_PX_ST_BE:
Willy Tarreau91861262007-10-17 17:06:05 +02003154 /* print the backend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01003155 if ((px->cap & PR_CAP_BE) &&
Willy Tarreau295a8372011-03-10 11:25:07 +01003156 (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_BE)))) {
3157 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003158 chunk_appendf(&trash, "<tr class=\"backend\">");
Willy Tarreau295a8372011-03-10 11:25:07 +01003159 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02003160 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003161 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02003162 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003163 chunk_appendf(&trash, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003164
3165 if (uri->flags&ST_SHLGNDS) {
3166 /* balancing */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003167 chunk_appendf(&trash, " title=\"balancing: %s",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003168 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003169
3170 /* cookie */
3171 if (px->cookie_name) {
3172 struct chunk src;
3173
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003174 chunk_appendf(&trash, ", cookie: '");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003175
3176 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003177 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003178
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003179 chunk_appendf(&trash, "'");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003180 }
3181
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003182 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003183
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003184 }
3185
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003186 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02003187 /* name */
Willy Tarreaue0454092010-02-26 12:29:07 +01003188 ">%s<a name=\"%s/Backend\"></a>"
3189 "<a class=lfsb href=\"#%s/Backend\">Backend</a>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02003190 /* queue : current, max */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003191 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02003192 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003193 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02003194 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01003195 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02003196 px->id, px->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01003197 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003198 U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->be_counters.nbpend_max),
3199 U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->be_counters.sps_max));
Willy Tarreaua3e49422009-05-10 19:19:41 +02003200
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003201 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003202 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003203 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003204 "<td"
3205 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003206 U2H2(px->beconn), U2H3(px->be_counters.conn_max), U2H4(px->fullconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003207
3208 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
3209 if (px->mode == PR_MODE_HTTP) {
3210 int i;
3211
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01003212 chunk_appendf(&trash, " title=\"%lld requests:", px->be_counters.p.http.cum_req);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003213
3214 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003215 chunk_appendf(&trash, " %dxx=%lld", i, px->be_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003216
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01003217 chunk_appendf(&trash, " other=%lld ", px->be_counters.p.http.rsp[0]);
3218 chunk_appendf(&trash, " compressed=%lld (%d%%)\"",
3219 px->be_counters.p.http.comp_rsp,
Willy Tarreau78bbeb42012-11-26 16:44:48 +01003220 px->be_counters.p.http.rsp[2] ?
Willy Tarreau5730c682012-11-26 14:13:09 +01003221 (int)(100*px->be_counters.p.http.comp_rsp/px->be_counters.p.http.rsp[2]) : 0);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003222 }
3223
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003224 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003225 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01003226 ">%s%s%s</td><td>%s</td>"
Willy Tarreau55058a72012-11-21 08:27:21 +01003227 /* bytes: in */
3228 "<td>%s</td><td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003229 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01003230 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003231 U2H6(px->be_counters.cum_conn),
Willy Tarreaue0454092010-02-26 12:29:07 +01003232 (px->mode == PR_MODE_HTTP)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003233 U2H7(px->be_counters.cum_lbconn),
Willy Tarreau55058a72012-11-21 08:27:21 +01003234 U2H8(px->be_counters.bytes_in));
3235
3236 /* compression stats (via td title): comp_in, comp_out, comp_byp */
Willy Tarreauf149d8f2012-11-24 14:06:49 +01003237 chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld savings=%d%%\"",
3238 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp,
3239 px->be_counters.comp_in ?
3240 (int)((px->be_counters.comp_in - px->be_counters.comp_out)*100/px->be_counters.comp_in) : 0);
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003241
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003242 chunk_appendf(&trash,
Willy Tarreau55058a72012-11-21 08:27:21 +01003243 /* bytes: out */
3244 ">%s%s%s</td>"
3245 "",
3246 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"",
3247 U2H0(px->be_counters.bytes_out),
3248 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":"");
3249
3250 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02003251 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003252 "<td>%s</td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01003253 /* errors : request, connect */
3254 "<td></td><td>%s</td>"
3255 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01003256 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003257 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003258 "<td>%lld</td><td>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003259 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +02003260 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003261 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +02003262 * active and backups. */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003263 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
3264 "<td class=ac>%d</td><td class=ac>%d</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003265 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003266 U2H0(px->be_counters.denied_req), U2H1(px->be_counters.denied_resp),
3267 U2H2(px->be_counters.failed_conns),
3268 px->be_counters.cli_aborts,
3269 px->be_counters.srv_aborts,
3270 U2H5(px->be_counters.failed_resp),
3271 px->be_counters.retries, px->be_counters.redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003272 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +01003273 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
3274 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5542af62007-12-03 02:04:00 +01003275 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01003276 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003277
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003278 chunk_appendf(&trash,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003279 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003280 "<td class=ac>&nbsp;</td><td>%d</td>"
3281 "<td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003282 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003283 "</tr>",
3284 px->down_trans,
3285 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003286 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003287 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003288 /* pxid, name */
3289 "%s,BACKEND,"
3290 /* queue : current, max */
3291 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003292 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003293 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003294 /* bytes : in, out */
3295 "%lld,%lld,"
3296 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003297 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003298 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003299 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003300 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003301 "%lld,%lld,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003302 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +02003303 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003304 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +02003305 * active and backups. */
3306 "%s,"
3307 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003308 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02003309 ",%d,%d,%d,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003310 /* pid, iid, sid, throttle, lbtot, tracked, type */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003311 "%d,%d,0,,%lld,,%d,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003312 /* rate, rate_lim, rate_max, */
3313 "%u,,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003314 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003315 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02003316 px->id,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003317 px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max,
3318 px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn,
3319 px->be_counters.bytes_in, px->be_counters.bytes_out,
3320 px->be_counters.denied_req, px->be_counters.denied_resp,
3321 px->be_counters.failed_conns, px->be_counters.failed_resp,
3322 px->be_counters.retries, px->be_counters.redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +01003323 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5542af62007-12-03 02:04:00 +01003324 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01003325 px->srv_act, px->srv_bck,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003326 px->down_trans, (int)(now.tv_sec - px->last_change),
Willy Tarreau20697042007-11-15 23:26:18 +01003327 px->srv?be_downtime(px):0,
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003328 relative_pid, px->uuid,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003329 px->be_counters.cum_lbconn, STATS_TYPE_BE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003330 read_freq_ctr(&px->be_sess_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003331 px->be_counters.sps_max);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003332
3333 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3334 if (px->mode == PR_MODE_HTTP) {
3335 int i;
3336
3337 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003338 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003339
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003340 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003341 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003342 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003343 }
3344
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003345 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003346 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003347
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003348 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003349 chunk_appendf(&trash, ",,,");
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003350
Willy Tarreauae526782010-03-04 20:34:23 +01003351 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003352 chunk_appendf(&trash, "%lld,%lld,",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003353 px->be_counters.cli_aborts, px->be_counters.srv_aborts);
Willy Tarreauae526782010-03-04 20:34:23 +01003354
Willy Tarreau55058a72012-11-21 08:27:21 +01003355 /* compression: in, out, bypassed */
3356 chunk_appendf(&trash, "%lld,%lld,%lld,",
3357 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
3358
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01003359 /* compression: comp_rsp */
3360 chunk_appendf(&trash, "%lld,",
3361 px->be_counters.p.http.comp_rsp);
3362
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003363 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003364 chunk_appendf(&trash, "\n");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003365
Willy Tarreau55bb8452007-10-17 18:44:57 +02003366 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003367 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02003368 return 0;
3369 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003370
Willy Tarreau295a8372011-03-10 11:25:07 +01003371 si->applet.ctx.stats.px_st = STAT_PX_ST_END;
Willy Tarreau91861262007-10-17 17:06:05 +02003372 /* fall through */
3373
Willy Tarreau295a8372011-03-10 11:25:07 +01003374 case STAT_PX_ST_END:
3375 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003376 chunk_appendf(&trash, "</table>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02003377
Willy Tarreau295a8372011-03-10 11:25:07 +01003378 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02003379 /* close the form used to enable/disable this proxy servers */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003380 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02003381 "Choose the action to perform on the checked servers : "
3382 "<select name=action>"
3383 "<option value=\"\"></option>"
3384 "<option value=\"disable\">Disable</option>"
3385 "<option value=\"enable\">Enable</option>"
Willy Tarreaud7282242012-06-04 00:22:44 +02003386 "<option value=\"stop\">Soft Stop</option>"
3387 "<option value=\"start\">Soft Start</option>"
Willy Tarreau4f8a83c2012-06-04 00:26:23 +02003388 "<option value=\"shutdown\">Kill Sessions</option>"
Cyril Bonté70be45d2010-10-12 00:14:35 +02003389 "</select>"
Cyril Bontéaa0a45d2012-04-04 12:57:20 +02003390 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
Cyril Bonté70be45d2010-10-12 00:14:35 +02003391 "&nbsp;<input type=\"submit\" value=\"Apply\">"
3392 "</form>",
Cyril Bontéaa0a45d2012-04-04 12:57:20 +02003393 px->uuid);
Cyril Bonté70be45d2010-10-12 00:14:35 +02003394 }
3395
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003396 chunk_appendf(&trash, "<p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +02003397
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003398 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02003399 return 0;
3400 }
Willy Tarreau91861262007-10-17 17:06:05 +02003401
Willy Tarreau295a8372011-03-10 11:25:07 +01003402 si->applet.ctx.stats.px_st = STAT_PX_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02003403 /* fall through */
3404
Willy Tarreau295a8372011-03-10 11:25:07 +01003405 case STAT_PX_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02003406 return 1;
3407
3408 default:
3409 /* unknown state, we should put an abort() here ! */
3410 return 1;
3411 }
3412}
3413
Willy Tarreau909d5172012-11-26 03:04:41 +01003414static inline const char *get_conn_ctrl_name(const struct connection *conn)
3415{
3416 if (!conn->ctrl)
3417 return "NONE";
3418 return conn->ctrl->name;
3419}
3420
3421static inline const char *get_conn_xprt_name(const struct connection *conn)
3422{
3423 static char ptr[17];
3424
3425 if (!conn->xprt)
3426 return "NONE";
3427
3428 if (conn->xprt == &raw_sock)
3429 return "RAW";
3430
3431#ifdef USE_OPENSSL
3432 if (conn->xprt == &ssl_sock)
3433 return "SSL";
3434#endif
3435 snprintf(ptr, sizeof(ptr), "%p", conn->xprt);
3436 return ptr;
3437}
3438
3439static inline const char *get_conn_data_name(const struct connection *conn)
3440{
3441 static char ptr[17];
3442
3443 if (!conn->data)
3444 return "NONE";
3445
3446 if (conn->data == &sess_conn_cb)
3447 return "SESS";
3448
3449 if (conn->data == &si_conn_cb)
3450 return "STRM";
3451
3452 if (conn->data == &check_conn_cb)
3453 return "CHCK";
3454
3455 snprintf(ptr, sizeof(ptr), "%p", conn->data);
3456 return ptr;
3457}
3458
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003459/* This function dumps a complete session state onto the stream interface's
3460 * read buffer. The xprt_ctx must have been zeroed first, and the flags
3461 * properly set. The session has to be set in xprt_ctx.sess.target. It returns
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003462 * 0 if the output buffer is full and it needs to be called again, otherwise
3463 * non-zero. It is designed to be called from stats_dump_sess_to_buffer() below.
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003464 */
Willy Tarreau76153662012-11-26 01:16:39 +01003465static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003466{
3467 struct tm tm;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003468 extern const char *monthname[12];
3469 char pn[INET6_ADDRSTRLEN];
3470
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003471 chunk_reset(&trash);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003472
Willy Tarreau295a8372011-03-10 11:25:07 +01003473 if (si->applet.ctx.sess.section > 0 && si->applet.ctx.sess.uid != sess->uniq_id) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003474 /* session changed, no need to go any further */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003475 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
3476 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003477 return 0;
Willy Tarreau295a8372011-03-10 11:25:07 +01003478 si->applet.ctx.sess.uid = 0;
Willy Tarreau76153662012-11-26 01:16:39 +01003479 si->applet.ctx.sess.section = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003480 return 1;
3481 }
3482
Willy Tarreau295a8372011-03-10 11:25:07 +01003483 switch (si->applet.ctx.sess.section) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003484 case 0: /* main status of the session */
Willy Tarreau295a8372011-03-10 11:25:07 +01003485 si->applet.ctx.sess.uid = sess->uniq_id;
3486 si->applet.ctx.sess.section = 1;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003487 /* fall through */
3488
3489 case 1:
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003490 get_localtime(sess->logs.accept_date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003491 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003492 "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003493 sess,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003494 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
3495 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003496 sess->uniq_id,
3497 sess->listener->proto->name);
3498
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003499 switch (addr_to_str(&sess->si[0].conn->addr.from, pn, sizeof(pn))) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003500 case AF_INET:
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003501 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003502 chunk_appendf(&trash, " source=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003503 pn, get_host_port(&sess->si[0].conn->addr.from));
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003504 break;
3505 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003506 chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid);
Emeric Brun837ca522010-10-22 16:19:01 +02003507 break;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003508 default:
3509 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003510 chunk_appendf(&trash, "\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003511 break;
3512 }
3513
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003514 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003515 " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n",
Willy Tarreauee28de02010-06-01 09:51:00 +02003516 sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003517
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003518 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003519 " frontend=%s (id=%u mode=%s), listener=%s (id=%u)",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003520 sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp",
3521 sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?",
3522 sess->listener ? sess->listener->luid : 0);
3523
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003524 conn_get_to_addr(sess->si[0].conn);
3525 switch (addr_to_str(&sess->si[0].conn->addr.to, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003526 case AF_INET:
3527 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003528 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003529 pn, get_host_port(&sess->si[0].conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07003530 break;
3531 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003532 chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid);
Daniel Schultze90690c72012-03-23 10:53:36 -07003533 break;
3534 default:
3535 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003536 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003537 break;
3538 }
3539
Willy Tarreau50943332011-09-02 17:33:05 +02003540 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003541 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003542 " backend=%s (id=%u mode=%s)",
Willy Tarreau50943332011-09-02 17:33:05 +02003543 sess->be->id,
Daniel Schultze90690c72012-03-23 10:53:36 -07003544 sess->be->uuid, sess->be->mode ? "http" : "tcp");
3545 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003546 chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)");
Daniel Schultze90690c72012-03-23 10:53:36 -07003547
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003548 conn_get_from_addr(sess->si[1].conn);
3549 switch (addr_to_str(&sess->si[1].conn->addr.from, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003550 case AF_INET:
3551 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003552 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003553 pn, get_host_port(&sess->si[1].conn->addr.from));
Daniel Schultze90690c72012-03-23 10:53:36 -07003554 break;
3555 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003556 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003557 break;
3558 default:
3559 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003560 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003561 break;
3562 }
3563
3564 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003565 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003566 " server=%s (id=%u)",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003567 objt_server(sess->target) ? objt_server(sess->target)->id : "<none>",
3568 objt_server(sess->target) ? objt_server(sess->target)->puid : 0);
Willy Tarreau50943332011-09-02 17:33:05 +02003569 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003570 chunk_appendf(&trash, " server=<NONE> (id=-1)");
Daniel Schultze90690c72012-03-23 10:53:36 -07003571
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003572 conn_get_to_addr(sess->si[1].conn);
3573 switch (addr_to_str(&sess->si[1].conn->addr.to, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003574 case AF_INET:
3575 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003576 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003577 pn, get_host_port(&sess->si[1].conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07003578 break;
3579 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003580 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003581 break;
3582 default:
3583 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003584 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003585 break;
3586 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003587
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003588 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003589 " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003590 sess->task,
3591 sess->task->state,
3592 sess->task->nice, sess->task->calls,
3593 sess->task->expire ?
3594 tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" :
3595 human_time(TICKS_TO_MS(sess->task->expire - now_ms),
3596 TICKS_TO_MS(1000)) : "<NEVER>",
3597 task_in_rq(sess->task) ? ", running" : "");
3598
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003599 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003600 " age=%s)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003601 human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1));
3602
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003603 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003604 " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n",
3605 &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status,
3606 http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state));
3607
3608 chunk_appendf(&trash,
3609 " si[0]=%p (state=%s flags=0x%02x conn0=%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003610 &sess->si[0],
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003611 si_state_str(sess->si[0].state),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003612 sess->si[0].flags,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003613 sess->si[0].conn,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003614 sess->si[0].exp ?
3615 tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" :
3616 human_time(TICKS_TO_MS(sess->si[0].exp - now_ms),
3617 TICKS_TO_MS(1000)) : "<NEVER>",
3618 sess->si[0].err_type);
3619
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003620 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003621 " si[1]=%p (state=%s flags=0x%02x conn1=%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003622 &sess->si[1],
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003623 si_state_str(sess->si[1].state),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003624 sess->si[1].flags,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003625 sess->si[1].conn,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003626 sess->si[1].exp ?
3627 tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" :
3628 human_time(TICKS_TO_MS(sess->si[1].exp - now_ms),
3629 TICKS_TO_MS(1000)) : "<NEVER>",
3630 sess->si[1].err_type);
3631
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003632 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003633 " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n",
Willy Tarreau909d5172012-11-26 03:04:41 +01003634 sess->si[0].conn,
3635 get_conn_ctrl_name(sess->si[0].conn),
3636 get_conn_xprt_name(sess->si[0].conn),
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003637 get_conn_data_name(sess->si[0].conn),
3638 obj_type_name(sess->si[0].conn->target),
3639 obj_base_ptr(sess->si[0].conn->target));
Willy Tarreau909d5172012-11-26 03:04:41 +01003640
3641 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003642 " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n",
Willy Tarreau1feca012012-11-19 18:15:19 +01003643 sess->si[0].conn->flags,
3644 sess->si[0].conn->t.sock.fd,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003645 sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_e : 0,
3646 sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_p : 0,
3647 sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].updated : 0);
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003648
3649 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003650 " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n",
Willy Tarreau909d5172012-11-26 03:04:41 +01003651 sess->si[1].conn,
3652 get_conn_ctrl_name(sess->si[1].conn),
3653 get_conn_xprt_name(sess->si[1].conn),
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003654 get_conn_data_name(sess->si[1].conn),
3655 obj_type_name(sess->si[1].conn->target),
3656 obj_base_ptr(sess->si[1].conn->target));
Willy Tarreau909d5172012-11-26 03:04:41 +01003657
3658 chunk_appendf(&trash,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003659 " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n",
Willy Tarreau1feca012012-11-19 18:15:19 +01003660 sess->si[1].conn->flags,
3661 sess->si[1].conn->t.sock.fd,
Willy Tarreau55e4ecd2012-12-08 17:48:47 +01003662 sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_e : 0,
3663 sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_p : 0,
3664 sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].updated : 0);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003665
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003666 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01003667 " req=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003668 " an_exp=%s",
3669 sess->req,
3670 sess->req->flags, sess->req->analysers,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003671 sess->req->pipe ? sess->req->pipe->data : 0,
Willy Tarreau909d5172012-11-26 03:04:41 +01003672 sess->req->to_forward, sess->req->total,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003673 sess->req->analyse_exp ?
3674 human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms),
3675 TICKS_TO_MS(1000)) : "<NEVER>");
3676
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003677 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003678 " rex=%s",
3679 sess->req->rex ?
3680 human_time(TICKS_TO_MS(sess->req->rex - now_ms),
3681 TICKS_TO_MS(1000)) : "<NEVER>");
3682
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003683 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003684 " wex=%s\n"
Willy Tarreau909d5172012-11-26 03:04:41 +01003685 " buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003686 sess->req->wex ?
3687 human_time(TICKS_TO_MS(sess->req->wex - now_ms),
3688 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau909d5172012-11-26 03:04:41 +01003689 sess->req->buf,
3690 sess->req->buf->data, sess->req->buf->o,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003691 (int)(sess->req->buf->p - sess->req->buf->data),
Willy Tarreau909d5172012-11-26 03:04:41 +01003692 sess->txn.req.next, sess->req->buf->i,
3693 sess->req->buf->size);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003694
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003695 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01003696 " res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003697 " an_exp=%s",
3698 sess->rep,
3699 sess->rep->flags, sess->rep->analysers,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003700 sess->rep->pipe ? sess->rep->pipe->data : 0,
Willy Tarreau909d5172012-11-26 03:04:41 +01003701 sess->rep->to_forward, sess->rep->total,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003702 sess->rep->analyse_exp ?
3703 human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms),
3704 TICKS_TO_MS(1000)) : "<NEVER>");
3705
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003706 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003707 " rex=%s",
3708 sess->rep->rex ?
3709 human_time(TICKS_TO_MS(sess->rep->rex - now_ms),
3710 TICKS_TO_MS(1000)) : "<NEVER>");
3711
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003712 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003713 " wex=%s\n"
Willy Tarreau909d5172012-11-26 03:04:41 +01003714 " buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003715 sess->rep->wex ?
3716 human_time(TICKS_TO_MS(sess->rep->wex - now_ms),
3717 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau909d5172012-11-26 03:04:41 +01003718 sess->rep->buf,
3719 sess->rep->buf->data, sess->rep->buf->o,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003720 (int)(sess->rep->buf->p - sess->rep->buf->data),
Willy Tarreau909d5172012-11-26 03:04:41 +01003721 sess->txn.rsp.next, sess->rep->buf->i,
3722 sess->rep->buf->size);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003723
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003724 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003725 return 0;
3726
3727 /* use other states to dump the contents */
3728 }
3729 /* end of dump */
Willy Tarreau295a8372011-03-10 11:25:07 +01003730 si->applet.ctx.sess.uid = 0;
Willy Tarreau76153662012-11-26 01:16:39 +01003731 si->applet.ctx.sess.section = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003732 return 1;
3733}
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003734
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003735/* This function dumps all sessions' states onto the stream interface's
3736 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003737 * properly set. It returns 0 if the output buffer is full and it needs
3738 * to be called again, otherwise non-zero. It is designed to be called
3739 * from stats_dump_sess_to_buffer() below.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003740 */
Simon Horman9bd2c732011-06-15 15:18:44 +09003741static int stats_dump_sess_to_buffer(struct stream_interface *si)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003742{
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02003743 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003744 /* If we're forced to shut down, we might have to remove our
3745 * reference to the last session being dumped.
3746 */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003747 if (si->conn->xprt_st == STAT_ST_LIST) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003748 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) {
3749 LIST_DEL(&si->applet.ctx.sess.bref.users);
3750 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003751 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003752 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003753 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003754 }
3755
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003756 chunk_reset(&trash);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003757
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003758 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003759 case STAT_ST_INIT:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003760 /* the function had not been called yet, let's prepare the
3761 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003762 * pointer to the first in the global list. When a target
3763 * session is being destroyed, it is responsible for updating
3764 * this pointer. We know we have reached the end when this
3765 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003766 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003767 LIST_INIT(&si->applet.ctx.sess.bref.users);
3768 si->applet.ctx.sess.bref.ref = sessions.n;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003769 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003770 /* fall through */
3771
Willy Tarreau295a8372011-03-10 11:25:07 +01003772 case STAT_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003773 /* first, let's detach the back-ref from a possible previous session */
Willy Tarreau295a8372011-03-10 11:25:07 +01003774 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) {
3775 LIST_DEL(&si->applet.ctx.sess.bref.users);
3776 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003777 }
3778
3779 /* and start from where we stopped */
Willy Tarreau295a8372011-03-10 11:25:07 +01003780 while (si->applet.ctx.sess.bref.ref != &sessions) {
Cyril Bontéacd7d632010-11-01 19:26:02 +01003781 char pn[INET6_ADDRSTRLEN];
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003782 struct session *curr_sess;
3783
Willy Tarreau295a8372011-03-10 11:25:07 +01003784 curr_sess = LIST_ELEM(si->applet.ctx.sess.bref.ref, struct session *, list);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003785
Willy Tarreau295a8372011-03-10 11:25:07 +01003786 if (si->applet.ctx.sess.target) {
Willy Tarreau76153662012-11-26 01:16:39 +01003787 if (si->applet.ctx.sess.target != (void *)-1 && si->applet.ctx.sess.target != curr_sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003788 goto next_sess;
3789
Willy Tarreau295a8372011-03-10 11:25:07 +01003790 LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003791 /* call the proper dump() function and return if we're missing space */
Willy Tarreau76153662012-11-26 01:16:39 +01003792 if (!stats_dump_full_sess_to_buffer(si, curr_sess))
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003793 return 0;
3794
3795 /* session dump complete */
Willy Tarreau295a8372011-03-10 11:25:07 +01003796 LIST_DEL(&si->applet.ctx.sess.bref.users);
3797 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreau76153662012-11-26 01:16:39 +01003798 if (si->applet.ctx.sess.target != (void *)-1) {
3799 si->applet.ctx.sess.target = NULL;
3800 break;
3801 }
3802 else
3803 goto next_sess;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003804 }
3805
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003806 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003807 "%p: proto=%s",
3808 curr_sess,
3809 curr_sess->listener->proto->name);
3810
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003811
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003812 switch (addr_to_str(&curr_sess->si[0].conn->addr.from, pn, sizeof(pn))) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02003813 case AF_INET:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003814 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003815 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003816 " src=%s:%d fe=%s be=%s srv=%s",
3817 pn,
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003818 get_host_port(&curr_sess->si[0].conn->addr.from),
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003819 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02003820 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003821 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003822 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003823 break;
3824 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003825 chunk_appendf(&trash,
Emeric Brun837ca522010-10-22 16:19:01 +02003826 " src=unix:%d fe=%s be=%s srv=%s",
3827 curr_sess->listener->luid,
3828 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02003829 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003830 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Emeric Brun837ca522010-10-22 16:19:01 +02003831 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003832 break;
3833 }
3834
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003835 chunk_appendf(&trash,
Willy Tarreau65671ab2009-10-04 14:24:59 +02003836 " ts=%02x age=%s calls=%d",
3837 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01003838 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
3839 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003840
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003841 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003842 " rq[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003843 curr_sess->req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003844 curr_sess->req->buf->i,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003845 curr_sess->req->analysers,
3846 curr_sess->req->rex ?
3847 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
3848 TICKS_TO_MS(1000)) : "");
3849
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003850 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003851 ",wx=%s",
3852 curr_sess->req->wex ?
3853 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
3854 TICKS_TO_MS(1000)) : "");
3855
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003856 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003857 ",ax=%s]",
3858 curr_sess->req->analyse_exp ?
3859 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
3860 TICKS_TO_MS(1000)) : "");
3861
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003862 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003863 " rp[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003864 curr_sess->rep->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003865 curr_sess->rep->buf->i,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003866 curr_sess->rep->analysers,
3867 curr_sess->rep->rex ?
3868 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
3869 TICKS_TO_MS(1000)) : "");
3870
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003871 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003872 ",wx=%s",
3873 curr_sess->rep->wex ?
3874 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
3875 TICKS_TO_MS(1000)) : "");
3876
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003877 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003878 ",ax=%s]",
3879 curr_sess->rep->analyse_exp ?
3880 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
3881 TICKS_TO_MS(1000)) : "");
3882
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003883 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003884 " s0=[%d,%1xh,fd=%d,ex=%s]",
3885 curr_sess->si[0].state,
3886 curr_sess->si[0].flags,
Willy Tarreau7f7ad912012-11-11 19:27:15 +01003887 curr_sess->si[0].conn->t.sock.fd,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003888 curr_sess->si[0].exp ?
3889 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
3890 TICKS_TO_MS(1000)) : "");
3891
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003892 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003893 " s1=[%d,%1xh,fd=%d,ex=%s]",
3894 curr_sess->si[1].state,
3895 curr_sess->si[1].flags,
Willy Tarreau7f7ad912012-11-11 19:27:15 +01003896 curr_sess->si[1].conn->t.sock.fd,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003897 curr_sess->si[1].exp ?
3898 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
3899 TICKS_TO_MS(1000)) : "");
3900
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003901 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003902 " exp=%s",
3903 curr_sess->task->expire ?
3904 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
3905 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01003906 if (task_in_rq(curr_sess->task))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003907 chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003908
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003909 chunk_appendf(&trash, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003910
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003911 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003912 /* let's try again later from this session. We add ourselves into
3913 * this session's users so that it can remove us upon termination.
3914 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003915 LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003916 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003917 }
3918
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003919 next_sess:
Willy Tarreau295a8372011-03-10 11:25:07 +01003920 si->applet.ctx.sess.bref.ref = curr_sess->list.n;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003921 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003922
Willy Tarreau76153662012-11-26 01:16:39 +01003923 if (si->applet.ctx.sess.target && si->applet.ctx.sess.target != (void *)-1) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003924 /* specified session not found */
Willy Tarreau295a8372011-03-10 11:25:07 +01003925 if (si->applet.ctx.sess.section > 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003926 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003927 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003928 chunk_appendf(&trash, "Session not found.\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003929
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003930 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003931 return 0;
3932
Willy Tarreau295a8372011-03-10 11:25:07 +01003933 si->applet.ctx.sess.target = NULL;
3934 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003935 return 1;
3936 }
3937
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003938 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003939 /* fall through */
3940
3941 default:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003942 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003943 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003944 }
Emeric Brun1e029aa2010-09-23 18:12:53 +02003945}
3946
Willy Tarreau5f9a8772012-11-26 02:22:40 +01003947/* This is called when the stream interface is closed. For instance, upon an
3948 * external abort, we won't call the i/o handler anymore so we may need to
3949 * remove back references to the session currently being dumped.
3950 */
3951void cli_release_handler(struct stream_interface *si)
3952{
3953 if (si->applet.st0 == STAT_CLI_O_SESS && si->conn->xprt_st == STAT_ST_LIST) {
3954 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users))
3955 LIST_DEL(&si->applet.ctx.sess.bref.users);
3956 }
3957}
3958
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003959/* This function dumps all tables' states onto the stream interface's
3960 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003961 * properly set. It returns 0 if the output buffer is full and it needs
3962 * to be called again, otherwise non-zero.
Willy Tarreau69f58c82010-07-12 17:55:33 +02003963 */
Willy Tarreau44455022012-12-05 23:01:12 +01003964static int stats_table_request(struct stream_interface *si, int show)
Willy Tarreau69f58c82010-07-12 17:55:33 +02003965{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003966 struct session *s = si->conn->xprt_ctx;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003967 struct ebmb_node *eb;
3968 int dt;
Willy Tarreau44455022012-12-05 23:01:12 +01003969 int skip_entry;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003970
3971 /*
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003972 * We have 3 possible states in si->conn->xprt_st :
Willy Tarreau295a8372011-03-10 11:25:07 +01003973 * - STAT_ST_INIT : the first call
3974 * - STAT_ST_INFO : the proxy pointer points to the next table to
Willy Tarreau69f58c82010-07-12 17:55:33 +02003975 * dump, the entry pointer is NULL ;
Willy Tarreau295a8372011-03-10 11:25:07 +01003976 * - STAT_ST_LIST : the proxy pointer points to the current table
Willy Tarreau69f58c82010-07-12 17:55:33 +02003977 * and the entry pointer points to the next entry to be dumped,
3978 * and the refcount on the next entry is held ;
Willy Tarreau295a8372011-03-10 11:25:07 +01003979 * - STAT_ST_END : nothing left to dump, the buffer may contain some
Willy Tarreau69f58c82010-07-12 17:55:33 +02003980 * data though.
3981 */
3982
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02003983 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02003984 /* in case of abort, remove any refcount we might have set on an entry */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003985 if (si->conn->xprt_st == STAT_ST_LIST) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003986 si->applet.ctx.table.entry->ref_cnt--;
3987 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
Willy Tarreauf6efda12010-08-03 20:34:06 +02003988 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02003989 return 1;
3990 }
3991
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003992 chunk_reset(&trash);
Willy Tarreau69f58c82010-07-12 17:55:33 +02003993
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003994 while (si->conn->xprt_st != STAT_ST_FIN) {
3995 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003996 case STAT_ST_INIT:
3997 si->applet.ctx.table.proxy = si->applet.ctx.table.target;
3998 if (!si->applet.ctx.table.proxy)
3999 si->applet.ctx.table.proxy = proxy;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004000
Willy Tarreau295a8372011-03-10 11:25:07 +01004001 si->applet.ctx.table.entry = NULL;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004002 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004003 break;
4004
Willy Tarreau295a8372011-03-10 11:25:07 +01004005 case STAT_ST_INFO:
4006 if (!si->applet.ctx.table.proxy ||
4007 (si->applet.ctx.table.target &&
4008 si->applet.ctx.table.proxy != si->applet.ctx.table.target)) {
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004009 si->conn->xprt_st = STAT_ST_END;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004010 break;
4011 }
4012
Willy Tarreau295a8372011-03-10 11:25:07 +01004013 if (si->applet.ctx.table.proxy->table.size) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004014 if (show && !stats_dump_table_head_to_buffer(&trash, si, si->applet.ctx.table.proxy,
Simon Hormanc88b8872011-06-15 15:18:49 +09004015 si->applet.ctx.table.target))
Willy Tarreau69f58c82010-07-12 17:55:33 +02004016 return 0;
4017
Willy Tarreau295a8372011-03-10 11:25:07 +01004018 if (si->applet.ctx.table.target &&
Willy Tarreau290e63a2012-09-20 18:07:14 +02004019 s->listener->bind_conf->level >= ACCESS_LVL_OPER) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02004020 /* dump entries only if table explicitly requested */
Willy Tarreau295a8372011-03-10 11:25:07 +01004021 eb = ebmb_first(&si->applet.ctx.table.proxy->table.keys);
Willy Tarreau69f58c82010-07-12 17:55:33 +02004022 if (eb) {
Willy Tarreau295a8372011-03-10 11:25:07 +01004023 si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key);
4024 si->applet.ctx.table.entry->ref_cnt++;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004025 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004026 break;
4027 }
4028 }
4029 }
Willy Tarreau295a8372011-03-10 11:25:07 +01004030 si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004031 break;
4032
Willy Tarreau295a8372011-03-10 11:25:07 +01004033 case STAT_ST_LIST:
Willy Tarreau44455022012-12-05 23:01:12 +01004034 skip_entry = 0;
Simon Hormanc88b8872011-06-15 15:18:49 +09004035
Willy Tarreau295a8372011-03-10 11:25:07 +01004036 if (si->applet.ctx.table.data_type >= 0) {
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02004037 /* we're filtering on some data contents */
4038 void *ptr;
4039 long long data;
4040
Willy Tarreau295a8372011-03-10 11:25:07 +01004041 dt = si->applet.ctx.table.data_type;
4042 ptr = stktable_data_ptr(&si->applet.ctx.table.proxy->table,
4043 si->applet.ctx.table.entry,
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02004044 dt);
4045
4046 data = 0;
4047 switch (stktable_data_types[dt].std_type) {
4048 case STD_T_SINT:
4049 data = stktable_data_cast(ptr, std_t_sint);
4050 break;
4051 case STD_T_UINT:
4052 data = stktable_data_cast(ptr, std_t_uint);
4053 break;
4054 case STD_T_ULL:
4055 data = stktable_data_cast(ptr, std_t_ull);
4056 break;
4057 case STD_T_FRQP:
4058 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Willy Tarreau295a8372011-03-10 11:25:07 +01004059 si->applet.ctx.table.proxy->table.data_arg[dt].u);
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02004060 break;
4061 }
4062
4063 /* skip the entry if the data does not match the test and the value */
Willy Tarreau295a8372011-03-10 11:25:07 +01004064 if ((data < si->applet.ctx.table.value &&
4065 (si->applet.ctx.table.data_op == STD_OP_EQ ||
4066 si->applet.ctx.table.data_op == STD_OP_GT ||
4067 si->applet.ctx.table.data_op == STD_OP_GE)) ||
4068 (data == si->applet.ctx.table.value &&
4069 (si->applet.ctx.table.data_op == STD_OP_NE ||
4070 si->applet.ctx.table.data_op == STD_OP_GT ||
4071 si->applet.ctx.table.data_op == STD_OP_LT)) ||
4072 (data > si->applet.ctx.table.value &&
4073 (si->applet.ctx.table.data_op == STD_OP_EQ ||
4074 si->applet.ctx.table.data_op == STD_OP_LT ||
4075 si->applet.ctx.table.data_op == STD_OP_LE)))
Willy Tarreau44455022012-12-05 23:01:12 +01004076 skip_entry = 1;
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02004077 }
4078
Simon Hormanc88b8872011-06-15 15:18:49 +09004079 if (show && !skip_entry &&
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004080 !stats_dump_table_entry_to_buffer(&trash, si, si->applet.ctx.table.proxy,
Simon Hormand9366582011-06-15 15:18:45 +09004081 si->applet.ctx.table.entry))
4082 return 0;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004083
Willy Tarreau295a8372011-03-10 11:25:07 +01004084 si->applet.ctx.table.entry->ref_cnt--;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004085
Willy Tarreau295a8372011-03-10 11:25:07 +01004086 eb = ebmb_next(&si->applet.ctx.table.entry->key);
Willy Tarreau69f58c82010-07-12 17:55:33 +02004087 if (eb) {
Willy Tarreau295a8372011-03-10 11:25:07 +01004088 struct stksess *old = si->applet.ctx.table.entry;
4089 si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key);
Willy Tarreau8fa52f42012-01-09 11:50:03 +01004090 if (show)
4091 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, old);
4092 else
4093 stksess_kill(&si->applet.ctx.table.proxy->table, old);
Willy Tarreau295a8372011-03-10 11:25:07 +01004094 si->applet.ctx.table.entry->ref_cnt++;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004095 break;
4096 }
4097
Simon Hormanc88b8872011-06-15 15:18:49 +09004098
4099 if (show)
4100 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
4101 else if (!skip_entry && !si->applet.ctx.table.entry->ref_cnt)
4102 stksess_kill(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
4103
Willy Tarreau295a8372011-03-10 11:25:07 +01004104 si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004105 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004106 break;
4107
Willy Tarreau295a8372011-03-10 11:25:07 +01004108 case STAT_ST_END:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004109 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004110 break;
4111 }
4112 }
4113 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01004114}
4115
Willy Tarreaud426a182010-03-05 14:58:26 +01004116/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
Willy Tarreau74808cb2009-03-04 15:53:18 +01004117 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
4118 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
4119 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
4120 * lines are respected within the limit of 70 output chars. Lines that are
4121 * continuation of a previous truncated line begin with "+" instead of " "
4122 * after the offset. The new pointer is returned.
4123 */
Willy Tarreaud426a182010-03-05 14:58:26 +01004124static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
4125 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004126{
4127 int end;
4128 unsigned char c;
4129
4130 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02004131 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004132 return ptr;
4133
Willy Tarreau77804732012-10-29 16:14:26 +01004134 chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01004135
Willy Tarreaud426a182010-03-05 14:58:26 +01004136 while (ptr < len && ptr < bsize) {
4137 c = buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01004138 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004139 if (out->len > end - 2)
4140 break;
4141 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01004142 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004143 if (out->len > end - 3)
4144 break;
4145 out->str[out->len++] = '\\';
4146 switch (c) {
4147 case '\t': c = 't'; break;
4148 case '\n': c = 'n'; break;
4149 case '\r': c = 'r'; break;
4150 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01004151 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004152 }
4153 out->str[out->len++] = c;
4154 } else {
4155 if (out->len > end - 5)
4156 break;
4157 out->str[out->len++] = '\\';
4158 out->str[out->len++] = 'x';
4159 out->str[out->len++] = hextab[(c >> 4) & 0xF];
4160 out->str[out->len++] = hextab[c & 0xF];
4161 }
Willy Tarreaud426a182010-03-05 14:58:26 +01004162 if (buf[ptr++] == '\n') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004163 /* we had a line break, let's return now */
4164 out->str[out->len++] = '\n';
4165 *line = ptr;
4166 return ptr;
4167 }
4168 }
4169 /* we have an incomplete line, we return it as-is */
4170 out->str[out->len++] = '\n';
4171 return ptr;
4172}
4173
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02004174/* This function dumps all captured errors onto the stream interface's
4175 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01004176 * properly set. It returns 0 if the output buffer is full and it needs
4177 * to be called again, otherwise non-zero.
Willy Tarreau74808cb2009-03-04 15:53:18 +01004178 */
Simon Horman9bd2c732011-06-15 15:18:44 +09004179static int stats_dump_errors_to_buffer(struct stream_interface *si)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004180{
4181 extern const char *monthname[12];
Willy Tarreau74808cb2009-03-04 15:53:18 +01004182
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02004183 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW)))
Willy Tarreau61b34732009-10-03 23:49:35 +02004184 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004185
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004186 chunk_reset(&trash);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004187
Willy Tarreau295a8372011-03-10 11:25:07 +01004188 if (!si->applet.ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004189 /* the function had not been called yet, let's prepare the
4190 * buffer for a response.
4191 */
Willy Tarreau10479e42010-12-12 14:00:34 +01004192 struct tm tm;
4193
4194 get_localtime(date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004195 chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n",
Willy Tarreau10479e42010-12-12 14:00:34 +01004196 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
4197 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000),
4198 error_snapshot_id);
4199
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004200 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau10479e42010-12-12 14:00:34 +01004201 /* Socket buffer full. Let's try again later from the same point */
4202 return 0;
4203 }
4204
Willy Tarreau295a8372011-03-10 11:25:07 +01004205 si->applet.ctx.errors.px = proxy;
4206 si->applet.ctx.errors.buf = 0;
4207 si->applet.ctx.errors.bol = 0;
4208 si->applet.ctx.errors.ptr = -1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004209 }
4210
4211 /* we have two inner loops here, one for the proxy, the other one for
4212 * the buffer.
4213 */
Willy Tarreau295a8372011-03-10 11:25:07 +01004214 while (si->applet.ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004215 struct error_snapshot *es;
4216
Willy Tarreau295a8372011-03-10 11:25:07 +01004217 if (si->applet.ctx.errors.buf == 0)
4218 es = &si->applet.ctx.errors.px->invalid_req;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004219 else
Willy Tarreau295a8372011-03-10 11:25:07 +01004220 es = &si->applet.ctx.errors.px->invalid_rep;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004221
4222 if (!es->when.tv_sec)
4223 goto next;
4224
Willy Tarreau295a8372011-03-10 11:25:07 +01004225 if (si->applet.ctx.errors.iid >= 0 &&
4226 si->applet.ctx.errors.px->uuid != si->applet.ctx.errors.iid &&
4227 es->oe->uuid != si->applet.ctx.errors.iid)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004228 goto next;
4229
Willy Tarreau295a8372011-03-10 11:25:07 +01004230 if (si->applet.ctx.errors.ptr < 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004231 /* just print headers now */
4232
4233 char pn[INET6_ADDRSTRLEN];
4234 struct tm tm;
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004235 int port;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004236
4237 get_localtime(es->when.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004238 chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01004239 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02004240 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01004241
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004242 switch (addr_to_str(&es->src, pn, sizeof(pn))) {
4243 case AF_INET:
4244 case AF_INET6:
4245 port = get_host_port(&es->src);
4246 break;
4247 default:
4248 port = 0;
4249 }
4250
Willy Tarreau295a8372011-03-10 11:25:07 +01004251 switch (si->applet.ctx.errors.buf) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004252 case 0:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004253 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004254 " frontend %s (#%d): invalid request\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004255 " backend %s (#%d)",
Willy Tarreau295a8372011-03-10 11:25:07 +01004256 si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004257 (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
4258 (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004259 break;
4260 case 1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004261 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004262 " backend %s (#%d) : invalid response\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004263 " frontend %s (#%d)",
Willy Tarreau295a8372011-03-10 11:25:07 +01004264 si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004265 es->oe->id, es->oe->uuid);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004266 break;
4267 }
4268
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004269 chunk_appendf(&trash,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004270 ", server %s (#%d), event #%u\n"
4271 " src %s:%d, session #%d, session flags 0x%08x\n"
4272 " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n"
4273 " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n"
4274 " buffer flags 0x%08x, out %d bytes, total %lld bytes\n"
4275 " pending %d bytes, wrapping at %d, error at position %d:\n \n",
4276 es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1,
4277 es->ev_id,
4278 pn, port, es->sid, es->s_flags,
4279 es->state, es->m_flags, es->t_flags,
4280 es->m_clen, es->m_blen,
4281 es->b_flags, es->b_out, es->b_tot,
4282 es->len, es->b_wrap, es->pos);
4283
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004284 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004285 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02004286 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004287 }
Willy Tarreau295a8372011-03-10 11:25:07 +01004288 si->applet.ctx.errors.ptr = 0;
4289 si->applet.ctx.errors.sid = es->sid;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004290 }
4291
Willy Tarreau295a8372011-03-10 11:25:07 +01004292 if (si->applet.ctx.errors.sid != es->sid) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004293 /* the snapshot changed while we were dumping it */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004294 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004295 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004296 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau61b34732009-10-03 23:49:35 +02004297 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004298 goto next;
4299 }
4300
4301 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau295a8372011-03-10 11:25:07 +01004302 while (si->applet.ctx.errors.ptr < es->len && si->applet.ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004303 int newptr;
4304 int newline;
4305
Willy Tarreau295a8372011-03-10 11:25:07 +01004306 newline = si->applet.ctx.errors.bol;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004307 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 +01004308 if (newptr == si->applet.ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02004309 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004310
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004311 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004312 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02004313 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004314 }
Willy Tarreau295a8372011-03-10 11:25:07 +01004315 si->applet.ctx.errors.ptr = newptr;
4316 si->applet.ctx.errors.bol = newline;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004317 };
4318 next:
Willy Tarreau295a8372011-03-10 11:25:07 +01004319 si->applet.ctx.errors.bol = 0;
4320 si->applet.ctx.errors.ptr = -1;
4321 si->applet.ctx.errors.buf++;
4322 if (si->applet.ctx.errors.buf > 1) {
4323 si->applet.ctx.errors.buf = 0;
4324 si->applet.ctx.errors.px = si->applet.ctx.errors.px->next;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004325 }
4326 }
4327
4328 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02004329 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004330}
4331
Willy Tarreaud5781202012-09-22 19:32:35 +02004332/* parse the "level" argument on the bind lines */
4333static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
4334{
4335 if (!*args[cur_arg + 1]) {
4336 memprintf(err, "'%s' : missing level", args[cur_arg]);
4337 return ERR_ALERT | ERR_FATAL;
4338 }
4339
4340 if (!strcmp(args[cur_arg+1], "user"))
4341 conf->level = ACCESS_LVL_USER;
4342 else if (!strcmp(args[cur_arg+1], "operator"))
4343 conf->level = ACCESS_LVL_OPER;
4344 else if (!strcmp(args[cur_arg+1], "admin"))
4345 conf->level = ACCESS_LVL_ADMIN;
4346 else {
4347 memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')",
4348 args[cur_arg], args[cur_arg+1]);
4349 return ERR_ALERT | ERR_FATAL;
4350 }
4351
4352 return 0;
4353}
4354
Willy Tarreaub24281b2011-02-13 13:16:36 +01004355struct si_applet http_stats_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01004356 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004357 .name = "<STATS>", /* used for logging */
4358 .fct = http_stats_io_handler,
Aman Gupta9a13e842012-04-02 18:57:53 -07004359 .release = NULL,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004360};
4361
Simon Horman9bd2c732011-06-15 15:18:44 +09004362static struct si_applet cli_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01004363 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004364 .name = "<CLI>", /* used for logging */
4365 .fct = cli_io_handler,
Willy Tarreau5f9a8772012-11-26 02:22:40 +01004366 .release = cli_release_handler,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004367};
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01004368
Willy Tarreau10522fd2008-07-09 20:12:41 +02004369static struct cfg_kw_list cfg_kws = {{ },{
4370 { CFG_GLOBAL, "stats", stats_parse_global },
4371 { 0, NULL, NULL },
4372}};
4373
Willy Tarreaud5781202012-09-22 19:32:35 +02004374static struct bind_kw_list bind_kws = { "STAT", { }, {
4375 { "level", bind_parse_level, 1 }, /* set the unix socket admin level */
4376 { NULL, NULL, 0 },
4377}};
4378
Willy Tarreau10522fd2008-07-09 20:12:41 +02004379__attribute__((constructor))
4380static void __dumpstats_module_init(void)
4381{
4382 cfg_register_keywords(&cfg_kws);
Willy Tarreaud5781202012-09-22 19:32:35 +02004383 bind_register_keywords(&bind_kws);
Willy Tarreau10522fd2008-07-09 20:12:41 +02004384}
4385
Willy Tarreau91861262007-10-17 17:06:05 +02004386/*
4387 * Local variables:
4388 * c-indent-level: 8
4389 * c-basic-offset: 8
4390 * End:
4391 */