blob: f2849efcebf2efafd492ddd6582ff352676afa5c [file] [log] [blame]
Willy Tarreau91861262007-10-17 17:06:05 +02001/*
Willy Tarreaueb472682010-05-28 18:46:57 +02002 * Functions dedicated to statistics output and the stats socket
Willy Tarreau91861262007-10-17 17:06:05 +02003 *
Willy Tarreaueb472682010-05-28 18:46:57 +02004 * Copyright 2000-2010 Willy Tarreau <w@1wt.eu>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02005 * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl>
Willy Tarreau91861262007-10-17 17:06:05 +02006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
14#include <ctype.h>
15#include <errno.h>
16#include <fcntl.h>
Simon Horman17bce342011-06-15 15:18:47 +090017#include <stdbool.h>
Willy Tarreau91861262007-10-17 17:06:05 +020018#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020021#include <pwd.h>
22#include <grp.h>
Willy Tarreau91861262007-10-17 17:06:05 +020023
24#include <sys/socket.h>
25#include <sys/stat.h>
26#include <sys/types.h>
27
Willy Tarreau10522fd2008-07-09 20:12:41 +020028#include <common/cfgparse.h>
Willy Tarreau91861262007-10-17 17:06:05 +020029#include <common/compat.h>
30#include <common/config.h>
31#include <common/debug.h>
32#include <common/memory.h>
33#include <common/mini-clist.h>
34#include <common/standard.h>
Willy Tarreau0c303ee2008-07-07 00:09:58 +020035#include <common/ticks.h>
Willy Tarreau91861262007-10-17 17:06:05 +020036#include <common/time.h>
37#include <common/uri_auth.h>
38#include <common/version.h>
39
Willy Tarreau91861262007-10-17 17:06:05 +020040#include <types/global.h>
Willy Tarreau91861262007-10-17 17:06:05 +020041
42#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020043#include <proto/channel.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020044#include <proto/checks.h>
William Lallemande3a7d992012-11-20 11:25:20 +010045#include <proto/compression.h>
Willy Tarreau91861262007-10-17 17:06:05 +020046#include <proto/dumpstats.h>
47#include <proto/fd.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010048#include <proto/freq_ctr.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020049#include <proto/log.h>
Willy Tarreaua206fa92009-01-25 14:02:00 +010050#include <proto/pipe.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020051#include <proto/listener.h>
Willy Tarreaue6d97022012-11-23 11:19:33 +010052#include <proto/proto_http.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020053#include <proto/proto_uxst.h>
Willy Tarreau89a63132009-08-16 17:41:45 +020054#include <proto/proxy.h>
Willy Tarreau91861262007-10-17 17:06:05 +020055#include <proto/session.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020056#include <proto/server.h>
Willy Tarreau75bf2c92012-08-20 17:01:35 +020057#include <proto/raw_sock.h>
Willy Tarreaudded32d2008-11-30 19:48:07 +010058#include <proto/stream_interface.h>
Willy Tarreau4726f532009-03-07 17:25:21 +010059#include <proto/task.h>
Willy Tarreau91861262007-10-17 17:06:05 +020060
Willy Tarreau7a0169a2012-11-19 17:13:16 +010061#ifdef USE_OPENSSL
62#include <proto/ssl_sock.h>
63#endif
64
Simon Horman9bd2c732011-06-15 15:18:44 +090065static int stats_dump_raw_to_buffer(struct stream_interface *si);
Willy Tarreau76153662012-11-26 01:16:39 +010066static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess);
Simon Horman9bd2c732011-06-15 15:18:44 +090067static int stats_dump_sess_to_buffer(struct stream_interface *si);
68static int stats_dump_errors_to_buffer(struct stream_interface *si);
Simon Hormanc88b8872011-06-15 15:18:49 +090069static int stats_table_request(struct stream_interface *si, bool show);
Simon Horman9bd2c732011-06-15 15:18:44 +090070static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struct uri_auth *uri);
71static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri);
72
73static struct si_applet cli_applet;
74
75static const char stats_sock_usage_msg[] =
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020076 "Unknown command. Please enter one of the following commands only :\n"
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +020077 " clear counters : clear max statistics counters (add 'all' for all counters)\n"
Willy Tarreau88ee3972010-07-13 13:48:00 +020078 " clear table : remove an entry from a table\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020079 " help : this message\n"
80 " prompt : toggle interactive mode with prompt\n"
81 " quit : disconnect\n"
82 " show info : report information about the running process\n"
83 " show stat : report counters for each proxy and server\n"
84 " show errors : report last request and response errors for each proxy\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +010085 " show sess [id] : report the list of current sessions or dump this session\n"
Willy Tarreau69f58c82010-07-12 17:55:33 +020086 " show table [id]: report table usage stats or dump this table's contents\n"
Willy Tarreau38338fa2009-10-10 18:37:29 +020087 " get weight : report a server's current weight\n"
Willy Tarreau4483d432009-10-10 19:30:08 +020088 " set weight : change a server's weight\n"
Willy Tarreau654694e2012-06-07 01:03:16 +020089 " set table [id] : update or create a table entry's data\n"
Willy Tarreau7aabd112010-01-26 10:59:06 +010090 " set timeout : change a timeout setting\n"
Willy Tarreau2a0f4d22011-08-02 11:49:05 +020091 " set maxconn : change a maxconn setting\n"
Willy Tarreauf5b22872011-09-07 16:13:44 +020092 " set rate-limit : change a rate limiting value\n"
Willy Tarreaua295edc2011-09-07 23:21:03 +020093 " disable : put a server or frontend in maintenance mode\n"
94 " enable : re-enable a server or frontend which is in maintenance mode\n"
95 " shutdown : kill a session or a frontend (eg:to release listening ports)\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020096 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +020097
Simon Horman9bd2c732011-06-15 15:18:44 +090098static const char stats_permission_denied_msg[] =
Willy Tarreau6162db22009-10-10 17:13:00 +020099 "Permission denied\n"
100 "";
101
Willy Tarreau295a8372011-03-10 11:25:07 +0100102/* data transmission states for the stats responses */
103enum {
104 STAT_ST_INIT = 0,
105 STAT_ST_HEAD,
106 STAT_ST_INFO,
107 STAT_ST_LIST,
108 STAT_ST_END,
109 STAT_ST_FIN,
110};
111
112/* data transmission states for the stats responses inside a proxy */
113enum {
114 STAT_PX_ST_INIT = 0,
115 STAT_PX_ST_TH,
116 STAT_PX_ST_FE,
117 STAT_PX_ST_LI,
118 STAT_PX_ST_SV,
119 STAT_PX_ST_BE,
120 STAT_PX_ST_END,
121 STAT_PX_ST_FIN,
122};
123
Cyril Bonté19979e12012-04-04 12:57:21 +0200124extern const char *stat_status_codes[];
125
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200126/* This function is called from the session-level accept() in order to instanciate
Willy Tarreaueb472682010-05-28 18:46:57 +0200127 * a new stats socket. It returns a positive value upon success, 0 if the connection
128 * needs to be closed and ignored, or a negative value upon critical failure.
129 */
Simon Horman9bd2c732011-06-15 15:18:44 +0900130static int stats_accept(struct session *s)
Willy Tarreaueb472682010-05-28 18:46:57 +0200131{
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200132 /* we have a dedicated I/O handler for the stats */
Willy Tarreaub24281b2011-02-13 13:16:36 +0100133 stream_int_register_handler(&s->si[1], &cli_applet);
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100134 s->target = s->si[1].conn->target; // for logging only
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200135 s->si[1].conn->xprt_ctx = s;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100136 s->si[1].applet.st1 = 0;
137 s->si[1].applet.st0 = STAT_CLI_INIT;
Willy Tarreaueb472682010-05-28 18:46:57 +0200138
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200139 tv_zero(&s->logs.tv_request);
140 s->logs.t_queue = 0;
141 s->logs.t_connect = 0;
142 s->logs.t_data = 0;
143 s->logs.t_close = 0;
144 s->logs.bytes_in = s->logs.bytes_out = 0;
145 s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
146 s->logs.srv_queue_size = 0; /* we will get this number soon */
Willy Tarreaueb472682010-05-28 18:46:57 +0200147
Willy Tarreau03cdb7c2012-08-27 23:14:58 +0200148 s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreaueb472682010-05-28 18:46:57 +0200149
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200150 if (s->listener->timeout) {
151 s->req->rto = *s->listener->timeout;
152 s->rep->wto = *s->listener->timeout;
Willy Tarreaueb472682010-05-28 18:46:57 +0200153 }
Willy Tarreaueb472682010-05-28 18:46:57 +0200154 return 1;
Willy Tarreaueb472682010-05-28 18:46:57 +0200155}
156
Willy Tarreau07e9e642010-08-17 21:48:17 +0200157/* allocate a new stats frontend named <name>, and return it
158 * (or NULL in case of lack of memory).
159 */
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200160static struct proxy *alloc_stats_fe(const char *name, const char *file, int line)
Willy Tarreau07e9e642010-08-17 21:48:17 +0200161{
162 struct proxy *fe;
163
164 fe = (struct proxy *)calloc(1, sizeof(struct proxy));
165 if (!fe)
166 return NULL;
167
Willy Tarreau237250c2011-07-29 01:49:03 +0200168 init_new_proxy(fe);
Willy Tarreau050536d2012-10-04 08:47:34 +0200169 fe->next = proxy;
170 proxy = fe;
Willy Tarreau07e9e642010-08-17 21:48:17 +0200171 fe->last_change = now.tv_sec;
172 fe->id = strdup("GLOBAL");
173 fe->cap = PR_CAP_FE;
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200174 fe->maxconn = 10; /* default to 10 concurrent connections */
175 fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200176 fe->conf.file = strdup(file);
177 fe->conf.line = line;
Willy Tarreauc53d4222012-09-20 20:19:28 +0200178 fe->accept = stats_accept;
Willy Tarreau050536d2012-10-04 08:47:34 +0200179
180 /* the stats frontend is the only one able to assign ID #0 */
181 fe->conf.id.key = fe->uuid = 0;
182 eb32_insert(&used_proxy_id, &fe->conf.id);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200183 return fe;
184}
185
Willy Tarreaufbee7132007-10-18 13:53:22 +0200186/* This function parses a "stats" statement in the "global" section. It returns
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200187 * -1 if there is any error, otherwise zero. If it returns -1, it will write an
188 * error message into the <err> buffer which will be preallocated. The trailing
189 * '\n' must not be written. The function must be called with <args> pointing to
190 * the first word after "stats".
Willy Tarreaufbee7132007-10-18 13:53:22 +0200191 */
Willy Tarreau10522fd2008-07-09 20:12:41 +0200192static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
Willy Tarreau28a47d62012-09-18 20:02:48 +0200193 struct proxy *defpx, const char *file, int line,
194 char **err)
Willy Tarreaufbee7132007-10-18 13:53:22 +0200195{
Willy Tarreau4348fad2012-09-20 16:48:07 +0200196 struct bind_conf *bind_conf;
Willy Tarreauc53d4222012-09-20 20:19:28 +0200197 struct listener *l;
Willy Tarreau4348fad2012-09-20 16:48:07 +0200198
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200199 if (!strcmp(args[1], "socket")) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200200 int cur_arg;
201
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200202 if (*args[2] == 0) {
Willy Tarreauc53d4222012-09-20 20:19:28 +0200203 memprintf(err, "'%s %s' in global section expects an address or a path to a UNIX socket", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200204 return -1;
205 }
206
Willy Tarreau89a63132009-08-16 17:41:45 +0200207 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200208 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200209 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreau89a63132009-08-16 17:41:45 +0200210 return -1;
211 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200212 }
213
Willy Tarreau4348fad2012-09-20 16:48:07 +0200214 bind_conf = bind_conf_alloc(&global.stats_fe->conf.bind, file, line, args[2]);
Willy Tarreau290e63a2012-09-20 18:07:14 +0200215 bind_conf->level = ACCESS_LVL_OPER; /* default access level */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200216
Willy Tarreauc53d4222012-09-20 20:19:28 +0200217 if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) {
218 memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n",
219 file, line, args[0], args[1], err && *err ? *err : "error");
220 return -1;
221 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200222
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200223 cur_arg = 3;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200224 while (*args[cur_arg]) {
Willy Tarreaud5781202012-09-22 19:32:35 +0200225 static int bind_dumped;
226 struct bind_kw *kw;
227
228 kw = bind_find_kw(args[cur_arg]);
229 if (kw) {
230 if (!kw->parse) {
231 memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).",
232 args[0], args[1], args[cur_arg]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200233 return -1;
234 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200235
236 if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) {
237 if (err && *err)
238 memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err);
239 else
240 memprintf(err, "'%s %s' : error encountered while processing '%s'",
241 args[0], args[1], args[cur_arg]);
Willy Tarreau6162db22009-10-10 17:13:00 +0200242 return -1;
243 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200244
245 cur_arg += 1 + kw->skip;
246 continue;
Willy Tarreau6162db22009-10-10 17:13:00 +0200247 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200248
249 if (!bind_dumped) {
250 bind_dump_kws(err);
251 indent_msg(err, 4);
252 bind_dumped = 1;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200253 }
Willy Tarreaud5781202012-09-22 19:32:35 +0200254
255 memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s",
256 args[0], args[1], args[cur_arg],
257 err && *err ? " Registered keywords :" : "", err && *err ? *err : "");
258 return -1;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200259 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100260
Willy Tarreauc53d4222012-09-20 20:19:28 +0200261 list_for_each_entry(l, &bind_conf->listeners, by_bind) {
262 l->maxconn = global.stats_fe->maxconn;
263 l->backlog = global.stats_fe->backlog;
264 l->timeout = &global.stats_fe->timeout.client;
265 l->accept = session_accept;
266 l->handler = process_session;
267 l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
268 l->nice = -64; /* we want to boost priority for local stats */
269 global.maxsock += l->maxconn;
270 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200271 }
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200272 else if (!strcmp(args[1], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100273 unsigned timeout;
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200274 const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS);
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100275
276 if (res) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200277 memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res);
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100278 return -1;
279 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200280
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100281 if (!timeout) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200282 memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200283 return -1;
284 }
Willy Tarreau07e9e642010-08-17 21:48:17 +0200285 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200286 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200287 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200288 return -1;
289 }
290 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200291 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200292 }
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200293 else if (!strcmp(args[1], "maxconn")) {
294 int maxconn = atol(args[2]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200295
296 if (maxconn <= 0) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200297 memprintf(err, "'%s %s' expects a positive value", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200298 return -1;
299 }
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200300
301 if (!global.stats_fe) {
Willy Tarreaua020fbd2012-09-18 20:05:00 +0200302 if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) {
Willy Tarreau0a3dd742012-05-08 19:47:01 +0200303 memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]);
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200304 return -1;
305 }
306 }
307 global.stats_fe->maxconn = maxconn;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200308 }
Willy Tarreau35b7b162012-10-22 23:17:18 +0200309 else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */
310 int cur_arg = 2;
311 unsigned int set = 0;
312
313 while (*args[cur_arg]) {
Willy Tarreau110ecc12012-11-15 17:50:01 +0100314 unsigned int low, high;
315
Willy Tarreau35b7b162012-10-22 23:17:18 +0200316 if (strcmp(args[cur_arg], "all") == 0) {
317 set = 0;
318 break;
319 }
320 else if (strcmp(args[cur_arg], "odd") == 0) {
321 set |= 0x55555555;
322 }
323 else if (strcmp(args[cur_arg], "even") == 0) {
324 set |= 0xAAAAAAAA;
325 }
Willy Tarreau83d84cf2012-11-22 01:04:31 +0100326 else if (isdigit((int)*args[cur_arg])) {
Willy Tarreau110ecc12012-11-15 17:50:01 +0100327 char *dash = strchr(args[cur_arg], '-');
328
329 low = high = str2uic(args[cur_arg]);
330 if (dash)
331 high = str2uic(dash + 1);
332
333 if (high < low) {
334 unsigned int swap = low;
335 low = high;
336 high = swap;
337 }
338
339 if (low < 1 || high > 32) {
340 memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n",
341 args[0], args[1]);
Willy Tarreau35b7b162012-10-22 23:17:18 +0200342 return -1;
343 }
Willy Tarreau110ecc12012-11-15 17:50:01 +0100344
345 while (low <= high)
346 set |= 1 << (low++ - 1);
347 }
348 else {
349 memprintf(err,
350 "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n",
351 args[0], args[1]);
352 return -1;
Willy Tarreau35b7b162012-10-22 23:17:18 +0200353 }
354 cur_arg++;
355 }
356 global.stats_fe->bind_proc = set;
357 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200358 else {
Willy Tarreau35b7b162012-10-22 23:17:18 +0200359 memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200360 return -1;
361 }
362 return 0;
363}
364
Simon Horman9bd2c732011-06-15 15:18:44 +0900365static int print_csv_header(struct chunk *msg)
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100366{
Willy Tarreau77804732012-10-29 16:14:26 +0100367 return chunk_appendf(msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100368 "# pxname,svname,"
369 "qcur,qmax,"
370 "scur,smax,slim,stot,"
371 "bin,bout,"
372 "dreq,dresp,"
373 "ereq,econ,eresp,"
374 "wretr,wredis,"
375 "status,weight,act,bck,"
376 "chkfail,chkdown,lastchg,downtime,qlimit,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +0200377 "pid,iid,sid,throttle,lbtot,tracked,type,"
378 "rate,rate_lim,rate_max,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200379 "check_status,check_code,check_duration,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100380 "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,"
Willy Tarreauae526782010-03-04 20:34:23 +0100381 "req_rate,req_rate_max,req_tot,"
382 "cli_abrt,srv_abrt,"
Willy Tarreau5e16cbc2012-11-24 14:54:13 +0100383 "comp_in,comp_out,comp_byp,comp_rsp,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100384 "\n");
385}
386
Simon Hormand9366582011-06-15 15:18:45 +0900387/* print a string of text buffer to <out>. The format is :
388 * Non-printable chars \t, \n, \r and \e are * encoded in C format.
389 * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped.
390 * Print stopped if null char or <bsize> is reached, or if no more place in the chunk.
391 */
392static int dump_text(struct chunk *out, const char *buf, int bsize)
393{
394 unsigned char c;
395 int ptr = 0;
396
397 while (buf[ptr] && ptr < bsize) {
398 c = buf[ptr];
399 if (isprint(c) && isascii(c) && c != '\\' && c != ' ') {
400 if (out->len > out->size - 1)
401 break;
402 out->str[out->len++] = c;
403 }
404 else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') {
405 if (out->len > out->size - 2)
406 break;
407 out->str[out->len++] = '\\';
408 switch (c) {
409 case ' ': c = ' '; break;
410 case '\t': c = 't'; break;
411 case '\n': c = 'n'; break;
412 case '\r': c = 'r'; break;
413 case '\e': c = 'e'; break;
414 case '\\': c = '\\'; break;
415 }
416 out->str[out->len++] = c;
417 }
418 else {
419 if (out->len > out->size - 4)
420 break;
421 out->str[out->len++] = '\\';
422 out->str[out->len++] = 'x';
423 out->str[out->len++] = hextab[(c >> 4) & 0xF];
424 out->str[out->len++] = hextab[c & 0xF];
425 }
426 ptr++;
427 }
428
429 return ptr;
430}
431
432/* print a buffer in hexa.
433 * Print stopped if <bsize> is reached, or if no more place in the chunk.
434 */
435static int dump_binary(struct chunk *out, const char *buf, int bsize)
436{
437 unsigned char c;
438 int ptr = 0;
439
440 while (ptr < bsize) {
441 c = buf[ptr];
442
443 if (out->len > out->size - 2)
444 break;
445 out->str[out->len++] = hextab[(c >> 4) & 0xF];
446 out->str[out->len++] = hextab[c & 0xF];
447
448 ptr++;
449 }
450 return ptr;
451}
452
453/* Dump the status of a table to a stream interface's
454 * read buffer. It returns 0 if the output buffer is full
455 * and needs to be called again, otherwise non-zero.
456 */
457static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si,
458 struct proxy *proxy, struct proxy *target)
459{
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200460 struct session *s = si->conn->xprt_ctx;
Simon Hormand9366582011-06-15 15:18:45 +0900461
Willy Tarreau77804732012-10-29 16:14:26 +0100462 chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n",
Simon Hormand9366582011-06-15 15:18:45 +0900463 proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current);
464
465 /* any other information should be dumped here */
466
Willy Tarreau290e63a2012-09-20 18:07:14 +0200467 if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER)
Willy Tarreau77804732012-10-29 16:14:26 +0100468 chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n");
Simon Hormand9366582011-06-15 15:18:45 +0900469
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200470 if (bi_putchk(si->ib, msg) == -1)
Simon Hormand9366582011-06-15 15:18:45 +0900471 return 0;
472
473 return 1;
474}
475
476/* Dump the a table entry to a stream interface's
477 * read buffer. It returns 0 if the output buffer is full
478 * and needs to be called again, otherwise non-zero.
479 */
480static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si,
481 struct proxy *proxy, struct stksess *entry)
482{
483 int dt;
484
Willy Tarreau77804732012-10-29 16:14:26 +0100485 chunk_appendf(msg, "%p:", entry);
Simon Hormand9366582011-06-15 15:18:45 +0900486
487 if (proxy->table.type == STKTABLE_TYPE_IP) {
488 char addr[INET_ADDRSTRLEN];
489 inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr));
Willy Tarreau77804732012-10-29 16:14:26 +0100490 chunk_appendf(msg, " key=%s", addr);
Simon Hormand9366582011-06-15 15:18:45 +0900491 }
492 else if (proxy->table.type == STKTABLE_TYPE_IPV6) {
493 char addr[INET6_ADDRSTRLEN];
494 inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr));
Willy Tarreau77804732012-10-29 16:14:26 +0100495 chunk_appendf(msg, " key=%s", addr);
Simon Hormand9366582011-06-15 15:18:45 +0900496 }
497 else if (proxy->table.type == STKTABLE_TYPE_INTEGER) {
Willy Tarreau77804732012-10-29 16:14:26 +0100498 chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key);
Simon Hormand9366582011-06-15 15:18:45 +0900499 }
500 else if (proxy->table.type == STKTABLE_TYPE_STRING) {
Willy Tarreau77804732012-10-29 16:14:26 +0100501 chunk_appendf(msg, " key=");
Simon Hormand9366582011-06-15 15:18:45 +0900502 dump_text(msg, (const char *)entry->key.key, proxy->table.key_size);
503 }
504 else {
Willy Tarreau77804732012-10-29 16:14:26 +0100505 chunk_appendf(msg, " key=");
Simon Hormand9366582011-06-15 15:18:45 +0900506 dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size);
507 }
508
Willy Tarreau77804732012-10-29 16:14:26 +0100509 chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire));
Simon Hormand9366582011-06-15 15:18:45 +0900510
511 for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) {
512 void *ptr;
513
514 if (proxy->table.data_ofs[dt] == 0)
515 continue;
516 if (stktable_data_types[dt].arg_type == ARG_T_DELAY)
Willy Tarreau77804732012-10-29 16:14:26 +0100517 chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u);
Simon Hormand9366582011-06-15 15:18:45 +0900518 else
Willy Tarreau77804732012-10-29 16:14:26 +0100519 chunk_appendf(msg, " %s=", stktable_data_types[dt].name);
Simon Hormand9366582011-06-15 15:18:45 +0900520
521 ptr = stktable_data_ptr(&proxy->table, entry, dt);
522 switch (stktable_data_types[dt].std_type) {
523 case STD_T_SINT:
Willy Tarreau77804732012-10-29 16:14:26 +0100524 chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint));
Simon Hormand9366582011-06-15 15:18:45 +0900525 break;
526 case STD_T_UINT:
Willy Tarreau77804732012-10-29 16:14:26 +0100527 chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint));
Simon Hormand9366582011-06-15 15:18:45 +0900528 break;
529 case STD_T_ULL:
Willy Tarreau77804732012-10-29 16:14:26 +0100530 chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull));
Simon Hormand9366582011-06-15 15:18:45 +0900531 break;
532 case STD_T_FRQP:
Willy Tarreau77804732012-10-29 16:14:26 +0100533 chunk_appendf(msg, "%d",
Simon Hormand9366582011-06-15 15:18:45 +0900534 read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
535 proxy->table.data_arg[dt].u));
536 break;
537 }
538 }
Willy Tarreau77804732012-10-29 16:14:26 +0100539 chunk_appendf(msg, "\n");
Simon Hormand9366582011-06-15 15:18:45 +0900540
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200541 if (bi_putchk(si->ib, msg) == -1)
Simon Hormand9366582011-06-15 15:18:45 +0900542 return 0;
543
544 return 1;
545}
546
Willy Tarreaudec98142012-06-06 23:37:08 +0200547static void stats_sock_table_key_request(struct stream_interface *si, char **args, int action)
Simon Horman121f3052011-06-15 15:18:46 +0900548{
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200549 struct session *s = si->conn->xprt_ctx;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900550 struct proxy *px = si->applet.ctx.table.target;
Simon Horman121f3052011-06-15 15:18:46 +0900551 struct stksess *ts;
Simon Hormancec9a222011-06-15 15:18:51 +0900552 uint32_t uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900553 unsigned char ip6_key[sizeof(struct in6_addr)];
Willy Tarreau654694e2012-06-07 01:03:16 +0200554 long long value;
555 int data_type;
556 void *ptr;
557 struct freq_ctr_period *frqp;
Simon Horman121f3052011-06-15 15:18:46 +0900558
Simon Hormand5b9fd92011-06-15 15:18:48 +0900559 si->applet.st0 = STAT_CLI_OUTPUT;
Simon Horman121f3052011-06-15 15:18:46 +0900560
561 if (!*args[4]) {
562 si->applet.ctx.cli.msg = "Key value expected\n";
563 si->applet.st0 = STAT_CLI_PRINT;
564 return;
565 }
566
Simon Hormanc5b89f62011-06-15 15:18:50 +0900567 switch (px->table.type) {
568 case STKTABLE_TYPE_IP:
Simon Hormancec9a222011-06-15 15:18:51 +0900569 uint32_key = htonl(inetaddr_host(args[4]));
Willy Tarreau07115412012-10-29 21:56:59 +0100570 static_table_key->key = &uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900571 break;
572 case STKTABLE_TYPE_IPV6:
573 inet_pton(AF_INET6, args[4], ip6_key);
Willy Tarreau07115412012-10-29 21:56:59 +0100574 static_table_key->key = &ip6_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900575 break;
Simon Hormancec9a222011-06-15 15:18:51 +0900576 case STKTABLE_TYPE_INTEGER:
577 {
578 char *endptr;
579 unsigned long val;
580 errno = 0;
581 val = strtoul(args[4], &endptr, 10);
582 if ((errno == ERANGE && val == ULONG_MAX) ||
583 (errno != 0 && val == 0) || endptr == args[4] ||
584 val > 0xffffffff) {
585 si->applet.ctx.cli.msg = "Invalid key\n";
586 si->applet.st0 = STAT_CLI_PRINT;
587 return;
588 }
589 uint32_key = (uint32_t) val;
Willy Tarreau07115412012-10-29 21:56:59 +0100590 static_table_key->key = &uint32_key;
Simon Hormancec9a222011-06-15 15:18:51 +0900591 break;
592 }
593 break;
Simon Horman619e3cc2011-06-15 15:18:52 +0900594 case STKTABLE_TYPE_STRING:
Willy Tarreau07115412012-10-29 21:56:59 +0100595 static_table_key->key = args[4];
596 static_table_key->key_len = strlen(args[4]);
Simon Horman619e3cc2011-06-15 15:18:52 +0900597 break;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900598 default:
Willy Tarreaudec98142012-06-06 23:37:08 +0200599 switch (action) {
600 case STAT_CLI_O_TAB:
601 si->applet.ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n";
602 break;
603 case STAT_CLI_O_CLR:
604 si->applet.ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6, string and integer is not supported\n";
605 break;
606 default:
607 si->applet.ctx.cli.msg = "Unknown action\n";
608 break;
609 }
Simon Horman121f3052011-06-15 15:18:46 +0900610 si->applet.st0 = STAT_CLI_PRINT;
611 return;
612 }
613
614 /* check permissions */
Willy Tarreau290e63a2012-09-20 18:07:14 +0200615 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Simon Horman121f3052011-06-15 15:18:46 +0900616 si->applet.ctx.cli.msg = stats_permission_denied_msg;
617 si->applet.st0 = STAT_CLI_PRINT;
618 return;
619 }
620
Willy Tarreau07115412012-10-29 21:56:59 +0100621 ts = stktable_lookup_key(&px->table, static_table_key);
Simon Horman17bce342011-06-15 15:18:47 +0900622
Willy Tarreaudec98142012-06-06 23:37:08 +0200623 switch (action) {
624 case STAT_CLI_O_TAB:
625 if (!ts)
626 return;
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100627 chunk_reset(&trash);
628 if (!stats_dump_table_head_to_buffer(&trash, si, px, px))
Simon Horman17bce342011-06-15 15:18:47 +0900629 return;
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100630 stats_dump_table_entry_to_buffer(&trash, si, px, ts);
Simon Horman121f3052011-06-15 15:18:46 +0900631 return;
Willy Tarreaudec98142012-06-06 23:37:08 +0200632
633 case STAT_CLI_O_CLR:
634 if (!ts)
635 return;
636 if (ts->ref_cnt) {
637 /* don't delete an entry which is currently referenced */
638 si->applet.ctx.cli.msg = "Entry currently in use, cannot remove\n";
639 si->applet.st0 = STAT_CLI_PRINT;
640 return;
641 }
642 stksess_kill(&px->table, ts);
643 break;
Simon Horman17bce342011-06-15 15:18:47 +0900644
Willy Tarreau654694e2012-06-07 01:03:16 +0200645 case STAT_CLI_O_SET:
646 if (strncmp(args[5], "data.", 5) != 0) {
647 si->applet.ctx.cli.msg = "\"data.<type>\" followed by a value expected\n";
648 si->applet.st0 = STAT_CLI_PRINT;
649 return;
650 }
651
652 data_type = stktable_get_data_type(args[5] + 5);
653 if (data_type < 0) {
654 si->applet.ctx.cli.msg = "Unknown data type\n";
655 si->applet.st0 = STAT_CLI_PRINT;
656 return;
657 }
658
659 if (!px->table.data_ofs[data_type]) {
660 si->applet.ctx.cli.msg = "Data type not stored in this table\n";
661 si->applet.st0 = STAT_CLI_PRINT;
662 return;
663 }
664
665 if (!*args[6] || strl2llrc(args[6], strlen(args[6]), &value) != 0) {
666 si->applet.ctx.cli.msg = "Require a valid integer value to store\n";
667 si->applet.st0 = STAT_CLI_PRINT;
668 return;
669 }
670
671 if (ts)
672 stktable_touch(&px->table, ts, 1);
673 else {
Willy Tarreau07115412012-10-29 21:56:59 +0100674 ts = stksess_new(&px->table, static_table_key);
Willy Tarreau654694e2012-06-07 01:03:16 +0200675 if (!ts) {
676 /* don't delete an entry which is currently referenced */
677 si->applet.ctx.cli.msg = "Unable to allocate a new entry\n";
678 si->applet.st0 = STAT_CLI_PRINT;
679 return;
680 }
681 stktable_store(&px->table, ts, 1);
682 }
683
684 ptr = stktable_data_ptr(&px->table, ts, data_type);
685 switch (stktable_data_types[data_type].std_type) {
686 case STD_T_SINT:
687 stktable_data_cast(ptr, std_t_sint) = value;
688 break;
689 case STD_T_UINT:
690 stktable_data_cast(ptr, std_t_uint) = value;
691 break;
692 case STD_T_ULL:
693 stktable_data_cast(ptr, std_t_ull) = value;
694 break;
695 case STD_T_FRQP:
696 /* We only reset the previous value so that it slowly fades out */
697 frqp = &stktable_data_cast(ptr, std_t_frqp);
698 frqp->curr_tick = now_ms;
699 frqp->prev_ctr = value;
700 frqp->curr_ctr = 0;
701 break;
702 }
703 break;
704
Willy Tarreaudec98142012-06-06 23:37:08 +0200705 default:
706 si->applet.ctx.cli.msg = "Unknown action\n";
Simon Horman121f3052011-06-15 15:18:46 +0900707 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreaudec98142012-06-06 23:37:08 +0200708 break;
Simon Horman121f3052011-06-15 15:18:46 +0900709 }
Simon Horman121f3052011-06-15 15:18:46 +0900710}
711
Willy Tarreau654694e2012-06-07 01:03:16 +0200712static void stats_sock_table_data_request(struct stream_interface *si, char **args, int action)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900713{
Willy Tarreau654694e2012-06-07 01:03:16 +0200714 if (action != STAT_CLI_O_TAB) {
715 si->applet.ctx.cli.msg = "content-based lookup is only supported with the \"show\" action";
716 si->applet.st0 = STAT_CLI_PRINT;
717 return;
718 }
719
Simon Hormand5b9fd92011-06-15 15:18:48 +0900720 /* condition on stored data value */
721 si->applet.ctx.table.data_type = stktable_get_data_type(args[3] + 5);
722 if (si->applet.ctx.table.data_type < 0) {
723 si->applet.ctx.cli.msg = "Unknown data type\n";
724 si->applet.st0 = STAT_CLI_PRINT;
725 return;
726 }
727
728 if (!((struct proxy *)si->applet.ctx.table.target)->table.data_ofs[si->applet.ctx.table.data_type]) {
729 si->applet.ctx.cli.msg = "Data type not stored in this table\n";
730 si->applet.st0 = STAT_CLI_PRINT;
731 return;
732 }
733
734 si->applet.ctx.table.data_op = get_std_op(args[4]);
735 if (si->applet.ctx.table.data_op < 0) {
736 si->applet.ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n";
737 si->applet.st0 = STAT_CLI_PRINT;
738 return;
739 }
740
741 if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &si->applet.ctx.table.value) != 0) {
742 si->applet.ctx.cli.msg = "Require a valid integer value to compare against\n";
743 si->applet.st0 = STAT_CLI_PRINT;
744 return;
745 }
746}
747
Willy Tarreaudec98142012-06-06 23:37:08 +0200748static void stats_sock_table_request(struct stream_interface *si, char **args, int action)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900749{
750 si->applet.ctx.table.data_type = -1;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200751 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaue17a8d02011-08-24 08:23:34 +0200752 si->applet.ctx.table.target = NULL;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900753 si->applet.ctx.table.proxy = NULL;
754 si->applet.ctx.table.entry = NULL;
Willy Tarreaudec98142012-06-06 23:37:08 +0200755 si->applet.st0 = action;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900756
757 if (*args[2]) {
758 si->applet.ctx.table.target = find_stktable(args[2]);
759 if (!si->applet.ctx.table.target) {
760 si->applet.ctx.cli.msg = "No such table\n";
761 si->applet.st0 = STAT_CLI_PRINT;
762 return;
763 }
764 }
765 else {
Willy Tarreaudec98142012-06-06 23:37:08 +0200766 if (action != STAT_CLI_O_TAB)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900767 goto err_args;
768 return;
769 }
770
771 if (strcmp(args[3], "key") == 0)
Willy Tarreaudec98142012-06-06 23:37:08 +0200772 stats_sock_table_key_request(si, args, action);
Simon Hormanc88b8872011-06-15 15:18:49 +0900773 else if (strncmp(args[3], "data.", 5) == 0)
Willy Tarreau654694e2012-06-07 01:03:16 +0200774 stats_sock_table_data_request(si, args, action);
Simon Hormanc88b8872011-06-15 15:18:49 +0900775 else if (*args[3])
Simon Hormand5b9fd92011-06-15 15:18:48 +0900776 goto err_args;
777
778 return;
779
780err_args:
Willy Tarreaudec98142012-06-06 23:37:08 +0200781 switch (action) {
782 case STAT_CLI_O_TAB:
Simon Hormand5b9fd92011-06-15 15:18:48 +0900783 si->applet.ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200784 break;
785 case STAT_CLI_O_CLR:
Simon Hormanc88b8872011-06-15 15:18:49 +0900786 si->applet.ctx.cli.msg = "Required arguments: <table> \"data.<store_data_type>\" <operator> <value> or <table> key <key>\n";
Willy Tarreaudec98142012-06-06 23:37:08 +0200787 break;
788 default:
789 si->applet.ctx.cli.msg = "Unknown action\n";
790 break;
791 }
Simon Hormand5b9fd92011-06-15 15:18:48 +0900792 si->applet.st0 = STAT_CLI_PRINT;
793}
794
Willy Tarreau532a4502011-09-07 22:37:44 +0200795/* Expects to find a frontend named <arg> and returns it, otherwise displays various
796 * adequate error messages and returns NULL. This function also expects the session
797 * level to be admin.
798 */
799static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg)
800{
801 struct proxy *px;
802
Willy Tarreau290e63a2012-09-20 18:07:14 +0200803 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau532a4502011-09-07 22:37:44 +0200804 si->applet.ctx.cli.msg = stats_permission_denied_msg;
805 si->applet.st0 = STAT_CLI_PRINT;
806 return NULL;
807 }
808
809 if (!*arg) {
810 si->applet.ctx.cli.msg = "A frontend name is expected.\n";
811 si->applet.st0 = STAT_CLI_PRINT;
812 return NULL;
813 }
814
815 px = findproxy(arg, PR_CAP_FE);
816 if (!px) {
817 si->applet.ctx.cli.msg = "No such frontend.\n";
818 si->applet.st0 = STAT_CLI_PRINT;
819 return NULL;
820 }
821 return px;
822}
823
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200824/* Expects to find a backend and a server in <arg> under the form <backend>/<server>,
825 * and returns the pointer to the server. Otherwise, display adequate error messages
826 * and returns NULL. This function also expects the session level to be admin. Note:
827 * the <arg> is modified to remove the '/'.
828 */
829static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg)
830{
831 struct proxy *px;
832 struct server *sv;
833 char *line;
834
Willy Tarreau290e63a2012-09-20 18:07:14 +0200835 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200836 si->applet.ctx.cli.msg = stats_permission_denied_msg;
837 si->applet.st0 = STAT_CLI_PRINT;
838 return NULL;
839 }
840
841 /* split "backend/server" and make <line> point to server */
842 for (line = arg; *line; line++)
843 if (*line == '/') {
844 *line++ = '\0';
845 break;
846 }
847
848 if (!*line || !*arg) {
849 si->applet.ctx.cli.msg = "Require 'backend/server'.\n";
850 si->applet.st0 = STAT_CLI_PRINT;
851 return NULL;
852 }
853
854 if (!get_backend_server(arg, line, &px, &sv)) {
855 si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
856 si->applet.st0 = STAT_CLI_PRINT;
857 return NULL;
858 }
859
860 if (px->state == PR_STSTOPPED) {
861 si->applet.ctx.cli.msg = "Proxy is disabled.\n";
862 si->applet.st0 = STAT_CLI_PRINT;
863 return NULL;
864 }
865
866 return sv;
867}
868
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200869/* Processes the stats interpreter on the statistics socket. This function is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200870 * called from an applet running in a stream interface. The function returns 1
Willy Tarreaubc4af052011-02-13 13:25:14 +0100871 * if the request was understood, otherwise zero. It sets si->applet.st0 to a value
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200872 * designating the function which will have to process the request, which can
873 * also be the print function to display the return message set into cli.msg.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200874 */
Simon Horman9bd2c732011-06-15 15:18:44 +0900875static int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200876{
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200877 struct session *s = si->conn->xprt_ctx;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200878 char *args[MAX_STATS_ARGS + 1];
879 int arg;
880
881 while (isspace((unsigned char)*line))
882 line++;
883
884 arg = 0;
885 args[arg] = line;
886
887 while (*line && arg < MAX_STATS_ARGS) {
888 if (isspace((unsigned char)*line)) {
889 *line++ = '\0';
890
891 while (isspace((unsigned char)*line))
892 line++;
893
894 args[++arg] = line;
895 continue;
896 }
897
898 line++;
899 }
900
901 while (++arg <= MAX_STATS_ARGS)
902 args[arg] = line;
903
Willy Tarreau295a8372011-03-10 11:25:07 +0100904 si->applet.ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200905 if (strcmp(args[0], "show") == 0) {
906 if (strcmp(args[1], "stat") == 0) {
907 if (*args[2] && *args[3] && *args[4]) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100908 si->applet.ctx.stats.flags |= STAT_BOUND;
909 si->applet.ctx.stats.iid = atoi(args[2]);
910 si->applet.ctx.stats.type = atoi(args[3]);
911 si->applet.ctx.stats.sid = atoi(args[4]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200912 }
913
Willy Tarreau295a8372011-03-10 11:25:07 +0100914 si->applet.ctx.stats.flags |= STAT_SHOW_STAT;
915 si->applet.ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200916 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100917 si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200918 }
919 else if (strcmp(args[1], "info") == 0) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100920 si->applet.ctx.stats.flags |= STAT_SHOW_INFO;
921 si->applet.ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200922 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100923 si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200924 }
925 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200926 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreau290e63a2012-09-20 18:07:14 +0200927 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100928 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100929 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200930 return 1;
931 }
Willy Tarreau76153662012-11-26 01:16:39 +0100932 if (*args[2] && strcmp(args[2], "all") == 0)
933 si->applet.ctx.sess.target = (void *)-1;
934 else if (*args[2])
Willy Tarreau295a8372011-03-10 11:25:07 +0100935 si->applet.ctx.sess.target = (void *)strtoul(args[2], NULL, 0);
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100936 else
Willy Tarreau295a8372011-03-10 11:25:07 +0100937 si->applet.ctx.sess.target = NULL;
938 si->applet.ctx.sess.section = 0; /* start with session status */
939 si->applet.ctx.sess.pos = 0;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100940 si->applet.st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200941 }
942 else if (strcmp(args[1], "errors") == 0) {
Willy Tarreau290e63a2012-09-20 18:07:14 +0200943 if (s->listener->bind_conf->level < ACCESS_LVL_OPER) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100944 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100945 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200946 return 1;
947 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200948 if (*args[2])
Willy Tarreau295a8372011-03-10 11:25:07 +0100949 si->applet.ctx.errors.iid = atoi(args[2]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200950 else
Willy Tarreau295a8372011-03-10 11:25:07 +0100951 si->applet.ctx.errors.iid = -1;
952 si->applet.ctx.errors.px = NULL;
Willy Tarreauf2943dc2012-10-26 20:10:28 +0200953 si->conn->xprt_st = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100954 si->applet.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200955 }
Willy Tarreau69f58c82010-07-12 17:55:33 +0200956 else if (strcmp(args[1], "table") == 0) {
Willy Tarreaudec98142012-06-06 23:37:08 +0200957 stats_sock_table_request(si, args, STAT_CLI_O_TAB);
Willy Tarreau69f58c82010-07-12 17:55:33 +0200958 }
Aman Guptaceafb4a2012-04-02 18:57:54 -0700959 else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200960 return 0;
961 }
962 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200963 else if (strcmp(args[0], "clear") == 0) {
964 if (strcmp(args[1], "counters") == 0) {
965 struct proxy *px;
966 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200967 struct listener *li;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200968 int clrall = 0;
969
970 if (strcmp(args[2], "all") == 0)
971 clrall = 1;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200972
Willy Tarreau6162db22009-10-10 17:13:00 +0200973 /* check permissions */
Willy Tarreau290e63a2012-09-20 18:07:14 +0200974 if (s->listener->bind_conf->level < ACCESS_LVL_OPER ||
975 (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100976 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100977 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200978 return 1;
979 }
980
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200981 for (px = proxy; px; px = px->next) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100982 if (clrall) {
983 memset(&px->be_counters, 0, sizeof(px->be_counters));
984 memset(&px->fe_counters, 0, sizeof(px->fe_counters));
985 }
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200986 else {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100987 px->be_counters.conn_max = 0;
988 px->be_counters.p.http.rps_max = 0;
989 px->be_counters.sps_max = 0;
990 px->be_counters.cps_max = 0;
991 px->be_counters.nbpend_max = 0;
992
993 px->fe_counters.conn_max = 0;
994 px->fe_counters.p.http.rps_max = 0;
995 px->fe_counters.sps_max = 0;
996 px->fe_counters.cps_max = 0;
997 px->fe_counters.nbpend_max = 0;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200998 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200999
1000 for (sv = px->srv; sv; sv = sv->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001001 if (clrall)
1002 memset(&sv->counters, 0, sizeof(sv->counters));
1003 else {
1004 sv->counters.cur_sess_max = 0;
1005 sv->counters.nbpend_max = 0;
1006 sv->counters.sps_max = 0;
1007 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001008
Willy Tarreaua7944ad2012-09-26 21:03:11 +02001009 list_for_each_entry(li, &px->conf.listeners, by_fe)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02001010 if (li->counters) {
1011 if (clrall)
1012 memset(li->counters, 0, sizeof(*li->counters));
1013 else
1014 li->counters->conn_max = 0;
1015 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001016 }
1017
Willy Tarreau81c25d02011-09-07 15:17:21 +02001018 global.cps_max = 0;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001019 return 1;
1020 }
Willy Tarreau88ee3972010-07-13 13:48:00 +02001021 else if (strcmp(args[1], "table") == 0) {
Willy Tarreaudec98142012-06-06 23:37:08 +02001022 stats_sock_table_request(si, args, STAT_CLI_O_CLR);
Willy Tarreau88ee3972010-07-13 13:48:00 +02001023 /* end of processing */
1024 return 1;
1025 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001026 else {
Willy Tarreau88ee3972010-07-13 13:48:00 +02001027 /* unknown "clear" argument */
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02001028 return 0;
1029 }
1030 }
Willy Tarreau38338fa2009-10-10 18:37:29 +02001031 else if (strcmp(args[0], "get") == 0) {
1032 if (strcmp(args[1], "weight") == 0) {
1033 struct proxy *px;
1034 struct server *sv;
1035
1036 /* split "backend/server" and make <line> point to server */
1037 for (line = args[2]; *line; line++)
1038 if (*line == '/') {
1039 *line++ = '\0';
1040 break;
1041 }
1042
1043 if (!*line) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001044 si->applet.ctx.cli.msg = "Require 'backend/server'.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001045 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +02001046 return 1;
1047 }
1048
1049 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001050 si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001051 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +02001052 return 1;
1053 }
1054
1055 /* return server's effective weight at the moment */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001056 snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight);
1057 bi_putstr(si->ib, trash.str);
Willy Tarreau38338fa2009-10-10 18:37:29 +02001058 return 1;
1059 }
1060 else { /* not "get weight" */
1061 return 0;
1062 }
1063 }
Willy Tarreau4483d432009-10-10 19:30:08 +02001064 else if (strcmp(args[0], "set") == 0) {
1065 if (strcmp(args[1], "weight") == 0) {
1066 struct proxy *px;
1067 struct server *sv;
1068 int w;
1069
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001070 sv = expect_server_admin(s, si, args[2]);
1071 if (!sv)
Willy Tarreau4483d432009-10-10 19:30:08 +02001072 return 1;
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001073 px = sv->proxy;
Willy Tarreau4483d432009-10-10 19:30:08 +02001074
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001075 /* if the weight is terminated with '%', it is set relative to
1076 * the initial weight, otherwise it is absolute.
1077 */
1078 if (!*args[3]) {
1079 si->applet.ctx.cli.msg = "Require <weight> or <weight%>.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001080 si->applet.st0 = STAT_CLI_PRINT;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001081 return 1;
1082 }
1083
Willy Tarreau4483d432009-10-10 19:30:08 +02001084 w = atoi(args[3]);
1085 if (strchr(args[3], '%') != NULL) {
1086 if (w < 0 || w > 100) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001087 si->applet.ctx.cli.msg = "Relative weight can only be set between 0 and 100% inclusive.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001088 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001089 return 1;
1090 }
1091 w = sv->iweight * w / 100;
1092 }
1093 else {
1094 if (w < 0 || w > 256) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001095 si->applet.ctx.cli.msg = "Absolute weight can only be between 0 and 256 inclusive.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001096 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001097 return 1;
1098 }
1099 }
1100
1101 if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001102 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 +01001103 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +02001104 return 1;
1105 }
1106
1107 sv->uweight = w;
1108
1109 if (px->lbprm.algo & BE_LB_PROP_DYN) {
1110 /* we must take care of not pushing the server to full throttle during slow starts */
1111 if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN))
1112 sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart;
1113 else
1114 sv->eweight = BE_WEIGHT_SCALE;
1115 sv->eweight *= sv->uweight;
1116 } else {
1117 sv->eweight = sv->uweight;
1118 }
1119
1120 /* static LB algorithms are a bit harder to update */
1121 if (px->lbprm.update_server_eweight)
1122 px->lbprm.update_server_eweight(sv);
Willy Tarreau9580d162012-05-19 19:07:40 +02001123 else if (sv->eweight) {
1124 if (px->lbprm.set_server_status_up)
1125 px->lbprm.set_server_status_up(sv);
1126 }
1127 else {
1128 if (px->lbprm.set_server_status_down)
1129 px->lbprm.set_server_status_down(sv);
1130 }
Willy Tarreau4483d432009-10-10 19:30:08 +02001131
1132 return 1;
1133 }
Willy Tarreau7aabd112010-01-26 10:59:06 +01001134 else if (strcmp(args[1], "timeout") == 0) {
1135 if (strcmp(args[2], "cli") == 0) {
1136 unsigned timeout;
1137 const char *res;
1138
1139 if (!*args[3]) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001140 si->applet.ctx.cli.msg = "Expects an integer value.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001141 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001142 return 1;
1143 }
1144
1145 res = parse_time_err(args[3], &timeout, TIME_UNIT_S);
1146 if (res || timeout < 1) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001147 si->applet.ctx.cli.msg = "Invalid timeout value.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001148 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001149 return 1;
1150 }
1151
1152 s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000);
1153 return 1;
1154 }
1155 else {
Willy Tarreau295a8372011-03-10 11:25:07 +01001156 si->applet.ctx.cli.msg = "'set timeout' only supports 'cli'.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001157 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001158 return 1;
1159 }
1160 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001161 else if (strcmp(args[1], "maxconn") == 0) {
1162 if (strcmp(args[2], "frontend") == 0) {
1163 struct proxy *px;
1164 struct listener *l;
1165 int v;
1166
Willy Tarreau532a4502011-09-07 22:37:44 +02001167 px = expect_frontend_admin(s, si, args[3]);
1168 if (!px)
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001169 return 1;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001170
1171 if (!*args[4]) {
1172 si->applet.ctx.cli.msg = "Integer value expected.\n";
1173 si->applet.st0 = STAT_CLI_PRINT;
1174 return 1;
1175 }
1176
1177 v = atoi(args[4]);
Willy Tarreau3c7a79d2012-09-26 21:07:15 +02001178 if (v < 0) {
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001179 si->applet.ctx.cli.msg = "Value out of range.\n";
1180 si->applet.st0 = STAT_CLI_PRINT;
1181 return 1;
1182 }
1183
1184 /* OK, the value is fine, so we assign it to the proxy and to all of
1185 * its listeners. The blocked ones will be dequeued.
1186 */
1187 px->maxconn = v;
Willy Tarreaua7944ad2012-09-26 21:03:11 +02001188 list_for_each_entry(l, &px->conf.listeners, by_fe) {
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001189 l->maxconn = v;
1190 if (l->state == LI_FULL)
1191 resume_listener(l);
1192 }
1193
1194 if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue))
1195 dequeue_all_listeners(&s->fe->listener_queue);
1196
1197 return 1;
1198 }
Willy Tarreau91886b62011-09-07 14:38:31 +02001199 else if (strcmp(args[2], "global") == 0) {
1200 int v;
1201
Willy Tarreau290e63a2012-09-20 18:07:14 +02001202 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreau91886b62011-09-07 14:38:31 +02001203 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1204 si->applet.st0 = STAT_CLI_PRINT;
1205 return 1;
1206 }
1207
1208 if (!*args[3]) {
1209 si->applet.ctx.cli.msg = "Expects an integer value.\n";
1210 si->applet.st0 = STAT_CLI_PRINT;
1211 return 1;
1212 }
1213
1214 v = atoi(args[3]);
1215 if (v > global.hardmaxconn) {
1216 si->applet.ctx.cli.msg = "Value out of range.\n";
1217 si->applet.st0 = STAT_CLI_PRINT;
1218 return 1;
1219 }
1220
1221 /* check for unlimited values */
1222 if (v <= 0)
1223 v = global.hardmaxconn;
1224
1225 global.maxconn = v;
1226
1227 /* Dequeues all of the listeners waiting for a resource */
1228 if (!LIST_ISEMPTY(&global_listener_queue))
1229 dequeue_all_listeners(&global_listener_queue);
1230
1231 return 1;
1232 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001233 else {
Willy Tarreau91886b62011-09-07 14:38:31 +02001234 si->applet.ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n";
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001235 si->applet.st0 = STAT_CLI_PRINT;
1236 return 1;
1237 }
1238 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001239 else if (strcmp(args[1], "rate-limit") == 0) {
1240 if (strcmp(args[2], "connections") == 0) {
1241 if (strcmp(args[3], "global") == 0) {
1242 int v;
1243
Willy Tarreau290e63a2012-09-20 18:07:14 +02001244 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreauf5b22872011-09-07 16:13:44 +02001245 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1246 si->applet.st0 = STAT_CLI_PRINT;
1247 return 1;
1248 }
1249
1250 if (!*args[4]) {
1251 si->applet.ctx.cli.msg = "Expects an integer value.\n";
1252 si->applet.st0 = STAT_CLI_PRINT;
1253 return 1;
1254 }
1255
1256 v = atoi(args[4]);
1257 if (v < 0) {
1258 si->applet.ctx.cli.msg = "Value out of range.\n";
1259 si->applet.st0 = STAT_CLI_PRINT;
1260 return 1;
1261 }
1262
1263 global.cps_lim = v;
1264
1265 /* Dequeues all of the listeners waiting for a resource */
1266 if (!LIST_ISEMPTY(&global_listener_queue))
1267 dequeue_all_listeners(&global_listener_queue);
1268
1269 return 1;
1270 }
1271 else {
1272 si->applet.ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n";
1273 si->applet.st0 = STAT_CLI_PRINT;
1274 return 1;
1275 }
1276 }
William Lallemandd85f9172012-11-09 17:05:39 +01001277 else if (strcmp(args[2], "http-compression") == 0) {
1278 if (strcmp(args[3], "global") == 0) {
1279 int v;
1280
Willy Tarreau85d47f92012-11-21 00:29:50 +01001281 if (!*args[4]) {
1282 si->applet.ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n";
1283 si->applet.st0 = STAT_CLI_PRINT;
1284 return 1;
1285 }
1286
William Lallemandd85f9172012-11-09 17:05:39 +01001287 v = atoi(args[4]);
1288 global.comp_rate_lim = v * 1024; /* Kilo to bytes. */
1289 }
1290 else {
1291 si->applet.ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n";
1292 si->applet.st0 = STAT_CLI_PRINT;
1293 return 1;
1294 }
1295 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001296 else {
William Lallemandd85f9172012-11-09 17:05:39 +01001297 si->applet.ctx.cli.msg = "'set rate-limit' supports 'connections' and 'http-compression'.\n";
Willy Tarreauf5b22872011-09-07 16:13:44 +02001298 si->applet.st0 = STAT_CLI_PRINT;
1299 return 1;
1300 }
1301 }
Willy Tarreau654694e2012-06-07 01:03:16 +02001302 else if (strcmp(args[1], "table") == 0) {
1303 stats_sock_table_request(si, args, STAT_CLI_O_SET);
1304 }
Willy Tarreau7aabd112010-01-26 10:59:06 +01001305 else { /* unknown "set" parameter */
Willy Tarreau4483d432009-10-10 19:30:08 +02001306 return 0;
1307 }
1308 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001309 else if (strcmp(args[0], "enable") == 0) {
1310 if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001311 struct server *sv;
1312
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001313 sv = expect_server_admin(s, si, args[2]);
1314 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01001315 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001316
Cyril Bontécd19e512010-01-31 22:34:03 +01001317 if (sv->state & SRV_MAINTAIN) {
1318 /* The server is really in maintenance, we can change the server state */
Willy Tarreau44267702011-10-28 15:35:33 +02001319 if (sv->track) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001320 /* If this server tracks the status of another one,
1321 * we must restore the good status.
1322 */
Willy Tarreau44267702011-10-28 15:35:33 +02001323 if (sv->track->state & SRV_RUNNING) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001324 set_server_up(sv);
Willy Tarreau70461302010-10-22 14:39:02 +02001325 sv->health = sv->rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +01001326 } else {
1327 sv->state &= ~SRV_MAINTAIN;
1328 set_server_down(sv);
1329 }
1330 } else {
1331 set_server_up(sv);
Willy Tarreau70461302010-10-22 14:39:02 +02001332 sv->health = sv->rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +01001333 }
1334 }
1335
Willy Tarreau532a4502011-09-07 22:37:44 +02001336 return 1;
1337 }
1338 else if (strcmp(args[1], "frontend") == 0) {
1339 struct proxy *px;
1340
1341 px = expect_frontend_admin(s, si, args[2]);
1342 if (!px)
1343 return 1;
1344
1345 if (px->state == PR_STSTOPPED) {
1346 si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n";
1347 si->applet.st0 = STAT_CLI_PRINT;
1348 return 1;
1349 }
1350
1351 if (px->state != PR_STPAUSED) {
1352 si->applet.ctx.cli.msg = "Frontend is already enabled.\n";
1353 si->applet.st0 = STAT_CLI_PRINT;
1354 return 1;
1355 }
1356
1357 if (!resume_proxy(px)) {
1358 si->applet.ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n";
1359 si->applet.st0 = STAT_CLI_PRINT;
1360 return 1;
1361 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001362 return 1;
1363 }
1364 else { /* unknown "enable" parameter */
Willy Tarreau532a4502011-09-07 22:37:44 +02001365 si->applet.ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n";
1366 si->applet.st0 = STAT_CLI_PRINT;
1367 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01001368 }
1369 }
1370 else if (strcmp(args[0], "disable") == 0) {
1371 if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001372 struct server *sv;
1373
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001374 sv = expect_server_admin(s, si, args[2]);
1375 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01001376 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001377
Cyril Bontécd19e512010-01-31 22:34:03 +01001378 if (! (sv->state & SRV_MAINTAIN)) {
1379 /* Not already in maintenance, we can change the server state */
1380 sv->state |= SRV_MAINTAIN;
1381 set_server_down(sv);
1382 }
1383
Willy Tarreau532a4502011-09-07 22:37:44 +02001384 return 1;
1385 }
1386 else if (strcmp(args[1], "frontend") == 0) {
1387 struct proxy *px;
1388
1389 px = expect_frontend_admin(s, si, args[2]);
1390 if (!px)
1391 return 1;
1392
1393 if (px->state == PR_STSTOPPED) {
1394 si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n";
1395 si->applet.st0 = STAT_CLI_PRINT;
1396 return 1;
1397 }
1398
1399 if (px->state == PR_STPAUSED) {
1400 si->applet.ctx.cli.msg = "Frontend is already disabled.\n";
1401 si->applet.st0 = STAT_CLI_PRINT;
1402 return 1;
1403 }
1404
1405 if (!pause_proxy(px)) {
1406 si->applet.ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n";
1407 si->applet.st0 = STAT_CLI_PRINT;
1408 return 1;
1409 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001410 return 1;
1411 }
1412 else { /* unknown "disable" parameter */
Willy Tarreau532a4502011-09-07 22:37:44 +02001413 si->applet.ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n";
1414 si->applet.st0 = STAT_CLI_PRINT;
1415 return 1;
1416 }
1417 }
1418 else if (strcmp(args[0], "shutdown") == 0) {
1419 if (strcmp(args[1], "frontend") == 0) {
1420 struct proxy *px;
1421
1422 px = expect_frontend_admin(s, si, args[2]);
1423 if (!px)
1424 return 1;
1425
1426 if (px->state == PR_STSTOPPED) {
1427 si->applet.ctx.cli.msg = "Frontend was already shut down.\n";
1428 si->applet.st0 = STAT_CLI_PRINT;
1429 return 1;
1430 }
1431
1432 Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
1433 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
1434 send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
1435 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
1436 stop_proxy(px);
1437 return 1;
1438 }
Willy Tarreaua295edc2011-09-07 23:21:03 +02001439 else if (strcmp(args[1], "session") == 0) {
1440 struct session *sess, *ptr;
1441
Willy Tarreau290e63a2012-09-20 18:07:14 +02001442 if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) {
Willy Tarreaua295edc2011-09-07 23:21:03 +02001443 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1444 si->applet.st0 = STAT_CLI_PRINT;
1445 return 1;
1446 }
1447
1448 if (!*args[2]) {
1449 si->applet.ctx.cli.msg = "Session pointer expected (use 'show sess').\n";
1450 si->applet.st0 = STAT_CLI_PRINT;
1451 return 1;
1452 }
1453
1454 ptr = (void *)strtoul(args[2], NULL, 0);
1455
1456 /* first, look for the requested session in the session table */
1457 list_for_each_entry(sess, &sessions, list) {
1458 if (sess == ptr)
1459 break;
1460 }
1461
1462 /* do we have the session ? */
1463 if (sess != ptr) {
1464 si->applet.ctx.cli.msg = "No such session (use 'show sess').\n";
1465 si->applet.st0 = STAT_CLI_PRINT;
1466 return 1;
1467 }
1468
1469 session_shutdown(sess, SN_ERR_KILLED);
1470 return 1;
1471 }
Willy Tarreau52b2d222011-09-07 23:48:48 +02001472 else if (strcmp(args[1], "sessions") == 0) {
1473 if (strcmp(args[2], "server") == 0) {
1474 struct server *sv;
1475 struct session *sess, *sess_bck;
1476
1477 sv = expect_server_admin(s, si, args[3]);
1478 if (!sv)
1479 return 1;
1480
1481 /* kill all the session that are on this server */
1482 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
1483 if (sess->srv_conn == sv)
1484 session_shutdown(sess, SN_ERR_KILLED);
1485
1486 return 1;
1487 }
1488 else {
1489 si->applet.ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n";
1490 si->applet.st0 = STAT_CLI_PRINT;
1491 return 1;
1492 }
1493 }
Willy Tarreau532a4502011-09-07 22:37:44 +02001494 else { /* unknown "disable" parameter */
Willy Tarreau52b2d222011-09-07 23:48:48 +02001495 si->applet.ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n";
Willy Tarreau532a4502011-09-07 22:37:44 +02001496 si->applet.st0 = STAT_CLI_PRINT;
1497 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01001498 }
1499 }
1500 else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001501 return 0;
1502 }
1503 return 1;
1504}
1505
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001506/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001507 * used to processes I/O from/to the stats unix socket. The system relies on a
1508 * state machine handling requests and various responses. We read a request,
1509 * then we process it and send the response, and we possibly display a prompt.
Willy Tarreaubc4af052011-02-13 13:25:14 +01001510 * Then we can read again. The state is stored in si->applet.st0 and is one of the
1511 * STAT_CLI_* constants. si->applet.st1 is used to indicate whether prompt is enabled
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001512 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001513 */
Willy Tarreaub24281b2011-02-13 13:16:36 +01001514static void cli_io_handler(struct stream_interface *si)
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001515{
Willy Tarreau7421efb2012-07-02 15:11:27 +02001516 struct channel *req = si->ob;
1517 struct channel *res = si->ib;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001518 int reql;
1519 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001520
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001521 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
1522 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001523
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001524 while (1) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001525 if (si->applet.st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001526 /* Stats output not initialized yet */
Willy Tarreau295a8372011-03-10 11:25:07 +01001527 memset(&si->applet.ctx.stats, 0, sizeof(si->applet.ctx.stats));
Willy Tarreaubc4af052011-02-13 13:25:14 +01001528 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001529 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001530 else if (si->applet.st0 == STAT_CLI_END) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001531 /* Let's close for real now. We just close the request
1532 * side, the conditions below will complete if needed.
1533 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001534 si_shutw(si);
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001535 break;
1536 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001537 else if (si->applet.st0 == STAT_CLI_GETREQ) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02001538 /* ensure we have some output room left in the event we
1539 * would want to return some info right after parsing.
1540 */
Willy Tarreau9b28e032012-10-12 23:49:43 +02001541 if (buffer_almost_full(si->ib->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02001542 break;
1543
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001544 reql = bo_getline(si->ob, trash.str, trash.size);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001545 if (reql <= 0) { /* closed or EOL not found */
1546 if (reql == 0)
1547 break;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001548 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001549 continue;
1550 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001551
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001552 /* seek for a possible semi-colon. If we find one, we
1553 * replace it with an LF and skip only this part.
1554 */
1555 for (len = 0; len < reql; len++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001556 if (trash.str[len] == ';') {
1557 trash.str[len] = '\n';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001558 reql = len + 1;
1559 break;
1560 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001561
Willy Tarreau816fc222009-10-04 07:36:58 +02001562 /* now it is time to check that we have a full line,
1563 * remove the trailing \n and possibly \r, then cut the
1564 * line.
1565 */
1566 len = reql - 1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001567 if (trash.str[len] != '\n') {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001568 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001569 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001570 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001571
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001572 if (len && trash.str[len-1] == '\r')
Willy Tarreau816fc222009-10-04 07:36:58 +02001573 len--;
1574
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001575 trash.str[len] = '\0';
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001576
Willy Tarreaubc4af052011-02-13 13:25:14 +01001577 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001578 if (len) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001579 if (strcmp(trash.str, "quit") == 0) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001580 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001581 continue;
1582 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001583 else if (strcmp(trash.str, "prompt") == 0)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001584 si->applet.st1 = !si->applet.st1;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001585 else if (strcmp(trash.str, "help") == 0 ||
1586 !stats_sock_parse_request(si, trash.str)) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001587 si->applet.ctx.cli.msg = stats_sock_usage_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001588 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001589 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001590 /* NB: stats_sock_parse_request() may have put
Willy Tarreaubc4af052011-02-13 13:25:14 +01001591 * another STAT_CLI_O_* into si->applet.st0.
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001592 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001593 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001594 else if (!si->applet.st1) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001595 /* if prompt is disabled, print help on empty lines,
1596 * so that the user at least knows how to enable
1597 * prompt and find help.
1598 */
Willy Tarreau295a8372011-03-10 11:25:07 +01001599 si->applet.ctx.cli.msg = stats_sock_usage_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001600 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001601 }
1602
1603 /* re-adjust req buffer */
Willy Tarreau9dab5fc2012-05-07 11:56:55 +02001604 bo_skip(si->ob, reql);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001605 req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001606 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001607 else { /* output functions: first check if the output buffer is closed then abort */
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001608 if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001609 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001610 continue;
1611 }
1612
Willy Tarreaubc4af052011-02-13 13:25:14 +01001613 switch (si->applet.st0) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001614 case STAT_CLI_PRINT:
Willy Tarreau9dab5fc2012-05-07 11:56:55 +02001615 if (bi_putstr(si->ib, si->applet.ctx.cli.msg) != -1)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001616 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001617 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001618 case STAT_CLI_O_INFO:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001619 if (stats_dump_raw_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001620 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001621 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001622 case STAT_CLI_O_SESS:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001623 if (stats_dump_sess_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001624 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001625 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001626 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001627 if (stats_dump_errors_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001628 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001629 break;
Willy Tarreau69f58c82010-07-12 17:55:33 +02001630 case STAT_CLI_O_TAB:
Simon Hormanc88b8872011-06-15 15:18:49 +09001631 case STAT_CLI_O_CLR:
Willy Tarreaudec98142012-06-06 23:37:08 +02001632 if (stats_table_request(si, si->applet.st0))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001633 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau69f58c82010-07-12 17:55:33 +02001634 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001635 default: /* abnormal state */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001636 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001637 break;
1638 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001639
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001640 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001641 if (si->applet.st0 == STAT_CLI_PROMPT) {
Willy Tarreau9dab5fc2012-05-07 11:56:55 +02001642 if (bi_putstr(si->ib, si->applet.st1 ? "\n> " : "\n") != -1)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001643 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001644 }
1645
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001646 /* If the output functions are still there, it means they require more room. */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001647 if (si->applet.st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001648 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001649
1650 /* Now we close the output if one of the writers did so,
1651 * or if we're not in interactive mode and the request
1652 * buffer is empty. This still allows pipelined requests
1653 * to be sent in non-interactive mode.
1654 */
Willy Tarreau9b28e032012-10-12 23:49:43 +02001655 if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!si->applet.st1 && !req->buf->o)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001656 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001657 continue;
1658 }
1659
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001660 /* switch state back to GETREQ to read next requests */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001661 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001662 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001663 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001664
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001665 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST) && (si->applet.st0 != STAT_CLI_GETREQ)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001666 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
1667 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
Aman Guptaceafb4a2012-04-02 18:57:54 -07001668 /* Other side has closed, let's abort if we have no more processing to do
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001669 * and nothing more to consume. This is comparable to a broken pipe, so
1670 * we forward the close to the request side so that it flows upstream to
1671 * the client.
1672 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001673 si_shutw(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001674 }
1675
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001676 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (si->applet.st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001677 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
1678 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
1679 /* We have no more processing to do, and nothing more to send, and
1680 * the client side has closed. So we'll forward this state downstream
1681 * on the response buffer.
1682 */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001683 si_shutr(si);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001684 res->flags |= CF_READ_NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001685 }
1686
1687 /* update all other flags and resync with the other side */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001688 si_update(si);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001689
1690 /* we don't want to expire timeouts while we're processing requests */
1691 si->ib->rex = TICK_ETERNITY;
1692 si->ob->wex = TICK_ETERNITY;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001693
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001694 out:
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01001695 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 +02001696 __FUNCTION__, __LINE__,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001697 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 +02001698
1699 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1700 /* check that we have released everything then unregister */
1701 stream_int_unregister_handler(si);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001702 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001703}
1704
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001705/* This function dumps statistics onto the stream interface's read buffer.
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02001706 * The xprt_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau24955a12009-10-04 11:54:04 +02001707 * It returns 0 as long as it does not complete, non-zero upon completion.
1708 * Some states are not used but it makes the code more similar to other
1709 * functions which handle stats too.
Willy Tarreau3e76e722007-10-17 18:57:38 +02001710 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001711static int stats_dump_raw_to_buffer(struct stream_interface *si)
Willy Tarreau3e76e722007-10-17 18:57:38 +02001712{
Willy Tarreau3e76e722007-10-17 18:57:38 +02001713 struct proxy *px;
Willy Tarreaua8efd362008-01-03 10:19:15 +01001714 unsigned int up;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001715
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001716 chunk_reset(&trash);
Willy Tarreau3e76e722007-10-17 18:57:38 +02001717
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001718 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001719 case STAT_ST_INIT:
Willy Tarreau24955a12009-10-04 11:54:04 +02001720 /* the function had not been called yet */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001721 si->conn->xprt_st = STAT_ST_HEAD;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001722 /* fall through */
1723
Willy Tarreau295a8372011-03-10 11:25:07 +01001724 case STAT_ST_HEAD:
1725 if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001726 print_csv_header(&trash);
1727 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001728 return 0;
1729 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001730
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001731 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001732 /* fall through */
1733
Willy Tarreau295a8372011-03-10 11:25:07 +01001734 case STAT_ST_INFO:
Willy Tarreaua8efd362008-01-03 10:19:15 +01001735 up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau295a8372011-03-10 11:25:07 +01001736 if (si->applet.ctx.stats.flags & STAT_SHOW_INFO) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001737 chunk_appendf(&trash,
Willy Tarreaua8efd362008-01-03 10:19:15 +01001738 "Name: " PRODUCT_NAME "\n"
1739 "Version: " HAPROXY_VERSION "\n"
1740 "Release_date: " HAPROXY_DATE "\n"
1741 "Nbproc: %d\n"
1742 "Process_num: %d\n"
1743 "Pid: %d\n"
1744 "Uptime: %dd %dh%02dm%02ds\n"
1745 "Uptime_sec: %d\n"
1746 "Memmax_MB: %d\n"
1747 "Ulimit-n: %d\n"
1748 "Maxsock: %d\n"
1749 "Maxconn: %d\n"
Willy Tarreau91886b62011-09-07 14:38:31 +02001750 "Hard_maxconn: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +01001751 "Maxpipes: %d\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001752 "CurrConns: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +01001753 "PipesUsed: %d\n"
1754 "PipesFree: %d\n"
Willy Tarreau9cd552d2011-09-07 15:26:48 +02001755 "ConnRate: %d\n"
1756 "ConnRateLimit: %d\n"
1757 "MaxConnRate: %d\n"
William Lallemandd85f9172012-11-09 17:05:39 +01001758 "CompressBpsIn: %u\n"
1759 "CompressBpsOut: %u\n"
William Lallemand096f5542012-11-19 17:26:05 +01001760 "CompressBpsRateLim: %u\n"
William Lallemande3a7d992012-11-20 11:25:20 +01001761#ifdef USE_ZLIB
1762 "ZlibMemUsage: %ld\n"
1763 "MaxZlibMemUsage: %ld\n"
1764#endif
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001765 "Tasks: %d\n"
1766 "Run_queue: %d\n"
Willy Tarreau45a12512011-09-10 16:56:42 +02001767 "Idle_pct: %d\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001768 "node: %s\n"
1769 "description: %s\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001770 "",
1771 global.nbproc,
1772 relative_pid,
1773 pid,
1774 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
1775 up,
1776 global.rlimit_memmax,
1777 global.rlimit_nofile,
Willy Tarreau91886b62011-09-07 14:38:31 +02001778 global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001779 actconn, pipes_used, pipes_free,
Willy Tarreau9cd552d2011-09-07 15:26:48 +02001780 read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max,
William Lallemandd85f9172012-11-09 17:05:39 +01001781 read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out),
William Lallemand096f5542012-11-19 17:26:05 +01001782 global.comp_rate_lim,
William Lallemande3a7d992012-11-20 11:25:20 +01001783#ifdef USE_ZLIB
1784 zlib_used_memory, global.maxzlibmem,
1785#endif
Willy Tarreau45a12512011-09-10 16:56:42 +02001786 nb_tasks_cur, run_queue_cur, idle_pct,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001787 global.node, global.desc?global.desc:""
Willy Tarreaua8efd362008-01-03 10:19:15 +01001788 );
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001789 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001790 return 0;
1791 }
1792
Willy Tarreau295a8372011-03-10 11:25:07 +01001793 si->applet.ctx.stats.px = proxy;
1794 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
1795 si->applet.ctx.stats.sv = NULL;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001796 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001797 /* fall through */
1798
Willy Tarreau295a8372011-03-10 11:25:07 +01001799 case STAT_ST_LIST:
Willy Tarreau3e76e722007-10-17 18:57:38 +02001800 /* dump proxies */
Willy Tarreau295a8372011-03-10 11:25:07 +01001801 if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) {
1802 while (si->applet.ctx.stats.px) {
1803 px = si->applet.ctx.stats.px;
Willy Tarreau050536d2012-10-04 08:47:34 +02001804 /* skip the disabled proxies, global frontend and non-networked ones */
1805 if (px->state != PR_STSTOPPED && px->uuid > 0 &&
Willy Tarreau24955a12009-10-04 11:54:04 +02001806 (px->cap & (PR_CAP_FE | PR_CAP_BE))) {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001807 if (stats_dump_proxy(si, px, NULL) == 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001808 return 0;
Willy Tarreau24955a12009-10-04 11:54:04 +02001809 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001810
Willy Tarreau295a8372011-03-10 11:25:07 +01001811 si->applet.ctx.stats.px = px->next;
1812 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreaua8efd362008-01-03 10:19:15 +01001813 }
1814 /* here, we just have reached the last proxy */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001815 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001816
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001817 si->conn->xprt_st = STAT_ST_END;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001818 /* fall through */
1819
Willy Tarreau295a8372011-03-10 11:25:07 +01001820 case STAT_ST_END:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001821 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau0a464892008-12-07 18:30:00 +01001822 /* fall through */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001823
Willy Tarreau295a8372011-03-10 11:25:07 +01001824 case STAT_ST_FIN:
Willy Tarreau3e76e722007-10-17 18:57:38 +02001825 return 1;
1826
1827 default:
1828 /* unknown state ! */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001829 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau24955a12009-10-04 11:54:04 +02001830 return 1;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001831 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001832}
1833
1834
Cyril Bonté70be45d2010-10-12 00:14:35 +02001835/* We don't want to land on the posted stats page because a refresh will
1836 * repost the data. We don't want this to happen on accident so we redirect
1837 * the browse to the stats page with a GET.
1838 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001839static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri)
Cyril Bonté70be45d2010-10-12 00:14:35 +02001840{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001841 struct session *s = si->conn->xprt_ctx;
Cyril Bonté70be45d2010-10-12 00:14:35 +02001842
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001843 chunk_reset(&trash);
Cyril Bonté70be45d2010-10-12 00:14:35 +02001844
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001845 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001846 case STAT_ST_INIT:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001847 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02001848 "HTTP/1.0 303 See Other\r\n"
1849 "Cache-Control: no-cache\r\n"
1850 "Content-Type: text/plain\r\n"
1851 "Connection: close\r\n"
1852 "Location: %s;st=%s",
Cyril Bonté19979e12012-04-04 12:57:21 +02001853 uri->uri_prefix,
1854 ((si->applet.ctx.stats.st_code > STAT_STATUS_INIT) &&
1855 (si->applet.ctx.stats.st_code < STAT_STATUS_SIZE) &&
1856 stat_status_codes[si->applet.ctx.stats.st_code]) ?
1857 stat_status_codes[si->applet.ctx.stats.st_code] :
1858 stat_status_codes[STAT_STATUS_UNKN]);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001859 chunk_appendf(&trash, "\r\n\r\n");
Cyril Bonté70be45d2010-10-12 00:14:35 +02001860
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001861 if (bi_putchk(si->ib, &trash) == -1)
Cyril Bonté70be45d2010-10-12 00:14:35 +02001862 return 0;
1863
1864 s->txn.status = 303;
1865
1866 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1867 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1868 if (!(s->flags & SN_FINST_MASK))
1869 s->flags |= SN_FINST_R;
1870
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001871 si->conn->xprt_st = STAT_ST_FIN;
Cyril Bonté70be45d2010-10-12 00:14:35 +02001872 return 1;
1873 }
1874 return 1;
1875}
1876
1877
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001878/* This I/O handler runs as an applet embedded in a stream interface. It is
1879 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
Willy Tarreaubc4af052011-02-13 13:25:14 +01001880 * si->applet.st0 becomes non-zero once the transfer is finished. The handler
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001881 * automatically unregisters itself once transfer is complete.
1882 */
Willy Tarreaub24281b2011-02-13 13:16:36 +01001883static void http_stats_io_handler(struct stream_interface *si)
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001884{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001885 struct session *s = si->conn->xprt_ctx;
Willy Tarreau7421efb2012-07-02 15:11:27 +02001886 struct channel *req = si->ob;
1887 struct channel *res = si->ib;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001888
1889 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
1890 goto out;
1891
1892 /* check that the output is not closed */
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001893 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001894 si->applet.st0 = 1;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001895
Willy Tarreaubc4af052011-02-13 13:25:14 +01001896 if (!si->applet.st0) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02001897 if (s->txn.meth == HTTP_METH_POST) {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001898 if (stats_http_redir(si, s->be->uri_auth)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001899 si->applet.st0 = 1;
Willy Tarreau73b013b2012-05-21 16:31:45 +02001900 si_shutw(si);
Cyril Bonté70be45d2010-10-12 00:14:35 +02001901 }
1902 } else {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001903 if (stats_dump_http(si, s->be->uri_auth)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001904 si->applet.st0 = 1;
Willy Tarreau73b013b2012-05-21 16:31:45 +02001905 si_shutw(si);
Cyril Bonté70be45d2010-10-12 00:14:35 +02001906 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001907 }
1908 }
1909
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001910 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST))
Willy Tarreau73b013b2012-05-21 16:31:45 +02001911 si_shutw(si);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001912
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001913 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && si->applet.st0) {
Willy Tarreau73b013b2012-05-21 16:31:45 +02001914 si_shutr(si);
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02001915 res->flags |= CF_READ_NULL;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001916 }
1917
1918 /* update all other flags and resync with the other side */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001919 si_update(si);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001920
1921 /* we don't want to expire timeouts while we're processing requests */
1922 si->ib->rex = TICK_ETERNITY;
1923 si->ob->wex = TICK_ETERNITY;
1924
1925 out:
1926 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1927 /* check that we have released everything then unregister */
1928 stream_int_unregister_handler(si);
1929 }
1930}
1931
1932
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001933/* This function dumps statistics in HTTP format onto the stream interface's
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02001934 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001935 * properly set. It returns 0 if it had to stop writing data and an I/O is
1936 * needed, 1 if the dump is finished and the session must be closed, or -1
1937 * in case of any error.
Willy Tarreau91861262007-10-17 17:06:05 +02001938 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001939static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001940{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001941 struct session *s = si->conn->xprt_ctx;
Willy Tarreau7421efb2012-07-02 15:11:27 +02001942 struct channel *rep = si->ib;
Willy Tarreau91861262007-10-17 17:06:05 +02001943 struct proxy *px;
Willy Tarreau91861262007-10-17 17:06:05 +02001944 unsigned int up;
1945
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001946 chunk_reset(&trash);
Willy Tarreau91861262007-10-17 17:06:05 +02001947
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001948 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001949 case STAT_ST_INIT:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001950 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02001951 "HTTP/1.0 200 OK\r\n"
1952 "Cache-Control: no-cache\r\n"
1953 "Connection: close\r\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001954 "Content-Type: %s\r\n",
Willy Tarreau295a8372011-03-10 11:25:07 +01001955 (si->applet.ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html");
Willy Tarreau91861262007-10-17 17:06:05 +02001956
Willy Tarreau295a8372011-03-10 11:25:07 +01001957 if (uri->refresh > 0 && !(si->applet.ctx.stats.flags & STAT_NO_REFRESH))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001958 chunk_appendf(&trash, "Refresh: %d\r\n",
Willy Tarreau91861262007-10-17 17:06:05 +02001959 uri->refresh);
1960
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001961 chunk_appendf(&trash, "\r\n");
Willy Tarreau91861262007-10-17 17:06:05 +02001962
1963 s->txn.status = 200;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001964 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau56a560a2009-09-22 19:27:35 +02001965 return 0;
1966
Willy Tarreau91861262007-10-17 17:06:05 +02001967 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1968 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1969 if (!(s->flags & SN_FINST_MASK))
1970 s->flags |= SN_FINST_R;
1971
1972 if (s->txn.meth == HTTP_METH_HEAD) {
1973 /* that's all we return in case of HEAD request */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001974 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001975 return 1;
1976 }
1977
Willy Tarreauf2943dc2012-10-26 20:10:28 +02001978 si->conn->xprt_st = STAT_ST_HEAD; /* let's start producing data */
Willy Tarreau91861262007-10-17 17:06:05 +02001979 /* fall through */
1980
Willy Tarreau295a8372011-03-10 11:25:07 +01001981 case STAT_ST_HEAD:
1982 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001983 /* WARNING! This must fit in the first buffer !!! */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01001984 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001985 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
1986 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001987 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001988 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
1989 "<style type=\"text/css\"><!--\n"
1990 "body {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001991 " font-family: arial, helvetica, sans-serif;"
Willy Tarreau91861262007-10-17 17:06:05 +02001992 " font-size: 12px;"
1993 " font-weight: normal;"
1994 " color: black;"
1995 " background: white;"
1996 "}\n"
1997 "th,td {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001998 " font-size: 10px;"
Willy Tarreau91861262007-10-17 17:06:05 +02001999 "}\n"
2000 "h1 {"
Willy Tarreauda6721b2009-07-15 10:07:05 +02002001 " font-size: x-large;"
Willy Tarreau91861262007-10-17 17:06:05 +02002002 " margin-bottom: 0.5em;"
2003 "}\n"
2004 "h2 {"
2005 " font-family: helvetica, arial;"
2006 " font-size: x-large;"
2007 " font-weight: bold;"
2008 " font-style: italic;"
2009 " color: #6020a0;"
2010 " margin-top: 0em;"
2011 " margin-bottom: 0em;"
2012 "}\n"
2013 "h3 {"
2014 " font-family: helvetica, arial;"
2015 " font-size: 16px;"
2016 " font-weight: bold;"
2017 " color: #b00040;"
2018 " background: #e8e8d0;"
2019 " margin-top: 0em;"
2020 " margin-bottom: 0em;"
2021 "}\n"
2022 "li {"
2023 " margin-top: 0.25em;"
2024 " margin-right: 2em;"
2025 "}\n"
2026 ".hr {margin-top: 0.25em;"
2027 " border-color: black;"
2028 " border-bottom-style: solid;"
2029 "}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002030 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002031 ".total {background: #20D0D0;color: #ffff80;}\n"
2032 ".frontend {background: #e8e8d0;}\n"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002033 ".socket {background: #d0d0d0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002034 ".backend {background: #e8e8d0;}\n"
2035 ".active0 {background: #ff9090;}\n"
2036 ".active1 {background: #ffd020;}\n"
2037 ".active2 {background: #ffffa0;}\n"
2038 ".active3 {background: #c0ffc0;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002039 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
2040 ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
2041 ".active6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002042 ".backup0 {background: #ff9090;}\n"
2043 ".backup1 {background: #ff80ff;}\n"
2044 ".backup2 {background: #c060ff;}\n"
2045 ".backup3 {background: #b0d0ff;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002046 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
2047 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
2048 ".backup6 {background: #e0e0e0;}\n"
Cyril Bontécd19e512010-01-31 22:34:03 +01002049 ".maintain {background: #c07820;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +02002050 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002051 "\n"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002052 "a.px:link {color: #ffff40; text-decoration: none;}"
2053 "a.px:visited {color: #ffff40; text-decoration: none;}"
2054 "a.px:hover {color: #ffffff; text-decoration: none;}"
2055 "a.lfsb:link {color: #000000; text-decoration: none;}"
2056 "a.lfsb:visited {color: #000000; text-decoration: none;}"
2057 "a.lfsb:hover {color: #505050; text-decoration: none;}"
2058 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002059 "table.tbl { border-collapse: collapse; border-style: none;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002060 "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"
2061 "table.tbl td.ac { text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002062 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002063 "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 +02002064 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002065 "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 +02002066 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002067 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
2068 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
2069 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
Willy Tarreaue0454092010-02-26 12:29:07 +01002070 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002071 "-->\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02002072 "</style></head>\n",
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002073 (uri->flags&ST_SHNODE) ? " on " : "",
2074 (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02002075 );
Willy Tarreau55bb8452007-10-17 18:44:57 +02002076 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002077 print_csv_header(&trash);
Willy Tarreau55bb8452007-10-17 18:44:57 +02002078 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002079 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02002080 return 0;
2081
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002082 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau91861262007-10-17 17:06:05 +02002083 /* fall through */
2084
Willy Tarreau295a8372011-03-10 11:25:07 +01002085 case STAT_ST_INFO:
Willy Tarreau91861262007-10-17 17:06:05 +02002086 up = (now.tv_sec - start_date.tv_sec);
2087
2088 /* WARNING! this has to fit the first packet too.
2089 * We are around 3.5 kB, add adding entries will
2090 * become tricky if we want to support 4kB buffers !
2091 */
Willy Tarreau295a8372011-03-10 11:25:07 +01002092 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002093 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002094 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
2095 PRODUCT_NAME "%s</a></h1>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002096 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002097 "<hr width=\"100%%\" class=\"hr\">\n"
2098 "<h3>&gt; General process information</h3>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002099 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01002100 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002101 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002102 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
2103 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
Willy Tarreau9cd552d2011-09-07 15:26:48 +02002104 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n"
Willy Tarreau45a12512011-09-10 16:56:42 +02002105 "Running tasks: %d/%d; idle = %d %%<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002106 "</td><td align=\"center\" nowrap>\n"
2107 "<table class=\"lgd\"><tr>\n"
2108 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
2109 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
2110 "</tr><tr>\n"
2111 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
2112 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
2113 "</tr><tr>\n"
2114 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
2115 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
2116 "</tr><tr>\n"
2117 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002118 "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
Cyril Bontécd19e512010-01-31 22:34:03 +01002119 "</tr><tr>\n"
2120 "<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 +02002121 "</tr></table>\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01002122 "Note: UP with load-balancing disabled is reported as \"NOLB\"."
Willy Tarreau91861262007-10-17 17:06:05 +02002123 "</td>"
2124 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2125 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
2126 "",
2127 (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002128 pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
2129 (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
2130 pid, relative_pid, global.nbproc,
Willy Tarreau91861262007-10-17 17:06:05 +02002131 up / 86400, (up % 86400) / 3600,
2132 (up % 3600) / 60, (up % 60),
2133 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
2134 global.rlimit_memmax ? " MB" : "",
2135 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +01002136 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreau9cd552d2011-09-07 15:26:48 +02002137 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
Willy Tarreau45a12512011-09-10 16:56:42 +02002138 run_queue_cur, nb_tasks_cur, idle_pct
Willy Tarreau91861262007-10-17 17:06:05 +02002139 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002140
Willy Tarreau295a8372011-03-10 11:25:07 +01002141 if (si->applet.ctx.stats.flags & STAT_HIDE_DOWN)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002142 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002143 "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
2144 uri->uri_prefix,
2145 "",
Willy Tarreau295a8372011-03-10 11:25:07 +01002146 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002147 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002148 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002149 "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
2150 uri->uri_prefix,
2151 ";up",
Willy Tarreau295a8372011-03-10 11:25:07 +01002152 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02002153
Willy Tarreau55bb8452007-10-17 18:44:57 +02002154 if (uri->refresh > 0) {
Willy Tarreau295a8372011-03-10 11:25:07 +01002155 if (si->applet.ctx.stats.flags & STAT_NO_REFRESH)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002156 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002157 "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
2158 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01002159 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02002160 "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002161 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002162 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002163 "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
2164 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01002165 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02002166 ";norefresh");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002167 }
Willy Tarreau91861262007-10-17 17:06:05 +02002168
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002169 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002170 "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
2171 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01002172 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2173 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02002174
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002175 chunk_appendf(&trash,
Willy Tarreau5031e6a2007-10-18 11:05:48 +02002176 "<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
2177 uri->uri_prefix,
2178 (uri->refresh > 0) ? ";norefresh" : "");
2179
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002180 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002181 "</ul></td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002182 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
Adrian Bridgettafdb6e52012-03-19 23:36:42 +00002183 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002184 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
2185 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
2186 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
2187 "</ul>"
2188 "</td>"
2189 "</tr></table>\n"
2190 ""
2191 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002192
Willy Tarreau295a8372011-03-10 11:25:07 +01002193 if (si->applet.ctx.stats.st_code) {
Cyril Bonté19979e12012-04-04 12:57:21 +02002194 switch (si->applet.ctx.stats.st_code) {
2195 case STAT_STATUS_DONE:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002196 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002197 "<p><div class=active3>"
2198 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2199 "Action processed successfully."
2200 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002201 break;
2202 case STAT_STATUS_NONE:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002203 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002204 "<p><div class=active2>"
2205 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2206 "Nothing has changed."
2207 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002208 break;
2209 case STAT_STATUS_PART:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002210 chunk_appendf(&trash,
Cyril Bontécf8d9ae2012-04-04 12:57:18 +02002211 "<p><div class=active2>"
2212 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2213 "Action partially processed.<br>"
2214 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
2215 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002216 break;
2217 case STAT_STATUS_ERRP:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002218 chunk_appendf(&trash,
Cyril Bontécf8d9ae2012-04-04 12:57:18 +02002219 "<p><div class=active0>"
2220 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2221 "Action not processed because of invalid parameters."
2222 "<ul>"
2223 "<li>The action is maybe unknown.</li>"
2224 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
2225 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
2226 "</ul>"
2227 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002228 break;
2229 case STAT_STATUS_EXCD:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002230 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002231 "<p><div class=active0>"
2232 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2233 "<b>Action not processed : the buffer couldn't store all the data.<br>"
2234 "You should retry with less servers at a time.</b>"
2235 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002236 break;
2237 case STAT_STATUS_DENY:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002238 chunk_appendf(&trash,
Cyril Bonté474be412010-10-12 00:14:36 +02002239 "<p><div class=active0>"
2240 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2241 "<b>Action denied.</b>"
2242 "</div>\n", uri->uri_prefix);
Cyril Bonté19979e12012-04-04 12:57:21 +02002243 break;
2244 default:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002245 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002246 "<p><div class=active6>"
2247 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2248 "Unexpected result."
2249 "</div>\n", uri->uri_prefix);
2250 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002251 chunk_appendf(&trash,"<p>\n");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002252 }
2253
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002254 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002255 return 0;
2256 }
Willy Tarreau91861262007-10-17 17:06:05 +02002257
Willy Tarreau295a8372011-03-10 11:25:07 +01002258 si->applet.ctx.stats.px = proxy;
2259 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002260 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau91861262007-10-17 17:06:05 +02002261 /* fall through */
2262
Willy Tarreau295a8372011-03-10 11:25:07 +01002263 case STAT_ST_LIST:
Willy Tarreau91861262007-10-17 17:06:05 +02002264 /* dump proxies */
Willy Tarreau295a8372011-03-10 11:25:07 +01002265 while (si->applet.ctx.stats.px) {
Willy Tarreau9b28e032012-10-12 23:49:43 +02002266 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002267 return 0;
Willy Tarreau295a8372011-03-10 11:25:07 +01002268 px = si->applet.ctx.stats.px;
Willy Tarreau050536d2012-10-04 08:47:34 +02002269 /* skip the disabled proxies, global frontend and non-networked ones */
2270 if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002271 if (stats_dump_proxy(si, px, uri) == 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002272 return 0;
2273
Willy Tarreau295a8372011-03-10 11:25:07 +01002274 si->applet.ctx.stats.px = px->next;
2275 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreau91861262007-10-17 17:06:05 +02002276 }
2277 /* here, we just have reached the last proxy */
2278
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002279 si->conn->xprt_st = STAT_ST_END;
Willy Tarreau91861262007-10-17 17:06:05 +02002280 /* fall through */
2281
Willy Tarreau295a8372011-03-10 11:25:07 +01002282 case STAT_ST_END:
2283 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002284 chunk_appendf(&trash, "</body></html>\n");
2285 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002286 return 0;
2287 }
Willy Tarreau91861262007-10-17 17:06:05 +02002288
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002289 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02002290 /* fall through */
2291
Willy Tarreau295a8372011-03-10 11:25:07 +01002292 case STAT_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02002293 return 1;
2294
2295 default:
2296 /* unknown state ! */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002297 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02002298 return -1;
2299 }
2300}
2301
2302
2303/*
2304 * Dumps statistics for a proxy.
2305 * Returns 0 if it had to stop dumping data because of lack of buffer space,
2306 * ot non-zero if everything completed.
2307 */
Simon Horman9bd2c732011-06-15 15:18:44 +09002308static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02002309{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02002310 struct session *s = si->conn->xprt_ctx;
Willy Tarreau7421efb2012-07-02 15:11:27 +02002311 struct channel *rep = si->ib;
Willy Tarreau44267702011-10-28 15:35:33 +02002312 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002313 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02002314
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002315 chunk_reset(&trash);
Willy Tarreau91861262007-10-17 17:06:05 +02002316
Willy Tarreau295a8372011-03-10 11:25:07 +01002317 switch (si->applet.ctx.stats.px_st) {
2318 case STAT_PX_ST_INIT:
Willy Tarreau91861262007-10-17 17:06:05 +02002319 /* we are on a new proxy */
2320
2321 if (uri && uri->scope) {
2322 /* we have a limited scope, we have to check the proxy name */
2323 struct stat_scope *scope;
2324 int len;
2325
2326 len = strlen(px->id);
2327 scope = uri->scope;
2328
2329 while (scope) {
2330 /* match exact proxy name */
2331 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
2332 break;
2333
2334 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02002335 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02002336 break;
2337 scope = scope->next;
2338 }
2339
2340 /* proxy name not found : don't dump anything */
2341 if (scope == NULL)
2342 return 1;
2343 }
2344
Willy Tarreau295a8372011-03-10 11:25:07 +01002345 if ((si->applet.ctx.stats.flags & STAT_BOUND) && (si->applet.ctx.stats.iid != -1) &&
2346 (px->uuid != si->applet.ctx.stats.iid))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002347 return 1;
2348
Willy Tarreau295a8372011-03-10 11:25:07 +01002349 si->applet.ctx.stats.px_st = STAT_PX_ST_TH;
Willy Tarreau91861262007-10-17 17:06:05 +02002350 /* fall through */
2351
Willy Tarreau295a8372011-03-10 11:25:07 +01002352 case STAT_PX_ST_TH:
2353 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
2354 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002355 /* A form to enable/disable this proxy servers */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002356 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002357 "<form action=\"%s\" method=\"post\">",
2358 uri->uri_prefix);
2359 }
2360
Willy Tarreau55bb8452007-10-17 18:44:57 +02002361 /* print a new table */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002362 chunk_appendf(&trash,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002363 "<table class=\"tbl\" width=\"100%%\">\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002364 "<tr class=\"titre\">"
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002365 "<th class=\"pxname\" width=\"10%%\"");
2366
2367 if (uri->flags&ST_SHLGNDS) {
2368 /* cap, mode, id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002369 chunk_appendf(&trash, " title=\"cap: %s, mode: %s, id: %d",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002370 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
2371 px->uuid);
2372
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002373 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002374 }
2375
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002376 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002377 ">%s<a name=\"%s\"></a>"
2378 "<a class=px href=\"#%s\">%s</a>%s</th>"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002379 "<th class=\"%s\" width=\"90%%\">%s</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002380 "</tr>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002381 "</table>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002382 "<table class=\"tbl\" width=\"100%%\">\n"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002383 "<tr class=\"titre\">",
2384 (uri->flags & ST_SHLGNDS)?"<u>":"",
2385 px->id, px->id, px->id,
2386 (uri->flags & ST_SHLGNDS)?"</u>":"",
2387 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
2388
Willy Tarreau295a8372011-03-10 11:25:07 +01002389 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002390 /* Column heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002391 chunk_appendf(&trash, "<th rowspan=2 width=1></th>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002392 }
2393
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002394 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002395 "<th rowspan=2></th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002396 "<th colspan=3>Queue</th>"
2397 "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002398 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002399 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002400 "<th colspan=9>Server</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002401 "</tr>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002402 "<tr class=\"titre\">"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002403 "<th>Cur</th><th>Max</th><th>Limit</th>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002404 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002405 "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002406 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002407 "<th>Resp</th><th>Retr</th><th>Redis</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002408 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002409 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
2410 "<th>Thrtle</th>\n"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002411 "</tr>");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002412
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002413 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002414 return 0;
2415 }
Willy Tarreau91861262007-10-17 17:06:05 +02002416
Willy Tarreau295a8372011-03-10 11:25:07 +01002417 si->applet.ctx.stats.px_st = STAT_PX_ST_FE;
Willy Tarreau91861262007-10-17 17:06:05 +02002418 /* fall through */
2419
Willy Tarreau295a8372011-03-10 11:25:07 +01002420 case STAT_PX_ST_FE:
Willy Tarreau91861262007-10-17 17:06:05 +02002421 /* print the frontend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002422 if ((px->cap & PR_CAP_FE) &&
Willy Tarreau295a8372011-03-10 11:25:07 +01002423 (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_FE)))) {
2424 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002425 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002426 /* name, queue */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002427 "<tr class=\"frontend\">");
2428
Willy Tarreau295a8372011-03-10 11:25:07 +01002429 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002430 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002431 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002432 }
2433
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002434 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002435 "<td class=ac>"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002436 "<a name=\"%s/Frontend\"></a>"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002437 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
2438 "<td colspan=3></td>"
Willy Tarreaub44939a2010-02-26 11:35:39 +01002439 "",
2440 px->id, px->id);
2441
2442 if (px->mode == PR_MODE_HTTP) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002443 chunk_appendf(&trash,
Willy Tarreaub44939a2010-02-26 11:35:39 +01002444 /* sessions rate : current, max, limit */
Willy Tarreaue0454092010-02-26 12:29:07 +01002445 "<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 +01002446 "",
2447 read_freq_ctr(&px->fe_req_per_sec),
2448 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002449 px->fe_counters.p.http.rps_max,
2450 U2H1(px->fe_counters.sps_max),
Willy Tarreaub44939a2010-02-26 11:35:39 +01002451 LIM2A2(px->fe_sps_lim, "-"));
2452 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002453 chunk_appendf(&trash,
Willy Tarreaub44939a2010-02-26 11:35:39 +01002454 /* sessions rate : current, max, limit */
2455 "<td>%s</td><td>%s</td><td>%s</td>"
2456 "",
2457 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002458 U2H1(px->fe_counters.sps_max), LIM2A2(px->fe_sps_lim, "-"));
Willy Tarreaub44939a2010-02-26 11:35:39 +01002459 }
2460
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002461 chunk_appendf(&trash,
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002462 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002463 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002464 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002465 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002466 U2H3(px->feconn), U2H4(px->fe_counters.conn_max), U2H5(px->maxconn));
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002467
2468 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2469 if (px->mode == PR_MODE_HTTP) {
2470 int i;
2471
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002472 chunk_appendf(&trash, " title=\"%lld requests:", px->fe_counters.p.http.cum_req);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002473
2474 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002475 chunk_appendf(&trash, " %dxx=%lld,", i, px->fe_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002476
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002477 chunk_appendf(&trash, " other=%lld,", px->fe_counters.p.http.rsp[0]);
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002478 chunk_appendf(&trash, " compressed=%lld (%d%%)",
2479 px->fe_counters.p.http.comp_rsp,
Willy Tarreau78bbeb42012-11-26 16:44:48 +01002480 px->fe_counters.p.http.rsp[2] ?
Willy Tarreau5730c682012-11-26 14:13:09 +01002481 (int)(100*px->fe_counters.p.http.comp_rsp/px->fe_counters.p.http.rsp[2]) : 0);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002482 chunk_appendf(&trash, " intercepted=%lld\"", px->fe_counters.intercepted_req);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002483 }
2484
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002485 chunk_appendf(&trash,
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002486 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002487 ">%s%s%s</td><td></td>"
Willy Tarreau55058a72012-11-21 08:27:21 +01002488 /* bytes : in */
2489 "<td>%s</td><td"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002490 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002491 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002492 U2H6(px->fe_counters.cum_sess),
Willy Tarreaue0454092010-02-26 12:29:07 +01002493 (px->mode == PR_MODE_HTTP)?"</u>":"",
Willy Tarreau55058a72012-11-21 08:27:21 +01002494 U2H7(px->fe_counters.bytes_in));
2495
2496 /* compression stats (via td title): comp_in, comp_out, comp_byp */
Willy Tarreauf149d8f2012-11-24 14:06:49 +01002497 chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld savings=%d%%\"",
2498 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp,
2499 px->fe_counters.comp_in ?
2500 (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 +02002501
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002502 chunk_appendf(&trash,
Willy Tarreau55058a72012-11-21 08:27:21 +01002503 /* bytes: out */
2504 ">%s%s%s</td>"
2505 "",
2506 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"",
2507 U2H0(px->fe_counters.bytes_out),
2508 (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":"");
2509
2510 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002511 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002512 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002513 /* errors : request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002514 "<td>%s</td><td></td><td></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002515 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002516 "<td></td><td></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002517 /* server status : reflect frontend status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002518 "<td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002519 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002520 "<td class=ac colspan=8></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +02002521 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002522 U2H0(px->fe_counters.denied_req), U2H1(px->fe_counters.denied_resp),
2523 U2H2(px->fe_counters.failed_req),
Willy Tarreau562515c2011-07-25 08:11:52 +02002524 px->state == PR_STREADY ? "OPEN" :
2525 px->state == PR_STFULL ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002526 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002527 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002528 /* pxid, name, queue cur, queue max, */
2529 "%s,FRONTEND,,,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002530 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002531 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002532 /* bytes : in, out */
2533 "%lld,%lld,"
2534 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002535 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002536 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002537 "%lld,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002538 /* warnings: retries, redispatches */
2539 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002540 /* server status : reflect frontend status */
2541 "%s,"
2542 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002543 ",,,,,,,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002544 /* pid, iid, sid, throttle, lbtot, tracked, type */
2545 "%d,%d,0,,,,%d,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002546 /* rate, rate_lim, rate_max */
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002547 "%u,%u,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002548 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002549 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02002550 px->id,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002551 px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess,
2552 px->fe_counters.bytes_in, px->fe_counters.bytes_out,
2553 px->fe_counters.denied_req, px->fe_counters.denied_resp,
2554 px->fe_counters.failed_req,
Willy Tarreau562515c2011-07-25 08:11:52 +02002555 px->state == PR_STREADY ? "OPEN" :
2556 px->state == PR_STFULL ? "FULL" : "STOP",
Willy Tarreau7f062c42009-03-05 18:43:00 +01002557 relative_pid, px->uuid, STATS_TYPE_FE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002558 read_freq_ctr(&px->fe_sess_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002559 px->fe_sps_lim, px->fe_counters.sps_max);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002560
2561 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2562 if (px->mode == PR_MODE_HTTP) {
2563 int i;
2564
2565 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002566 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002567
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002568 chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002569 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002570 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002571 }
2572
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002573 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002574 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002575
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002576 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002577 chunk_appendf(&trash, "%u,%u,%lld,",
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002578 read_freq_ctr(&px->fe_req_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002579 px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req);
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002580
Willy Tarreauae526782010-03-04 20:34:23 +01002581 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002582 chunk_appendf(&trash, ",,");
Willy Tarreauae526782010-03-04 20:34:23 +01002583
Willy Tarreau55058a72012-11-21 08:27:21 +01002584 /* compression: in, out, bypassed */
2585 chunk_appendf(&trash, "%lld,%lld,%lld,",
2586 px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp);
2587
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002588 /* compression: comp_rsp */
2589 chunk_appendf(&trash, "%lld,",
2590 px->fe_counters.p.http.comp_rsp);
2591
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002592 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002593 chunk_appendf(&trash, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002594 }
Willy Tarreau91861262007-10-17 17:06:05 +02002595
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002596 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02002597 return 0;
2598 }
2599
Willy Tarreau4348fad2012-09-20 16:48:07 +02002600 si->applet.ctx.stats.l = px->conf.listeners.n;
Willy Tarreau295a8372011-03-10 11:25:07 +01002601 si->applet.ctx.stats.px_st = STAT_PX_ST_LI;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002602 /* fall through */
2603
Willy Tarreau295a8372011-03-10 11:25:07 +01002604 case STAT_PX_ST_LI:
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002605 /* stats.l has been initialized above */
Willy Tarreau4348fad2012-09-20 16:48:07 +02002606 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 +02002607 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002608 return 0;
2609
Willy Tarreau4348fad2012-09-20 16:48:07 +02002610 l = LIST_ELEM(si->applet.ctx.stats.l, struct listener *, by_fe);
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002611 if (!l->counters)
2612 continue;
2613
Willy Tarreau295a8372011-03-10 11:25:07 +01002614 if (si->applet.ctx.stats.flags & STAT_BOUND) {
2615 if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SO)))
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002616 break;
2617
Willy Tarreau295a8372011-03-10 11:25:07 +01002618 if (si->applet.ctx.stats.sid != -1 && l->luid != si->applet.ctx.stats.sid)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002619 continue;
2620 }
2621
Willy Tarreau295a8372011-03-10 11:25:07 +01002622 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002623 chunk_appendf(&trash, "<tr class=socket>");
Willy Tarreau295a8372011-03-10 11:25:07 +01002624 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002625 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002626 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002627 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002628 chunk_appendf(&trash, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002629
2630 if (uri->flags&ST_SHLGNDS) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02002631 char str[INET6_ADDRSTRLEN];
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002632 int port;
2633
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002634 chunk_appendf(&trash, " title=\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002635
Willy Tarreau631f01c2011-09-05 00:36:48 +02002636 port = get_host_port(&l->addr);
2637 switch (addr_to_str(&l->addr, str, sizeof(str))) {
2638 case AF_INET:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002639 chunk_appendf(&trash, "IPv4: %s:%d, ", str, port);
Willy Tarreau631f01c2011-09-05 00:36:48 +02002640 break;
2641 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002642 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port);
Willy Tarreau631f01c2011-09-05 00:36:48 +02002643 break;
2644 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002645 chunk_appendf(&trash, "unix, ");
Willy Tarreau631f01c2011-09-05 00:36:48 +02002646 break;
2647 case -1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002648 chunk_appendf(&trash, "(%s), ", strerror(errno));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002649 break;
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002650 }
2651
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002652 /* id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002653 chunk_appendf(&trash, "id: %d\"", l->luid);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002654 }
2655
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002656 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002657 /* name, queue */
Willy Tarreaue0454092010-02-26 12:29:07 +01002658 ">%s<a name=\"%s/+%s\"></a>"
2659 "<a class=lfsb href=\"#%s/+%s\">%s</a></td><td colspan=3>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002660 /* sessions rate: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002661 "<td colspan=3>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002662 /* sessions: current, max, limit, total, lbtot */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002663 "<td>%s</td><td>%s</td><td>%s</td>"
2664 "<td>%s</td><td>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002665 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002666 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002667 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002668 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki2ec025d2010-01-04 11:33:32 +01002669 px->id, l->name, px->id, l->name, l->name,
Willy Tarreaue0454092010-02-26 12:29:07 +01002670 (uri->flags & ST_SHLGNDS)?"</u>":"",
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002671 U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn),
2672 U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out));
2673
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002674 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002675 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002676 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002677 /* errors: request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002678 "<td>%s</td><td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002679 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002680 "<td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002681 /* server status: reflect listener status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002682 "<td class=ac>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002683 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002684 "<td class=ac colspan=8></td></tr>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002685 "",
2686 U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp),
2687 U2H2(l->counters->failed_req),
Willy Tarreaua17c2d92011-07-25 08:16:20 +02002688 (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002689 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002690 chunk_appendf(&trash,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002691 /* pxid, name, queue cur, queue max, */
2692 "%s,%s,,,"
2693 /* sessions: current, max, limit, total */
2694 "%d,%d,%d,%lld,"
2695 /* bytes: in, out */
2696 "%lld,%lld,"
2697 /* denied: req, resp */
2698 "%lld,%lld,"
2699 /* errors: request, connect, response */
2700 "%lld,,,"
2701 /* warnings: retries, redispatches */
2702 ",,"
2703 /* server status: reflect listener status */
2704 "%s,"
2705 /* rest of server: nothing */
2706 ",,,,,,,,"
2707 /* pid, iid, sid, throttle, lbtot, tracked, type */
2708 "%d,%d,%d,,,,%d,"
2709 /* rate, rate_lim, rate_max */
2710 ",,,"
2711 /* check_status, check_code, check_duration */
2712 ",,,"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002713 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2714 ",,,,,,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002715 /* failed health analyses */
2716 ","
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002717 /* requests : req_rate, req_rate_max, req_tot, */
2718 ",,,"
Willy Tarreauae526782010-03-04 20:34:23 +01002719 /* errors: cli_aborts, srv_aborts */
2720 ",,"
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002721 /* compression: in, out, bypassed, comp_rsp */
2722 ",,,,"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002723 "\n",
2724 px->id, l->name,
2725 l->nbconn, l->counters->conn_max,
2726 l->maxconn, l->counters->cum_conn,
2727 l->counters->bytes_in, l->counters->bytes_out,
2728 l->counters->denied_req, l->counters->denied_resp,
2729 l->counters->failed_req,
2730 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
2731 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
2732 }
2733
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002734 if (bi_putchk(rep, &trash) == -1)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002735 return 0;
2736 }
2737
Willy Tarreau295a8372011-03-10 11:25:07 +01002738 si->applet.ctx.stats.sv = px->srv; /* may be NULL */
2739 si->applet.ctx.stats.px_st = STAT_PX_ST_SV;
Willy Tarreau91861262007-10-17 17:06:05 +02002740 /* fall through */
2741
Willy Tarreau295a8372011-03-10 11:25:07 +01002742 case STAT_PX_ST_SV:
Willy Tarreau91861262007-10-17 17:06:05 +02002743 /* stats.sv has been initialized above */
Willy Tarreau295a8372011-03-10 11:25:07 +01002744 for (; si->applet.ctx.stats.sv != NULL; si->applet.ctx.stats.sv = sv->next) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002745 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 +02002746
Willy Tarreau9b28e032012-10-12 23:49:43 +02002747 if (buffer_almost_full(rep->buf))
Willy Tarreau4e33d862009-10-11 23:35:10 +02002748 return 0;
2749
Willy Tarreau295a8372011-03-10 11:25:07 +01002750 sv = si->applet.ctx.stats.sv;
Willy Tarreau91861262007-10-17 17:06:05 +02002751
Willy Tarreau295a8372011-03-10 11:25:07 +01002752 if (si->applet.ctx.stats.flags & STAT_BOUND) {
2753 if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SV)))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002754 break;
2755
Willy Tarreau295a8372011-03-10 11:25:07 +01002756 if (si->applet.ctx.stats.sid != -1 && sv->puid != si->applet.ctx.stats.sid)
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002757 continue;
2758 }
2759
Willy Tarreau44267702011-10-28 15:35:33 +02002760 if (sv->track)
2761 svs = sv->track;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002762 else
2763 svs = sv;
2764
Willy Tarreau91861262007-10-17 17:06:05 +02002765 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002766 if (!(svs->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +01002767 sv_state = 6;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002768 else if (svs->state & SRV_RUNNING) {
2769 if (svs->health == svs->rise + svs->fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02002770 sv_state = 3; /* UP */
2771 else
2772 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01002773
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002774 if (svs->state & SRV_GOINGDOWN)
Willy Tarreau2ea81932007-11-30 12:04:38 +01002775 sv_state += 2;
2776 }
Willy Tarreau91861262007-10-17 17:06:05 +02002777 else
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002778 if (svs->health)
Willy Tarreau91861262007-10-17 17:06:05 +02002779 sv_state = 1; /* going up */
2780 else
2781 sv_state = 0; /* DOWN */
2782
Willy Tarreau295a8372011-03-10 11:25:07 +01002783 if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (si->applet.ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02002784 /* do not report servers which are DOWN */
Willy Tarreau295a8372011-03-10 11:25:07 +01002785 si->applet.ctx.stats.sv = sv->next;
Willy Tarreau91861262007-10-17 17:06:05 +02002786 continue;
2787 }
2788
Willy Tarreau295a8372011-03-10 11:25:07 +01002789 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002790 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
2791 "UP %d/%d &darr;", "UP",
2792 "NOLB %d/%d &darr;", "NOLB",
2793 "<i>no check</i>" };
Cyril Bonté0dae5852010-02-03 00:26:28 +01002794 if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002795 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01002796 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002797 "<tr class=\"maintain\">"
Cyril Bontécd19e512010-01-31 22:34:03 +01002798 );
2799 }
2800 else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002801 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01002802 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002803 "<tr class=\"%s%d\">",
Cyril Bontécd19e512010-01-31 22:34:03 +01002804 (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state);
2805 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002806
Willy Tarreau295a8372011-03-10 11:25:07 +01002807 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002808 chunk_appendf(&trash,
Cyril Bonté474be412010-10-12 00:14:36 +02002809 "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
2810 sv->id);
2811 }
2812
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002813 chunk_appendf(&trash, "<td class=ac");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002814
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002815 if (uri->flags&ST_SHLGNDS) {
2816 char str[INET6_ADDRSTRLEN];
2817
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002818 chunk_appendf(&trash, " title=\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002819
Willy Tarreau631f01c2011-09-05 00:36:48 +02002820 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
David du Colombier6f5ccb12011-03-10 22:26:24 +01002821 case AF_INET:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002822 chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr));
David du Colombier6f5ccb12011-03-10 22:26:24 +01002823 break;
2824 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002825 chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002826 break;
2827 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002828 chunk_appendf(&trash, "unix, ");
Willy Tarreau631f01c2011-09-05 00:36:48 +02002829 break;
2830 case -1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002831 chunk_appendf(&trash, "(%s), ", strerror(errno));
Willy Tarreau631f01c2011-09-05 00:36:48 +02002832 break;
2833 default: /* address family not supported */
David du Colombier6f5ccb12011-03-10 22:26:24 +01002834 break;
2835 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002836
2837 /* id */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002838 chunk_appendf(&trash, "id: %d", sv->puid);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002839
2840 /* cookie */
2841 if (sv->cookie) {
2842 struct chunk src;
2843
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002844 chunk_appendf(&trash, ", cookie: '");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002845
2846 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002847 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002848
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002849 chunk_appendf(&trash, "'");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002850 }
2851
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002852 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002853 }
2854
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002855 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002856 ">%s<a name=\"%s/%s\"></a>"
2857 "<a class=lfsb href=\"#%s/%s\">%s</a>%s</td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002858 /* queue : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002859 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002860 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002861 "<td>%s</td><td>%s</td><td></td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002862 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002863 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002864 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002865 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002866 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002867 px->id, sv->id, px->id, sv->id, sv->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01002868 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002869 U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"),
2870 U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max),
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002871 U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-"));
2872
2873 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2874 if (px->mode == PR_MODE_HTTP) {
2875 int i;
2876
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002877 chunk_appendf(&trash, " title=\"rsp codes:");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002878
2879 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002880 chunk_appendf(&trash, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002881
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002882 chunk_appendf(&trash, " other=%lld\"", sv->counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002883 }
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002884
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002885 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002886 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002887 ">%s%s%s</td><td>%s</td>",
2888 (px->mode == PR_MODE_HTTP)?"<u>":"",
2889 U2H0(sv->counters.cum_sess),
2890 (px->mode == PR_MODE_HTTP)?"</u>":"",
2891 U2H1(sv->counters.cum_lbconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002892
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002893 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002894 /* bytes : in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002895 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002896 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002897 "<td></td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01002898 /* errors : request, connect */
2899 "<td></td><td>%s</td>"
2900 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002901 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002902 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002903 "<td>%lld</td><td>%lld</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002904 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002905 U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out),
2906 U2H2(sv->counters.failed_secu),
Willy Tarreauae526782010-03-04 20:34:23 +01002907 U2H3(sv->counters.failed_conns),
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002908 sv->counters.cli_aborts,
2909 sv->counters.srv_aborts,
Willy Tarreauae526782010-03-04 20:34:23 +01002910 U2H6(sv->counters.failed_resp),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002911 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002912
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002913 /* status, lest check */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002914 chunk_appendf(&trash, "<td class=ac>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002915
Cyril Bontécd19e512010-01-31 22:34:03 +01002916 if (sv->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002917 chunk_appendf(&trash, "%s ",
Cyril Bontécd19e512010-01-31 22:34:03 +01002918 human_time(now.tv_sec - sv->last_change, 1));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002919 chunk_appendf(&trash, "MAINT");
Cyril Bontécd19e512010-01-31 22:34:03 +01002920 }
Cyril Bonté0dae5852010-02-03 00:26:28 +01002921 else if (svs != sv && svs->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002922 chunk_appendf(&trash, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01002923 human_time(now.tv_sec - svs->last_change, 1));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002924 chunk_appendf(&trash, "MAINT(via)");
Cyril Bonté0dae5852010-02-03 00:26:28 +01002925 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002926 else if (svs->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002927 chunk_appendf(&trash, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01002928 human_time(now.tv_sec - svs->last_change, 1));
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002929
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002930 chunk_appendf(&trash,
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002931 srv_hlt_st[sv_state],
2932 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
2933 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002934 }
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002935
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002936 if (sv->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002937 chunk_appendf(&trash, "</td><td class=ac title=\"%s",
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002938 get_check_status_description(sv->check.status));
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002939
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002940 if (*sv->check.desc) {
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002941 struct chunk src;
2942
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002943 chunk_appendf(&trash, ": ");
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002944
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002945 chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002946 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002947 }
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002948
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002949 chunk_appendf(&trash, "\"><u> %s%s",
Willy Tarreau0eb2bed2012-11-24 00:20:24 +01002950 (sv->state & SRV_CHK_RUNNING) ? "* " : "",
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002951 get_check_status_info(sv->check.status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002952
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002953 if (sv->check.status >= HCHK_STATUS_L57DATA)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002954 chunk_appendf(&trash, "/%d", sv->check.code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002955
Willy Tarreau5b3a2022012-09-28 15:01:02 +02002956 if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002957 chunk_appendf(&trash, " in %lums</u>", sv->check.duration);
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002958 } else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002959 chunk_appendf(&trash, "</td><td>");
Willy Tarreau91861262007-10-17 17:06:05 +02002960
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002961 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02002962 /* weight */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002963 "</td><td class=ac>%d</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002964 /* act, bck */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002965 "<td class=ac>%s</td><td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002966 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01002967 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +02002968 (sv->state & SRV_BACKUP) ? "-" : "Y",
2969 (sv->state & SRV_BACKUP) ? "Y" : "-");
2970
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002971 /* check failures: unique, fatal, down time */
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002972 if (sv->state & SRV_CHECKED) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002973 chunk_appendf(&trash, "<td title=\"Failed Health Checks%s\"><u>%lld",
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002974 svs->observe?"/Health Analyses":"", svs->counters.failed_checks);
2975
2976 if (svs->observe)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002977 chunk_appendf(&trash, "/%lld", svs->counters.failed_hana);
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002978
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002979 chunk_appendf(&trash,
Willy Tarreaue0454092010-02-26 12:29:07 +01002980 "</u></td>"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002981 "<td>%lld</td><td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002982 "",
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002983 svs->counters.down_trans, human_time(srv_downtime(sv), 1));
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002984 } else if (sv != svs)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002985 chunk_appendf(&trash,
Krzysztof Piotr Oledzki88a14af2010-01-05 18:33:01 +01002986 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>",
2987 svs->proxy->id, svs->id, svs->proxy->id, svs->id);
Willy Tarreau55bb8452007-10-17 18:44:57 +02002988 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002989 chunk_appendf(&trash,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002990 "<td colspan=3></td>");
2991
2992 /* throttle */
2993 if ((sv->state & SRV_WARMINGUP) &&
2994 now.tv_sec < sv->last_change + sv->slowstart &&
2995 now.tv_sec >= sv->last_change) {
2996 unsigned int ratio;
2997 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002998 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002999 "<td class=ac>%d %%</td></tr>\n", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003000 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003001 chunk_appendf(&trash,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003002 "<td class=ac>-</td></tr>\n");
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003003 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02003004 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +01003005 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
3006 "UP %d/%d,", "UP,",
3007 "NOLB %d/%d,", "NOLB,",
3008 "no check," };
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003009 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003010 /* pxid, name */
3011 "%s,%s,"
3012 /* queue : current, max */
3013 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003014 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003015 "%d,%d,%s,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003016 /* bytes : in, out */
3017 "%lld,%lld,"
3018 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003019 ",%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003020 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003021 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003022 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003023 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003024 "",
3025 px->id, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02003026 sv->nbpend, sv->counters.nbpend_max,
3027 sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02003028 sv->counters.bytes_in, sv->counters.bytes_out,
3029 sv->counters.failed_secu,
3030 sv->counters.failed_conns, sv->counters.failed_resp,
3031 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003032
Willy Tarreau55bb8452007-10-17 18:44:57 +02003033 /* status */
Cyril Bontécd19e512010-01-31 22:34:03 +01003034 if (sv->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003035 chunk_appendf(&trash, "MAINT,");
Cyril Bonté0dae5852010-02-03 00:26:28 +01003036 }
3037 else if (svs != sv && svs->state & SRV_MAINTAIN) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003038 chunk_appendf(&trash, "MAINT(via),");
Cyril Bonté0dae5852010-02-03 00:26:28 +01003039 }
3040 else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003041 chunk_appendf(&trash,
Cyril Bontécd19e512010-01-31 22:34:03 +01003042 srv_hlt_st[sv_state],
3043 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
3044 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
3045 }
Willy Tarreau91861262007-10-17 17:06:05 +02003046
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003047 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003048 /* weight, active, backup */
3049 "%d,%d,%d,"
3050 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01003051 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003052 (sv->state & SRV_BACKUP) ? 0 : 1,
3053 (sv->state & SRV_BACKUP) ? 1 : 0);
3054
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003055 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +02003056 if (sv->state & SRV_CHECKED)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003057 chunk_appendf(&trash,
Willy Tarreau3b88d442009-04-11 20:44:08 +02003058 "%lld,%lld,%d,%d,",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02003059 sv->counters.failed_checks, sv->counters.down_trans,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003060 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +02003061 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003062 chunk_appendf(&trash,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02003063 ",,,,");
3064
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003065 /* queue limit, pid, iid, sid, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003066 chunk_appendf(&trash,
Willy Tarreaudcd47712007-11-04 23:35:08 +01003067 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003068 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +01003069 LIM2A0(sv->maxqueue, ""),
3070 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003071
3072 /* throttle */
3073 if ((sv->state & SRV_WARMINGUP) &&
3074 now.tv_sec < sv->last_change + sv->slowstart &&
3075 now.tv_sec >= sv->last_change) {
3076 unsigned int ratio;
3077 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003078 chunk_appendf(&trash, "%d", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003079 }
3080
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003081 /* sessions: lbtot */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003082 chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003083
3084 /* tracked */
Willy Tarreau44267702011-10-28 15:35:33 +02003085 if (sv->track)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003086 chunk_appendf(&trash, "%s/%s,",
Willy Tarreau44267702011-10-28 15:35:33 +02003087 sv->track->proxy->id, sv->track->id);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003088 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003089 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01003090
Willy Tarreau7f062c42009-03-05 18:43:00 +01003091 /* type */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003092 chunk_appendf(&trash, "%d,", STATS_TYPE_SV);
Willy Tarreau7f062c42009-03-05 18:43:00 +01003093
3094 /* rate */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003095 chunk_appendf(&trash, "%u,,%u,",
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003096 read_freq_ctr(&sv->sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02003097 sv->counters.sps_max);
Willy Tarreau7f062c42009-03-05 18:43:00 +01003098
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003099 if (sv->state & SRV_CHECKED) {
3100 /* check_status */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003101 chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003102
3103 /* check_code */
Willy Tarreau5b3a2022012-09-28 15:01:02 +02003104 if (sv->check.status >= HCHK_STATUS_L57DATA)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003105 chunk_appendf(&trash, "%u,", sv->check.code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003106 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003107 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003108
3109 /* check_duration */
Willy Tarreau5b3a2022012-09-28 15:01:02 +02003110 if (sv->check.status >= HCHK_STATUS_CHECKED)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003111 chunk_appendf(&trash, "%lu,", sv->check.duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003112 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003113 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003114
3115 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003116 chunk_appendf(&trash, ",,,");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003117 }
3118
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003119 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3120 if (px->mode == PR_MODE_HTTP) {
3121 int i;
3122
3123 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003124 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003125
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003126 chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003127 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003128 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003129 }
3130
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003131 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003132 chunk_appendf(&trash, "%lld,", sv->counters.failed_hana);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003133
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003134 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003135 chunk_appendf(&trash, ",,,");
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003136
Willy Tarreauae526782010-03-04 20:34:23 +01003137 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003138 chunk_appendf(&trash, "%lld,%lld,",
Willy Tarreauae526782010-03-04 20:34:23 +01003139 sv->counters.cli_aborts, sv->counters.srv_aborts);
3140
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01003141 /* compression: in, out, bypassed, comp_rsp */
3142 chunk_appendf(&trash, ",,,,");
3143
Willy Tarreau7f062c42009-03-05 18:43:00 +01003144 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003145 chunk_appendf(&trash, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003146 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003147 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02003148 return 0;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003149 } /* for sv */
Willy Tarreau91861262007-10-17 17:06:05 +02003150
Willy Tarreau295a8372011-03-10 11:25:07 +01003151 si->applet.ctx.stats.px_st = STAT_PX_ST_BE;
Willy Tarreau91861262007-10-17 17:06:05 +02003152 /* fall through */
3153
Willy Tarreau295a8372011-03-10 11:25:07 +01003154 case STAT_PX_ST_BE:
Willy Tarreau91861262007-10-17 17:06:05 +02003155 /* print the backend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01003156 if ((px->cap & PR_CAP_BE) &&
Willy Tarreau295a8372011-03-10 11:25:07 +01003157 (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_BE)))) {
3158 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003159 chunk_appendf(&trash, "<tr class=\"backend\">");
Willy Tarreau295a8372011-03-10 11:25:07 +01003160 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02003161 /* Column sub-heading for Enable or Disable server */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003162 chunk_appendf(&trash, "<td></td>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02003163 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003164 chunk_appendf(&trash, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003165
3166 if (uri->flags&ST_SHLGNDS) {
3167 /* balancing */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003168 chunk_appendf(&trash, " title=\"balancing: %s",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003169 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003170
3171 /* cookie */
3172 if (px->cookie_name) {
3173 struct chunk src;
3174
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003175 chunk_appendf(&trash, ", cookie: '");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003176
3177 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003178 chunk_htmlencode(&trash, &src);
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003179
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003180 chunk_appendf(&trash, "'");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003181 }
3182
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003183 chunk_appendf(&trash, "\"");
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01003184
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01003185 }
3186
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003187 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02003188 /* name */
Willy Tarreaue0454092010-02-26 12:29:07 +01003189 ">%s<a name=\"%s/Backend\"></a>"
3190 "<a class=lfsb href=\"#%s/Backend\">Backend</a>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02003191 /* queue : current, max */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003192 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02003193 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003194 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02003195 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01003196 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02003197 px->id, px->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01003198 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003199 U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->be_counters.nbpend_max),
3200 U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->be_counters.sps_max));
Willy Tarreaua3e49422009-05-10 19:19:41 +02003201
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003202 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003203 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003204 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003205 "<td"
3206 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003207 U2H2(px->beconn), U2H3(px->be_counters.conn_max), U2H4(px->fullconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003208
3209 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
3210 if (px->mode == PR_MODE_HTTP) {
3211 int i;
3212
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01003213 chunk_appendf(&trash, " title=\"%lld requests:", px->be_counters.p.http.cum_req);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003214
3215 for (i = 1; i < 6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003216 chunk_appendf(&trash, " %dxx=%lld", i, px->be_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003217
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01003218 chunk_appendf(&trash, " other=%lld ", px->be_counters.p.http.rsp[0]);
3219 chunk_appendf(&trash, " compressed=%lld (%d%%)\"",
3220 px->be_counters.p.http.comp_rsp,
Willy Tarreau78bbeb42012-11-26 16:44:48 +01003221 px->be_counters.p.http.rsp[2] ?
Willy Tarreau5730c682012-11-26 14:13:09 +01003222 (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 +02003223 }
3224
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003225 chunk_appendf(&trash,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003226 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01003227 ">%s%s%s</td><td>%s</td>"
Willy Tarreau55058a72012-11-21 08:27:21 +01003228 /* bytes: in */
3229 "<td>%s</td><td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003230 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01003231 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003232 U2H6(px->be_counters.cum_conn),
Willy Tarreaue0454092010-02-26 12:29:07 +01003233 (px->mode == PR_MODE_HTTP)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003234 U2H7(px->be_counters.cum_lbconn),
Willy Tarreau55058a72012-11-21 08:27:21 +01003235 U2H8(px->be_counters.bytes_in));
3236
3237 /* compression stats (via td title): comp_in, comp_out, comp_byp */
Willy Tarreauf149d8f2012-11-24 14:06:49 +01003238 chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld savings=%d%%\"",
3239 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp,
3240 px->be_counters.comp_in ?
3241 (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 +02003242
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003243 chunk_appendf(&trash,
Willy Tarreau55058a72012-11-21 08:27:21 +01003244 /* bytes: out */
3245 ">%s%s%s</td>"
3246 "",
3247 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"",
3248 U2H0(px->be_counters.bytes_out),
3249 (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":"");
3250
3251 chunk_appendf(&trash,
Willy Tarreau91861262007-10-17 17:06:05 +02003252 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003253 "<td>%s</td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01003254 /* errors : request, connect */
3255 "<td></td><td>%s</td>"
3256 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01003257 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003258 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003259 "<td>%lld</td><td>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003260 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +02003261 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003262 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +02003263 * active and backups. */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003264 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
3265 "<td class=ac>%d</td><td class=ac>%d</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003266 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003267 U2H0(px->be_counters.denied_req), U2H1(px->be_counters.denied_resp),
3268 U2H2(px->be_counters.failed_conns),
3269 px->be_counters.cli_aborts,
3270 px->be_counters.srv_aborts,
3271 U2H5(px->be_counters.failed_resp),
3272 px->be_counters.retries, px->be_counters.redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003273 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +01003274 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
3275 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5542af62007-12-03 02:04:00 +01003276 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01003277 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003278
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003279 chunk_appendf(&trash,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003280 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003281 "<td class=ac>&nbsp;</td><td>%d</td>"
3282 "<td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003283 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003284 "</tr>",
3285 px->down_trans,
3286 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003287 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003288 chunk_appendf(&trash,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003289 /* pxid, name */
3290 "%s,BACKEND,"
3291 /* queue : current, max */
3292 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003293 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003294 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003295 /* bytes : in, out */
3296 "%lld,%lld,"
3297 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003298 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003299 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003300 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003301 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003302 "%lld,%lld,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003303 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +02003304 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003305 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +02003306 * active and backups. */
3307 "%s,"
3308 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003309 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02003310 ",%d,%d,%d,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003311 /* pid, iid, sid, throttle, lbtot, tracked, type */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003312 "%d,%d,0,,%lld,,%d,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003313 /* rate, rate_lim, rate_max, */
3314 "%u,,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003315 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003316 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02003317 px->id,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003318 px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max,
3319 px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn,
3320 px->be_counters.bytes_in, px->be_counters.bytes_out,
3321 px->be_counters.denied_req, px->be_counters.denied_resp,
3322 px->be_counters.failed_conns, px->be_counters.failed_resp,
3323 px->be_counters.retries, px->be_counters.redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +01003324 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5542af62007-12-03 02:04:00 +01003325 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01003326 px->srv_act, px->srv_bck,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003327 px->down_trans, (int)(now.tv_sec - px->last_change),
Willy Tarreau20697042007-11-15 23:26:18 +01003328 px->srv?be_downtime(px):0,
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003329 relative_pid, px->uuid,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003330 px->be_counters.cum_lbconn, STATS_TYPE_BE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003331 read_freq_ctr(&px->be_sess_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003332 px->be_counters.sps_max);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003333
3334 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3335 if (px->mode == PR_MODE_HTTP) {
3336 int i;
3337
3338 for (i=1; i<6; i++)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003339 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003340
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003341 chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003342 } else {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003343 chunk_appendf(&trash, ",,,,,,");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003344 }
3345
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003346 /* failed health analyses */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003347 chunk_appendf(&trash, ",");
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003348
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003349 /* requests : req_rate, req_rate_max, req_tot, */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003350 chunk_appendf(&trash, ",,,");
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003351
Willy Tarreauae526782010-03-04 20:34:23 +01003352 /* errors: cli_aborts, srv_aborts */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003353 chunk_appendf(&trash, "%lld,%lld,",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003354 px->be_counters.cli_aborts, px->be_counters.srv_aborts);
Willy Tarreauae526782010-03-04 20:34:23 +01003355
Willy Tarreau55058a72012-11-21 08:27:21 +01003356 /* compression: in, out, bypassed */
3357 chunk_appendf(&trash, "%lld,%lld,%lld,",
3358 px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp);
3359
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01003360 /* compression: comp_rsp */
3361 chunk_appendf(&trash, "%lld,",
3362 px->be_counters.p.http.comp_rsp);
3363
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003364 /* finish with EOL */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003365 chunk_appendf(&trash, "\n");
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003366
Willy Tarreau55bb8452007-10-17 18:44:57 +02003367 }
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003368 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau91861262007-10-17 17:06:05 +02003369 return 0;
3370 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003371
Willy Tarreau295a8372011-03-10 11:25:07 +01003372 si->applet.ctx.stats.px_st = STAT_PX_ST_END;
Willy Tarreau91861262007-10-17 17:06:05 +02003373 /* fall through */
3374
Willy Tarreau295a8372011-03-10 11:25:07 +01003375 case STAT_PX_ST_END:
3376 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003377 chunk_appendf(&trash, "</table>");
Cyril Bonté70be45d2010-10-12 00:14:35 +02003378
Willy Tarreau295a8372011-03-10 11:25:07 +01003379 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02003380 /* close the form used to enable/disable this proxy servers */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003381 chunk_appendf(&trash,
Cyril Bonté70be45d2010-10-12 00:14:35 +02003382 "Choose the action to perform on the checked servers : "
3383 "<select name=action>"
3384 "<option value=\"\"></option>"
3385 "<option value=\"disable\">Disable</option>"
3386 "<option value=\"enable\">Enable</option>"
Willy Tarreaud7282242012-06-04 00:22:44 +02003387 "<option value=\"stop\">Soft Stop</option>"
3388 "<option value=\"start\">Soft Start</option>"
Willy Tarreau4f8a83c2012-06-04 00:26:23 +02003389 "<option value=\"shutdown\">Kill Sessions</option>"
Cyril Bonté70be45d2010-10-12 00:14:35 +02003390 "</select>"
Cyril Bontéaa0a45d2012-04-04 12:57:20 +02003391 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
Cyril Bonté70be45d2010-10-12 00:14:35 +02003392 "&nbsp;<input type=\"submit\" value=\"Apply\">"
3393 "</form>",
Cyril Bontéaa0a45d2012-04-04 12:57:20 +02003394 px->uuid);
Cyril Bonté70be45d2010-10-12 00:14:35 +02003395 }
3396
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003397 chunk_appendf(&trash, "<p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +02003398
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003399 if (bi_putchk(rep, &trash) == -1)
Willy Tarreau55bb8452007-10-17 18:44:57 +02003400 return 0;
3401 }
Willy Tarreau91861262007-10-17 17:06:05 +02003402
Willy Tarreau295a8372011-03-10 11:25:07 +01003403 si->applet.ctx.stats.px_st = STAT_PX_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02003404 /* fall through */
3405
Willy Tarreau295a8372011-03-10 11:25:07 +01003406 case STAT_PX_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02003407 return 1;
3408
3409 default:
3410 /* unknown state, we should put an abort() here ! */
3411 return 1;
3412 }
3413}
3414
Willy Tarreau909d5172012-11-26 03:04:41 +01003415static inline const char *get_conn_ctrl_name(const struct connection *conn)
3416{
3417 if (!conn->ctrl)
3418 return "NONE";
3419 return conn->ctrl->name;
3420}
3421
3422static inline const char *get_conn_xprt_name(const struct connection *conn)
3423{
3424 static char ptr[17];
3425
3426 if (!conn->xprt)
3427 return "NONE";
3428
3429 if (conn->xprt == &raw_sock)
3430 return "RAW";
3431
3432#ifdef USE_OPENSSL
3433 if (conn->xprt == &ssl_sock)
3434 return "SSL";
3435#endif
3436 snprintf(ptr, sizeof(ptr), "%p", conn->xprt);
3437 return ptr;
3438}
3439
3440static inline const char *get_conn_data_name(const struct connection *conn)
3441{
3442 static char ptr[17];
3443
3444 if (!conn->data)
3445 return "NONE";
3446
3447 if (conn->data == &sess_conn_cb)
3448 return "SESS";
3449
3450 if (conn->data == &si_conn_cb)
3451 return "STRM";
3452
3453 if (conn->data == &check_conn_cb)
3454 return "CHCK";
3455
3456 snprintf(ptr, sizeof(ptr), "%p", conn->data);
3457 return ptr;
3458}
3459
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003460/* This function dumps a complete session state onto the stream interface's
3461 * read buffer. The xprt_ctx must have been zeroed first, and the flags
3462 * properly set. The session has to be set in xprt_ctx.sess.target. It returns
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003463 * 0 if the output buffer is full and it needs to be called again, otherwise
3464 * non-zero. It is designed to be called from stats_dump_sess_to_buffer() below.
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003465 */
Willy Tarreau76153662012-11-26 01:16:39 +01003466static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003467{
3468 struct tm tm;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003469 extern const char *monthname[12];
3470 char pn[INET6_ADDRSTRLEN];
3471
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003472 chunk_reset(&trash);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003473
Willy Tarreau295a8372011-03-10 11:25:07 +01003474 if (si->applet.ctx.sess.section > 0 && si->applet.ctx.sess.uid != sess->uniq_id) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003475 /* session changed, no need to go any further */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003476 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
3477 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003478 return 0;
Willy Tarreau295a8372011-03-10 11:25:07 +01003479 si->applet.ctx.sess.uid = 0;
Willy Tarreau76153662012-11-26 01:16:39 +01003480 si->applet.ctx.sess.section = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003481 return 1;
3482 }
3483
Willy Tarreau295a8372011-03-10 11:25:07 +01003484 switch (si->applet.ctx.sess.section) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003485 case 0: /* main status of the session */
Willy Tarreau295a8372011-03-10 11:25:07 +01003486 si->applet.ctx.sess.uid = sess->uniq_id;
3487 si->applet.ctx.sess.section = 1;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003488 /* fall through */
3489
3490 case 1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003491 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003492 "%p: id=%u, proto=%s",
3493 sess,
3494 sess->uniq_id,
3495 sess->listener->proto->name);
3496
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003497 switch (addr_to_str(&sess->si[0].conn->addr.from, pn, sizeof(pn))) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003498 case AF_INET:
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003499 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003500 chunk_appendf(&trash, " source=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003501 pn, get_host_port(&sess->si[0].conn->addr.from));
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003502 break;
3503 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003504 chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid);
Emeric Brun837ca522010-10-22 16:19:01 +02003505 break;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003506 default:
3507 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003508 chunk_appendf(&trash, "\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003509 break;
3510 }
3511
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003512 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003513 " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n",
Willy Tarreauee28de02010-06-01 09:51:00 +02003514 sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003515
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003516 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003517 " frontend=%s (id=%u mode=%s), listener=%s (id=%u)",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003518 sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp",
3519 sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?",
3520 sess->listener ? sess->listener->luid : 0);
3521
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003522 conn_get_to_addr(sess->si[0].conn);
3523 switch (addr_to_str(&sess->si[0].conn->addr.to, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003524 case AF_INET:
3525 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003526 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003527 pn, get_host_port(&sess->si[0].conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07003528 break;
3529 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003530 chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid);
Daniel Schultze90690c72012-03-23 10:53:36 -07003531 break;
3532 default:
3533 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003534 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003535 break;
3536 }
3537
Willy Tarreau50943332011-09-02 17:33:05 +02003538 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003539 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003540 " backend=%s (id=%u mode=%s)",
Willy Tarreau50943332011-09-02 17:33:05 +02003541 sess->be->id,
Daniel Schultze90690c72012-03-23 10:53:36 -07003542 sess->be->uuid, sess->be->mode ? "http" : "tcp");
3543 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003544 chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)");
Daniel Schultze90690c72012-03-23 10:53:36 -07003545
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003546 conn_get_from_addr(sess->si[1].conn);
3547 switch (addr_to_str(&sess->si[1].conn->addr.from, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003548 case AF_INET:
3549 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003550 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003551 pn, get_host_port(&sess->si[1].conn->addr.from));
Daniel Schultze90690c72012-03-23 10:53:36 -07003552 break;
3553 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003554 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003555 break;
3556 default:
3557 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003558 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003559 break;
3560 }
3561
3562 if (sess->be->cap & PR_CAP_BE)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003563 chunk_appendf(&trash,
Daniel Schultze90690c72012-03-23 10:53:36 -07003564 " server=%s (id=%u)",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003565 objt_server(sess->target) ? objt_server(sess->target)->id : "<none>",
3566 objt_server(sess->target) ? objt_server(sess->target)->puid : 0);
Willy Tarreau50943332011-09-02 17:33:05 +02003567 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003568 chunk_appendf(&trash, " server=<NONE> (id=-1)");
Daniel Schultze90690c72012-03-23 10:53:36 -07003569
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003570 conn_get_to_addr(sess->si[1].conn);
3571 switch (addr_to_str(&sess->si[1].conn->addr.to, pn, sizeof(pn))) {
Daniel Schultze90690c72012-03-23 10:53:36 -07003572 case AF_INET:
3573 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003574 chunk_appendf(&trash, " addr=%s:%d\n",
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003575 pn, get_host_port(&sess->si[1].conn->addr.to));
Daniel Schultze90690c72012-03-23 10:53:36 -07003576 break;
3577 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003578 chunk_appendf(&trash, " addr=unix\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003579 break;
3580 default:
3581 /* no more information to print right now */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003582 chunk_appendf(&trash, "\n");
Daniel Schultze90690c72012-03-23 10:53:36 -07003583 break;
3584 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003585
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003586 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003587 " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s)\n",
3588 sess->task,
3589 sess->task->state,
3590 sess->task->nice, sess->task->calls,
3591 sess->task->expire ?
3592 tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" :
3593 human_time(TICKS_TO_MS(sess->task->expire - now_ms),
3594 TICKS_TO_MS(1000)) : "<NEVER>",
3595 task_in_rq(sess->task) ? ", running" : "");
3596
3597 get_localtime(sess->logs.accept_date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003598 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003599 " task created [%02d/%s/%04d:%02d:%02d:%02d.%06d] (age=%s)\n",
3600 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
3601 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec),
3602 human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1));
3603
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003604 chunk_appendf(&trash,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003605 " si[0]=%p (state=%d flags=0x%02x conn=%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003606 &sess->si[0],
3607 sess->si[0].state,
3608 sess->si[0].flags,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003609 sess->si[0].conn,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003610 sess->si[0].exp ?
3611 tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" :
3612 human_time(TICKS_TO_MS(sess->si[0].exp - now_ms),
3613 TICKS_TO_MS(1000)) : "<NEVER>",
3614 sess->si[0].err_type);
3615
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003616 chunk_appendf(&trash,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003617 " si[1]=%p (state=%d flags=0x%02x conn=%p exp=%s, et=0x%03x)\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003618 &sess->si[1],
3619 sess->si[1].state,
3620 sess->si[1].flags,
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003621 sess->si[1].conn,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003622 sess->si[1].exp ?
3623 tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" :
3624 human_time(TICKS_TO_MS(sess->si[1].exp - now_ms),
3625 TICKS_TO_MS(1000)) : "<NEVER>",
3626 sess->si[1].err_type);
3627
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003628 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01003629 " lconn=%p ctrl=%s xprt=%s data=%s\n",
3630 sess->si[0].conn,
3631 get_conn_ctrl_name(sess->si[0].conn),
3632 get_conn_xprt_name(sess->si[0].conn),
3633 get_conn_data_name(sess->si[0].conn));
3634
3635 chunk_appendf(&trash,
3636 " target=%d flags=0x%08x fd=%d fd_spec=%02x\n",
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003637 sess->si[0].conn->target ? *sess->si[0].conn->target : 0,
Willy Tarreau1feca012012-11-19 18:15:19 +01003638 sess->si[0].conn->flags,
3639 sess->si[0].conn->t.sock.fd,
3640 sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_e : 0);
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003641
3642 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01003643 " rconn=%p ctrl=%s xprt=%s data=%s\n",
3644 sess->si[1].conn,
3645 get_conn_ctrl_name(sess->si[1].conn),
3646 get_conn_xprt_name(sess->si[1].conn),
3647 get_conn_data_name(sess->si[1].conn));
3648
3649 chunk_appendf(&trash,
3650 " target=%d flags=0x%08x fd=%d fd_spec=%02x\n",
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003651 sess->si[1].conn->target ? *sess->si[1].conn->target : 0,
Willy Tarreau1feca012012-11-19 18:15:19 +01003652 sess->si[1].conn->flags,
3653 sess->si[1].conn->t.sock.fd,
3654 sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_e : 0);
Willy Tarreaubc174aa2012-11-19 16:10:32 +01003655
3656 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01003657 " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003658 &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status,
Willy Tarreaue6d97022012-11-23 11:19:33 +01003659 http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state));
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003660
3661
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003662 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01003663 " req=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003664 " an_exp=%s",
3665 sess->req,
3666 sess->req->flags, sess->req->analysers,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003667 sess->req->pipe ? sess->req->pipe->data : 0,
Willy Tarreau909d5172012-11-26 03:04:41 +01003668 sess->req->to_forward, sess->req->total,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003669 sess->req->analyse_exp ?
3670 human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms),
3671 TICKS_TO_MS(1000)) : "<NEVER>");
3672
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003673 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003674 " rex=%s",
3675 sess->req->rex ?
3676 human_time(TICKS_TO_MS(sess->req->rex - now_ms),
3677 TICKS_TO_MS(1000)) : "<NEVER>");
3678
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003679 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003680 " wex=%s\n"
Willy Tarreau909d5172012-11-26 03:04:41 +01003681 " buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003682 sess->req->wex ?
3683 human_time(TICKS_TO_MS(sess->req->wex - now_ms),
3684 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau909d5172012-11-26 03:04:41 +01003685 sess->req->buf,
3686 sess->req->buf->data, sess->req->buf->o,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003687 (int)(sess->req->buf->p - sess->req->buf->data),
Willy Tarreau909d5172012-11-26 03:04:41 +01003688 sess->txn.req.next, sess->req->buf->i,
3689 sess->req->buf->size);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003690
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003691 chunk_appendf(&trash,
Willy Tarreau909d5172012-11-26 03:04:41 +01003692 " res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003693 " an_exp=%s",
3694 sess->rep,
3695 sess->rep->flags, sess->rep->analysers,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003696 sess->rep->pipe ? sess->rep->pipe->data : 0,
Willy Tarreau909d5172012-11-26 03:04:41 +01003697 sess->rep->to_forward, sess->rep->total,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003698 sess->rep->analyse_exp ?
3699 human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms),
3700 TICKS_TO_MS(1000)) : "<NEVER>");
3701
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003702 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003703 " rex=%s",
3704 sess->rep->rex ?
3705 human_time(TICKS_TO_MS(sess->rep->rex - now_ms),
3706 TICKS_TO_MS(1000)) : "<NEVER>");
3707
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003708 chunk_appendf(&trash,
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003709 " wex=%s\n"
Willy Tarreau909d5172012-11-26 03:04:41 +01003710 " buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d\n",
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003711 sess->rep->wex ?
3712 human_time(TICKS_TO_MS(sess->rep->wex - now_ms),
3713 TICKS_TO_MS(1000)) : "<NEVER>",
Willy Tarreau909d5172012-11-26 03:04:41 +01003714 sess->rep->buf,
3715 sess->rep->buf->data, sess->rep->buf->o,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003716 (int)(sess->rep->buf->p - sess->rep->buf->data),
Willy Tarreau909d5172012-11-26 03:04:41 +01003717 sess->txn.rsp.next, sess->rep->buf->i,
3718 sess->rep->buf->size);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003719
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003720 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003721 return 0;
3722
3723 /* use other states to dump the contents */
3724 }
3725 /* end of dump */
Willy Tarreau295a8372011-03-10 11:25:07 +01003726 si->applet.ctx.sess.uid = 0;
Willy Tarreau76153662012-11-26 01:16:39 +01003727 si->applet.ctx.sess.section = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003728 return 1;
3729}
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003730
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003731/* This function dumps all sessions' states onto the stream interface's
3732 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003733 * properly set. It returns 0 if the output buffer is full and it needs
3734 * to be called again, otherwise non-zero. It is designed to be called
3735 * from stats_dump_sess_to_buffer() below.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003736 */
Simon Horman9bd2c732011-06-15 15:18:44 +09003737static int stats_dump_sess_to_buffer(struct stream_interface *si)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003738{
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02003739 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003740 /* If we're forced to shut down, we might have to remove our
3741 * reference to the last session being dumped.
3742 */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003743 if (si->conn->xprt_st == STAT_ST_LIST) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003744 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) {
3745 LIST_DEL(&si->applet.ctx.sess.bref.users);
3746 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003747 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003748 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003749 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003750 }
3751
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003752 chunk_reset(&trash);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003753
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003754 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003755 case STAT_ST_INIT:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003756 /* the function had not been called yet, let's prepare the
3757 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003758 * pointer to the first in the global list. When a target
3759 * session is being destroyed, it is responsible for updating
3760 * this pointer. We know we have reached the end when this
3761 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003762 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003763 LIST_INIT(&si->applet.ctx.sess.bref.users);
3764 si->applet.ctx.sess.bref.ref = sessions.n;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003765 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003766 /* fall through */
3767
Willy Tarreau295a8372011-03-10 11:25:07 +01003768 case STAT_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003769 /* first, let's detach the back-ref from a possible previous session */
Willy Tarreau295a8372011-03-10 11:25:07 +01003770 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) {
3771 LIST_DEL(&si->applet.ctx.sess.bref.users);
3772 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003773 }
3774
3775 /* and start from where we stopped */
Willy Tarreau295a8372011-03-10 11:25:07 +01003776 while (si->applet.ctx.sess.bref.ref != &sessions) {
Cyril Bontéacd7d632010-11-01 19:26:02 +01003777 char pn[INET6_ADDRSTRLEN];
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003778 struct session *curr_sess;
3779
Willy Tarreau295a8372011-03-10 11:25:07 +01003780 curr_sess = LIST_ELEM(si->applet.ctx.sess.bref.ref, struct session *, list);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003781
Willy Tarreau295a8372011-03-10 11:25:07 +01003782 if (si->applet.ctx.sess.target) {
Willy Tarreau76153662012-11-26 01:16:39 +01003783 if (si->applet.ctx.sess.target != (void *)-1 && si->applet.ctx.sess.target != curr_sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003784 goto next_sess;
3785
Willy Tarreau295a8372011-03-10 11:25:07 +01003786 LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003787 /* call the proper dump() function and return if we're missing space */
Willy Tarreau76153662012-11-26 01:16:39 +01003788 if (!stats_dump_full_sess_to_buffer(si, curr_sess))
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003789 return 0;
3790
3791 /* session dump complete */
Willy Tarreau295a8372011-03-10 11:25:07 +01003792 LIST_DEL(&si->applet.ctx.sess.bref.users);
3793 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreau76153662012-11-26 01:16:39 +01003794 if (si->applet.ctx.sess.target != (void *)-1) {
3795 si->applet.ctx.sess.target = NULL;
3796 break;
3797 }
3798 else
3799 goto next_sess;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003800 }
3801
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003802 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003803 "%p: proto=%s",
3804 curr_sess,
3805 curr_sess->listener->proto->name);
3806
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003807
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003808 switch (addr_to_str(&curr_sess->si[0].conn->addr.from, pn, sizeof(pn))) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02003809 case AF_INET:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003810 case AF_INET6:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003811 chunk_appendf(&trash,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003812 " src=%s:%d fe=%s be=%s srv=%s",
3813 pn,
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003814 get_host_port(&curr_sess->si[0].conn->addr.from),
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003815 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02003816 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003817 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003818 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003819 break;
3820 case AF_UNIX:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003821 chunk_appendf(&trash,
Emeric Brun837ca522010-10-22 16:19:01 +02003822 " src=unix:%d fe=%s be=%s srv=%s",
3823 curr_sess->listener->luid,
3824 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02003825 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau3fdb3662012-11-12 00:42:33 +01003826 objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
Emeric Brun837ca522010-10-22 16:19:01 +02003827 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003828 break;
3829 }
3830
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003831 chunk_appendf(&trash,
Willy Tarreau65671ab2009-10-04 14:24:59 +02003832 " ts=%02x age=%s calls=%d",
3833 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01003834 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
3835 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003836
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003837 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003838 " rq[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003839 curr_sess->req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003840 curr_sess->req->buf->i,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003841 curr_sess->req->analysers,
3842 curr_sess->req->rex ?
3843 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
3844 TICKS_TO_MS(1000)) : "");
3845
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003846 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003847 ",wx=%s",
3848 curr_sess->req->wex ?
3849 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
3850 TICKS_TO_MS(1000)) : "");
3851
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003852 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003853 ",ax=%s]",
3854 curr_sess->req->analyse_exp ?
3855 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
3856 TICKS_TO_MS(1000)) : "");
3857
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003858 chunk_appendf(&trash,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01003859 " rp[f=%06xh,i=%d,an=%02xh,rx=%s",
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003860 curr_sess->rep->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02003861 curr_sess->rep->buf->i,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003862 curr_sess->rep->analysers,
3863 curr_sess->rep->rex ?
3864 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
3865 TICKS_TO_MS(1000)) : "");
3866
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003867 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003868 ",wx=%s",
3869 curr_sess->rep->wex ?
3870 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
3871 TICKS_TO_MS(1000)) : "");
3872
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003873 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003874 ",ax=%s]",
3875 curr_sess->rep->analyse_exp ?
3876 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
3877 TICKS_TO_MS(1000)) : "");
3878
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003879 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003880 " s0=[%d,%1xh,fd=%d,ex=%s]",
3881 curr_sess->si[0].state,
3882 curr_sess->si[0].flags,
Willy Tarreau7f7ad912012-11-11 19:27:15 +01003883 curr_sess->si[0].conn->t.sock.fd,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003884 curr_sess->si[0].exp ?
3885 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
3886 TICKS_TO_MS(1000)) : "");
3887
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003888 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003889 " s1=[%d,%1xh,fd=%d,ex=%s]",
3890 curr_sess->si[1].state,
3891 curr_sess->si[1].flags,
Willy Tarreau7f7ad912012-11-11 19:27:15 +01003892 curr_sess->si[1].conn->t.sock.fd,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003893 curr_sess->si[1].exp ?
3894 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
3895 TICKS_TO_MS(1000)) : "");
3896
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003897 chunk_appendf(&trash,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003898 " exp=%s",
3899 curr_sess->task->expire ?
3900 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
3901 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01003902 if (task_in_rq(curr_sess->task))
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003903 chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003904
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003905 chunk_appendf(&trash, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003906
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003907 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003908 /* let's try again later from this session. We add ourselves into
3909 * this session's users so that it can remove us upon termination.
3910 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003911 LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003912 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003913 }
3914
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003915 next_sess:
Willy Tarreau295a8372011-03-10 11:25:07 +01003916 si->applet.ctx.sess.bref.ref = curr_sess->list.n;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003917 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003918
Willy Tarreau76153662012-11-26 01:16:39 +01003919 if (si->applet.ctx.sess.target && si->applet.ctx.sess.target != (void *)-1) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003920 /* specified session not found */
Willy Tarreau295a8372011-03-10 11:25:07 +01003921 if (si->applet.ctx.sess.section > 0)
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003922 chunk_appendf(&trash, " *** session terminated while we were watching it ***\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003923 else
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003924 chunk_appendf(&trash, "Session not found.\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003925
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003926 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003927 return 0;
3928
Willy Tarreau295a8372011-03-10 11:25:07 +01003929 si->applet.ctx.sess.target = NULL;
3930 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003931 return 1;
3932 }
3933
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003934 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003935 /* fall through */
3936
3937 default:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003938 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003939 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003940 }
Emeric Brun1e029aa2010-09-23 18:12:53 +02003941}
3942
Willy Tarreau5f9a8772012-11-26 02:22:40 +01003943/* This is called when the stream interface is closed. For instance, upon an
3944 * external abort, we won't call the i/o handler anymore so we may need to
3945 * remove back references to the session currently being dumped.
3946 */
3947void cli_release_handler(struct stream_interface *si)
3948{
3949 if (si->applet.st0 == STAT_CLI_O_SESS && si->conn->xprt_st == STAT_ST_LIST) {
3950 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users))
3951 LIST_DEL(&si->applet.ctx.sess.bref.users);
3952 }
3953}
3954
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02003955/* This function dumps all tables' states onto the stream interface's
3956 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003957 * properly set. It returns 0 if the output buffer is full and it needs
3958 * to be called again, otherwise non-zero.
Willy Tarreau69f58c82010-07-12 17:55:33 +02003959 */
Simon Hormanc88b8872011-06-15 15:18:49 +09003960static int stats_table_request(struct stream_interface *si, bool show)
Willy Tarreau69f58c82010-07-12 17:55:33 +02003961{
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003962 struct session *s = si->conn->xprt_ctx;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003963 struct ebmb_node *eb;
3964 int dt;
Simon Hormanc88b8872011-06-15 15:18:49 +09003965 bool skip_entry;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003966
3967 /*
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003968 * We have 3 possible states in si->conn->xprt_st :
Willy Tarreau295a8372011-03-10 11:25:07 +01003969 * - STAT_ST_INIT : the first call
3970 * - STAT_ST_INFO : the proxy pointer points to the next table to
Willy Tarreau69f58c82010-07-12 17:55:33 +02003971 * dump, the entry pointer is NULL ;
Willy Tarreau295a8372011-03-10 11:25:07 +01003972 * - STAT_ST_LIST : the proxy pointer points to the current table
Willy Tarreau69f58c82010-07-12 17:55:33 +02003973 * and the entry pointer points to the next entry to be dumped,
3974 * and the refcount on the next entry is held ;
Willy Tarreau295a8372011-03-10 11:25:07 +01003975 * - STAT_ST_END : nothing left to dump, the buffer may contain some
Willy Tarreau69f58c82010-07-12 17:55:33 +02003976 * data though.
3977 */
3978
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02003979 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02003980 /* in case of abort, remove any refcount we might have set on an entry */
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003981 if (si->conn->xprt_st == STAT_ST_LIST) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003982 si->applet.ctx.table.entry->ref_cnt--;
3983 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
Willy Tarreauf6efda12010-08-03 20:34:06 +02003984 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02003985 return 1;
3986 }
3987
Willy Tarreau19d14ef2012-10-29 16:51:55 +01003988 chunk_reset(&trash);
Willy Tarreau69f58c82010-07-12 17:55:33 +02003989
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003990 while (si->conn->xprt_st != STAT_ST_FIN) {
3991 switch (si->conn->xprt_st) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003992 case STAT_ST_INIT:
3993 si->applet.ctx.table.proxy = si->applet.ctx.table.target;
3994 if (!si->applet.ctx.table.proxy)
3995 si->applet.ctx.table.proxy = proxy;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003996
Willy Tarreau295a8372011-03-10 11:25:07 +01003997 si->applet.ctx.table.entry = NULL;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02003998 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003999 break;
4000
Willy Tarreau295a8372011-03-10 11:25:07 +01004001 case STAT_ST_INFO:
4002 if (!si->applet.ctx.table.proxy ||
4003 (si->applet.ctx.table.target &&
4004 si->applet.ctx.table.proxy != si->applet.ctx.table.target)) {
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004005 si->conn->xprt_st = STAT_ST_END;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004006 break;
4007 }
4008
Willy Tarreau295a8372011-03-10 11:25:07 +01004009 if (si->applet.ctx.table.proxy->table.size) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004010 if (show && !stats_dump_table_head_to_buffer(&trash, si, si->applet.ctx.table.proxy,
Simon Hormanc88b8872011-06-15 15:18:49 +09004011 si->applet.ctx.table.target))
Willy Tarreau69f58c82010-07-12 17:55:33 +02004012 return 0;
4013
Willy Tarreau295a8372011-03-10 11:25:07 +01004014 if (si->applet.ctx.table.target &&
Willy Tarreau290e63a2012-09-20 18:07:14 +02004015 s->listener->bind_conf->level >= ACCESS_LVL_OPER) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02004016 /* dump entries only if table explicitly requested */
Willy Tarreau295a8372011-03-10 11:25:07 +01004017 eb = ebmb_first(&si->applet.ctx.table.proxy->table.keys);
Willy Tarreau69f58c82010-07-12 17:55:33 +02004018 if (eb) {
Willy Tarreau295a8372011-03-10 11:25:07 +01004019 si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key);
4020 si->applet.ctx.table.entry->ref_cnt++;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004021 si->conn->xprt_st = STAT_ST_LIST;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004022 break;
4023 }
4024 }
4025 }
Willy Tarreau295a8372011-03-10 11:25:07 +01004026 si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004027 break;
4028
Willy Tarreau295a8372011-03-10 11:25:07 +01004029 case STAT_ST_LIST:
Simon Hormanc88b8872011-06-15 15:18:49 +09004030 skip_entry = false;
4031
Willy Tarreau295a8372011-03-10 11:25:07 +01004032 if (si->applet.ctx.table.data_type >= 0) {
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02004033 /* we're filtering on some data contents */
4034 void *ptr;
4035 long long data;
4036
Willy Tarreau295a8372011-03-10 11:25:07 +01004037 dt = si->applet.ctx.table.data_type;
4038 ptr = stktable_data_ptr(&si->applet.ctx.table.proxy->table,
4039 si->applet.ctx.table.entry,
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02004040 dt);
4041
4042 data = 0;
4043 switch (stktable_data_types[dt].std_type) {
4044 case STD_T_SINT:
4045 data = stktable_data_cast(ptr, std_t_sint);
4046 break;
4047 case STD_T_UINT:
4048 data = stktable_data_cast(ptr, std_t_uint);
4049 break;
4050 case STD_T_ULL:
4051 data = stktable_data_cast(ptr, std_t_ull);
4052 break;
4053 case STD_T_FRQP:
4054 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Willy Tarreau295a8372011-03-10 11:25:07 +01004055 si->applet.ctx.table.proxy->table.data_arg[dt].u);
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02004056 break;
4057 }
4058
4059 /* skip the entry if the data does not match the test and the value */
Willy Tarreau295a8372011-03-10 11:25:07 +01004060 if ((data < si->applet.ctx.table.value &&
4061 (si->applet.ctx.table.data_op == STD_OP_EQ ||
4062 si->applet.ctx.table.data_op == STD_OP_GT ||
4063 si->applet.ctx.table.data_op == STD_OP_GE)) ||
4064 (data == si->applet.ctx.table.value &&
4065 (si->applet.ctx.table.data_op == STD_OP_NE ||
4066 si->applet.ctx.table.data_op == STD_OP_GT ||
4067 si->applet.ctx.table.data_op == STD_OP_LT)) ||
4068 (data > si->applet.ctx.table.value &&
4069 (si->applet.ctx.table.data_op == STD_OP_EQ ||
4070 si->applet.ctx.table.data_op == STD_OP_LT ||
4071 si->applet.ctx.table.data_op == STD_OP_LE)))
Simon Hormanc88b8872011-06-15 15:18:49 +09004072 skip_entry = true;
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02004073 }
4074
Simon Hormanc88b8872011-06-15 15:18:49 +09004075 if (show && !skip_entry &&
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004076 !stats_dump_table_entry_to_buffer(&trash, si, si->applet.ctx.table.proxy,
Simon Hormand9366582011-06-15 15:18:45 +09004077 si->applet.ctx.table.entry))
4078 return 0;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004079
Willy Tarreau295a8372011-03-10 11:25:07 +01004080 si->applet.ctx.table.entry->ref_cnt--;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004081
Willy Tarreau295a8372011-03-10 11:25:07 +01004082 eb = ebmb_next(&si->applet.ctx.table.entry->key);
Willy Tarreau69f58c82010-07-12 17:55:33 +02004083 if (eb) {
Willy Tarreau295a8372011-03-10 11:25:07 +01004084 struct stksess *old = si->applet.ctx.table.entry;
4085 si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key);
Willy Tarreau8fa52f42012-01-09 11:50:03 +01004086 if (show)
4087 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, old);
4088 else
4089 stksess_kill(&si->applet.ctx.table.proxy->table, old);
Willy Tarreau295a8372011-03-10 11:25:07 +01004090 si->applet.ctx.table.entry->ref_cnt++;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004091 break;
4092 }
4093
Simon Hormanc88b8872011-06-15 15:18:49 +09004094
4095 if (show)
4096 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
4097 else if (!skip_entry && !si->applet.ctx.table.entry->ref_cnt)
4098 stksess_kill(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
4099
Willy Tarreau295a8372011-03-10 11:25:07 +01004100 si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next;
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004101 si->conn->xprt_st = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004102 break;
4103
Willy Tarreau295a8372011-03-10 11:25:07 +01004104 case STAT_ST_END:
Willy Tarreauf2943dc2012-10-26 20:10:28 +02004105 si->conn->xprt_st = STAT_ST_FIN;
Willy Tarreau69f58c82010-07-12 17:55:33 +02004106 break;
4107 }
4108 }
4109 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01004110}
4111
Willy Tarreaud426a182010-03-05 14:58:26 +01004112/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
Willy Tarreau74808cb2009-03-04 15:53:18 +01004113 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
4114 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
4115 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
4116 * lines are respected within the limit of 70 output chars. Lines that are
4117 * continuation of a previous truncated line begin with "+" instead of " "
4118 * after the offset. The new pointer is returned.
4119 */
Willy Tarreaud426a182010-03-05 14:58:26 +01004120static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
4121 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004122{
4123 int end;
4124 unsigned char c;
4125
4126 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02004127 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004128 return ptr;
4129
Willy Tarreau77804732012-10-29 16:14:26 +01004130 chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01004131
Willy Tarreaud426a182010-03-05 14:58:26 +01004132 while (ptr < len && ptr < bsize) {
4133 c = buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01004134 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004135 if (out->len > end - 2)
4136 break;
4137 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01004138 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004139 if (out->len > end - 3)
4140 break;
4141 out->str[out->len++] = '\\';
4142 switch (c) {
4143 case '\t': c = 't'; break;
4144 case '\n': c = 'n'; break;
4145 case '\r': c = 'r'; break;
4146 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01004147 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004148 }
4149 out->str[out->len++] = c;
4150 } else {
4151 if (out->len > end - 5)
4152 break;
4153 out->str[out->len++] = '\\';
4154 out->str[out->len++] = 'x';
4155 out->str[out->len++] = hextab[(c >> 4) & 0xF];
4156 out->str[out->len++] = hextab[c & 0xF];
4157 }
Willy Tarreaud426a182010-03-05 14:58:26 +01004158 if (buf[ptr++] == '\n') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004159 /* we had a line break, let's return now */
4160 out->str[out->len++] = '\n';
4161 *line = ptr;
4162 return ptr;
4163 }
4164 }
4165 /* we have an incomplete line, we return it as-is */
4166 out->str[out->len++] = '\n';
4167 return ptr;
4168}
4169
Willy Tarreauf7bc57c2012-10-03 00:19:48 +02004170/* This function dumps all captured errors onto the stream interface's
4171 * read buffer. The xprt_ctx must have been zeroed first, and the flags
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01004172 * properly set. It returns 0 if the output buffer is full and it needs
4173 * to be called again, otherwise non-zero.
Willy Tarreau74808cb2009-03-04 15:53:18 +01004174 */
Simon Horman9bd2c732011-06-15 15:18:44 +09004175static int stats_dump_errors_to_buffer(struct stream_interface *si)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004176{
4177 extern const char *monthname[12];
Willy Tarreau74808cb2009-03-04 15:53:18 +01004178
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02004179 if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW)))
Willy Tarreau61b34732009-10-03 23:49:35 +02004180 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004181
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004182 chunk_reset(&trash);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004183
Willy Tarreau295a8372011-03-10 11:25:07 +01004184 if (!si->applet.ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004185 /* the function had not been called yet, let's prepare the
4186 * buffer for a response.
4187 */
Willy Tarreau10479e42010-12-12 14:00:34 +01004188 struct tm tm;
4189
4190 get_localtime(date.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004191 chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n",
Willy Tarreau10479e42010-12-12 14:00:34 +01004192 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
4193 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000),
4194 error_snapshot_id);
4195
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004196 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau10479e42010-12-12 14:00:34 +01004197 /* Socket buffer full. Let's try again later from the same point */
4198 return 0;
4199 }
4200
Willy Tarreau295a8372011-03-10 11:25:07 +01004201 si->applet.ctx.errors.px = proxy;
4202 si->applet.ctx.errors.buf = 0;
4203 si->applet.ctx.errors.bol = 0;
4204 si->applet.ctx.errors.ptr = -1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004205 }
4206
4207 /* we have two inner loops here, one for the proxy, the other one for
4208 * the buffer.
4209 */
Willy Tarreau295a8372011-03-10 11:25:07 +01004210 while (si->applet.ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004211 struct error_snapshot *es;
4212
Willy Tarreau295a8372011-03-10 11:25:07 +01004213 if (si->applet.ctx.errors.buf == 0)
4214 es = &si->applet.ctx.errors.px->invalid_req;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004215 else
Willy Tarreau295a8372011-03-10 11:25:07 +01004216 es = &si->applet.ctx.errors.px->invalid_rep;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004217
4218 if (!es->when.tv_sec)
4219 goto next;
4220
Willy Tarreau295a8372011-03-10 11:25:07 +01004221 if (si->applet.ctx.errors.iid >= 0 &&
4222 si->applet.ctx.errors.px->uuid != si->applet.ctx.errors.iid &&
4223 es->oe->uuid != si->applet.ctx.errors.iid)
Willy Tarreau74808cb2009-03-04 15:53:18 +01004224 goto next;
4225
Willy Tarreau295a8372011-03-10 11:25:07 +01004226 if (si->applet.ctx.errors.ptr < 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004227 /* just print headers now */
4228
4229 char pn[INET6_ADDRSTRLEN];
4230 struct tm tm;
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004231 int port;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004232
4233 get_localtime(es->when.tv_sec, &tm);
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004234 chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01004235 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02004236 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01004237
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004238 switch (addr_to_str(&es->src, pn, sizeof(pn))) {
4239 case AF_INET:
4240 case AF_INET6:
4241 port = get_host_port(&es->src);
4242 break;
4243 default:
4244 port = 0;
4245 }
4246
Willy Tarreau295a8372011-03-10 11:25:07 +01004247 switch (si->applet.ctx.errors.buf) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004248 case 0:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004249 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004250 " frontend %s (#%d): invalid request\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004251 " backend %s (#%d)",
Willy Tarreau295a8372011-03-10 11:25:07 +01004252 si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004253 (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
4254 (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004255 break;
4256 case 1:
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004257 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004258 " backend %s (#%d) : invalid response\n"
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004259 " frontend %s (#%d)",
Willy Tarreau295a8372011-03-10 11:25:07 +01004260 si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004261 es->oe->id, es->oe->uuid);
Willy Tarreau74808cb2009-03-04 15:53:18 +01004262 break;
4263 }
4264
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004265 chunk_appendf(&trash,
Willy Tarreaud04b1bc2012-05-08 11:03:10 +02004266 ", server %s (#%d), event #%u\n"
4267 " src %s:%d, session #%d, session flags 0x%08x\n"
4268 " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n"
4269 " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n"
4270 " buffer flags 0x%08x, out %d bytes, total %lld bytes\n"
4271 " pending %d bytes, wrapping at %d, error at position %d:\n \n",
4272 es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1,
4273 es->ev_id,
4274 pn, port, es->sid, es->s_flags,
4275 es->state, es->m_flags, es->t_flags,
4276 es->m_clen, es->m_blen,
4277 es->b_flags, es->b_out, es->b_tot,
4278 es->len, es->b_wrap, es->pos);
4279
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004280 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004281 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02004282 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004283 }
Willy Tarreau295a8372011-03-10 11:25:07 +01004284 si->applet.ctx.errors.ptr = 0;
4285 si->applet.ctx.errors.sid = es->sid;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004286 }
4287
Willy Tarreau295a8372011-03-10 11:25:07 +01004288 if (si->applet.ctx.errors.sid != es->sid) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004289 /* the snapshot changed while we were dumping it */
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004290 chunk_appendf(&trash,
Willy Tarreau74808cb2009-03-04 15:53:18 +01004291 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004292 if (bi_putchk(si->ib, &trash) == -1)
Willy Tarreau61b34732009-10-03 23:49:35 +02004293 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004294 goto next;
4295 }
4296
4297 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau295a8372011-03-10 11:25:07 +01004298 while (si->applet.ctx.errors.ptr < es->len && si->applet.ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004299 int newptr;
4300 int newline;
4301
Willy Tarreau295a8372011-03-10 11:25:07 +01004302 newline = si->applet.ctx.errors.bol;
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004303 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 +01004304 if (newptr == si->applet.ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02004305 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004306
Willy Tarreau19d14ef2012-10-29 16:51:55 +01004307 if (bi_putchk(si->ib, &trash) == -1) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01004308 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02004309 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004310 }
Willy Tarreau295a8372011-03-10 11:25:07 +01004311 si->applet.ctx.errors.ptr = newptr;
4312 si->applet.ctx.errors.bol = newline;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004313 };
4314 next:
Willy Tarreau295a8372011-03-10 11:25:07 +01004315 si->applet.ctx.errors.bol = 0;
4316 si->applet.ctx.errors.ptr = -1;
4317 si->applet.ctx.errors.buf++;
4318 if (si->applet.ctx.errors.buf > 1) {
4319 si->applet.ctx.errors.buf = 0;
4320 si->applet.ctx.errors.px = si->applet.ctx.errors.px->next;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004321 }
4322 }
4323
4324 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02004325 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01004326}
4327
Willy Tarreaud5781202012-09-22 19:32:35 +02004328/* parse the "level" argument on the bind lines */
4329static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
4330{
4331 if (!*args[cur_arg + 1]) {
4332 memprintf(err, "'%s' : missing level", args[cur_arg]);
4333 return ERR_ALERT | ERR_FATAL;
4334 }
4335
4336 if (!strcmp(args[cur_arg+1], "user"))
4337 conf->level = ACCESS_LVL_USER;
4338 else if (!strcmp(args[cur_arg+1], "operator"))
4339 conf->level = ACCESS_LVL_OPER;
4340 else if (!strcmp(args[cur_arg+1], "admin"))
4341 conf->level = ACCESS_LVL_ADMIN;
4342 else {
4343 memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')",
4344 args[cur_arg], args[cur_arg+1]);
4345 return ERR_ALERT | ERR_FATAL;
4346 }
4347
4348 return 0;
4349}
4350
Willy Tarreaub24281b2011-02-13 13:16:36 +01004351struct si_applet http_stats_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01004352 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004353 .name = "<STATS>", /* used for logging */
4354 .fct = http_stats_io_handler,
Aman Gupta9a13e842012-04-02 18:57:53 -07004355 .release = NULL,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004356};
4357
Simon Horman9bd2c732011-06-15 15:18:44 +09004358static struct si_applet cli_applet = {
Willy Tarreau3fdb3662012-11-12 00:42:33 +01004359 .obj_type = OBJ_TYPE_APPLET,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004360 .name = "<CLI>", /* used for logging */
4361 .fct = cli_io_handler,
Willy Tarreau5f9a8772012-11-26 02:22:40 +01004362 .release = cli_release_handler,
Willy Tarreaub24281b2011-02-13 13:16:36 +01004363};
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01004364
Willy Tarreau10522fd2008-07-09 20:12:41 +02004365static struct cfg_kw_list cfg_kws = {{ },{
4366 { CFG_GLOBAL, "stats", stats_parse_global },
4367 { 0, NULL, NULL },
4368}};
4369
Willy Tarreaud5781202012-09-22 19:32:35 +02004370static struct bind_kw_list bind_kws = { "STAT", { }, {
4371 { "level", bind_parse_level, 1 }, /* set the unix socket admin level */
4372 { NULL, NULL, 0 },
4373}};
4374
Willy Tarreau10522fd2008-07-09 20:12:41 +02004375__attribute__((constructor))
4376static void __dumpstats_module_init(void)
4377{
4378 cfg_register_keywords(&cfg_kws);
Willy Tarreaud5781202012-09-22 19:32:35 +02004379 bind_register_keywords(&bind_kws);
Willy Tarreau10522fd2008-07-09 20:12:41 +02004380}
4381
Willy Tarreau91861262007-10-17 17:06:05 +02004382/*
4383 * Local variables:
4384 * c-indent-level: 8
4385 * c-basic-offset: 8
4386 * End:
4387 */