2
* Functions dedicated to statistics output
4
* Copyright 2000-2007 Willy Tarreau <w@1wt.eu>
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.
22
#include <sys/socket.h>
24
#include <sys/types.h>
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>
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>
42
#include <proto/backend.h>
43
#include <proto/buffers.h>
44
#include <proto/dumpstats.h>
46
#include <proto/proto_uxst.h>
47
#include <proto/senddata.h>
48
#include <proto/session.h>
49
#include <proto/server.h>
51
/* 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".
57
int stats_parse_global(const char **args, char *err, int errlen)
59
if (!strcmp(args[0], "socket")) {
60
struct sockaddr_un su;
64
snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket");
68
if (global.stats_sock.state != LI_NEW) {
69
snprintf(err, errlen, "'stats socket' already specified in global section");
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
78
global.stats_sock.state = LI_INIT;
79
global.stats_sock.options = LI_O_NONE;
80
global.stats_sock.accept = uxst_event_accept;
81
global.stats_sock.handler = process_uxst_stats;
82
global.stats_sock.private = NULL;
85
while (*args[cur_arg]) {
86
if (!strcmp(args[cur_arg], "uid")) {
87
global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]);
90
else if (!strcmp(args[cur_arg], "gid")) {
91
global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]);
94
else if (!strcmp(args[cur_arg], "mode")) {
95
global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
98
else if (!strcmp(args[cur_arg], "user")) {
100
user = getpwnam(args[cur_arg + 1]);
102
snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')",
106
global.stats_sock.perm.ux.uid = user->pw_uid;
109
else if (!strcmp(args[cur_arg], "group")) {
111
group = getgrnam(args[cur_arg + 1]);
113
snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')",
117
global.stats_sock.perm.ux.gid = group->gr_gid;
121
snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', and 'mode'");
126
uxst_add_listener(&global.stats_sock);
129
else if (!strcmp(args[0], "timeout")) {
131
const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS);
134
snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res);
139
snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'");
142
__tv_from_ms(&global.stats_timeout, timeout);
144
else if (!strcmp(args[0], "maxconn")) {
145
int maxconn = atol(args[1]);
148
snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'");
151
global.maxsock -= global.stats_sock.maxconn;
152
global.stats_sock.maxconn = maxconn;
153
global.maxsock += global.stats_sock.maxconn;
156
snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section");
162
int print_csv_header(struct chunk *msg, int size)
164
return chunk_printf(msg, size,
167
"scur,smax,slim,stot,"
172
"status,weight,act,bck,"
173
"chkfail,chkdown,lastchg,downtime,qlimit,"
174
"pid,iid,sid,throttle,lbtot,"
179
* Produces statistics data for the session <s>. Expects to be called with
180
* s->cli_state == CL_STSHUTR. It *may* make use of informations from <uri>
182
* It returns 0 if it had to stop writing data and an I/O is needed, 1 if the
183
* dump is finished and the session must be closed, or -1 in case of any error.
185
int stats_dump_raw(struct session *s, struct uri_auth *uri, int flags)
187
struct buffer *rep = s->rep;
195
switch (s->data_state) {
197
/* the function had not been called yet, let's prepare the
198
* buffer for a response.
200
client_retnclose(s, &msg);
201
s->data_state = DATA_ST_HEAD;
205
if (flags & STAT_SHOW_STAT) {
206
print_csv_header(&msg, sizeof(trash));
207
if (buffer_write_chunk(rep, &msg) != 0)
211
s->data_state = DATA_ST_INFO;
215
up = (now.tv_sec - start_date.tv_sec);
216
memset(&s->data_ctx, 0, sizeof(s->data_ctx));
218
if (flags & STAT_SHOW_INFO) {
219
chunk_printf(&msg, sizeof(trash),
220
"Name: " PRODUCT_NAME "\n"
221
"Version: " HAPROXY_VERSION "\n"
222
"Release_date: " HAPROXY_DATE "\n"
226
"Uptime: %dd %dh%02dm%02ds\n"
237
up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
239
global.rlimit_memmax,
240
global.rlimit_nofile,
245
if (buffer_write_chunk(rep, &msg) != 0)
249
s->data_ctx.stats.px = proxy;
250
s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
251
s->data_state = DATA_ST_LIST;
256
if (flags & STAT_SHOW_STAT) {
257
while (s->data_ctx.stats.px) {
258
px = s->data_ctx.stats.px;
259
/* skip the disabled proxies and non-networked ones */
260
if (px->state != PR_STSTOPPED &&
261
(px->cap & (PR_CAP_FE | PR_CAP_BE)))
262
if (stats_dump_proxy(s, px, NULL, 0) == 0)
265
s->data_ctx.stats.px = px->next;
266
s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
268
/* here, we just have reached the last proxy */
271
s->data_state = DATA_ST_END;
275
s->data_state = DATA_ST_FIN;
282
/* unknown state ! */
289
* Produces statistics data for the session <s>. Expects to be called with
290
* s->cli_state == CL_STSHUTR. It stops by itself by unsetting the SN_SELF_GEN
291
* flag from the session, which it uses to keep on being called when there is
292
* free space in the buffer, of simply by letting an empty buffer upon return.
293
* It returns 0 if it had to stop writing data and an I/O is needed, 1 if the
294
* dump is finished and the session must be closed, or -1 in case of any error.
296
int stats_dump_http(struct session *s, struct uri_auth *uri, int flags)
298
struct buffer *rep = s->rep;
306
switch (s->data_state) {
308
/* the function had not been called yet */
309
s->flags |= SN_SELF_GEN; // more data will follow
311
chunk_printf(&msg, sizeof(trash),
312
"HTTP/1.0 200 OK\r\n"
313
"Cache-Control: no-cache\r\n"
314
"Connection: close\r\n"
315
"Content-Type: %s\r\n",
316
(flags & STAT_FMT_HTML) ? "text/html" : "text/plain");
318
if (uri->refresh > 0 && !(s->flags & SN_STAT_NORFRSH))
319
chunk_printf(&msg, sizeof(trash), "Refresh: %d\r\n",
322
chunk_printf(&msg, sizeof(trash), "\r\n");
325
client_retnclose(s, &msg); // send the start of the response.
328
if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
329
s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
330
if (!(s->flags & SN_FINST_MASK))
331
s->flags |= SN_FINST_R;
333
if (s->txn.meth == HTTP_METH_HEAD) {
334
/* that's all we return in case of HEAD request */
335
s->data_state = DATA_ST_FIN;
336
s->flags &= ~SN_SELF_GEN;
340
s->data_state = DATA_ST_HEAD; /* let's start producing data */
344
if (flags & STAT_FMT_HTML) {
345
/* WARNING! This must fit in the first buffer !!! */
346
chunk_printf(&msg, sizeof(trash),
347
"<html><head><title>Statistics Report for " PRODUCT_NAME "</title>\n"
348
"<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
349
"<style type=\"text/css\"><!--\n"
351
" font-family: helvetica, arial;"
353
" font-weight: normal;"
355
" background: white;"
362
" font-size: xx-large;"
363
" margin-bottom: 0.5em;"
366
" font-family: helvetica, arial;"
367
" font-size: x-large;"
368
" font-weight: bold;"
369
" font-style: italic;"
372
" margin-bottom: 0em;"
375
" font-family: helvetica, arial;"
377
" font-weight: bold;"
379
" background: #e8e8d0;"
381
" margin-bottom: 0em;"
384
" margin-top: 0.25em;"
385
" margin-right: 2em;"
387
".hr {margin-top: 0.25em;"
388
" border-color: black;"
389
" border-bottom-style: solid;"
391
".pxname {background: #b00040;color: #ffff40;font-weight: bold;}\n"
392
".titre {background: #20D0D0;color: #000000;font-weight: bold;}\n"
393
".total {background: #20D0D0;color: #ffff80;}\n"
394
".frontend {background: #e8e8d0;}\n"
395
".backend {background: #e8e8d0;}\n"
396
".active0 {background: #ff9090;}\n"
397
".active1 {background: #ffd020;}\n"
398
".active2 {background: #ffffa0;}\n"
399
".active3 {background: #c0ffc0;}\n"
400
".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
401
".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
402
".active6 {background: #e0e0e0;}\n"
403
".backup0 {background: #ff9090;}\n"
404
".backup1 {background: #ff80ff;}\n"
405
".backup2 {background: #c060ff;}\n"
406
".backup3 {background: #b0d0ff;}\n"
407
".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
408
".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
409
".backup6 {background: #e0e0e0;}\n"
410
"table.tbl { border-collapse: collapse; border-style: none;}\n"
411
"table.tbl td { border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray;}\n"
412
"table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
413
"table.tbl th.empty { border-style: none; empty-cells: hide;}\n"
414
"table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
415
"table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
416
"table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
418
"</style></head>\n");
420
print_csv_header(&msg, sizeof(trash));
422
if (buffer_write_chunk(rep, &msg) != 0)
425
s->data_state = DATA_ST_INFO;
429
up = (now.tv_sec - start_date.tv_sec);
431
/* WARNING! this has to fit the first packet too.
432
* We are around 3.5 kB, add adding entries will
433
* become tricky if we want to support 4kB buffers !
435
if (flags & STAT_FMT_HTML) {
436
chunk_printf(&msg, sizeof(trash),
437
"<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
438
PRODUCT_NAME "%s</a></h1>\n"
439
"<h2>Statistics Report for pid %d</h2>\n"
440
"<hr width=\"100%%\" class=\"hr\">\n"
441
"<h3>> General process information</h3>\n"
442
"<table border=0 cols=4><tr><td align=\"left\" nowrap width=\"1%%\">\n"
443
"<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
444
"<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
445
"<b>system limits :</b> memmax = %s%s ; ulimit-n = %d<br>\n"
446
"<b>maxsock = </b> %d<br>\n"
447
"<b>maxconn = </b> %d (current conns = %d)<br>\n"
448
"</td><td align=\"center\" nowrap>\n"
449
"<table class=\"lgd\"><tr>\n"
450
"<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>"
451
"<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>"
453
"<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
454
"<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
456
"<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
457
"<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
459
"<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>"
460
"<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
462
"Note: UP with load-balancing disabled is reported as \"NOLB\"."
464
"<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
465
"<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
467
(uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
469
relative_pid, global.nbproc,
470
up / 86400, (up % 86400) / 3600,
471
(up % 3600) / 60, (up % 60),
472
global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
473
global.rlimit_memmax ? " MB" : "",
474
global.rlimit_nofile,
480
if (s->flags & SN_STAT_HIDEDWN)
481
chunk_printf(&msg, sizeof(trash),
482
"<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
485
(s->flags & SN_STAT_NORFRSH) ? ";norefresh" : "");
487
chunk_printf(&msg, sizeof(trash),
488
"<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
491
(s->flags & SN_STAT_NORFRSH) ? ";norefresh" : "");
493
if (uri->refresh > 0) {
494
if (s->flags & SN_STAT_NORFRSH)
495
chunk_printf(&msg, sizeof(trash),
496
"<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
498
(s->flags & SN_STAT_HIDEDWN) ? ";up" : "",
501
chunk_printf(&msg, sizeof(trash),
502
"<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
504
(s->flags & SN_STAT_HIDEDWN) ? ";up" : "",
508
chunk_printf(&msg, sizeof(trash),
509
"<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
511
(s->flags & SN_STAT_HIDEDWN) ? ";up" : "",
512
(s->flags & SN_STAT_NORFRSH) ? ";norefresh" : "");
514
chunk_printf(&msg, sizeof(trash),
515
"<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
517
(uri->refresh > 0) ? ";norefresh" : "");
519
chunk_printf(&msg, sizeof(trash),
521
"<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
522
"<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n"
523
"<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
524
"<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
525
"<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
532
if (buffer_write_chunk(rep, &msg) != 0)
536
memset(&s->data_ctx, 0, sizeof(s->data_ctx));
538
s->data_ctx.stats.px = proxy;
539
s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
540
s->data_state = DATA_ST_LIST;
545
while (s->data_ctx.stats.px) {
546
px = s->data_ctx.stats.px;
547
/* skip the disabled proxies and non-networked ones */
548
if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
549
if (stats_dump_proxy(s, px, uri, flags) == 0)
552
s->data_ctx.stats.px = px->next;
553
s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
555
/* here, we just have reached the last proxy */
557
s->data_state = DATA_ST_END;
561
if (flags & STAT_FMT_HTML) {
562
chunk_printf(&msg, sizeof(trash), "</body></html>\n");
563
if (buffer_write_chunk(rep, &msg) != 0)
567
s->data_state = DATA_ST_FIN;
571
s->flags &= ~SN_SELF_GEN;
575
/* unknown state ! */
576
s->flags &= ~SN_SELF_GEN;
583
* Dumps statistics for a proxy.
584
* Returns 0 if it had to stop dumping data because of lack of buffer space,
585
* ot non-zero if everything completed.
587
int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, int flags)
589
struct buffer *rep = s->rep;
596
switch (s->data_ctx.stats.px_st) {
597
case DATA_ST_PX_INIT:
598
/* we are on a new proxy */
600
if (uri && uri->scope) {
601
/* we have a limited scope, we have to check the proxy name */
602
struct stat_scope *scope;
605
len = strlen(px->id);
609
/* match exact proxy name */
610
if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
613
/* match '.' which means 'self' proxy */
614
if (!strcmp(scope->px_id, ".") && px == s->be)
619
/* proxy name not found : don't dump anything */
624
s->data_ctx.stats.px_st = DATA_ST_PX_TH;
628
if (flags & STAT_FMT_HTML) {
629
/* print a new table */
630
chunk_printf(&msg, sizeof(trash),
631
"<table cols=\"26\" class=\"tbl\" width=\"100%%\">\n"
632
"<tr align=\"center\" class=\"titre\">"
633
"<th colspan=2 class=\"pxname\">%s</th>"
634
"<th colspan=24 class=\"empty\"></th>"
636
"<tr align=\"center\" class=\"titre\">"
637
"<th rowspan=2></th>"
638
"<th colspan=3>Queue</th><th colspan=5>Sessions</th>"
639
"<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
640
"<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
641
"<th colspan=8>Server</th>"
643
"<tr align=\"center\" class=\"titre\">"
644
"<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
645
"<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
646
"<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
647
"<th>Resp</th><th>Retr</th><th>Redis</th>"
648
"<th>Status</th><th>Wght</th><th>Act</th>"
649
"<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
654
if (buffer_write_chunk(rep, &msg) != 0)
658
s->data_ctx.stats.px_st = DATA_ST_PX_FE;
662
/* print the frontend */
663
if (px->cap & PR_CAP_FE) {
664
if (flags & STAT_FMT_HTML) {
665
chunk_printf(&msg, sizeof(trash),
667
"<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=3></td>"
668
/* sessions : current, max, limit, total, lbtot */
669
"<td align=right>%d</td><td align=right>%d</td>"
670
"<td align=right>%d</td><td align=right>%d</td>"
671
"<td align=right></td>"
672
/* bytes : in, out */
673
"<td align=right>%lld</td><td align=right>%lld</td>"
674
/* denied: req, resp */
675
"<td align=right>%d</td><td align=right>%d</td>"
676
/* errors : request, connect, response */
677
"<td align=right>%d</td><td align=right></td><td align=right></td>"
678
/* warnings: retries, redispatches */
679
"<td align=right></td><td align=right></td>"
680
/* server status : reflect frontend status */
681
"<td align=center>%s</td>"
682
/* rest of server: nothing */
683
"<td align=center colspan=7></td></tr>"
685
px->feconn, px->feconn_max, px->maxconn, px->cum_feconn,
686
px->bytes_in, px->bytes_out,
687
px->denied_req, px->denied_resp,
689
px->state == PR_STRUN ? "OPEN" :
690
px->state == PR_STIDLE ? "FULL" : "STOP");
692
chunk_printf(&msg, sizeof(trash),
693
/* pxid, name, queue cur, queue max, */
695
/* sessions : current, max, limit, total */
697
/* bytes : in, out */
699
/* denied: req, resp */
701
/* errors : request, connect, response */
703
/* warnings: retries, redispatches */
705
/* server status : reflect frontend status */
707
/* rest of server: nothing */
709
/* pid, iid, sid, throttle, lbtot, */
713
px->feconn, px->feconn_max, px->maxconn, px->cum_feconn,
714
px->bytes_in, px->bytes_out,
715
px->denied_req, px->denied_resp,
717
px->state == PR_STRUN ? "OPEN" :
718
px->state == PR_STIDLE ? "FULL" : "STOP",
719
relative_pid, px->uuid);
722
if (buffer_write_chunk(rep, &msg) != 0)
726
s->data_ctx.stats.sv = px->srv; /* may be NULL */
727
s->data_ctx.stats.px_st = DATA_ST_PX_SV;
731
/* stats.sv has been initialized above */
732
while (s->data_ctx.stats.sv != NULL) {
733
int sv_state; /* 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, 6=unchecked */
735
sv = s->data_ctx.stats.sv;
737
/* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
738
if (!(sv->state & SRV_CHECKED))
740
else if (sv->state & SRV_RUNNING) {
741
if (sv->health == sv->rise + sv->fall - 1)
742
sv_state = 3; /* UP */
744
sv_state = 2; /* going down */
746
if (sv->state & SRV_GOINGDOWN)
751
sv_state = 1; /* going up */
753
sv_state = 0; /* DOWN */
755
if ((sv_state == 0) && (s->flags & SN_STAT_HIDEDWN)) {
756
/* do not report servers which are DOWN */
757
s->data_ctx.stats.sv = sv->next;
761
if (flags & STAT_FMT_HTML) {
762
static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d ↑",
763
"UP %d/%d ↓", "UP",
764
"NOLB %d/%d ↓", "NOLB",
766
chunk_printf(&msg, sizeof(trash),
768
"<tr align=\"center\" class=\"%s%d\"><td>%s</td>"
769
/* queue : current, max, limit */
770
"<td align=right>%d</td><td align=right>%d</td><td align=right>%s</td>"
771
/* sessions : current, max, limit, total, lbtot */
772
"<td align=right>%d</td><td align=right>%d</td>"
773
"<td align=right>%s</td><td align=right>%d</td>"
774
"<td align=right>%d</td>"
775
/* bytes : in, out */
776
"<td align=right>%lld</td><td align=right>%lld</td>"
777
/* denied: req, resp */
778
"<td align=right></td><td align=right>%d</td>"
779
/* errors : request, connect, response */
780
"<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n"
781
/* warnings: retries, redispatches */
782
"<td align=right>%d</td><td align=right></td>"
784
(sv->state & SRV_BACKUP) ? "backup" : "active",
786
sv->nbpend, sv->nbpend_max, LIM2A0(sv->maxqueue, "-"),
787
sv->cur_sess, sv->cur_sess_max, LIM2A1(sv->maxconn, "-"),
788
sv->cum_sess, sv->cum_lbconn,
789
sv->bytes_in, sv->bytes_out,
791
sv->failed_conns, sv->failed_resp,
795
chunk_printf(&msg, sizeof(trash), "<td nowrap>");
797
if (sv->state & SRV_CHECKED)
798
chunk_printf(&msg, sizeof(trash), "%s ",
799
human_time(now.tv_sec - sv->last_change, 1));
801
chunk_printf(&msg, sizeof(trash),
802
srv_hlt_st[sv_state],
803
(sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health),
804
(sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise));
806
chunk_printf(&msg, sizeof(trash),
810
"<td>%s</td><td>%s</td>"
812
(sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
813
(sv->state & SRV_BACKUP) ? "-" : "Y",
814
(sv->state & SRV_BACKUP) ? "Y" : "-");
816
/* check failures: unique, fatal, down time */
817
if (sv->state & SRV_CHECKED)
818
chunk_printf(&msg, sizeof(trash),
819
"<td align=right>%d</td><td align=right>%d</td>"
820
"<td nowrap align=right>%s</td>"
822
sv->failed_checks, sv->down_trans,
823
human_time(srv_downtime(sv), 1));
825
chunk_printf(&msg, sizeof(trash),
826
"<td colspan=3></td>");
829
if ((sv->state & SRV_WARMINGUP) &&
830
now.tv_sec < sv->last_change + sv->slowstart &&
831
now.tv_sec >= sv->last_change) {
833
ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
834
chunk_printf(&msg, sizeof(trash),
835
"<td>%d %%</td></tr>\n", ratio);
837
chunk_printf(&msg, sizeof(trash),
838
"<td>-</td></tr>\n");
841
static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
843
"NOLB %d/%d,", "NOLB,",
845
chunk_printf(&msg, sizeof(trash),
848
/* queue : current, max */
850
/* sessions : current, max, limit, total */
852
/* bytes : in, out */
854
/* denied: req, resp */
856
/* errors : request, connect, response */
858
/* warnings: retries, redispatches */
862
sv->nbpend, sv->nbpend_max,
863
sv->cur_sess, sv->cur_sess_max, LIM2A0(sv->maxconn, ""), sv->cum_sess,
864
sv->bytes_in, sv->bytes_out,
866
sv->failed_conns, sv->failed_resp,
870
chunk_printf(&msg, sizeof(trash),
871
srv_hlt_st[sv_state],
872
(sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health),
873
(sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise));
875
chunk_printf(&msg, sizeof(trash),
876
/* weight, active, backup */
879
(sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
880
(sv->state & SRV_BACKUP) ? 0 : 1,
881
(sv->state & SRV_BACKUP) ? 1 : 0);
883
/* check failures: unique, fatal; last change, total downtime */
884
if (sv->state & SRV_CHECKED)
885
chunk_printf(&msg, sizeof(trash),
887
sv->failed_checks, sv->down_trans,
888
now.tv_sec - sv->last_change, srv_downtime(sv));
890
chunk_printf(&msg, sizeof(trash),
893
/* queue limit, pid, iid, sid, */
894
chunk_printf(&msg, sizeof(trash),
897
LIM2A0(sv->maxqueue, ""),
898
relative_pid, px->uuid, sv->puid);
901
if ((sv->state & SRV_WARMINGUP) &&
902
now.tv_sec < sv->last_change + sv->slowstart &&
903
now.tv_sec >= sv->last_change) {
905
ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
906
chunk_printf(&msg, sizeof(trash), "%d", ratio);
909
/* sessions: lbtot */
910
chunk_printf(&msg, sizeof(trash), ",%d", sv->cum_lbconn);
912
chunk_printf(&msg, sizeof(trash), ",\n");
914
if (buffer_write_chunk(rep, &msg) != 0)
917
s->data_ctx.stats.sv = sv->next;
920
s->data_ctx.stats.px_st = DATA_ST_PX_BE;
924
/* print the backend */
925
if (px->cap & PR_CAP_BE) {
926
if (flags & STAT_FMT_HTML) {
927
chunk_printf(&msg, sizeof(trash),
929
"<tr align=center class=\"backend\"><td>Backend</td>"
930
/* queue : current, max */
931
"<td align=right>%d</td><td align=right>%d</td><td></td>"
932
/* sessions : current, max, limit, total, lbtot */
933
"<td align=right>%d</td><td align=right>%d</td>"
934
"<td align=right>%d</td><td align=right>%d</td>"
935
"<td align=right>%d</td>"
936
/* bytes : in, out */
937
"<td align=right>%lld</td><td align=right>%lld</td>"
938
/* denied: req, resp */
939
"<td align=right>%d</td><td align=right>%d</td>"
940
/* errors : request, connect, response */
941
"<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n"
942
/* warnings: retries, redispatches */
943
"<td align=right>%d</td><td align=right>%d</td>"
944
/* backend status: reflect backend status (up/down): we display UP
945
* if the backend has known working servers or if it has no server at
946
* all (eg: for stats). Then we display the total weight, number of
947
* active and backups. */
948
"<td align=center nowrap>%s %s</td><td align=center>%d</td>"
949
"<td align=center>%d</td><td align=center>%d</td>",
950
px->nbpend /* or px->totpend ? */, px->nbpend_max,
951
px->beconn, px->beconn_max, px->fullconn, px->cum_beconn, px->cum_lbconn,
952
px->bytes_in, px->bytes_out,
953
px->denied_req, px->denied_resp,
954
px->failed_conns, px->failed_resp,
955
px->retries, px->redispatches,
956
human_time(now.tv_sec - px->last_change, 1),
957
(px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
958
"<font color=\"red\"><b>DOWN</b></font>",
959
(px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
960
px->srv_act, px->srv_bck);
962
chunk_printf(&msg, sizeof(trash),
963
/* rest of backend: nothing, down transitions, total downtime, throttle */
964
"<td align=center> </td><td align=\"right\">%d</td>"
965
"<td align=\"right\" nowrap>%s</td>"
969
px->srv?human_time(be_downtime(px), 1):" ");
971
chunk_printf(&msg, sizeof(trash),
974
/* queue : current, max */
976
/* sessions : current, max, limit, total */
978
/* bytes : in, out */
980
/* denied: req, resp */
982
/* errors : request, connect, response */
984
/* warnings: retries, redispatches */
986
/* backend status: reflect backend status (up/down): we display UP
987
* if the backend has known working servers or if it has no server at
988
* all (eg: for stats). Then we display the total weight, number of
989
* active and backups. */
992
/* rest of backend: nothing, down transitions, last change, total downtime */
994
/* pid, iid, sid, throttle, lbtot, */
998
px->nbpend /* or px->totpend ? */, px->nbpend_max,
999
px->beconn, px->beconn_max, px->fullconn, px->cum_beconn,
1000
px->bytes_in, px->bytes_out,
1001
px->denied_req, px->denied_resp,
1002
px->failed_conns, px->failed_resp,
1003
px->retries, px->redispatches,
1004
(px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
1005
(px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
1006
px->srv_act, px->srv_bck,
1007
px->down_trans, now.tv_sec - px->last_change,
1008
px->srv?be_downtime(px):0,
1009
relative_pid, px->uuid,
1012
if (buffer_write_chunk(rep, &msg) != 0)
1016
s->data_ctx.stats.px_st = DATA_ST_PX_END;
1019
case DATA_ST_PX_END:
1020
if (flags & STAT_FMT_HTML) {
1021
chunk_printf(&msg, sizeof(trash), "</table><p>\n");
1023
if (buffer_write_chunk(rep, &msg) != 0)
1027
s->data_ctx.stats.px_st = DATA_ST_PX_FIN;
1030
case DATA_ST_PX_FIN:
1034
/* unknown state, we should put an abort() here ! */