blob: 3f88fc50734a93a6154eaec8c48787e92d37b9cc [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>
43#include <proto/buffers.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020044#include <proto/checks.h>
Willy Tarreau91861262007-10-17 17:06:05 +020045#include <proto/dumpstats.h>
46#include <proto/fd.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010047#include <proto/freq_ctr.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020048#include <proto/log.h>
Willy Tarreaua206fa92009-01-25 14:02:00 +010049#include <proto/pipe.h>
Willy Tarreau2a0f4d22011-08-02 11:49:05 +020050#include <proto/protocols.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020051#include <proto/proto_uxst.h>
Willy Tarreau89a63132009-08-16 17:41:45 +020052#include <proto/proxy.h>
Willy Tarreau91861262007-10-17 17:06:05 +020053#include <proto/session.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020054#include <proto/server.h>
Willy Tarreaudded32d2008-11-30 19:48:07 +010055#include <proto/stream_interface.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020056#include <proto/stream_sock.h>
Willy Tarreau4726f532009-03-07 17:25:21 +010057#include <proto/task.h>
Willy Tarreau91861262007-10-17 17:06:05 +020058
Simon Horman9bd2c732011-06-15 15:18:44 +090059static int stats_dump_raw_to_buffer(struct stream_interface *si);
60static int stats_dump_full_sess_to_buffer(struct stream_interface *si);
61static int stats_dump_sess_to_buffer(struct stream_interface *si);
62static int stats_dump_errors_to_buffer(struct stream_interface *si);
Simon Hormanc88b8872011-06-15 15:18:49 +090063static int stats_table_request(struct stream_interface *si, bool show);
Simon Horman9bd2c732011-06-15 15:18:44 +090064static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struct uri_auth *uri);
65static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri);
66
67static struct si_applet cli_applet;
68
69static const char stats_sock_usage_msg[] =
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020070 "Unknown command. Please enter one of the following commands only :\n"
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +020071 " clear counters : clear max statistics counters (add 'all' for all counters)\n"
Willy Tarreau88ee3972010-07-13 13:48:00 +020072 " clear table : remove an entry from a table\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020073 " help : this message\n"
74 " prompt : toggle interactive mode with prompt\n"
75 " quit : disconnect\n"
76 " show info : report information about the running process\n"
77 " show stat : report counters for each proxy and server\n"
78 " show errors : report last request and response errors for each proxy\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +010079 " show sess [id] : report the list of current sessions or dump this session\n"
Willy Tarreau69f58c82010-07-12 17:55:33 +020080 " show table [id]: report table usage stats or dump this table's contents\n"
Willy Tarreau38338fa2009-10-10 18:37:29 +020081 " get weight : report a server's current weight\n"
Willy Tarreau4483d432009-10-10 19:30:08 +020082 " set weight : change a server's weight\n"
Willy Tarreau7aabd112010-01-26 10:59:06 +010083 " set timeout : change a timeout setting\n"
Willy Tarreau2a0f4d22011-08-02 11:49:05 +020084 " set maxconn : change a maxconn setting\n"
Willy Tarreauf5b22872011-09-07 16:13:44 +020085 " set rate-limit : change a rate limiting value\n"
Willy Tarreaua295edc2011-09-07 23:21:03 +020086 " disable : put a server or frontend in maintenance mode\n"
87 " enable : re-enable a server or frontend which is in maintenance mode\n"
88 " shutdown : kill a session or a frontend (eg:to release listening ports)\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020089 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +020090
Simon Horman9bd2c732011-06-15 15:18:44 +090091static const char stats_permission_denied_msg[] =
Willy Tarreau6162db22009-10-10 17:13:00 +020092 "Permission denied\n"
93 "";
94
Willy Tarreau295a8372011-03-10 11:25:07 +010095/* data transmission states for the stats responses */
96enum {
97 STAT_ST_INIT = 0,
98 STAT_ST_HEAD,
99 STAT_ST_INFO,
100 STAT_ST_LIST,
101 STAT_ST_END,
102 STAT_ST_FIN,
103};
104
105/* data transmission states for the stats responses inside a proxy */
106enum {
107 STAT_PX_ST_INIT = 0,
108 STAT_PX_ST_TH,
109 STAT_PX_ST_FE,
110 STAT_PX_ST_LI,
111 STAT_PX_ST_SV,
112 STAT_PX_ST_BE,
113 STAT_PX_ST_END,
114 STAT_PX_ST_FIN,
115};
116
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200117/* This function is called from the session-level accept() in order to instanciate
Willy Tarreaueb472682010-05-28 18:46:57 +0200118 * a new stats socket. It returns a positive value upon success, 0 if the connection
119 * needs to be closed and ignored, or a negative value upon critical failure.
120 */
Simon Horman9bd2c732011-06-15 15:18:44 +0900121static int stats_accept(struct session *s)
Willy Tarreaueb472682010-05-28 18:46:57 +0200122{
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200123 /* we have a dedicated I/O handler for the stats */
Willy Tarreaub24281b2011-02-13 13:16:36 +0100124 stream_int_register_handler(&s->si[1], &cli_applet);
Willy Tarreau7b7a8e92011-03-27 19:53:06 +0200125 copy_target(&s->target, &s->si[1].target); // for logging only
Willy Tarreaubc4af052011-02-13 13:25:14 +0100126 s->si[1].applet.private = s;
127 s->si[1].applet.st1 = 0;
128 s->si[1].applet.st0 = STAT_CLI_INIT;
Willy Tarreaueb472682010-05-28 18:46:57 +0200129
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200130 tv_zero(&s->logs.tv_request);
131 s->logs.t_queue = 0;
132 s->logs.t_connect = 0;
133 s->logs.t_data = 0;
134 s->logs.t_close = 0;
135 s->logs.bytes_in = s->logs.bytes_out = 0;
136 s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
137 s->logs.srv_queue_size = 0; /* we will get this number soon */
Willy Tarreaueb472682010-05-28 18:46:57 +0200138
Willy Tarreaueb472682010-05-28 18:46:57 +0200139 s->req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */
140
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200141 if (s->listener->timeout) {
142 s->req->rto = *s->listener->timeout;
143 s->rep->wto = *s->listener->timeout;
Willy Tarreaueb472682010-05-28 18:46:57 +0200144 }
Willy Tarreaueb472682010-05-28 18:46:57 +0200145 return 1;
Willy Tarreaueb472682010-05-28 18:46:57 +0200146}
147
Willy Tarreau07e9e642010-08-17 21:48:17 +0200148/* allocate a new stats frontend named <name>, and return it
149 * (or NULL in case of lack of memory).
150 */
151static struct proxy *alloc_stats_fe(const char *name)
152{
153 struct proxy *fe;
154
155 fe = (struct proxy *)calloc(1, sizeof(struct proxy));
156 if (!fe)
157 return NULL;
158
Willy Tarreau237250c2011-07-29 01:49:03 +0200159 init_new_proxy(fe);
Willy Tarreau07e9e642010-08-17 21:48:17 +0200160
161 fe->last_change = now.tv_sec;
162 fe->id = strdup("GLOBAL");
163 fe->cap = PR_CAP_FE;
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200164 fe->maxconn = 10; /* default to 10 concurrent connections */
165 fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
166
Willy Tarreau07e9e642010-08-17 21:48:17 +0200167 return fe;
168}
169
Willy Tarreaufbee7132007-10-18 13:53:22 +0200170/* This function parses a "stats" statement in the "global" section. It returns
171 * -1 if there is any error, otherwise zero. If it returns -1, it may write an
172 * error message into ther <err> buffer, for at most <errlen> bytes, trailing
173 * zero included. The trailing '\n' must not be written. The function must be
174 * called with <args> pointing to the first word after "stats".
175 */
Willy Tarreau10522fd2008-07-09 20:12:41 +0200176static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
177 struct proxy *defpx, char *err, int errlen)
Willy Tarreaufbee7132007-10-18 13:53:22 +0200178{
Willy Tarreau10522fd2008-07-09 20:12:41 +0200179 args++;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200180 if (!strcmp(args[0], "socket")) {
Andreas Kohn16171e22011-01-19 20:29:32 +0100181 struct sockaddr_un *su;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200182 int cur_arg;
183
184 if (*args[1] == 0) {
185 snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket");
186 return -1;
187 }
188
189 if (global.stats_sock.state != LI_NEW) {
190 snprintf(err, errlen, "'stats socket' already specified in global section");
191 return -1;
192 }
193
Andreas Kohn16171e22011-01-19 20:29:32 +0100194 su = str2sun(args[1]);
195 if (!su) {
196 snprintf(err, errlen, "'stats socket' path would require truncation");
197 return -1;
198 }
199 memcpy(&global.stats_sock.addr, su, sizeof(struct sockaddr_un)); // guaranteed to fit
Willy Tarreaufbee7132007-10-18 13:53:22 +0200200
Willy Tarreau89a63132009-08-16 17:41:45 +0200201 if (!global.stats_fe) {
Willy Tarreau07e9e642010-08-17 21:48:17 +0200202 if ((global.stats_fe = alloc_stats_fe("GLOBAL")) == NULL) {
Willy Tarreau89a63132009-08-16 17:41:45 +0200203 snprintf(err, errlen, "out of memory");
204 return -1;
205 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200206 }
207
Willy Tarreaufbee7132007-10-18 13:53:22 +0200208 global.stats_sock.state = LI_INIT;
Willy Tarreau3c63fd82011-09-07 18:00:47 +0200209 global.stats_sock.options = LI_O_UNLIMITED;
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200210 global.stats_sock.accept = session_accept;
211 global.stats_fe->accept = stats_accept;
Willy Tarreau104eb362009-08-16 18:51:29 +0200212 global.stats_sock.handler = process_session;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200213 global.stats_sock.analysers = 0;
Willy Tarreau2c9f5b12009-08-16 19:12:36 +0200214 global.stats_sock.nice = -64; /* we want to boost priority for local stats */
Willy Tarreaueb472682010-05-28 18:46:57 +0200215 global.stats_sock.frontend = global.stats_fe;
Willy Tarreau6162db22009-10-10 17:13:00 +0200216 global.stats_sock.perm.ux.level = ACCESS_LVL_OPER; /* default access level */
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200217 global.stats_sock.maxconn = global.stats_fe->maxconn;
Willy Tarreau89a63132009-08-16 17:41:45 +0200218 global.stats_sock.timeout = &global.stats_fe->timeout.client;
219
220 global.stats_sock.next = global.stats_fe->listen;
221 global.stats_fe->listen = &global.stats_sock;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200222
223 cur_arg = 2;
224 while (*args[cur_arg]) {
225 if (!strcmp(args[cur_arg], "uid")) {
226 global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]);
227 cur_arg += 2;
228 }
229 else if (!strcmp(args[cur_arg], "gid")) {
230 global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]);
231 cur_arg += 2;
232 }
233 else if (!strcmp(args[cur_arg], "mode")) {
234 global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
235 cur_arg += 2;
236 }
237 else if (!strcmp(args[cur_arg], "user")) {
238 struct passwd *user;
239 user = getpwnam(args[cur_arg + 1]);
240 if (!user) {
241 snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')",
242 args[cur_arg + 1]);
243 return -1;
244 }
245 global.stats_sock.perm.ux.uid = user->pw_uid;
246 cur_arg += 2;
247 }
248 else if (!strcmp(args[cur_arg], "group")) {
249 struct group *group;
250 group = getgrnam(args[cur_arg + 1]);
251 if (!group) {
252 snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')",
253 args[cur_arg + 1]);
254 return -1;
255 }
256 global.stats_sock.perm.ux.gid = group->gr_gid;
257 cur_arg += 2;
258 }
Willy Tarreau6162db22009-10-10 17:13:00 +0200259 else if (!strcmp(args[cur_arg], "level")) {
260 if (!strcmp(args[cur_arg+1], "user"))
261 global.stats_sock.perm.ux.level = ACCESS_LVL_USER;
262 else if (!strcmp(args[cur_arg+1], "operator"))
263 global.stats_sock.perm.ux.level = ACCESS_LVL_OPER;
264 else if (!strcmp(args[cur_arg+1], "admin"))
265 global.stats_sock.perm.ux.level = ACCESS_LVL_ADMIN;
266 else {
267 snprintf(err, errlen, "'stats socket level' only supports 'user', 'operator', and 'admin'");
268 return -1;
269 }
270 cur_arg += 2;
271 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200272 else {
Willy Tarreau6162db22009-10-10 17:13:00 +0200273 snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', 'level', and 'mode'");
Willy Tarreaufbee7132007-10-18 13:53:22 +0200274 return -1;
275 }
276 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100277
Willy Tarreaufbee7132007-10-18 13:53:22 +0200278 uxst_add_listener(&global.stats_sock);
279 global.maxsock++;
280 }
281 else if (!strcmp(args[0], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100282 unsigned timeout;
283 const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS);
284
285 if (res) {
286 snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res);
287 return -1;
288 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200289
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100290 if (!timeout) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200291 snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'");
292 return -1;
293 }
Willy Tarreau07e9e642010-08-17 21:48:17 +0200294 if (!global.stats_fe) {
295 if ((global.stats_fe = alloc_stats_fe("GLOBAL")) == NULL) {
296 snprintf(err, errlen, "out of memory");
297 return -1;
298 }
299 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200300 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200301 }
302 else if (!strcmp(args[0], "maxconn")) {
303 int maxconn = atol(args[1]);
304
305 if (maxconn <= 0) {
306 snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'");
307 return -1;
308 }
Willy Tarreauc2adf8b2011-09-07 12:13:34 +0200309
310 if (!global.stats_fe) {
311 if ((global.stats_fe = alloc_stats_fe("GLOBAL")) == NULL) {
312 snprintf(err, errlen, "out of memory");
313 return -1;
314 }
315 }
316 global.stats_fe->maxconn = maxconn;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200317 }
318 else {
319 snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section");
320 return -1;
321 }
322 return 0;
323}
324
Simon Horman9bd2c732011-06-15 15:18:44 +0900325static int print_csv_header(struct chunk *msg)
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100326{
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200327 return chunk_printf(msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100328 "# pxname,svname,"
329 "qcur,qmax,"
330 "scur,smax,slim,stot,"
331 "bin,bout,"
332 "dreq,dresp,"
333 "ereq,econ,eresp,"
334 "wretr,wredis,"
335 "status,weight,act,bck,"
336 "chkfail,chkdown,lastchg,downtime,qlimit,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +0200337 "pid,iid,sid,throttle,lbtot,tracked,type,"
338 "rate,rate_lim,rate_max,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200339 "check_status,check_code,check_duration,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100340 "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,"
Willy Tarreauae526782010-03-04 20:34:23 +0100341 "req_rate,req_rate_max,req_tot,"
342 "cli_abrt,srv_abrt,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100343 "\n");
344}
345
Simon Hormand9366582011-06-15 15:18:45 +0900346/* print a string of text buffer to <out>. The format is :
347 * Non-printable chars \t, \n, \r and \e are * encoded in C format.
348 * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped.
349 * Print stopped if null char or <bsize> is reached, or if no more place in the chunk.
350 */
351static int dump_text(struct chunk *out, const char *buf, int bsize)
352{
353 unsigned char c;
354 int ptr = 0;
355
356 while (buf[ptr] && ptr < bsize) {
357 c = buf[ptr];
358 if (isprint(c) && isascii(c) && c != '\\' && c != ' ') {
359 if (out->len > out->size - 1)
360 break;
361 out->str[out->len++] = c;
362 }
363 else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') {
364 if (out->len > out->size - 2)
365 break;
366 out->str[out->len++] = '\\';
367 switch (c) {
368 case ' ': c = ' '; break;
369 case '\t': c = 't'; break;
370 case '\n': c = 'n'; break;
371 case '\r': c = 'r'; break;
372 case '\e': c = 'e'; break;
373 case '\\': c = '\\'; break;
374 }
375 out->str[out->len++] = c;
376 }
377 else {
378 if (out->len > out->size - 4)
379 break;
380 out->str[out->len++] = '\\';
381 out->str[out->len++] = 'x';
382 out->str[out->len++] = hextab[(c >> 4) & 0xF];
383 out->str[out->len++] = hextab[c & 0xF];
384 }
385 ptr++;
386 }
387
388 return ptr;
389}
390
391/* print a buffer in hexa.
392 * Print stopped if <bsize> is reached, or if no more place in the chunk.
393 */
394static int dump_binary(struct chunk *out, const char *buf, int bsize)
395{
396 unsigned char c;
397 int ptr = 0;
398
399 while (ptr < bsize) {
400 c = buf[ptr];
401
402 if (out->len > out->size - 2)
403 break;
404 out->str[out->len++] = hextab[(c >> 4) & 0xF];
405 out->str[out->len++] = hextab[c & 0xF];
406
407 ptr++;
408 }
409 return ptr;
410}
411
412/* Dump the status of a table to a stream interface's
413 * read buffer. It returns 0 if the output buffer is full
414 * and needs to be called again, otherwise non-zero.
415 */
416static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si,
417 struct proxy *proxy, struct proxy *target)
418{
419 struct session *s = si->applet.private;
420
421 chunk_printf(msg, "# table: %s, type: %s, size:%d, used:%d\n",
422 proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current);
423
424 /* any other information should be dumped here */
425
426 if (target && s->listener->perm.ux.level < ACCESS_LVL_OPER)
427 chunk_printf(msg, "# contents not dumped due to insufficient privileges\n");
428
429 if (buffer_feed_chunk(si->ib, msg) >= 0)
430 return 0;
431
432 return 1;
433}
434
435/* Dump the a table entry to a stream interface's
436 * read buffer. It returns 0 if the output buffer is full
437 * and needs to be called again, otherwise non-zero.
438 */
439static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si,
440 struct proxy *proxy, struct stksess *entry)
441{
442 int dt;
443
444 chunk_printf(msg, "%p:", entry);
445
446 if (proxy->table.type == STKTABLE_TYPE_IP) {
447 char addr[INET_ADDRSTRLEN];
448 inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr));
449 chunk_printf(msg, " key=%s", addr);
450 }
451 else if (proxy->table.type == STKTABLE_TYPE_IPV6) {
452 char addr[INET6_ADDRSTRLEN];
453 inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr));
454 chunk_printf(msg, " key=%s", addr);
455 }
456 else if (proxy->table.type == STKTABLE_TYPE_INTEGER) {
457 chunk_printf(msg, " key=%u", *(unsigned int *)entry->key.key);
458 }
459 else if (proxy->table.type == STKTABLE_TYPE_STRING) {
460 chunk_printf(msg, " key=");
461 dump_text(msg, (const char *)entry->key.key, proxy->table.key_size);
462 }
463 else {
464 chunk_printf(msg, " key=");
465 dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size);
466 }
467
468 chunk_printf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire));
469
470 for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) {
471 void *ptr;
472
473 if (proxy->table.data_ofs[dt] == 0)
474 continue;
475 if (stktable_data_types[dt].arg_type == ARG_T_DELAY)
476 chunk_printf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u);
477 else
478 chunk_printf(msg, " %s=", stktable_data_types[dt].name);
479
480 ptr = stktable_data_ptr(&proxy->table, entry, dt);
481 switch (stktable_data_types[dt].std_type) {
482 case STD_T_SINT:
483 chunk_printf(msg, "%d", stktable_data_cast(ptr, std_t_sint));
484 break;
485 case STD_T_UINT:
486 chunk_printf(msg, "%u", stktable_data_cast(ptr, std_t_uint));
487 break;
488 case STD_T_ULL:
489 chunk_printf(msg, "%lld", stktable_data_cast(ptr, std_t_ull));
490 break;
491 case STD_T_FRQP:
492 chunk_printf(msg, "%d",
493 read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
494 proxy->table.data_arg[dt].u));
495 break;
496 }
497 }
498 chunk_printf(msg, "\n");
499
500 if (buffer_feed_chunk(si->ib, msg) >= 0)
501 return 0;
502
503 return 1;
504}
505
Simon Horman17bce342011-06-15 15:18:47 +0900506static void stats_sock_table_key_request(struct stream_interface *si, char **args, bool show)
Simon Horman121f3052011-06-15 15:18:46 +0900507{
508 struct session *s = si->applet.private;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900509 struct proxy *px = si->applet.ctx.table.target;
Simon Horman121f3052011-06-15 15:18:46 +0900510 struct stksess *ts;
Simon Hormancec9a222011-06-15 15:18:51 +0900511 uint32_t uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900512 unsigned char ip6_key[sizeof(struct in6_addr)];
Simon Horman121f3052011-06-15 15:18:46 +0900513
Simon Hormand5b9fd92011-06-15 15:18:48 +0900514 si->applet.st0 = STAT_CLI_OUTPUT;
Simon Horman121f3052011-06-15 15:18:46 +0900515
516 if (!*args[4]) {
517 si->applet.ctx.cli.msg = "Key value expected\n";
518 si->applet.st0 = STAT_CLI_PRINT;
519 return;
520 }
521
Simon Hormanc5b89f62011-06-15 15:18:50 +0900522 switch (px->table.type) {
523 case STKTABLE_TYPE_IP:
Simon Hormancec9a222011-06-15 15:18:51 +0900524 uint32_key = htonl(inetaddr_host(args[4]));
525 static_table_key.key = &uint32_key;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900526 break;
527 case STKTABLE_TYPE_IPV6:
528 inet_pton(AF_INET6, args[4], ip6_key);
529 static_table_key.key = &ip6_key;
530 break;
Simon Hormancec9a222011-06-15 15:18:51 +0900531 case STKTABLE_TYPE_INTEGER:
532 {
533 char *endptr;
534 unsigned long val;
535 errno = 0;
536 val = strtoul(args[4], &endptr, 10);
537 if ((errno == ERANGE && val == ULONG_MAX) ||
538 (errno != 0 && val == 0) || endptr == args[4] ||
539 val > 0xffffffff) {
540 si->applet.ctx.cli.msg = "Invalid key\n";
541 si->applet.st0 = STAT_CLI_PRINT;
542 return;
543 }
544 uint32_key = (uint32_t) val;
545 static_table_key.key = &uint32_key;
546 break;
547 }
548 break;
Simon Horman619e3cc2011-06-15 15:18:52 +0900549 case STKTABLE_TYPE_STRING:
550 static_table_key.key = args[4];
551 static_table_key.key_len = strlen(args[4]);
552 break;
Simon Hormanc5b89f62011-06-15 15:18:50 +0900553 default:
Simon Horman17bce342011-06-15 15:18:47 +0900554 if (show)
Simon Hormancec9a222011-06-15 15:18:51 +0900555 si->applet.ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6 and integer is not supported\n";
Simon Horman17bce342011-06-15 15:18:47 +0900556 else
Simon Hormancec9a222011-06-15 15:18:51 +0900557 si->applet.ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6 and integer is not supported\n";
Simon Horman121f3052011-06-15 15:18:46 +0900558 si->applet.st0 = STAT_CLI_PRINT;
559 return;
560 }
561
562 /* check permissions */
563 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
564 si->applet.ctx.cli.msg = stats_permission_denied_msg;
565 si->applet.st0 = STAT_CLI_PRINT;
566 return;
567 }
568
569 ts = stktable_lookup_key(&px->table, &static_table_key);
Simon Horman17bce342011-06-15 15:18:47 +0900570 if (!ts)
571 return;
572
573 if (show) {
574 struct chunk msg;
575 chunk_init(&msg, trash, sizeof(trash));
576 if (!stats_dump_table_head_to_buffer(&msg, si, px, px))
577 return;
578 stats_dump_table_entry_to_buffer(&msg, si, px, ts);
Simon Horman121f3052011-06-15 15:18:46 +0900579 return;
580 }
Simon Horman17bce342011-06-15 15:18:47 +0900581
582 if (ts->ref_cnt) {
Simon Horman121f3052011-06-15 15:18:46 +0900583 /* don't delete an entry which is currently referenced */
584 si->applet.ctx.cli.msg = "Entry currently in use, cannot remove\n";
585 si->applet.st0 = STAT_CLI_PRINT;
586 return;
587 }
588
589 stksess_kill(&px->table, ts);
590}
591
Simon Hormand5b9fd92011-06-15 15:18:48 +0900592static void stats_sock_table_data_request(struct stream_interface *si, char **args)
593{
594 /* condition on stored data value */
595 si->applet.ctx.table.data_type = stktable_get_data_type(args[3] + 5);
596 if (si->applet.ctx.table.data_type < 0) {
597 si->applet.ctx.cli.msg = "Unknown data type\n";
598 si->applet.st0 = STAT_CLI_PRINT;
599 return;
600 }
601
602 if (!((struct proxy *)si->applet.ctx.table.target)->table.data_ofs[si->applet.ctx.table.data_type]) {
603 si->applet.ctx.cli.msg = "Data type not stored in this table\n";
604 si->applet.st0 = STAT_CLI_PRINT;
605 return;
606 }
607
608 si->applet.ctx.table.data_op = get_std_op(args[4]);
609 if (si->applet.ctx.table.data_op < 0) {
610 si->applet.ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n";
611 si->applet.st0 = STAT_CLI_PRINT;
612 return;
613 }
614
615 if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &si->applet.ctx.table.value) != 0) {
616 si->applet.ctx.cli.msg = "Require a valid integer value to compare against\n";
617 si->applet.st0 = STAT_CLI_PRINT;
618 return;
619 }
620}
621
622static void stats_sock_table_request(struct stream_interface *si, char **args, bool show)
623{
624 si->applet.ctx.table.data_type = -1;
625 si->applet.state = STAT_ST_INIT;
Willy Tarreaue17a8d02011-08-24 08:23:34 +0200626 si->applet.ctx.table.target = NULL;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900627 si->applet.ctx.table.proxy = NULL;
628 si->applet.ctx.table.entry = NULL;
Simon Hormanc88b8872011-06-15 15:18:49 +0900629 if (show)
630 si->applet.st0 = STAT_CLI_O_TAB;
631 else
632 si->applet.st0 = STAT_CLI_O_CLR;
Simon Hormand5b9fd92011-06-15 15:18:48 +0900633
634 if (*args[2]) {
635 si->applet.ctx.table.target = find_stktable(args[2]);
636 if (!si->applet.ctx.table.target) {
637 si->applet.ctx.cli.msg = "No such table\n";
638 si->applet.st0 = STAT_CLI_PRINT;
639 return;
640 }
641 }
642 else {
643 if (!show)
644 goto err_args;
645 return;
646 }
647
648 if (strcmp(args[3], "key") == 0)
649 stats_sock_table_key_request(si, args, show);
Simon Hormanc88b8872011-06-15 15:18:49 +0900650 else if (strncmp(args[3], "data.", 5) == 0)
Simon Hormand5b9fd92011-06-15 15:18:48 +0900651 stats_sock_table_data_request(si, args);
Simon Hormanc88b8872011-06-15 15:18:49 +0900652 else if (*args[3])
Simon Hormand5b9fd92011-06-15 15:18:48 +0900653 goto err_args;
654
655 return;
656
657err_args:
658 if (show)
659 si->applet.ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n";
660 else
Simon Hormanc88b8872011-06-15 15:18:49 +0900661 si->applet.ctx.cli.msg = "Required arguments: <table> \"data.<store_data_type>\" <operator> <value> or <table> key <key>\n";
Simon Hormand5b9fd92011-06-15 15:18:48 +0900662 si->applet.st0 = STAT_CLI_PRINT;
663}
664
Willy Tarreau532a4502011-09-07 22:37:44 +0200665/* Expects to find a frontend named <arg> and returns it, otherwise displays various
666 * adequate error messages and returns NULL. This function also expects the session
667 * level to be admin.
668 */
669static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg)
670{
671 struct proxy *px;
672
673 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
674 si->applet.ctx.cli.msg = stats_permission_denied_msg;
675 si->applet.st0 = STAT_CLI_PRINT;
676 return NULL;
677 }
678
679 if (!*arg) {
680 si->applet.ctx.cli.msg = "A frontend name is expected.\n";
681 si->applet.st0 = STAT_CLI_PRINT;
682 return NULL;
683 }
684
685 px = findproxy(arg, PR_CAP_FE);
686 if (!px) {
687 si->applet.ctx.cli.msg = "No such frontend.\n";
688 si->applet.st0 = STAT_CLI_PRINT;
689 return NULL;
690 }
691 return px;
692}
693
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200694/* Expects to find a backend and a server in <arg> under the form <backend>/<server>,
695 * and returns the pointer to the server. Otherwise, display adequate error messages
696 * and returns NULL. This function also expects the session level to be admin. Note:
697 * the <arg> is modified to remove the '/'.
698 */
699static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg)
700{
701 struct proxy *px;
702 struct server *sv;
703 char *line;
704
705 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
706 si->applet.ctx.cli.msg = stats_permission_denied_msg;
707 si->applet.st0 = STAT_CLI_PRINT;
708 return NULL;
709 }
710
711 /* split "backend/server" and make <line> point to server */
712 for (line = arg; *line; line++)
713 if (*line == '/') {
714 *line++ = '\0';
715 break;
716 }
717
718 if (!*line || !*arg) {
719 si->applet.ctx.cli.msg = "Require 'backend/server'.\n";
720 si->applet.st0 = STAT_CLI_PRINT;
721 return NULL;
722 }
723
724 if (!get_backend_server(arg, line, &px, &sv)) {
725 si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
726 si->applet.st0 = STAT_CLI_PRINT;
727 return NULL;
728 }
729
730 if (px->state == PR_STSTOPPED) {
731 si->applet.ctx.cli.msg = "Proxy is disabled.\n";
732 si->applet.st0 = STAT_CLI_PRINT;
733 return NULL;
734 }
735
736 return sv;
737}
738
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200739/* Processes the stats interpreter on the statistics socket. This function is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200740 * called from an applet running in a stream interface. The function returns 1
Willy Tarreaubc4af052011-02-13 13:25:14 +0100741 * if the request was understood, otherwise zero. It sets si->applet.st0 to a value
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200742 * designating the function which will have to process the request, which can
743 * also be the print function to display the return message set into cli.msg.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200744 */
Simon Horman9bd2c732011-06-15 15:18:44 +0900745static int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200746{
Willy Tarreaubc4af052011-02-13 13:25:14 +0100747 struct session *s = si->applet.private;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200748 char *args[MAX_STATS_ARGS + 1];
749 int arg;
750
751 while (isspace((unsigned char)*line))
752 line++;
753
754 arg = 0;
755 args[arg] = line;
756
757 while (*line && arg < MAX_STATS_ARGS) {
758 if (isspace((unsigned char)*line)) {
759 *line++ = '\0';
760
761 while (isspace((unsigned char)*line))
762 line++;
763
764 args[++arg] = line;
765 continue;
766 }
767
768 line++;
769 }
770
771 while (++arg <= MAX_STATS_ARGS)
772 args[arg] = line;
773
Willy Tarreau295a8372011-03-10 11:25:07 +0100774 si->applet.ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200775 if (strcmp(args[0], "show") == 0) {
776 if (strcmp(args[1], "stat") == 0) {
777 if (*args[2] && *args[3] && *args[4]) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100778 si->applet.ctx.stats.flags |= STAT_BOUND;
779 si->applet.ctx.stats.iid = atoi(args[2]);
780 si->applet.ctx.stats.type = atoi(args[3]);
781 si->applet.ctx.stats.sid = atoi(args[4]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200782 }
783
Willy Tarreau295a8372011-03-10 11:25:07 +0100784 si->applet.ctx.stats.flags |= STAT_SHOW_STAT;
785 si->applet.ctx.stats.flags |= STAT_FMT_CSV;
786 si->applet.state = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100787 si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200788 }
789 else if (strcmp(args[1], "info") == 0) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100790 si->applet.ctx.stats.flags |= STAT_SHOW_INFO;
791 si->applet.ctx.stats.flags |= STAT_FMT_CSV;
792 si->applet.state = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100793 si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200794 }
795 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100796 si->applet.state = STAT_ST_INIT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200797 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100798 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100799 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200800 return 1;
801 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100802 if (*args[2])
Willy Tarreau295a8372011-03-10 11:25:07 +0100803 si->applet.ctx.sess.target = (void *)strtoul(args[2], NULL, 0);
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100804 else
Willy Tarreau295a8372011-03-10 11:25:07 +0100805 si->applet.ctx.sess.target = NULL;
806 si->applet.ctx.sess.section = 0; /* start with session status */
807 si->applet.ctx.sess.pos = 0;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100808 si->applet.st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200809 }
810 else if (strcmp(args[1], "errors") == 0) {
Willy Tarreau6162db22009-10-10 17:13:00 +0200811 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100812 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100813 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200814 return 1;
815 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200816 if (*args[2])
Willy Tarreau295a8372011-03-10 11:25:07 +0100817 si->applet.ctx.errors.iid = atoi(args[2]);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200818 else
Willy Tarreau295a8372011-03-10 11:25:07 +0100819 si->applet.ctx.errors.iid = -1;
820 si->applet.ctx.errors.px = NULL;
821 si->applet.state = STAT_ST_INIT;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100822 si->applet.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200823 }
Willy Tarreau69f58c82010-07-12 17:55:33 +0200824 else if (strcmp(args[1], "table") == 0) {
Simon Hormand5b9fd92011-06-15 15:18:48 +0900825 stats_sock_table_request(si, args, true);
Willy Tarreau69f58c82010-07-12 17:55:33 +0200826 }
Willy Tarreau88ee3972010-07-13 13:48:00 +0200827 else { /* neither "stat" nor "info" nor "sess" nor "errors" no "table" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200828 return 0;
829 }
830 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200831 else if (strcmp(args[0], "clear") == 0) {
832 if (strcmp(args[1], "counters") == 0) {
833 struct proxy *px;
834 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200835 struct listener *li;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200836 int clrall = 0;
837
838 if (strcmp(args[2], "all") == 0)
839 clrall = 1;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200840
Willy Tarreau6162db22009-10-10 17:13:00 +0200841 /* check permissions */
842 if (s->listener->perm.ux.level < ACCESS_LVL_OPER ||
843 (clrall && s->listener->perm.ux.level < ACCESS_LVL_ADMIN)) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100844 si->applet.ctx.cli.msg = stats_permission_denied_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +0100845 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200846 return 1;
847 }
848
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200849 for (px = proxy; px; px = px->next) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100850 if (clrall) {
851 memset(&px->be_counters, 0, sizeof(px->be_counters));
852 memset(&px->fe_counters, 0, sizeof(px->fe_counters));
853 }
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200854 else {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100855 px->be_counters.conn_max = 0;
856 px->be_counters.p.http.rps_max = 0;
857 px->be_counters.sps_max = 0;
858 px->be_counters.cps_max = 0;
859 px->be_counters.nbpend_max = 0;
860
861 px->fe_counters.conn_max = 0;
862 px->fe_counters.p.http.rps_max = 0;
863 px->fe_counters.sps_max = 0;
864 px->fe_counters.cps_max = 0;
865 px->fe_counters.nbpend_max = 0;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200866 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200867
868 for (sv = px->srv; sv; sv = sv->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200869 if (clrall)
870 memset(&sv->counters, 0, sizeof(sv->counters));
871 else {
872 sv->counters.cur_sess_max = 0;
873 sv->counters.nbpend_max = 0;
874 sv->counters.sps_max = 0;
875 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200876
877 for (li = px->listen; li; li = li->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200878 if (li->counters) {
879 if (clrall)
880 memset(li->counters, 0, sizeof(*li->counters));
881 else
882 li->counters->conn_max = 0;
883 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200884 }
885
Willy Tarreau81c25d02011-09-07 15:17:21 +0200886 global.cps_max = 0;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200887 return 1;
888 }
Willy Tarreau88ee3972010-07-13 13:48:00 +0200889 else if (strcmp(args[1], "table") == 0) {
Simon Hormand5b9fd92011-06-15 15:18:48 +0900890 stats_sock_table_request(si, args, false);
Willy Tarreau88ee3972010-07-13 13:48:00 +0200891 /* end of processing */
892 return 1;
893 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200894 else {
Willy Tarreau88ee3972010-07-13 13:48:00 +0200895 /* unknown "clear" argument */
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200896 return 0;
897 }
898 }
Willy Tarreau38338fa2009-10-10 18:37:29 +0200899 else if (strcmp(args[0], "get") == 0) {
900 if (strcmp(args[1], "weight") == 0) {
901 struct proxy *px;
902 struct server *sv;
903
904 /* split "backend/server" and make <line> point to server */
905 for (line = args[2]; *line; line++)
906 if (*line == '/') {
907 *line++ = '\0';
908 break;
909 }
910
911 if (!*line) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100912 si->applet.ctx.cli.msg = "Require 'backend/server'.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +0100913 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +0200914 return 1;
915 }
916
917 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100918 si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +0100919 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +0200920 return 1;
921 }
922
923 /* return server's effective weight at the moment */
924 snprintf(trash, sizeof(trash), "%d (initial %d)\n", sv->uweight, sv->iweight);
925 buffer_feed(si->ib, trash);
926 return 1;
927 }
928 else { /* not "get weight" */
929 return 0;
930 }
931 }
Willy Tarreau4483d432009-10-10 19:30:08 +0200932 else if (strcmp(args[0], "set") == 0) {
933 if (strcmp(args[1], "weight") == 0) {
934 struct proxy *px;
935 struct server *sv;
936 int w;
937
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200938 sv = expect_server_admin(s, si, args[2]);
939 if (!sv)
Willy Tarreau4483d432009-10-10 19:30:08 +0200940 return 1;
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200941 px = sv->proxy;
Willy Tarreau4483d432009-10-10 19:30:08 +0200942
Willy Tarreaud52c41e2011-09-07 23:41:01 +0200943 /* if the weight is terminated with '%', it is set relative to
944 * the initial weight, otherwise it is absolute.
945 */
946 if (!*args[3]) {
947 si->applet.ctx.cli.msg = "Require <weight> or <weight%>.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +0100948 si->applet.st0 = STAT_CLI_PRINT;
Cyril Bonté613f0df2011-03-03 20:49:04 +0100949 return 1;
950 }
951
Willy Tarreau4483d432009-10-10 19:30:08 +0200952 w = atoi(args[3]);
953 if (strchr(args[3], '%') != NULL) {
954 if (w < 0 || w > 100) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100955 si->applet.ctx.cli.msg = "Relative weight can only be set between 0 and 100% inclusive.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +0100956 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200957 return 1;
958 }
959 w = sv->iweight * w / 100;
960 }
961 else {
962 if (w < 0 || w > 256) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100963 si->applet.ctx.cli.msg = "Absolute weight can only be between 0 and 256 inclusive.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +0100964 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200965 return 1;
966 }
967 }
968
969 if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) {
Willy Tarreau295a8372011-03-10 11:25:07 +0100970 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 +0100971 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200972 return 1;
973 }
974
975 sv->uweight = w;
976
977 if (px->lbprm.algo & BE_LB_PROP_DYN) {
978 /* we must take care of not pushing the server to full throttle during slow starts */
979 if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN))
980 sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart;
981 else
982 sv->eweight = BE_WEIGHT_SCALE;
983 sv->eweight *= sv->uweight;
984 } else {
985 sv->eweight = sv->uweight;
986 }
987
988 /* static LB algorithms are a bit harder to update */
989 if (px->lbprm.update_server_eweight)
990 px->lbprm.update_server_eweight(sv);
991 else if (sv->eweight)
992 px->lbprm.set_server_status_up(sv);
993 else
994 px->lbprm.set_server_status_down(sv);
995
996 return 1;
997 }
Willy Tarreau7aabd112010-01-26 10:59:06 +0100998 else if (strcmp(args[1], "timeout") == 0) {
999 if (strcmp(args[2], "cli") == 0) {
1000 unsigned timeout;
1001 const char *res;
1002
1003 if (!*args[3]) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001004 si->applet.ctx.cli.msg = "Expects an integer value.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001005 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001006 return 1;
1007 }
1008
1009 res = parse_time_err(args[3], &timeout, TIME_UNIT_S);
1010 if (res || timeout < 1) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001011 si->applet.ctx.cli.msg = "Invalid timeout value.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001012 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001013 return 1;
1014 }
1015
1016 s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000);
1017 return 1;
1018 }
1019 else {
Willy Tarreau295a8372011-03-10 11:25:07 +01001020 si->applet.ctx.cli.msg = "'set timeout' only supports 'cli'.\n";
Willy Tarreaubc4af052011-02-13 13:25:14 +01001021 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau7aabd112010-01-26 10:59:06 +01001022 return 1;
1023 }
1024 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001025 else if (strcmp(args[1], "maxconn") == 0) {
1026 if (strcmp(args[2], "frontend") == 0) {
1027 struct proxy *px;
1028 struct listener *l;
1029 int v;
1030
Willy Tarreau532a4502011-09-07 22:37:44 +02001031 px = expect_frontend_admin(s, si, args[3]);
1032 if (!px)
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001033 return 1;
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001034
1035 if (!*args[4]) {
1036 si->applet.ctx.cli.msg = "Integer value expected.\n";
1037 si->applet.st0 = STAT_CLI_PRINT;
1038 return 1;
1039 }
1040
1041 v = atoi(args[4]);
1042 /* check for unlimited values, we restore default setting (cfg_maxpconn) */
1043 if (v < 1) {
1044 si->applet.ctx.cli.msg = "Value out of range.\n";
1045 si->applet.st0 = STAT_CLI_PRINT;
1046 return 1;
1047 }
1048
1049 /* OK, the value is fine, so we assign it to the proxy and to all of
1050 * its listeners. The blocked ones will be dequeued.
1051 */
1052 px->maxconn = v;
1053 for (l = px->listen; l != NULL; l = l->next) {
1054 l->maxconn = v;
1055 if (l->state == LI_FULL)
1056 resume_listener(l);
1057 }
1058
1059 if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue))
1060 dequeue_all_listeners(&s->fe->listener_queue);
1061
1062 return 1;
1063 }
Willy Tarreau91886b62011-09-07 14:38:31 +02001064 else if (strcmp(args[2], "global") == 0) {
1065 int v;
1066
1067 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
1068 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1069 si->applet.st0 = STAT_CLI_PRINT;
1070 return 1;
1071 }
1072
1073 if (!*args[3]) {
1074 si->applet.ctx.cli.msg = "Expects an integer value.\n";
1075 si->applet.st0 = STAT_CLI_PRINT;
1076 return 1;
1077 }
1078
1079 v = atoi(args[3]);
1080 if (v > global.hardmaxconn) {
1081 si->applet.ctx.cli.msg = "Value out of range.\n";
1082 si->applet.st0 = STAT_CLI_PRINT;
1083 return 1;
1084 }
1085
1086 /* check for unlimited values */
1087 if (v <= 0)
1088 v = global.hardmaxconn;
1089
1090 global.maxconn = v;
1091
1092 /* Dequeues all of the listeners waiting for a resource */
1093 if (!LIST_ISEMPTY(&global_listener_queue))
1094 dequeue_all_listeners(&global_listener_queue);
1095
1096 return 1;
1097 }
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001098 else {
Willy Tarreau91886b62011-09-07 14:38:31 +02001099 si->applet.ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n";
Willy Tarreau2a0f4d22011-08-02 11:49:05 +02001100 si->applet.st0 = STAT_CLI_PRINT;
1101 return 1;
1102 }
1103 }
Willy Tarreauf5b22872011-09-07 16:13:44 +02001104 else if (strcmp(args[1], "rate-limit") == 0) {
1105 if (strcmp(args[2], "connections") == 0) {
1106 if (strcmp(args[3], "global") == 0) {
1107 int v;
1108
1109 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
1110 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1111 si->applet.st0 = STAT_CLI_PRINT;
1112 return 1;
1113 }
1114
1115 if (!*args[4]) {
1116 si->applet.ctx.cli.msg = "Expects an integer value.\n";
1117 si->applet.st0 = STAT_CLI_PRINT;
1118 return 1;
1119 }
1120
1121 v = atoi(args[4]);
1122 if (v < 0) {
1123 si->applet.ctx.cli.msg = "Value out of range.\n";
1124 si->applet.st0 = STAT_CLI_PRINT;
1125 return 1;
1126 }
1127
1128 global.cps_lim = v;
1129
1130 /* Dequeues all of the listeners waiting for a resource */
1131 if (!LIST_ISEMPTY(&global_listener_queue))
1132 dequeue_all_listeners(&global_listener_queue);
1133
1134 return 1;
1135 }
1136 else {
1137 si->applet.ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n";
1138 si->applet.st0 = STAT_CLI_PRINT;
1139 return 1;
1140 }
1141 }
1142 else {
1143 si->applet.ctx.cli.msg = "'set rate-limit' only supports 'connections'.\n";
1144 si->applet.st0 = STAT_CLI_PRINT;
1145 return 1;
1146 }
1147 }
Willy Tarreau7aabd112010-01-26 10:59:06 +01001148 else { /* unknown "set" parameter */
Willy Tarreau4483d432009-10-10 19:30:08 +02001149 return 0;
1150 }
1151 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001152 else if (strcmp(args[0], "enable") == 0) {
1153 if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001154 struct server *sv;
1155
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001156 sv = expect_server_admin(s, si, args[2]);
1157 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01001158 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001159
Cyril Bontécd19e512010-01-31 22:34:03 +01001160 if (sv->state & SRV_MAINTAIN) {
1161 /* The server is really in maintenance, we can change the server state */
Willy Tarreau44267702011-10-28 15:35:33 +02001162 if (sv->track) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001163 /* If this server tracks the status of another one,
1164 * we must restore the good status.
1165 */
Willy Tarreau44267702011-10-28 15:35:33 +02001166 if (sv->track->state & SRV_RUNNING) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001167 set_server_up(sv);
Willy Tarreau70461302010-10-22 14:39:02 +02001168 sv->health = sv->rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +01001169 } else {
1170 sv->state &= ~SRV_MAINTAIN;
1171 set_server_down(sv);
1172 }
1173 } else {
1174 set_server_up(sv);
Willy Tarreau70461302010-10-22 14:39:02 +02001175 sv->health = sv->rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +01001176 }
1177 }
1178
Willy Tarreau532a4502011-09-07 22:37:44 +02001179 return 1;
1180 }
1181 else if (strcmp(args[1], "frontend") == 0) {
1182 struct proxy *px;
1183
1184 px = expect_frontend_admin(s, si, args[2]);
1185 if (!px)
1186 return 1;
1187
1188 if (px->state == PR_STSTOPPED) {
1189 si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n";
1190 si->applet.st0 = STAT_CLI_PRINT;
1191 return 1;
1192 }
1193
1194 if (px->state != PR_STPAUSED) {
1195 si->applet.ctx.cli.msg = "Frontend is already enabled.\n";
1196 si->applet.st0 = STAT_CLI_PRINT;
1197 return 1;
1198 }
1199
1200 if (!resume_proxy(px)) {
1201 si->applet.ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n";
1202 si->applet.st0 = STAT_CLI_PRINT;
1203 return 1;
1204 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001205 return 1;
1206 }
1207 else { /* unknown "enable" parameter */
Willy Tarreau532a4502011-09-07 22:37:44 +02001208 si->applet.ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n";
1209 si->applet.st0 = STAT_CLI_PRINT;
1210 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01001211 }
1212 }
1213 else if (strcmp(args[0], "disable") == 0) {
1214 if (strcmp(args[1], "server") == 0) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001215 struct server *sv;
1216
Willy Tarreaud52c41e2011-09-07 23:41:01 +02001217 sv = expect_server_admin(s, si, args[2]);
1218 if (!sv)
Cyril Bonté613f0df2011-03-03 20:49:04 +01001219 return 1;
Cyril Bonté613f0df2011-03-03 20:49:04 +01001220
Cyril Bontécd19e512010-01-31 22:34:03 +01001221 if (! (sv->state & SRV_MAINTAIN)) {
1222 /* Not already in maintenance, we can change the server state */
1223 sv->state |= SRV_MAINTAIN;
1224 set_server_down(sv);
1225 }
1226
Willy Tarreau532a4502011-09-07 22:37:44 +02001227 return 1;
1228 }
1229 else if (strcmp(args[1], "frontend") == 0) {
1230 struct proxy *px;
1231
1232 px = expect_frontend_admin(s, si, args[2]);
1233 if (!px)
1234 return 1;
1235
1236 if (px->state == PR_STSTOPPED) {
1237 si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n";
1238 si->applet.st0 = STAT_CLI_PRINT;
1239 return 1;
1240 }
1241
1242 if (px->state == PR_STPAUSED) {
1243 si->applet.ctx.cli.msg = "Frontend is already disabled.\n";
1244 si->applet.st0 = STAT_CLI_PRINT;
1245 return 1;
1246 }
1247
1248 if (!pause_proxy(px)) {
1249 si->applet.ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n";
1250 si->applet.st0 = STAT_CLI_PRINT;
1251 return 1;
1252 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001253 return 1;
1254 }
1255 else { /* unknown "disable" parameter */
Willy Tarreau532a4502011-09-07 22:37:44 +02001256 si->applet.ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n";
1257 si->applet.st0 = STAT_CLI_PRINT;
1258 return 1;
1259 }
1260 }
1261 else if (strcmp(args[0], "shutdown") == 0) {
1262 if (strcmp(args[1], "frontend") == 0) {
1263 struct proxy *px;
1264
1265 px = expect_frontend_admin(s, si, args[2]);
1266 if (!px)
1267 return 1;
1268
1269 if (px->state == PR_STSTOPPED) {
1270 si->applet.ctx.cli.msg = "Frontend was already shut down.\n";
1271 si->applet.st0 = STAT_CLI_PRINT;
1272 return 1;
1273 }
1274
1275 Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
1276 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
1277 send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n",
1278 px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn);
1279 stop_proxy(px);
1280 return 1;
1281 }
Willy Tarreaua295edc2011-09-07 23:21:03 +02001282 else if (strcmp(args[1], "session") == 0) {
1283 struct session *sess, *ptr;
1284
1285 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
1286 si->applet.ctx.cli.msg = stats_permission_denied_msg;
1287 si->applet.st0 = STAT_CLI_PRINT;
1288 return 1;
1289 }
1290
1291 if (!*args[2]) {
1292 si->applet.ctx.cli.msg = "Session pointer expected (use 'show sess').\n";
1293 si->applet.st0 = STAT_CLI_PRINT;
1294 return 1;
1295 }
1296
1297 ptr = (void *)strtoul(args[2], NULL, 0);
1298
1299 /* first, look for the requested session in the session table */
1300 list_for_each_entry(sess, &sessions, list) {
1301 if (sess == ptr)
1302 break;
1303 }
1304
1305 /* do we have the session ? */
1306 if (sess != ptr) {
1307 si->applet.ctx.cli.msg = "No such session (use 'show sess').\n";
1308 si->applet.st0 = STAT_CLI_PRINT;
1309 return 1;
1310 }
1311
1312 session_shutdown(sess, SN_ERR_KILLED);
1313 return 1;
1314 }
Willy Tarreau52b2d222011-09-07 23:48:48 +02001315 else if (strcmp(args[1], "sessions") == 0) {
1316 if (strcmp(args[2], "server") == 0) {
1317 struct server *sv;
1318 struct session *sess, *sess_bck;
1319
1320 sv = expect_server_admin(s, si, args[3]);
1321 if (!sv)
1322 return 1;
1323
1324 /* kill all the session that are on this server */
1325 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
1326 if (sess->srv_conn == sv)
1327 session_shutdown(sess, SN_ERR_KILLED);
1328
1329 return 1;
1330 }
1331 else {
1332 si->applet.ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n";
1333 si->applet.st0 = STAT_CLI_PRINT;
1334 return 1;
1335 }
1336 }
Willy Tarreau532a4502011-09-07 22:37:44 +02001337 else { /* unknown "disable" parameter */
Willy Tarreau52b2d222011-09-07 23:48:48 +02001338 si->applet.ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n";
Willy Tarreau532a4502011-09-07 22:37:44 +02001339 si->applet.st0 = STAT_CLI_PRINT;
1340 return 1;
Cyril Bontécd19e512010-01-31 22:34:03 +01001341 }
1342 }
1343 else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001344 return 0;
1345 }
1346 return 1;
1347}
1348
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001349/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001350 * used to processes I/O from/to the stats unix socket. The system relies on a
1351 * state machine handling requests and various responses. We read a request,
1352 * then we process it and send the response, and we possibly display a prompt.
Willy Tarreaubc4af052011-02-13 13:25:14 +01001353 * Then we can read again. The state is stored in si->applet.st0 and is one of the
1354 * STAT_CLI_* constants. si->applet.st1 is used to indicate whether prompt is enabled
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001355 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001356 */
Willy Tarreaub24281b2011-02-13 13:16:36 +01001357static void cli_io_handler(struct stream_interface *si)
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001358{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001359 struct buffer *req = si->ob;
1360 struct buffer *res = si->ib;
1361 int reql;
1362 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001363
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001364 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
1365 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001366
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001367 while (1) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001368 if (si->applet.st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001369 /* Stats output not initialized yet */
Willy Tarreau295a8372011-03-10 11:25:07 +01001370 memset(&si->applet.ctx.stats, 0, sizeof(si->applet.ctx.stats));
Willy Tarreaubc4af052011-02-13 13:25:14 +01001371 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001372 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001373 else if (si->applet.st0 == STAT_CLI_END) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001374 /* Let's close for real now. We just close the request
1375 * side, the conditions below will complete if needed.
1376 */
1377 si->shutw(si);
1378 break;
1379 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001380 else if (si->applet.st0 == STAT_CLI_GETREQ) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02001381 /* ensure we have some output room left in the event we
1382 * would want to return some info right after parsing.
1383 */
1384 if (buffer_almost_full(si->ib))
1385 break;
1386
Willy Tarreau74b08c92010-09-08 17:04:31 +02001387 reql = buffer_get_line(si->ob, trash, sizeof(trash));
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001388 if (reql <= 0) { /* closed or EOL not found */
1389 if (reql == 0)
1390 break;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001391 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001392 continue;
1393 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001394
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001395 /* seek for a possible semi-colon. If we find one, we
1396 * replace it with an LF and skip only this part.
1397 */
1398 for (len = 0; len < reql; len++)
1399 if (trash[len] == ';') {
1400 trash[len] = '\n';
1401 reql = len + 1;
1402 break;
1403 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001404
Willy Tarreau816fc222009-10-04 07:36:58 +02001405 /* now it is time to check that we have a full line,
1406 * remove the trailing \n and possibly \r, then cut the
1407 * line.
1408 */
1409 len = reql - 1;
1410 if (trash[len] != '\n') {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001411 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001412 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001413 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001414
Willy Tarreau816fc222009-10-04 07:36:58 +02001415 if (len && trash[len-1] == '\r')
1416 len--;
1417
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001418 trash[len] = '\0';
1419
Willy Tarreaubc4af052011-02-13 13:25:14 +01001420 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001421 if (len) {
1422 if (strcmp(trash, "quit") == 0) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001423 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001424 continue;
1425 }
1426 else if (strcmp(trash, "prompt") == 0)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001427 si->applet.st1 = !si->applet.st1;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001428 else if (strcmp(trash, "help") == 0 ||
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001429 !stats_sock_parse_request(si, trash)) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001430 si->applet.ctx.cli.msg = stats_sock_usage_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001431 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001432 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001433 /* NB: stats_sock_parse_request() may have put
Willy Tarreaubc4af052011-02-13 13:25:14 +01001434 * another STAT_CLI_O_* into si->applet.st0.
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001435 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001436 }
Willy Tarreaubc4af052011-02-13 13:25:14 +01001437 else if (!si->applet.st1) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001438 /* if prompt is disabled, print help on empty lines,
1439 * so that the user at least knows how to enable
1440 * prompt and find help.
1441 */
Willy Tarreau295a8372011-03-10 11:25:07 +01001442 si->applet.ctx.cli.msg = stats_sock_usage_msg;
Willy Tarreaubc4af052011-02-13 13:25:14 +01001443 si->applet.st0 = STAT_CLI_PRINT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001444 }
1445
1446 /* re-adjust req buffer */
1447 buffer_skip(si->ob, reql);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001448 req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001449 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001450 else { /* output functions: first check if the output buffer is closed then abort */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001451 if (res->flags & (BF_SHUTR_NOW|BF_SHUTR)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001452 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001453 continue;
1454 }
1455
Willy Tarreaubc4af052011-02-13 13:25:14 +01001456 switch (si->applet.st0) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +02001457 case STAT_CLI_PRINT:
Willy Tarreau295a8372011-03-10 11:25:07 +01001458 if (buffer_feed(si->ib, si->applet.ctx.cli.msg) < 0)
Willy Tarreaubc4af052011-02-13 13:25:14 +01001459 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001460 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001461 case STAT_CLI_O_INFO:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001462 if (stats_dump_raw_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001463 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001464 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001465 case STAT_CLI_O_SESS:
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001466 if (stats_dump_sess_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001467 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001468 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001469 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001470 if (stats_dump_errors_to_buffer(si))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001471 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001472 break;
Willy Tarreau69f58c82010-07-12 17:55:33 +02001473 case STAT_CLI_O_TAB:
Simon Hormanc88b8872011-06-15 15:18:49 +09001474 if (stats_table_request(si, true))
1475 si->applet.st0 = STAT_CLI_PROMPT;
1476 break;
1477 case STAT_CLI_O_CLR:
1478 if (stats_table_request(si, false))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001479 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau69f58c82010-07-12 17:55:33 +02001480 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001481 default: /* abnormal state */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001482 si->applet.st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001483 break;
1484 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001485
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001486 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001487 if (si->applet.st0 == STAT_CLI_PROMPT) {
1488 if (buffer_feed(si->ib, si->applet.st1 ? "\n> " : "\n") < 0)
1489 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001490 }
1491
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001492 /* If the output functions are still there, it means they require more room. */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001493 if (si->applet.st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001494 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001495
1496 /* Now we close the output if one of the writers did so,
1497 * or if we're not in interactive mode and the request
1498 * buffer is empty. This still allows pipelined requests
1499 * to be sent in non-interactive mode.
1500 */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001501 if ((res->flags & (BF_SHUTW|BF_SHUTW_NOW)) || (!si->applet.st1 && !req->send_max)) {
1502 si->applet.st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001503 continue;
1504 }
1505
Willy Tarreauf5a885f2009-10-04 14:22:18 +02001506 /* switch state back to GETREQ to read next requests */
Willy Tarreaubc4af052011-02-13 13:25:14 +01001507 si->applet.st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001508 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001509 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001510
Willy Tarreaubc4af052011-02-13 13:25:14 +01001511 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST) && (si->applet.st0 != STAT_CLI_GETREQ)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001512 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
1513 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
1514 /* Other size has closed, let's abort if we have no more processing to do
1515 * and nothing more to consume. This is comparable to a broken pipe, so
1516 * we forward the close to the request side so that it flows upstream to
1517 * the client.
1518 */
1519 si->shutw(si);
1520 }
1521
Willy Tarreaubc4af052011-02-13 13:25:14 +01001522 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && (si->applet.st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001523 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
1524 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
1525 /* We have no more processing to do, and nothing more to send, and
1526 * the client side has closed. So we'll forward this state downstream
1527 * on the response buffer.
1528 */
1529 si->shutr(si);
1530 res->flags |= BF_READ_NULL;
1531 }
1532
1533 /* update all other flags and resync with the other side */
1534 si->update(si);
1535
1536 /* we don't want to expire timeouts while we're processing requests */
1537 si->ib->rex = TICK_ETERNITY;
1538 si->ob->wex = TICK_ETERNITY;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001539
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001540 out:
1541 DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rql=%d, rqs=%d, rl=%d, rs=%d\n",
1542 __FUNCTION__, __LINE__,
1543 si->state, req->flags, res->flags, req->l, req->send_max, res->l, res->send_max);
1544
1545 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1546 /* check that we have released everything then unregister */
1547 stream_int_unregister_handler(si);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001548 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001549}
1550
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001551/* This function dumps statistics onto the stream interface's read buffer.
1552 * The data_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau24955a12009-10-04 11:54:04 +02001553 * It returns 0 as long as it does not complete, non-zero upon completion.
1554 * Some states are not used but it makes the code more similar to other
1555 * functions which handle stats too.
Willy Tarreau3e76e722007-10-17 18:57:38 +02001556 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001557static int stats_dump_raw_to_buffer(struct stream_interface *si)
Willy Tarreau3e76e722007-10-17 18:57:38 +02001558{
Willy Tarreau3e76e722007-10-17 18:57:38 +02001559 struct proxy *px;
1560 struct chunk msg;
Willy Tarreaua8efd362008-01-03 10:19:15 +01001561 unsigned int up;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001562
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001563 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3e76e722007-10-17 18:57:38 +02001564
Willy Tarreau295a8372011-03-10 11:25:07 +01001565 switch (si->applet.state) {
1566 case STAT_ST_INIT:
Willy Tarreau24955a12009-10-04 11:54:04 +02001567 /* the function had not been called yet */
Willy Tarreau295a8372011-03-10 11:25:07 +01001568 si->applet.state = STAT_ST_HEAD;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001569 /* fall through */
1570
Willy Tarreau295a8372011-03-10 11:25:07 +01001571 case STAT_ST_HEAD:
1572 if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001573 print_csv_header(&msg);
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001574 if (buffer_feed_chunk(si->ib, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001575 return 0;
1576 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001577
Willy Tarreau295a8372011-03-10 11:25:07 +01001578 si->applet.state = STAT_ST_INFO;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001579 /* fall through */
1580
Willy Tarreau295a8372011-03-10 11:25:07 +01001581 case STAT_ST_INFO:
Willy Tarreaua8efd362008-01-03 10:19:15 +01001582 up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau295a8372011-03-10 11:25:07 +01001583 if (si->applet.ctx.stats.flags & STAT_SHOW_INFO) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001584 chunk_printf(&msg,
Willy Tarreaua8efd362008-01-03 10:19:15 +01001585 "Name: " PRODUCT_NAME "\n"
1586 "Version: " HAPROXY_VERSION "\n"
1587 "Release_date: " HAPROXY_DATE "\n"
1588 "Nbproc: %d\n"
1589 "Process_num: %d\n"
1590 "Pid: %d\n"
1591 "Uptime: %dd %dh%02dm%02ds\n"
1592 "Uptime_sec: %d\n"
1593 "Memmax_MB: %d\n"
1594 "Ulimit-n: %d\n"
1595 "Maxsock: %d\n"
1596 "Maxconn: %d\n"
Willy Tarreau91886b62011-09-07 14:38:31 +02001597 "Hard_maxconn: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +01001598 "Maxpipes: %d\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001599 "CurrConns: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +01001600 "PipesUsed: %d\n"
1601 "PipesFree: %d\n"
Willy Tarreau9cd552d2011-09-07 15:26:48 +02001602 "ConnRate: %d\n"
1603 "ConnRateLimit: %d\n"
1604 "MaxConnRate: %d\n"
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001605 "Tasks: %d\n"
1606 "Run_queue: %d\n"
Willy Tarreau45a12512011-09-10 16:56:42 +02001607 "Idle_pct: %d\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001608 "node: %s\n"
1609 "description: %s\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001610 "",
1611 global.nbproc,
1612 relative_pid,
1613 pid,
1614 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
1615 up,
1616 global.rlimit_memmax,
1617 global.rlimit_nofile,
Willy Tarreau91886b62011-09-07 14:38:31 +02001618 global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001619 actconn, pipes_used, pipes_free,
Willy Tarreau9cd552d2011-09-07 15:26:48 +02001620 read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max,
Willy Tarreau45a12512011-09-10 16:56:42 +02001621 nb_tasks_cur, run_queue_cur, idle_pct,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001622 global.node, global.desc?global.desc:""
Willy Tarreaua8efd362008-01-03 10:19:15 +01001623 );
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001624 if (buffer_feed_chunk(si->ib, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001625 return 0;
1626 }
1627
Willy Tarreau295a8372011-03-10 11:25:07 +01001628 si->applet.ctx.stats.px = proxy;
1629 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
1630 si->applet.ctx.stats.sv = NULL;
1631 si->applet.state = STAT_ST_LIST;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001632 /* fall through */
1633
Willy Tarreau295a8372011-03-10 11:25:07 +01001634 case STAT_ST_LIST:
Willy Tarreau3e76e722007-10-17 18:57:38 +02001635 /* dump proxies */
Willy Tarreau295a8372011-03-10 11:25:07 +01001636 if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) {
1637 while (si->applet.ctx.stats.px) {
1638 px = si->applet.ctx.stats.px;
Willy Tarreaua8efd362008-01-03 10:19:15 +01001639 /* skip the disabled proxies and non-networked ones */
1640 if (px->state != PR_STSTOPPED &&
Willy Tarreau24955a12009-10-04 11:54:04 +02001641 (px->cap & (PR_CAP_FE | PR_CAP_BE))) {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001642 if (stats_dump_proxy(si, px, NULL) == 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001643 return 0;
Willy Tarreau24955a12009-10-04 11:54:04 +02001644 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001645
Willy Tarreau295a8372011-03-10 11:25:07 +01001646 si->applet.ctx.stats.px = px->next;
1647 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreaua8efd362008-01-03 10:19:15 +01001648 }
1649 /* here, we just have reached the last proxy */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001650 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001651
Willy Tarreau295a8372011-03-10 11:25:07 +01001652 si->applet.state = STAT_ST_END;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001653 /* fall through */
1654
Willy Tarreau295a8372011-03-10 11:25:07 +01001655 case STAT_ST_END:
1656 si->applet.state = STAT_ST_FIN;
Willy Tarreau0a464892008-12-07 18:30:00 +01001657 /* fall through */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001658
Willy Tarreau295a8372011-03-10 11:25:07 +01001659 case STAT_ST_FIN:
Willy Tarreau3e76e722007-10-17 18:57:38 +02001660 return 1;
1661
1662 default:
1663 /* unknown state ! */
Willy Tarreau295a8372011-03-10 11:25:07 +01001664 si->applet.state = STAT_ST_FIN;
Willy Tarreau24955a12009-10-04 11:54:04 +02001665 return 1;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001666 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001667}
1668
1669
Cyril Bonté70be45d2010-10-12 00:14:35 +02001670/* We don't want to land on the posted stats page because a refresh will
1671 * repost the data. We don't want this to happen on accident so we redirect
1672 * the browse to the stats page with a GET.
1673 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001674static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri)
Cyril Bonté70be45d2010-10-12 00:14:35 +02001675{
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001676 struct session *s = si->applet.private;
Cyril Bonté70be45d2010-10-12 00:14:35 +02001677 struct chunk msg;
1678
1679 chunk_init(&msg, trash, sizeof(trash));
1680
Willy Tarreau295a8372011-03-10 11:25:07 +01001681 switch (si->applet.state) {
1682 case STAT_ST_INIT:
Cyril Bonté70be45d2010-10-12 00:14:35 +02001683 chunk_printf(&msg,
1684 "HTTP/1.0 303 See Other\r\n"
1685 "Cache-Control: no-cache\r\n"
1686 "Content-Type: text/plain\r\n"
1687 "Connection: close\r\n"
1688 "Location: %s;st=%s",
Willy Tarreau295a8372011-03-10 11:25:07 +01001689 uri->uri_prefix, si->applet.ctx.stats.st_code);
Cyril Bonté70be45d2010-10-12 00:14:35 +02001690 chunk_printf(&msg, "\r\n\r\n");
1691
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001692 if (buffer_feed_chunk(si->ib, &msg) >= 0)
Cyril Bonté70be45d2010-10-12 00:14:35 +02001693 return 0;
1694
1695 s->txn.status = 303;
1696
1697 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1698 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1699 if (!(s->flags & SN_FINST_MASK))
1700 s->flags |= SN_FINST_R;
1701
Willy Tarreau295a8372011-03-10 11:25:07 +01001702 si->applet.state = STAT_ST_FIN;
Cyril Bonté70be45d2010-10-12 00:14:35 +02001703 return 1;
1704 }
1705 return 1;
1706}
1707
1708
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001709/* This I/O handler runs as an applet embedded in a stream interface. It is
1710 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
Willy Tarreaubc4af052011-02-13 13:25:14 +01001711 * si->applet.st0 becomes non-zero once the transfer is finished. The handler
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001712 * automatically unregisters itself once transfer is complete.
1713 */
Willy Tarreaub24281b2011-02-13 13:16:36 +01001714static void http_stats_io_handler(struct stream_interface *si)
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001715{
Willy Tarreaubc4af052011-02-13 13:25:14 +01001716 struct session *s = si->applet.private;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001717 struct buffer *req = si->ob;
1718 struct buffer *res = si->ib;
1719
1720 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
1721 goto out;
1722
1723 /* check that the output is not closed */
1724 if (res->flags & (BF_SHUTW|BF_SHUTW_NOW))
Willy Tarreaubc4af052011-02-13 13:25:14 +01001725 si->applet.st0 = 1;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001726
Willy Tarreaubc4af052011-02-13 13:25:14 +01001727 if (!si->applet.st0) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02001728 if (s->txn.meth == HTTP_METH_POST) {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001729 if (stats_http_redir(si, s->be->uri_auth)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001730 si->applet.st0 = 1;
Cyril Bonté70be45d2010-10-12 00:14:35 +02001731 si->shutw(si);
1732 }
1733 } else {
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001734 if (stats_dump_http(si, s->be->uri_auth)) {
Willy Tarreaubc4af052011-02-13 13:25:14 +01001735 si->applet.st0 = 1;
Cyril Bonté70be45d2010-10-12 00:14:35 +02001736 si->shutw(si);
1737 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001738 }
1739 }
1740
1741 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST))
1742 si->shutw(si);
1743
Willy Tarreaubc4af052011-02-13 13:25:14 +01001744 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && si->applet.st0) {
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001745 si->shutr(si);
1746 res->flags |= BF_READ_NULL;
1747 }
1748
1749 /* update all other flags and resync with the other side */
1750 si->update(si);
1751
1752 /* we don't want to expire timeouts while we're processing requests */
1753 si->ib->rex = TICK_ETERNITY;
1754 si->ob->wex = TICK_ETERNITY;
1755
1756 out:
1757 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1758 /* check that we have released everything then unregister */
1759 stream_int_unregister_handler(si);
1760 }
1761}
1762
1763
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001764/* This function dumps statistics in HTTP format onto the stream interface's
1765 * read buffer. The data_ctx must have been zeroed first, and the flags
1766 * properly set. It returns 0 if it had to stop writing data and an I/O is
1767 * needed, 1 if the dump is finished and the session must be closed, or -1
1768 * in case of any error.
Willy Tarreau91861262007-10-17 17:06:05 +02001769 */
Simon Horman9bd2c732011-06-15 15:18:44 +09001770static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001771{
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01001772 struct session *s = si->applet.private;
1773 struct buffer *rep = si->ib;
Willy Tarreau91861262007-10-17 17:06:05 +02001774 struct proxy *px;
1775 struct chunk msg;
1776 unsigned int up;
1777
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001778 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +02001779
Willy Tarreau295a8372011-03-10 11:25:07 +01001780 switch (si->applet.state) {
1781 case STAT_ST_INIT:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001782 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001783 "HTTP/1.0 200 OK\r\n"
1784 "Cache-Control: no-cache\r\n"
1785 "Connection: close\r\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001786 "Content-Type: %s\r\n",
Willy Tarreau295a8372011-03-10 11:25:07 +01001787 (si->applet.ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html");
Willy Tarreau91861262007-10-17 17:06:05 +02001788
Willy Tarreau295a8372011-03-10 11:25:07 +01001789 if (uri->refresh > 0 && !(si->applet.ctx.stats.flags & STAT_NO_REFRESH))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001790 chunk_printf(&msg, "Refresh: %d\r\n",
Willy Tarreau91861262007-10-17 17:06:05 +02001791 uri->refresh);
1792
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001793 chunk_printf(&msg, "\r\n");
Willy Tarreau91861262007-10-17 17:06:05 +02001794
1795 s->txn.status = 200;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001796 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau56a560a2009-09-22 19:27:35 +02001797 return 0;
1798
Willy Tarreau91861262007-10-17 17:06:05 +02001799 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1800 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1801 if (!(s->flags & SN_FINST_MASK))
1802 s->flags |= SN_FINST_R;
1803
1804 if (s->txn.meth == HTTP_METH_HEAD) {
1805 /* that's all we return in case of HEAD request */
Willy Tarreau295a8372011-03-10 11:25:07 +01001806 si->applet.state = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001807 return 1;
1808 }
1809
Willy Tarreau295a8372011-03-10 11:25:07 +01001810 si->applet.state = STAT_ST_HEAD; /* let's start producing data */
Willy Tarreau91861262007-10-17 17:06:05 +02001811 /* fall through */
1812
Willy Tarreau295a8372011-03-10 11:25:07 +01001813 case STAT_ST_HEAD:
1814 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001815 /* WARNING! This must fit in the first buffer !!! */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001816 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001817 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
1818 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001819 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001820 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
1821 "<style type=\"text/css\"><!--\n"
1822 "body {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001823 " font-family: arial, helvetica, sans-serif;"
Willy Tarreau91861262007-10-17 17:06:05 +02001824 " font-size: 12px;"
1825 " font-weight: normal;"
1826 " color: black;"
1827 " background: white;"
1828 "}\n"
1829 "th,td {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001830 " font-size: 10px;"
Willy Tarreau91861262007-10-17 17:06:05 +02001831 "}\n"
1832 "h1 {"
Willy Tarreauda6721b2009-07-15 10:07:05 +02001833 " font-size: x-large;"
Willy Tarreau91861262007-10-17 17:06:05 +02001834 " margin-bottom: 0.5em;"
1835 "}\n"
1836 "h2 {"
1837 " font-family: helvetica, arial;"
1838 " font-size: x-large;"
1839 " font-weight: bold;"
1840 " font-style: italic;"
1841 " color: #6020a0;"
1842 " margin-top: 0em;"
1843 " margin-bottom: 0em;"
1844 "}\n"
1845 "h3 {"
1846 " font-family: helvetica, arial;"
1847 " font-size: 16px;"
1848 " font-weight: bold;"
1849 " color: #b00040;"
1850 " background: #e8e8d0;"
1851 " margin-top: 0em;"
1852 " margin-bottom: 0em;"
1853 "}\n"
1854 "li {"
1855 " margin-top: 0.25em;"
1856 " margin-right: 2em;"
1857 "}\n"
1858 ".hr {margin-top: 0.25em;"
1859 " border-color: black;"
1860 " border-bottom-style: solid;"
1861 "}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001862 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001863 ".total {background: #20D0D0;color: #ffff80;}\n"
1864 ".frontend {background: #e8e8d0;}\n"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001865 ".socket {background: #d0d0d0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001866 ".backend {background: #e8e8d0;}\n"
1867 ".active0 {background: #ff9090;}\n"
1868 ".active1 {background: #ffd020;}\n"
1869 ".active2 {background: #ffffa0;}\n"
1870 ".active3 {background: #c0ffc0;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001871 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
1872 ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
1873 ".active6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001874 ".backup0 {background: #ff9090;}\n"
1875 ".backup1 {background: #ff80ff;}\n"
1876 ".backup2 {background: #c060ff;}\n"
1877 ".backup3 {background: #b0d0ff;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001878 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
1879 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
1880 ".backup6 {background: #e0e0e0;}\n"
Cyril Bontécd19e512010-01-31 22:34:03 +01001881 ".maintain {background: #c07820;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +02001882 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001883 "\n"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001884 "a.px:link {color: #ffff40; text-decoration: none;}"
1885 "a.px:visited {color: #ffff40; text-decoration: none;}"
1886 "a.px:hover {color: #ffffff; text-decoration: none;}"
1887 "a.lfsb:link {color: #000000; text-decoration: none;}"
1888 "a.lfsb:visited {color: #000000; text-decoration: none;}"
1889 "a.lfsb:hover {color: #505050; text-decoration: none;}"
1890 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001891 "table.tbl { border-collapse: collapse; border-style: none;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001892 "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"
1893 "table.tbl td.ac { text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001894 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001895 "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 +02001896 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001897 "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 +02001898 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001899 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
1900 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
1901 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
Willy Tarreaue0454092010-02-26 12:29:07 +01001902 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001903 "-->\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001904 "</style></head>\n",
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001905 (uri->flags&ST_SHNODE) ? " on " : "",
1906 (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001907 );
Willy Tarreau55bb8452007-10-17 18:44:57 +02001908 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001909 print_csv_header(&msg);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001910 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001911 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001912 return 0;
1913
Willy Tarreau295a8372011-03-10 11:25:07 +01001914 si->applet.state = STAT_ST_INFO;
Willy Tarreau91861262007-10-17 17:06:05 +02001915 /* fall through */
1916
Willy Tarreau295a8372011-03-10 11:25:07 +01001917 case STAT_ST_INFO:
Willy Tarreau91861262007-10-17 17:06:05 +02001918 up = (now.tv_sec - start_date.tv_sec);
1919
1920 /* WARNING! this has to fit the first packet too.
1921 * We are around 3.5 kB, add adding entries will
1922 * become tricky if we want to support 4kB buffers !
1923 */
Willy Tarreau295a8372011-03-10 11:25:07 +01001924 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001925 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001926 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
1927 PRODUCT_NAME "%s</a></h1>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001928 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001929 "<hr width=\"100%%\" class=\"hr\">\n"
1930 "<h3>&gt; General process information</h3>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001931 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001932 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001933 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001934 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
1935 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
Willy Tarreau9cd552d2011-09-07 15:26:48 +02001936 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n"
Willy Tarreau45a12512011-09-10 16:56:42 +02001937 "Running tasks: %d/%d; idle = %d %%<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001938 "</td><td align=\"center\" nowrap>\n"
1939 "<table class=\"lgd\"><tr>\n"
1940 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
1941 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
1942 "</tr><tr>\n"
1943 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
1944 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
1945 "</tr><tr>\n"
1946 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
1947 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
1948 "</tr><tr>\n"
1949 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001950 "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
Cyril Bontécd19e512010-01-31 22:34:03 +01001951 "</tr><tr>\n"
1952 "<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 +02001953 "</tr></table>\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001954 "Note: UP with load-balancing disabled is reported as \"NOLB\"."
Willy Tarreau91861262007-10-17 17:06:05 +02001955 "</td>"
1956 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
1957 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
1958 "",
1959 (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001960 pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
1961 (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
1962 pid, relative_pid, global.nbproc,
Willy Tarreau91861262007-10-17 17:06:05 +02001963 up / 86400, (up % 86400) / 3600,
1964 (up % 3600) / 60, (up % 60),
1965 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
1966 global.rlimit_memmax ? " MB" : "",
1967 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +01001968 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreau9cd552d2011-09-07 15:26:48 +02001969 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
Willy Tarreau45a12512011-09-10 16:56:42 +02001970 run_queue_cur, nb_tasks_cur, idle_pct
Willy Tarreau91861262007-10-17 17:06:05 +02001971 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001972
Willy Tarreau295a8372011-03-10 11:25:07 +01001973 if (si->applet.ctx.stats.flags & STAT_HIDE_DOWN)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001974 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001975 "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
1976 uri->uri_prefix,
1977 "",
Willy Tarreau295a8372011-03-10 11:25:07 +01001978 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001979 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001980 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001981 "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
1982 uri->uri_prefix,
1983 ";up",
Willy Tarreau295a8372011-03-10 11:25:07 +01001984 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02001985
Willy Tarreau55bb8452007-10-17 18:44:57 +02001986 if (uri->refresh > 0) {
Willy Tarreau295a8372011-03-10 11:25:07 +01001987 if (si->applet.ctx.stats.flags & STAT_NO_REFRESH)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001988 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001989 "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
1990 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01001991 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02001992 "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001993 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001994 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001995 "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
1996 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01001997 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02001998 ";norefresh");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001999 }
Willy Tarreau91861262007-10-17 17:06:05 +02002000
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002001 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002002 "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
2003 uri->uri_prefix,
Willy Tarreau295a8372011-03-10 11:25:07 +01002004 (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2005 (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02002006
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002007 chunk_printf(&msg,
Willy Tarreau5031e6a2007-10-18 11:05:48 +02002008 "<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
2009 uri->uri_prefix,
2010 (uri->refresh > 0) ? ";norefresh" : "");
2011
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002012 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002013 "</ul></td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002014 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
Adrian Bridgettafdb6e52012-03-19 23:36:42 +00002015 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
Willy Tarreau91861262007-10-17 17:06:05 +02002016 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
2017 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
2018 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
2019 "</ul>"
2020 "</td>"
2021 "</tr></table>\n"
2022 ""
2023 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002024
Willy Tarreau295a8372011-03-10 11:25:07 +01002025 if (si->applet.ctx.stats.st_code) {
2026 if (strcmp(si->applet.ctx.stats.st_code, STAT_STATUS_DONE) == 0) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002027 chunk_printf(&msg,
2028 "<p><div class=active3>"
2029 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2030 "Action processed successfully."
2031 "</div>\n", uri->uri_prefix);
2032 }
Willy Tarreau295a8372011-03-10 11:25:07 +01002033 else if (strcmp(si->applet.ctx.stats.st_code, STAT_STATUS_NONE) == 0) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002034 chunk_printf(&msg,
2035 "<p><div class=active2>"
2036 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2037 "Nothing has changed."
2038 "</div>\n", uri->uri_prefix);
2039 }
Cyril Bontécf8d9ae2012-04-04 12:57:18 +02002040 else if (strcmp(si->applet.ctx.stats.st_code, STAT_STATUS_PART) == 0) {
2041 chunk_printf(&msg,
2042 "<p><div class=active2>"
2043 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2044 "Action partially processed.<br>"
2045 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
2046 "</div>\n", uri->uri_prefix);
2047 }
2048 else if (strcmp(si->applet.ctx.stats.st_code, STAT_STATUS_ERRP) == 0) {
2049 chunk_printf(&msg,
2050 "<p><div class=active0>"
2051 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2052 "Action not processed because of invalid parameters."
2053 "<ul>"
2054 "<li>The action is maybe unknown.</li>"
2055 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
2056 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
2057 "</ul>"
2058 "</div>\n", uri->uri_prefix);
2059 }
Willy Tarreau295a8372011-03-10 11:25:07 +01002060 else if (strcmp(si->applet.ctx.stats.st_code, STAT_STATUS_EXCD) == 0) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002061 chunk_printf(&msg,
2062 "<p><div class=active0>"
2063 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2064 "<b>Action not processed : the buffer couldn't store all the data.<br>"
2065 "You should retry with less servers at a time.</b>"
2066 "</div>\n", uri->uri_prefix);
2067 }
Willy Tarreau295a8372011-03-10 11:25:07 +01002068 else if (strcmp(si->applet.ctx.stats.st_code, STAT_STATUS_DENY) == 0) {
Cyril Bonté474be412010-10-12 00:14:36 +02002069 chunk_printf(&msg,
2070 "<p><div class=active0>"
2071 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2072 "<b>Action denied.</b>"
2073 "</div>\n", uri->uri_prefix);
2074 }
Cyril Bonté70be45d2010-10-12 00:14:35 +02002075 else {
2076 chunk_printf(&msg,
2077 "<p><div class=active6>"
2078 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
2079 "Unexpected result."
2080 "</div>\n", uri->uri_prefix);
2081 }
2082 chunk_printf(&msg,"<p>\n");
2083 }
2084
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002085 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002086 return 0;
2087 }
Willy Tarreau91861262007-10-17 17:06:05 +02002088
Willy Tarreau295a8372011-03-10 11:25:07 +01002089 si->applet.ctx.stats.px = proxy;
2090 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
2091 si->applet.state = STAT_ST_LIST;
Willy Tarreau91861262007-10-17 17:06:05 +02002092 /* fall through */
2093
Willy Tarreau295a8372011-03-10 11:25:07 +01002094 case STAT_ST_LIST:
Willy Tarreau91861262007-10-17 17:06:05 +02002095 /* dump proxies */
Willy Tarreau295a8372011-03-10 11:25:07 +01002096 while (si->applet.ctx.stats.px) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02002097 if (buffer_almost_full(rep))
2098 return 0;
Willy Tarreau295a8372011-03-10 11:25:07 +01002099 px = si->applet.ctx.stats.px;
Willy Tarreau91861262007-10-17 17:06:05 +02002100 /* skip the disabled proxies and non-networked ones */
2101 if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002102 if (stats_dump_proxy(si, px, uri) == 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002103 return 0;
2104
Willy Tarreau295a8372011-03-10 11:25:07 +01002105 si->applet.ctx.stats.px = px->next;
2106 si->applet.ctx.stats.px_st = STAT_PX_ST_INIT;
Willy Tarreau91861262007-10-17 17:06:05 +02002107 }
2108 /* here, we just have reached the last proxy */
2109
Willy Tarreau295a8372011-03-10 11:25:07 +01002110 si->applet.state = STAT_ST_END;
Willy Tarreau91861262007-10-17 17:06:05 +02002111 /* fall through */
2112
Willy Tarreau295a8372011-03-10 11:25:07 +01002113 case STAT_ST_END:
2114 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002115 chunk_printf(&msg, "</body></html>\n");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002116 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002117 return 0;
2118 }
Willy Tarreau91861262007-10-17 17:06:05 +02002119
Willy Tarreau295a8372011-03-10 11:25:07 +01002120 si->applet.state = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02002121 /* fall through */
2122
Willy Tarreau295a8372011-03-10 11:25:07 +01002123 case STAT_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02002124 return 1;
2125
2126 default:
2127 /* unknown state ! */
Willy Tarreau295a8372011-03-10 11:25:07 +01002128 si->applet.state = STAT_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02002129 return -1;
2130 }
2131}
2132
2133
2134/*
2135 * Dumps statistics for a proxy.
2136 * Returns 0 if it had to stop dumping data because of lack of buffer space,
2137 * ot non-zero if everything completed.
2138 */
Simon Horman9bd2c732011-06-15 15:18:44 +09002139static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02002140{
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01002141 struct session *s = si->applet.private;
2142 struct buffer *rep = si->ib;
Willy Tarreau44267702011-10-28 15:35:33 +02002143 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002144 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02002145 struct chunk msg;
2146
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002147 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +02002148
Willy Tarreau295a8372011-03-10 11:25:07 +01002149 switch (si->applet.ctx.stats.px_st) {
2150 case STAT_PX_ST_INIT:
Willy Tarreau91861262007-10-17 17:06:05 +02002151 /* we are on a new proxy */
2152
2153 if (uri && uri->scope) {
2154 /* we have a limited scope, we have to check the proxy name */
2155 struct stat_scope *scope;
2156 int len;
2157
2158 len = strlen(px->id);
2159 scope = uri->scope;
2160
2161 while (scope) {
2162 /* match exact proxy name */
2163 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
2164 break;
2165
2166 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02002167 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02002168 break;
2169 scope = scope->next;
2170 }
2171
2172 /* proxy name not found : don't dump anything */
2173 if (scope == NULL)
2174 return 1;
2175 }
2176
Willy Tarreau295a8372011-03-10 11:25:07 +01002177 if ((si->applet.ctx.stats.flags & STAT_BOUND) && (si->applet.ctx.stats.iid != -1) &&
2178 (px->uuid != si->applet.ctx.stats.iid))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002179 return 1;
2180
Willy Tarreau295a8372011-03-10 11:25:07 +01002181 si->applet.ctx.stats.px_st = STAT_PX_ST_TH;
Willy Tarreau91861262007-10-17 17:06:05 +02002182 /* fall through */
2183
Willy Tarreau295a8372011-03-10 11:25:07 +01002184 case STAT_PX_ST_TH:
2185 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
2186 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002187 /* A form to enable/disable this proxy servers */
2188 chunk_printf(&msg,
2189 "<form action=\"%s\" method=\"post\">",
2190 uri->uri_prefix);
2191 }
2192
Willy Tarreau55bb8452007-10-17 18:44:57 +02002193 /* print a new table */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002194 chunk_printf(&msg,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002195 "<table class=\"tbl\" width=\"100%%\">\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002196 "<tr class=\"titre\">"
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002197 "<th class=\"pxname\" width=\"10%%\"");
2198
2199 if (uri->flags&ST_SHLGNDS) {
2200 /* cap, mode, id */
2201 chunk_printf(&msg, " title=\"cap: %s, mode: %s, id: %d",
2202 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
2203 px->uuid);
2204
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002205 chunk_printf(&msg, "\"");
2206 }
2207
2208 chunk_printf(&msg,
Willy Tarreaue0454092010-02-26 12:29:07 +01002209 ">%s<a name=\"%s\"></a>"
2210 "<a class=px href=\"#%s\">%s</a>%s</th>"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002211 "<th class=\"%s\" width=\"90%%\">%s</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002212 "</tr>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02002213 "</table>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002214 "<table class=\"tbl\" width=\"100%%\">\n"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002215 "<tr class=\"titre\">",
2216 (uri->flags & ST_SHLGNDS)?"<u>":"",
2217 px->id, px->id, px->id,
2218 (uri->flags & ST_SHLGNDS)?"</u>":"",
2219 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
2220
Willy Tarreau295a8372011-03-10 11:25:07 +01002221 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002222 /* Column heading for Enable or Disable server */
2223 chunk_printf(&msg, "<th rowspan=2 width=1></th>");
2224 }
2225
2226 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002227 "<th rowspan=2></th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002228 "<th colspan=3>Queue</th>"
2229 "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002230 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002231 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002232 "<th colspan=9>Server</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002233 "</tr>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002234 "<tr class=\"titre\">"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002235 "<th>Cur</th><th>Max</th><th>Limit</th>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002236 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002237 "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002238 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002239 "<th>Resp</th><th>Retr</th><th>Redis</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002240 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002241 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
2242 "<th>Thrtle</th>\n"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002243 "</tr>");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002244
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002245 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002246 return 0;
2247 }
Willy Tarreau91861262007-10-17 17:06:05 +02002248
Willy Tarreau295a8372011-03-10 11:25:07 +01002249 si->applet.ctx.stats.px_st = STAT_PX_ST_FE;
Willy Tarreau91861262007-10-17 17:06:05 +02002250 /* fall through */
2251
Willy Tarreau295a8372011-03-10 11:25:07 +01002252 case STAT_PX_ST_FE:
Willy Tarreau91861262007-10-17 17:06:05 +02002253 /* print the frontend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002254 if ((px->cap & PR_CAP_FE) &&
Willy Tarreau295a8372011-03-10 11:25:07 +01002255 (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_FE)))) {
2256 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002257 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002258 /* name, queue */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002259 "<tr class=\"frontend\">");
2260
Willy Tarreau295a8372011-03-10 11:25:07 +01002261 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002262 /* Column sub-heading for Enable or Disable server */
2263 chunk_printf(&msg, "<td></td>");
2264 }
2265
2266 chunk_printf(&msg,
2267 "<td class=ac>"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002268 "<a name=\"%s/Frontend\"></a>"
Cyril Bonté70be45d2010-10-12 00:14:35 +02002269 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
2270 "<td colspan=3></td>"
Willy Tarreaub44939a2010-02-26 11:35:39 +01002271 "",
2272 px->id, px->id);
2273
2274 if (px->mode == PR_MODE_HTTP) {
2275 chunk_printf(&msg,
2276 /* sessions rate : current, max, limit */
Willy Tarreaue0454092010-02-26 12:29:07 +01002277 "<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 +01002278 "",
2279 read_freq_ctr(&px->fe_req_per_sec),
2280 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002281 px->fe_counters.p.http.rps_max,
2282 U2H1(px->fe_counters.sps_max),
Willy Tarreaub44939a2010-02-26 11:35:39 +01002283 LIM2A2(px->fe_sps_lim, "-"));
2284 } else {
2285 chunk_printf(&msg,
2286 /* sessions rate : current, max, limit */
2287 "<td>%s</td><td>%s</td><td>%s</td>"
2288 "",
2289 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002290 U2H1(px->fe_counters.sps_max), LIM2A2(px->fe_sps_lim, "-"));
Willy Tarreaub44939a2010-02-26 11:35:39 +01002291 }
2292
2293 chunk_printf(&msg,
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002294 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002295 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002296 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002297 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002298 U2H3(px->feconn), U2H4(px->fe_counters.conn_max), U2H5(px->maxconn));
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002299
2300 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2301 if (px->mode == PR_MODE_HTTP) {
2302 int i;
2303
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002304 chunk_printf(&msg, " title=\"%lld requests:", px->fe_counters.p.http.cum_req);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002305
2306 for (i = 1; i < 6; i++)
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002307 chunk_printf(&msg, " %dxx=%lld,", i, px->fe_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002308
Willy Tarreaueabea072011-09-10 23:29:44 +02002309 chunk_printf(&msg, " other=%lld,", px->fe_counters.p.http.rsp[0]);
2310 chunk_printf(&msg, " intercepted=%lld\"", px->fe_counters.intercepted_req);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002311 }
2312
2313 chunk_printf(&msg,
2314 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002315 ">%s%s%s</td><td></td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002316 /* bytes : in, out */
2317 "<td>%s</td><td>%s</td>"
2318 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002319 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002320 U2H6(px->fe_counters.cum_sess),
Willy Tarreaue0454092010-02-26 12:29:07 +01002321 (px->mode == PR_MODE_HTTP)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002322 U2H7(px->fe_counters.bytes_in), U2H8(px->fe_counters.bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002323
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002324 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002325 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002326 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002327 /* errors : request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002328 "<td>%s</td><td></td><td></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002329 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002330 "<td></td><td></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002331 /* server status : reflect frontend status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002332 "<td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002333 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002334 "<td class=ac colspan=8></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +02002335 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002336 U2H0(px->fe_counters.denied_req), U2H1(px->fe_counters.denied_resp),
2337 U2H2(px->fe_counters.failed_req),
Willy Tarreau562515c2011-07-25 08:11:52 +02002338 px->state == PR_STREADY ? "OPEN" :
2339 px->state == PR_STFULL ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002340 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002341 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002342 /* pxid, name, queue cur, queue max, */
2343 "%s,FRONTEND,,,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002344 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002345 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002346 /* bytes : in, out */
2347 "%lld,%lld,"
2348 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002349 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002350 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002351 "%lld,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002352 /* warnings: retries, redispatches */
2353 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002354 /* server status : reflect frontend status */
2355 "%s,"
2356 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002357 ",,,,,,,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002358 /* pid, iid, sid, throttle, lbtot, tracked, type */
2359 "%d,%d,0,,,,%d,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002360 /* rate, rate_lim, rate_max */
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002361 "%u,%u,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002362 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002363 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02002364 px->id,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002365 px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess,
2366 px->fe_counters.bytes_in, px->fe_counters.bytes_out,
2367 px->fe_counters.denied_req, px->fe_counters.denied_resp,
2368 px->fe_counters.failed_req,
Willy Tarreau562515c2011-07-25 08:11:52 +02002369 px->state == PR_STREADY ? "OPEN" :
2370 px->state == PR_STFULL ? "FULL" : "STOP",
Willy Tarreau7f062c42009-03-05 18:43:00 +01002371 relative_pid, px->uuid, STATS_TYPE_FE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002372 read_freq_ctr(&px->fe_sess_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002373 px->fe_sps_lim, px->fe_counters.sps_max);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002374
2375 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2376 if (px->mode == PR_MODE_HTTP) {
2377 int i;
2378
2379 for (i=1; i<6; i++)
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002380 chunk_printf(&msg, "%lld,", px->fe_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002381
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002382 chunk_printf(&msg, "%lld,", px->fe_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002383 } else {
2384 chunk_printf(&msg, ",,,,,,");
2385 }
2386
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002387 /* failed health analyses */
2388 chunk_printf(&msg, ",");
2389
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002390 /* requests : req_rate, req_rate_max, req_tot, */
2391 chunk_printf(&msg, "%u,%u,%lld,",
2392 read_freq_ctr(&px->fe_req_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002393 px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req);
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002394
Willy Tarreauae526782010-03-04 20:34:23 +01002395 /* errors: cli_aborts, srv_aborts */
2396 chunk_printf(&msg, ",,");
2397
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002398 /* finish with EOL */
2399 chunk_printf(&msg, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002400 }
Willy Tarreau91861262007-10-17 17:06:05 +02002401
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002402 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002403 return 0;
2404 }
2405
Willy Tarreau295a8372011-03-10 11:25:07 +01002406 si->applet.ctx.stats.l = px->listen; /* may be NULL */
2407 si->applet.ctx.stats.px_st = STAT_PX_ST_LI;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002408 /* fall through */
2409
Willy Tarreau295a8372011-03-10 11:25:07 +01002410 case STAT_PX_ST_LI:
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002411 /* stats.l has been initialized above */
Willy Tarreau295a8372011-03-10 11:25:07 +01002412 for (; si->applet.ctx.stats.l != NULL; si->applet.ctx.stats.l = l->next) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02002413 if (buffer_almost_full(rep))
2414 return 0;
2415
Willy Tarreau295a8372011-03-10 11:25:07 +01002416 l = si->applet.ctx.stats.l;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002417 if (!l->counters)
2418 continue;
2419
Willy Tarreau295a8372011-03-10 11:25:07 +01002420 if (si->applet.ctx.stats.flags & STAT_BOUND) {
2421 if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SO)))
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002422 break;
2423
Willy Tarreau295a8372011-03-10 11:25:07 +01002424 if (si->applet.ctx.stats.sid != -1 && l->luid != si->applet.ctx.stats.sid)
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002425 continue;
2426 }
2427
Willy Tarreau295a8372011-03-10 11:25:07 +01002428 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002429 chunk_printf(&msg, "<tr class=socket>");
Willy Tarreau295a8372011-03-10 11:25:07 +01002430 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002431 /* Column sub-heading for Enable or Disable server */
2432 chunk_printf(&msg, "<td></td>");
2433 }
2434 chunk_printf(&msg, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002435
2436 if (uri->flags&ST_SHLGNDS) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02002437 char str[INET6_ADDRSTRLEN];
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002438 int port;
2439
Willy Tarreau631f01c2011-09-05 00:36:48 +02002440 chunk_printf(&msg, " title=\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002441
Willy Tarreau631f01c2011-09-05 00:36:48 +02002442 port = get_host_port(&l->addr);
2443 switch (addr_to_str(&l->addr, str, sizeof(str))) {
2444 case AF_INET:
2445 chunk_printf(&msg, "IPv4: %s:%d, ", str, port);
2446 break;
2447 case AF_INET6:
2448 chunk_printf(&msg, "IPv6: [%s]:%d, ", str, port);
2449 break;
2450 case AF_UNIX:
2451 chunk_printf(&msg, "unix, ");
2452 break;
2453 case -1:
2454 chunk_printf(&msg, "(%s), ", strerror(errno));
2455 break;
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002456 }
2457
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002458 /* id */
Willy Tarreau631f01c2011-09-05 00:36:48 +02002459 chunk_printf(&msg, "id: %d\"", l->luid);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002460 }
2461
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002462 chunk_printf(&msg,
2463 /* name, queue */
Willy Tarreaue0454092010-02-26 12:29:07 +01002464 ">%s<a name=\"%s/+%s\"></a>"
2465 "<a class=lfsb href=\"#%s/+%s\">%s</a></td><td colspan=3>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002466 /* sessions rate: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002467 "<td colspan=3>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002468 /* sessions: current, max, limit, total, lbtot */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002469 "<td>%s</td><td>%s</td><td>%s</td>"
2470 "<td>%s</td><td>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002471 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002472 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002473 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002474 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki2ec025d2010-01-04 11:33:32 +01002475 px->id, l->name, px->id, l->name, l->name,
Willy Tarreaue0454092010-02-26 12:29:07 +01002476 (uri->flags & ST_SHLGNDS)?"</u>":"",
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002477 U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn),
2478 U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out));
2479
2480 chunk_printf(&msg,
2481 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002482 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002483 /* errors: request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002484 "<td>%s</td><td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002485 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002486 "<td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002487 /* server status: reflect listener status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002488 "<td class=ac>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002489 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002490 "<td class=ac colspan=8></td></tr>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002491 "",
2492 U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp),
2493 U2H2(l->counters->failed_req),
Willy Tarreaua17c2d92011-07-25 08:16:20 +02002494 (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002495 } else {
2496 chunk_printf(&msg,
2497 /* pxid, name, queue cur, queue max, */
2498 "%s,%s,,,"
2499 /* sessions: current, max, limit, total */
2500 "%d,%d,%d,%lld,"
2501 /* bytes: in, out */
2502 "%lld,%lld,"
2503 /* denied: req, resp */
2504 "%lld,%lld,"
2505 /* errors: request, connect, response */
2506 "%lld,,,"
2507 /* warnings: retries, redispatches */
2508 ",,"
2509 /* server status: reflect listener status */
2510 "%s,"
2511 /* rest of server: nothing */
2512 ",,,,,,,,"
2513 /* pid, iid, sid, throttle, lbtot, tracked, type */
2514 "%d,%d,%d,,,,%d,"
2515 /* rate, rate_lim, rate_max */
2516 ",,,"
2517 /* check_status, check_code, check_duration */
2518 ",,,"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002519 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2520 ",,,,,,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002521 /* failed health analyses */
2522 ","
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002523 /* requests : req_rate, req_rate_max, req_tot, */
2524 ",,,"
Willy Tarreauae526782010-03-04 20:34:23 +01002525 /* errors: cli_aborts, srv_aborts */
2526 ",,"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002527 "\n",
2528 px->id, l->name,
2529 l->nbconn, l->counters->conn_max,
2530 l->maxconn, l->counters->cum_conn,
2531 l->counters->bytes_in, l->counters->bytes_out,
2532 l->counters->denied_req, l->counters->denied_resp,
2533 l->counters->failed_req,
2534 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
2535 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
2536 }
2537
2538 if (buffer_feed_chunk(rep, &msg) >= 0)
2539 return 0;
2540 }
2541
Willy Tarreau295a8372011-03-10 11:25:07 +01002542 si->applet.ctx.stats.sv = px->srv; /* may be NULL */
2543 si->applet.ctx.stats.px_st = STAT_PX_ST_SV;
Willy Tarreau91861262007-10-17 17:06:05 +02002544 /* fall through */
2545
Willy Tarreau295a8372011-03-10 11:25:07 +01002546 case STAT_PX_ST_SV:
Willy Tarreau91861262007-10-17 17:06:05 +02002547 /* stats.sv has been initialized above */
Willy Tarreau295a8372011-03-10 11:25:07 +01002548 for (; si->applet.ctx.stats.sv != NULL; si->applet.ctx.stats.sv = sv->next) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002549 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 +02002550
Willy Tarreau4e33d862009-10-11 23:35:10 +02002551 if (buffer_almost_full(rep))
2552 return 0;
2553
Willy Tarreau295a8372011-03-10 11:25:07 +01002554 sv = si->applet.ctx.stats.sv;
Willy Tarreau91861262007-10-17 17:06:05 +02002555
Willy Tarreau295a8372011-03-10 11:25:07 +01002556 if (si->applet.ctx.stats.flags & STAT_BOUND) {
2557 if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SV)))
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002558 break;
2559
Willy Tarreau295a8372011-03-10 11:25:07 +01002560 if (si->applet.ctx.stats.sid != -1 && sv->puid != si->applet.ctx.stats.sid)
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002561 continue;
2562 }
2563
Willy Tarreau44267702011-10-28 15:35:33 +02002564 if (sv->track)
2565 svs = sv->track;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002566 else
2567 svs = sv;
2568
Willy Tarreau91861262007-10-17 17:06:05 +02002569 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002570 if (!(svs->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +01002571 sv_state = 6;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002572 else if (svs->state & SRV_RUNNING) {
2573 if (svs->health == svs->rise + svs->fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02002574 sv_state = 3; /* UP */
2575 else
2576 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01002577
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002578 if (svs->state & SRV_GOINGDOWN)
Willy Tarreau2ea81932007-11-30 12:04:38 +01002579 sv_state += 2;
2580 }
Willy Tarreau91861262007-10-17 17:06:05 +02002581 else
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002582 if (svs->health)
Willy Tarreau91861262007-10-17 17:06:05 +02002583 sv_state = 1; /* going up */
2584 else
2585 sv_state = 0; /* DOWN */
2586
Willy Tarreau295a8372011-03-10 11:25:07 +01002587 if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (si->applet.ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02002588 /* do not report servers which are DOWN */
Willy Tarreau295a8372011-03-10 11:25:07 +01002589 si->applet.ctx.stats.sv = sv->next;
Willy Tarreau91861262007-10-17 17:06:05 +02002590 continue;
2591 }
2592
Willy Tarreau295a8372011-03-10 11:25:07 +01002593 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002594 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
2595 "UP %d/%d &darr;", "UP",
2596 "NOLB %d/%d &darr;", "NOLB",
2597 "<i>no check</i>" };
Cyril Bonté0dae5852010-02-03 00:26:28 +01002598 if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) {
Cyril Bontécd19e512010-01-31 22:34:03 +01002599 chunk_printf(&msg,
2600 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002601 "<tr class=\"maintain\">"
Cyril Bontécd19e512010-01-31 22:34:03 +01002602 );
2603 }
2604 else {
2605 chunk_printf(&msg,
2606 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002607 "<tr class=\"%s%d\">",
Cyril Bontécd19e512010-01-31 22:34:03 +01002608 (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state);
2609 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002610
Willy Tarreau295a8372011-03-10 11:25:07 +01002611 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté474be412010-10-12 00:14:36 +02002612 chunk_printf(&msg,
2613 "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
2614 sv->id);
2615 }
2616
2617 chunk_printf(&msg, "<td class=ac");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002618
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002619 if (uri->flags&ST_SHLGNDS) {
2620 char str[INET6_ADDRSTRLEN];
2621
Willy Tarreau631f01c2011-09-05 00:36:48 +02002622 chunk_printf(&msg, " title=\"");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002623
Willy Tarreau631f01c2011-09-05 00:36:48 +02002624 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
David du Colombier6f5ccb12011-03-10 22:26:24 +01002625 case AF_INET:
Willy Tarreau631f01c2011-09-05 00:36:48 +02002626 chunk_printf(&msg, "IPv4: %s:%d, ", str, get_host_port(&sv->addr));
David du Colombier6f5ccb12011-03-10 22:26:24 +01002627 break;
2628 case AF_INET6:
Willy Tarreau631f01c2011-09-05 00:36:48 +02002629 chunk_printf(&msg, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr));
2630 break;
2631 case AF_UNIX:
2632 chunk_printf(&msg, "unix, ");
2633 break;
2634 case -1:
2635 chunk_printf(&msg, "(%s), ", strerror(errno));
2636 break;
2637 default: /* address family not supported */
David du Colombier6f5ccb12011-03-10 22:26:24 +01002638 break;
2639 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002640
2641 /* id */
Willy Tarreau631f01c2011-09-05 00:36:48 +02002642 chunk_printf(&msg, "id: %d", sv->puid);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002643
2644 /* cookie */
2645 if (sv->cookie) {
2646 struct chunk src;
2647
2648 chunk_printf(&msg, ", cookie: '");
2649
2650 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
2651 chunk_htmlencode(&msg, &src);
2652
2653 chunk_printf(&msg, "'");
2654 }
2655
2656 chunk_printf(&msg, "\"");
2657 }
2658
2659 chunk_printf(&msg,
Willy Tarreaue0454092010-02-26 12:29:07 +01002660 ">%s<a name=\"%s/%s\"></a>"
2661 "<a class=lfsb href=\"#%s/%s\">%s</a>%s</td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002662 /* queue : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002663 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002664 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002665 "<td>%s</td><td>%s</td><td></td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002666 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002667 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002668 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002669 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002670 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002671 px->id, sv->id, px->id, sv->id, sv->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01002672 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002673 U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"),
2674 U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max),
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002675 U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-"));
2676
2677 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2678 if (px->mode == PR_MODE_HTTP) {
2679 int i;
2680
2681 chunk_printf(&msg, " title=\"rsp codes:");
2682
2683 for (i = 1; i < 6; i++)
2684 chunk_printf(&msg, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]);
2685
2686 chunk_printf(&msg, " other=%lld\"", sv->counters.p.http.rsp[0]);
2687 }
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002688
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002689 chunk_printf(&msg,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002690 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002691 ">%s%s%s</td><td>%s</td>",
2692 (px->mode == PR_MODE_HTTP)?"<u>":"",
2693 U2H0(sv->counters.cum_sess),
2694 (px->mode == PR_MODE_HTTP)?"</u>":"",
2695 U2H1(sv->counters.cum_lbconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002696
2697 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002698 /* bytes : in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002699 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002700 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002701 "<td></td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01002702 /* errors : request, connect */
2703 "<td></td><td>%s</td>"
2704 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002705 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002706 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002707 "<td>%lld</td><td>%lld</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002708 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002709 U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out),
2710 U2H2(sv->counters.failed_secu),
Willy Tarreauae526782010-03-04 20:34:23 +01002711 U2H3(sv->counters.failed_conns),
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002712 sv->counters.cli_aborts,
2713 sv->counters.srv_aborts,
Willy Tarreauae526782010-03-04 20:34:23 +01002714 U2H6(sv->counters.failed_resp),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002715 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002716
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002717 /* status, lest check */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002718 chunk_printf(&msg, "<td class=ac>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002719
Cyril Bontécd19e512010-01-31 22:34:03 +01002720 if (sv->state & SRV_MAINTAIN) {
2721 chunk_printf(&msg, "%s ",
2722 human_time(now.tv_sec - sv->last_change, 1));
2723 chunk_printf(&msg, "MAINT");
2724 }
Cyril Bonté0dae5852010-02-03 00:26:28 +01002725 else if (svs != sv && svs->state & SRV_MAINTAIN) {
2726 chunk_printf(&msg, "%s ",
2727 human_time(now.tv_sec - svs->last_change, 1));
2728 chunk_printf(&msg, "MAINT(via)");
2729 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002730 else if (svs->state & SRV_CHECKED) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002731 chunk_printf(&msg, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01002732 human_time(now.tv_sec - svs->last_change, 1));
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002733
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002734 chunk_printf(&msg,
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002735 srv_hlt_st[sv_state],
2736 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
2737 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002738 }
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002739
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002740 if (sv->state & SRV_CHECKED) {
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002741 chunk_printf(&msg, "</td><td class=ac title=\"%s",
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002742 get_check_status_description(sv->check_status));
2743
2744 if (*sv->check_desc) {
2745 struct chunk src;
2746
2747 chunk_printf(&msg, ": ");
2748
2749 chunk_initlen(&src, sv->check_desc, 0, strlen(sv->check_desc));
2750 chunk_htmlencode(&msg, &src);
2751 }
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002752
Willy Tarreaue0454092010-02-26 12:29:07 +01002753 chunk_printf(&msg, "\"><u> %s%s",
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002754 tv_iszero(&sv->check_start)?"":"* ",
2755 get_check_status_info(sv->check_status));
2756
2757 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002758 chunk_printf(&msg, "/%d", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002759
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002760 if (sv->check_status >= HCHK_STATUS_CHECKED && sv->check_duration >= 0)
Willy Tarreaue0454092010-02-26 12:29:07 +01002761 chunk_printf(&msg, " in %lums</u>", sv->check_duration);
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002762 } else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002763 chunk_printf(&msg, "</td><td>");
Willy Tarreau91861262007-10-17 17:06:05 +02002764
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002765 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002766 /* weight */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002767 "</td><td class=ac>%d</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002768 /* act, bck */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002769 "<td class=ac>%s</td><td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002770 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01002771 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +02002772 (sv->state & SRV_BACKUP) ? "-" : "Y",
2773 (sv->state & SRV_BACKUP) ? "Y" : "-");
2774
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002775 /* check failures: unique, fatal, down time */
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002776 if (sv->state & SRV_CHECKED) {
Willy Tarreaue0454092010-02-26 12:29:07 +01002777 chunk_printf(&msg, "<td title=\"Failed Health Checks%s\"><u>%lld",
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002778 svs->observe?"/Health Analyses":"", svs->counters.failed_checks);
2779
2780 if (svs->observe)
2781 chunk_printf(&msg, "/%lld", svs->counters.failed_hana);
2782
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002783 chunk_printf(&msg,
Willy Tarreaue0454092010-02-26 12:29:07 +01002784 "</u></td>"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002785 "<td>%lld</td><td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002786 "",
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002787 svs->counters.down_trans, human_time(srv_downtime(sv), 1));
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002788 } else if (sv != svs)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002789 chunk_printf(&msg,
Krzysztof Piotr Oledzki88a14af2010-01-05 18:33:01 +01002790 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>",
2791 svs->proxy->id, svs->id, svs->proxy->id, svs->id);
Willy Tarreau55bb8452007-10-17 18:44:57 +02002792 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002793 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002794 "<td colspan=3></td>");
2795
2796 /* throttle */
2797 if ((sv->state & SRV_WARMINGUP) &&
2798 now.tv_sec < sv->last_change + sv->slowstart &&
2799 now.tv_sec >= sv->last_change) {
2800 unsigned int ratio;
2801 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002802 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002803 "<td class=ac>%d %%</td></tr>\n", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002804 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002805 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002806 "<td class=ac>-</td></tr>\n");
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002807 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02002808 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002809 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
2810 "UP %d/%d,", "UP,",
2811 "NOLB %d/%d,", "NOLB,",
2812 "no check," };
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002813 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002814 /* pxid, name */
2815 "%s,%s,"
2816 /* queue : current, max */
2817 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002818 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002819 "%d,%d,%s,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002820 /* bytes : in, out */
2821 "%lld,%lld,"
2822 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002823 ",%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002824 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002825 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002826 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002827 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002828 "",
2829 px->id, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002830 sv->nbpend, sv->counters.nbpend_max,
2831 sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002832 sv->counters.bytes_in, sv->counters.bytes_out,
2833 sv->counters.failed_secu,
2834 sv->counters.failed_conns, sv->counters.failed_resp,
2835 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002836
Willy Tarreau55bb8452007-10-17 18:44:57 +02002837 /* status */
Cyril Bontécd19e512010-01-31 22:34:03 +01002838 if (sv->state & SRV_MAINTAIN) {
2839 chunk_printf(&msg, "MAINT,");
Cyril Bonté0dae5852010-02-03 00:26:28 +01002840 }
2841 else if (svs != sv && svs->state & SRV_MAINTAIN) {
2842 chunk_printf(&msg, "MAINT(via),");
2843 }
2844 else {
Cyril Bontécd19e512010-01-31 22:34:03 +01002845 chunk_printf(&msg,
2846 srv_hlt_st[sv_state],
2847 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
2848 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
2849 }
Willy Tarreau91861262007-10-17 17:06:05 +02002850
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002851 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002852 /* weight, active, backup */
2853 "%d,%d,%d,"
2854 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01002855 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002856 (sv->state & SRV_BACKUP) ? 0 : 1,
2857 (sv->state & SRV_BACKUP) ? 1 : 0);
2858
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002859 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +02002860 if (sv->state & SRV_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002861 chunk_printf(&msg,
Willy Tarreau3b88d442009-04-11 20:44:08 +02002862 "%lld,%lld,%d,%d,",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002863 sv->counters.failed_checks, sv->counters.down_trans,
Willy Tarreau1772ece2009-04-03 14:49:12 +02002864 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +02002865 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002866 chunk_printf(&msg,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002867 ",,,,");
2868
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002869 /* queue limit, pid, iid, sid, */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002870 chunk_printf(&msg,
Willy Tarreaudcd47712007-11-04 23:35:08 +01002871 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002872 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +01002873 LIM2A0(sv->maxqueue, ""),
2874 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002875
2876 /* throttle */
2877 if ((sv->state & SRV_WARMINGUP) &&
2878 now.tv_sec < sv->last_change + sv->slowstart &&
2879 now.tv_sec >= sv->last_change) {
2880 unsigned int ratio;
2881 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002882 chunk_printf(&msg, "%d", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002883 }
2884
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002885 /* sessions: lbtot */
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002886 chunk_printf(&msg, ",%lld,", sv->counters.cum_lbconn);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002887
2888 /* tracked */
Willy Tarreau44267702011-10-28 15:35:33 +02002889 if (sv->track)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002890 chunk_printf(&msg, "%s/%s,",
Willy Tarreau44267702011-10-28 15:35:33 +02002891 sv->track->proxy->id, sv->track->id);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002892 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002893 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002894
Willy Tarreau7f062c42009-03-05 18:43:00 +01002895 /* type */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002896 chunk_printf(&msg, "%d,", STATS_TYPE_SV);
Willy Tarreau7f062c42009-03-05 18:43:00 +01002897
2898 /* rate */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002899 chunk_printf(&msg, "%u,,%u,",
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002900 read_freq_ctr(&sv->sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002901 sv->counters.sps_max);
Willy Tarreau7f062c42009-03-05 18:43:00 +01002902
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002903 if (sv->state & SRV_CHECKED) {
2904 /* check_status */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002905 chunk_printf(&msg, "%s,", get_check_status_info(sv->check_status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002906
2907 /* check_code */
2908 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002909 chunk_printf(&msg, "%u,", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002910 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002911 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002912
2913 /* check_duration */
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002914 if (sv->check_status >= HCHK_STATUS_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002915 chunk_printf(&msg, "%lu,", sv->check_duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002916 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002917 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002918
2919 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002920 chunk_printf(&msg, ",,,");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002921 }
2922
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002923 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2924 if (px->mode == PR_MODE_HTTP) {
2925 int i;
2926
2927 for (i=1; i<6; i++)
2928 chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[i]);
2929
2930 chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[0]);
2931 } else {
2932 chunk_printf(&msg, ",,,,,,");
2933 }
2934
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002935 /* failed health analyses */
2936 chunk_printf(&msg, "%lld,", sv->counters.failed_hana);
2937
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002938 /* requests : req_rate, req_rate_max, req_tot, */
2939 chunk_printf(&msg, ",,,");
2940
Willy Tarreauae526782010-03-04 20:34:23 +01002941 /* errors: cli_aborts, srv_aborts */
2942 chunk_printf(&msg, "%lld,%lld,",
2943 sv->counters.cli_aborts, sv->counters.srv_aborts);
2944
Willy Tarreau7f062c42009-03-05 18:43:00 +01002945 /* finish with EOL */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002946 chunk_printf(&msg, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002947 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002948 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002949 return 0;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002950 } /* for sv */
Willy Tarreau91861262007-10-17 17:06:05 +02002951
Willy Tarreau295a8372011-03-10 11:25:07 +01002952 si->applet.ctx.stats.px_st = STAT_PX_ST_BE;
Willy Tarreau91861262007-10-17 17:06:05 +02002953 /* fall through */
2954
Willy Tarreau295a8372011-03-10 11:25:07 +01002955 case STAT_PX_ST_BE:
Willy Tarreau91861262007-10-17 17:06:05 +02002956 /* print the backend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002957 if ((px->cap & PR_CAP_BE) &&
Willy Tarreau295a8372011-03-10 11:25:07 +01002958 (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_BE)))) {
2959 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002960 chunk_printf(&msg, "<tr class=\"backend\">");
Willy Tarreau295a8372011-03-10 11:25:07 +01002961 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002962 /* Column sub-heading for Enable or Disable server */
2963 chunk_printf(&msg, "<td></td>");
2964 }
2965 chunk_printf(&msg, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002966
2967 if (uri->flags&ST_SHLGNDS) {
2968 /* balancing */
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01002969 chunk_printf(&msg, " title=\"balancing: %s",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002970 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01002971
2972 /* cookie */
2973 if (px->cookie_name) {
2974 struct chunk src;
2975
2976 chunk_printf(&msg, ", cookie: '");
2977
2978 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
2979 chunk_htmlencode(&msg, &src);
2980
2981 chunk_printf(&msg, "'");
2982 }
2983
2984 chunk_printf(&msg, "\"");
2985
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002986 }
2987
2988 chunk_printf(&msg,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002989 /* name */
Willy Tarreaue0454092010-02-26 12:29:07 +01002990 ">%s<a name=\"%s/Backend\"></a>"
2991 "<a class=lfsb href=\"#%s/Backend\">Backend</a>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002992 /* queue : current, max */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002993 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002994 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002995 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002996 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002997 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002998 px->id, px->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01002999 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003000 U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->be_counters.nbpend_max),
3001 U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->be_counters.sps_max));
Willy Tarreaua3e49422009-05-10 19:19:41 +02003002
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003003 chunk_printf(&msg,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003004 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003005 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003006 "<td"
3007 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003008 U2H2(px->beconn), U2H3(px->be_counters.conn_max), U2H4(px->fullconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003009
3010 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
3011 if (px->mode == PR_MODE_HTTP) {
3012 int i;
3013
3014 chunk_printf(&msg, " title=\"rsp codes:");
3015
3016 for (i = 1; i < 6; i++)
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003017 chunk_printf(&msg, " %dxx=%lld", i, px->be_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003018
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003019 chunk_printf(&msg, " other=%lld\"", px->be_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003020 }
3021
3022 chunk_printf(&msg,
3023 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01003024 ">%s%s%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003025 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003026 "<td>%s</td><td>%s</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003027 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01003028 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003029 U2H6(px->be_counters.cum_conn),
Willy Tarreaue0454092010-02-26 12:29:07 +01003030 (px->mode == PR_MODE_HTTP)?"</u>":"",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003031 U2H7(px->be_counters.cum_lbconn),
3032 U2H8(px->be_counters.bytes_in), U2H9(px->be_counters.bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003033
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003034 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02003035 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003036 "<td>%s</td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01003037 /* errors : request, connect */
3038 "<td></td><td>%s</td>"
3039 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01003040 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003041 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003042 "<td>%lld</td><td>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003043 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +02003044 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003045 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +02003046 * active and backups. */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003047 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
3048 "<td class=ac>%d</td><td class=ac>%d</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02003049 "",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003050 U2H0(px->be_counters.denied_req), U2H1(px->be_counters.denied_resp),
3051 U2H2(px->be_counters.failed_conns),
3052 px->be_counters.cli_aborts,
3053 px->be_counters.srv_aborts,
3054 U2H5(px->be_counters.failed_resp),
3055 px->be_counters.retries, px->be_counters.redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003056 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +01003057 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
3058 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5542af62007-12-03 02:04:00 +01003059 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01003060 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003061
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003062 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003063 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02003064 "<td class=ac>&nbsp;</td><td>%d</td>"
3065 "<td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003066 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003067 "</tr>",
3068 px->down_trans,
3069 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +02003070 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003071 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02003072 /* pxid, name */
3073 "%s,BACKEND,"
3074 /* queue : current, max */
3075 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003076 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003077 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003078 /* bytes : in, out */
3079 "%lld,%lld,"
3080 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003081 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02003082 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003083 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02003084 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003085 "%lld,%lld,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003086 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +02003087 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02003088 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +02003089 * active and backups. */
3090 "%s,"
3091 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01003092 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02003093 ",%d,%d,%d,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01003094 /* pid, iid, sid, throttle, lbtot, tracked, type */
Willy Tarreau3b88d442009-04-11 20:44:08 +02003095 "%d,%d,0,,%lld,,%d,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003096 /* rate, rate_lim, rate_max, */
3097 "%u,,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02003098 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003099 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02003100 px->id,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003101 px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max,
3102 px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn,
3103 px->be_counters.bytes_in, px->be_counters.bytes_out,
3104 px->be_counters.denied_req, px->be_counters.denied_resp,
3105 px->be_counters.failed_conns, px->be_counters.failed_resp,
3106 px->be_counters.retries, px->be_counters.redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +01003107 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5542af62007-12-03 02:04:00 +01003108 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01003109 px->srv_act, px->srv_bck,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003110 px->down_trans, (int)(now.tv_sec - px->last_change),
Willy Tarreau20697042007-11-15 23:26:18 +01003111 px->srv?be_downtime(px):0,
Willy Tarreauddbb82f2007-12-05 10:34:49 +01003112 relative_pid, px->uuid,
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003113 px->be_counters.cum_lbconn, STATS_TYPE_BE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02003114 read_freq_ctr(&px->be_sess_per_sec),
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003115 px->be_counters.sps_max);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003116
3117 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
3118 if (px->mode == PR_MODE_HTTP) {
3119 int i;
3120
3121 for (i=1; i<6; i++)
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003122 chunk_printf(&msg, "%lld,", px->be_counters.p.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003123
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003124 chunk_printf(&msg, "%lld,", px->be_counters.p.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003125 } else {
3126 chunk_printf(&msg, ",,,,,,");
3127 }
3128
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01003129 /* failed health analyses */
3130 chunk_printf(&msg, ",");
3131
Willy Tarreaud9b587f2010-02-26 10:05:55 +01003132 /* requests : req_rate, req_rate_max, req_tot, */
3133 chunk_printf(&msg, ",,,");
3134
Willy Tarreauae526782010-03-04 20:34:23 +01003135 /* errors: cli_aborts, srv_aborts */
3136 chunk_printf(&msg, "%lld,%lld,",
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01003137 px->be_counters.cli_aborts, px->be_counters.srv_aborts);
Willy Tarreauae526782010-03-04 20:34:23 +01003138
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02003139 /* finish with EOL */
3140 chunk_printf(&msg, "\n");
3141
Willy Tarreau55bb8452007-10-17 18:44:57 +02003142 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003143 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02003144 return 0;
3145 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01003146
Willy Tarreau295a8372011-03-10 11:25:07 +01003147 si->applet.ctx.stats.px_st = STAT_PX_ST_END;
Willy Tarreau91861262007-10-17 17:06:05 +02003148 /* fall through */
3149
Willy Tarreau295a8372011-03-10 11:25:07 +01003150 case STAT_PX_ST_END:
3151 if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02003152 chunk_printf(&msg, "</table>");
3153
Willy Tarreau295a8372011-03-10 11:25:07 +01003154 if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02003155 /* close the form used to enable/disable this proxy servers */
3156 chunk_printf(&msg,
3157 "Choose the action to perform on the checked servers : "
3158 "<select name=action>"
3159 "<option value=\"\"></option>"
3160 "<option value=\"disable\">Disable</option>"
3161 "<option value=\"enable\">Enable</option>"
3162 "</select>"
Cyril Bontéaa0a45d2012-04-04 12:57:20 +02003163 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
Cyril Bonté70be45d2010-10-12 00:14:35 +02003164 "&nbsp;<input type=\"submit\" value=\"Apply\">"
3165 "</form>",
Cyril Bontéaa0a45d2012-04-04 12:57:20 +02003166 px->uuid);
Cyril Bonté70be45d2010-10-12 00:14:35 +02003167 }
3168
3169 chunk_printf(&msg, "<p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +02003170
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02003171 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02003172 return 0;
3173 }
Willy Tarreau91861262007-10-17 17:06:05 +02003174
Willy Tarreau295a8372011-03-10 11:25:07 +01003175 si->applet.ctx.stats.px_st = STAT_PX_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02003176 /* fall through */
3177
Willy Tarreau295a8372011-03-10 11:25:07 +01003178 case STAT_PX_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02003179 return 1;
3180
3181 default:
3182 /* unknown state, we should put an abort() here ! */
3183 return 1;
3184 }
3185}
3186
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003187/* This function dumps a complete session state onto the stream intreface's
3188 * read buffer. The data_ctx must have been zeroed first, and the flags
3189 * properly set. The session has to be set in data_ctx.sess.target. It returns
3190 * 0 if the output buffer is full and it needs to be called again, otherwise
3191 * non-zero. It is designed to be called from stats_dump_sess_to_buffer() below.
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003192 */
Simon Horman9bd2c732011-06-15 15:18:44 +09003193static int stats_dump_full_sess_to_buffer(struct stream_interface *si)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003194{
3195 struct tm tm;
3196 struct chunk msg;
3197 struct session *sess;
3198 extern const char *monthname[12];
3199 char pn[INET6_ADDRSTRLEN];
3200
3201 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau295a8372011-03-10 11:25:07 +01003202 sess = si->applet.ctx.sess.target;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003203
Willy Tarreau295a8372011-03-10 11:25:07 +01003204 if (si->applet.ctx.sess.section > 0 && si->applet.ctx.sess.uid != sess->uniq_id) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003205 /* session changed, no need to go any further */
3206 chunk_printf(&msg, " *** session terminated while we were watching it ***\n");
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003207 if (buffer_feed_chunk(si->ib, &msg) >= 0)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003208 return 0;
Willy Tarreau295a8372011-03-10 11:25:07 +01003209 si->applet.ctx.sess.target = NULL;
3210 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003211 return 1;
3212 }
3213
Willy Tarreau295a8372011-03-10 11:25:07 +01003214 switch (si->applet.ctx.sess.section) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003215 case 0: /* main status of the session */
Willy Tarreau295a8372011-03-10 11:25:07 +01003216 si->applet.ctx.sess.uid = sess->uniq_id;
3217 si->applet.ctx.sess.section = 1;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003218 /* fall through */
3219
3220 case 1:
3221 chunk_printf(&msg,
3222 "%p: id=%u, proto=%s",
3223 sess,
3224 sess->uniq_id,
3225 sess->listener->proto->name);
3226
Willy Tarreau6471afb2011-09-23 10:54:59 +02003227 switch (addr_to_str(&sess->si[0].addr.from, pn, sizeof(pn))) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003228 case AF_INET:
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003229 case AF_INET6:
Willy Tarreau631f01c2011-09-05 00:36:48 +02003230 chunk_printf(&msg, " source=%s:%d\n",
Willy Tarreau6471afb2011-09-23 10:54:59 +02003231 pn, get_host_port(&sess->si[0].addr.from));
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003232 break;
3233 case AF_UNIX:
Willy Tarreau631f01c2011-09-05 00:36:48 +02003234 chunk_printf(&msg, " source=unix:%d\n", sess->listener->luid);
Emeric Brun837ca522010-10-22 16:19:01 +02003235 break;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003236 default:
3237 /* no more information to print right now */
3238 chunk_printf(&msg, "\n");
3239 break;
3240 }
3241
3242 chunk_printf(&msg,
3243 " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n",
Willy Tarreauee28de02010-06-01 09:51:00 +02003244 sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003245
3246 chunk_printf(&msg,
3247 " frontend=%s (id=%u mode=%s), listener=%s (id=%u)\n",
3248 sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp",
3249 sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?",
3250 sess->listener ? sess->listener->luid : 0);
3251
Willy Tarreau50943332011-09-02 17:33:05 +02003252 if (sess->be->cap & PR_CAP_BE)
3253 chunk_printf(&msg,
3254 " backend=%s (id=%u mode=%s) server=%s (id=%u)\n",
3255 sess->be->id,
3256 sess->be->uuid, sess->be->mode ? "http" : "tcp",
3257 target_srv(&sess->target) ? target_srv(&sess->target)->id : "<none>",
3258 target_srv(&sess->target) ? target_srv(&sess->target)->puid : 0);
3259 else
3260 chunk_printf(&msg, " backend=<NONE> (id=-1 mode=-) server=<NONE> (id=-1)\n");
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003261
3262 chunk_printf(&msg,
3263 " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s)\n",
3264 sess->task,
3265 sess->task->state,
3266 sess->task->nice, sess->task->calls,
3267 sess->task->expire ?
3268 tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" :
3269 human_time(TICKS_TO_MS(sess->task->expire - now_ms),
3270 TICKS_TO_MS(1000)) : "<NEVER>",
3271 task_in_rq(sess->task) ? ", running" : "");
3272
3273 get_localtime(sess->logs.accept_date.tv_sec, &tm);
3274 chunk_printf(&msg,
3275 " task created [%02d/%s/%04d:%02d:%02d:%02d.%06d] (age=%s)\n",
3276 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
3277 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec),
3278 human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1));
3279
3280 chunk_printf(&msg,
3281 " si[0]=%p (state=%d flags=0x%02x fd=%d exp=%s, et=0x%03x)\n",
3282 &sess->si[0],
3283 sess->si[0].state,
3284 sess->si[0].flags,
3285 sess->si[0].fd,
3286 sess->si[0].exp ?
3287 tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" :
3288 human_time(TICKS_TO_MS(sess->si[0].exp - now_ms),
3289 TICKS_TO_MS(1000)) : "<NEVER>",
3290 sess->si[0].err_type);
3291
3292 chunk_printf(&msg,
3293 " si[1]=%p (state=%d flags=0x%02x fd=%d exp=%s, et=0x%03x)\n",
3294 &sess->si[1],
3295 sess->si[1].state,
3296 sess->si[1].flags,
3297 sess->si[1].fd,
3298 sess->si[1].exp ?
3299 tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" :
3300 human_time(TICKS_TO_MS(sess->si[1].exp - now_ms),
3301 TICKS_TO_MS(1000)) : "<NEVER>",
3302 sess->si[1].err_type);
3303
3304 chunk_printf(&msg,
3305 " txn=%p (flags=0x%x meth=%d status=%d req.st=%d rsp.st=%d)\n",
3306 &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status,
3307 sess->txn.req.msg_state, sess->txn.rsp.msg_state);
3308
3309
3310 chunk_printf(&msg,
Willy Tarreaud8ee85a2011-03-28 16:06:28 +02003311 " req=%p (f=0x%06x an=0x%x l=%d sndmx=%d pipe=%d fwd=%d)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003312 " an_exp=%s",
3313 sess->req,
3314 sess->req->flags, sess->req->analysers,
3315 sess->req->l, sess->req->send_max,
3316 sess->req->pipe ? sess->req->pipe->data : 0,
3317 sess->req->to_forward,
3318 sess->req->analyse_exp ?
3319 human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms),
3320 TICKS_TO_MS(1000)) : "<NEVER>");
3321
3322 chunk_printf(&msg,
3323 " rex=%s",
3324 sess->req->rex ?
3325 human_time(TICKS_TO_MS(sess->req->rex - now_ms),
3326 TICKS_TO_MS(1000)) : "<NEVER>");
3327
3328 chunk_printf(&msg,
3329 " wex=%s\n"
3330 " data=%p r=%d w=%d lr=%d total=%lld\n",
3331 sess->req->wex ?
3332 human_time(TICKS_TO_MS(sess->req->wex - now_ms),
3333 TICKS_TO_MS(1000)) : "<NEVER>",
3334 sess->req->data,
Willy Tarreau4e1554c2010-03-21 23:21:00 +01003335 (int)(sess->req->r - sess->req->data),
3336 (int)(sess->req->w - sess->req->data),
3337 (int)(sess->req->lr - sess->req->data),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003338 sess->req->total);
3339
3340 chunk_printf(&msg,
Willy Tarreaud8ee85a2011-03-28 16:06:28 +02003341 " res=%p (f=0x%06x an=0x%x l=%d sndmx=%d pipe=%d fwd=%d)\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003342 " an_exp=%s",
3343 sess->rep,
3344 sess->rep->flags, sess->rep->analysers,
3345 sess->rep->l, sess->rep->send_max,
3346 sess->rep->pipe ? sess->rep->pipe->data : 0,
3347 sess->rep->to_forward,
3348 sess->rep->analyse_exp ?
3349 human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms),
3350 TICKS_TO_MS(1000)) : "<NEVER>");
3351
3352 chunk_printf(&msg,
3353 " rex=%s",
3354 sess->rep->rex ?
3355 human_time(TICKS_TO_MS(sess->rep->rex - now_ms),
3356 TICKS_TO_MS(1000)) : "<NEVER>");
3357
3358 chunk_printf(&msg,
3359 " wex=%s\n"
3360 " data=%p r=%d w=%d lr=%d total=%lld\n",
3361 sess->rep->wex ?
3362 human_time(TICKS_TO_MS(sess->rep->wex - now_ms),
3363 TICKS_TO_MS(1000)) : "<NEVER>",
3364 sess->rep->data,
Willy Tarreau4e1554c2010-03-21 23:21:00 +01003365 (int)(sess->rep->r - sess->rep->data),
3366 (int)(sess->rep->w - sess->rep->data),
3367 (int)(sess->rep->lr - sess->rep->data),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003368 sess->rep->total);
3369
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003370 if (buffer_feed_chunk(si->ib, &msg) >= 0)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003371 return 0;
3372
3373 /* use other states to dump the contents */
3374 }
3375 /* end of dump */
Willy Tarreau295a8372011-03-10 11:25:07 +01003376 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003377 return 1;
3378}
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003379
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003380/* This function dumps all sessions' states onto the stream intreface's
3381 * read buffer. The data_ctx must have been zeroed first, and the flags
3382 * properly set. It returns 0 if the output buffer is full and it needs
3383 * to be called again, otherwise non-zero. It is designed to be called
3384 * from stats_dump_sess_to_buffer() below.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003385 */
Simon Horman9bd2c732011-06-15 15:18:44 +09003386static int stats_dump_sess_to_buffer(struct stream_interface *si)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003387{
3388 struct chunk msg;
3389
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003390 if (unlikely(si->ib->flags & (BF_WRITE_ERROR|BF_SHUTW))) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003391 /* If we're forced to shut down, we might have to remove our
3392 * reference to the last session being dumped.
3393 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003394 if (si->applet.state == STAT_ST_LIST) {
3395 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) {
3396 LIST_DEL(&si->applet.ctx.sess.bref.users);
3397 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003398 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003399 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003400 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003401 }
3402
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003403 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003404
Willy Tarreau295a8372011-03-10 11:25:07 +01003405 switch (si->applet.state) {
3406 case STAT_ST_INIT:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003407 /* the function had not been called yet, let's prepare the
3408 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003409 * pointer to the first in the global list. When a target
3410 * session is being destroyed, it is responsible for updating
3411 * this pointer. We know we have reached the end when this
3412 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003413 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003414 LIST_INIT(&si->applet.ctx.sess.bref.users);
3415 si->applet.ctx.sess.bref.ref = sessions.n;
3416 si->applet.state = STAT_ST_LIST;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003417 /* fall through */
3418
Willy Tarreau295a8372011-03-10 11:25:07 +01003419 case STAT_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003420 /* first, let's detach the back-ref from a possible previous session */
Willy Tarreau295a8372011-03-10 11:25:07 +01003421 if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) {
3422 LIST_DEL(&si->applet.ctx.sess.bref.users);
3423 LIST_INIT(&si->applet.ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003424 }
3425
3426 /* and start from where we stopped */
Willy Tarreau295a8372011-03-10 11:25:07 +01003427 while (si->applet.ctx.sess.bref.ref != &sessions) {
Cyril Bontéacd7d632010-11-01 19:26:02 +01003428 char pn[INET6_ADDRSTRLEN];
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003429 struct session *curr_sess;
3430
Willy Tarreau295a8372011-03-10 11:25:07 +01003431 curr_sess = LIST_ELEM(si->applet.ctx.sess.bref.ref, struct session *, list);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003432
Willy Tarreau295a8372011-03-10 11:25:07 +01003433 if (si->applet.ctx.sess.target) {
3434 if (si->applet.ctx.sess.target != curr_sess)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003435 goto next_sess;
3436
Willy Tarreau295a8372011-03-10 11:25:07 +01003437 LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003438 /* call the proper dump() function and return if we're missing space */
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003439 if (!stats_dump_full_sess_to_buffer(si))
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003440 return 0;
3441
3442 /* session dump complete */
Willy Tarreau295a8372011-03-10 11:25:07 +01003443 LIST_DEL(&si->applet.ctx.sess.bref.users);
3444 LIST_INIT(&si->applet.ctx.sess.bref.users);
3445 si->applet.ctx.sess.target = NULL;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003446 break;
3447 }
3448
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003449 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003450 "%p: proto=%s",
3451 curr_sess,
3452 curr_sess->listener->proto->name);
3453
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003454
Willy Tarreau6471afb2011-09-23 10:54:59 +02003455 switch (addr_to_str(&curr_sess->si[0].addr.from, pn, sizeof(pn))) {
Willy Tarreau631f01c2011-09-05 00:36:48 +02003456 case AF_INET:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003457 case AF_INET6:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003458 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003459 " src=%s:%d fe=%s be=%s srv=%s",
3460 pn,
Willy Tarreau6471afb2011-09-23 10:54:59 +02003461 get_host_port(&curr_sess->si[0].addr.from),
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003462 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02003463 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau827aee92011-03-10 16:55:02 +01003464 target_srv(&curr_sess->target) ? target_srv(&curr_sess->target)->id : "<none>"
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003465 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003466 break;
3467 case AF_UNIX:
Emeric Brun837ca522010-10-22 16:19:01 +02003468 chunk_printf(&msg,
3469 " src=unix:%d fe=%s be=%s srv=%s",
3470 curr_sess->listener->luid,
3471 curr_sess->fe->id,
Willy Tarreau50943332011-09-02 17:33:05 +02003472 (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
Willy Tarreau827aee92011-03-10 16:55:02 +01003473 target_srv(&curr_sess->target) ? target_srv(&curr_sess->target)->id : "<none>"
Emeric Brun837ca522010-10-22 16:19:01 +02003474 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003475 break;
3476 }
3477
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003478 chunk_printf(&msg,
Willy Tarreau65671ab2009-10-04 14:24:59 +02003479 " ts=%02x age=%s calls=%d",
3480 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01003481 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
3482 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003483
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003484 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003485 " rq[f=%06xh,l=%d,an=%02xh,rx=%s",
3486 curr_sess->req->flags,
3487 curr_sess->req->l,
3488 curr_sess->req->analysers,
3489 curr_sess->req->rex ?
3490 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
3491 TICKS_TO_MS(1000)) : "");
3492
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003493 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003494 ",wx=%s",
3495 curr_sess->req->wex ?
3496 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
3497 TICKS_TO_MS(1000)) : "");
3498
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003499 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003500 ",ax=%s]",
3501 curr_sess->req->analyse_exp ?
3502 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
3503 TICKS_TO_MS(1000)) : "");
3504
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003505 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003506 " rp[f=%06xh,l=%d,an=%02xh,rx=%s",
3507 curr_sess->rep->flags,
3508 curr_sess->rep->l,
3509 curr_sess->rep->analysers,
3510 curr_sess->rep->rex ?
3511 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
3512 TICKS_TO_MS(1000)) : "");
3513
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003514 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003515 ",wx=%s",
3516 curr_sess->rep->wex ?
3517 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
3518 TICKS_TO_MS(1000)) : "");
3519
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003520 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003521 ",ax=%s]",
3522 curr_sess->rep->analyse_exp ?
3523 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
3524 TICKS_TO_MS(1000)) : "");
3525
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003526 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003527 " s0=[%d,%1xh,fd=%d,ex=%s]",
3528 curr_sess->si[0].state,
3529 curr_sess->si[0].flags,
3530 curr_sess->si[0].fd,
3531 curr_sess->si[0].exp ?
3532 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
3533 TICKS_TO_MS(1000)) : "");
3534
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003535 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003536 " s1=[%d,%1xh,fd=%d,ex=%s]",
3537 curr_sess->si[1].state,
3538 curr_sess->si[1].flags,
3539 curr_sess->si[1].fd,
3540 curr_sess->si[1].exp ?
3541 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
3542 TICKS_TO_MS(1000)) : "");
3543
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003544 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003545 " exp=%s",
3546 curr_sess->task->expire ?
3547 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
3548 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01003549 if (task_in_rq(curr_sess->task))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003550 chunk_printf(&msg, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003551
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003552 chunk_printf(&msg, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003553
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003554 if (buffer_feed_chunk(si->ib, &msg) >= 0) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003555 /* let's try again later from this session. We add ourselves into
3556 * this session's users so that it can remove us upon termination.
3557 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003558 LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003559 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003560 }
3561
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003562 next_sess:
Willy Tarreau295a8372011-03-10 11:25:07 +01003563 si->applet.ctx.sess.bref.ref = curr_sess->list.n;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003564 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003565
Willy Tarreau295a8372011-03-10 11:25:07 +01003566 if (si->applet.ctx.sess.target) {
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003567 /* specified session not found */
Willy Tarreau295a8372011-03-10 11:25:07 +01003568 if (si->applet.ctx.sess.section > 0)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003569 chunk_printf(&msg, " *** session terminated while we were watching it ***\n");
3570 else
3571 chunk_printf(&msg, "Session not found.\n");
3572
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003573 if (buffer_feed_chunk(si->ib, &msg) >= 0)
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003574 return 0;
3575
Willy Tarreau295a8372011-03-10 11:25:07 +01003576 si->applet.ctx.sess.target = NULL;
3577 si->applet.ctx.sess.uid = 0;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003578 return 1;
3579 }
3580
Willy Tarreau295a8372011-03-10 11:25:07 +01003581 si->applet.state = STAT_ST_FIN;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003582 /* fall through */
3583
3584 default:
Willy Tarreau295a8372011-03-10 11:25:07 +01003585 si->applet.state = STAT_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003586 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003587 }
Emeric Brun1e029aa2010-09-23 18:12:53 +02003588}
3589
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003590/* This function dumps all tables' states onto the stream intreface's
3591 * read buffer. The data_ctx must have been zeroed first, and the flags
3592 * properly set. It returns 0 if the output buffer is full and it needs
3593 * to be called again, otherwise non-zero.
Willy Tarreau69f58c82010-07-12 17:55:33 +02003594 */
Simon Hormanc88b8872011-06-15 15:18:49 +09003595static int stats_table_request(struct stream_interface *si, bool show)
Willy Tarreau69f58c82010-07-12 17:55:33 +02003596{
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003597 struct session *s = si->applet.private;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003598 struct chunk msg;
3599 struct ebmb_node *eb;
3600 int dt;
Simon Hormanc88b8872011-06-15 15:18:49 +09003601 bool skip_entry;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003602
3603 /*
Willy Tarreau295a8372011-03-10 11:25:07 +01003604 * We have 3 possible states in si->applet.state :
3605 * - STAT_ST_INIT : the first call
3606 * - STAT_ST_INFO : the proxy pointer points to the next table to
Willy Tarreau69f58c82010-07-12 17:55:33 +02003607 * dump, the entry pointer is NULL ;
Willy Tarreau295a8372011-03-10 11:25:07 +01003608 * - STAT_ST_LIST : the proxy pointer points to the current table
Willy Tarreau69f58c82010-07-12 17:55:33 +02003609 * and the entry pointer points to the next entry to be dumped,
3610 * and the refcount on the next entry is held ;
Willy Tarreau295a8372011-03-10 11:25:07 +01003611 * - STAT_ST_END : nothing left to dump, the buffer may contain some
Willy Tarreau69f58c82010-07-12 17:55:33 +02003612 * data though.
3613 */
3614
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003615 if (unlikely(si->ib->flags & (BF_WRITE_ERROR|BF_SHUTW))) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02003616 /* in case of abort, remove any refcount we might have set on an entry */
Willy Tarreau295a8372011-03-10 11:25:07 +01003617 if (si->applet.state == STAT_ST_LIST) {
3618 si->applet.ctx.table.entry->ref_cnt--;
3619 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
Willy Tarreauf6efda12010-08-03 20:34:06 +02003620 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02003621 return 1;
3622 }
3623
3624 chunk_init(&msg, trash, sizeof(trash));
3625
Willy Tarreau295a8372011-03-10 11:25:07 +01003626 while (si->applet.state != STAT_ST_FIN) {
3627 switch (si->applet.state) {
3628 case STAT_ST_INIT:
3629 si->applet.ctx.table.proxy = si->applet.ctx.table.target;
3630 if (!si->applet.ctx.table.proxy)
3631 si->applet.ctx.table.proxy = proxy;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003632
Willy Tarreau295a8372011-03-10 11:25:07 +01003633 si->applet.ctx.table.entry = NULL;
3634 si->applet.state = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003635 break;
3636
Willy Tarreau295a8372011-03-10 11:25:07 +01003637 case STAT_ST_INFO:
3638 if (!si->applet.ctx.table.proxy ||
3639 (si->applet.ctx.table.target &&
3640 si->applet.ctx.table.proxy != si->applet.ctx.table.target)) {
3641 si->applet.state = STAT_ST_END;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003642 break;
3643 }
3644
Willy Tarreau295a8372011-03-10 11:25:07 +01003645 if (si->applet.ctx.table.proxy->table.size) {
Simon Hormanc88b8872011-06-15 15:18:49 +09003646 if (show && !stats_dump_table_head_to_buffer(&msg, si, si->applet.ctx.table.proxy,
3647 si->applet.ctx.table.target))
Willy Tarreau69f58c82010-07-12 17:55:33 +02003648 return 0;
3649
Willy Tarreau295a8372011-03-10 11:25:07 +01003650 if (si->applet.ctx.table.target &&
Willy Tarreau69f58c82010-07-12 17:55:33 +02003651 s->listener->perm.ux.level >= ACCESS_LVL_OPER) {
3652 /* dump entries only if table explicitly requested */
Willy Tarreau295a8372011-03-10 11:25:07 +01003653 eb = ebmb_first(&si->applet.ctx.table.proxy->table.keys);
Willy Tarreau69f58c82010-07-12 17:55:33 +02003654 if (eb) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003655 si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key);
3656 si->applet.ctx.table.entry->ref_cnt++;
3657 si->applet.state = STAT_ST_LIST;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003658 break;
3659 }
3660 }
3661 }
Willy Tarreau295a8372011-03-10 11:25:07 +01003662 si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003663 break;
3664
Willy Tarreau295a8372011-03-10 11:25:07 +01003665 case STAT_ST_LIST:
Simon Hormanc88b8872011-06-15 15:18:49 +09003666 skip_entry = false;
3667
Willy Tarreau295a8372011-03-10 11:25:07 +01003668 if (si->applet.ctx.table.data_type >= 0) {
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003669 /* we're filtering on some data contents */
3670 void *ptr;
3671 long long data;
3672
Willy Tarreau295a8372011-03-10 11:25:07 +01003673 dt = si->applet.ctx.table.data_type;
3674 ptr = stktable_data_ptr(&si->applet.ctx.table.proxy->table,
3675 si->applet.ctx.table.entry,
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003676 dt);
3677
3678 data = 0;
3679 switch (stktable_data_types[dt].std_type) {
3680 case STD_T_SINT:
3681 data = stktable_data_cast(ptr, std_t_sint);
3682 break;
3683 case STD_T_UINT:
3684 data = stktable_data_cast(ptr, std_t_uint);
3685 break;
3686 case STD_T_ULL:
3687 data = stktable_data_cast(ptr, std_t_ull);
3688 break;
3689 case STD_T_FRQP:
3690 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Willy Tarreau295a8372011-03-10 11:25:07 +01003691 si->applet.ctx.table.proxy->table.data_arg[dt].u);
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003692 break;
3693 }
3694
3695 /* skip the entry if the data does not match the test and the value */
Willy Tarreau295a8372011-03-10 11:25:07 +01003696 if ((data < si->applet.ctx.table.value &&
3697 (si->applet.ctx.table.data_op == STD_OP_EQ ||
3698 si->applet.ctx.table.data_op == STD_OP_GT ||
3699 si->applet.ctx.table.data_op == STD_OP_GE)) ||
3700 (data == si->applet.ctx.table.value &&
3701 (si->applet.ctx.table.data_op == STD_OP_NE ||
3702 si->applet.ctx.table.data_op == STD_OP_GT ||
3703 si->applet.ctx.table.data_op == STD_OP_LT)) ||
3704 (data > si->applet.ctx.table.value &&
3705 (si->applet.ctx.table.data_op == STD_OP_EQ ||
3706 si->applet.ctx.table.data_op == STD_OP_LT ||
3707 si->applet.ctx.table.data_op == STD_OP_LE)))
Simon Hormanc88b8872011-06-15 15:18:49 +09003708 skip_entry = true;
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003709 }
3710
Simon Hormanc88b8872011-06-15 15:18:49 +09003711 if (show && !skip_entry &&
3712 !stats_dump_table_entry_to_buffer(&msg, si, si->applet.ctx.table.proxy,
Simon Hormand9366582011-06-15 15:18:45 +09003713 si->applet.ctx.table.entry))
3714 return 0;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003715
Willy Tarreau295a8372011-03-10 11:25:07 +01003716 si->applet.ctx.table.entry->ref_cnt--;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003717
Willy Tarreau295a8372011-03-10 11:25:07 +01003718 eb = ebmb_next(&si->applet.ctx.table.entry->key);
Willy Tarreau69f58c82010-07-12 17:55:33 +02003719 if (eb) {
Willy Tarreau295a8372011-03-10 11:25:07 +01003720 struct stksess *old = si->applet.ctx.table.entry;
3721 si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key);
Willy Tarreau8fa52f42012-01-09 11:50:03 +01003722 if (show)
3723 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, old);
3724 else
3725 stksess_kill(&si->applet.ctx.table.proxy->table, old);
Willy Tarreau295a8372011-03-10 11:25:07 +01003726 si->applet.ctx.table.entry->ref_cnt++;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003727 break;
3728 }
3729
Simon Hormanc88b8872011-06-15 15:18:49 +09003730
3731 if (show)
3732 stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
3733 else if (!skip_entry && !si->applet.ctx.table.entry->ref_cnt)
3734 stksess_kill(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry);
3735
Willy Tarreau295a8372011-03-10 11:25:07 +01003736 si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next;
3737 si->applet.state = STAT_ST_INFO;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003738 break;
3739
Willy Tarreau295a8372011-03-10 11:25:07 +01003740 case STAT_ST_END:
3741 si->applet.state = STAT_ST_FIN;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003742 break;
3743 }
3744 }
3745 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003746}
3747
Willy Tarreaud426a182010-03-05 14:58:26 +01003748/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
Willy Tarreau74808cb2009-03-04 15:53:18 +01003749 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
3750 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
3751 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
3752 * lines are respected within the limit of 70 output chars. Lines that are
3753 * continuation of a previous truncated line begin with "+" instead of " "
3754 * after the offset. The new pointer is returned.
3755 */
Willy Tarreaud426a182010-03-05 14:58:26 +01003756static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
3757 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01003758{
3759 int end;
3760 unsigned char c;
3761
3762 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003763 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01003764 return ptr;
3765
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003766 chunk_printf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01003767
Willy Tarreaud426a182010-03-05 14:58:26 +01003768 while (ptr < len && ptr < bsize) {
3769 c = buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01003770 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003771 if (out->len > end - 2)
3772 break;
3773 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01003774 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003775 if (out->len > end - 3)
3776 break;
3777 out->str[out->len++] = '\\';
3778 switch (c) {
3779 case '\t': c = 't'; break;
3780 case '\n': c = 'n'; break;
3781 case '\r': c = 'r'; break;
3782 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01003783 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003784 }
3785 out->str[out->len++] = c;
3786 } else {
3787 if (out->len > end - 5)
3788 break;
3789 out->str[out->len++] = '\\';
3790 out->str[out->len++] = 'x';
3791 out->str[out->len++] = hextab[(c >> 4) & 0xF];
3792 out->str[out->len++] = hextab[c & 0xF];
3793 }
Willy Tarreaud426a182010-03-05 14:58:26 +01003794 if (buf[ptr++] == '\n') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003795 /* we had a line break, let's return now */
3796 out->str[out->len++] = '\n';
3797 *line = ptr;
3798 return ptr;
3799 }
3800 }
3801 /* we have an incomplete line, we return it as-is */
3802 out->str[out->len++] = '\n';
3803 return ptr;
3804}
3805
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003806/* This function dumps all captured errors onto the stream intreface's
3807 * read buffer. The data_ctx must have been zeroed first, and the flags
3808 * properly set. It returns 0 if the output buffer is full and it needs
3809 * to be called again, otherwise non-zero.
Willy Tarreau74808cb2009-03-04 15:53:18 +01003810 */
Simon Horman9bd2c732011-06-15 15:18:44 +09003811static int stats_dump_errors_to_buffer(struct stream_interface *si)
Willy Tarreau74808cb2009-03-04 15:53:18 +01003812{
3813 extern const char *monthname[12];
3814 struct chunk msg;
3815
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003816 if (unlikely(si->ib->flags & (BF_WRITE_ERROR|BF_SHUTW)))
Willy Tarreau61b34732009-10-03 23:49:35 +02003817 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003818
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003819 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau74808cb2009-03-04 15:53:18 +01003820
Willy Tarreau295a8372011-03-10 11:25:07 +01003821 if (!si->applet.ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003822 /* the function had not been called yet, let's prepare the
3823 * buffer for a response.
3824 */
Willy Tarreau10479e42010-12-12 14:00:34 +01003825 struct tm tm;
3826
3827 get_localtime(date.tv_sec, &tm);
3828 chunk_printf(&msg, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n",
3829 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
3830 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000),
3831 error_snapshot_id);
3832
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003833 if (buffer_feed_chunk(si->ib, &msg) >= 0) {
Willy Tarreau10479e42010-12-12 14:00:34 +01003834 /* Socket buffer full. Let's try again later from the same point */
3835 return 0;
3836 }
3837
Willy Tarreau295a8372011-03-10 11:25:07 +01003838 si->applet.ctx.errors.px = proxy;
3839 si->applet.ctx.errors.buf = 0;
3840 si->applet.ctx.errors.bol = 0;
3841 si->applet.ctx.errors.ptr = -1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003842 }
3843
3844 /* we have two inner loops here, one for the proxy, the other one for
3845 * the buffer.
3846 */
Willy Tarreau295a8372011-03-10 11:25:07 +01003847 while (si->applet.ctx.errors.px) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003848 struct error_snapshot *es;
3849
Willy Tarreau295a8372011-03-10 11:25:07 +01003850 if (si->applet.ctx.errors.buf == 0)
3851 es = &si->applet.ctx.errors.px->invalid_req;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003852 else
Willy Tarreau295a8372011-03-10 11:25:07 +01003853 es = &si->applet.ctx.errors.px->invalid_rep;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003854
3855 if (!es->when.tv_sec)
3856 goto next;
3857
Willy Tarreau295a8372011-03-10 11:25:07 +01003858 if (si->applet.ctx.errors.iid >= 0 &&
3859 si->applet.ctx.errors.px->uuid != si->applet.ctx.errors.iid &&
3860 es->oe->uuid != si->applet.ctx.errors.iid)
Willy Tarreau74808cb2009-03-04 15:53:18 +01003861 goto next;
3862
Willy Tarreau295a8372011-03-10 11:25:07 +01003863 if (si->applet.ctx.errors.ptr < 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003864 /* just print headers now */
3865
3866 char pn[INET6_ADDRSTRLEN];
3867 struct tm tm;
3868
3869 get_localtime(es->when.tv_sec, &tm);
Willy Tarreau8811f8e2010-03-05 17:42:58 +01003870 chunk_printf(&msg, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01003871 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003872 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01003873
Willy Tarreau631f01c2011-09-05 00:36:48 +02003874 addr_to_str(&es->src, pn, sizeof(pn));
Willy Tarreau295a8372011-03-10 11:25:07 +01003875 switch (si->applet.ctx.errors.buf) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003876 case 0:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003877 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003878 " frontend %s (#%d): invalid request\n"
3879 " src %s, session #%d, backend %s (#%d), server %s (#%d)\n"
Willy Tarreau10479e42010-12-12 14:00:34 +01003880 " HTTP internal state %d, buffer flags 0x%08x, event #%u\n"
Willy Tarreau8811f8e2010-03-05 17:42:58 +01003881 " request length %d bytes, error at position %d:\n \n",
Willy Tarreau295a8372011-03-10 11:25:07 +01003882 si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid,
Willy Tarreau3fd6cec2010-03-25 06:45:07 +01003883 pn, es->sid, (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
3884 (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003885 es->srv ? es->srv->id : "<NONE>",
3886 es->srv ? es->srv->puid : -1,
Willy Tarreau10479e42010-12-12 14:00:34 +01003887 es->state, es->flags, es->ev_id,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003888 es->len, es->pos);
3889 break;
3890 case 1:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003891 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003892 " backend %s (#%d) : invalid response\n"
3893 " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n"
Willy Tarreau10479e42010-12-12 14:00:34 +01003894 " HTTP internal state %d, buffer flags 0x%08x, event #%u\n"
Willy Tarreau8811f8e2010-03-05 17:42:58 +01003895 " response length %d bytes, error at position %d:\n \n",
Willy Tarreau295a8372011-03-10 11:25:07 +01003896 si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003897 pn, es->sid, es->oe->id, es->oe->uuid,
3898 es->srv ? es->srv->id : "<NONE>",
3899 es->srv ? es->srv->puid : -1,
Willy Tarreau10479e42010-12-12 14:00:34 +01003900 es->state, es->flags, es->ev_id,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003901 es->len, es->pos);
3902 break;
3903 }
3904
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003905 if (buffer_feed_chunk(si->ib, &msg) >= 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003906 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02003907 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003908 }
Willy Tarreau295a8372011-03-10 11:25:07 +01003909 si->applet.ctx.errors.ptr = 0;
3910 si->applet.ctx.errors.sid = es->sid;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003911 }
3912
Willy Tarreau295a8372011-03-10 11:25:07 +01003913 if (si->applet.ctx.errors.sid != es->sid) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003914 /* the snapshot changed while we were dumping it */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003915 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003916 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003917 if (buffer_feed_chunk(si->ib, &msg) >= 0)
Willy Tarreau61b34732009-10-03 23:49:35 +02003918 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003919 goto next;
3920 }
3921
3922 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau295a8372011-03-10 11:25:07 +01003923 while (si->applet.ctx.errors.ptr < es->len && si->applet.ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003924 int newptr;
3925 int newline;
3926
Willy Tarreau295a8372011-03-10 11:25:07 +01003927 newline = si->applet.ctx.errors.bol;
3928 newptr = dump_text_line(&msg, es->buf, sizeof(es->buf), es->len, &newline, si->applet.ctx.errors.ptr);
3929 if (newptr == si->applet.ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02003930 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003931
Willy Tarreau5ec29ff2011-02-13 15:27:22 +01003932 if (buffer_feed_chunk(si->ib, &msg) >= 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003933 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02003934 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003935 }
Willy Tarreau295a8372011-03-10 11:25:07 +01003936 si->applet.ctx.errors.ptr = newptr;
3937 si->applet.ctx.errors.bol = newline;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003938 };
3939 next:
Willy Tarreau295a8372011-03-10 11:25:07 +01003940 si->applet.ctx.errors.bol = 0;
3941 si->applet.ctx.errors.ptr = -1;
3942 si->applet.ctx.errors.buf++;
3943 if (si->applet.ctx.errors.buf > 1) {
3944 si->applet.ctx.errors.buf = 0;
3945 si->applet.ctx.errors.px = si->applet.ctx.errors.px->next;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003946 }
3947 }
3948
3949 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02003950 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003951}
3952
Willy Tarreaub24281b2011-02-13 13:16:36 +01003953struct si_applet http_stats_applet = {
3954 .name = "<STATS>", /* used for logging */
3955 .fct = http_stats_io_handler,
3956};
3957
Simon Horman9bd2c732011-06-15 15:18:44 +09003958static struct si_applet cli_applet = {
Willy Tarreaub24281b2011-02-13 13:16:36 +01003959 .name = "<CLI>", /* used for logging */
3960 .fct = cli_io_handler,
3961};
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003962
Willy Tarreau10522fd2008-07-09 20:12:41 +02003963static struct cfg_kw_list cfg_kws = {{ },{
3964 { CFG_GLOBAL, "stats", stats_parse_global },
3965 { 0, NULL, NULL },
3966}};
3967
3968__attribute__((constructor))
3969static void __dumpstats_module_init(void)
3970{
3971 cfg_register_keywords(&cfg_kws);
3972}
3973
Willy Tarreau91861262007-10-17 17:06:05 +02003974/*
3975 * Local variables:
3976 * c-indent-level: 8
3977 * c-basic-offset: 8
3978 * End:
3979 */