blob: 26951845669de3dbf61541ffba162adb56f7dfdc [file] [log] [blame]
Willy Tarreau91861262007-10-17 17:06:05 +02001/*
Willy Tarreaueb472682010-05-28 18:46:57 +02002 * Functions dedicated to statistics output and the stats socket
Willy Tarreau91861262007-10-17 17:06:05 +02003 *
Willy Tarreaueb472682010-05-28 18:46:57 +02004 * Copyright 2000-2010 Willy Tarreau <w@1wt.eu>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02005 * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl>
Willy Tarreau91861262007-10-17 17:06:05 +02006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
14#include <ctype.h>
15#include <errno.h>
16#include <fcntl.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020020#include <pwd.h>
21#include <grp.h>
Willy Tarreau91861262007-10-17 17:06:05 +020022
23#include <sys/socket.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26
Willy Tarreau10522fd2008-07-09 20:12:41 +020027#include <common/cfgparse.h>
Willy Tarreau91861262007-10-17 17:06:05 +020028#include <common/compat.h>
29#include <common/config.h>
30#include <common/debug.h>
31#include <common/memory.h>
32#include <common/mini-clist.h>
33#include <common/standard.h>
Willy Tarreau0c303ee2008-07-07 00:09:58 +020034#include <common/ticks.h>
Willy Tarreau91861262007-10-17 17:06:05 +020035#include <common/time.h>
36#include <common/uri_auth.h>
37#include <common/version.h>
38
Willy Tarreau91861262007-10-17 17:06:05 +020039#include <types/global.h>
Willy Tarreau91861262007-10-17 17:06:05 +020040
41#include <proto/backend.h>
42#include <proto/buffers.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020043#include <proto/checks.h>
Willy Tarreau91861262007-10-17 17:06:05 +020044#include <proto/dumpstats.h>
45#include <proto/fd.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010046#include <proto/freq_ctr.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020047#include <proto/log.h>
Willy Tarreaua206fa92009-01-25 14:02:00 +010048#include <proto/pipe.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020049#include <proto/proto_uxst.h>
Willy Tarreau89a63132009-08-16 17:41:45 +020050#include <proto/proxy.h>
Willy Tarreau91861262007-10-17 17:06:05 +020051#include <proto/session.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020052#include <proto/server.h>
Willy Tarreaudded32d2008-11-30 19:48:07 +010053#include <proto/stream_interface.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020054#include <proto/stream_sock.h>
Willy Tarreau4726f532009-03-07 17:25:21 +010055#include <proto/task.h>
Willy Tarreau91861262007-10-17 17:06:05 +020056
Willy Tarreau5ca791d2009-08-16 19:06:42 +020057const char stats_sock_usage_msg[] =
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020058 "Unknown command. Please enter one of the following commands only :\n"
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +020059 " clear counters : clear max statistics counters (add 'all' for all counters)\n"
Willy Tarreau88ee3972010-07-13 13:48:00 +020060 " clear table : remove an entry from a table\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020061 " help : this message\n"
62 " prompt : toggle interactive mode with prompt\n"
63 " quit : disconnect\n"
64 " show info : report information about the running process\n"
65 " show stat : report counters for each proxy and server\n"
66 " show errors : report last request and response errors for each proxy\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +010067 " show sess [id] : report the list of current sessions or dump this session\n"
Willy Tarreau69f58c82010-07-12 17:55:33 +020068 " show table [id]: report table usage stats or dump this table's contents\n"
Willy Tarreau38338fa2009-10-10 18:37:29 +020069 " get weight : report a server's current weight\n"
Willy Tarreau4483d432009-10-10 19:30:08 +020070 " set weight : change a server's weight\n"
Willy Tarreau7aabd112010-01-26 10:59:06 +010071 " set timeout : change a timeout setting\n"
Cyril Bontécd19e512010-01-31 22:34:03 +010072 " disable server : set a server in maintenance mode\n"
73 " enable server : re-enable a server that was previously in maintenance mode\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020074 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +020075
Willy Tarreau6162db22009-10-10 17:13:00 +020076const char stats_permission_denied_msg[] =
77 "Permission denied\n"
78 "";
79
Willy Tarreaudecd14d2010-06-01 18:03:19 +020080/* This function is called from the session-level accept() in order to instanciate
Willy Tarreaueb472682010-05-28 18:46:57 +020081 * a new stats socket. It returns a positive value upon success, 0 if the connection
82 * needs to be closed and ignored, or a negative value upon critical failure.
83 */
Willy Tarreaudecd14d2010-06-01 18:03:19 +020084int stats_accept(struct session *s)
Willy Tarreaueb472682010-05-28 18:46:57 +020085{
Willy Tarreaudecd14d2010-06-01 18:03:19 +020086 /* we have a dedicated I/O handler for the stats */
Willy Tarreaueb472682010-05-28 18:46:57 +020087 stream_int_register_handler(&s->si[1], stats_io_handler);
88 s->si[1].private = s;
89 s->si[1].st1 = 0;
90 s->si[1].st0 = STAT_CLI_INIT;
91
Willy Tarreaudecd14d2010-06-01 18:03:19 +020092 tv_zero(&s->logs.tv_request);
93 s->logs.t_queue = 0;
94 s->logs.t_connect = 0;
95 s->logs.t_data = 0;
96 s->logs.t_close = 0;
97 s->logs.bytes_in = s->logs.bytes_out = 0;
98 s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
99 s->logs.srv_queue_size = 0; /* we will get this number soon */
Willy Tarreaueb472682010-05-28 18:46:57 +0200100
101 s->data_state = DATA_ST_INIT;
102 s->data_source = DATA_SRC_NONE;
Willy Tarreaueb472682010-05-28 18:46:57 +0200103
Willy Tarreaueb472682010-05-28 18:46:57 +0200104 s->req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */
105
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200106 if (s->listener->timeout) {
107 s->req->rto = *s->listener->timeout;
108 s->rep->wto = *s->listener->timeout;
Willy Tarreaueb472682010-05-28 18:46:57 +0200109 }
Willy Tarreaueb472682010-05-28 18:46:57 +0200110 return 1;
Willy Tarreaueb472682010-05-28 18:46:57 +0200111}
112
Willy Tarreau07e9e642010-08-17 21:48:17 +0200113/* allocate a new stats frontend named <name>, and return it
114 * (or NULL in case of lack of memory).
115 */
116static struct proxy *alloc_stats_fe(const char *name)
117{
118 struct proxy *fe;
119
120 fe = (struct proxy *)calloc(1, sizeof(struct proxy));
121 if (!fe)
122 return NULL;
123
124 LIST_INIT(&fe->pendconns);
125 LIST_INIT(&fe->acl);
126 LIST_INIT(&fe->block_cond);
127 LIST_INIT(&fe->redirect_rules);
128 LIST_INIT(&fe->mon_fail_cond);
129 LIST_INIT(&fe->switching_rules);
130 LIST_INIT(&fe->tcp_req.inspect_rules);
131
132 /* Timeouts are defined as -1, so we cannot use the zeroed area
133 * as a default value.
134 */
135 proxy_reset_timeouts(fe);
136
137 fe->last_change = now.tv_sec;
138 fe->id = strdup("GLOBAL");
139 fe->cap = PR_CAP_FE;
140 return fe;
141}
142
Willy Tarreaufbee7132007-10-18 13:53:22 +0200143/* This function parses a "stats" statement in the "global" section. It returns
144 * -1 if there is any error, otherwise zero. If it returns -1, it may write an
145 * error message into ther <err> buffer, for at most <errlen> bytes, trailing
146 * zero included. The trailing '\n' must not be written. The function must be
147 * called with <args> pointing to the first word after "stats".
148 */
Willy Tarreau10522fd2008-07-09 20:12:41 +0200149static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
150 struct proxy *defpx, char *err, int errlen)
Willy Tarreaufbee7132007-10-18 13:53:22 +0200151{
Willy Tarreau10522fd2008-07-09 20:12:41 +0200152 args++;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200153 if (!strcmp(args[0], "socket")) {
154 struct sockaddr_un su;
155 int cur_arg;
156
157 if (*args[1] == 0) {
158 snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket");
159 return -1;
160 }
161
162 if (global.stats_sock.state != LI_NEW) {
163 snprintf(err, errlen, "'stats socket' already specified in global section");
164 return -1;
165 }
166
167 su.sun_family = AF_UNIX;
168 strncpy(su.sun_path, args[1], sizeof(su.sun_path));
169 su.sun_path[sizeof(su.sun_path) - 1] = 0;
170 memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit
171
Willy Tarreau89a63132009-08-16 17:41:45 +0200172 if (!global.stats_fe) {
Willy Tarreau07e9e642010-08-17 21:48:17 +0200173 if ((global.stats_fe = alloc_stats_fe("GLOBAL")) == NULL) {
Willy Tarreau89a63132009-08-16 17:41:45 +0200174 snprintf(err, errlen, "out of memory");
175 return -1;
176 }
Willy Tarreau07e9e642010-08-17 21:48:17 +0200177 global.stats_fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
Willy Tarreau89a63132009-08-16 17:41:45 +0200178 }
179
Willy Tarreaufbee7132007-10-18 13:53:22 +0200180 global.stats_sock.state = LI_INIT;
Willy Tarreau6fb42e02007-10-28 17:02:33 +0100181 global.stats_sock.options = LI_O_NONE;
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200182 global.stats_sock.accept = session_accept;
183 global.stats_fe->accept = stats_accept;
Willy Tarreau104eb362009-08-16 18:51:29 +0200184 global.stats_sock.handler = process_session;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200185 global.stats_sock.analysers = 0;
Willy Tarreau2c9f5b12009-08-16 19:12:36 +0200186 global.stats_sock.nice = -64; /* we want to boost priority for local stats */
Willy Tarreaueb472682010-05-28 18:46:57 +0200187 global.stats_sock.frontend = global.stats_fe;
Willy Tarreau6162db22009-10-10 17:13:00 +0200188 global.stats_sock.perm.ux.level = ACCESS_LVL_OPER; /* default access level */
Willy Tarreau07e9e642010-08-17 21:48:17 +0200189 global.stats_fe->maxconn = global.stats_sock.maxconn;
Willy Tarreau89a63132009-08-16 17:41:45 +0200190 global.stats_sock.timeout = &global.stats_fe->timeout.client;
191
192 global.stats_sock.next = global.stats_fe->listen;
193 global.stats_fe->listen = &global.stats_sock;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200194
195 cur_arg = 2;
196 while (*args[cur_arg]) {
197 if (!strcmp(args[cur_arg], "uid")) {
198 global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]);
199 cur_arg += 2;
200 }
201 else if (!strcmp(args[cur_arg], "gid")) {
202 global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]);
203 cur_arg += 2;
204 }
205 else if (!strcmp(args[cur_arg], "mode")) {
206 global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
207 cur_arg += 2;
208 }
209 else if (!strcmp(args[cur_arg], "user")) {
210 struct passwd *user;
211 user = getpwnam(args[cur_arg + 1]);
212 if (!user) {
213 snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')",
214 args[cur_arg + 1]);
215 return -1;
216 }
217 global.stats_sock.perm.ux.uid = user->pw_uid;
218 cur_arg += 2;
219 }
220 else if (!strcmp(args[cur_arg], "group")) {
221 struct group *group;
222 group = getgrnam(args[cur_arg + 1]);
223 if (!group) {
224 snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')",
225 args[cur_arg + 1]);
226 return -1;
227 }
228 global.stats_sock.perm.ux.gid = group->gr_gid;
229 cur_arg += 2;
230 }
Willy Tarreau6162db22009-10-10 17:13:00 +0200231 else if (!strcmp(args[cur_arg], "level")) {
232 if (!strcmp(args[cur_arg+1], "user"))
233 global.stats_sock.perm.ux.level = ACCESS_LVL_USER;
234 else if (!strcmp(args[cur_arg+1], "operator"))
235 global.stats_sock.perm.ux.level = ACCESS_LVL_OPER;
236 else if (!strcmp(args[cur_arg+1], "admin"))
237 global.stats_sock.perm.ux.level = ACCESS_LVL_ADMIN;
238 else {
239 snprintf(err, errlen, "'stats socket level' only supports 'user', 'operator', and 'admin'");
240 return -1;
241 }
242 cur_arg += 2;
243 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200244 else {
Willy Tarreau6162db22009-10-10 17:13:00 +0200245 snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', 'level', and 'mode'");
Willy Tarreaufbee7132007-10-18 13:53:22 +0200246 return -1;
247 }
248 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100249
Willy Tarreaufbee7132007-10-18 13:53:22 +0200250 uxst_add_listener(&global.stats_sock);
251 global.maxsock++;
252 }
253 else if (!strcmp(args[0], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100254 unsigned timeout;
255 const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS);
256
257 if (res) {
258 snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res);
259 return -1;
260 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200261
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100262 if (!timeout) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200263 snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'");
264 return -1;
265 }
Willy Tarreau07e9e642010-08-17 21:48:17 +0200266 if (!global.stats_fe) {
267 if ((global.stats_fe = alloc_stats_fe("GLOBAL")) == NULL) {
268 snprintf(err, errlen, "out of memory");
269 return -1;
270 }
271 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200272 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200273 }
274 else if (!strcmp(args[0], "maxconn")) {
275 int maxconn = atol(args[1]);
276
277 if (maxconn <= 0) {
278 snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'");
279 return -1;
280 }
281 global.maxsock -= global.stats_sock.maxconn;
282 global.stats_sock.maxconn = maxconn;
283 global.maxsock += global.stats_sock.maxconn;
Willy Tarreaueb472682010-05-28 18:46:57 +0200284 if (global.stats_fe)
285 global.stats_fe->maxconn = global.stats_sock.maxconn;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200286 }
287 else {
288 snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section");
289 return -1;
290 }
291 return 0;
292}
293
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200294int print_csv_header(struct chunk *msg)
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100295{
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200296 return chunk_printf(msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100297 "# pxname,svname,"
298 "qcur,qmax,"
299 "scur,smax,slim,stot,"
300 "bin,bout,"
301 "dreq,dresp,"
302 "ereq,econ,eresp,"
303 "wretr,wredis,"
304 "status,weight,act,bck,"
305 "chkfail,chkdown,lastchg,downtime,qlimit,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +0200306 "pid,iid,sid,throttle,lbtot,tracked,type,"
307 "rate,rate_lim,rate_max,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200308 "check_status,check_code,check_duration,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100309 "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,"
Willy Tarreauae526782010-03-04 20:34:23 +0100310 "req_rate,req_rate_max,req_tot,"
311 "cli_abrt,srv_abrt,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100312 "\n");
313}
314
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200315/* Processes the stats interpreter on the statistics socket. This function is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200316 * called from an applet running in a stream interface. The function returns 1
317 * if the request was understood, otherwise zero. It sets si->st0 to a value
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200318 * designating the function which will have to process the request, which can
319 * also be the print function to display the return message set into cli.msg.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200320 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200321int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200322{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200323 struct session *s = si->private;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200324 char *args[MAX_STATS_ARGS + 1];
325 int arg;
326
327 while (isspace((unsigned char)*line))
328 line++;
329
330 arg = 0;
331 args[arg] = line;
332
333 while (*line && arg < MAX_STATS_ARGS) {
334 if (isspace((unsigned char)*line)) {
335 *line++ = '\0';
336
337 while (isspace((unsigned char)*line))
338 line++;
339
340 args[++arg] = line;
341 continue;
342 }
343
344 line++;
345 }
346
347 while (++arg <= MAX_STATS_ARGS)
348 args[arg] = line;
349
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200350 s->data_ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200351 if (strcmp(args[0], "show") == 0) {
352 if (strcmp(args[1], "stat") == 0) {
353 if (*args[2] && *args[3] && *args[4]) {
354 s->data_ctx.stats.flags |= STAT_BOUND;
355 s->data_ctx.stats.iid = atoi(args[2]);
356 s->data_ctx.stats.type = atoi(args[3]);
357 s->data_ctx.stats.sid = atoi(args[4]);
358 }
359
360 s->data_ctx.stats.flags |= STAT_SHOW_STAT;
361 s->data_ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200362 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200363 si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200364 }
365 else if (strcmp(args[1], "info") == 0) {
366 s->data_ctx.stats.flags |= STAT_SHOW_INFO;
367 s->data_ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200368 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200369 si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200370 }
371 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200372 s->data_state = DATA_ST_INIT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200373 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200374 s->data_ctx.cli.msg = stats_permission_denied_msg;
375 si->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200376 return 1;
377 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100378 if (*args[2])
379 s->data_ctx.sess.target = (void *)strtoul(args[2], NULL, 0);
380 else
381 s->data_ctx.sess.target = NULL;
382 s->data_ctx.sess.section = 0; /* start with session status */
383 s->data_ctx.sess.pos = 0;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200384 si->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200385 }
386 else if (strcmp(args[1], "errors") == 0) {
Willy Tarreau6162db22009-10-10 17:13:00 +0200387 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200388 s->data_ctx.cli.msg = stats_permission_denied_msg;
389 si->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200390 return 1;
391 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200392 if (*args[2])
393 s->data_ctx.errors.iid = atoi(args[2]);
394 else
395 s->data_ctx.errors.iid = -1;
396 s->data_ctx.errors.px = NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200397 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200398 si->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200399 }
Willy Tarreau69f58c82010-07-12 17:55:33 +0200400 else if (strcmp(args[1], "table") == 0) {
401 s->data_state = DATA_ST_INIT;
Willy Tarreau603861e2010-07-18 08:31:59 +0200402 if (*args[2]) {
403 s->data_ctx.table.target = find_stktable(args[2]);
404 if (!s->data_ctx.table.target) {
405 s->data_ctx.cli.msg = "No such table\n";
406 si->st0 = STAT_CLI_PRINT;
407 return 1;
408 }
409 }
Willy Tarreau69f58c82010-07-12 17:55:33 +0200410 else
411 s->data_ctx.table.target = NULL;
Willy Tarreau4f3f01f2010-07-18 11:46:20 +0200412
413 s->data_ctx.table.data_type = -1;
414 if (s->data_ctx.table.target && strncmp(args[3], "data.", 5) == 0) {
415 /* condition on stored data value */
416 s->data_ctx.table.data_type = stktable_get_data_type(args[3] + 5);
417 if (s->data_ctx.table.data_type < 0) {
418 s->data_ctx.cli.msg = "Unknown data type\n";
419 si->st0 = STAT_CLI_PRINT;
420 return 1;
421 }
422
423 if (!((struct proxy *)s->data_ctx.table.target)->table.data_ofs[s->data_ctx.table.data_type]) {
424 s->data_ctx.cli.msg = "Data type not stored in this table\n";
425 si->st0 = STAT_CLI_PRINT;
426 return 1;
427 }
428
429 s->data_ctx.table.data_op = get_std_op(args[4]);
430 if (s->data_ctx.table.data_op < 0) {
431 s->data_ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n";
432 si->st0 = STAT_CLI_PRINT;
433 return 1;
434 }
435
436 if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &s->data_ctx.table.value) != 0) {
437 s->data_ctx.cli.msg = "Require a valid integer value to compare against\n";
438 si->st0 = STAT_CLI_PRINT;
439 return 1;
440 }
441 }
442 else if (*args[3]) {
443 s->data_ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value>\n";
444 si->st0 = STAT_CLI_PRINT;
445 return 1;
446 }
447
Willy Tarreau69f58c82010-07-12 17:55:33 +0200448 s->data_ctx.table.proxy = NULL;
449 s->data_ctx.table.entry = NULL;
450 si->st0 = STAT_CLI_O_TAB; // stats_dump_table_to_buffer
451 }
Willy Tarreau88ee3972010-07-13 13:48:00 +0200452 else { /* neither "stat" nor "info" nor "sess" nor "errors" no "table" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200453 return 0;
454 }
455 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200456 else if (strcmp(args[0], "clear") == 0) {
457 if (strcmp(args[1], "counters") == 0) {
458 struct proxy *px;
459 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200460 struct listener *li;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200461 int clrall = 0;
462
463 if (strcmp(args[2], "all") == 0)
464 clrall = 1;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200465
Willy Tarreau6162db22009-10-10 17:13:00 +0200466 /* check permissions */
467 if (s->listener->perm.ux.level < ACCESS_LVL_OPER ||
468 (clrall && s->listener->perm.ux.level < ACCESS_LVL_ADMIN)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200469 s->data_ctx.cli.msg = stats_permission_denied_msg;
470 si->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200471 return 1;
472 }
473
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200474 for (px = proxy; px; px = px->next) {
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200475 if (clrall)
476 memset(&px->counters, 0, sizeof(px->counters));
477 else {
478 px->counters.feconn_max = 0;
479 px->counters.beconn_max = 0;
Willy Tarreaud9b587f2010-02-26 10:05:55 +0100480 px->counters.fe_rps_max = 0;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200481 px->counters.fe_sps_max = 0;
Willy Tarreaub36b4242010-06-04 20:59:39 +0200482 px->counters.fe_cps_max = 0;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200483 px->counters.be_sps_max = 0;
484 px->counters.nbpend_max = 0;
485 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200486
487 for (sv = px->srv; sv; sv = sv->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200488 if (clrall)
489 memset(&sv->counters, 0, sizeof(sv->counters));
490 else {
491 sv->counters.cur_sess_max = 0;
492 sv->counters.nbpend_max = 0;
493 sv->counters.sps_max = 0;
494 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200495
496 for (li = px->listen; li; li = li->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200497 if (li->counters) {
498 if (clrall)
499 memset(li->counters, 0, sizeof(*li->counters));
500 else
501 li->counters->conn_max = 0;
502 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200503 }
504
505 return 1;
506 }
Willy Tarreau88ee3972010-07-13 13:48:00 +0200507 else if (strcmp(args[1], "table") == 0) {
508 struct proxy *px;
509 struct stksess *ts;
510 unsigned int ip_key;
511
512 if (!*args[2]) {
Willy Tarreau603861e2010-07-18 08:31:59 +0200513 s->data_ctx.cli.msg = "\"table\" argument expected\n";
Willy Tarreau88ee3972010-07-13 13:48:00 +0200514 si->st0 = STAT_CLI_PRINT;
515 return 1;
516 }
517
518 px = find_stktable(args[2]);
519
520 if (!px) {
Willy Tarreau603861e2010-07-18 08:31:59 +0200521 s->data_ctx.cli.msg = "No such table\n";
Willy Tarreau88ee3972010-07-13 13:48:00 +0200522 si->st0 = STAT_CLI_PRINT;
523 return 1;
524 }
525
526 if (strcmp(args[3], "key") != 0) {
Willy Tarreau603861e2010-07-18 08:31:59 +0200527 s->data_ctx.cli.msg = "\"key\" argument expected\n";
Willy Tarreau88ee3972010-07-13 13:48:00 +0200528 si->st0 = STAT_CLI_PRINT;
529 return 1;
530 }
531
532 if (!*args[4]) {
Willy Tarreau603861e2010-07-18 08:31:59 +0200533 s->data_ctx.cli.msg = "Key value expected\n";
Willy Tarreau88ee3972010-07-13 13:48:00 +0200534 si->st0 = STAT_CLI_PRINT;
535 return 1;
536 }
537
538 if (px->table.type == STKTABLE_TYPE_IP) {
539 ip_key = htonl(inetaddr_host(args[4]));
540 static_table_key.key = (void *)&ip_key;
541 }
542 else {
Willy Tarreau603861e2010-07-18 08:31:59 +0200543 s->data_ctx.cli.msg = "Removing keys from non-ip tables is not supported\n";
Willy Tarreau88ee3972010-07-13 13:48:00 +0200544 si->st0 = STAT_CLI_PRINT;
545 return 1;
546 }
547
548 /* check permissions */
549 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
550 s->data_ctx.cli.msg = stats_permission_denied_msg;
551 si->st0 = STAT_CLI_PRINT;
552 return 1;
553 }
554
555 ts = stktable_lookup_key(&px->table, &static_table_key);
556 if (!ts) {
557 /* silent return, entry was already removed */
558 return 1;
559 }
560 else if (ts->ref_cnt) {
561 /* don't delete an entry which is currently referenced */
Willy Tarreau603861e2010-07-18 08:31:59 +0200562 s->data_ctx.cli.msg = "Entry currently in use, cannot remove\n";
Willy Tarreau88ee3972010-07-13 13:48:00 +0200563 si->st0 = STAT_CLI_PRINT;
564 return 1;
565 }
566
Willy Tarreaudf39e952010-08-10 11:11:40 +0200567 stksess_kill(&px->table, ts);
Willy Tarreau88ee3972010-07-13 13:48:00 +0200568 /* end of processing */
569 return 1;
570 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200571 else {
Willy Tarreau88ee3972010-07-13 13:48:00 +0200572 /* unknown "clear" argument */
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200573 return 0;
574 }
575 }
Willy Tarreau38338fa2009-10-10 18:37:29 +0200576 else if (strcmp(args[0], "get") == 0) {
577 if (strcmp(args[1], "weight") == 0) {
578 struct proxy *px;
579 struct server *sv;
580
581 /* split "backend/server" and make <line> point to server */
582 for (line = args[2]; *line; line++)
583 if (*line == '/') {
584 *line++ = '\0';
585 break;
586 }
587
588 if (!*line) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200589 s->data_ctx.cli.msg = "Require 'backend/server'.\n";
590 si->st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +0200591 return 1;
592 }
593
594 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200595 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
596 si->st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +0200597 return 1;
598 }
599
600 /* return server's effective weight at the moment */
601 snprintf(trash, sizeof(trash), "%d (initial %d)\n", sv->uweight, sv->iweight);
602 buffer_feed(si->ib, trash);
603 return 1;
604 }
605 else { /* not "get weight" */
606 return 0;
607 }
608 }
Willy Tarreau4483d432009-10-10 19:30:08 +0200609 else if (strcmp(args[0], "set") == 0) {
610 if (strcmp(args[1], "weight") == 0) {
611 struct proxy *px;
612 struct server *sv;
613 int w;
614
615 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200616 s->data_ctx.cli.msg = stats_permission_denied_msg;
617 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200618 return 1;
619 }
620
621 /* split "backend/server" and make <line> point to server */
622 for (line = args[2]; *line; line++)
623 if (*line == '/') {
624 *line++ = '\0';
625 break;
626 }
627
628 if (!*line || !*args[3]) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200629 s->data_ctx.cli.msg = "Require 'backend/server' and 'weight' or 'weight%'.\n";
630 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200631 return 1;
632 }
633
634 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200635 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
636 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200637 return 1;
638 }
639
640 /* if the weight is terminated with '%', it is set relative to
641 * the initial weight, otherwise it is absolute.
642 */
643 w = atoi(args[3]);
644 if (strchr(args[3], '%') != NULL) {
645 if (w < 0 || w > 100) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200646 s->data_ctx.cli.msg = "Relative weight can only be set between 0 and 100% inclusive.\n";
647 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200648 return 1;
649 }
650 w = sv->iweight * w / 100;
651 }
652 else {
653 if (w < 0 || w > 256) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200654 s->data_ctx.cli.msg = "Absolute weight can only be between 0 and 256 inclusive.\n";
655 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200656 return 1;
657 }
658 }
659
660 if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200661 s->data_ctx.cli.msg = "Backend is using a static LB algorithm and only accepts weights '0%' and '100%'.\n";
662 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200663 return 1;
664 }
665
666 sv->uweight = w;
667
668 if (px->lbprm.algo & BE_LB_PROP_DYN) {
669 /* we must take care of not pushing the server to full throttle during slow starts */
670 if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN))
671 sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart;
672 else
673 sv->eweight = BE_WEIGHT_SCALE;
674 sv->eweight *= sv->uweight;
675 } else {
676 sv->eweight = sv->uweight;
677 }
678
679 /* static LB algorithms are a bit harder to update */
680 if (px->lbprm.update_server_eweight)
681 px->lbprm.update_server_eweight(sv);
682 else if (sv->eweight)
683 px->lbprm.set_server_status_up(sv);
684 else
685 px->lbprm.set_server_status_down(sv);
686
687 return 1;
688 }
Willy Tarreau7aabd112010-01-26 10:59:06 +0100689 else if (strcmp(args[1], "timeout") == 0) {
690 if (strcmp(args[2], "cli") == 0) {
691 unsigned timeout;
692 const char *res;
693
694 if (!*args[3]) {
695 s->data_ctx.cli.msg = "Expects an integer value.\n";
696 si->st0 = STAT_CLI_PRINT;
697 return 1;
698 }
699
700 res = parse_time_err(args[3], &timeout, TIME_UNIT_S);
701 if (res || timeout < 1) {
702 s->data_ctx.cli.msg = "Invalid timeout value.\n";
703 si->st0 = STAT_CLI_PRINT;
704 return 1;
705 }
706
707 s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000);
708 return 1;
709 }
710 else {
711 s->data_ctx.cli.msg = "'set timeout' only supports 'cli'.\n";
712 si->st0 = STAT_CLI_PRINT;
713 return 1;
714 }
715 }
716 else { /* unknown "set" parameter */
Willy Tarreau4483d432009-10-10 19:30:08 +0200717 return 0;
718 }
719 }
Cyril Bontécd19e512010-01-31 22:34:03 +0100720 else if (strcmp(args[0], "enable") == 0) {
721 if (strcmp(args[1], "server") == 0) {
722 struct proxy *px;
723 struct server *sv;
724
725 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
726 s->data_ctx.cli.msg = stats_permission_denied_msg;
727 si->st0 = STAT_CLI_PRINT;
728 return 1;
729 }
730
731 /* split "backend/server" and make <line> point to server */
732 for (line = args[2]; *line; line++)
733 if (*line == '/') {
734 *line++ = '\0';
735 break;
736 }
737
738 if (!*line || !*args[2]) {
739 s->data_ctx.cli.msg = "Require 'backend/server'.\n";
740 si->st0 = STAT_CLI_PRINT;
741 return 1;
742 }
743
744 if (!get_backend_server(args[2], line, &px, &sv)) {
745 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
746 si->st0 = STAT_CLI_PRINT;
747 return 1;
748 }
749
750 if (sv->state & SRV_MAINTAIN) {
751 /* The server is really in maintenance, we can change the server state */
752 if (sv->tracked) {
753 /* If this server tracks the status of another one,
754 * we must restore the good status.
755 */
756 if (sv->tracked->state & SRV_RUNNING) {
757 set_server_up(sv);
Willy Tarreau70461302010-10-22 14:39:02 +0200758 sv->health = sv->rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +0100759 } else {
760 sv->state &= ~SRV_MAINTAIN;
761 set_server_down(sv);
762 }
763 } else {
764 set_server_up(sv);
Willy Tarreau70461302010-10-22 14:39:02 +0200765 sv->health = sv->rise; /* up, but will fall down at first failure */
Cyril Bontécd19e512010-01-31 22:34:03 +0100766 }
767 }
768
769 return 1;
770 }
771 else { /* unknown "enable" parameter */
772 return 0;
773 }
774 }
775 else if (strcmp(args[0], "disable") == 0) {
776 if (strcmp(args[1], "server") == 0) {
777 struct proxy *px;
778 struct server *sv;
779
780 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
781 s->data_ctx.cli.msg = stats_permission_denied_msg;
782 si->st0 = STAT_CLI_PRINT;
783 return 1;
784 }
785
786 /* split "backend/server" and make <line> point to server */
787 for (line = args[2]; *line; line++)
788 if (*line == '/') {
789 *line++ = '\0';
790 break;
791 }
792
793 if (!*line || !*args[2]) {
794 s->data_ctx.cli.msg = "Require 'backend/server'.\n";
795 si->st0 = STAT_CLI_PRINT;
796 return 1;
797 }
798
799 if (!get_backend_server(args[2], line, &px, &sv)) {
800 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
801 si->st0 = STAT_CLI_PRINT;
802 return 1;
803 }
804
805 if (! (sv->state & SRV_MAINTAIN)) {
806 /* Not already in maintenance, we can change the server state */
807 sv->state |= SRV_MAINTAIN;
808 set_server_down(sv);
809 }
810
811 return 1;
812 }
813 else { /* unknown "disable" parameter */
814 return 0;
815 }
816 }
817 else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200818 return 0;
819 }
820 return 1;
821}
822
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200823/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200824 * used to processes I/O from/to the stats unix socket. The system relies on a
825 * state machine handling requests and various responses. We read a request,
826 * then we process it and send the response, and we possibly display a prompt.
827 * Then we can read again. The state is stored in si->st0 and is one of the
828 * STAT_CLI_* constants. si->st1 is used to indicate whether prompt is enabled
829 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200830 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200831void stats_io_handler(struct stream_interface *si)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200832{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200833 struct session *s = si->private;
834 struct buffer *req = si->ob;
835 struct buffer *res = si->ib;
836 int reql;
837 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200838
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200839 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
840 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200841
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200842 while (1) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200843 if (si->st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200844 /* Stats output not initialized yet */
845 memset(&s->data_ctx.stats, 0, sizeof(s->data_ctx.stats));
846 s->data_source = DATA_SRC_STATS;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200847 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200848 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200849 else if (si->st0 == STAT_CLI_END) {
850 /* Let's close for real now. We just close the request
851 * side, the conditions below will complete if needed.
852 */
853 si->shutw(si);
854 break;
855 }
856 else if (si->st0 == STAT_CLI_GETREQ) {
Willy Tarreau4e33d862009-10-11 23:35:10 +0200857 /* ensure we have some output room left in the event we
858 * would want to return some info right after parsing.
859 */
860 if (buffer_almost_full(si->ib))
861 break;
862
Willy Tarreau74b08c92010-09-08 17:04:31 +0200863 reql = buffer_get_line(si->ob, trash, sizeof(trash));
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200864 if (reql <= 0) { /* closed or EOL not found */
865 if (reql == 0)
866 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200867 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200868 continue;
869 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200870
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200871 /* seek for a possible semi-colon. If we find one, we
872 * replace it with an LF and skip only this part.
873 */
874 for (len = 0; len < reql; len++)
875 if (trash[len] == ';') {
876 trash[len] = '\n';
877 reql = len + 1;
878 break;
879 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200880
Willy Tarreau816fc222009-10-04 07:36:58 +0200881 /* now it is time to check that we have a full line,
882 * remove the trailing \n and possibly \r, then cut the
883 * line.
884 */
885 len = reql - 1;
886 if (trash[len] != '\n') {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200887 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200888 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200889 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200890
Willy Tarreau816fc222009-10-04 07:36:58 +0200891 if (len && trash[len-1] == '\r')
892 len--;
893
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200894 trash[len] = '\0';
895
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200896 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200897 if (len) {
898 if (strcmp(trash, "quit") == 0) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200899 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200900 continue;
901 }
902 else if (strcmp(trash, "prompt") == 0)
903 si->st1 = !si->st1;
904 else if (strcmp(trash, "help") == 0 ||
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200905 !stats_sock_parse_request(si, trash)) {
906 s->data_ctx.cli.msg = stats_sock_usage_msg;
907 si->st0 = STAT_CLI_PRINT;
908 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200909 /* NB: stats_sock_parse_request() may have put
910 * another STAT_CLI_O_* into si->st0.
911 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200912 }
913 else if (!si->st1) {
914 /* if prompt is disabled, print help on empty lines,
915 * so that the user at least knows how to enable
916 * prompt and find help.
917 */
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200918 s->data_ctx.cli.msg = stats_sock_usage_msg;
919 si->st0 = STAT_CLI_PRINT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200920 }
921
922 /* re-adjust req buffer */
923 buffer_skip(si->ob, reql);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200924 req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200925 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200926 else { /* output functions: first check if the output buffer is closed then abort */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200927 if (res->flags & (BF_SHUTR_NOW|BF_SHUTR)) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200928 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200929 continue;
930 }
931
932 switch (si->st0) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200933 case STAT_CLI_PRINT:
934 if (buffer_feed(si->ib, s->data_ctx.cli.msg) < 0)
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200935 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200936 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200937 case STAT_CLI_O_INFO:
Willy Tarreau24955a12009-10-04 11:54:04 +0200938 if (stats_dump_raw_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200939 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200940 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200941 case STAT_CLI_O_SESS:
Willy Tarreau7e72a8f2009-10-03 23:55:14 +0200942 if (stats_dump_sess_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200943 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200944 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200945 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau61b34732009-10-03 23:49:35 +0200946 if (stats_dump_errors_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200947 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200948 break;
Willy Tarreau69f58c82010-07-12 17:55:33 +0200949 case STAT_CLI_O_TAB:
950 if (stats_dump_table_to_buffer(s, res))
951 si->st0 = STAT_CLI_PROMPT;
952 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200953 default: /* abnormal state */
954 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200955 break;
956 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200957
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200958 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
959 if (si->st0 == STAT_CLI_PROMPT) {
Willy Tarreau9bcc91e2009-10-10 18:01:44 +0200960 if (buffer_feed(si->ib, si->st1 ? "\n> " : "\n") < 0)
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200961 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200962 }
963
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200964 /* If the output functions are still there, it means they require more room. */
Willy Tarreau96fd4b52009-10-04 17:18:35 +0200965 if (si->st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200966 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200967
968 /* Now we close the output if one of the writers did so,
969 * or if we're not in interactive mode and the request
970 * buffer is empty. This still allows pipelined requests
971 * to be sent in non-interactive mode.
972 */
973 if ((res->flags & (BF_SHUTW|BF_SHUTW_NOW)) || (!si->st1 && !req->send_max)) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200974 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200975 continue;
976 }
977
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200978 /* switch state back to GETREQ to read next requests */
979 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200980 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200981 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200982
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200983 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST) && (si->st0 != STAT_CLI_GETREQ)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200984 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
985 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
986 /* Other size has closed, let's abort if we have no more processing to do
987 * and nothing more to consume. This is comparable to a broken pipe, so
988 * we forward the close to the request side so that it flows upstream to
989 * the client.
990 */
991 si->shutw(si);
992 }
993
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200994 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && (si->st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200995 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
996 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
997 /* We have no more processing to do, and nothing more to send, and
998 * the client side has closed. So we'll forward this state downstream
999 * on the response buffer.
1000 */
1001 si->shutr(si);
1002 res->flags |= BF_READ_NULL;
1003 }
1004
1005 /* update all other flags and resync with the other side */
1006 si->update(si);
1007
1008 /* we don't want to expire timeouts while we're processing requests */
1009 si->ib->rex = TICK_ETERNITY;
1010 si->ob->wex = TICK_ETERNITY;
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001011
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02001012 out:
1013 DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rql=%d, rqs=%d, rl=%d, rs=%d\n",
1014 __FUNCTION__, __LINE__,
1015 si->state, req->flags, res->flags, req->l, req->send_max, res->l, res->send_max);
1016
1017 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1018 /* check that we have released everything then unregister */
1019 stream_int_unregister_handler(si);
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001020 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +02001021}
1022
Willy Tarreau24955a12009-10-04 11:54:04 +02001023/* This function is called to send output to the response buffer.
1024 * It dumps statistics onto the output buffer <rep> owned by session <s>.
1025 * s->data_ctx must have been zeroed first, and the flags properly set.
1026 * It returns 0 as long as it does not complete, non-zero upon completion.
1027 * Some states are not used but it makes the code more similar to other
1028 * functions which handle stats too.
Willy Tarreau3e76e722007-10-17 18:57:38 +02001029 */
Willy Tarreau24955a12009-10-04 11:54:04 +02001030int stats_dump_raw_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau3e76e722007-10-17 18:57:38 +02001031{
Willy Tarreau3e76e722007-10-17 18:57:38 +02001032 struct proxy *px;
1033 struct chunk msg;
Willy Tarreaua8efd362008-01-03 10:19:15 +01001034 unsigned int up;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001035
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001036 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3e76e722007-10-17 18:57:38 +02001037
1038 switch (s->data_state) {
1039 case DATA_ST_INIT:
Willy Tarreau24955a12009-10-04 11:54:04 +02001040 /* the function had not been called yet */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001041 s->data_state = DATA_ST_HEAD;
1042 /* fall through */
1043
1044 case DATA_ST_HEAD:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001045 if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001046 print_csv_header(&msg);
Willy Tarreau24955a12009-10-04 11:54:04 +02001047 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001048 return 0;
1049 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001050
1051 s->data_state = DATA_ST_INFO;
1052 /* fall through */
1053
1054 case DATA_ST_INFO:
Willy Tarreaua8efd362008-01-03 10:19:15 +01001055 up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001056 if (s->data_ctx.stats.flags & STAT_SHOW_INFO) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001057 chunk_printf(&msg,
Willy Tarreaua8efd362008-01-03 10:19:15 +01001058 "Name: " PRODUCT_NAME "\n"
1059 "Version: " HAPROXY_VERSION "\n"
1060 "Release_date: " HAPROXY_DATE "\n"
1061 "Nbproc: %d\n"
1062 "Process_num: %d\n"
1063 "Pid: %d\n"
1064 "Uptime: %dd %dh%02dm%02ds\n"
1065 "Uptime_sec: %d\n"
1066 "Memmax_MB: %d\n"
1067 "Ulimit-n: %d\n"
1068 "Maxsock: %d\n"
1069 "Maxconn: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +01001070 "Maxpipes: %d\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001071 "CurrConns: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +01001072 "PipesUsed: %d\n"
1073 "PipesFree: %d\n"
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001074 "Tasks: %d\n"
1075 "Run_queue: %d\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001076 "node: %s\n"
1077 "description: %s\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001078 "",
1079 global.nbproc,
1080 relative_pid,
1081 pid,
1082 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
1083 up,
1084 global.rlimit_memmax,
1085 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +01001086 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001087 actconn, pipes_used, pipes_free,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001088 nb_tasks_cur, run_queue_cur,
1089 global.node, global.desc?global.desc:""
Willy Tarreaua8efd362008-01-03 10:19:15 +01001090 );
Willy Tarreau24955a12009-10-04 11:54:04 +02001091 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001092 return 0;
1093 }
1094
Willy Tarreau3e76e722007-10-17 18:57:38 +02001095 s->data_ctx.stats.px = proxy;
1096 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001097
1098 s->data_ctx.stats.sv = NULL;
1099 s->data_ctx.stats.sv_st = 0;
1100
Willy Tarreau3e76e722007-10-17 18:57:38 +02001101 s->data_state = DATA_ST_LIST;
1102 /* fall through */
1103
1104 case DATA_ST_LIST:
1105 /* dump proxies */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001106 if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
Willy Tarreaua8efd362008-01-03 10:19:15 +01001107 while (s->data_ctx.stats.px) {
1108 px = s->data_ctx.stats.px;
1109 /* skip the disabled proxies and non-networked ones */
1110 if (px->state != PR_STSTOPPED &&
Willy Tarreau24955a12009-10-04 11:54:04 +02001111 (px->cap & (PR_CAP_FE | PR_CAP_BE))) {
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001112 if (stats_dump_proxy(s, px, NULL) == 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +01001113 return 0;
Willy Tarreau24955a12009-10-04 11:54:04 +02001114 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001115
Willy Tarreaua8efd362008-01-03 10:19:15 +01001116 s->data_ctx.stats.px = px->next;
1117 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
1118 }
1119 /* here, we just have reached the last proxy */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001120 }
Willy Tarreau3e76e722007-10-17 18:57:38 +02001121
1122 s->data_state = DATA_ST_END;
1123 /* fall through */
1124
1125 case DATA_ST_END:
1126 s->data_state = DATA_ST_FIN;
Willy Tarreau0a464892008-12-07 18:30:00 +01001127 /* fall through */
Willy Tarreau3e76e722007-10-17 18:57:38 +02001128
1129 case DATA_ST_FIN:
1130 return 1;
1131
1132 default:
1133 /* unknown state ! */
Willy Tarreau24955a12009-10-04 11:54:04 +02001134 s->data_state = DATA_ST_FIN;
1135 return 1;
Willy Tarreau3e76e722007-10-17 18:57:38 +02001136 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001137}
1138
1139
Cyril Bonté70be45d2010-10-12 00:14:35 +02001140/* We don't want to land on the posted stats page because a refresh will
1141 * repost the data. We don't want this to happen on accident so we redirect
1142 * the browse to the stats page with a GET.
1143 */
1144int stats_http_redir(struct session *s, struct buffer *rep, struct uri_auth *uri)
1145{
1146 struct chunk msg;
1147
1148 chunk_init(&msg, trash, sizeof(trash));
1149
1150 switch (s->data_state) {
1151 case DATA_ST_INIT:
1152 chunk_printf(&msg,
1153 "HTTP/1.0 303 See Other\r\n"
1154 "Cache-Control: no-cache\r\n"
1155 "Content-Type: text/plain\r\n"
1156 "Connection: close\r\n"
1157 "Location: %s;st=%s",
1158 uri->uri_prefix, s->data_ctx.stats.st_code);
1159 chunk_printf(&msg, "\r\n\r\n");
1160
1161 if (buffer_feed_chunk(rep, &msg) >= 0)
1162 return 0;
1163
1164 s->txn.status = 303;
1165
1166 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1167 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1168 if (!(s->flags & SN_FINST_MASK))
1169 s->flags |= SN_FINST_R;
1170
1171 s->data_state = DATA_ST_FIN;
1172 return 1;
1173 }
1174 return 1;
1175}
1176
1177
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001178/* This I/O handler runs as an applet embedded in a stream interface. It is
1179 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
1180 * si->st0 becomes non-zero once the transfer is finished. The handler
1181 * automatically unregisters itself once transfer is complete.
1182 */
1183void http_stats_io_handler(struct stream_interface *si)
1184{
1185 struct session *s = si->private;
1186 struct buffer *req = si->ob;
1187 struct buffer *res = si->ib;
1188
1189 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
1190 goto out;
1191
1192 /* check that the output is not closed */
1193 if (res->flags & (BF_SHUTW|BF_SHUTW_NOW))
1194 si->st0 = 1;
1195
1196 if (!si->st0) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02001197 if (s->txn.meth == HTTP_METH_POST) {
1198 if (stats_http_redir(s, res, s->be->uri_auth)) {
1199 si->st0 = 1;
1200 si->shutw(si);
1201 }
1202 } else {
1203 if (stats_dump_http(s, res, s->be->uri_auth)) {
1204 si->st0 = 1;
1205 si->shutw(si);
1206 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001207 }
1208 }
1209
1210 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST))
1211 si->shutw(si);
1212
1213 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && si->st0) {
1214 si->shutr(si);
1215 res->flags |= BF_READ_NULL;
1216 }
1217
1218 /* update all other flags and resync with the other side */
1219 si->update(si);
1220
1221 /* we don't want to expire timeouts while we're processing requests */
1222 si->ib->rex = TICK_ETERNITY;
1223 si->ob->wex = TICK_ETERNITY;
1224
1225 out:
1226 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1227 /* check that we have released everything then unregister */
1228 stream_int_unregister_handler(si);
1229 }
1230}
1231
1232
Willy Tarreau3e76e722007-10-17 18:57:38 +02001233/*
1234 * Produces statistics data for the session <s>. Expects to be called with
Willy Tarreau1ae3a052008-08-16 10:56:30 +02001235 * client socket shut down on input. It stops by itself by unsetting the
Willy Tarreau72b179a2008-08-28 16:01:32 +02001236 * BF_HIJACK flag from the buffer, which it uses to keep on being called
Willy Tarreau1ae3a052008-08-16 10:56:30 +02001237 * when there is free space in the buffer, of simply by letting an empty buffer
1238 * upon return.s->data_ctx must have been zeroed before the first call, and the
1239 * flags set. It returns 0 if it had to stop writing data and an I/O is needed,
1240 * 1 if the dump is finished and the session must be closed, or -1 in case of
1241 * any error.
Willy Tarreau91861262007-10-17 17:06:05 +02001242 */
Willy Tarreau0a464892008-12-07 18:30:00 +01001243int stats_dump_http(struct session *s, struct buffer *rep, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001244{
Willy Tarreau91861262007-10-17 17:06:05 +02001245 struct proxy *px;
1246 struct chunk msg;
1247 unsigned int up;
1248
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001249 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +02001250
1251 switch (s->data_state) {
1252 case DATA_ST_INIT:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001253 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001254 "HTTP/1.0 200 OK\r\n"
1255 "Cache-Control: no-cache\r\n"
1256 "Connection: close\r\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001257 "Content-Type: %s\r\n",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001258 (s->data_ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html");
Willy Tarreau91861262007-10-17 17:06:05 +02001259
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001260 if (uri->refresh > 0 && !(s->data_ctx.stats.flags & STAT_NO_REFRESH))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001261 chunk_printf(&msg, "Refresh: %d\r\n",
Willy Tarreau91861262007-10-17 17:06:05 +02001262 uri->refresh);
1263
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001264 chunk_printf(&msg, "\r\n");
Willy Tarreau91861262007-10-17 17:06:05 +02001265
1266 s->txn.status = 200;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001267 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau56a560a2009-09-22 19:27:35 +02001268 return 0;
1269
Willy Tarreau91861262007-10-17 17:06:05 +02001270 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1271 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1272 if (!(s->flags & SN_FINST_MASK))
1273 s->flags |= SN_FINST_R;
1274
1275 if (s->txn.meth == HTTP_METH_HEAD) {
1276 /* that's all we return in case of HEAD request */
1277 s->data_state = DATA_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001278 return 1;
1279 }
1280
1281 s->data_state = DATA_ST_HEAD; /* let's start producing data */
1282 /* fall through */
1283
1284 case DATA_ST_HEAD:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001285 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001286 /* WARNING! This must fit in the first buffer !!! */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001287 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001288 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
1289 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001290 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001291 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
1292 "<style type=\"text/css\"><!--\n"
1293 "body {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001294 " font-family: arial, helvetica, sans-serif;"
Willy Tarreau91861262007-10-17 17:06:05 +02001295 " font-size: 12px;"
1296 " font-weight: normal;"
1297 " color: black;"
1298 " background: white;"
1299 "}\n"
1300 "th,td {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001301 " font-size: 10px;"
Willy Tarreau91861262007-10-17 17:06:05 +02001302 "}\n"
1303 "h1 {"
Willy Tarreauda6721b2009-07-15 10:07:05 +02001304 " font-size: x-large;"
Willy Tarreau91861262007-10-17 17:06:05 +02001305 " margin-bottom: 0.5em;"
1306 "}\n"
1307 "h2 {"
1308 " font-family: helvetica, arial;"
1309 " font-size: x-large;"
1310 " font-weight: bold;"
1311 " font-style: italic;"
1312 " color: #6020a0;"
1313 " margin-top: 0em;"
1314 " margin-bottom: 0em;"
1315 "}\n"
1316 "h3 {"
1317 " font-family: helvetica, arial;"
1318 " font-size: 16px;"
1319 " font-weight: bold;"
1320 " color: #b00040;"
1321 " background: #e8e8d0;"
1322 " margin-top: 0em;"
1323 " margin-bottom: 0em;"
1324 "}\n"
1325 "li {"
1326 " margin-top: 0.25em;"
1327 " margin-right: 2em;"
1328 "}\n"
1329 ".hr {margin-top: 0.25em;"
1330 " border-color: black;"
1331 " border-bottom-style: solid;"
1332 "}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001333 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001334 ".total {background: #20D0D0;color: #ffff80;}\n"
1335 ".frontend {background: #e8e8d0;}\n"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001336 ".socket {background: #d0d0d0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001337 ".backend {background: #e8e8d0;}\n"
1338 ".active0 {background: #ff9090;}\n"
1339 ".active1 {background: #ffd020;}\n"
1340 ".active2 {background: #ffffa0;}\n"
1341 ".active3 {background: #c0ffc0;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001342 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
1343 ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
1344 ".active6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001345 ".backup0 {background: #ff9090;}\n"
1346 ".backup1 {background: #ff80ff;}\n"
1347 ".backup2 {background: #c060ff;}\n"
1348 ".backup3 {background: #b0d0ff;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001349 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
1350 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
1351 ".backup6 {background: #e0e0e0;}\n"
Cyril Bontécd19e512010-01-31 22:34:03 +01001352 ".maintain {background: #c07820;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +02001353 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001354 "\n"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001355 "a.px:link {color: #ffff40; text-decoration: none;}"
1356 "a.px:visited {color: #ffff40; text-decoration: none;}"
1357 "a.px:hover {color: #ffffff; text-decoration: none;}"
1358 "a.lfsb:link {color: #000000; text-decoration: none;}"
1359 "a.lfsb:visited {color: #000000; text-decoration: none;}"
1360 "a.lfsb:hover {color: #505050; text-decoration: none;}"
1361 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001362 "table.tbl { border-collapse: collapse; border-style: none;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001363 "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"
1364 "table.tbl td.ac { text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001365 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001366 "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 +02001367 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001368 "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 +02001369 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001370 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
1371 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
1372 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
Willy Tarreaue0454092010-02-26 12:29:07 +01001373 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001374 "-->\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001375 "</style></head>\n",
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001376 (uri->flags&ST_SHNODE) ? " on " : "",
1377 (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001378 );
Willy Tarreau55bb8452007-10-17 18:44:57 +02001379 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001380 print_csv_header(&msg);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001381 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001382 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001383 return 0;
1384
1385 s->data_state = DATA_ST_INFO;
1386 /* fall through */
1387
1388 case DATA_ST_INFO:
1389 up = (now.tv_sec - start_date.tv_sec);
1390
1391 /* WARNING! this has to fit the first packet too.
1392 * We are around 3.5 kB, add adding entries will
1393 * become tricky if we want to support 4kB buffers !
1394 */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001395 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001396 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001397 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
1398 PRODUCT_NAME "%s</a></h1>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001399 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001400 "<hr width=\"100%%\" class=\"hr\">\n"
1401 "<h3>&gt; General process information</h3>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001402 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001403 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001404 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001405 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
1406 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
1407 "current conns = %d; current pipes = %d/%d<br>\n"
1408 "Running tasks: %d/%d<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001409 "</td><td align=\"center\" nowrap>\n"
1410 "<table class=\"lgd\"><tr>\n"
1411 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
1412 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
1413 "</tr><tr>\n"
1414 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
1415 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
1416 "</tr><tr>\n"
1417 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
1418 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
1419 "</tr><tr>\n"
1420 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001421 "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
Cyril Bontécd19e512010-01-31 22:34:03 +01001422 "</tr><tr>\n"
1423 "<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 +02001424 "</tr></table>\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001425 "Note: UP with load-balancing disabled is reported as \"NOLB\"."
Willy Tarreau91861262007-10-17 17:06:05 +02001426 "</td>"
1427 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
1428 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
1429 "",
1430 (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001431 pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
1432 (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
1433 pid, relative_pid, global.nbproc,
Willy Tarreau91861262007-10-17 17:06:05 +02001434 up / 86400, (up % 86400) / 3600,
1435 (up % 3600) / 60, (up % 60),
1436 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
1437 global.rlimit_memmax ? " MB" : "",
1438 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +01001439 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001440 actconn, pipes_used, pipes_used+pipes_free,
1441 run_queue_cur, nb_tasks_cur
Willy Tarreau91861262007-10-17 17:06:05 +02001442 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001443
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001444 if (s->data_ctx.stats.flags & STAT_HIDE_DOWN)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001445 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001446 "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
1447 uri->uri_prefix,
1448 "",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001449 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001450 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001451 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001452 "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
1453 uri->uri_prefix,
1454 ";up",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001455 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02001456
Willy Tarreau55bb8452007-10-17 18:44:57 +02001457 if (uri->refresh > 0) {
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001458 if (s->data_ctx.stats.flags & STAT_NO_REFRESH)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001459 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001460 "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
1461 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001462 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02001463 "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001464 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001465 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001466 "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
1467 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001468 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02001469 ";norefresh");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001470 }
Willy Tarreau91861262007-10-17 17:06:05 +02001471
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001472 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001473 "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
1474 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001475 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
1476 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02001477
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001478 chunk_printf(&msg,
Willy Tarreau5031e6a2007-10-18 11:05:48 +02001479 "<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
1480 uri->uri_prefix,
1481 (uri->refresh > 0) ? ";norefresh" : "");
1482
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001483 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001484 "</ul></td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001485 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
1486 "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n"
1487 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
1488 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
1489 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
1490 "</ul>"
1491 "</td>"
1492 "</tr></table>\n"
1493 ""
1494 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001495
Cyril Bonté70be45d2010-10-12 00:14:35 +02001496 if (s->data_ctx.stats.st_code) {
1497 if (strcmp(s->data_ctx.stats.st_code, STAT_STATUS_DONE) == 0) {
1498 chunk_printf(&msg,
1499 "<p><div class=active3>"
1500 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
1501 "Action processed successfully."
1502 "</div>\n", uri->uri_prefix);
1503 }
1504 else if (strcmp(s->data_ctx.stats.st_code, STAT_STATUS_NONE) == 0) {
1505 chunk_printf(&msg,
1506 "<p><div class=active2>"
1507 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
1508 "Nothing has changed."
1509 "</div>\n", uri->uri_prefix);
1510 }
1511 else if (strcmp(s->data_ctx.stats.st_code, STAT_STATUS_EXCD) == 0) {
1512 chunk_printf(&msg,
1513 "<p><div class=active0>"
1514 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
1515 "<b>Action not processed : the buffer couldn't store all the data.<br>"
1516 "You should retry with less servers at a time.</b>"
1517 "</div>\n", uri->uri_prefix);
1518 }
Cyril Bonté474be412010-10-12 00:14:36 +02001519 else if (strcmp(s->data_ctx.stats.st_code, STAT_STATUS_DENY) == 0) {
1520 chunk_printf(&msg,
1521 "<p><div class=active0>"
1522 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
1523 "<b>Action denied.</b>"
1524 "</div>\n", uri->uri_prefix);
1525 }
Cyril Bonté70be45d2010-10-12 00:14:35 +02001526 else {
1527 chunk_printf(&msg,
1528 "<p><div class=active6>"
1529 "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> "
1530 "Unexpected result."
1531 "</div>\n", uri->uri_prefix);
1532 }
1533 chunk_printf(&msg,"<p>\n");
1534 }
1535
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001536 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001537 return 0;
1538 }
Willy Tarreau91861262007-10-17 17:06:05 +02001539
Willy Tarreau91861262007-10-17 17:06:05 +02001540 s->data_ctx.stats.px = proxy;
1541 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
1542 s->data_state = DATA_ST_LIST;
1543 /* fall through */
1544
1545 case DATA_ST_LIST:
1546 /* dump proxies */
1547 while (s->data_ctx.stats.px) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02001548 if (buffer_almost_full(rep))
1549 return 0;
Willy Tarreau91861262007-10-17 17:06:05 +02001550 px = s->data_ctx.stats.px;
1551 /* skip the disabled proxies and non-networked ones */
1552 if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001553 if (stats_dump_proxy(s, px, uri) == 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001554 return 0;
1555
1556 s->data_ctx.stats.px = px->next;
1557 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
1558 }
1559 /* here, we just have reached the last proxy */
1560
1561 s->data_state = DATA_ST_END;
1562 /* fall through */
1563
1564 case DATA_ST_END:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001565 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001566 chunk_printf(&msg, "</body></html>\n");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001567 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001568 return 0;
1569 }
Willy Tarreau91861262007-10-17 17:06:05 +02001570
1571 s->data_state = DATA_ST_FIN;
1572 /* fall through */
1573
1574 case DATA_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02001575 return 1;
1576
1577 default:
1578 /* unknown state ! */
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001579 s->data_state = DATA_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001580 return -1;
1581 }
1582}
1583
1584
1585/*
1586 * Dumps statistics for a proxy.
1587 * Returns 0 if it had to stop dumping data because of lack of buffer space,
1588 * ot non-zero if everything completed.
1589 */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001590int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001591{
1592 struct buffer *rep = s->rep;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001593 struct server *sv, *svs; /* server and server-state, server-state=server or server->tracked */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001594 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02001595 struct chunk msg;
1596
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001597 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +02001598
1599 switch (s->data_ctx.stats.px_st) {
1600 case DATA_ST_PX_INIT:
1601 /* we are on a new proxy */
1602
1603 if (uri && uri->scope) {
1604 /* we have a limited scope, we have to check the proxy name */
1605 struct stat_scope *scope;
1606 int len;
1607
1608 len = strlen(px->id);
1609 scope = uri->scope;
1610
1611 while (scope) {
1612 /* match exact proxy name */
1613 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
1614 break;
1615
1616 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02001617 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02001618 break;
1619 scope = scope->next;
1620 }
1621
1622 /* proxy name not found : don't dump anything */
1623 if (scope == NULL)
1624 return 1;
1625 }
1626
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001627 if ((s->data_ctx.stats.flags & STAT_BOUND) && (s->data_ctx.stats.iid != -1) &&
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001628 (px->uuid != s->data_ctx.stats.iid))
1629 return 1;
1630
Willy Tarreau91861262007-10-17 17:06:05 +02001631 s->data_ctx.stats.px_st = DATA_ST_PX_TH;
1632 /* fall through */
1633
1634 case DATA_ST_PX_TH:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001635 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Cyril Bonté474be412010-10-12 00:14:36 +02001636 if (px->cap & PR_CAP_BE && px->srv && (s->data_ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02001637 /* A form to enable/disable this proxy servers */
1638 chunk_printf(&msg,
1639 "<form action=\"%s\" method=\"post\">",
1640 uri->uri_prefix);
1641 }
1642
Willy Tarreau55bb8452007-10-17 18:44:57 +02001643 /* print a new table */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001644 chunk_printf(&msg,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001645 "<table class=\"tbl\" width=\"100%%\">\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001646 "<tr class=\"titre\">"
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001647 "<th class=\"pxname\" width=\"10%%\"");
1648
1649 if (uri->flags&ST_SHLGNDS) {
1650 /* cap, mode, id */
1651 chunk_printf(&msg, " title=\"cap: %s, mode: %s, id: %d",
1652 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
1653 px->uuid);
1654
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001655 chunk_printf(&msg, "\"");
1656 }
1657
1658 chunk_printf(&msg,
Willy Tarreaue0454092010-02-26 12:29:07 +01001659 ">%s<a name=\"%s\"></a>"
1660 "<a class=px href=\"#%s\">%s</a>%s</th>"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001661 "<th class=\"%s\" width=\"90%%\">%s</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001662 "</tr>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001663 "</table>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001664 "<table class=\"tbl\" width=\"100%%\">\n"
Cyril Bonté70be45d2010-10-12 00:14:35 +02001665 "<tr class=\"titre\">",
1666 (uri->flags & ST_SHLGNDS)?"<u>":"",
1667 px->id, px->id, px->id,
1668 (uri->flags & ST_SHLGNDS)?"</u>":"",
1669 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
1670
Cyril Bonté474be412010-10-12 00:14:36 +02001671 if (px->cap & PR_CAP_BE && px->srv && (s->data_ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02001672 /* Column heading for Enable or Disable server */
1673 chunk_printf(&msg, "<th rowspan=2 width=1></th>");
1674 }
1675
1676 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001677 "<th rowspan=2></th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001678 "<th colspan=3>Queue</th>"
1679 "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001680 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001681 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001682 "<th colspan=9>Server</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001683 "</tr>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001684 "<tr class=\"titre\">"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001685 "<th>Cur</th><th>Max</th><th>Limit</th>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001686 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001687 "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001688 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001689 "<th>Resp</th><th>Retr</th><th>Redis</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001690 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001691 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
1692 "<th>Thrtle</th>\n"
Cyril Bonté70be45d2010-10-12 00:14:35 +02001693 "</tr>");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001694
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001695 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001696 return 0;
1697 }
Willy Tarreau91861262007-10-17 17:06:05 +02001698
1699 s->data_ctx.stats.px_st = DATA_ST_PX_FE;
1700 /* fall through */
1701
1702 case DATA_ST_PX_FE:
1703 /* print the frontend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001704 if ((px->cap & PR_CAP_FE) &&
1705 (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) {
1706 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001707 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001708 /* name, queue */
Cyril Bonté70be45d2010-10-12 00:14:35 +02001709 "<tr class=\"frontend\">");
1710
Cyril Bonté474be412010-10-12 00:14:36 +02001711 if (px->cap & PR_CAP_BE && px->srv && (s->data_ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02001712 /* Column sub-heading for Enable or Disable server */
1713 chunk_printf(&msg, "<td></td>");
1714 }
1715
1716 chunk_printf(&msg,
1717 "<td class=ac>"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001718 "<a name=\"%s/Frontend\"></a>"
Cyril Bonté70be45d2010-10-12 00:14:35 +02001719 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
1720 "<td colspan=3></td>"
Willy Tarreaub44939a2010-02-26 11:35:39 +01001721 "",
1722 px->id, px->id);
1723
1724 if (px->mode == PR_MODE_HTTP) {
1725 chunk_printf(&msg,
1726 /* sessions rate : current, max, limit */
Willy Tarreaue0454092010-02-26 12:29:07 +01001727 "<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 +01001728 "",
1729 read_freq_ctr(&px->fe_req_per_sec),
1730 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
1731 px->counters.fe_rps_max,
Cyril Bonté4d179eb2010-07-23 18:59:11 +02001732 U2H1(px->counters.fe_sps_max),
Willy Tarreaub44939a2010-02-26 11:35:39 +01001733 LIM2A2(px->fe_sps_lim, "-"));
1734 } else {
1735 chunk_printf(&msg,
1736 /* sessions rate : current, max, limit */
1737 "<td>%s</td><td>%s</td><td>%s</td>"
1738 "",
1739 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
1740 U2H1(px->counters.fe_sps_max), LIM2A2(px->fe_sps_lim, "-"));
1741 }
1742
1743 chunk_printf(&msg,
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001744 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001745 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001746 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001747 "",
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001748 U2H3(px->feconn), U2H4(px->counters.feconn_max), U2H5(px->maxconn));
1749
1750 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1751 if (px->mode == PR_MODE_HTTP) {
1752 int i;
1753
Willy Tarreaub44939a2010-02-26 11:35:39 +01001754 chunk_printf(&msg, " title=\"%lld requests:", px->counters.cum_fe_req);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001755
1756 for (i = 1; i < 6; i++)
Willy Tarreau24657792010-02-26 10:30:28 +01001757 chunk_printf(&msg, " %dxx=%lld,", i, px->counters.fe.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001758
Willy Tarreau24657792010-02-26 10:30:28 +01001759 chunk_printf(&msg, " other=%lld\"", px->counters.fe.http.rsp[0]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001760 }
1761
1762 chunk_printf(&msg,
1763 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01001764 ">%s%s%s</td><td></td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001765 /* bytes : in, out */
1766 "<td>%s</td><td>%s</td>"
1767 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01001768 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreaub36b4242010-06-04 20:59:39 +02001769 U2H6(px->counters.cum_fesess),
Willy Tarreaue0454092010-02-26 12:29:07 +01001770 (px->mode == PR_MODE_HTTP)?"</u>":"",
1771 U2H7(px->counters.bytes_in), U2H8(px->counters.bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001772
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001773 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001774 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001775 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001776 /* errors : request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001777 "<td>%s</td><td></td><td></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001778 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001779 "<td></td><td></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001780 /* server status : reflect frontend status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001781 "<td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001782 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001783 "<td class=ac colspan=8></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +02001784 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001785 U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp),
1786 U2H2(px->counters.failed_req),
Willy Tarreau91861262007-10-17 17:06:05 +02001787 px->state == PR_STRUN ? "OPEN" :
1788 px->state == PR_STIDLE ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001789 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001790 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001791 /* pxid, name, queue cur, queue max, */
1792 "%s,FRONTEND,,,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001793 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001794 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001795 /* bytes : in, out */
1796 "%lld,%lld,"
1797 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001798 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001799 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001800 "%lld,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001801 /* warnings: retries, redispatches */
1802 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001803 /* server status : reflect frontend status */
1804 "%s,"
1805 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001806 ",,,,,,,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001807 /* pid, iid, sid, throttle, lbtot, tracked, type */
1808 "%d,%d,0,,,,%d,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001809 /* rate, rate_lim, rate_max */
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001810 "%u,%u,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001811 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001812 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02001813 px->id,
Willy Tarreaub36b4242010-06-04 20:59:39 +02001814 px->feconn, px->counters.feconn_max, px->maxconn, px->counters.cum_fesess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001815 px->counters.bytes_in, px->counters.bytes_out,
1816 px->counters.denied_req, px->counters.denied_resp,
1817 px->counters.failed_req,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001818 px->state == PR_STRUN ? "OPEN" :
Willy Tarreaudcd47712007-11-04 23:35:08 +01001819 px->state == PR_STIDLE ? "FULL" : "STOP",
Willy Tarreau7f062c42009-03-05 18:43:00 +01001820 relative_pid, px->uuid, STATS_TYPE_FE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001821 read_freq_ctr(&px->fe_sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001822 px->fe_sps_lim, px->counters.fe_sps_max);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001823
1824 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1825 if (px->mode == PR_MODE_HTTP) {
1826 int i;
1827
1828 for (i=1; i<6; i++)
Willy Tarreau24657792010-02-26 10:30:28 +01001829 chunk_printf(&msg, "%lld,", px->counters.fe.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001830
Willy Tarreau24657792010-02-26 10:30:28 +01001831 chunk_printf(&msg, "%lld,", px->counters.fe.http.rsp[0]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001832 } else {
1833 chunk_printf(&msg, ",,,,,,");
1834 }
1835
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001836 /* failed health analyses */
1837 chunk_printf(&msg, ",");
1838
Willy Tarreaud9b587f2010-02-26 10:05:55 +01001839 /* requests : req_rate, req_rate_max, req_tot, */
1840 chunk_printf(&msg, "%u,%u,%lld,",
1841 read_freq_ctr(&px->fe_req_per_sec),
1842 px->counters.fe_rps_max, px->counters.cum_fe_req);
1843
Willy Tarreauae526782010-03-04 20:34:23 +01001844 /* errors: cli_aborts, srv_aborts */
1845 chunk_printf(&msg, ",,");
1846
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001847 /* finish with EOL */
1848 chunk_printf(&msg, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001849 }
Willy Tarreau91861262007-10-17 17:06:05 +02001850
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001851 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001852 return 0;
1853 }
1854
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001855 s->data_ctx.stats.l = px->listen; /* may be NULL */
1856 s->data_ctx.stats.px_st = DATA_ST_PX_LI;
1857 /* fall through */
1858
1859 case DATA_ST_PX_LI:
1860 /* stats.l has been initialized above */
1861 for (; s->data_ctx.stats.l != NULL; s->data_ctx.stats.l = l->next) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02001862 if (buffer_almost_full(rep))
1863 return 0;
1864
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001865 l = s->data_ctx.stats.l;
1866 if (!l->counters)
1867 continue;
1868
1869 if (s->data_ctx.stats.flags & STAT_BOUND) {
1870 if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SO)))
1871 break;
1872
1873 if (s->data_ctx.stats.sid != -1 && l->luid != s->data_ctx.stats.sid)
1874 continue;
1875 }
1876
1877 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02001878 chunk_printf(&msg, "<tr class=socket>");
Cyril Bonté474be412010-10-12 00:14:36 +02001879 if (px->cap & PR_CAP_BE && px->srv && (s->data_ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02001880 /* Column sub-heading for Enable or Disable server */
1881 chunk_printf(&msg, "<td></td>");
1882 }
1883 chunk_printf(&msg, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001884
1885 if (uri->flags&ST_SHLGNDS) {
1886 char str[INET6_ADDRSTRLEN], *fmt = NULL;
1887 int port;
1888
1889 chunk_printf(&msg, " title=\"IP: ");
1890
1891 port = (l->addr.ss_family == AF_INET6)
1892 ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port)
1893 : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port);
1894
1895 if (l->addr.ss_family == AF_INET) {
1896 if (inet_ntop(AF_INET,
1897 (const void *)&((struct sockaddr_in *)&l->addr)->sin_addr,
1898 str, sizeof(str)))
1899 fmt = "%s:%d";
1900 } else {
1901 if (inet_ntop(AF_INET6,
1902 (const void *)&((struct sockaddr_in6 *)(&l->addr))->sin6_addr,
1903 str, sizeof(str)))
1904 fmt = "[%s]:%d";
1905 }
1906
1907 if (fmt)
1908 chunk_printf(&msg, fmt, str, port);
1909 else
1910 chunk_printf(&msg, "(%s)", strerror(errno));
1911
1912 /* id */
1913 chunk_printf(&msg, ", id: %d", l->luid);
1914
1915 chunk_printf(&msg, "\"");
1916 }
1917
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001918 chunk_printf(&msg,
1919 /* name, queue */
Willy Tarreaue0454092010-02-26 12:29:07 +01001920 ">%s<a name=\"%s/+%s\"></a>"
1921 "<a class=lfsb href=\"#%s/+%s\">%s</a></td><td colspan=3>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001922 /* sessions rate: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001923 "<td colspan=3>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001924 /* sessions: current, max, limit, total, lbtot */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001925 "<td>%s</td><td>%s</td><td>%s</td>"
1926 "<td>%s</td><td>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001927 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001928 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001929 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01001930 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki2ec025d2010-01-04 11:33:32 +01001931 px->id, l->name, px->id, l->name, l->name,
Willy Tarreaue0454092010-02-26 12:29:07 +01001932 (uri->flags & ST_SHLGNDS)?"</u>":"",
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001933 U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn),
1934 U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out));
1935
1936 chunk_printf(&msg,
1937 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001938 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001939 /* errors: request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001940 "<td>%s</td><td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001941 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001942 "<td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001943 /* server status: reflect listener status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001944 "<td class=ac>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001945 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001946 "<td class=ac colspan=8></td></tr>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001947 "",
1948 U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp),
1949 U2H2(l->counters->failed_req),
1950 (l->nbconn < l->maxconn) ? "OPEN" : "FULL");
1951 } else {
1952 chunk_printf(&msg,
1953 /* pxid, name, queue cur, queue max, */
1954 "%s,%s,,,"
1955 /* sessions: current, max, limit, total */
1956 "%d,%d,%d,%lld,"
1957 /* bytes: in, out */
1958 "%lld,%lld,"
1959 /* denied: req, resp */
1960 "%lld,%lld,"
1961 /* errors: request, connect, response */
1962 "%lld,,,"
1963 /* warnings: retries, redispatches */
1964 ",,"
1965 /* server status: reflect listener status */
1966 "%s,"
1967 /* rest of server: nothing */
1968 ",,,,,,,,"
1969 /* pid, iid, sid, throttle, lbtot, tracked, type */
1970 "%d,%d,%d,,,,%d,"
1971 /* rate, rate_lim, rate_max */
1972 ",,,"
1973 /* check_status, check_code, check_duration */
1974 ",,,"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001975 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1976 ",,,,,,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001977 /* failed health analyses */
1978 ","
Willy Tarreaud9b587f2010-02-26 10:05:55 +01001979 /* requests : req_rate, req_rate_max, req_tot, */
1980 ",,,"
Willy Tarreauae526782010-03-04 20:34:23 +01001981 /* errors: cli_aborts, srv_aborts */
1982 ",,"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001983 "\n",
1984 px->id, l->name,
1985 l->nbconn, l->counters->conn_max,
1986 l->maxconn, l->counters->cum_conn,
1987 l->counters->bytes_in, l->counters->bytes_out,
1988 l->counters->denied_req, l->counters->denied_resp,
1989 l->counters->failed_req,
1990 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
1991 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
1992 }
1993
1994 if (buffer_feed_chunk(rep, &msg) >= 0)
1995 return 0;
1996 }
1997
Willy Tarreau91861262007-10-17 17:06:05 +02001998 s->data_ctx.stats.sv = px->srv; /* may be NULL */
1999 s->data_ctx.stats.px_st = DATA_ST_PX_SV;
2000 /* fall through */
2001
2002 case DATA_ST_PX_SV:
2003 /* stats.sv has been initialized above */
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002004 for (; s->data_ctx.stats.sv != NULL; s->data_ctx.stats.sv = sv->next) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002005 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 +02002006
Willy Tarreau4e33d862009-10-11 23:35:10 +02002007 if (buffer_almost_full(rep))
2008 return 0;
2009
Willy Tarreau91861262007-10-17 17:06:05 +02002010 sv = s->data_ctx.stats.sv;
2011
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002012 if (s->data_ctx.stats.flags & STAT_BOUND) {
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002013 if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SV)))
2014 break;
2015
2016 if (s->data_ctx.stats.sid != -1 && sv->puid != s->data_ctx.stats.sid)
2017 continue;
2018 }
2019
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002020 if (sv->tracked)
2021 svs = sv->tracked;
2022 else
2023 svs = sv;
2024
Willy Tarreau91861262007-10-17 17:06:05 +02002025 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002026 if (!(svs->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +01002027 sv_state = 6;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002028 else if (svs->state & SRV_RUNNING) {
2029 if (svs->health == svs->rise + svs->fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02002030 sv_state = 3; /* UP */
2031 else
2032 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01002033
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002034 if (svs->state & SRV_GOINGDOWN)
Willy Tarreau2ea81932007-11-30 12:04:38 +01002035 sv_state += 2;
2036 }
Willy Tarreau91861262007-10-17 17:06:05 +02002037 else
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002038 if (svs->health)
Willy Tarreau91861262007-10-17 17:06:05 +02002039 sv_state = 1; /* going up */
2040 else
2041 sv_state = 0; /* DOWN */
2042
Cyril Bonté0dae5852010-02-03 00:26:28 +01002043 if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (s->data_ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02002044 /* do not report servers which are DOWN */
2045 s->data_ctx.stats.sv = sv->next;
2046 continue;
2047 }
2048
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002049 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002050 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
2051 "UP %d/%d &darr;", "UP",
2052 "NOLB %d/%d &darr;", "NOLB",
2053 "<i>no check</i>" };
Cyril Bonté0dae5852010-02-03 00:26:28 +01002054 if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) {
Cyril Bontécd19e512010-01-31 22:34:03 +01002055 chunk_printf(&msg,
2056 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002057 "<tr class=\"maintain\">"
Cyril Bontécd19e512010-01-31 22:34:03 +01002058 );
2059 }
2060 else {
2061 chunk_printf(&msg,
2062 /* name */
Cyril Bonté70be45d2010-10-12 00:14:35 +02002063 "<tr class=\"%s%d\">",
Cyril Bontécd19e512010-01-31 22:34:03 +01002064 (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state);
2065 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002066
Cyril Bonté474be412010-10-12 00:14:36 +02002067 if (px->cap & PR_CAP_BE && px->srv && (s->data_ctx.stats.flags & STAT_ADMIN)) {
2068 chunk_printf(&msg,
2069 "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
2070 sv->id);
2071 }
2072
2073 chunk_printf(&msg, "<td class=ac");
Cyril Bonté70be45d2010-10-12 00:14:35 +02002074
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002075 if (uri->flags&ST_SHLGNDS) {
2076 char str[INET6_ADDRSTRLEN];
2077
2078 chunk_printf(&msg, " title=\"IP: ");
2079
2080 /* IP */
2081 if (inet_ntop(sv->addr.sin_family, &sv->addr.sin_addr, str, sizeof(str)))
2082 chunk_printf(&msg, "%s:%d", str, htons(sv->addr.sin_port));
2083 else
2084 chunk_printf(&msg, "(%s)", strerror(errno));
2085
2086 /* id */
2087 chunk_printf(&msg, ", id: %d", sv->puid);
2088
2089 /* cookie */
2090 if (sv->cookie) {
2091 struct chunk src;
2092
2093 chunk_printf(&msg, ", cookie: '");
2094
2095 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
2096 chunk_htmlencode(&msg, &src);
2097
2098 chunk_printf(&msg, "'");
2099 }
2100
2101 chunk_printf(&msg, "\"");
2102 }
2103
2104 chunk_printf(&msg,
Willy Tarreaue0454092010-02-26 12:29:07 +01002105 ">%s<a name=\"%s/%s\"></a>"
2106 "<a class=lfsb href=\"#%s/%s\">%s</a>%s</td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002107 /* queue : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002108 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002109 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002110 "<td>%s</td><td>%s</td><td></td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002111 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002112 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002113 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002114 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002115 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002116 px->id, sv->id, px->id, sv->id, sv->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01002117 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002118 U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"),
2119 U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max),
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002120 U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-"));
2121
2122 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2123 if (px->mode == PR_MODE_HTTP) {
2124 int i;
2125
2126 chunk_printf(&msg, " title=\"rsp codes:");
2127
2128 for (i = 1; i < 6; i++)
2129 chunk_printf(&msg, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]);
2130
2131 chunk_printf(&msg, " other=%lld\"", sv->counters.p.http.rsp[0]);
2132 }
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002133
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002134 chunk_printf(&msg,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002135 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002136 ">%s%s%s</td><td>%s</td>",
2137 (px->mode == PR_MODE_HTTP)?"<u>":"",
2138 U2H0(sv->counters.cum_sess),
2139 (px->mode == PR_MODE_HTTP)?"</u>":"",
2140 U2H1(sv->counters.cum_lbconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002141
2142 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002143 /* bytes : in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002144 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002145 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002146 "<td></td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01002147 /* errors : request, connect */
2148 "<td></td><td>%s</td>"
2149 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002150 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002151 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002152 "<td>%lld</td><td>%lld</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002153 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002154 U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out),
2155 U2H2(sv->counters.failed_secu),
Willy Tarreauae526782010-03-04 20:34:23 +01002156 U2H3(sv->counters.failed_conns),
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002157 sv->counters.cli_aborts,
2158 sv->counters.srv_aborts,
Willy Tarreauae526782010-03-04 20:34:23 +01002159 U2H6(sv->counters.failed_resp),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002160 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002161
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002162 /* status, lest check */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002163 chunk_printf(&msg, "<td class=ac>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002164
Cyril Bontécd19e512010-01-31 22:34:03 +01002165 if (sv->state & SRV_MAINTAIN) {
2166 chunk_printf(&msg, "%s ",
2167 human_time(now.tv_sec - sv->last_change, 1));
2168 chunk_printf(&msg, "MAINT");
2169 }
Cyril Bonté0dae5852010-02-03 00:26:28 +01002170 else if (svs != sv && svs->state & SRV_MAINTAIN) {
2171 chunk_printf(&msg, "%s ",
2172 human_time(now.tv_sec - svs->last_change, 1));
2173 chunk_printf(&msg, "MAINT(via)");
2174 }
Cyril Bontécd19e512010-01-31 22:34:03 +01002175 else if (svs->state & SRV_CHECKED) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002176 chunk_printf(&msg, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01002177 human_time(now.tv_sec - svs->last_change, 1));
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002178
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002179 chunk_printf(&msg,
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002180 srv_hlt_st[sv_state],
2181 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
2182 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002183 }
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002184
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002185 if (sv->state & SRV_CHECKED) {
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002186 chunk_printf(&msg, "</td><td class=ac title=\"%s",
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02002187 get_check_status_description(sv->check_status));
2188
2189 if (*sv->check_desc) {
2190 struct chunk src;
2191
2192 chunk_printf(&msg, ": ");
2193
2194 chunk_initlen(&src, sv->check_desc, 0, strlen(sv->check_desc));
2195 chunk_htmlencode(&msg, &src);
2196 }
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002197
Willy Tarreaue0454092010-02-26 12:29:07 +01002198 chunk_printf(&msg, "\"><u> %s%s",
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002199 tv_iszero(&sv->check_start)?"":"* ",
2200 get_check_status_info(sv->check_status));
2201
2202 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002203 chunk_printf(&msg, "/%d", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002204
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002205 if (sv->check_status >= HCHK_STATUS_CHECKED && sv->check_duration >= 0)
Willy Tarreaue0454092010-02-26 12:29:07 +01002206 chunk_printf(&msg, " in %lums</u>", sv->check_duration);
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002207 } else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002208 chunk_printf(&msg, "</td><td>");
Willy Tarreau91861262007-10-17 17:06:05 +02002209
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002210 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002211 /* weight */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002212 "</td><td class=ac>%d</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002213 /* act, bck */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002214 "<td class=ac>%s</td><td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002215 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01002216 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +02002217 (sv->state & SRV_BACKUP) ? "-" : "Y",
2218 (sv->state & SRV_BACKUP) ? "Y" : "-");
2219
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002220 /* check failures: unique, fatal, down time */
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002221 if (sv->state & SRV_CHECKED) {
Willy Tarreaue0454092010-02-26 12:29:07 +01002222 chunk_printf(&msg, "<td title=\"Failed Health Checks%s\"><u>%lld",
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002223 svs->observe?"/Health Analyses":"", svs->counters.failed_checks);
2224
2225 if (svs->observe)
2226 chunk_printf(&msg, "/%lld", svs->counters.failed_hana);
2227
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002228 chunk_printf(&msg,
Willy Tarreaue0454092010-02-26 12:29:07 +01002229 "</u></td>"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002230 "<td>%lld</td><td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002231 "",
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002232 svs->counters.down_trans, human_time(srv_downtime(sv), 1));
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01002233 } else if (sv != svs)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002234 chunk_printf(&msg,
Krzysztof Piotr Oledzki88a14af2010-01-05 18:33:01 +01002235 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>",
2236 svs->proxy->id, svs->id, svs->proxy->id, svs->id);
Willy Tarreau55bb8452007-10-17 18:44:57 +02002237 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002238 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002239 "<td colspan=3></td>");
2240
2241 /* throttle */
2242 if ((sv->state & SRV_WARMINGUP) &&
2243 now.tv_sec < sv->last_change + sv->slowstart &&
2244 now.tv_sec >= sv->last_change) {
2245 unsigned int ratio;
2246 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002247 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002248 "<td class=ac>%d %%</td></tr>\n", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002249 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002250 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002251 "<td class=ac>-</td></tr>\n");
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002252 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02002253 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +01002254 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
2255 "UP %d/%d,", "UP,",
2256 "NOLB %d/%d,", "NOLB,",
2257 "no check," };
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002258 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002259 /* pxid, name */
2260 "%s,%s,"
2261 /* queue : current, max */
2262 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002263 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002264 "%d,%d,%s,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002265 /* bytes : in, out */
2266 "%lld,%lld,"
2267 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002268 ",%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002269 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002270 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002271 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002272 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002273 "",
2274 px->id, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002275 sv->nbpend, sv->counters.nbpend_max,
2276 sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002277 sv->counters.bytes_in, sv->counters.bytes_out,
2278 sv->counters.failed_secu,
2279 sv->counters.failed_conns, sv->counters.failed_resp,
2280 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002281
Willy Tarreau55bb8452007-10-17 18:44:57 +02002282 /* status */
Cyril Bontécd19e512010-01-31 22:34:03 +01002283 if (sv->state & SRV_MAINTAIN) {
2284 chunk_printf(&msg, "MAINT,");
Cyril Bonté0dae5852010-02-03 00:26:28 +01002285 }
2286 else if (svs != sv && svs->state & SRV_MAINTAIN) {
2287 chunk_printf(&msg, "MAINT(via),");
2288 }
2289 else {
Cyril Bontécd19e512010-01-31 22:34:03 +01002290 chunk_printf(&msg,
2291 srv_hlt_st[sv_state],
2292 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
2293 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
2294 }
Willy Tarreau91861262007-10-17 17:06:05 +02002295
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002296 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002297 /* weight, active, backup */
2298 "%d,%d,%d,"
2299 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01002300 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002301 (sv->state & SRV_BACKUP) ? 0 : 1,
2302 (sv->state & SRV_BACKUP) ? 1 : 0);
2303
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002304 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +02002305 if (sv->state & SRV_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002306 chunk_printf(&msg,
Willy Tarreau3b88d442009-04-11 20:44:08 +02002307 "%lld,%lld,%d,%d,",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002308 sv->counters.failed_checks, sv->counters.down_trans,
Willy Tarreau1772ece2009-04-03 14:49:12 +02002309 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +02002310 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002311 chunk_printf(&msg,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002312 ",,,,");
2313
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002314 /* queue limit, pid, iid, sid, */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002315 chunk_printf(&msg,
Willy Tarreaudcd47712007-11-04 23:35:08 +01002316 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002317 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +01002318 LIM2A0(sv->maxqueue, ""),
2319 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002320
2321 /* throttle */
2322 if ((sv->state & SRV_WARMINGUP) &&
2323 now.tv_sec < sv->last_change + sv->slowstart &&
2324 now.tv_sec >= sv->last_change) {
2325 unsigned int ratio;
2326 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002327 chunk_printf(&msg, "%d", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002328 }
2329
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002330 /* sessions: lbtot */
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002331 chunk_printf(&msg, ",%lld,", sv->counters.cum_lbconn);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002332
2333 /* tracked */
2334 if (sv->tracked)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002335 chunk_printf(&msg, "%s/%s,",
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002336 sv->tracked->proxy->id, sv->tracked->id);
2337 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002338 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002339
Willy Tarreau7f062c42009-03-05 18:43:00 +01002340 /* type */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002341 chunk_printf(&msg, "%d,", STATS_TYPE_SV);
Willy Tarreau7f062c42009-03-05 18:43:00 +01002342
2343 /* rate */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002344 chunk_printf(&msg, "%u,,%u,",
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002345 read_freq_ctr(&sv->sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002346 sv->counters.sps_max);
Willy Tarreau7f062c42009-03-05 18:43:00 +01002347
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002348 if (sv->state & SRV_CHECKED) {
2349 /* check_status */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002350 chunk_printf(&msg, "%s,", get_check_status_info(sv->check_status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002351
2352 /* check_code */
2353 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002354 chunk_printf(&msg, "%u,", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002355 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002356 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002357
2358 /* check_duration */
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002359 if (sv->check_status >= HCHK_STATUS_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002360 chunk_printf(&msg, "%lu,", sv->check_duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002361 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002362 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002363
2364 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002365 chunk_printf(&msg, ",,,");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002366 }
2367
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002368 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2369 if (px->mode == PR_MODE_HTTP) {
2370 int i;
2371
2372 for (i=1; i<6; i++)
2373 chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[i]);
2374
2375 chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[0]);
2376 } else {
2377 chunk_printf(&msg, ",,,,,,");
2378 }
2379
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002380 /* failed health analyses */
2381 chunk_printf(&msg, "%lld,", sv->counters.failed_hana);
2382
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002383 /* requests : req_rate, req_rate_max, req_tot, */
2384 chunk_printf(&msg, ",,,");
2385
Willy Tarreauae526782010-03-04 20:34:23 +01002386 /* errors: cli_aborts, srv_aborts */
2387 chunk_printf(&msg, "%lld,%lld,",
2388 sv->counters.cli_aborts, sv->counters.srv_aborts);
2389
Willy Tarreau7f062c42009-03-05 18:43:00 +01002390 /* finish with EOL */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002391 chunk_printf(&msg, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002392 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002393 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002394 return 0;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002395 } /* for sv */
Willy Tarreau91861262007-10-17 17:06:05 +02002396
2397 s->data_ctx.stats.px_st = DATA_ST_PX_BE;
2398 /* fall through */
2399
2400 case DATA_ST_PX_BE:
2401 /* print the backend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002402 if ((px->cap & PR_CAP_BE) &&
2403 (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_BE)))) {
2404 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002405 chunk_printf(&msg, "<tr class=\"backend\">");
Cyril Bonté474be412010-10-12 00:14:36 +02002406 if (px->cap & PR_CAP_BE && px->srv && (s->data_ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002407 /* Column sub-heading for Enable or Disable server */
2408 chunk_printf(&msg, "<td></td>");
2409 }
2410 chunk_printf(&msg, "<td class=ac");
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002411
2412 if (uri->flags&ST_SHLGNDS) {
2413 /* balancing */
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01002414 chunk_printf(&msg, " title=\"balancing: %s",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002415 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01002416
2417 /* cookie */
2418 if (px->cookie_name) {
2419 struct chunk src;
2420
2421 chunk_printf(&msg, ", cookie: '");
2422
2423 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
2424 chunk_htmlencode(&msg, &src);
2425
2426 chunk_printf(&msg, "'");
2427 }
2428
2429 chunk_printf(&msg, "\"");
2430
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002431 }
2432
2433 chunk_printf(&msg,
Cyril Bonté70be45d2010-10-12 00:14:35 +02002434 /* name */
Willy Tarreaue0454092010-02-26 12:29:07 +01002435 ">%s<a name=\"%s/Backend\"></a>"
2436 "<a class=lfsb href=\"#%s/Backend\">Backend</a>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002437 /* queue : current, max */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002438 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002439 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002440 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002441 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002442 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002443 px->id, px->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01002444 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002445 U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->counters.nbpend_max),
2446 U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->counters.be_sps_max));
Willy Tarreaua3e49422009-05-10 19:19:41 +02002447
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002448 chunk_printf(&msg,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002449 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002450 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002451 "<td"
2452 "",
2453 U2H2(px->beconn), U2H3(px->counters.beconn_max), U2H4(px->fullconn));
2454
2455 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2456 if (px->mode == PR_MODE_HTTP) {
2457 int i;
2458
2459 chunk_printf(&msg, " title=\"rsp codes:");
2460
2461 for (i = 1; i < 6; i++)
Willy Tarreau24657792010-02-26 10:30:28 +01002462 chunk_printf(&msg, " %dxx=%lld", i, px->counters.be.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002463
Willy Tarreau24657792010-02-26 10:30:28 +01002464 chunk_printf(&msg, " other=%lld\"", px->counters.be.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002465 }
2466
2467 chunk_printf(&msg,
2468 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002469 ">%s%s%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002470 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002471 "<td>%s</td><td>%s</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002472 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002473 (px->mode == PR_MODE_HTTP)?"<u>":"",
2474 U2H6(px->counters.cum_beconn),
2475 (px->mode == PR_MODE_HTTP)?"</u>":"",
2476 U2H7(px->counters.cum_lbconn),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002477 U2H8(px->counters.bytes_in), U2H9(px->counters.bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002478
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002479 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002480 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002481 "<td>%s</td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01002482 /* errors : request, connect */
2483 "<td></td><td>%s</td>"
2484 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002485 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002486 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002487 "<td>%lld</td><td>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002488 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +02002489 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002490 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +02002491 * active and backups. */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002492 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
2493 "<td class=ac>%d</td><td class=ac>%d</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002494 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002495 U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp),
Willy Tarreauae526782010-03-04 20:34:23 +01002496 U2H2(px->counters.failed_conns),
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002497 px->counters.cli_aborts,
2498 px->counters.srv_aborts,
Willy Tarreauae526782010-03-04 20:34:23 +01002499 U2H5(px->counters.failed_resp),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002500 px->counters.retries, px->counters.redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002501 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +01002502 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
2503 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5542af62007-12-03 02:04:00 +01002504 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01002505 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002506
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002507 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002508 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002509 "<td class=ac>&nbsp;</td><td>%d</td>"
2510 "<td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002511 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002512 "</tr>",
2513 px->down_trans,
2514 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002515 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002516 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002517 /* pxid, name */
2518 "%s,BACKEND,"
2519 /* queue : current, max */
2520 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002521 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002522 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002523 /* bytes : in, out */
2524 "%lld,%lld,"
2525 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002526 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002527 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002528 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002529 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002530 "%lld,%lld,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002531 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +02002532 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002533 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +02002534 * active and backups. */
2535 "%s,"
2536 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002537 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002538 ",%d,%d,%d,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002539 /* pid, iid, sid, throttle, lbtot, tracked, type */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002540 "%d,%d,0,,%lld,,%d,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002541 /* rate, rate_lim, rate_max, */
2542 "%u,,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002543 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002544 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02002545 px->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002546 px->nbpend /* or px->totpend ? */, px->counters.nbpend_max,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002547 px->beconn, px->counters.beconn_max, px->fullconn, px->counters.cum_beconn,
2548 px->counters.bytes_in, px->counters.bytes_out,
2549 px->counters.denied_req, px->counters.denied_resp,
2550 px->counters.failed_conns, px->counters.failed_resp,
2551 px->counters.retries, px->counters.redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +01002552 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5542af62007-12-03 02:04:00 +01002553 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01002554 px->srv_act, px->srv_bck,
Willy Tarreau1772ece2009-04-03 14:49:12 +02002555 px->down_trans, (int)(now.tv_sec - px->last_change),
Willy Tarreau20697042007-11-15 23:26:18 +01002556 px->srv?be_downtime(px):0,
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002557 relative_pid, px->uuid,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002558 px->counters.cum_lbconn, STATS_TYPE_BE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002559 read_freq_ctr(&px->be_sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002560 px->counters.be_sps_max);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002561
2562 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2563 if (px->mode == PR_MODE_HTTP) {
2564 int i;
2565
2566 for (i=1; i<6; i++)
Willy Tarreau24657792010-02-26 10:30:28 +01002567 chunk_printf(&msg, "%lld,", px->counters.be.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002568
Willy Tarreau24657792010-02-26 10:30:28 +01002569 chunk_printf(&msg, "%lld,", px->counters.be.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002570 } else {
2571 chunk_printf(&msg, ",,,,,,");
2572 }
2573
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002574 /* failed health analyses */
2575 chunk_printf(&msg, ",");
2576
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002577 /* requests : req_rate, req_rate_max, req_tot, */
2578 chunk_printf(&msg, ",,,");
2579
Willy Tarreauae526782010-03-04 20:34:23 +01002580 /* errors: cli_aborts, srv_aborts */
2581 chunk_printf(&msg, "%lld,%lld,",
2582 px->counters.cli_aborts, px->counters.srv_aborts);
2583
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002584 /* finish with EOL */
2585 chunk_printf(&msg, "\n");
2586
Willy Tarreau55bb8452007-10-17 18:44:57 +02002587 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002588 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002589 return 0;
2590 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002591
Willy Tarreau91861262007-10-17 17:06:05 +02002592 s->data_ctx.stats.px_st = DATA_ST_PX_END;
2593 /* fall through */
2594
2595 case DATA_ST_PX_END:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002596 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002597 chunk_printf(&msg, "</table>");
2598
Cyril Bonté474be412010-10-12 00:14:36 +02002599 if (px->cap & PR_CAP_BE && px->srv && (s->data_ctx.stats.flags & STAT_ADMIN)) {
Cyril Bonté70be45d2010-10-12 00:14:35 +02002600 /* close the form used to enable/disable this proxy servers */
2601 chunk_printf(&msg,
2602 "Choose the action to perform on the checked servers : "
2603 "<select name=action>"
2604 "<option value=\"\"></option>"
2605 "<option value=\"disable\">Disable</option>"
2606 "<option value=\"enable\">Enable</option>"
2607 "</select>"
2608 "<input type=\"hidden\" name=\"b\" value=\"%s\">"
2609 "&nbsp;<input type=\"submit\" value=\"Apply\">"
2610 "</form>",
2611 px->id);
2612 }
2613
2614 chunk_printf(&msg, "<p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +02002615
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002616 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002617 return 0;
2618 }
Willy Tarreau91861262007-10-17 17:06:05 +02002619
2620 s->data_ctx.stats.px_st = DATA_ST_PX_FIN;
2621 /* fall through */
2622
2623 case DATA_ST_PX_FIN:
2624 return 1;
2625
2626 default:
2627 /* unknown state, we should put an abort() here ! */
2628 return 1;
2629 }
2630}
2631
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002632/* This function is called to send output to the response buffer. It dumps a
2633 * complete session state onto the output buffer <rep>. The session has to be
2634 * set in data_ctx.sess.target. It returns 0 if the output buffer is full and
2635 * it needs to be called again, otherwise non-zero. It is designed to be called
2636 * from stats_dump_sess_to_buffer() below.
2637 */
2638
2639/* returns 1 if dump is not complete */
2640int stats_dump_full_sess_to_buffer(struct session *s, struct buffer *rep)
2641{
2642 struct tm tm;
2643 struct chunk msg;
2644 struct session *sess;
2645 extern const char *monthname[12];
2646 char pn[INET6_ADDRSTRLEN];
2647
2648 chunk_init(&msg, trash, sizeof(trash));
2649 sess = s->data_ctx.sess.target;
2650
2651 if (s->data_ctx.sess.section > 0 && s->data_ctx.sess.uid != sess->uniq_id) {
2652 /* session changed, no need to go any further */
2653 chunk_printf(&msg, " *** session terminated while we were watching it ***\n");
2654 if (buffer_feed_chunk(rep, &msg) >= 0)
2655 return 0;
2656 s->data_ctx.sess.target = NULL;
2657 s->data_ctx.sess.uid = 0;
2658 return 1;
2659 }
2660
2661 switch (s->data_ctx.sess.section) {
2662 case 0: /* main status of the session */
2663 s->data_ctx.sess.uid = sess->uniq_id;
2664 s->data_ctx.sess.section = 1;
2665 /* fall through */
2666
2667 case 1:
2668 chunk_printf(&msg,
2669 "%p: id=%u, proto=%s",
2670 sess,
2671 sess->uniq_id,
2672 sess->listener->proto->name);
2673
2674 switch (sess->listener->proto->sock_family) {
2675 case AF_INET:
2676 inet_ntop(AF_INET,
2677 (const void *)&((struct sockaddr_in *)&sess->cli_addr)->sin_addr,
2678 pn, sizeof(pn));
2679
2680 chunk_printf(&msg,
2681 " source=%s:%d\n",
2682 pn,
2683 ntohs(((struct sockaddr_in *)&sess->cli_addr)->sin_port));
2684 break;
2685 case AF_INET6:
2686 inet_ntop(AF_INET6,
2687 (const void *)&((struct sockaddr_in6 *)(&sess->cli_addr))->sin6_addr,
2688 pn, sizeof(pn));
2689
2690 chunk_printf(&msg,
2691 " source=%s:%d\n",
2692 pn,
2693 ntohs(((struct sockaddr_in6 *)&sess->cli_addr)->sin6_port));
2694 break;
2695 case AF_UNIX:
Emeric Brun837ca522010-10-22 16:19:01 +02002696 chunk_printf(&msg,
2697 " source=unix:%d\n", sess->listener->luid);
2698 break;
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002699 default:
2700 /* no more information to print right now */
2701 chunk_printf(&msg, "\n");
2702 break;
2703 }
2704
2705 chunk_printf(&msg,
2706 " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n",
Willy Tarreauee28de02010-06-01 09:51:00 +02002707 sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002708
2709 chunk_printf(&msg,
2710 " frontend=%s (id=%u mode=%s), listener=%s (id=%u)\n",
2711 sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp",
2712 sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?",
2713 sess->listener ? sess->listener->luid : 0);
2714
2715 chunk_printf(&msg,
2716 " backend=%s (id=%u mode=%s) server=%s (id=%u)\n",
2717 sess->be->id, sess->be->uuid, sess->be->mode ? "http" : "tcp",
2718 sess->srv ? sess->srv->id : "<none>",
2719 sess->srv ? sess->srv->puid : 0);
2720
2721 chunk_printf(&msg,
2722 " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s)\n",
2723 sess->task,
2724 sess->task->state,
2725 sess->task->nice, sess->task->calls,
2726 sess->task->expire ?
2727 tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" :
2728 human_time(TICKS_TO_MS(sess->task->expire - now_ms),
2729 TICKS_TO_MS(1000)) : "<NEVER>",
2730 task_in_rq(sess->task) ? ", running" : "");
2731
2732 get_localtime(sess->logs.accept_date.tv_sec, &tm);
2733 chunk_printf(&msg,
2734 " task created [%02d/%s/%04d:%02d:%02d:%02d.%06d] (age=%s)\n",
2735 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
2736 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec),
2737 human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1));
2738
2739 chunk_printf(&msg,
2740 " si[0]=%p (state=%d flags=0x%02x fd=%d exp=%s, et=0x%03x)\n",
2741 &sess->si[0],
2742 sess->si[0].state,
2743 sess->si[0].flags,
2744 sess->si[0].fd,
2745 sess->si[0].exp ?
2746 tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" :
2747 human_time(TICKS_TO_MS(sess->si[0].exp - now_ms),
2748 TICKS_TO_MS(1000)) : "<NEVER>",
2749 sess->si[0].err_type);
2750
2751 chunk_printf(&msg,
2752 " si[1]=%p (state=%d flags=0x%02x fd=%d exp=%s, et=0x%03x)\n",
2753 &sess->si[1],
2754 sess->si[1].state,
2755 sess->si[1].flags,
2756 sess->si[1].fd,
2757 sess->si[1].exp ?
2758 tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" :
2759 human_time(TICKS_TO_MS(sess->si[1].exp - now_ms),
2760 TICKS_TO_MS(1000)) : "<NEVER>",
2761 sess->si[1].err_type);
2762
2763 chunk_printf(&msg,
2764 " txn=%p (flags=0x%x meth=%d status=%d req.st=%d rsp.st=%d)\n",
2765 &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status,
2766 sess->txn.req.msg_state, sess->txn.rsp.msg_state);
2767
2768
2769 chunk_printf(&msg,
2770 " req=%p (f=0x%06x an=0x%x l=%d sndmx=%d pipe=%d fwd=%ld)\n"
2771 " an_exp=%s",
2772 sess->req,
2773 sess->req->flags, sess->req->analysers,
2774 sess->req->l, sess->req->send_max,
2775 sess->req->pipe ? sess->req->pipe->data : 0,
2776 sess->req->to_forward,
2777 sess->req->analyse_exp ?
2778 human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms),
2779 TICKS_TO_MS(1000)) : "<NEVER>");
2780
2781 chunk_printf(&msg,
2782 " rex=%s",
2783 sess->req->rex ?
2784 human_time(TICKS_TO_MS(sess->req->rex - now_ms),
2785 TICKS_TO_MS(1000)) : "<NEVER>");
2786
2787 chunk_printf(&msg,
2788 " wex=%s\n"
2789 " data=%p r=%d w=%d lr=%d total=%lld\n",
2790 sess->req->wex ?
2791 human_time(TICKS_TO_MS(sess->req->wex - now_ms),
2792 TICKS_TO_MS(1000)) : "<NEVER>",
2793 sess->req->data,
Willy Tarreau4e1554c2010-03-21 23:21:00 +01002794 (int)(sess->req->r - sess->req->data),
2795 (int)(sess->req->w - sess->req->data),
2796 (int)(sess->req->lr - sess->req->data),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002797 sess->req->total);
2798
2799 chunk_printf(&msg,
2800 " res=%p (f=0x%06x an=0x%x l=%d sndmx=%d pipe=%d fwd=%ld)\n"
2801 " an_exp=%s",
2802 sess->rep,
2803 sess->rep->flags, sess->rep->analysers,
2804 sess->rep->l, sess->rep->send_max,
2805 sess->rep->pipe ? sess->rep->pipe->data : 0,
2806 sess->rep->to_forward,
2807 sess->rep->analyse_exp ?
2808 human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms),
2809 TICKS_TO_MS(1000)) : "<NEVER>");
2810
2811 chunk_printf(&msg,
2812 " rex=%s",
2813 sess->rep->rex ?
2814 human_time(TICKS_TO_MS(sess->rep->rex - now_ms),
2815 TICKS_TO_MS(1000)) : "<NEVER>");
2816
2817 chunk_printf(&msg,
2818 " wex=%s\n"
2819 " data=%p r=%d w=%d lr=%d total=%lld\n",
2820 sess->rep->wex ?
2821 human_time(TICKS_TO_MS(sess->rep->wex - now_ms),
2822 TICKS_TO_MS(1000)) : "<NEVER>",
2823 sess->rep->data,
Willy Tarreau4e1554c2010-03-21 23:21:00 +01002824 (int)(sess->rep->r - sess->rep->data),
2825 (int)(sess->rep->w - sess->rep->data),
2826 (int)(sess->rep->lr - sess->rep->data),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002827 sess->rep->total);
2828
2829 if (buffer_feed_chunk(rep, &msg) >= 0)
2830 return 0;
2831
2832 /* use other states to dump the contents */
2833 }
2834 /* end of dump */
2835 s->data_ctx.sess.uid = 0;
2836 return 1;
2837}
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002838
2839/* This function is called to send output to the response buffer.
2840 * It dumps the sessions states onto the output buffer <rep>.
2841 * Expects to be called with client socket shut down on input.
2842 * s->data_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002843 * It returns 0 as long as it does not complete, non-zero upon completion.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002844 */
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002845int stats_dump_sess_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002846{
2847 struct chunk msg;
2848
2849 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) {
2850 /* If we're forced to shut down, we might have to remove our
2851 * reference to the last session being dumped.
2852 */
2853 if (s->data_state == DATA_ST_LIST) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002854 if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002855 LIST_DEL(&s->data_ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002856 LIST_INIT(&s->data_ctx.sess.bref.users);
2857 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002858 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002859 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002860 }
2861
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002862 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002863
2864 switch (s->data_state) {
2865 case DATA_ST_INIT:
2866 /* the function had not been called yet, let's prepare the
2867 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002868 * pointer to the first in the global list. When a target
2869 * session is being destroyed, it is responsible for updating
2870 * this pointer. We know we have reached the end when this
2871 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002872 */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002873 LIST_INIT(&s->data_ctx.sess.bref.users);
2874 s->data_ctx.sess.bref.ref = sessions.n;
2875 s->data_state = DATA_ST_LIST;
2876 /* fall through */
2877
2878 case DATA_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002879 /* first, let's detach the back-ref from a possible previous session */
2880 if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) {
2881 LIST_DEL(&s->data_ctx.sess.bref.users);
2882 LIST_INIT(&s->data_ctx.sess.bref.users);
2883 }
2884
2885 /* and start from where we stopped */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002886 while (s->data_ctx.sess.bref.ref != &sessions) {
Cyril Bontéacd7d632010-11-01 19:26:02 +01002887 char pn[INET6_ADDRSTRLEN];
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002888 struct session *curr_sess;
2889
2890 curr_sess = LIST_ELEM(s->data_ctx.sess.bref.ref, struct session *, list);
2891
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002892 if (s->data_ctx.sess.target) {
2893 if (s->data_ctx.sess.target != curr_sess)
2894 goto next_sess;
2895
2896 LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users);
2897 /* call the proper dump() function and return if we're missing space */
2898 if (!stats_dump_full_sess_to_buffer(s, rep))
2899 return 0;
2900
2901 /* session dump complete */
2902 LIST_DEL(&s->data_ctx.sess.bref.users);
2903 LIST_INIT(&s->data_ctx.sess.bref.users);
2904 s->data_ctx.sess.target = NULL;
2905 break;
2906 }
2907
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002908 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002909 "%p: proto=%s",
2910 curr_sess,
2911 curr_sess->listener->proto->name);
2912
2913 switch (curr_sess->listener->proto->sock_family) {
2914 case AF_INET:
2915 inet_ntop(AF_INET,
2916 (const void *)&((struct sockaddr_in *)&curr_sess->cli_addr)->sin_addr,
2917 pn, sizeof(pn));
2918
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002919 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002920 " src=%s:%d fe=%s be=%s srv=%s",
2921 pn,
2922 ntohs(((struct sockaddr_in *)&curr_sess->cli_addr)->sin_port),
2923 curr_sess->fe->id,
2924 curr_sess->be->id,
2925 curr_sess->srv ? curr_sess->srv->id : "<none>"
2926 );
2927 break;
2928 case AF_INET6:
2929 inet_ntop(AF_INET6,
2930 (const void *)&((struct sockaddr_in6 *)(&curr_sess->cli_addr))->sin6_addr,
2931 pn, sizeof(pn));
2932
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002933 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002934 " src=%s:%d fe=%s be=%s srv=%s",
2935 pn,
2936 ntohs(((struct sockaddr_in6 *)&curr_sess->cli_addr)->sin6_port),
2937 curr_sess->fe->id,
2938 curr_sess->be->id,
2939 curr_sess->srv ? curr_sess->srv->id : "<none>"
2940 );
2941
2942 break;
2943 case AF_UNIX:
Emeric Brun837ca522010-10-22 16:19:01 +02002944 chunk_printf(&msg,
2945 " src=unix:%d fe=%s be=%s srv=%s",
2946 curr_sess->listener->luid,
2947 curr_sess->fe->id,
2948 curr_sess->be->id,
2949 curr_sess->srv ? curr_sess->srv->id : "<none>"
2950 );
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002951 break;
2952 }
2953
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002954 chunk_printf(&msg,
Willy Tarreau65671ab2009-10-04 14:24:59 +02002955 " ts=%02x age=%s calls=%d",
2956 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01002957 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
2958 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002959
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002960 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002961 " rq[f=%06xh,l=%d,an=%02xh,rx=%s",
2962 curr_sess->req->flags,
2963 curr_sess->req->l,
2964 curr_sess->req->analysers,
2965 curr_sess->req->rex ?
2966 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
2967 TICKS_TO_MS(1000)) : "");
2968
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002969 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002970 ",wx=%s",
2971 curr_sess->req->wex ?
2972 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
2973 TICKS_TO_MS(1000)) : "");
2974
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002975 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002976 ",ax=%s]",
2977 curr_sess->req->analyse_exp ?
2978 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
2979 TICKS_TO_MS(1000)) : "");
2980
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002981 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002982 " rp[f=%06xh,l=%d,an=%02xh,rx=%s",
2983 curr_sess->rep->flags,
2984 curr_sess->rep->l,
2985 curr_sess->rep->analysers,
2986 curr_sess->rep->rex ?
2987 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
2988 TICKS_TO_MS(1000)) : "");
2989
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002990 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002991 ",wx=%s",
2992 curr_sess->rep->wex ?
2993 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
2994 TICKS_TO_MS(1000)) : "");
2995
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002996 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002997 ",ax=%s]",
2998 curr_sess->rep->analyse_exp ?
2999 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
3000 TICKS_TO_MS(1000)) : "");
3001
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003002 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003003 " s0=[%d,%1xh,fd=%d,ex=%s]",
3004 curr_sess->si[0].state,
3005 curr_sess->si[0].flags,
3006 curr_sess->si[0].fd,
3007 curr_sess->si[0].exp ?
3008 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
3009 TICKS_TO_MS(1000)) : "");
3010
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003011 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003012 " s1=[%d,%1xh,fd=%d,ex=%s]",
3013 curr_sess->si[1].state,
3014 curr_sess->si[1].flags,
3015 curr_sess->si[1].fd,
3016 curr_sess->si[1].exp ?
3017 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
3018 TICKS_TO_MS(1000)) : "");
3019
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003020 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003021 " exp=%s",
3022 curr_sess->task->expire ?
3023 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
3024 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01003025 if (task_in_rq(curr_sess->task))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003026 chunk_printf(&msg, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01003027
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003028 chunk_printf(&msg, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003029
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003030 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01003031 /* let's try again later from this session. We add ourselves into
3032 * this session's users so that it can remove us upon termination.
3033 */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003034 LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003035 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003036 }
3037
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003038 next_sess:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003039 s->data_ctx.sess.bref.ref = curr_sess->list.n;
3040 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01003041
3042 if (s->data_ctx.sess.target) {
3043 /* specified session not found */
3044 if (s->data_ctx.sess.section > 0)
3045 chunk_printf(&msg, " *** session terminated while we were watching it ***\n");
3046 else
3047 chunk_printf(&msg, "Session not found.\n");
3048
3049 if (buffer_feed_chunk(rep, &msg) >= 0)
3050 return 0;
3051
3052 s->data_ctx.sess.target = NULL;
3053 s->data_ctx.sess.uid = 0;
3054 return 1;
3055 }
3056
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003057 s->data_state = DATA_ST_FIN;
3058 /* fall through */
3059
3060 default:
3061 s->data_state = DATA_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02003062 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003063 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02003064}
3065
Emeric Brun1e029aa2010-09-23 18:12:53 +02003066
3067/* print a string of text buffer to <out>. The format is :
3068 * Non-printable chars \t, \n, \r and \e are * encoded in C format.
3069 * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped.
3070 * Print stopped if null char or <bsize> is reached, or if no more place in the chunk.
3071 */
3072
3073static int dump_text(struct chunk *out, const char *buf, int bsize)
3074{
3075 unsigned char c;
3076 int ptr = 0;
3077
3078 while (buf[ptr] && ptr < bsize) {
3079 c = buf[ptr];
3080 if (isprint(c) && isascii(c) && c != '\\' && c != ' ') {
3081 if (out->len > out->size - 1)
3082 break;
3083 out->str[out->len++] = c;
3084 }
3085 else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') {
3086 if (out->len > out->size - 2)
3087 break;
3088 out->str[out->len++] = '\\';
3089 switch (c) {
3090 case ' ': c = ' '; break;
3091 case '\t': c = 't'; break;
3092 case '\n': c = 'n'; break;
3093 case '\r': c = 'r'; break;
3094 case '\e': c = 'e'; break;
3095 case '\\': c = '\\'; break;
3096 }
3097 out->str[out->len++] = c;
3098 }
3099 else {
3100 if (out->len > out->size - 4)
3101 break;
3102 out->str[out->len++] = '\\';
3103 out->str[out->len++] = 'x';
3104 out->str[out->len++] = hextab[(c >> 4) & 0xF];
3105 out->str[out->len++] = hextab[c & 0xF];
3106 }
3107 ptr++;
3108 }
3109
3110 return ptr;
3111}
3112
3113/* print a buffer in hexa.
3114 * Print stopped if <bsize> is reached, or if no more place in the chunk.
3115 */
3116
3117static int dump_binary(struct chunk *out, const char *buf, int bsize)
3118{
3119 unsigned char c;
3120 int ptr = 0;
3121
3122 while (ptr < bsize) {
3123 c = buf[ptr];
3124
3125 if (out->len > out->size - 2)
3126 break;
3127 out->str[out->len++] = hextab[(c >> 4) & 0xF];
3128 out->str[out->len++] = hextab[c & 0xF];
3129
3130 ptr++;
3131 }
3132 return ptr;
3133}
3134
Willy Tarreau69f58c82010-07-12 17:55:33 +02003135/* This function is called to send output to the response buffer.
3136 * It dumps the tables states onto the output buffer <rep>.
3137 * Expects to be called with client socket shut down on input.
3138 * s->data_ctx must have been zeroed first, and the flags properly set.
3139 * It returns 0 as long as it does not complete, non-zero upon completion.
3140 */
3141int stats_dump_table_to_buffer(struct session *s, struct buffer *rep)
3142{
3143 struct chunk msg;
3144 struct ebmb_node *eb;
3145 int dt;
3146
3147 /*
3148 * We have 3 possible states in s->data_state :
3149 * - DATA_ST_INIT : the first call
3150 * - DATA_ST_INFO : the proxy pointer points to the next table to
3151 * dump, the entry pointer is NULL ;
3152 * - DATA_ST_LIST : the proxy pointer points to the current table
3153 * and the entry pointer points to the next entry to be dumped,
3154 * and the refcount on the next entry is held ;
3155 * - DATA_ST_END : nothing left to dump, the buffer may contain some
3156 * data though.
3157 */
3158
3159 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) {
3160 /* in case of abort, remove any refcount we might have set on an entry */
Willy Tarreauf6efda12010-08-03 20:34:06 +02003161 if (s->data_state == DATA_ST_LIST) {
Willy Tarreau69f58c82010-07-12 17:55:33 +02003162 s->data_ctx.table.entry->ref_cnt--;
Willy Tarreauf6efda12010-08-03 20:34:06 +02003163 stksess_kill_if_expired(&s->data_ctx.table.proxy->table, s->data_ctx.table.entry);
3164 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02003165 return 1;
3166 }
3167
3168 chunk_init(&msg, trash, sizeof(trash));
3169
3170 while (s->data_state != DATA_ST_FIN) {
3171 switch (s->data_state) {
3172 case DATA_ST_INIT:
3173 s->data_ctx.table.proxy = s->data_ctx.table.target;
3174 if (!s->data_ctx.table.proxy)
3175 s->data_ctx.table.proxy = proxy;
3176
3177 s->data_ctx.table.entry = NULL;
3178 s->data_state = DATA_ST_INFO;
3179 break;
3180
3181 case DATA_ST_INFO:
3182 if (!s->data_ctx.table.proxy ||
3183 (s->data_ctx.table.target &&
3184 s->data_ctx.table.proxy != s->data_ctx.table.target)) {
3185 s->data_state = DATA_ST_END;
3186 break;
3187 }
3188
3189 if (s->data_ctx.table.proxy->table.size) {
Emeric Brun1e029aa2010-09-23 18:12:53 +02003190 chunk_printf(&msg, "# table: %s, type: %s, size:%d, used:%d\n",
Willy Tarreau69f58c82010-07-12 17:55:33 +02003191 s->data_ctx.table.proxy->id,
Emeric Brun1e029aa2010-09-23 18:12:53 +02003192 stktable_types[s->data_ctx.table.proxy->table.type].kw,
Willy Tarreau69f58c82010-07-12 17:55:33 +02003193 s->data_ctx.table.proxy->table.size,
3194 s->data_ctx.table.proxy->table.current);
3195
3196 /* any other information should be dumped here */
3197
3198 if (s->data_ctx.table.target &&
3199 s->listener->perm.ux.level < ACCESS_LVL_OPER)
3200 chunk_printf(&msg, "# contents not dumped due to insufficient privileges\n");
3201
3202 if (buffer_feed_chunk(rep, &msg) >= 0)
3203 return 0;
3204
3205 if (s->data_ctx.table.target &&
3206 s->listener->perm.ux.level >= ACCESS_LVL_OPER) {
3207 /* dump entries only if table explicitly requested */
3208 eb = ebmb_first(&s->data_ctx.table.proxy->table.keys);
3209 if (eb) {
3210 s->data_ctx.table.entry = ebmb_entry(eb, struct stksess, key);
3211 s->data_ctx.table.entry->ref_cnt++;
3212 s->data_state = DATA_ST_LIST;
3213 break;
3214 }
3215 }
3216 }
3217 s->data_ctx.table.proxy = s->data_ctx.table.proxy->next;
3218 break;
3219
3220 case DATA_ST_LIST:
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003221 if (s->data_ctx.table.data_type >= 0) {
3222 /* we're filtering on some data contents */
3223 void *ptr;
3224 long long data;
3225
3226 dt = s->data_ctx.table.data_type;
3227 ptr = stktable_data_ptr(&s->data_ctx.table.proxy->table,
3228 s->data_ctx.table.entry,
3229 dt);
3230
3231 data = 0;
3232 switch (stktable_data_types[dt].std_type) {
3233 case STD_T_SINT:
3234 data = stktable_data_cast(ptr, std_t_sint);
3235 break;
3236 case STD_T_UINT:
3237 data = stktable_data_cast(ptr, std_t_uint);
3238 break;
3239 case STD_T_ULL:
3240 data = stktable_data_cast(ptr, std_t_ull);
3241 break;
3242 case STD_T_FRQP:
3243 data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
3244 s->data_ctx.table.proxy->table.data_arg[dt].u);
3245 break;
3246 }
3247
3248 /* skip the entry if the data does not match the test and the value */
3249 if ((data < s->data_ctx.table.value &&
3250 (s->data_ctx.table.data_op == STD_OP_EQ ||
3251 s->data_ctx.table.data_op == STD_OP_GT ||
3252 s->data_ctx.table.data_op == STD_OP_GE)) ||
3253 (data == s->data_ctx.table.value &&
3254 (s->data_ctx.table.data_op == STD_OP_NE ||
3255 s->data_ctx.table.data_op == STD_OP_GT ||
3256 s->data_ctx.table.data_op == STD_OP_LT)) ||
3257 (data > s->data_ctx.table.value &&
3258 (s->data_ctx.table.data_op == STD_OP_EQ ||
3259 s->data_ctx.table.data_op == STD_OP_LT ||
3260 s->data_ctx.table.data_op == STD_OP_LE)))
3261 goto skip_entry;
3262 }
3263
Willy Tarreau69f58c82010-07-12 17:55:33 +02003264 chunk_printf(&msg, "%p:", s->data_ctx.table.entry);
3265
3266 if (s->data_ctx.table.proxy->table.type == STKTABLE_TYPE_IP) {
3267 char addr[16];
3268 inet_ntop(AF_INET,
3269 (const void *)&s->data_ctx.table.entry->key.key,
3270 addr, sizeof(addr));
3271 chunk_printf(&msg, " key=%s", addr);
3272 }
Emeric Brun1e029aa2010-09-23 18:12:53 +02003273 else if (s->data_ctx.table.proxy->table.type == STKTABLE_TYPE_INTEGER) {
3274 chunk_printf(&msg, " key=%u", *(unsigned int *)s->data_ctx.table.entry->key.key);
3275 }
3276 else if (s->data_ctx.table.proxy->table.type == STKTABLE_TYPE_STRING) {
3277 chunk_printf(&msg, " key=");
3278 dump_text(&msg, (const char *)s->data_ctx.table.entry->key.key, s->data_ctx.table.proxy->table.key_size);
3279 }
3280 else {
3281 chunk_printf(&msg, " key=");
3282 dump_binary(&msg, (const char *)s->data_ctx.table.entry->key.key, s->data_ctx.table.proxy->table.key_size);
3283 }
Willy Tarreau69f58c82010-07-12 17:55:33 +02003284
3285 chunk_printf(&msg, " use=%d exp=%d",
3286 s->data_ctx.table.entry->ref_cnt - 1,
3287 tick_remain(now_ms, s->data_ctx.table.entry->expire));
3288
3289 for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) {
3290 void *ptr;
3291
3292 if (s->data_ctx.table.proxy->table.data_ofs[dt] == 0)
3293 continue;
3294 if (stktable_data_types[dt].arg_type == ARG_T_DELAY)
3295 chunk_printf(&msg, " %s(%d)=",
3296 stktable_data_types[dt].name,
3297 s->data_ctx.table.proxy->table.data_arg[dt].u);
3298 else
3299 chunk_printf(&msg, " %s=", stktable_data_types[dt].name);
3300
3301 ptr = stktable_data_ptr(&s->data_ctx.table.proxy->table,
3302 s->data_ctx.table.entry,
3303 dt);
Willy Tarreau3b9c6e02010-07-18 08:04:30 +02003304 switch (stktable_data_types[dt].std_type) {
3305 case STD_T_SINT:
3306 chunk_printf(&msg, "%d", stktable_data_cast(ptr, std_t_sint));
Willy Tarreau69f58c82010-07-12 17:55:33 +02003307 break;
Willy Tarreau3b9c6e02010-07-18 08:04:30 +02003308 case STD_T_UINT:
3309 chunk_printf(&msg, "%u", stktable_data_cast(ptr, std_t_uint));
3310 break;
3311 case STD_T_ULL:
3312 chunk_printf(&msg, "%lld", stktable_data_cast(ptr, std_t_ull));
3313 break;
3314 case STD_T_FRQP:
Willy Tarreau69f58c82010-07-12 17:55:33 +02003315 chunk_printf(&msg, "%d",
Willy Tarreau3b9c6e02010-07-18 08:04:30 +02003316 read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
Willy Tarreau69f58c82010-07-12 17:55:33 +02003317 s->data_ctx.table.proxy->table.data_arg[dt].u));
3318 break;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003319 }
3320 }
3321 chunk_printf(&msg, "\n");
3322
3323 if (buffer_feed_chunk(rep, &msg) >= 0)
3324 return 0;
3325
Willy Tarreau4f3f01f2010-07-18 11:46:20 +02003326 skip_entry:
Willy Tarreau69f58c82010-07-12 17:55:33 +02003327 s->data_ctx.table.entry->ref_cnt--;
3328
3329 eb = ebmb_next(&s->data_ctx.table.entry->key);
3330 if (eb) {
Willy Tarreauf6efda12010-08-03 20:34:06 +02003331 struct stksess *old = s->data_ctx.table.entry;
Willy Tarreau69f58c82010-07-12 17:55:33 +02003332 s->data_ctx.table.entry = ebmb_entry(eb, struct stksess, key);
Willy Tarreauf6efda12010-08-03 20:34:06 +02003333 stksess_kill_if_expired(&s->data_ctx.table.proxy->table, old);
Willy Tarreau69f58c82010-07-12 17:55:33 +02003334 s->data_ctx.table.entry->ref_cnt++;
3335 break;
3336 }
3337
Willy Tarreauf6efda12010-08-03 20:34:06 +02003338 stksess_kill_if_expired(&s->data_ctx.table.proxy->table, s->data_ctx.table.entry);
Willy Tarreau69f58c82010-07-12 17:55:33 +02003339 s->data_ctx.table.proxy = s->data_ctx.table.proxy->next;
3340 s->data_state = DATA_ST_INFO;
3341 break;
3342
3343 case DATA_ST_END:
3344 s->data_state = DATA_ST_FIN;
3345 break;
3346 }
3347 }
3348 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003349}
3350
Willy Tarreaud426a182010-03-05 14:58:26 +01003351/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
Willy Tarreau74808cb2009-03-04 15:53:18 +01003352 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
3353 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
3354 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
3355 * lines are respected within the limit of 70 output chars. Lines that are
3356 * continuation of a previous truncated line begin with "+" instead of " "
3357 * after the offset. The new pointer is returned.
3358 */
Willy Tarreaud426a182010-03-05 14:58:26 +01003359static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
3360 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01003361{
3362 int end;
3363 unsigned char c;
3364
3365 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003366 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01003367 return ptr;
3368
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003369 chunk_printf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01003370
Willy Tarreaud426a182010-03-05 14:58:26 +01003371 while (ptr < len && ptr < bsize) {
3372 c = buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01003373 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003374 if (out->len > end - 2)
3375 break;
3376 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01003377 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003378 if (out->len > end - 3)
3379 break;
3380 out->str[out->len++] = '\\';
3381 switch (c) {
3382 case '\t': c = 't'; break;
3383 case '\n': c = 'n'; break;
3384 case '\r': c = 'r'; break;
3385 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01003386 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003387 }
3388 out->str[out->len++] = c;
3389 } else {
3390 if (out->len > end - 5)
3391 break;
3392 out->str[out->len++] = '\\';
3393 out->str[out->len++] = 'x';
3394 out->str[out->len++] = hextab[(c >> 4) & 0xF];
3395 out->str[out->len++] = hextab[c & 0xF];
3396 }
Willy Tarreaud426a182010-03-05 14:58:26 +01003397 if (buf[ptr++] == '\n') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003398 /* we had a line break, let's return now */
3399 out->str[out->len++] = '\n';
3400 *line = ptr;
3401 return ptr;
3402 }
3403 }
3404 /* we have an incomplete line, we return it as-is */
3405 out->str[out->len++] = '\n';
3406 return ptr;
3407}
3408
3409/* This function is called to send output to the response buffer.
3410 * It dumps the errors logged in proxies onto the output buffer <rep>.
3411 * Expects to be called with client socket shut down on input.
3412 * s->data_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau61b34732009-10-03 23:49:35 +02003413 * It returns 0 as long as it does not complete, non-zero upon completion.
Willy Tarreau74808cb2009-03-04 15:53:18 +01003414 */
Willy Tarreau61b34732009-10-03 23:49:35 +02003415int stats_dump_errors_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau74808cb2009-03-04 15:53:18 +01003416{
3417 extern const char *monthname[12];
3418 struct chunk msg;
3419
Willy Tarreau61b34732009-10-03 23:49:35 +02003420 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW)))
3421 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003422
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003423 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau74808cb2009-03-04 15:53:18 +01003424
3425 if (!s->data_ctx.errors.px) {
3426 /* the function had not been called yet, let's prepare the
3427 * buffer for a response.
3428 */
Willy Tarreau74808cb2009-03-04 15:53:18 +01003429 s->data_ctx.errors.px = proxy;
3430 s->data_ctx.errors.buf = 0;
3431 s->data_ctx.errors.bol = 0;
3432 s->data_ctx.errors.ptr = -1;
3433 }
3434
3435 /* we have two inner loops here, one for the proxy, the other one for
3436 * the buffer.
3437 */
3438 while (s->data_ctx.errors.px) {
3439 struct error_snapshot *es;
3440
3441 if (s->data_ctx.errors.buf == 0)
3442 es = &s->data_ctx.errors.px->invalid_req;
3443 else
3444 es = &s->data_ctx.errors.px->invalid_rep;
3445
3446 if (!es->when.tv_sec)
3447 goto next;
3448
3449 if (s->data_ctx.errors.iid >= 0 &&
3450 s->data_ctx.errors.px->uuid != s->data_ctx.errors.iid &&
3451 es->oe->uuid != s->data_ctx.errors.iid)
3452 goto next;
3453
3454 if (s->data_ctx.errors.ptr < 0) {
3455 /* just print headers now */
3456
3457 char pn[INET6_ADDRSTRLEN];
3458 struct tm tm;
3459
3460 get_localtime(es->when.tv_sec, &tm);
Willy Tarreau8811f8e2010-03-05 17:42:58 +01003461 chunk_printf(&msg, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01003462 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02003463 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01003464
3465
3466 if (es->src.ss_family == AF_INET)
3467 inet_ntop(AF_INET,
3468 (const void *)&((struct sockaddr_in *)&es->src)->sin_addr,
3469 pn, sizeof(pn));
3470 else
3471 inet_ntop(AF_INET6,
3472 (const void *)&((struct sockaddr_in6 *)(&es->src))->sin6_addr,
3473 pn, sizeof(pn));
3474
3475 switch (s->data_ctx.errors.buf) {
3476 case 0:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003477 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003478 " frontend %s (#%d): invalid request\n"
3479 " src %s, session #%d, backend %s (#%d), server %s (#%d)\n"
Willy Tarreau8811f8e2010-03-05 17:42:58 +01003480 " request length %d bytes, error at position %d:\n \n",
Willy Tarreau74808cb2009-03-04 15:53:18 +01003481 s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid,
Willy Tarreau3fd6cec2010-03-25 06:45:07 +01003482 pn, es->sid, (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
3483 (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003484 es->srv ? es->srv->id : "<NONE>",
3485 es->srv ? es->srv->puid : -1,
3486 es->len, es->pos);
3487 break;
3488 case 1:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003489 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003490 " backend %s (#%d) : invalid response\n"
3491 " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n"
Willy Tarreau8811f8e2010-03-05 17:42:58 +01003492 " response length %d bytes, error at position %d:\n \n",
Willy Tarreau74808cb2009-03-04 15:53:18 +01003493 s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid,
3494 pn, es->sid, es->oe->id, es->oe->uuid,
3495 es->srv ? es->srv->id : "<NONE>",
3496 es->srv ? es->srv->puid : -1,
3497 es->len, es->pos);
3498 break;
3499 }
3500
Willy Tarreau61b34732009-10-03 23:49:35 +02003501 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003502 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02003503 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003504 }
3505 s->data_ctx.errors.ptr = 0;
3506 s->data_ctx.errors.sid = es->sid;
3507 }
3508
3509 if (s->data_ctx.errors.sid != es->sid) {
3510 /* the snapshot changed while we were dumping it */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02003511 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01003512 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreau61b34732009-10-03 23:49:35 +02003513 if (buffer_feed_chunk(rep, &msg) >= 0)
3514 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003515 goto next;
3516 }
3517
3518 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau61b34732009-10-03 23:49:35 +02003519 while (s->data_ctx.errors.ptr < es->len && s->data_ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003520 int newptr;
3521 int newline;
3522
3523 newline = s->data_ctx.errors.bol;
Willy Tarreaud426a182010-03-05 14:58:26 +01003524 newptr = dump_text_line(&msg, es->buf, sizeof(es->buf), es->len, &newline, s->data_ctx.errors.ptr);
Willy Tarreau74808cb2009-03-04 15:53:18 +01003525 if (newptr == s->data_ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02003526 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003527
Willy Tarreau61b34732009-10-03 23:49:35 +02003528 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01003529 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02003530 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003531 }
3532 s->data_ctx.errors.ptr = newptr;
3533 s->data_ctx.errors.bol = newline;
3534 };
3535 next:
3536 s->data_ctx.errors.bol = 0;
3537 s->data_ctx.errors.ptr = -1;
3538 s->data_ctx.errors.buf++;
3539 if (s->data_ctx.errors.buf > 1) {
3540 s->data_ctx.errors.buf = 0;
3541 s->data_ctx.errors.px = s->data_ctx.errors.px->next;
3542 }
3543 }
3544
3545 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02003546 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01003547}
3548
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01003549
Willy Tarreau10522fd2008-07-09 20:12:41 +02003550static struct cfg_kw_list cfg_kws = {{ },{
3551 { CFG_GLOBAL, "stats", stats_parse_global },
3552 { 0, NULL, NULL },
3553}};
3554
3555__attribute__((constructor))
3556static void __dumpstats_module_init(void)
3557{
3558 cfg_register_keywords(&cfg_kws);
3559}
3560
Willy Tarreau91861262007-10-17 17:06:05 +02003561/*
3562 * Local variables:
3563 * c-indent-level: 8
3564 * c-basic-offset: 8
3565 * End:
3566 */