blob: 7454600f4b73bfc0a4a03f1df1a3da0bd055ba21 [file] [log] [blame]
Willy Tarreau91861262007-10-17 17:06:05 +02001/*
2 * Functions dedicated to statistics output
3 *
4 * Copyright 2000-2007 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <ctype.h>
14#include <errno.h>
15#include <fcntl.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020019#include <pwd.h>
20#include <grp.h>
Willy Tarreau91861262007-10-17 17:06:05 +020021
22#include <sys/socket.h>
23#include <sys/stat.h>
24#include <sys/types.h>
25
26#include <common/compat.h>
27#include <common/config.h>
28#include <common/debug.h>
29#include <common/memory.h>
30#include <common/mini-clist.h>
31#include <common/standard.h>
32#include <common/time.h>
33#include <common/uri_auth.h>
34#include <common/version.h>
35
36#include <types/client.h>
37#include <types/global.h>
38#include <types/polling.h>
39#include <types/proxy.h>
40#include <types/server.h>
41
42#include <proto/backend.h>
43#include <proto/buffers.h>
44#include <proto/dumpstats.h>
45#include <proto/fd.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020046#include <proto/proto_uxst.h>
Willy Tarreau91861262007-10-17 17:06:05 +020047#include <proto/senddata.h>
48#include <proto/session.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020049#include <proto/server.h>
Willy Tarreau91861262007-10-17 17:06:05 +020050
Willy Tarreaufbee7132007-10-18 13:53:22 +020051/* This function parses a "stats" statement in the "global" section. It returns
52 * -1 if there is any error, otherwise zero. If it returns -1, it may write an
53 * error message into ther <err> buffer, for at most <errlen> bytes, trailing
54 * zero included. The trailing '\n' must not be written. The function must be
55 * called with <args> pointing to the first word after "stats".
56 */
57int stats_parse_global(const char **args, char *err, int errlen)
58{
59 if (!strcmp(args[0], "socket")) {
60 struct sockaddr_un su;
61 int cur_arg;
62
63 if (*args[1] == 0) {
64 snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket");
65 return -1;
66 }
67
68 if (global.stats_sock.state != LI_NEW) {
69 snprintf(err, errlen, "'stats socket' already specified in global section");
70 return -1;
71 }
72
73 su.sun_family = AF_UNIX;
74 strncpy(su.sun_path, args[1], sizeof(su.sun_path));
75 su.sun_path[sizeof(su.sun_path) - 1] = 0;
76 memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit
77
78 global.stats_sock.state = LI_INIT;
Willy Tarreau6fb42e02007-10-28 17:02:33 +010079 global.stats_sock.options = LI_O_NONE;
Willy Tarreaufbee7132007-10-18 13:53:22 +020080 global.stats_sock.accept = uxst_event_accept;
81 global.stats_sock.handler = process_uxst_stats;
82 global.stats_sock.private = NULL;
83
84 cur_arg = 2;
85 while (*args[cur_arg]) {
86 if (!strcmp(args[cur_arg], "uid")) {
87 global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]);
88 cur_arg += 2;
89 }
90 else if (!strcmp(args[cur_arg], "gid")) {
91 global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]);
92 cur_arg += 2;
93 }
94 else if (!strcmp(args[cur_arg], "mode")) {
95 global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
96 cur_arg += 2;
97 }
98 else if (!strcmp(args[cur_arg], "user")) {
99 struct passwd *user;
100 user = getpwnam(args[cur_arg + 1]);
101 if (!user) {
102 snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')",
103 args[cur_arg + 1]);
104 return -1;
105 }
106 global.stats_sock.perm.ux.uid = user->pw_uid;
107 cur_arg += 2;
108 }
109 else if (!strcmp(args[cur_arg], "group")) {
110 struct group *group;
111 group = getgrnam(args[cur_arg + 1]);
112 if (!group) {
113 snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')",
114 args[cur_arg + 1]);
115 return -1;
116 }
117 global.stats_sock.perm.ux.gid = group->gr_gid;
118 cur_arg += 2;
119 }
120 else {
121 snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', and 'mode'");
122 return -1;
123 }
124 }
125
126 uxst_add_listener(&global.stats_sock);
127 global.maxsock++;
128 }
129 else if (!strcmp(args[0], "timeout")) {
130 int timeout = atol(args[1]);
131
132 if (timeout <= 0) {
133 snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'");
134 return -1;
135 }
136 __tv_from_ms(&global.stats_timeout, timeout);
137 }
138 else if (!strcmp(args[0], "maxconn")) {
139 int maxconn = atol(args[1]);
140
141 if (maxconn <= 0) {
142 snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'");
143 return -1;
144 }
145 global.maxsock -= global.stats_sock.maxconn;
146 global.stats_sock.maxconn = maxconn;
147 global.maxsock += global.stats_sock.maxconn;
148 }
149 else {
150 snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section");
151 return -1;
152 }
153 return 0;
154}
155
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100156int print_csv_header(struct chunk *msg, int size)
157{
158 return chunk_printf(msg, size,
159 "# pxname,svname,"
160 "qcur,qmax,"
161 "scur,smax,slim,stot,"
162 "bin,bout,"
163 "dreq,dresp,"
164 "ereq,econ,eresp,"
165 "wretr,wredis,"
166 "status,weight,act,bck,"
167 "chkfail,chkdown,lastchg,downtime,qlimit,"
168 "pid,iid,sid,throttle,"
169 "\n");
170}
171
Willy Tarreau91861262007-10-17 17:06:05 +0200172/*
173 * Produces statistics data for the session <s>. Expects to be called with
Willy Tarreau3e76e722007-10-17 18:57:38 +0200174 * s->cli_state == CL_STSHUTR. It *may* make use of informations from <uri>
175 * and <flags>.
176 * It returns 0 if it had to stop writing data and an I/O is needed, 1 if the
177 * dump is finished and the session must be closed, or -1 in case of any error.
178 */
179int stats_dump_raw(struct session *s, struct uri_auth *uri, int flags)
180{
181 struct buffer *rep = s->rep;
182 struct proxy *px;
183 struct chunk msg;
184
185 msg.len = 0;
186 msg.str = trash;
187
188 switch (s->data_state) {
189 case DATA_ST_INIT:
190 /* the function had not been called yet, let's prepare the
191 * buffer for a response.
192 */
193 client_retnclose(s, &msg);
194 s->data_state = DATA_ST_HEAD;
195 /* fall through */
196
197 case DATA_ST_HEAD:
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100198 print_csv_header(&msg, sizeof(trash));
Willy Tarreau3e76e722007-10-17 18:57:38 +0200199 if (buffer_write_chunk(rep, &msg) != 0)
200 return 0;
201
202 s->data_state = DATA_ST_INFO;
203 /* fall through */
204
205 case DATA_ST_INFO:
206 memset(&s->data_ctx, 0, sizeof(s->data_ctx));
207
208 s->data_ctx.stats.px = proxy;
209 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
210 s->data_state = DATA_ST_LIST;
211 /* fall through */
212
213 case DATA_ST_LIST:
214 /* dump proxies */
215 while (s->data_ctx.stats.px) {
216 px = s->data_ctx.stats.px;
217 /* skip the disabled proxies and non-networked ones */
218 if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
219 if (stats_dump_proxy(s, px, NULL, 0) == 0)
220 return 0;
221
222 s->data_ctx.stats.px = px->next;
223 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
224 }
225 /* here, we just have reached the last proxy */
226
227 s->data_state = DATA_ST_END;
228 /* fall through */
229
230 case DATA_ST_END:
231 s->data_state = DATA_ST_FIN;
232 return 1;
233
234 case DATA_ST_FIN:
235 return 1;
236
237 default:
238 /* unknown state ! */
239 return -1;
240 }
241}
242
243
244/*
245 * Produces statistics data for the session <s>. Expects to be called with
Willy Tarreau91861262007-10-17 17:06:05 +0200246 * s->cli_state == CL_STSHUTR. It stops by itself by unsetting the SN_SELF_GEN
247 * flag from the session, which it uses to keep on being called when there is
248 * free space in the buffer, of simply by letting an empty buffer upon return.
249 * It returns 0 if it had to stop writing data and an I/O is needed, 1 if the
250 * dump is finished and the session must be closed, or -1 in case of any error.
251 */
252int stats_dump_http(struct session *s, struct uri_auth *uri, int flags)
253{
254 struct buffer *rep = s->rep;
255 struct proxy *px;
256 struct chunk msg;
257 unsigned int up;
258
259 msg.len = 0;
260 msg.str = trash;
261
262 switch (s->data_state) {
263 case DATA_ST_INIT:
264 /* the function had not been called yet */
265 s->flags |= SN_SELF_GEN; // more data will follow
266
267 chunk_printf(&msg, sizeof(trash),
268 "HTTP/1.0 200 OK\r\n"
269 "Cache-Control: no-cache\r\n"
270 "Connection: close\r\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200271 "Content-Type: %s\r\n",
272 (flags & STAT_FMT_HTML) ? "text/html" : "text/plain");
Willy Tarreau91861262007-10-17 17:06:05 +0200273
274 if (uri->refresh > 0 && !(s->flags & SN_STAT_NORFRSH))
275 chunk_printf(&msg, sizeof(trash), "Refresh: %d\r\n",
276 uri->refresh);
277
278 chunk_printf(&msg, sizeof(trash), "\r\n");
279
280 s->txn.status = 200;
281 client_retnclose(s, &msg); // send the start of the response.
282 msg.len = 0;
283
284 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
285 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
286 if (!(s->flags & SN_FINST_MASK))
287 s->flags |= SN_FINST_R;
288
289 if (s->txn.meth == HTTP_METH_HEAD) {
290 /* that's all we return in case of HEAD request */
291 s->data_state = DATA_ST_FIN;
292 s->flags &= ~SN_SELF_GEN;
293 return 1;
294 }
295
296 s->data_state = DATA_ST_HEAD; /* let's start producing data */
297 /* fall through */
298
299 case DATA_ST_HEAD:
Willy Tarreau55bb8452007-10-17 18:44:57 +0200300 if (flags & STAT_FMT_HTML) {
301 /* WARNING! This must fit in the first buffer !!! */
302 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200303 "<html><head><title>Statistics Report for " PRODUCT_NAME "</title>\n"
304 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
305 "<style type=\"text/css\"><!--\n"
306 "body {"
307 " font-family: helvetica, arial;"
308 " font-size: 12px;"
309 " font-weight: normal;"
310 " color: black;"
311 " background: white;"
312 "}\n"
313 "th,td {"
314 " font-size: 0.8em;"
315 " align: center;"
316 "}\n"
317 "h1 {"
318 " font-size: xx-large;"
319 " margin-bottom: 0.5em;"
320 "}\n"
321 "h2 {"
322 " font-family: helvetica, arial;"
323 " font-size: x-large;"
324 " font-weight: bold;"
325 " font-style: italic;"
326 " color: #6020a0;"
327 " margin-top: 0em;"
328 " margin-bottom: 0em;"
329 "}\n"
330 "h3 {"
331 " font-family: helvetica, arial;"
332 " font-size: 16px;"
333 " font-weight: bold;"
334 " color: #b00040;"
335 " background: #e8e8d0;"
336 " margin-top: 0em;"
337 " margin-bottom: 0em;"
338 "}\n"
339 "li {"
340 " margin-top: 0.25em;"
341 " margin-right: 2em;"
342 "}\n"
343 ".hr {margin-top: 0.25em;"
344 " border-color: black;"
345 " border-bottom-style: solid;"
346 "}\n"
347 ".pxname {background: #b00040;color: #ffff40;font-weight: bold;}\n"
348 ".titre {background: #20D0D0;color: #000000;font-weight: bold;}\n"
349 ".total {background: #20D0D0;color: #ffff80;}\n"
350 ".frontend {background: #e8e8d0;}\n"
351 ".backend {background: #e8e8d0;}\n"
352 ".active0 {background: #ff9090;}\n"
353 ".active1 {background: #ffd020;}\n"
354 ".active2 {background: #ffffa0;}\n"
355 ".active3 {background: #c0ffc0;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +0100356 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
357 ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
358 ".active6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200359 ".backup0 {background: #ff9090;}\n"
360 ".backup1 {background: #ff80ff;}\n"
361 ".backup2 {background: #c060ff;}\n"
362 ".backup3 {background: #b0d0ff;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +0100363 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
364 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
365 ".backup6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200366 "table.tbl { border-collapse: collapse; border-style: none;}\n"
367 "table.tbl td { border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray;}\n"
368 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
369 "table.tbl th.empty { border-style: none; empty-cells: hide;}\n"
370 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
371 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
372 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
373 "-->\n"
374 "</style></head>\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +0200375 } else {
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100376 print_csv_header(&msg, sizeof(trash));
Willy Tarreau55bb8452007-10-17 18:44:57 +0200377 }
Willy Tarreau91861262007-10-17 17:06:05 +0200378 if (buffer_write_chunk(rep, &msg) != 0)
379 return 0;
380
381 s->data_state = DATA_ST_INFO;
382 /* fall through */
383
384 case DATA_ST_INFO:
385 up = (now.tv_sec - start_date.tv_sec);
386
387 /* WARNING! this has to fit the first packet too.
388 * We are around 3.5 kB, add adding entries will
389 * become tricky if we want to support 4kB buffers !
390 */
Willy Tarreau55bb8452007-10-17 18:44:57 +0200391 if (flags & STAT_FMT_HTML) {
392 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200393 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
394 PRODUCT_NAME "%s</a></h1>\n"
395 "<h2>Statistics Report for pid %d</h2>\n"
396 "<hr width=\"100%%\" class=\"hr\">\n"
397 "<h3>&gt; General process information</h3>\n"
398 "<table border=0 cols=4><tr><td align=\"left\" nowrap width=\"1%%\">\n"
399 "<p><b>pid = </b> %d (nbproc = %d)<br>\n"
400 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
401 "<b>system limits :</b> memmax = %s%s ; ulimit-n = %d<br>\n"
402 "<b>maxsock = </b> %d<br>\n"
403 "<b>maxconn = </b> %d (current conns = %d)<br>\n"
404 "</td><td align=\"center\" nowrap>\n"
405 "<table class=\"lgd\"><tr>\n"
406 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
407 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
408 "</tr><tr>\n"
409 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
410 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
411 "</tr><tr>\n"
412 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
413 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
414 "</tr><tr>\n"
415 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Willy Tarreau2ea81932007-11-30 12:04:38 +0100416 "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
Willy Tarreau91861262007-10-17 17:06:05 +0200417 "</tr></table>\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +0100418 "Note: UP with load-balancing disabled is reported as \"NOLB\"."
Willy Tarreau91861262007-10-17 17:06:05 +0200419 "</td>"
420 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
421 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
422 "",
423 (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
424 pid, pid, global.nbproc,
425 up / 86400, (up % 86400) / 3600,
426 (up % 3600) / 60, (up % 60),
427 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
428 global.rlimit_memmax ? " MB" : "",
429 global.rlimit_nofile,
430 global.maxsock,
431 global.maxconn,
432 actconn
433 );
434
Willy Tarreau55bb8452007-10-17 18:44:57 +0200435 if (s->flags & SN_STAT_HIDEDWN)
436 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200437 "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
438 uri->uri_prefix,
439 "",
440 (s->flags & SN_STAT_NORFRSH) ? ";norefresh" : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +0200441 else
442 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200443 "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
444 uri->uri_prefix,
445 ";up",
446 (s->flags & SN_STAT_NORFRSH) ? ";norefresh" : "");
447
Willy Tarreau55bb8452007-10-17 18:44:57 +0200448 if (uri->refresh > 0) {
449 if (s->flags & SN_STAT_NORFRSH)
450 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200451 "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
452 uri->uri_prefix,
453 (s->flags & SN_STAT_HIDEDWN) ? ";up" : "",
454 "");
Willy Tarreau55bb8452007-10-17 18:44:57 +0200455 else
456 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200457 "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
458 uri->uri_prefix,
459 (s->flags & SN_STAT_HIDEDWN) ? ";up" : "",
460 ";norefresh");
Willy Tarreau55bb8452007-10-17 18:44:57 +0200461 }
Willy Tarreau91861262007-10-17 17:06:05 +0200462
Willy Tarreau55bb8452007-10-17 18:44:57 +0200463 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200464 "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
465 uri->uri_prefix,
466 (s->flags & SN_STAT_HIDEDWN) ? ";up" : "",
467 (s->flags & SN_STAT_NORFRSH) ? ";norefresh" : "");
468
Willy Tarreau55bb8452007-10-17 18:44:57 +0200469 chunk_printf(&msg, sizeof(trash),
Willy Tarreau5031e6a2007-10-18 11:05:48 +0200470 "<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
471 uri->uri_prefix,
472 (uri->refresh > 0) ? ";norefresh" : "");
473
474 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200475 "</td>"
476 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
477 "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n"
478 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
479 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
480 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
481 "</ul>"
482 "</td>"
483 "</tr></table>\n"
484 ""
485 );
486
Willy Tarreau55bb8452007-10-17 18:44:57 +0200487 if (buffer_write_chunk(rep, &msg) != 0)
488 return 0;
489 }
Willy Tarreau91861262007-10-17 17:06:05 +0200490
491 memset(&s->data_ctx, 0, sizeof(s->data_ctx));
492
493 s->data_ctx.stats.px = proxy;
494 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
495 s->data_state = DATA_ST_LIST;
496 /* fall through */
497
498 case DATA_ST_LIST:
499 /* dump proxies */
500 while (s->data_ctx.stats.px) {
501 px = s->data_ctx.stats.px;
502 /* skip the disabled proxies and non-networked ones */
503 if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
504 if (stats_dump_proxy(s, px, uri, flags) == 0)
505 return 0;
506
507 s->data_ctx.stats.px = px->next;
508 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
509 }
510 /* here, we just have reached the last proxy */
511
512 s->data_state = DATA_ST_END;
513 /* fall through */
514
515 case DATA_ST_END:
Willy Tarreau55bb8452007-10-17 18:44:57 +0200516 if (flags & STAT_FMT_HTML) {
517 chunk_printf(&msg, sizeof(trash), "</body></html>\n");
518 if (buffer_write_chunk(rep, &msg) != 0)
519 return 0;
520 }
Willy Tarreau91861262007-10-17 17:06:05 +0200521
522 s->data_state = DATA_ST_FIN;
523 /* fall through */
524
525 case DATA_ST_FIN:
526 s->flags &= ~SN_SELF_GEN;
527 return 1;
528
529 default:
530 /* unknown state ! */
531 s->flags &= ~SN_SELF_GEN;
532 return -1;
533 }
534}
535
536
537/*
538 * Dumps statistics for a proxy.
539 * Returns 0 if it had to stop dumping data because of lack of buffer space,
540 * ot non-zero if everything completed.
541 */
542int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, int flags)
543{
544 struct buffer *rep = s->rep;
545 struct server *sv;
546 struct chunk msg;
547
548 msg.len = 0;
549 msg.str = trash;
550
551 switch (s->data_ctx.stats.px_st) {
552 case DATA_ST_PX_INIT:
553 /* we are on a new proxy */
554
555 if (uri && uri->scope) {
556 /* we have a limited scope, we have to check the proxy name */
557 struct stat_scope *scope;
558 int len;
559
560 len = strlen(px->id);
561 scope = uri->scope;
562
563 while (scope) {
564 /* match exact proxy name */
565 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
566 break;
567
568 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +0200569 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +0200570 break;
571 scope = scope->next;
572 }
573
574 /* proxy name not found : don't dump anything */
575 if (scope == NULL)
576 return 1;
577 }
578
579 s->data_ctx.stats.px_st = DATA_ST_PX_TH;
580 /* fall through */
581
582 case DATA_ST_PX_TH:
Willy Tarreau55bb8452007-10-17 18:44:57 +0200583 if (flags & STAT_FMT_HTML) {
584 /* print a new table */
585 chunk_printf(&msg, sizeof(trash),
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100586 "<table cols=\"25\" class=\"tbl\" width=\"100%%\">\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200587 "<tr align=\"center\" class=\"titre\">"
588 "<th colspan=2 class=\"pxname\">%s</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100589 "<th colspan=22 class=\"empty\"></th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200590 "</tr>\n"
591 "<tr align=\"center\" class=\"titre\">"
592 "<th rowspan=2></th>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200593 "<th colspan=3>Queue</th><th colspan=4>Sessions</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200594 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200595 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100596 "<th colspan=8>Server</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200597 "</tr>\n"
598 "<tr align=\"center\" class=\"titre\">"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200599 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200600 "<th>Limit</th><th>Cumul</th><th>In</th><th>Out</th>"
601 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200602 "<th>Resp</th><th>Retr</th><th>Redis</th>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200603 "<th>Status</th><th>Wght</th><th>Act</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100604 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
605 "<th>Thrtle</th>\n"
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200606 "</tr>",
Willy Tarreau55bb8452007-10-17 18:44:57 +0200607 px->id);
608
609 if (buffer_write_chunk(rep, &msg) != 0)
610 return 0;
611 }
Willy Tarreau91861262007-10-17 17:06:05 +0200612
613 s->data_ctx.stats.px_st = DATA_ST_PX_FE;
614 /* fall through */
615
616 case DATA_ST_PX_FE:
617 /* print the frontend */
618 if (px->cap & PR_CAP_FE) {
Willy Tarreau55bb8452007-10-17 18:44:57 +0200619 if (flags & STAT_FMT_HTML) {
620 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200621 /* name, queue */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200622 "<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=3></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200623 /* sessions : current, max, limit, cumul */
624 "<td align=right>%d</td><td align=right>%d</td>"
625 "<td align=right>%d</td><td align=right>%d</td>"
Willy Tarreau91861262007-10-17 17:06:05 +0200626 /* bytes : in, out */
627 "<td align=right>%lld</td><td align=right>%lld</td>"
628 /* denied: req, resp */
629 "<td align=right>%d</td><td align=right>%d</td>"
630 /* errors : request, connect, response */
631 "<td align=right>%d</td><td align=right></td><td align=right></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200632 /* warnings: retries, redispatches */
633 "<td align=right></td><td align=right></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200634 /* server status : reflect frontend status */
Willy Tarreau91861262007-10-17 17:06:05 +0200635 "<td align=center>%s</td>"
636 /* rest of server: nothing */
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100637 "<td align=center colspan=7></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +0200638 "",
639 px->feconn, px->feconn_max, px->maxconn, px->cum_feconn,
640 px->bytes_in, px->bytes_out,
641 px->denied_req, px->denied_resp,
642 px->failed_req,
643 px->state == PR_STRUN ? "OPEN" :
644 px->state == PR_STIDLE ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +0200645 } else {
646 chunk_printf(&msg, sizeof(trash),
647 /* pxid, name, queue cur, queue max, */
648 "%s,FRONTEND,,,"
649 /* sessions : current, max, limit, cumul */
650 "%d,%d,%d,%d,"
651 /* bytes : in, out */
652 "%lld,%lld,"
653 /* denied: req, resp */
654 "%d,%d,"
655 /* errors : request, connect, response */
656 "%d,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200657 /* warnings: retries, redispatches */
658 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200659 /* server status : reflect frontend status */
660 "%s,"
661 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200662 ",,,,,,,,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100663 /* pid, iid, sid, throttle, */
664 "%d,%d,0,,"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200665 "\n",
666 px->id,
667 px->feconn, px->feconn_max, px->maxconn, px->cum_feconn,
668 px->bytes_in, px->bytes_out,
669 px->denied_req, px->denied_resp,
670 px->failed_req,
671 px->state == PR_STRUN ? "OPEN" :
Willy Tarreaudcd47712007-11-04 23:35:08 +0100672 px->state == PR_STIDLE ? "FULL" : "STOP",
673 relative_pid, px->uuid);
Willy Tarreau55bb8452007-10-17 18:44:57 +0200674 }
Willy Tarreau91861262007-10-17 17:06:05 +0200675
676 if (buffer_write_chunk(rep, &msg) != 0)
677 return 0;
678 }
679
680 s->data_ctx.stats.sv = px->srv; /* may be NULL */
681 s->data_ctx.stats.px_st = DATA_ST_PX_SV;
682 /* fall through */
683
684 case DATA_ST_PX_SV:
685 /* stats.sv has been initialized above */
686 while (s->data_ctx.stats.sv != NULL) {
Willy Tarreau2ea81932007-11-30 12:04:38 +0100687 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 +0200688
689 sv = s->data_ctx.stats.sv;
690
691 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
692 if (!(sv->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +0100693 sv_state = 6;
694 else if (sv->state & SRV_RUNNING) {
Willy Tarreau91861262007-10-17 17:06:05 +0200695 if (sv->health == sv->rise + sv->fall - 1)
696 sv_state = 3; /* UP */
697 else
698 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +0100699
700 if (sv->state & SRV_GOINGDOWN)
701 sv_state += 2;
702 }
Willy Tarreau91861262007-10-17 17:06:05 +0200703 else
704 if (sv->health)
705 sv_state = 1; /* going up */
706 else
707 sv_state = 0; /* DOWN */
708
709 if ((sv_state == 0) && (s->flags & SN_STAT_HIDEDWN)) {
710 /* do not report servers which are DOWN */
711 s->data_ctx.stats.sv = sv->next;
712 continue;
713 }
714
Willy Tarreau55bb8452007-10-17 18:44:57 +0200715 if (flags & STAT_FMT_HTML) {
Willy Tarreau2ea81932007-11-30 12:04:38 +0100716 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
717 "UP %d/%d &darr;", "UP",
718 "NOLB %d/%d &darr;", "NOLB",
719 "<i>no check</i>" };
Willy Tarreau55bb8452007-10-17 18:44:57 +0200720 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200721 /* name */
722 "<tr align=\"center\" class=\"%s%d\"><td>%s</td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200723 /* queue : current, max, limit */
724 "<td align=right>%d</td><td align=right>%d</td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +0200725 /* sessions : current, max, limit, cumul */
Willy Tarreau55bb8452007-10-17 18:44:57 +0200726 "<td align=right>%d</td><td align=right>%d</td>"
727 "<td align=right>%s</td><td align=right>%d</td>"
Willy Tarreau91861262007-10-17 17:06:05 +0200728 /* bytes : in, out */
729 "<td align=right>%lld</td><td align=right>%lld</td>"
730 /* denied: req, resp */
731 "<td align=right></td><td align=right>%d</td>"
732 /* errors : request, connect, response */
733 "<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200734 /* warnings: retries, redispatches */
735 "<td align=right>%d</td><td align=right></td>"
Willy Tarreau91861262007-10-17 17:06:05 +0200736 "",
737 (sv->state & SRV_BACKUP) ? "backup" : "active",
738 sv_state, sv->id,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200739 sv->nbpend, sv->nbpend_max, LIM2A0(sv->maxqueue, "-"),
740 sv->cur_sess, sv->cur_sess_max, LIM2A1(sv->maxconn, "-"), sv->cum_sess,
Willy Tarreau91861262007-10-17 17:06:05 +0200741 sv->bytes_in, sv->bytes_out,
742 sv->failed_secu,
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200743 sv->failed_conns, sv->failed_resp,
744 sv->retries);
Willy Tarreau91861262007-10-17 17:06:05 +0200745
Willy Tarreau55bb8452007-10-17 18:44:57 +0200746 /* status */
747 chunk_printf(&msg, sizeof(trash), "<td nowrap>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200748
749 if (sv->state & SRV_CHECKED)
750 chunk_printf(&msg, sizeof(trash), "%s ",
751 human_time(now.tv_sec - sv->last_change, 1));
752
Willy Tarreau55bb8452007-10-17 18:44:57 +0200753 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200754 srv_hlt_st[sv_state],
755 (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health),
756 (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise));
757
Willy Tarreau55bb8452007-10-17 18:44:57 +0200758 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200759 /* weight */
760 "</td><td>%d</td>"
761 /* act, bck */
762 "<td>%s</td><td>%s</td>"
763 "",
Willy Tarreau5dc2fa62007-11-19 19:10:18 +0100764 sv->eweight * px->lbprm.wmult / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +0200765 (sv->state & SRV_BACKUP) ? "-" : "Y",
766 (sv->state & SRV_BACKUP) ? "Y" : "-");
767
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200768 /* check failures: unique, fatal, down time */
Willy Tarreau55bb8452007-10-17 18:44:57 +0200769 if (sv->state & SRV_CHECKED)
770 chunk_printf(&msg, sizeof(trash),
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200771 "<td align=right>%d</td><td align=right>%d</td>"
772 "<td nowrap align=right>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100773 "",
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200774 sv->failed_checks, sv->down_trans,
775 human_time(srv_downtime(sv), 1));
Willy Tarreau55bb8452007-10-17 18:44:57 +0200776 else
777 chunk_printf(&msg, sizeof(trash),
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100778 "<td colspan=3></td>");
779
780 /* throttle */
781 if ((sv->state & SRV_WARMINGUP) &&
782 now.tv_sec < sv->last_change + sv->slowstart &&
783 now.tv_sec >= sv->last_change) {
784 unsigned int ratio;
785 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
786 chunk_printf(&msg, sizeof(trash),
787 "<td>%d %%</td></tr>\n", ratio);
788 } else {
789 chunk_printf(&msg, sizeof(trash),
790 "<td>-</td></tr>\n");
791 }
Willy Tarreau55bb8452007-10-17 18:44:57 +0200792 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +0100793 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
794 "UP %d/%d,", "UP,",
795 "NOLB %d/%d,", "NOLB,",
796 "no check," };
Willy Tarreau55bb8452007-10-17 18:44:57 +0200797 chunk_printf(&msg, sizeof(trash),
798 /* pxid, name */
799 "%s,%s,"
800 /* queue : current, max */
801 "%d,%d,"
802 /* sessions : current, max, limit, cumul */
803 "%d,%d,%s,%d,"
804 /* bytes : in, out */
805 "%lld,%lld,"
806 /* denied: req, resp */
807 ",%d,"
808 /* errors : request, connect, response */
809 ",%d,%d,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200810 /* warnings: retries, redispatches */
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200811 "%d,,"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200812 "",
813 px->id, sv->id,
814 sv->nbpend, sv->nbpend_max,
Willy Tarreaudcd47712007-11-04 23:35:08 +0100815 sv->cur_sess, sv->cur_sess_max, LIM2A0(sv->maxconn, ""), sv->cum_sess,
Willy Tarreau55bb8452007-10-17 18:44:57 +0200816 sv->bytes_in, sv->bytes_out,
817 sv->failed_secu,
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200818 sv->failed_conns, sv->failed_resp,
819 sv->retries);
Willy Tarreau55bb8452007-10-17 18:44:57 +0200820
821 /* status */
822 chunk_printf(&msg, sizeof(trash),
823 srv_hlt_st[sv_state],
824 (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health),
825 (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise));
Willy Tarreau91861262007-10-17 17:06:05 +0200826
Willy Tarreau55bb8452007-10-17 18:44:57 +0200827 chunk_printf(&msg, sizeof(trash),
828 /* weight, active, backup */
829 "%d,%d,%d,"
830 "",
Willy Tarreau5dc2fa62007-11-19 19:10:18 +0100831 sv->eweight * px->lbprm.wmult / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +0200832 (sv->state & SRV_BACKUP) ? 0 : 1,
833 (sv->state & SRV_BACKUP) ? 1 : 0);
834
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200835 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +0200836 if (sv->state & SRV_CHECKED)
837 chunk_printf(&msg, sizeof(trash),
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200838 "%d,%d,%d,%d,",
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200839 sv->failed_checks, sv->down_trans,
840 now.tv_sec - sv->last_change, srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +0200841 else
842 chunk_printf(&msg, sizeof(trash),
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200843 ",,,,");
844
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100845 /* queue limit, pid, iid, sid, */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200846 chunk_printf(&msg, sizeof(trash),
Willy Tarreaudcd47712007-11-04 23:35:08 +0100847 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100848 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +0100849 LIM2A0(sv->maxqueue, ""),
850 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100851
852 /* throttle */
853 if ((sv->state & SRV_WARMINGUP) &&
854 now.tv_sec < sv->last_change + sv->slowstart &&
855 now.tv_sec >= sv->last_change) {
856 unsigned int ratio;
857 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
858 chunk_printf(&msg, sizeof(trash), "%d", ratio);
859 }
860
861 /* ',' then EOL */
862 chunk_printf(&msg, sizeof(trash), ",\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +0200863 }
Willy Tarreau91861262007-10-17 17:06:05 +0200864 if (buffer_write_chunk(rep, &msg) != 0)
865 return 0;
866
867 s->data_ctx.stats.sv = sv->next;
868 } /* while sv */
869
870 s->data_ctx.stats.px_st = DATA_ST_PX_BE;
871 /* fall through */
872
873 case DATA_ST_PX_BE:
874 /* print the backend */
875 if (px->cap & PR_CAP_BE) {
Willy Tarreau55bb8452007-10-17 18:44:57 +0200876 if (flags & STAT_FMT_HTML) {
877 chunk_printf(&msg, sizeof(trash),
Willy Tarreau91861262007-10-17 17:06:05 +0200878 /* name */
879 "<tr align=center class=\"backend\"><td>Backend</td>"
880 /* queue : current, max */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200881 "<td align=right>%d</td><td align=right>%d</td><td></td>"
Willy Tarreau91861262007-10-17 17:06:05 +0200882 /* sessions : current, max, limit, cumul. */
883 "<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>"
884 /* bytes : in, out */
885 "<td align=right>%lld</td><td align=right>%lld</td>"
886 /* denied: req, resp */
887 "<td align=right>%d</td><td align=right>%d</td>"
888 /* errors : request, connect, response */
889 "<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200890 /* warnings: retries, redispatches */
891 "<td align=right>%d</td><td align=right>%d</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200892 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +0200893 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200894 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +0200895 * active and backups. */
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200896 "<td align=center nowrap>%s %s</td><td align=center>%d</td>"
897 "<td align=center>%d</td><td align=center>%d</td>",
Willy Tarreau91861262007-10-17 17:06:05 +0200898 px->nbpend /* or px->totpend ? */, px->nbpend_max,
899 px->beconn, px->beconn_max, px->fullconn, px->cum_beconn,
900 px->bytes_in, px->bytes_out,
901 px->denied_req, px->denied_resp,
902 px->failed_conns, px->failed_resp,
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200903 px->retries, px->redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200904 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +0100905 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
906 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5dc2fa62007-11-19 19:10:18 +0100907 px->lbprm.tot_weight * px->lbprm.wmult / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +0100908 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200909
910 chunk_printf(&msg, sizeof(trash),
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100911 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200912 "<td align=center>&nbsp;</td><td align=\"right\">%d</td>"
913 "<td align=\"right\" nowrap>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100914 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200915 "</tr>",
916 px->down_trans,
917 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +0200918 } else {
919 chunk_printf(&msg, sizeof(trash),
920 /* pxid, name */
921 "%s,BACKEND,"
922 /* queue : current, max */
923 "%d,%d,"
924 /* sessions : current, max, limit, cumul */
925 "%d,%d,%d,%d,"
926 /* bytes : in, out */
927 "%lld,%lld,"
928 /* denied: req, resp */
929 "%d,%d,"
930 /* errors : request, connect, response */
931 ",%d,%d,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200932 /* warnings: retries, redispatches */
933 "%d,%d,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200934 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +0200935 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200936 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +0200937 * active and backups. */
938 "%s,"
939 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100940 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200941 ",%d,%d,%d,,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100942 /* pid, iid, sid, throttle, */
943 "%d,%d,0,,"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200944 "\n",
945 px->id,
946 px->nbpend /* or px->totpend ? */, px->nbpend_max,
947 px->beconn, px->beconn_max, px->fullconn, px->cum_beconn,
948 px->bytes_in, px->bytes_out,
949 px->denied_req, px->denied_resp,
950 px->failed_conns, px->failed_resp,
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200951 px->retries, px->redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +0100952 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5dc2fa62007-11-19 19:10:18 +0100953 px->lbprm.tot_weight * px->lbprm.wmult / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +0100954 px->srv_act, px->srv_bck,
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200955 px->down_trans, now.tv_sec - px->last_change,
Willy Tarreau20697042007-11-15 23:26:18 +0100956 px->srv?be_downtime(px):0,
Willy Tarreaudcd47712007-11-04 23:35:08 +0100957 relative_pid, px->uuid);
Willy Tarreau55bb8452007-10-17 18:44:57 +0200958 }
Willy Tarreau91861262007-10-17 17:06:05 +0200959 if (buffer_write_chunk(rep, &msg) != 0)
960 return 0;
961 }
962
963 s->data_ctx.stats.px_st = DATA_ST_PX_END;
964 /* fall through */
965
966 case DATA_ST_PX_END:
Willy Tarreau55bb8452007-10-17 18:44:57 +0200967 if (flags & STAT_FMT_HTML) {
968 chunk_printf(&msg, sizeof(trash), "</table><p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +0200969
Willy Tarreau55bb8452007-10-17 18:44:57 +0200970 if (buffer_write_chunk(rep, &msg) != 0)
971 return 0;
972 }
Willy Tarreau91861262007-10-17 17:06:05 +0200973
974 s->data_ctx.stats.px_st = DATA_ST_PX_FIN;
975 /* fall through */
976
977 case DATA_ST_PX_FIN:
978 return 1;
979
980 default:
981 /* unknown state, we should put an abort() here ! */
982 return 1;
983 }
984}
985
986/*
987 * Local variables:
988 * c-indent-level: 8
989 * c-basic-offset: 8
990 * End:
991 */