blob: 86ce23e86e6b4f2f86c31a7a3c09da535f60e1ef [file] [log] [blame]
Willy Tarreau91861262007-10-17 17:06:05 +02001/*
2 * Functions dedicated to statistics output
3 *
Willy Tarreaua206fa92009-01-25 14:02:00 +01004 * Copyright 2000-2009 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 Tarreaua206fa92009-01-25 14:02:00 +010047#include <proto/pipe.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020048#include <proto/proto_uxst.h>
Willy Tarreau89a63132009-08-16 17:41:45 +020049#include <proto/proxy.h>
Willy Tarreau91861262007-10-17 17:06:05 +020050#include <proto/session.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020051#include <proto/server.h>
Willy Tarreaudded32d2008-11-30 19:48:07 +010052#include <proto/stream_interface.h>
Willy Tarreau4726f532009-03-07 17:25:21 +010053#include <proto/task.h>
Willy Tarreau91861262007-10-17 17:06:05 +020054
Willy Tarreau5ca791d2009-08-16 19:06:42 +020055const char stats_sock_usage_msg[] =
56 "Unknown command. Please enter one of the following commands only :\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020057 " help : this message\n"
58 " prompt : toggle interactive mode with prompt\n"
59 " quit : disconnect\n"
Willy Tarreau5ca791d2009-08-16 19:06:42 +020060 " show info : report information about the running process\n"
61 " show stat : report counters for each proxy and server\n"
62 " show errors : report last request and response errors for each proxy\n"
63 " show sess : report the list of current sessions\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020064 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +020065
66const struct chunk stats_sock_usage = {
67 .str = (char *)&stats_sock_usage_msg,
68 .len = sizeof(stats_sock_usage_msg)-1
69};
70
Willy Tarreaufbee7132007-10-18 13:53:22 +020071/* This function parses a "stats" statement in the "global" section. It returns
72 * -1 if there is any error, otherwise zero. If it returns -1, it may write an
73 * error message into ther <err> buffer, for at most <errlen> bytes, trailing
74 * zero included. The trailing '\n' must not be written. The function must be
75 * called with <args> pointing to the first word after "stats".
76 */
Willy Tarreau10522fd2008-07-09 20:12:41 +020077static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
78 struct proxy *defpx, char *err, int errlen)
Willy Tarreaufbee7132007-10-18 13:53:22 +020079{
Willy Tarreau10522fd2008-07-09 20:12:41 +020080 args++;
Willy Tarreaufbee7132007-10-18 13:53:22 +020081 if (!strcmp(args[0], "socket")) {
82 struct sockaddr_un su;
83 int cur_arg;
84
85 if (*args[1] == 0) {
86 snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket");
87 return -1;
88 }
89
90 if (global.stats_sock.state != LI_NEW) {
91 snprintf(err, errlen, "'stats socket' already specified in global section");
92 return -1;
93 }
94
95 su.sun_family = AF_UNIX;
96 strncpy(su.sun_path, args[1], sizeof(su.sun_path));
97 su.sun_path[sizeof(su.sun_path) - 1] = 0;
98 memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit
99
Willy Tarreau89a63132009-08-16 17:41:45 +0200100 if (!global.stats_fe) {
101 if ((global.stats_fe = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) {
102 snprintf(err, errlen, "out of memory");
103 return -1;
104 }
105
106 LIST_INIT(&global.stats_fe->pendconns);
107 LIST_INIT(&global.stats_fe->acl);
108 LIST_INIT(&global.stats_fe->block_cond);
109 LIST_INIT(&global.stats_fe->redirect_rules);
110 LIST_INIT(&global.stats_fe->mon_fail_cond);
111 LIST_INIT(&global.stats_fe->switching_rules);
112 LIST_INIT(&global.stats_fe->tcp_req.inspect_rules);
113
114 /* Timeouts are defined as -1, so we cannot use the zeroed area
115 * as a default value.
116 */
117 proxy_reset_timeouts(global.stats_fe);
118
119 global.stats_fe->last_change = now.tv_sec;
120 global.stats_fe->id = strdup("GLOBAL");
121 global.stats_fe->cap = PR_CAP_FE;
122 }
123
Willy Tarreaufbee7132007-10-18 13:53:22 +0200124 global.stats_sock.state = LI_INIT;
Willy Tarreau6fb42e02007-10-28 17:02:33 +0100125 global.stats_sock.options = LI_O_NONE;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200126 global.stats_sock.accept = uxst_event_accept;
Willy Tarreau104eb362009-08-16 18:51:29 +0200127 global.stats_sock.handler = process_session;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200128 global.stats_sock.analysers = 0;
Willy Tarreau2c9f5b12009-08-16 19:12:36 +0200129 global.stats_sock.nice = -64; /* we want to boost priority for local stats */
Willy Tarreau89a63132009-08-16 17:41:45 +0200130 global.stats_sock.private = global.stats_fe; /* must point to the frontend */
131
132 global.stats_fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
133 global.stats_sock.timeout = &global.stats_fe->timeout.client;
134
135 global.stats_sock.next = global.stats_fe->listen;
136 global.stats_fe->listen = &global.stats_sock;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200137
138 cur_arg = 2;
139 while (*args[cur_arg]) {
140 if (!strcmp(args[cur_arg], "uid")) {
141 global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]);
142 cur_arg += 2;
143 }
144 else if (!strcmp(args[cur_arg], "gid")) {
145 global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]);
146 cur_arg += 2;
147 }
148 else if (!strcmp(args[cur_arg], "mode")) {
149 global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
150 cur_arg += 2;
151 }
152 else if (!strcmp(args[cur_arg], "user")) {
153 struct passwd *user;
154 user = getpwnam(args[cur_arg + 1]);
155 if (!user) {
156 snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')",
157 args[cur_arg + 1]);
158 return -1;
159 }
160 global.stats_sock.perm.ux.uid = user->pw_uid;
161 cur_arg += 2;
162 }
163 else if (!strcmp(args[cur_arg], "group")) {
164 struct group *group;
165 group = getgrnam(args[cur_arg + 1]);
166 if (!group) {
167 snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')",
168 args[cur_arg + 1]);
169 return -1;
170 }
171 global.stats_sock.perm.ux.gid = group->gr_gid;
172 cur_arg += 2;
173 }
174 else {
175 snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', and 'mode'");
176 return -1;
177 }
178 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100179
Willy Tarreaufbee7132007-10-18 13:53:22 +0200180 uxst_add_listener(&global.stats_sock);
181 global.maxsock++;
182 }
183 else if (!strcmp(args[0], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100184 unsigned timeout;
185 const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS);
186
187 if (res) {
188 snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res);
189 return -1;
190 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200191
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100192 if (!timeout) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200193 snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'");
194 return -1;
195 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200196 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200197 }
198 else if (!strcmp(args[0], "maxconn")) {
199 int maxconn = atol(args[1]);
200
201 if (maxconn <= 0) {
202 snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'");
203 return -1;
204 }
205 global.maxsock -= global.stats_sock.maxconn;
206 global.stats_sock.maxconn = maxconn;
207 global.maxsock += global.stats_sock.maxconn;
208 }
209 else {
210 snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section");
211 return -1;
212 }
213 return 0;
214}
215
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200216int print_csv_header(struct chunk *msg)
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100217{
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200218 return chunk_printf(msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100219 "# pxname,svname,"
220 "qcur,qmax,"
221 "scur,smax,slim,stot,"
222 "bin,bout,"
223 "dreq,dresp,"
224 "ereq,econ,eresp,"
225 "wretr,wredis,"
226 "status,weight,act,bck,"
227 "chkfail,chkdown,lastchg,downtime,qlimit,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +0200228 "pid,iid,sid,throttle,lbtot,tracked,type,"
229 "rate,rate_lim,rate_max,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200230 "check_status,check_code,check_duration,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100231 "\n");
232}
233
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200234/* Processes the stats interpreter on the statistics socket. This function is
235 * called from an applet running in a stream interface. Right now we still
236 * support older functions which used to emulate servers and to set
237 * STATS_ST_CLOSE upon completion, but we also support a new interactive mode.
238 * The function returns 1 if the request was understood, otherwise zero.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200239 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200240int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200241{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200242 struct session *s = si->private;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200243 char *args[MAX_STATS_ARGS + 1];
244 int arg;
245
246 while (isspace((unsigned char)*line))
247 line++;
248
249 arg = 0;
250 args[arg] = line;
251
252 while (*line && arg < MAX_STATS_ARGS) {
253 if (isspace((unsigned char)*line)) {
254 *line++ = '\0';
255
256 while (isspace((unsigned char)*line))
257 line++;
258
259 args[++arg] = line;
260 continue;
261 }
262
263 line++;
264 }
265
266 while (++arg <= MAX_STATS_ARGS)
267 args[arg] = line;
268
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200269 si->st0 = 0;
270 s->data_ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200271 if (strcmp(args[0], "show") == 0) {
272 if (strcmp(args[1], "stat") == 0) {
273 if (*args[2] && *args[3] && *args[4]) {
274 s->data_ctx.stats.flags |= STAT_BOUND;
275 s->data_ctx.stats.iid = atoi(args[2]);
276 s->data_ctx.stats.type = atoi(args[3]);
277 s->data_ctx.stats.sid = atoi(args[4]);
278 }
279
280 s->data_ctx.stats.flags |= STAT_SHOW_STAT;
281 s->data_ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200282 s->data_state = DATA_ST_INIT;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200283 s->ana_state = STATS_ST_REP;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200284 si->st0 = 3; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200285 }
286 else if (strcmp(args[1], "info") == 0) {
287 s->data_ctx.stats.flags |= STAT_SHOW_INFO;
288 s->data_ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200289 s->data_state = DATA_ST_INIT;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200290 s->ana_state = STATS_ST_REP;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200291 si->st0 = 3; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200292 }
293 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200294 s->data_state = DATA_ST_INIT;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200295 s->ana_state = STATS_ST_REP;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200296 si->st0 = 4; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200297 }
298 else if (strcmp(args[1], "errors") == 0) {
299 if (*args[2])
300 s->data_ctx.errors.iid = atoi(args[2]);
301 else
302 s->data_ctx.errors.iid = -1;
303 s->data_ctx.errors.px = NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200304 s->data_state = DATA_ST_INIT;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200305 s->ana_state = STATS_ST_REP;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200306 si->st0 = 5; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200307 }
308 else { /* neither "stat" nor "info" nor "sess" */
309 return 0;
310 }
311 }
312 else { /* not "show" */
313 return 0;
314 }
315 return 1;
316}
317
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200318/* This I/O handler runs as an applet embedded in a stream interface. It is
319 * used to processes I/O from/to the stats unix socket. Right now we still
320 * support older functions which used to emulate servers and to set
321 * STATS_ST_CLOSE upon completion, but we also support a new interactive mode.
322 * The system relies on a request/response flip-flop state machine. We read
323 * a request, then we process it and send the response. Then we can read again.
324 * This could be enhanced a lot but we're still bound to support older output
325 * functions which were designed to work as hijackers.
326 * At the moment, we use si->st0 as the output type, and si->st1 to indicate
327 * whether we're in prompt mode or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200328 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200329void stats_io_handler(struct stream_interface *si)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200330{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200331 struct session *s = si->private;
332 struct buffer *req = si->ob;
333 struct buffer *res = si->ib;
334 int reql;
335 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200336
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200337 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
338 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200339
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200340 while (1) {
341 if (s->ana_state == STATS_ST_INIT) {
342 /* Stats output not initialized yet */
343 memset(&s->data_ctx.stats, 0, sizeof(s->data_ctx.stats));
344 s->data_source = DATA_SRC_STATS;
345 s->ana_state = STATS_ST_REQ;
346 }
347 else if (s->ana_state == STATS_ST_REQ) {
348 reql = buffer_si_peekline(si->ob, trash, sizeof(trash));
349 if (reql <= 0) { /* closed or EOL not found */
350 if (reql == 0)
351 break;
352 s->ana_state = STATS_ST_CLOSE;
353 continue;
354 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200355
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200356 /* seek for a possible semi-colon. If we find one, we
357 * replace it with an LF and skip only this part.
358 */
359 for (len = 0; len < reql; len++)
360 if (trash[len] == ';') {
361 trash[len] = '\n';
362 reql = len + 1;
363 break;
364 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200365
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200366 /* ensure we have a full line */
367 if (trash[reql-1] != '\n') {
368 s->ana_state = STATS_ST_CLOSE;
369 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200370 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200371
372 len = reql - 1;
373 trash[len] = '\0';
374
375 si->st0 = 1; // default to prompt
376 if (len) {
377 if (strcmp(trash, "quit") == 0) {
378 s->ana_state = STATS_ST_CLOSE;
379 continue;
380 }
381 else if (strcmp(trash, "prompt") == 0)
382 si->st1 = !si->st1;
383 else if (strcmp(trash, "help") == 0 ||
384 !stats_sock_parse_request(si, trash))
385 si->st0 = 2; // help
386 }
387 else if (!si->st1) {
388 /* if prompt is disabled, print help on empty lines,
389 * so that the user at least knows how to enable
390 * prompt and find help.
391 */
392 si->st0 = 2;
393 }
394
395 /* re-adjust req buffer */
396 buffer_skip(si->ob, reql);
397
398 s->ana_state = STATS_ST_REP;
399 req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200400 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200401 else if (s->ana_state == STATS_ST_REP) {
402 if (res->flags & (BF_SHUTR_NOW|BF_SHUTR)) {
403 s->ana_state = STATS_ST_CLOSE;
404 continue;
405 }
406
407 switch (si->st0) {
408 case 2: /* help */
409 if (buffer_feed(si->ib, stats_sock_usage.str, stats_sock_usage.len) < 0)
410 /* message sent or too large for buffer (!) */
411 si->st0 = 1; // send prompt
412 break;
413 case 3: /* stats/info dump, should be split later ? */
414 stats_dump_raw_to_buffer(s, res);
415 si->ib->flags |= BF_READ_PARTIAL; /* remove this once we use buffer_feed */
416 if (s->ana_state == STATS_ST_CLOSE)
417 si->st0 = 1; // end of command, send prompt
418 break;
419 case 4: /* sessions dump */
420 stats_dump_sess_to_buffer(s, res);
421 si->ib->flags |= BF_READ_PARTIAL; /* remove this once we use buffer_feed */
422 if (s->ana_state == STATS_ST_CLOSE)
423 si->st0 = 1; // end of command, send prompt
424 break;
425 case 5: /* errors dump */
426 stats_dump_errors_to_buffer(s, res);
427 si->ib->flags |= BF_READ_PARTIAL; /* remove this once we use buffer_feed */
428 if (s->ana_state == STATS_ST_CLOSE)
429 si->st0 = 1; // end of command, send prompt
430 break;
431 default: /* abnormal state or lack of space for prompt */
432 si->st0 = 1; // return to prompt
433 break;
434 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200435
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200436 if (si->st0 == 1) { /* post-command prompt (LF or LF + '> ') */
437 if (!si->st1) { /* non-interactive mode */
438 if (buffer_feed(si->ib, "\n", 1) < 0)
439 si->st0 = 0; // end of output
440 }
441 else { /* interactive mode */
442 if (buffer_feed(si->ib, "\n> ", 3) < 0)
443 si->st0 = 0; // end of output
444 }
445 }
446
447 /* If the output functions are still there, it means
448 * they require more room.
449 */
450 if (si->st0 > 0) {
451 s->ana_state = STATS_ST_REP; /* some old applets still force CLOSE */
452 si->flags |= SI_FL_WAIT_ROOM;
453 break;
454 }
455
456 /* Now we close the output if one of the writers did so,
457 * or if we're not in interactive mode and the request
458 * buffer is empty. This still allows pipelined requests
459 * to be sent in non-interactive mode.
460 */
461 if ((res->flags & (BF_SHUTW|BF_SHUTW_NOW)) || (!si->st1 && !req->send_max)) {
462 s->ana_state = STATS_ST_CLOSE;
463 continue;
464 }
465
466 /* switch state back to ST_REQ to read next requests */
467 s->ana_state = STATS_ST_REQ;
468 }
469 else if (s->ana_state == STATS_ST_CLOSE) {
470 /* let's close for real now. Note that we may as well
471 * call shutw+shutr, but this is enough since the shut
472 * conditions below will complete.
473 */
474 buffer_shutw(si->ob);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200475 s->ana_state = 0;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200476 break;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200477 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200478 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200479
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200480 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST) && (s->ana_state != STATS_ST_REQ)) {
481 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
482 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
483 /* Other size has closed, let's abort if we have no more processing to do
484 * and nothing more to consume. This is comparable to a broken pipe, so
485 * we forward the close to the request side so that it flows upstream to
486 * the client.
487 */
488 si->shutw(si);
489 }
490
491 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && (s->ana_state != STATS_ST_REP)) {
492 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
493 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
494 /* We have no more processing to do, and nothing more to send, and
495 * the client side has closed. So we'll forward this state downstream
496 * on the response buffer.
497 */
498 si->shutr(si);
499 res->flags |= BF_READ_NULL;
500 }
501
502 /* update all other flags and resync with the other side */
503 si->update(si);
504
505 /* we don't want to expire timeouts while we're processing requests */
506 si->ib->rex = TICK_ETERNITY;
507 si->ob->wex = TICK_ETERNITY;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200508
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200509 out:
510 DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rql=%d, rqs=%d, rl=%d, rs=%d\n",
511 __FUNCTION__, __LINE__,
512 si->state, req->flags, res->flags, req->l, req->send_max, res->l, res->send_max);
513
514 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
515 /* check that we have released everything then unregister */
516 stream_int_unregister_handler(si);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200517 s->ana_state = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200518 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200519}
520
Willy Tarreau91861262007-10-17 17:06:05 +0200521/*
522 * Produces statistics data for the session <s>. Expects to be called with
Willy Tarreau1ae3a052008-08-16 10:56:30 +0200523 * client socket shut down on input. It *may* make use of informations from
524 * <uri>. s->data_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau3e76e722007-10-17 18:57:38 +0200525 * It returns 0 if it had to stop writing data and an I/O is needed, 1 if the
526 * dump is finished and the session must be closed, or -1 in case of any error.
Willy Tarreau0a464892008-12-07 18:30:00 +0100527 * It automatically clears the HIJACK bit from the response buffer.
Willy Tarreau3e76e722007-10-17 18:57:38 +0200528 */
Willy Tarreau0a464892008-12-07 18:30:00 +0100529int stats_dump_raw(struct session *s, struct buffer *rep, struct uri_auth *uri)
Willy Tarreau3e76e722007-10-17 18:57:38 +0200530{
Willy Tarreau3e76e722007-10-17 18:57:38 +0200531 struct proxy *px;
532 struct chunk msg;
Willy Tarreaua8efd362008-01-03 10:19:15 +0100533 unsigned int up;
Willy Tarreau3e76e722007-10-17 18:57:38 +0200534
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200535 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3e76e722007-10-17 18:57:38 +0200536
537 switch (s->data_state) {
538 case DATA_ST_INIT:
539 /* the function had not been called yet, let's prepare the
540 * buffer for a response.
541 */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200542 s->data_state = DATA_ST_HEAD;
543 /* fall through */
544
545 case DATA_ST_HEAD:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100546 if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200547 print_csv_header(&msg);
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +0200548 if (buffer_write_chunk(rep, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100549 return 0;
550 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200551
552 s->data_state = DATA_ST_INFO;
553 /* fall through */
554
555 case DATA_ST_INFO:
Willy Tarreaua8efd362008-01-03 10:19:15 +0100556 up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100557 if (s->data_ctx.stats.flags & STAT_SHOW_INFO) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200558 chunk_printf(&msg,
Willy Tarreaua8efd362008-01-03 10:19:15 +0100559 "Name: " PRODUCT_NAME "\n"
560 "Version: " HAPROXY_VERSION "\n"
561 "Release_date: " HAPROXY_DATE "\n"
562 "Nbproc: %d\n"
563 "Process_num: %d\n"
564 "Pid: %d\n"
565 "Uptime: %dd %dh%02dm%02ds\n"
566 "Uptime_sec: %d\n"
567 "Memmax_MB: %d\n"
568 "Ulimit-n: %d\n"
569 "Maxsock: %d\n"
570 "Maxconn: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +0100571 "Maxpipes: %d\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +0100572 "CurrConns: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +0100573 "PipesUsed: %d\n"
574 "PipesFree: %d\n"
Willy Tarreauc7bdf092009-03-21 18:33:52 +0100575 "Tasks: %d\n"
576 "Run_queue: %d\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +0100577 "",
578 global.nbproc,
579 relative_pid,
580 pid,
581 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
582 up,
583 global.rlimit_memmax,
584 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +0100585 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +0100586 actconn, pipes_used, pipes_free,
587 nb_tasks_cur, run_queue_cur
Willy Tarreaua8efd362008-01-03 10:19:15 +0100588 );
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +0200589 if (buffer_write_chunk(rep, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100590 return 0;
591 }
592
Willy Tarreau3e76e722007-10-17 18:57:38 +0200593 s->data_ctx.stats.px = proxy;
594 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +0100595
596 s->data_ctx.stats.sv = NULL;
597 s->data_ctx.stats.sv_st = 0;
598
Willy Tarreau3e76e722007-10-17 18:57:38 +0200599 s->data_state = DATA_ST_LIST;
600 /* fall through */
601
602 case DATA_ST_LIST:
603 /* dump proxies */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100604 if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
Willy Tarreaua8efd362008-01-03 10:19:15 +0100605 while (s->data_ctx.stats.px) {
606 px = s->data_ctx.stats.px;
607 /* skip the disabled proxies and non-networked ones */
608 if (px->state != PR_STSTOPPED &&
609 (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100610 if (stats_dump_proxy(s, px, NULL) == 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100611 return 0;
Willy Tarreau3e76e722007-10-17 18:57:38 +0200612
Willy Tarreaua8efd362008-01-03 10:19:15 +0100613 s->data_ctx.stats.px = px->next;
614 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
615 }
616 /* here, we just have reached the last proxy */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200617 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200618
619 s->data_state = DATA_ST_END;
620 /* fall through */
621
622 case DATA_ST_END:
623 s->data_state = DATA_ST_FIN;
Willy Tarreau0a464892008-12-07 18:30:00 +0100624 /* fall through */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200625
626 case DATA_ST_FIN:
Willy Tarreau0a464892008-12-07 18:30:00 +0100627 buffer_stop_hijack(rep);
Willy Tarreau3e76e722007-10-17 18:57:38 +0200628 return 1;
629
630 default:
631 /* unknown state ! */
Willy Tarreau0a464892008-12-07 18:30:00 +0100632 buffer_stop_hijack(rep);
Willy Tarreau3e76e722007-10-17 18:57:38 +0200633 return -1;
634 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100635}
636
637
638/* This function is called to send output to the response buffer. It simply
639 * calls stats_dump_raw(), and releases the buffer's hijack bit when the dump
Willy Tarreau01bf8672008-12-07 18:03:29 +0100640 * is finished.
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100641 */
Willy Tarreau0a464892008-12-07 18:30:00 +0100642void stats_dump_raw_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100643{
644 if (s->ana_state != STATS_ST_REP)
Willy Tarreau01bf8672008-12-07 18:03:29 +0100645 return;
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100646
Willy Tarreau0a464892008-12-07 18:30:00 +0100647 if (stats_dump_raw(s, rep, NULL) != 0)
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100648 s->ana_state = STATS_ST_CLOSE;
Willy Tarreau01bf8672008-12-07 18:03:29 +0100649 return;
Willy Tarreau3e76e722007-10-17 18:57:38 +0200650}
651
652
653/*
654 * Produces statistics data for the session <s>. Expects to be called with
Willy Tarreau1ae3a052008-08-16 10:56:30 +0200655 * client socket shut down on input. It stops by itself by unsetting the
Willy Tarreau72b179a2008-08-28 16:01:32 +0200656 * BF_HIJACK flag from the buffer, which it uses to keep on being called
Willy Tarreau1ae3a052008-08-16 10:56:30 +0200657 * when there is free space in the buffer, of simply by letting an empty buffer
658 * upon return.s->data_ctx must have been zeroed before the first call, and the
659 * flags set. It returns 0 if it had to stop writing data and an I/O is needed,
660 * 1 if the dump is finished and the session must be closed, or -1 in case of
661 * any error.
Willy Tarreau91861262007-10-17 17:06:05 +0200662 */
Willy Tarreau0a464892008-12-07 18:30:00 +0100663int stats_dump_http(struct session *s, struct buffer *rep, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +0200664{
Willy Tarreau91861262007-10-17 17:06:05 +0200665 struct proxy *px;
666 struct chunk msg;
667 unsigned int up;
668
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200669 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +0200670
671 switch (s->data_state) {
672 case DATA_ST_INIT:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200673 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +0200674 "HTTP/1.0 200 OK\r\n"
675 "Cache-Control: no-cache\r\n"
676 "Connection: close\r\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200677 "Content-Type: %s\r\n",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100678 (s->data_ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html");
Willy Tarreau91861262007-10-17 17:06:05 +0200679
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100680 if (uri->refresh > 0 && !(s->data_ctx.stats.flags & STAT_NO_REFRESH))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200681 chunk_printf(&msg, "Refresh: %d\r\n",
Willy Tarreau91861262007-10-17 17:06:05 +0200682 uri->refresh);
683
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200684 chunk_printf(&msg, "\r\n");
Willy Tarreau91861262007-10-17 17:06:05 +0200685
686 s->txn.status = 200;
Willy Tarreau56a560a2009-09-22 19:27:35 +0200687 if (buffer_write_chunk(rep, &msg) >= 0)
688 return 0;
689
Willy Tarreau91861262007-10-17 17:06:05 +0200690 msg.len = 0;
691
692 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
693 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
694 if (!(s->flags & SN_FINST_MASK))
695 s->flags |= SN_FINST_R;
696
697 if (s->txn.meth == HTTP_METH_HEAD) {
698 /* that's all we return in case of HEAD request */
699 s->data_state = DATA_ST_FIN;
Willy Tarreau72b179a2008-08-28 16:01:32 +0200700 buffer_stop_hijack(rep);
Willy Tarreau91861262007-10-17 17:06:05 +0200701 return 1;
702 }
703
704 s->data_state = DATA_ST_HEAD; /* let's start producing data */
705 /* fall through */
706
707 case DATA_ST_HEAD:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100708 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau55bb8452007-10-17 18:44:57 +0200709 /* WARNING! This must fit in the first buffer !!! */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200710 chunk_printf(&msg,
Willy Tarreau1d45b7c2009-08-16 10:29:18 +0200711 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200712 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
713 "<style type=\"text/css\"><!--\n"
714 "body {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +0200715 " font-family: arial, helvetica, sans-serif;"
Willy Tarreau91861262007-10-17 17:06:05 +0200716 " font-size: 12px;"
717 " font-weight: normal;"
718 " color: black;"
719 " background: white;"
720 "}\n"
721 "th,td {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +0200722 " font-size: 10px;"
Willy Tarreau91861262007-10-17 17:06:05 +0200723 " align: center;"
724 "}\n"
725 "h1 {"
Willy Tarreauda6721b2009-07-15 10:07:05 +0200726 " font-size: x-large;"
Willy Tarreau91861262007-10-17 17:06:05 +0200727 " margin-bottom: 0.5em;"
728 "}\n"
729 "h2 {"
730 " font-family: helvetica, arial;"
731 " font-size: x-large;"
732 " font-weight: bold;"
733 " font-style: italic;"
734 " color: #6020a0;"
735 " margin-top: 0em;"
736 " margin-bottom: 0em;"
737 "}\n"
738 "h3 {"
739 " font-family: helvetica, arial;"
740 " font-size: 16px;"
741 " font-weight: bold;"
742 " color: #b00040;"
743 " background: #e8e8d0;"
744 " margin-top: 0em;"
745 " margin-bottom: 0em;"
746 "}\n"
747 "li {"
748 " margin-top: 0.25em;"
749 " margin-right: 2em;"
750 "}\n"
751 ".hr {margin-top: 0.25em;"
752 " border-color: black;"
753 " border-bottom-style: solid;"
754 "}\n"
755 ".pxname {background: #b00040;color: #ffff40;font-weight: bold;}\n"
756 ".titre {background: #20D0D0;color: #000000;font-weight: bold;}\n"
757 ".total {background: #20D0D0;color: #ffff80;}\n"
758 ".frontend {background: #e8e8d0;}\n"
759 ".backend {background: #e8e8d0;}\n"
760 ".active0 {background: #ff9090;}\n"
761 ".active1 {background: #ffd020;}\n"
762 ".active2 {background: #ffffa0;}\n"
763 ".active3 {background: #c0ffc0;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +0100764 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
765 ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
766 ".active6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200767 ".backup0 {background: #ff9090;}\n"
768 ".backup1 {background: #ff80ff;}\n"
769 ".backup2 {background: #c060ff;}\n"
770 ".backup3 {background: #b0d0ff;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +0100771 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
772 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
773 ".backup6 {background: #e0e0e0;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +0200774 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
Willy Tarreau91861262007-10-17 17:06:05 +0200775 "table.tbl { border-collapse: collapse; border-style: none;}\n"
776 "table.tbl td { border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray;}\n"
777 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +0200778 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200779 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
780 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
781 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
782 "-->\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +0200783 "</style></head>\n",
784 uri->node_name ? " on " : "",
785 uri->node_name ? uri->node_name : ""
786 );
Willy Tarreau55bb8452007-10-17 18:44:57 +0200787 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200788 print_csv_header(&msg);
Willy Tarreau55bb8452007-10-17 18:44:57 +0200789 }
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +0200790 if (buffer_write_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +0200791 return 0;
792
793 s->data_state = DATA_ST_INFO;
794 /* fall through */
795
796 case DATA_ST_INFO:
797 up = (now.tv_sec - start_date.tv_sec);
798
799 /* WARNING! this has to fit the first packet too.
800 * We are around 3.5 kB, add adding entries will
801 * become tricky if we want to support 4kB buffers !
802 */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100803 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200804 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +0200805 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
806 PRODUCT_NAME "%s</a></h1>\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +0200807 "<h2>Statistics Report for pid %d%s%s</h2>\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200808 "<hr width=\"100%%\" class=\"hr\">\n"
809 "<h3>&gt; General process information</h3>\n"
810 "<table border=0 cols=4><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +0100811 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200812 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
813 "<b>system limits :</b> memmax = %s%s ; ulimit-n = %d<br>\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +0100814 "<b>maxsock = </b> %d ; <b>maxconn = </b> %d ; <b>maxpipes = </b> %d<br>\n"
815 "current conns = %d ; current pipes = %d/%d<br>\n"
Willy Tarreauc7bdf092009-03-21 18:33:52 +0100816 "Running tasks : %d/%d<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200817 "</td><td align=\"center\" nowrap>\n"
818 "<table class=\"lgd\"><tr>\n"
819 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
820 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
821 "</tr><tr>\n"
822 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
823 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
824 "</tr><tr>\n"
825 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
826 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
827 "</tr><tr>\n"
828 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Willy Tarreau2ea81932007-11-30 12:04:38 +0100829 "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
Willy Tarreau91861262007-10-17 17:06:05 +0200830 "</tr></table>\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +0100831 "Note: UP with load-balancing disabled is reported as \"NOLB\"."
Willy Tarreau91861262007-10-17 17:06:05 +0200832 "</td>"
833 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
834 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
835 "",
836 (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
Willy Tarreau1d45b7c2009-08-16 10:29:18 +0200837 pid, uri->node_name ? " on " : "", uri->node_name ? uri->node_name : "",
838 pid,
Willy Tarreaua8efd362008-01-03 10:19:15 +0100839 relative_pid, global.nbproc,
Willy Tarreau91861262007-10-17 17:06:05 +0200840 up / 86400, (up % 86400) / 3600,
841 (up % 3600) / 60, (up % 60),
842 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
843 global.rlimit_memmax ? " MB" : "",
844 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +0100845 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +0100846 actconn, pipes_used, pipes_used+pipes_free,
847 run_queue_cur, nb_tasks_cur
Willy Tarreau91861262007-10-17 17:06:05 +0200848 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100849
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100850 if (s->data_ctx.stats.flags & STAT_HIDE_DOWN)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200851 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +0200852 "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
853 uri->uri_prefix,
854 "",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100855 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +0200856 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200857 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +0200858 "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
859 uri->uri_prefix,
860 ";up",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100861 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +0200862
Willy Tarreau55bb8452007-10-17 18:44:57 +0200863 if (uri->refresh > 0) {
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100864 if (s->data_ctx.stats.flags & STAT_NO_REFRESH)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200865 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +0200866 "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
867 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100868 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +0200869 "");
Willy Tarreau55bb8452007-10-17 18:44:57 +0200870 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200871 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +0200872 "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
873 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100874 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +0200875 ";norefresh");
Willy Tarreau55bb8452007-10-17 18:44:57 +0200876 }
Willy Tarreau91861262007-10-17 17:06:05 +0200877
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200878 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +0200879 "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
880 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100881 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
882 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +0200883
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200884 chunk_printf(&msg,
Willy Tarreau5031e6a2007-10-18 11:05:48 +0200885 "<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
886 uri->uri_prefix,
887 (uri->refresh > 0) ? ";norefresh" : "");
888
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200889 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +0200890 "</td>"
891 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
892 "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n"
893 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
894 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
895 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
896 "</ul>"
897 "</td>"
898 "</tr></table>\n"
899 ""
900 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100901
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +0200902 if (buffer_write_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +0200903 return 0;
904 }
Willy Tarreau91861262007-10-17 17:06:05 +0200905
Willy Tarreau91861262007-10-17 17:06:05 +0200906 s->data_ctx.stats.px = proxy;
907 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
908 s->data_state = DATA_ST_LIST;
909 /* fall through */
910
911 case DATA_ST_LIST:
912 /* dump proxies */
913 while (s->data_ctx.stats.px) {
914 px = s->data_ctx.stats.px;
915 /* skip the disabled proxies and non-networked ones */
916 if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100917 if (stats_dump_proxy(s, px, uri) == 0)
Willy Tarreau91861262007-10-17 17:06:05 +0200918 return 0;
919
920 s->data_ctx.stats.px = px->next;
921 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
922 }
923 /* here, we just have reached the last proxy */
924
925 s->data_state = DATA_ST_END;
926 /* fall through */
927
928 case DATA_ST_END:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100929 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200930 chunk_printf(&msg, "</body></html>\n");
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +0200931 if (buffer_write_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +0200932 return 0;
933 }
Willy Tarreau91861262007-10-17 17:06:05 +0200934
935 s->data_state = DATA_ST_FIN;
936 /* fall through */
937
938 case DATA_ST_FIN:
Willy Tarreau72b179a2008-08-28 16:01:32 +0200939 buffer_stop_hijack(rep);
Willy Tarreau91861262007-10-17 17:06:05 +0200940 return 1;
941
942 default:
943 /* unknown state ! */
Willy Tarreau72b179a2008-08-28 16:01:32 +0200944 buffer_stop_hijack(rep);
Willy Tarreau91861262007-10-17 17:06:05 +0200945 return -1;
946 }
947}
948
949
950/*
951 * Dumps statistics for a proxy.
952 * Returns 0 if it had to stop dumping data because of lack of buffer space,
953 * ot non-zero if everything completed.
954 */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100955int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +0200956{
957 struct buffer *rep = s->rep;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100958 struct server *sv, *svs; /* server and server-state, server-state=server or server->tracked */
Willy Tarreau91861262007-10-17 17:06:05 +0200959 struct chunk msg;
960
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200961 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +0200962
963 switch (s->data_ctx.stats.px_st) {
964 case DATA_ST_PX_INIT:
965 /* we are on a new proxy */
966
967 if (uri && uri->scope) {
968 /* we have a limited scope, we have to check the proxy name */
969 struct stat_scope *scope;
970 int len;
971
972 len = strlen(px->id);
973 scope = uri->scope;
974
975 while (scope) {
976 /* match exact proxy name */
977 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
978 break;
979
980 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +0200981 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +0200982 break;
983 scope = scope->next;
984 }
985
986 /* proxy name not found : don't dump anything */
987 if (scope == NULL)
988 return 1;
989 }
990
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100991 if ((s->data_ctx.stats.flags & STAT_BOUND) && (s->data_ctx.stats.iid != -1) &&
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +0100992 (px->uuid != s->data_ctx.stats.iid))
993 return 1;
994
Willy Tarreau91861262007-10-17 17:06:05 +0200995 s->data_ctx.stats.px_st = DATA_ST_PX_TH;
996 /* fall through */
997
998 case DATA_ST_PX_TH:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100999 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau55bb8452007-10-17 18:44:57 +02001000 /* print a new table */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001001 chunk_printf(&msg,
Willy Tarreaua3e49422009-05-10 19:19:41 +02001002 "<table cols=\"29\" class=\"tbl\" width=\"100%%\">\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001003 "<tr align=\"center\" class=\"titre\">"
1004 "<th colspan=2 class=\"pxname\">%s</th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001005 "<th colspan=27 class=\"empty\"></th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001006 "</tr>\n"
1007 "<tr align=\"center\" class=\"titre\">"
1008 "<th rowspan=2></th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001009 "<th colspan=3>Queue</th>"
1010 "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001011 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001012 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001013 "<th colspan=9>Server</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001014 "</tr>\n"
1015 "<tr align=\"center\" class=\"titre\">"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001016 "<th>Cur</th><th>Max</th><th>Limit</th>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001017 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001018 "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001019 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001020 "<th>Resp</th><th>Retr</th><th>Redis</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001021 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001022 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
1023 "<th>Thrtle</th>\n"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001024 "</tr>",
Willy Tarreau55bb8452007-10-17 18:44:57 +02001025 px->id);
1026
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +02001027 if (buffer_write_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001028 return 0;
1029 }
Willy Tarreau91861262007-10-17 17:06:05 +02001030
1031 s->data_ctx.stats.px_st = DATA_ST_PX_FE;
1032 /* fall through */
1033
1034 case DATA_ST_PX_FE:
1035 /* print the frontend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001036 if ((px->cap & PR_CAP_FE) &&
1037 (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) {
1038 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001039 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001040 /* name, queue */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001041 "<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=3></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001042 /* sessions rate : current, max, limit */
1043 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
1044 /* sessions : current, max, limit, total, lbtot */
1045 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001046 "<td align=right>%s</td><td align=right></td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001047 /* bytes : in, out */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001048 "<td align=right>%s</td><td align=right>%s</td>"
1049 "",
Willy Tarreaua3e49422009-05-10 19:19:41 +02001050 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
1051 U2H1(px->fe_sps_max), LIM2A2(px->fe_sps_lim, "-"),
1052 U2H3(px->feconn), U2H4(px->feconn_max), U2H5(px->maxconn),
1053 U2H6(px->cum_feconn), U2H7(px->bytes_in), U2H8(px->bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001054
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001055 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001056 /* denied: req, resp */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001057 "<td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001058 /* errors : request, connect, response */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001059 "<td align=right>%s</td><td align=right></td><td align=right></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001060 /* warnings: retries, redispatches */
1061 "<td align=right></td><td align=right></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001062 /* server status : reflect frontend status */
Willy Tarreau91861262007-10-17 17:06:05 +02001063 "<td align=center>%s</td>"
1064 /* rest of server: nothing */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001065 "<td align=center colspan=8></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +02001066 "",
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001067 U2H0(px->denied_req), U2H1(px->denied_resp),
1068 U2H2(px->failed_req),
Willy Tarreau91861262007-10-17 17:06:05 +02001069 px->state == PR_STRUN ? "OPEN" :
1070 px->state == PR_STIDLE ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001071 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001072 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001073 /* pxid, name, queue cur, queue max, */
1074 "%s,FRONTEND,,,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001075 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001076 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001077 /* bytes : in, out */
1078 "%lld,%lld,"
1079 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001080 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001081 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001082 "%lld,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001083 /* warnings: retries, redispatches */
1084 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001085 /* server status : reflect frontend status */
1086 "%s,"
1087 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001088 ",,,,,,,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001089 /* pid, iid, sid, throttle, lbtot, tracked, type */
1090 "%d,%d,0,,,,%d,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001091 /* rate, rate_lim, rate_max */
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001092 "%u,%u,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001093 /* check_status, check_code, check_duration */
1094 ",,,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001095 "\n",
1096 px->id,
1097 px->feconn, px->feconn_max, px->maxconn, px->cum_feconn,
1098 px->bytes_in, px->bytes_out,
1099 px->denied_req, px->denied_resp,
1100 px->failed_req,
1101 px->state == PR_STRUN ? "OPEN" :
Willy Tarreaudcd47712007-11-04 23:35:08 +01001102 px->state == PR_STIDLE ? "FULL" : "STOP",
Willy Tarreau7f062c42009-03-05 18:43:00 +01001103 relative_pid, px->uuid, STATS_TYPE_FE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001104 read_freq_ctr(&px->fe_sess_per_sec),
1105 px->fe_sps_lim, px->fe_sps_max);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001106 }
Willy Tarreau91861262007-10-17 17:06:05 +02001107
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +02001108 if (buffer_write_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001109 return 0;
1110 }
1111
1112 s->data_ctx.stats.sv = px->srv; /* may be NULL */
1113 s->data_ctx.stats.px_st = DATA_ST_PX_SV;
1114 /* fall through */
1115
1116 case DATA_ST_PX_SV:
1117 /* stats.sv has been initialized above */
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001118 for (; s->data_ctx.stats.sv != NULL; s->data_ctx.stats.sv = sv->next) {
1119
Willy Tarreau2ea81932007-11-30 12:04:38 +01001120 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 +02001121
1122 sv = s->data_ctx.stats.sv;
1123
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001124 if (s->data_ctx.stats.flags & STAT_BOUND) {
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001125 if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SV)))
1126 break;
1127
1128 if (s->data_ctx.stats.sid != -1 && sv->puid != s->data_ctx.stats.sid)
1129 continue;
1130 }
1131
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001132 if (sv->tracked)
1133 svs = sv->tracked;
1134 else
1135 svs = sv;
1136
Willy Tarreau91861262007-10-17 17:06:05 +02001137 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001138 if (!(svs->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +01001139 sv_state = 6;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001140 else if (svs->state & SRV_RUNNING) {
1141 if (svs->health == svs->rise + svs->fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02001142 sv_state = 3; /* UP */
1143 else
1144 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01001145
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001146 if (svs->state & SRV_GOINGDOWN)
Willy Tarreau2ea81932007-11-30 12:04:38 +01001147 sv_state += 2;
1148 }
Willy Tarreau91861262007-10-17 17:06:05 +02001149 else
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001150 if (svs->health)
Willy Tarreau91861262007-10-17 17:06:05 +02001151 sv_state = 1; /* going up */
1152 else
1153 sv_state = 0; /* DOWN */
1154
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001155 if ((sv_state == 0) && (s->data_ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02001156 /* do not report servers which are DOWN */
1157 s->data_ctx.stats.sv = sv->next;
1158 continue;
1159 }
1160
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001161 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01001162 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
1163 "UP %d/%d &darr;", "UP",
1164 "NOLB %d/%d &darr;", "NOLB",
1165 "<i>no check</i>" };
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001166 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001167 /* name */
1168 "<tr align=\"center\" class=\"%s%d\"><td>%s</td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001169 /* queue : current, max, limit */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001170 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001171 /* sessions rate : current, max, limit */
1172 "<td align=right>%s</td><td align=right>%s</td><td align=right></td>"
1173 /* sessions : current, max, limit, total, lbtot */
1174 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001175 "<td align=right>%s</td><td align=right>%s</td>"
1176 "",
1177 (sv->state & SRV_BACKUP) ? "backup" : "active",
1178 sv_state, sv->id,
1179 U2H0(sv->nbpend), U2H1(sv->nbpend_max), LIM2A2(sv->maxqueue, "-"),
Willy Tarreaua3e49422009-05-10 19:19:41 +02001180 U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->sps_max),
1181 U2H5(sv->cur_sess), U2H6(sv->cur_sess_max), LIM2A7(sv->maxconn, "-"),
1182 U2H8(sv->cum_sess), U2H9(sv->cum_lbconn));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001183
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001184 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001185 /* bytes : in, out */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001186 "<td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001187 /* denied: req, resp */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001188 "<td align=right></td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001189 /* errors : request, connect, response */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001190 "<td align=right></td><td align=right>%s</td><td align=right>%s</td>\n"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001191 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001192 "<td align=right>%lld</td><td align=right>%lld</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001193 "",
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001194 U2H0(sv->bytes_in), U2H1(sv->bytes_out),
1195 U2H2(sv->failed_secu),
1196 U2H3(sv->failed_conns), U2H4(sv->failed_resp),
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01001197 sv->retries, sv->redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001198
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001199 /* status, lest check */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001200 chunk_printf(&msg, "<td nowrap>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001201
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001202 if (sv->state & SRV_CHECKED) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001203 chunk_printf(&msg, "%s ",
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001204 human_time(now.tv_sec - sv->last_change, 1));
1205
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001206 chunk_printf(&msg,
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001207 srv_hlt_st[sv_state],
1208 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
1209 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
1210
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001211 chunk_printf(&msg, "</td><td title=\"%s\" nowrap> %s%s",
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001212 get_check_status_description(sv->check_status),
1213 tv_iszero(&sv->check_start)?"":"* ",
1214 get_check_status_info(sv->check_status));
1215
1216 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001217 chunk_printf(&msg, "/%d", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001218
1219 if (sv->check_status >= HCHK_STATUS_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001220 chunk_printf(&msg, " in %lums", sv->check_duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001221 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001222 chunk_printf(&msg, "</td><td>");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001223 }
Willy Tarreau91861262007-10-17 17:06:05 +02001224
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001225 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001226 /* weight */
1227 "</td><td>%d</td>"
1228 /* act, bck */
1229 "<td>%s</td><td>%s</td>"
1230 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01001231 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +02001232 (sv->state & SRV_BACKUP) ? "-" : "Y",
1233 (sv->state & SRV_BACKUP) ? "Y" : "-");
1234
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001235 /* check failures: unique, fatal, down time */
Willy Tarreau55bb8452007-10-17 18:44:57 +02001236 if (sv->state & SRV_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001237 chunk_printf(&msg,
Willy Tarreau3b88d442009-04-11 20:44:08 +02001238 "<td align=right>%lld</td><td align=right>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001239 "<td nowrap align=right>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001240 "",
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001241 svs->failed_checks, svs->down_trans,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001242 human_time(srv_downtime(sv), 1));
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001243 else if (sv != svs)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001244 chunk_printf(&msg,
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001245 "<td nowrap colspan=3>via %s/%s</td>", svs->proxy->id, svs->id);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001246 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001247 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001248 "<td colspan=3></td>");
1249
1250 /* throttle */
1251 if ((sv->state & SRV_WARMINGUP) &&
1252 now.tv_sec < sv->last_change + sv->slowstart &&
1253 now.tv_sec >= sv->last_change) {
1254 unsigned int ratio;
1255 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001256 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001257 "<td>%d %%</td></tr>\n", ratio);
1258 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001259 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001260 "<td>-</td></tr>\n");
1261 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02001262 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +01001263 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
1264 "UP %d/%d,", "UP,",
1265 "NOLB %d/%d,", "NOLB,",
1266 "no check," };
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001267 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001268 /* pxid, name */
1269 "%s,%s,"
1270 /* queue : current, max */
1271 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001272 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001273 "%d,%d,%s,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001274 /* bytes : in, out */
1275 "%lld,%lld,"
1276 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001277 ",%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001278 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001279 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001280 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001281 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001282 "",
1283 px->id, sv->id,
1284 sv->nbpend, sv->nbpend_max,
Willy Tarreaudcd47712007-11-04 23:35:08 +01001285 sv->cur_sess, sv->cur_sess_max, LIM2A0(sv->maxconn, ""), sv->cum_sess,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001286 sv->bytes_in, sv->bytes_out,
1287 sv->failed_secu,
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001288 sv->failed_conns, sv->failed_resp,
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01001289 sv->retries, sv->redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001290
Willy Tarreau55bb8452007-10-17 18:44:57 +02001291 /* status */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001292 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001293 srv_hlt_st[sv_state],
1294 (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health),
1295 (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise));
Willy Tarreau91861262007-10-17 17:06:05 +02001296
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001297 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001298 /* weight, active, backup */
1299 "%d,%d,%d,"
1300 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01001301 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001302 (sv->state & SRV_BACKUP) ? 0 : 1,
1303 (sv->state & SRV_BACKUP) ? 1 : 0);
1304
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001305 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +02001306 if (sv->state & SRV_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001307 chunk_printf(&msg,
Willy Tarreau3b88d442009-04-11 20:44:08 +02001308 "%lld,%lld,%d,%d,",
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001309 sv->failed_checks, sv->down_trans,
Willy Tarreau1772ece2009-04-03 14:49:12 +02001310 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +02001311 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001312 chunk_printf(&msg,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001313 ",,,,");
1314
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001315 /* queue limit, pid, iid, sid, */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001316 chunk_printf(&msg,
Willy Tarreaudcd47712007-11-04 23:35:08 +01001317 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001318 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +01001319 LIM2A0(sv->maxqueue, ""),
1320 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001321
1322 /* throttle */
1323 if ((sv->state & SRV_WARMINGUP) &&
1324 now.tv_sec < sv->last_change + sv->slowstart &&
1325 now.tv_sec >= sv->last_change) {
1326 unsigned int ratio;
1327 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001328 chunk_printf(&msg, "%d", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001329 }
1330
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001331 /* sessions: lbtot */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001332 chunk_printf(&msg, ",%lld,", sv->cum_lbconn);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001333
1334 /* tracked */
1335 if (sv->tracked)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001336 chunk_printf(&msg, "%s/%s,",
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001337 sv->tracked->proxy->id, sv->tracked->id);
1338 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001339 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001340
Willy Tarreau7f062c42009-03-05 18:43:00 +01001341 /* type */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001342 chunk_printf(&msg, "%d,", STATS_TYPE_SV);
Willy Tarreau7f062c42009-03-05 18:43:00 +01001343
1344 /* rate */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001345 chunk_printf(&msg, "%u,,%u,",
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001346 read_freq_ctr(&sv->sess_per_sec),
1347 sv->sps_max);
Willy Tarreau7f062c42009-03-05 18:43:00 +01001348
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001349 if (sv->state & SRV_CHECKED) {
1350 /* check_status */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001351 chunk_printf(&msg, "%s,", get_check_status_info(sv->check_status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001352
1353 /* check_code */
1354 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001355 chunk_printf(&msg, "%u,", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001356 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001357 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001358
1359 /* check_duration */
1360 if (sv->check_status >= HCHK_STATUS_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001361 chunk_printf(&msg, "%lu,", sv->check_duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001362 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001363 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001364
1365 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001366 chunk_printf(&msg, ",,,");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001367 }
1368
Willy Tarreau7f062c42009-03-05 18:43:00 +01001369 /* finish with EOL */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001370 chunk_printf(&msg, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001371 }
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +02001372 if (buffer_write_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001373 return 0;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001374 } /* for sv */
Willy Tarreau91861262007-10-17 17:06:05 +02001375
1376 s->data_ctx.stats.px_st = DATA_ST_PX_BE;
1377 /* fall through */
1378
1379 case DATA_ST_PX_BE:
1380 /* print the backend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001381 if ((px->cap & PR_CAP_BE) &&
1382 (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_BE)))) {
1383 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001384 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001385 /* name */
1386 "<tr align=center class=\"backend\"><td>Backend</td>"
1387 /* queue : current, max */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001388 "<td align=right>%s</td><td align=right>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001389 /* sessions rate : current, max, limit */
1390 "<td align=right>%s</td><td align=right>%s</td><td align=right></td>"
1391 "",
1392 U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->nbpend_max),
1393 U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->be_sps_max));
1394
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001395 chunk_printf(&msg,
Willy Tarreaua3e49422009-05-10 19:19:41 +02001396 /* sessions : current, max, limit, total, lbtot */
1397 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001398 "<td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001399 /* bytes : in, out */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001400 "<td align=right>%s</td><td align=right>%s</td>"
1401 "",
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001402 U2H2(px->beconn), U2H3(px->beconn_max), U2H4(px->fullconn),
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001403 U2H6(px->cum_beconn), U2H7(px->cum_lbconn),
1404 U2H8(px->bytes_in), U2H9(px->bytes_out));
1405
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001406 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001407 /* denied: req, resp */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001408 "<td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001409 /* errors : request, connect, response */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001410 "<td align=right></td><td align=right>%s</td><td align=right>%s</td>\n"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001411 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001412 "<td align=right>%lld</td><td align=right>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001413 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +02001414 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001415 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +02001416 * active and backups. */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001417 "<td align=center nowrap>%s %s</td><td align=center>&nbsp;</td><td align=center>%d</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001418 "<td align=center>%d</td><td align=center>%d</td>"
1419 "",
1420 U2H0(px->denied_req), U2H1(px->denied_resp),
1421 U2H2(px->failed_conns), U2H3(px->failed_resp),
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001422 px->retries, px->redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001423 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +01001424 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
1425 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5542af62007-12-03 02:04:00 +01001426 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01001427 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001428
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001429 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001430 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001431 "<td align=center>&nbsp;</td><td align=\"right\">%d</td>"
1432 "<td align=\"right\" nowrap>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001433 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001434 "</tr>",
1435 px->down_trans,
1436 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001437 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001438 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001439 /* pxid, name */
1440 "%s,BACKEND,"
1441 /* queue : current, max */
1442 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001443 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001444 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001445 /* bytes : in, out */
1446 "%lld,%lld,"
1447 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001448 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001449 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001450 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001451 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001452 "%lld,%lld,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001453 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +02001454 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001455 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +02001456 * active and backups. */
1457 "%s,"
1458 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001459 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001460 ",%d,%d,%d,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001461 /* pid, iid, sid, throttle, lbtot, tracked, type */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001462 "%d,%d,0,,%lld,,%d,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001463 /* rate, rate_lim, rate_max, */
1464 "%u,,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001465 /* check_status, check_code, check_duration */
1466 ",,,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001467 "\n",
1468 px->id,
1469 px->nbpend /* or px->totpend ? */, px->nbpend_max,
1470 px->beconn, px->beconn_max, px->fullconn, px->cum_beconn,
1471 px->bytes_in, px->bytes_out,
1472 px->denied_req, px->denied_resp,
1473 px->failed_conns, px->failed_resp,
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001474 px->retries, px->redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +01001475 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5542af62007-12-03 02:04:00 +01001476 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01001477 px->srv_act, px->srv_bck,
Willy Tarreau1772ece2009-04-03 14:49:12 +02001478 px->down_trans, (int)(now.tv_sec - px->last_change),
Willy Tarreau20697042007-11-15 23:26:18 +01001479 px->srv?be_downtime(px):0,
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001480 relative_pid, px->uuid,
Willy Tarreau7f062c42009-03-05 18:43:00 +01001481 px->cum_lbconn, STATS_TYPE_BE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001482 read_freq_ctr(&px->be_sess_per_sec),
1483 px->be_sps_max);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001484 }
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +02001485 if (buffer_write_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001486 return 0;
1487 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001488
Willy Tarreau91861262007-10-17 17:06:05 +02001489 s->data_ctx.stats.px_st = DATA_ST_PX_END;
1490 /* fall through */
1491
1492 case DATA_ST_PX_END:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001493 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001494 chunk_printf(&msg, "</table><p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +02001495
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +02001496 if (buffer_write_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001497 return 0;
1498 }
Willy Tarreau91861262007-10-17 17:06:05 +02001499
1500 s->data_ctx.stats.px_st = DATA_ST_PX_FIN;
1501 /* fall through */
1502
1503 case DATA_ST_PX_FIN:
1504 return 1;
1505
1506 default:
1507 /* unknown state, we should put an abort() here ! */
1508 return 1;
1509 }
1510}
1511
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001512
1513/* This function is called to send output to the response buffer.
1514 * It dumps the sessions states onto the output buffer <rep>.
1515 * Expects to be called with client socket shut down on input.
1516 * s->data_ctx must have been zeroed first, and the flags properly set.
1517 * It automatically clears the HIJACK bit from the response buffer.
1518 */
1519void stats_dump_sess_to_buffer(struct session *s, struct buffer *rep)
1520{
1521 struct chunk msg;
1522
1523 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) {
1524 /* If we're forced to shut down, we might have to remove our
1525 * reference to the last session being dumped.
1526 */
1527 if (s->data_state == DATA_ST_LIST) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01001528 if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001529 LIST_DEL(&s->data_ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01001530 LIST_INIT(&s->data_ctx.sess.bref.users);
1531 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001532 }
1533 s->data_state = DATA_ST_FIN;
1534 buffer_stop_hijack(rep);
1535 s->ana_state = STATS_ST_CLOSE;
1536 return;
1537 }
1538
1539 if (s->ana_state != STATS_ST_REP)
1540 return;
1541
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001542 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001543
1544 switch (s->data_state) {
1545 case DATA_ST_INIT:
1546 /* the function had not been called yet, let's prepare the
1547 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01001548 * pointer to the first in the global list. When a target
1549 * session is being destroyed, it is responsible for updating
1550 * this pointer. We know we have reached the end when this
1551 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001552 */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001553 LIST_INIT(&s->data_ctx.sess.bref.users);
1554 s->data_ctx.sess.bref.ref = sessions.n;
1555 s->data_state = DATA_ST_LIST;
1556 /* fall through */
1557
1558 case DATA_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01001559 /* first, let's detach the back-ref from a possible previous session */
1560 if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) {
1561 LIST_DEL(&s->data_ctx.sess.bref.users);
1562 LIST_INIT(&s->data_ctx.sess.bref.users);
1563 }
1564
1565 /* and start from where we stopped */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001566 while (s->data_ctx.sess.bref.ref != &sessions) {
1567 char pn[INET6_ADDRSTRLEN + strlen(":65535")];
1568 struct session *curr_sess;
1569
1570 curr_sess = LIST_ELEM(s->data_ctx.sess.bref.ref, struct session *, list);
1571
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001572 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001573 "%p: proto=%s",
1574 curr_sess,
1575 curr_sess->listener->proto->name);
1576
1577 switch (curr_sess->listener->proto->sock_family) {
1578 case AF_INET:
1579 inet_ntop(AF_INET,
1580 (const void *)&((struct sockaddr_in *)&curr_sess->cli_addr)->sin_addr,
1581 pn, sizeof(pn));
1582
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001583 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001584 " src=%s:%d fe=%s be=%s srv=%s",
1585 pn,
1586 ntohs(((struct sockaddr_in *)&curr_sess->cli_addr)->sin_port),
1587 curr_sess->fe->id,
1588 curr_sess->be->id,
1589 curr_sess->srv ? curr_sess->srv->id : "<none>"
1590 );
1591 break;
1592 case AF_INET6:
1593 inet_ntop(AF_INET6,
1594 (const void *)&((struct sockaddr_in6 *)(&curr_sess->cli_addr))->sin6_addr,
1595 pn, sizeof(pn));
1596
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001597 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001598 " src=%s:%d fe=%s be=%s srv=%s",
1599 pn,
1600 ntohs(((struct sockaddr_in6 *)&curr_sess->cli_addr)->sin6_port),
1601 curr_sess->fe->id,
1602 curr_sess->be->id,
1603 curr_sess->srv ? curr_sess->srv->id : "<none>"
1604 );
1605
1606 break;
1607 case AF_UNIX:
1608 /* no more information to print right now */
1609 break;
1610 }
1611
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001612 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001613 " as=%d ts=%02x age=%s calls=%d",
Willy Tarreau8a5c6262008-12-08 00:16:21 +01001614 curr_sess->ana_state, curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01001615 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
1616 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001617
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001618 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001619 " rq[f=%06xh,l=%d,an=%02xh,rx=%s",
1620 curr_sess->req->flags,
1621 curr_sess->req->l,
1622 curr_sess->req->analysers,
1623 curr_sess->req->rex ?
1624 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
1625 TICKS_TO_MS(1000)) : "");
1626
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001627 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001628 ",wx=%s",
1629 curr_sess->req->wex ?
1630 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
1631 TICKS_TO_MS(1000)) : "");
1632
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001633 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001634 ",ax=%s]",
1635 curr_sess->req->analyse_exp ?
1636 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
1637 TICKS_TO_MS(1000)) : "");
1638
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001639 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001640 " rp[f=%06xh,l=%d,an=%02xh,rx=%s",
1641 curr_sess->rep->flags,
1642 curr_sess->rep->l,
1643 curr_sess->rep->analysers,
1644 curr_sess->rep->rex ?
1645 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
1646 TICKS_TO_MS(1000)) : "");
1647
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001648 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001649 ",wx=%s",
1650 curr_sess->rep->wex ?
1651 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
1652 TICKS_TO_MS(1000)) : "");
1653
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001654 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001655 ",ax=%s]",
1656 curr_sess->rep->analyse_exp ?
1657 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
1658 TICKS_TO_MS(1000)) : "");
1659
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001660 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001661 " s0=[%d,%1xh,fd=%d,ex=%s]",
1662 curr_sess->si[0].state,
1663 curr_sess->si[0].flags,
1664 curr_sess->si[0].fd,
1665 curr_sess->si[0].exp ?
1666 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
1667 TICKS_TO_MS(1000)) : "");
1668
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001669 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001670 " s1=[%d,%1xh,fd=%d,ex=%s]",
1671 curr_sess->si[1].state,
1672 curr_sess->si[1].flags,
1673 curr_sess->si[1].fd,
1674 curr_sess->si[1].exp ?
1675 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
1676 TICKS_TO_MS(1000)) : "");
1677
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001678 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001679 " exp=%s",
1680 curr_sess->task->expire ?
1681 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
1682 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01001683 if (task_in_rq(curr_sess->task))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001684 chunk_printf(&msg, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001685
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001686 chunk_printf(&msg, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001687
1688 if (buffer_write_chunk(rep, &msg) >= 0) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01001689 /* let's try again later from this session. We add ourselves into
1690 * this session's users so that it can remove us upon termination.
1691 */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001692 LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users);
1693 return;
1694 }
1695
1696 s->data_ctx.sess.bref.ref = curr_sess->list.n;
1697 }
1698 s->data_state = DATA_ST_FIN;
1699 /* fall through */
1700
1701 default:
1702 s->data_state = DATA_ST_FIN;
1703 buffer_stop_hijack(rep);
1704 s->ana_state = STATS_ST_CLOSE;
1705 return;
1706 }
1707}
1708
Willy Tarreau74808cb2009-03-04 15:53:18 +01001709/* print a line of error buffer (limited to 70 bytes) to <out>. The format is :
1710 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
1711 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
1712 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
1713 * lines are respected within the limit of 70 output chars. Lines that are
1714 * continuation of a previous truncated line begin with "+" instead of " "
1715 * after the offset. The new pointer is returned.
1716 */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001717static int dump_error_line(struct chunk *out, struct error_snapshot *err,
1718 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01001719{
1720 int end;
1721 unsigned char c;
1722
1723 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001724 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01001725 return ptr;
1726
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001727 chunk_printf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01001728
1729 while (ptr < err->len) {
1730 c = err->buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01001731 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01001732 if (out->len > end - 2)
1733 break;
1734 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01001735 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01001736 if (out->len > end - 3)
1737 break;
1738 out->str[out->len++] = '\\';
1739 switch (c) {
1740 case '\t': c = 't'; break;
1741 case '\n': c = 'n'; break;
1742 case '\r': c = 'r'; break;
1743 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01001744 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01001745 }
1746 out->str[out->len++] = c;
1747 } else {
1748 if (out->len > end - 5)
1749 break;
1750 out->str[out->len++] = '\\';
1751 out->str[out->len++] = 'x';
1752 out->str[out->len++] = hextab[(c >> 4) & 0xF];
1753 out->str[out->len++] = hextab[c & 0xF];
1754 }
1755 if (err->buf[ptr++] == '\n') {
1756 /* we had a line break, let's return now */
1757 out->str[out->len++] = '\n';
1758 *line = ptr;
1759 return ptr;
1760 }
1761 }
1762 /* we have an incomplete line, we return it as-is */
1763 out->str[out->len++] = '\n';
1764 return ptr;
1765}
1766
1767/* This function is called to send output to the response buffer.
1768 * It dumps the errors logged in proxies onto the output buffer <rep>.
1769 * Expects to be called with client socket shut down on input.
1770 * s->data_ctx must have been zeroed first, and the flags properly set.
1771 * It automatically clears the HIJACK bit from the response buffer.
1772 */
1773void stats_dump_errors_to_buffer(struct session *s, struct buffer *rep)
1774{
1775 extern const char *monthname[12];
1776 struct chunk msg;
1777
1778 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) {
1779 s->data_state = DATA_ST_FIN;
1780 buffer_stop_hijack(rep);
1781 s->ana_state = STATS_ST_CLOSE;
1782 return;
1783 }
1784
1785 if (s->ana_state != STATS_ST_REP)
1786 return;
1787
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001788 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau74808cb2009-03-04 15:53:18 +01001789
1790 if (!s->data_ctx.errors.px) {
1791 /* the function had not been called yet, let's prepare the
1792 * buffer for a response.
1793 */
Willy Tarreau74808cb2009-03-04 15:53:18 +01001794 s->data_ctx.errors.px = proxy;
1795 s->data_ctx.errors.buf = 0;
1796 s->data_ctx.errors.bol = 0;
1797 s->data_ctx.errors.ptr = -1;
1798 }
1799
1800 /* we have two inner loops here, one for the proxy, the other one for
1801 * the buffer.
1802 */
1803 while (s->data_ctx.errors.px) {
1804 struct error_snapshot *es;
1805
1806 if (s->data_ctx.errors.buf == 0)
1807 es = &s->data_ctx.errors.px->invalid_req;
1808 else
1809 es = &s->data_ctx.errors.px->invalid_rep;
1810
1811 if (!es->when.tv_sec)
1812 goto next;
1813
1814 if (s->data_ctx.errors.iid >= 0 &&
1815 s->data_ctx.errors.px->uuid != s->data_ctx.errors.iid &&
1816 es->oe->uuid != s->data_ctx.errors.iid)
1817 goto next;
1818
1819 if (s->data_ctx.errors.ptr < 0) {
1820 /* just print headers now */
1821
1822 char pn[INET6_ADDRSTRLEN];
1823 struct tm tm;
1824
1825 get_localtime(es->when.tv_sec, &tm);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001826 chunk_printf(&msg, "\n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01001827 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02001828 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01001829
1830
1831 if (es->src.ss_family == AF_INET)
1832 inet_ntop(AF_INET,
1833 (const void *)&((struct sockaddr_in *)&es->src)->sin_addr,
1834 pn, sizeof(pn));
1835 else
1836 inet_ntop(AF_INET6,
1837 (const void *)&((struct sockaddr_in6 *)(&es->src))->sin6_addr,
1838 pn, sizeof(pn));
1839
1840 switch (s->data_ctx.errors.buf) {
1841 case 0:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001842 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01001843 " frontend %s (#%d): invalid request\n"
1844 " src %s, session #%d, backend %s (#%d), server %s (#%d)\n"
1845 " request length %d bytes, error at position %d:\n\n",
1846 s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid,
1847 pn, es->sid, es->oe->id, es->oe->uuid,
1848 es->srv ? es->srv->id : "<NONE>",
1849 es->srv ? es->srv->puid : -1,
1850 es->len, es->pos);
1851 break;
1852 case 1:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001853 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01001854 " backend %s (#%d) : invalid response\n"
1855 " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n"
1856 " response length %d bytes, error at position %d:\n\n",
1857 s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid,
1858 pn, es->sid, es->oe->id, es->oe->uuid,
1859 es->srv ? es->srv->id : "<NONE>",
1860 es->srv ? es->srv->puid : -1,
1861 es->len, es->pos);
1862 break;
1863 }
1864
1865 if (buffer_write_chunk(rep, &msg) >= 0) {
1866 /* Socket buffer full. Let's try again later from the same point */
1867 return;
1868 }
1869 s->data_ctx.errors.ptr = 0;
1870 s->data_ctx.errors.sid = es->sid;
1871 }
1872
1873 if (s->data_ctx.errors.sid != es->sid) {
1874 /* the snapshot changed while we were dumping it */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001875 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01001876 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
1877 if (buffer_write_chunk(rep, &msg) >= 0)
1878 return;
1879 goto next;
1880 }
1881
1882 /* OK, ptr >= 0, so we have to dump the current line */
1883 while (s->data_ctx.errors.ptr < es->len) {
1884 int newptr;
1885 int newline;
1886
1887 newline = s->data_ctx.errors.bol;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001888 newptr = dump_error_line(&msg, es, &newline, s->data_ctx.errors.ptr);
Willy Tarreau74808cb2009-03-04 15:53:18 +01001889 if (newptr == s->data_ctx.errors.ptr)
1890 return;
1891
1892 if (buffer_write_chunk(rep, &msg) >= 0) {
1893 /* Socket buffer full. Let's try again later from the same point */
1894 return;
1895 }
1896 s->data_ctx.errors.ptr = newptr;
1897 s->data_ctx.errors.bol = newline;
1898 };
1899 next:
1900 s->data_ctx.errors.bol = 0;
1901 s->data_ctx.errors.ptr = -1;
1902 s->data_ctx.errors.buf++;
1903 if (s->data_ctx.errors.buf > 1) {
1904 s->data_ctx.errors.buf = 0;
1905 s->data_ctx.errors.px = s->data_ctx.errors.px->next;
1906 }
1907 }
1908
1909 /* dump complete */
1910 buffer_stop_hijack(rep);
1911 s->ana_state = STATS_ST_CLOSE;
1912}
1913
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001914
Willy Tarreau10522fd2008-07-09 20:12:41 +02001915static struct cfg_kw_list cfg_kws = {{ },{
1916 { CFG_GLOBAL, "stats", stats_parse_global },
1917 { 0, NULL, NULL },
1918}};
1919
1920__attribute__((constructor))
1921static void __dumpstats_module_init(void)
1922{
1923 cfg_register_keywords(&cfg_kws);
1924}
1925
Willy Tarreau91861262007-10-17 17:06:05 +02001926/*
1927 * Local variables:
1928 * c-indent-level: 8
1929 * c-basic-offset: 8
1930 * End:
1931 */