blob: 510d0d25f790333409701cdf0554d478cd07a87f [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[] =
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020056 "Unknown command. Please enter one of the following commands only :\n"
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +020057 " clear counters : clear max statistics counters (add 'all' for all counters)\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020058 " help : this message\n"
59 " prompt : toggle interactive mode with prompt\n"
60 " quit : disconnect\n"
61 " show info : report information about the running process\n"
62 " show stat : report counters for each proxy and server\n"
63 " show errors : report last request and response errors for each proxy\n"
64 " show sess : report the list of current sessions\n"
Willy Tarreau38338fa2009-10-10 18:37:29 +020065 " get weight : report a server's current weight\n"
Willy Tarreau4483d432009-10-10 19:30:08 +020066 " set weight : change a server's weight\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020067 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +020068
Willy Tarreau6162db22009-10-10 17:13:00 +020069const char stats_permission_denied_msg[] =
70 "Permission denied\n"
71 "";
72
Willy Tarreaufbee7132007-10-18 13:53:22 +020073/* This function parses a "stats" statement in the "global" section. It returns
74 * -1 if there is any error, otherwise zero. If it returns -1, it may write an
75 * error message into ther <err> buffer, for at most <errlen> bytes, trailing
76 * zero included. The trailing '\n' must not be written. The function must be
77 * called with <args> pointing to the first word after "stats".
78 */
Willy Tarreau10522fd2008-07-09 20:12:41 +020079static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
80 struct proxy *defpx, char *err, int errlen)
Willy Tarreaufbee7132007-10-18 13:53:22 +020081{
Willy Tarreau10522fd2008-07-09 20:12:41 +020082 args++;
Willy Tarreaufbee7132007-10-18 13:53:22 +020083 if (!strcmp(args[0], "socket")) {
84 struct sockaddr_un su;
85 int cur_arg;
86
87 if (*args[1] == 0) {
88 snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket");
89 return -1;
90 }
91
92 if (global.stats_sock.state != LI_NEW) {
93 snprintf(err, errlen, "'stats socket' already specified in global section");
94 return -1;
95 }
96
97 su.sun_family = AF_UNIX;
98 strncpy(su.sun_path, args[1], sizeof(su.sun_path));
99 su.sun_path[sizeof(su.sun_path) - 1] = 0;
100 memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit
101
Willy Tarreau89a63132009-08-16 17:41:45 +0200102 if (!global.stats_fe) {
103 if ((global.stats_fe = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) {
104 snprintf(err, errlen, "out of memory");
105 return -1;
106 }
107
108 LIST_INIT(&global.stats_fe->pendconns);
109 LIST_INIT(&global.stats_fe->acl);
110 LIST_INIT(&global.stats_fe->block_cond);
111 LIST_INIT(&global.stats_fe->redirect_rules);
112 LIST_INIT(&global.stats_fe->mon_fail_cond);
113 LIST_INIT(&global.stats_fe->switching_rules);
114 LIST_INIT(&global.stats_fe->tcp_req.inspect_rules);
115
116 /* Timeouts are defined as -1, so we cannot use the zeroed area
117 * as a default value.
118 */
119 proxy_reset_timeouts(global.stats_fe);
120
121 global.stats_fe->last_change = now.tv_sec;
122 global.stats_fe->id = strdup("GLOBAL");
123 global.stats_fe->cap = PR_CAP_FE;
124 }
125
Willy Tarreaufbee7132007-10-18 13:53:22 +0200126 global.stats_sock.state = LI_INIT;
Willy Tarreau6fb42e02007-10-28 17:02:33 +0100127 global.stats_sock.options = LI_O_NONE;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200128 global.stats_sock.accept = uxst_event_accept;
Willy Tarreau104eb362009-08-16 18:51:29 +0200129 global.stats_sock.handler = process_session;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200130 global.stats_sock.analysers = 0;
Willy Tarreau2c9f5b12009-08-16 19:12:36 +0200131 global.stats_sock.nice = -64; /* we want to boost priority for local stats */
Willy Tarreau89a63132009-08-16 17:41:45 +0200132 global.stats_sock.private = global.stats_fe; /* must point to the frontend */
Willy Tarreau6162db22009-10-10 17:13:00 +0200133 global.stats_sock.perm.ux.level = ACCESS_LVL_OPER; /* default access level */
Willy Tarreau89a63132009-08-16 17:41:45 +0200134
135 global.stats_fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
136 global.stats_sock.timeout = &global.stats_fe->timeout.client;
137
138 global.stats_sock.next = global.stats_fe->listen;
139 global.stats_fe->listen = &global.stats_sock;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200140
141 cur_arg = 2;
142 while (*args[cur_arg]) {
143 if (!strcmp(args[cur_arg], "uid")) {
144 global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]);
145 cur_arg += 2;
146 }
147 else if (!strcmp(args[cur_arg], "gid")) {
148 global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]);
149 cur_arg += 2;
150 }
151 else if (!strcmp(args[cur_arg], "mode")) {
152 global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
153 cur_arg += 2;
154 }
155 else if (!strcmp(args[cur_arg], "user")) {
156 struct passwd *user;
157 user = getpwnam(args[cur_arg + 1]);
158 if (!user) {
159 snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')",
160 args[cur_arg + 1]);
161 return -1;
162 }
163 global.stats_sock.perm.ux.uid = user->pw_uid;
164 cur_arg += 2;
165 }
166 else if (!strcmp(args[cur_arg], "group")) {
167 struct group *group;
168 group = getgrnam(args[cur_arg + 1]);
169 if (!group) {
170 snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')",
171 args[cur_arg + 1]);
172 return -1;
173 }
174 global.stats_sock.perm.ux.gid = group->gr_gid;
175 cur_arg += 2;
176 }
Willy Tarreau6162db22009-10-10 17:13:00 +0200177 else if (!strcmp(args[cur_arg], "level")) {
178 if (!strcmp(args[cur_arg+1], "user"))
179 global.stats_sock.perm.ux.level = ACCESS_LVL_USER;
180 else if (!strcmp(args[cur_arg+1], "operator"))
181 global.stats_sock.perm.ux.level = ACCESS_LVL_OPER;
182 else if (!strcmp(args[cur_arg+1], "admin"))
183 global.stats_sock.perm.ux.level = ACCESS_LVL_ADMIN;
184 else {
185 snprintf(err, errlen, "'stats socket level' only supports 'user', 'operator', and 'admin'");
186 return -1;
187 }
188 cur_arg += 2;
189 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200190 else {
Willy Tarreau6162db22009-10-10 17:13:00 +0200191 snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', 'level', and 'mode'");
Willy Tarreaufbee7132007-10-18 13:53:22 +0200192 return -1;
193 }
194 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100195
Willy Tarreaufbee7132007-10-18 13:53:22 +0200196 uxst_add_listener(&global.stats_sock);
197 global.maxsock++;
198 }
199 else if (!strcmp(args[0], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100200 unsigned timeout;
201 const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS);
202
203 if (res) {
204 snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res);
205 return -1;
206 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200207
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100208 if (!timeout) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200209 snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'");
210 return -1;
211 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200212 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200213 }
214 else if (!strcmp(args[0], "maxconn")) {
215 int maxconn = atol(args[1]);
216
217 if (maxconn <= 0) {
218 snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'");
219 return -1;
220 }
221 global.maxsock -= global.stats_sock.maxconn;
222 global.stats_sock.maxconn = maxconn;
223 global.maxsock += global.stats_sock.maxconn;
224 }
225 else {
226 snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section");
227 return -1;
228 }
229 return 0;
230}
231
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200232int print_csv_header(struct chunk *msg)
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100233{
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200234 return chunk_printf(msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100235 "# pxname,svname,"
236 "qcur,qmax,"
237 "scur,smax,slim,stot,"
238 "bin,bout,"
239 "dreq,dresp,"
240 "ereq,econ,eresp,"
241 "wretr,wredis,"
242 "status,weight,act,bck,"
243 "chkfail,chkdown,lastchg,downtime,qlimit,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +0200244 "pid,iid,sid,throttle,lbtot,tracked,type,"
245 "rate,rate_lim,rate_max,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200246 "check_status,check_code,check_duration,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100247 "\n");
248}
249
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200250/* Processes the stats interpreter on the statistics socket. This function is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200251 * called from an applet running in a stream interface. The function returns 1
252 * if the request was understood, otherwise zero. It sets si->st0 to a value
253 * designating the function which will have to process the request.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200254 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200255int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200256{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200257 struct session *s = si->private;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200258 char *args[MAX_STATS_ARGS + 1];
259 int arg;
260
261 while (isspace((unsigned char)*line))
262 line++;
263
264 arg = 0;
265 args[arg] = line;
266
267 while (*line && arg < MAX_STATS_ARGS) {
268 if (isspace((unsigned char)*line)) {
269 *line++ = '\0';
270
271 while (isspace((unsigned char)*line))
272 line++;
273
274 args[++arg] = line;
275 continue;
276 }
277
278 line++;
279 }
280
281 while (++arg <= MAX_STATS_ARGS)
282 args[arg] = line;
283
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200284 s->data_ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200285 if (strcmp(args[0], "show") == 0) {
286 if (strcmp(args[1], "stat") == 0) {
287 if (*args[2] && *args[3] && *args[4]) {
288 s->data_ctx.stats.flags |= STAT_BOUND;
289 s->data_ctx.stats.iid = atoi(args[2]);
290 s->data_ctx.stats.type = atoi(args[3]);
291 s->data_ctx.stats.sid = atoi(args[4]);
292 }
293
294 s->data_ctx.stats.flags |= STAT_SHOW_STAT;
295 s->data_ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200296 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200297 si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200298 }
299 else if (strcmp(args[1], "info") == 0) {
300 s->data_ctx.stats.flags |= STAT_SHOW_INFO;
301 s->data_ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200302 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200303 si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200304 }
305 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200306 s->data_state = DATA_ST_INIT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200307 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
Willy Tarreau9bcc91e2009-10-10 18:01:44 +0200308 buffer_feed(si->ib, stats_permission_denied_msg);
Willy Tarreau6162db22009-10-10 17:13:00 +0200309 return 1;
310 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200311 si->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200312 }
313 else if (strcmp(args[1], "errors") == 0) {
Willy Tarreau6162db22009-10-10 17:13:00 +0200314 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
Willy Tarreau9bcc91e2009-10-10 18:01:44 +0200315 buffer_feed(si->ib, stats_permission_denied_msg);
Willy Tarreau6162db22009-10-10 17:13:00 +0200316 return 1;
317 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200318 if (*args[2])
319 s->data_ctx.errors.iid = atoi(args[2]);
320 else
321 s->data_ctx.errors.iid = -1;
322 s->data_ctx.errors.px = NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200323 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200324 si->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200325 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200326 else { /* neither "stat" nor "info" nor "sess" nor "errors"*/
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200327 return 0;
328 }
329 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200330 else if (strcmp(args[0], "clear") == 0) {
331 if (strcmp(args[1], "counters") == 0) {
332 struct proxy *px;
333 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200334 struct listener *li;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200335 int clrall = 0;
336
337 if (strcmp(args[2], "all") == 0)
338 clrall = 1;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200339
Willy Tarreau6162db22009-10-10 17:13:00 +0200340 /* check permissions */
341 if (s->listener->perm.ux.level < ACCESS_LVL_OPER ||
342 (clrall && s->listener->perm.ux.level < ACCESS_LVL_ADMIN)) {
Willy Tarreau9bcc91e2009-10-10 18:01:44 +0200343 buffer_feed(si->ib, stats_permission_denied_msg);
Willy Tarreau6162db22009-10-10 17:13:00 +0200344 return 1;
345 }
346
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200347 for (px = proxy; px; px = px->next) {
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200348 if (clrall)
349 memset(&px->counters, 0, sizeof(px->counters));
350 else {
351 px->counters.feconn_max = 0;
352 px->counters.beconn_max = 0;
353 px->counters.fe_sps_max = 0;
354 px->counters.be_sps_max = 0;
355 px->counters.nbpend_max = 0;
356 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200357
358 for (sv = px->srv; sv; sv = sv->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200359 if (clrall)
360 memset(&sv->counters, 0, sizeof(sv->counters));
361 else {
362 sv->counters.cur_sess_max = 0;
363 sv->counters.nbpend_max = 0;
364 sv->counters.sps_max = 0;
365 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200366
367 for (li = px->listen; li; li = li->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200368 if (li->counters) {
369 if (clrall)
370 memset(li->counters, 0, sizeof(*li->counters));
371 else
372 li->counters->conn_max = 0;
373 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200374 }
375
376 return 1;
377 }
378 else {
379 return 0;
380 }
381 }
Willy Tarreau38338fa2009-10-10 18:37:29 +0200382 else if (strcmp(args[0], "get") == 0) {
383 if (strcmp(args[1], "weight") == 0) {
384 struct proxy *px;
385 struct server *sv;
386
387 /* split "backend/server" and make <line> point to server */
388 for (line = args[2]; *line; line++)
389 if (*line == '/') {
390 *line++ = '\0';
391 break;
392 }
393
394 if (!*line) {
395 buffer_feed(si->ib, "Require 'backend/server'.\n");
396 return 1;
397 }
398
399 if (!get_backend_server(args[2], line, &px, &sv)) {
400 if (!px)
401 buffer_feed(si->ib, "No such backend.\n");
402 else
403 buffer_feed(si->ib, "No such server.\n");
404 return 1;
405 }
406
407 /* return server's effective weight at the moment */
408 snprintf(trash, sizeof(trash), "%d (initial %d)\n", sv->uweight, sv->iweight);
409 buffer_feed(si->ib, trash);
410 return 1;
411 }
412 else { /* not "get weight" */
413 return 0;
414 }
415 }
Willy Tarreau4483d432009-10-10 19:30:08 +0200416 else if (strcmp(args[0], "set") == 0) {
417 if (strcmp(args[1], "weight") == 0) {
418 struct proxy *px;
419 struct server *sv;
420 int w;
421
422 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
423 buffer_feed(si->ib, stats_permission_denied_msg);
424 return 1;
425 }
426
427 /* split "backend/server" and make <line> point to server */
428 for (line = args[2]; *line; line++)
429 if (*line == '/') {
430 *line++ = '\0';
431 break;
432 }
433
434 if (!*line || !*args[3]) {
435 buffer_feed(si->ib, "Require 'backend/server' and 'weight' or 'weight%'.\n");
436 return 1;
437 }
438
439 if (!get_backend_server(args[2], line, &px, &sv)) {
440 if (!px)
441 buffer_feed(si->ib, "No such backend.\n");
442 else
443 buffer_feed(si->ib, "No such server.\n");
444 return 1;
445 }
446
447 /* if the weight is terminated with '%', it is set relative to
448 * the initial weight, otherwise it is absolute.
449 */
450 w = atoi(args[3]);
451 if (strchr(args[3], '%') != NULL) {
452 if (w < 0 || w > 100) {
453 buffer_feed(si->ib, "Relative weight can only be set between 0 and 100% inclusive.\n");
454 return 1;
455 }
456 w = sv->iweight * w / 100;
457 }
458 else {
459 if (w < 0 || w > 256) {
460 buffer_feed(si->ib, "Absolute weight can only be between 0 and 256 inclusive.\n");
461 return 1;
462 }
463 }
464
465 if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) {
466 buffer_feed(si->ib, "Backend is using a static LB algorithm and only accepts weights '0%' and '100%'.\n");
467 return 1;
468 }
469
470 sv->uweight = w;
471
472 if (px->lbprm.algo & BE_LB_PROP_DYN) {
473 /* we must take care of not pushing the server to full throttle during slow starts */
474 if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN))
475 sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart;
476 else
477 sv->eweight = BE_WEIGHT_SCALE;
478 sv->eweight *= sv->uweight;
479 } else {
480 sv->eweight = sv->uweight;
481 }
482
483 /* static LB algorithms are a bit harder to update */
484 if (px->lbprm.update_server_eweight)
485 px->lbprm.update_server_eweight(sv);
486 else if (sv->eweight)
487 px->lbprm.set_server_status_up(sv);
488 else
489 px->lbprm.set_server_status_down(sv);
490
491 return 1;
492 }
493 else { /* not "set weight" */
494 return 0;
495 }
496 }
497 else { /* not "show" nor "clear" nor "get" nor "set" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200498 return 0;
499 }
500 return 1;
501}
502
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200503/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200504 * used to processes I/O from/to the stats unix socket. The system relies on a
505 * state machine handling requests and various responses. We read a request,
506 * then we process it and send the response, and we possibly display a prompt.
507 * Then we can read again. The state is stored in si->st0 and is one of the
508 * STAT_CLI_* constants. si->st1 is used to indicate whether prompt is enabled
509 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200510 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200511void stats_io_handler(struct stream_interface *si)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200512{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200513 struct session *s = si->private;
514 struct buffer *req = si->ob;
515 struct buffer *res = si->ib;
516 int reql;
517 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200518
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200519 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
520 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200521
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200522 while (1) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200523 if (si->st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200524 /* Stats output not initialized yet */
525 memset(&s->data_ctx.stats, 0, sizeof(s->data_ctx.stats));
526 s->data_source = DATA_SRC_STATS;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200527 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200528 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200529 else if (si->st0 == STAT_CLI_END) {
530 /* Let's close for real now. We just close the request
531 * side, the conditions below will complete if needed.
532 */
533 si->shutw(si);
534 break;
535 }
536 else if (si->st0 == STAT_CLI_GETREQ) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200537 reql = buffer_si_peekline(si->ob, trash, sizeof(trash));
538 if (reql <= 0) { /* closed or EOL not found */
539 if (reql == 0)
540 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200541 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200542 continue;
543 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200544
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200545 /* seek for a possible semi-colon. If we find one, we
546 * replace it with an LF and skip only this part.
547 */
548 for (len = 0; len < reql; len++)
549 if (trash[len] == ';') {
550 trash[len] = '\n';
551 reql = len + 1;
552 break;
553 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200554
Willy Tarreau816fc222009-10-04 07:36:58 +0200555 /* now it is time to check that we have a full line,
556 * remove the trailing \n and possibly \r, then cut the
557 * line.
558 */
559 len = reql - 1;
560 if (trash[len] != '\n') {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200561 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200562 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200563 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200564
Willy Tarreau816fc222009-10-04 07:36:58 +0200565 if (len && trash[len-1] == '\r')
566 len--;
567
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200568 trash[len] = '\0';
569
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200570 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200571 if (len) {
572 if (strcmp(trash, "quit") == 0) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200573 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200574 continue;
575 }
576 else if (strcmp(trash, "prompt") == 0)
577 si->st1 = !si->st1;
578 else if (strcmp(trash, "help") == 0 ||
579 !stats_sock_parse_request(si, trash))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200580 si->st0 = STAT_CLI_O_HELP;
581 /* NB: stats_sock_parse_request() may have put
582 * another STAT_CLI_O_* into si->st0.
583 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200584 }
585 else if (!si->st1) {
586 /* if prompt is disabled, print help on empty lines,
587 * so that the user at least knows how to enable
588 * prompt and find help.
589 */
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200590 si->st0 = STAT_CLI_O_HELP;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200591 }
592
593 /* re-adjust req buffer */
594 buffer_skip(si->ob, reql);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200595 req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200596 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200597 else { /* output functions: first check if the output buffer is closed then abort */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200598 if (res->flags & (BF_SHUTR_NOW|BF_SHUTR)) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200599 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200600 continue;
601 }
602
603 switch (si->st0) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200604 case STAT_CLI_O_HELP:
Willy Tarreau9bcc91e2009-10-10 18:01:44 +0200605 if (buffer_feed(si->ib, stats_sock_usage_msg) < 0)
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200606 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200607 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200608 case STAT_CLI_O_INFO:
Willy Tarreau24955a12009-10-04 11:54:04 +0200609 if (stats_dump_raw_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200610 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200611 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200612 case STAT_CLI_O_SESS:
Willy Tarreau7e72a8f2009-10-03 23:55:14 +0200613 if (stats_dump_sess_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200614 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200615 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200616 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau61b34732009-10-03 23:49:35 +0200617 if (stats_dump_errors_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200618 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200619 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200620 default: /* abnormal state */
621 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200622 break;
623 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200624
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200625 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
626 if (si->st0 == STAT_CLI_PROMPT) {
Willy Tarreau9bcc91e2009-10-10 18:01:44 +0200627 if (buffer_feed(si->ib, si->st1 ? "\n> " : "\n") < 0)
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200628 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200629 }
630
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200631 /* If the output functions are still there, it means they require more room. */
Willy Tarreau96fd4b52009-10-04 17:18:35 +0200632 if (si->st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200633 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200634
635 /* Now we close the output if one of the writers did so,
636 * or if we're not in interactive mode and the request
637 * buffer is empty. This still allows pipelined requests
638 * to be sent in non-interactive mode.
639 */
640 if ((res->flags & (BF_SHUTW|BF_SHUTW_NOW)) || (!si->st1 && !req->send_max)) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200641 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200642 continue;
643 }
644
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200645 /* switch state back to GETREQ to read next requests */
646 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200647 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200648 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200649
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200650 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST) && (si->st0 != STAT_CLI_GETREQ)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200651 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
652 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
653 /* Other size has closed, let's abort if we have no more processing to do
654 * and nothing more to consume. This is comparable to a broken pipe, so
655 * we forward the close to the request side so that it flows upstream to
656 * the client.
657 */
658 si->shutw(si);
659 }
660
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200661 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && (si->st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200662 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
663 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
664 /* We have no more processing to do, and nothing more to send, and
665 * the client side has closed. So we'll forward this state downstream
666 * on the response buffer.
667 */
668 si->shutr(si);
669 res->flags |= BF_READ_NULL;
670 }
671
672 /* update all other flags and resync with the other side */
673 si->update(si);
674
675 /* we don't want to expire timeouts while we're processing requests */
676 si->ib->rex = TICK_ETERNITY;
677 si->ob->wex = TICK_ETERNITY;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200678
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200679 out:
680 DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rql=%d, rqs=%d, rl=%d, rs=%d\n",
681 __FUNCTION__, __LINE__,
682 si->state, req->flags, res->flags, req->l, req->send_max, res->l, res->send_max);
683
684 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
685 /* check that we have released everything then unregister */
686 stream_int_unregister_handler(si);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200687 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200688}
689
Willy Tarreau24955a12009-10-04 11:54:04 +0200690/* This function is called to send output to the response buffer.
691 * It dumps statistics onto the output buffer <rep> owned by session <s>.
692 * s->data_ctx must have been zeroed first, and the flags properly set.
693 * It returns 0 as long as it does not complete, non-zero upon completion.
694 * Some states are not used but it makes the code more similar to other
695 * functions which handle stats too.
Willy Tarreau3e76e722007-10-17 18:57:38 +0200696 */
Willy Tarreau24955a12009-10-04 11:54:04 +0200697int stats_dump_raw_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau3e76e722007-10-17 18:57:38 +0200698{
Willy Tarreau3e76e722007-10-17 18:57:38 +0200699 struct proxy *px;
700 struct chunk msg;
Willy Tarreaua8efd362008-01-03 10:19:15 +0100701 unsigned int up;
Willy Tarreau3e76e722007-10-17 18:57:38 +0200702
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200703 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3e76e722007-10-17 18:57:38 +0200704
705 switch (s->data_state) {
706 case DATA_ST_INIT:
Willy Tarreau24955a12009-10-04 11:54:04 +0200707 /* the function had not been called yet */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200708 s->data_state = DATA_ST_HEAD;
709 /* fall through */
710
711 case DATA_ST_HEAD:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100712 if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200713 print_csv_header(&msg);
Willy Tarreau24955a12009-10-04 11:54:04 +0200714 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100715 return 0;
716 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200717
718 s->data_state = DATA_ST_INFO;
719 /* fall through */
720
721 case DATA_ST_INFO:
Willy Tarreaua8efd362008-01-03 10:19:15 +0100722 up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100723 if (s->data_ctx.stats.flags & STAT_SHOW_INFO) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200724 chunk_printf(&msg,
Willy Tarreaua8efd362008-01-03 10:19:15 +0100725 "Name: " PRODUCT_NAME "\n"
726 "Version: " HAPROXY_VERSION "\n"
727 "Release_date: " HAPROXY_DATE "\n"
728 "Nbproc: %d\n"
729 "Process_num: %d\n"
730 "Pid: %d\n"
731 "Uptime: %dd %dh%02dm%02ds\n"
732 "Uptime_sec: %d\n"
733 "Memmax_MB: %d\n"
734 "Ulimit-n: %d\n"
735 "Maxsock: %d\n"
736 "Maxconn: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +0100737 "Maxpipes: %d\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +0100738 "CurrConns: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +0100739 "PipesUsed: %d\n"
740 "PipesFree: %d\n"
Willy Tarreauc7bdf092009-03-21 18:33:52 +0100741 "Tasks: %d\n"
742 "Run_queue: %d\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200743 "node: %s\n"
744 "description: %s\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +0100745 "",
746 global.nbproc,
747 relative_pid,
748 pid,
749 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
750 up,
751 global.rlimit_memmax,
752 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +0100753 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +0100754 actconn, pipes_used, pipes_free,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200755 nb_tasks_cur, run_queue_cur,
756 global.node, global.desc?global.desc:""
Willy Tarreaua8efd362008-01-03 10:19:15 +0100757 );
Willy Tarreau24955a12009-10-04 11:54:04 +0200758 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100759 return 0;
760 }
761
Willy Tarreau3e76e722007-10-17 18:57:38 +0200762 s->data_ctx.stats.px = proxy;
763 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +0100764
765 s->data_ctx.stats.sv = NULL;
766 s->data_ctx.stats.sv_st = 0;
767
Willy Tarreau3e76e722007-10-17 18:57:38 +0200768 s->data_state = DATA_ST_LIST;
769 /* fall through */
770
771 case DATA_ST_LIST:
772 /* dump proxies */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100773 if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
Willy Tarreaua8efd362008-01-03 10:19:15 +0100774 while (s->data_ctx.stats.px) {
775 px = s->data_ctx.stats.px;
776 /* skip the disabled proxies and non-networked ones */
777 if (px->state != PR_STSTOPPED &&
Willy Tarreau24955a12009-10-04 11:54:04 +0200778 (px->cap & (PR_CAP_FE | PR_CAP_BE))) {
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100779 if (stats_dump_proxy(s, px, NULL) == 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100780 return 0;
Willy Tarreau24955a12009-10-04 11:54:04 +0200781 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200782
Willy Tarreaua8efd362008-01-03 10:19:15 +0100783 s->data_ctx.stats.px = px->next;
784 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
785 }
786 /* here, we just have reached the last proxy */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200787 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200788
789 s->data_state = DATA_ST_END;
790 /* fall through */
791
792 case DATA_ST_END:
793 s->data_state = DATA_ST_FIN;
Willy Tarreau0a464892008-12-07 18:30:00 +0100794 /* fall through */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200795
796 case DATA_ST_FIN:
797 return 1;
798
799 default:
800 /* unknown state ! */
Willy Tarreau24955a12009-10-04 11:54:04 +0200801 s->data_state = DATA_ST_FIN;
802 return 1;
Willy Tarreau3e76e722007-10-17 18:57:38 +0200803 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100804}
805
806
Willy Tarreaub0c9bc42009-10-04 15:56:38 +0200807/* This I/O handler runs as an applet embedded in a stream interface. It is
808 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
809 * si->st0 becomes non-zero once the transfer is finished. The handler
810 * automatically unregisters itself once transfer is complete.
811 */
812void http_stats_io_handler(struct stream_interface *si)
813{
814 struct session *s = si->private;
815 struct buffer *req = si->ob;
816 struct buffer *res = si->ib;
817
818 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
819 goto out;
820
821 /* check that the output is not closed */
822 if (res->flags & (BF_SHUTW|BF_SHUTW_NOW))
823 si->st0 = 1;
824
825 if (!si->st0) {
826 if (stats_dump_http(s, res, s->be->uri_auth)) {
827 si->st0 = 1;
828 si->shutw(si);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +0200829 }
830 }
831
832 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST))
833 si->shutw(si);
834
835 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && si->st0) {
836 si->shutr(si);
837 res->flags |= BF_READ_NULL;
838 }
839
840 /* update all other flags and resync with the other side */
841 si->update(si);
842
843 /* we don't want to expire timeouts while we're processing requests */
844 si->ib->rex = TICK_ETERNITY;
845 si->ob->wex = TICK_ETERNITY;
846
847 out:
848 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
849 /* check that we have released everything then unregister */
850 stream_int_unregister_handler(si);
851 }
852}
853
854
Willy Tarreau3e76e722007-10-17 18:57:38 +0200855/*
856 * Produces statistics data for the session <s>. Expects to be called with
Willy Tarreau1ae3a052008-08-16 10:56:30 +0200857 * client socket shut down on input. It stops by itself by unsetting the
Willy Tarreau72b179a2008-08-28 16:01:32 +0200858 * BF_HIJACK flag from the buffer, which it uses to keep on being called
Willy Tarreau1ae3a052008-08-16 10:56:30 +0200859 * when there is free space in the buffer, of simply by letting an empty buffer
860 * upon return.s->data_ctx must have been zeroed before the first call, and the
861 * flags set. It returns 0 if it had to stop writing data and an I/O is needed,
862 * 1 if the dump is finished and the session must be closed, or -1 in case of
863 * any error.
Willy Tarreau91861262007-10-17 17:06:05 +0200864 */
Willy Tarreau0a464892008-12-07 18:30:00 +0100865int stats_dump_http(struct session *s, struct buffer *rep, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +0200866{
Willy Tarreau91861262007-10-17 17:06:05 +0200867 struct proxy *px;
868 struct chunk msg;
869 unsigned int up;
870
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200871 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +0200872
873 switch (s->data_state) {
874 case DATA_ST_INIT:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200875 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +0200876 "HTTP/1.0 200 OK\r\n"
877 "Cache-Control: no-cache\r\n"
878 "Connection: close\r\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +0200879 "Content-Type: %s\r\n",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100880 (s->data_ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html");
Willy Tarreau91861262007-10-17 17:06:05 +0200881
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100882 if (uri->refresh > 0 && !(s->data_ctx.stats.flags & STAT_NO_REFRESH))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200883 chunk_printf(&msg, "Refresh: %d\r\n",
Willy Tarreau91861262007-10-17 17:06:05 +0200884 uri->refresh);
885
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200886 chunk_printf(&msg, "\r\n");
Willy Tarreau91861262007-10-17 17:06:05 +0200887
888 s->txn.status = 200;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +0200889 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau56a560a2009-09-22 19:27:35 +0200890 return 0;
891
Willy Tarreau91861262007-10-17 17:06:05 +0200892 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
893 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
894 if (!(s->flags & SN_FINST_MASK))
895 s->flags |= SN_FINST_R;
896
897 if (s->txn.meth == HTTP_METH_HEAD) {
898 /* that's all we return in case of HEAD request */
899 s->data_state = DATA_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +0200900 return 1;
901 }
902
903 s->data_state = DATA_ST_HEAD; /* let's start producing data */
904 /* fall through */
905
906 case DATA_ST_HEAD:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100907 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau55bb8452007-10-17 18:44:57 +0200908 /* WARNING! This must fit in the first buffer !!! */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200909 chunk_printf(&msg,
Willy Tarreau1d45b7c2009-08-16 10:29:18 +0200910 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200911 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
912 "<style type=\"text/css\"><!--\n"
913 "body {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +0200914 " font-family: arial, helvetica, sans-serif;"
Willy Tarreau91861262007-10-17 17:06:05 +0200915 " font-size: 12px;"
916 " font-weight: normal;"
917 " color: black;"
918 " background: white;"
919 "}\n"
920 "th,td {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +0200921 " font-size: 10px;"
Willy Tarreau91861262007-10-17 17:06:05 +0200922 " align: center;"
923 "}\n"
924 "h1 {"
Willy Tarreauda6721b2009-07-15 10:07:05 +0200925 " font-size: x-large;"
Willy Tarreau91861262007-10-17 17:06:05 +0200926 " margin-bottom: 0.5em;"
927 "}\n"
928 "h2 {"
929 " font-family: helvetica, arial;"
930 " font-size: x-large;"
931 " font-weight: bold;"
932 " font-style: italic;"
933 " color: #6020a0;"
934 " margin-top: 0em;"
935 " margin-bottom: 0em;"
936 "}\n"
937 "h3 {"
938 " font-family: helvetica, arial;"
939 " font-size: 16px;"
940 " font-weight: bold;"
941 " color: #b00040;"
942 " background: #e8e8d0;"
943 " margin-top: 0em;"
944 " margin-bottom: 0em;"
945 "}\n"
946 "li {"
947 " margin-top: 0.25em;"
948 " margin-right: 2em;"
949 "}\n"
950 ".hr {margin-top: 0.25em;"
951 " border-color: black;"
952 " border-bottom-style: solid;"
953 "}\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200954 ".titre {background: #20D0D0;color: #000000; font-weight: bold;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200955 ".total {background: #20D0D0;color: #ffff80;}\n"
956 ".frontend {background: #e8e8d0;}\n"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200957 ".socket {background: #d0d0d0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200958 ".backend {background: #e8e8d0;}\n"
959 ".active0 {background: #ff9090;}\n"
960 ".active1 {background: #ffd020;}\n"
961 ".active2 {background: #ffffa0;}\n"
962 ".active3 {background: #c0ffc0;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +0100963 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
964 ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
965 ".active6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200966 ".backup0 {background: #ff9090;}\n"
967 ".backup1 {background: #ff80ff;}\n"
968 ".backup2 {background: #c060ff;}\n"
969 ".backup3 {background: #b0d0ff;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +0100970 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
971 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
972 ".backup6 {background: #e0e0e0;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +0200973 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
Willy Tarreau91861262007-10-17 17:06:05 +0200974 "table.tbl { border-collapse: collapse; border-style: none;}\n"
975 "table.tbl td { border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray;}\n"
976 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
Krzysztof Piotr Oledzki619caca2009-10-03 15:46:08 +0200977 "table.tbl th.pxname {background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +0200978 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200979 "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +0200980 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
981 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
982 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
983 "-->\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +0200984 "</style></head>\n",
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200985 (uri->flags&ST_SHNODE) ? " on " : "",
986 (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
Willy Tarreau1d45b7c2009-08-16 10:29:18 +0200987 );
Willy Tarreau55bb8452007-10-17 18:44:57 +0200988 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200989 print_csv_header(&msg);
Willy Tarreau55bb8452007-10-17 18:44:57 +0200990 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +0200991 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +0200992 return 0;
993
994 s->data_state = DATA_ST_INFO;
995 /* fall through */
996
997 case DATA_ST_INFO:
998 up = (now.tv_sec - start_date.tv_sec);
999
1000 /* WARNING! this has to fit the first packet too.
1001 * We are around 3.5 kB, add adding entries will
1002 * become tricky if we want to support 4kB buffers !
1003 */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001004 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001005 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001006 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
1007 PRODUCT_NAME "%s</a></h1>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001008 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001009 "<hr width=\"100%%\" class=\"hr\">\n"
1010 "<h3>&gt; General process information</h3>\n"
1011 "<table border=0 cols=4><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001012 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001013 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001014 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
1015 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
1016 "current conns = %d; current pipes = %d/%d<br>\n"
1017 "Running tasks: %d/%d<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001018 "</td><td align=\"center\" nowrap>\n"
1019 "<table class=\"lgd\"><tr>\n"
1020 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
1021 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
1022 "</tr><tr>\n"
1023 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
1024 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
1025 "</tr><tr>\n"
1026 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
1027 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
1028 "</tr><tr>\n"
1029 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001030 "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001031 "</tr></table>\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001032 "Note: UP with load-balancing disabled is reported as \"NOLB\"."
Willy Tarreau91861262007-10-17 17:06:05 +02001033 "</td>"
1034 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
1035 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
1036 "",
1037 (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001038 pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
1039 (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
1040 pid, relative_pid, global.nbproc,
Willy Tarreau91861262007-10-17 17:06:05 +02001041 up / 86400, (up % 86400) / 3600,
1042 (up % 3600) / 60, (up % 60),
1043 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
1044 global.rlimit_memmax ? " MB" : "",
1045 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +01001046 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001047 actconn, pipes_used, pipes_used+pipes_free,
1048 run_queue_cur, nb_tasks_cur
Willy Tarreau91861262007-10-17 17:06:05 +02001049 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001050
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001051 if (s->data_ctx.stats.flags & STAT_HIDE_DOWN)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001052 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001053 "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
1054 uri->uri_prefix,
1055 "",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001056 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001057 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001058 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001059 "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
1060 uri->uri_prefix,
1061 ";up",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001062 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02001063
Willy Tarreau55bb8452007-10-17 18:44:57 +02001064 if (uri->refresh > 0) {
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001065 if (s->data_ctx.stats.flags & STAT_NO_REFRESH)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001066 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001067 "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
1068 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001069 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02001070 "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001071 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001072 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001073 "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
1074 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001075 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02001076 ";norefresh");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001077 }
Willy Tarreau91861262007-10-17 17:06:05 +02001078
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001079 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001080 "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
1081 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001082 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
1083 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02001084
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001085 chunk_printf(&msg,
Willy Tarreau5031e6a2007-10-18 11:05:48 +02001086 "<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
1087 uri->uri_prefix,
1088 (uri->refresh > 0) ? ";norefresh" : "");
1089
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001090 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001091 "</td>"
1092 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
1093 "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n"
1094 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
1095 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
1096 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
1097 "</ul>"
1098 "</td>"
1099 "</tr></table>\n"
1100 ""
1101 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001102
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001103 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001104 return 0;
1105 }
Willy Tarreau91861262007-10-17 17:06:05 +02001106
Willy Tarreau91861262007-10-17 17:06:05 +02001107 s->data_ctx.stats.px = proxy;
1108 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
1109 s->data_state = DATA_ST_LIST;
1110 /* fall through */
1111
1112 case DATA_ST_LIST:
1113 /* dump proxies */
1114 while (s->data_ctx.stats.px) {
1115 px = s->data_ctx.stats.px;
1116 /* skip the disabled proxies and non-networked ones */
1117 if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001118 if (stats_dump_proxy(s, px, uri) == 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001119 return 0;
1120
1121 s->data_ctx.stats.px = px->next;
1122 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
1123 }
1124 /* here, we just have reached the last proxy */
1125
1126 s->data_state = DATA_ST_END;
1127 /* fall through */
1128
1129 case DATA_ST_END:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001130 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001131 chunk_printf(&msg, "</body></html>\n");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001132 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001133 return 0;
1134 }
Willy Tarreau91861262007-10-17 17:06:05 +02001135
1136 s->data_state = DATA_ST_FIN;
1137 /* fall through */
1138
1139 case DATA_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02001140 return 1;
1141
1142 default:
1143 /* unknown state ! */
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001144 s->data_state = DATA_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001145 return -1;
1146 }
1147}
1148
1149
1150/*
1151 * Dumps statistics for a proxy.
1152 * Returns 0 if it had to stop dumping data because of lack of buffer space,
1153 * ot non-zero if everything completed.
1154 */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001155int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001156{
1157 struct buffer *rep = s->rep;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001158 struct server *sv, *svs; /* server and server-state, server-state=server or server->tracked */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001159 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02001160 struct chunk msg;
1161
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001162 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +02001163
1164 switch (s->data_ctx.stats.px_st) {
1165 case DATA_ST_PX_INIT:
1166 /* we are on a new proxy */
1167
1168 if (uri && uri->scope) {
1169 /* we have a limited scope, we have to check the proxy name */
1170 struct stat_scope *scope;
1171 int len;
1172
1173 len = strlen(px->id);
1174 scope = uri->scope;
1175
1176 while (scope) {
1177 /* match exact proxy name */
1178 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
1179 break;
1180
1181 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02001182 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02001183 break;
1184 scope = scope->next;
1185 }
1186
1187 /* proxy name not found : don't dump anything */
1188 if (scope == NULL)
1189 return 1;
1190 }
1191
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001192 if ((s->data_ctx.stats.flags & STAT_BOUND) && (s->data_ctx.stats.iid != -1) &&
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001193 (px->uuid != s->data_ctx.stats.iid))
1194 return 1;
1195
Willy Tarreau91861262007-10-17 17:06:05 +02001196 s->data_ctx.stats.px_st = DATA_ST_PX_TH;
1197 /* fall through */
1198
1199 case DATA_ST_PX_TH:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001200 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau55bb8452007-10-17 18:44:57 +02001201 /* print a new table */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001202 chunk_printf(&msg,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001203 "<table class=\"tbl\" width=\"100%%\">\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001204 "<tr align=\"center\" class=\"titre\">"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001205 "<th class=\"pxname\" width=\"10%%\">%s</th>"
1206 "<th class=\"%s\" width=\"90%%\">%s</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001207 "</tr>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001208 "</table>\n"
1209 "<table cols=\"29\" class=\"tbl\" width=\"100%%\">\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001210 "<tr align=\"center\" class=\"titre\">"
1211 "<th rowspan=2></th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001212 "<th colspan=3>Queue</th>"
1213 "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001214 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001215 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001216 "<th colspan=9>Server</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001217 "</tr>\n"
1218 "<tr align=\"center\" class=\"titre\">"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001219 "<th>Cur</th><th>Max</th><th>Limit</th>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001220 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001221 "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001222 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001223 "<th>Resp</th><th>Retr</th><th>Redis</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001224 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001225 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
1226 "<th>Thrtle</th>\n"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001227 "</tr>",
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001228 px->id,
1229 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001230
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001231 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001232 return 0;
1233 }
Willy Tarreau91861262007-10-17 17:06:05 +02001234
1235 s->data_ctx.stats.px_st = DATA_ST_PX_FE;
1236 /* fall through */
1237
1238 case DATA_ST_PX_FE:
1239 /* print the frontend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001240 if ((px->cap & PR_CAP_FE) &&
1241 (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) {
1242 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001243 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001244 /* name, queue */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001245 "<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=3></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001246 /* sessions rate : current, max, limit */
1247 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
1248 /* sessions : current, max, limit, total, lbtot */
1249 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001250 "<td align=right>%s</td><td align=right></td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001251 /* bytes : in, out */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001252 "<td align=right>%s</td><td align=right>%s</td>"
1253 "",
Willy Tarreaua3e49422009-05-10 19:19:41 +02001254 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001255 U2H1(px->counters.fe_sps_max), LIM2A2(px->fe_sps_lim, "-"),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001256 U2H3(px->feconn), U2H4(px->counters.feconn_max), U2H5(px->maxconn),
1257 U2H6(px->counters.cum_feconn), U2H7(px->counters.bytes_in), U2H8(px->counters.bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001258
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001259 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001260 /* denied: req, resp */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001261 "<td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001262 /* errors : request, connect, response */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001263 "<td align=right>%s</td><td align=right></td><td align=right></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001264 /* warnings: retries, redispatches */
1265 "<td align=right></td><td align=right></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001266 /* server status : reflect frontend status */
Willy Tarreau91861262007-10-17 17:06:05 +02001267 "<td align=center>%s</td>"
1268 /* rest of server: nothing */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001269 "<td align=center colspan=8></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +02001270 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001271 U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp),
1272 U2H2(px->counters.failed_req),
Willy Tarreau91861262007-10-17 17:06:05 +02001273 px->state == PR_STRUN ? "OPEN" :
1274 px->state == PR_STIDLE ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001275 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001276 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001277 /* pxid, name, queue cur, queue max, */
1278 "%s,FRONTEND,,,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001279 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001280 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001281 /* bytes : in, out */
1282 "%lld,%lld,"
1283 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001284 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001285 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001286 "%lld,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001287 /* warnings: retries, redispatches */
1288 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001289 /* server status : reflect frontend status */
1290 "%s,"
1291 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001292 ",,,,,,,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001293 /* pid, iid, sid, throttle, lbtot, tracked, type */
1294 "%d,%d,0,,,,%d,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001295 /* rate, rate_lim, rate_max */
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001296 "%u,%u,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001297 /* check_status, check_code, check_duration */
1298 ",,,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001299 "\n",
1300 px->id,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001301 px->feconn, px->counters.feconn_max, px->maxconn, px->counters.cum_feconn,
1302 px->counters.bytes_in, px->counters.bytes_out,
1303 px->counters.denied_req, px->counters.denied_resp,
1304 px->counters.failed_req,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001305 px->state == PR_STRUN ? "OPEN" :
Willy Tarreaudcd47712007-11-04 23:35:08 +01001306 px->state == PR_STIDLE ? "FULL" : "STOP",
Willy Tarreau7f062c42009-03-05 18:43:00 +01001307 relative_pid, px->uuid, STATS_TYPE_FE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001308 read_freq_ctr(&px->fe_sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001309 px->fe_sps_lim, px->counters.fe_sps_max);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001310 }
Willy Tarreau91861262007-10-17 17:06:05 +02001311
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001312 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001313 return 0;
1314 }
1315
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001316 s->data_ctx.stats.l = px->listen; /* may be NULL */
1317 s->data_ctx.stats.px_st = DATA_ST_PX_LI;
1318 /* fall through */
1319
1320 case DATA_ST_PX_LI:
1321 /* stats.l has been initialized above */
1322 for (; s->data_ctx.stats.l != NULL; s->data_ctx.stats.l = l->next) {
1323 l = s->data_ctx.stats.l;
1324 if (!l->counters)
1325 continue;
1326
1327 if (s->data_ctx.stats.flags & STAT_BOUND) {
1328 if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SO)))
1329 break;
1330
1331 if (s->data_ctx.stats.sid != -1 && l->luid != s->data_ctx.stats.sid)
1332 continue;
1333 }
1334
1335 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
1336 chunk_printf(&msg,
1337 /* name, queue */
1338 "<tr align=center class=\"socket\"><td>%s</td><td colspan=3></td>"
1339 /* sessions rate: current, max, limit */
1340 "<td align=right colspan=3>&nbsp;</td>"
1341 /* sessions: current, max, limit, total, lbtot */
1342 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
1343 "<td align=right>%s</td><td align=right>&nbsp;</td>"
1344 /* bytes: in, out */
1345 "<td align=right>%s</td><td align=right>%s</td>"
1346 "",
1347 l->name,
1348 U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn),
1349 U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out));
1350
1351 chunk_printf(&msg,
1352 /* denied: req, resp */
1353 "<td align=right>%s</td><td align=right>%s</td>"
1354 /* errors: request, connect, response */
1355 "<td align=right>%s</td><td align=right></td><td align=right></td>"
1356 /* warnings: retries, redispatches */
1357 "<td align=right></td><td align=right></td>"
1358 /* server status: reflect listener status */
1359 "<td align=center>%s</td>"
1360 /* rest of server: nothing */
1361 "<td align=center colspan=8></td></tr>"
1362 "",
1363 U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp),
1364 U2H2(l->counters->failed_req),
1365 (l->nbconn < l->maxconn) ? "OPEN" : "FULL");
1366 } else {
1367 chunk_printf(&msg,
1368 /* pxid, name, queue cur, queue max, */
1369 "%s,%s,,,"
1370 /* sessions: current, max, limit, total */
1371 "%d,%d,%d,%lld,"
1372 /* bytes: in, out */
1373 "%lld,%lld,"
1374 /* denied: req, resp */
1375 "%lld,%lld,"
1376 /* errors: request, connect, response */
1377 "%lld,,,"
1378 /* warnings: retries, redispatches */
1379 ",,"
1380 /* server status: reflect listener status */
1381 "%s,"
1382 /* rest of server: nothing */
1383 ",,,,,,,,"
1384 /* pid, iid, sid, throttle, lbtot, tracked, type */
1385 "%d,%d,%d,,,,%d,"
1386 /* rate, rate_lim, rate_max */
1387 ",,,"
1388 /* check_status, check_code, check_duration */
1389 ",,,"
1390 "\n",
1391 px->id, l->name,
1392 l->nbconn, l->counters->conn_max,
1393 l->maxconn, l->counters->cum_conn,
1394 l->counters->bytes_in, l->counters->bytes_out,
1395 l->counters->denied_req, l->counters->denied_resp,
1396 l->counters->failed_req,
1397 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
1398 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
1399 }
1400
1401 if (buffer_feed_chunk(rep, &msg) >= 0)
1402 return 0;
1403 }
1404
Willy Tarreau91861262007-10-17 17:06:05 +02001405 s->data_ctx.stats.sv = px->srv; /* may be NULL */
1406 s->data_ctx.stats.px_st = DATA_ST_PX_SV;
1407 /* fall through */
1408
1409 case DATA_ST_PX_SV:
1410 /* stats.sv has been initialized above */
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001411 for (; s->data_ctx.stats.sv != NULL; s->data_ctx.stats.sv = sv->next) {
1412
Willy Tarreau2ea81932007-11-30 12:04:38 +01001413 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 +02001414
1415 sv = s->data_ctx.stats.sv;
1416
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001417 if (s->data_ctx.stats.flags & STAT_BOUND) {
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001418 if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SV)))
1419 break;
1420
1421 if (s->data_ctx.stats.sid != -1 && sv->puid != s->data_ctx.stats.sid)
1422 continue;
1423 }
1424
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001425 if (sv->tracked)
1426 svs = sv->tracked;
1427 else
1428 svs = sv;
1429
Willy Tarreau91861262007-10-17 17:06:05 +02001430 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001431 if (!(svs->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +01001432 sv_state = 6;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001433 else if (svs->state & SRV_RUNNING) {
1434 if (svs->health == svs->rise + svs->fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02001435 sv_state = 3; /* UP */
1436 else
1437 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01001438
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001439 if (svs->state & SRV_GOINGDOWN)
Willy Tarreau2ea81932007-11-30 12:04:38 +01001440 sv_state += 2;
1441 }
Willy Tarreau91861262007-10-17 17:06:05 +02001442 else
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001443 if (svs->health)
Willy Tarreau91861262007-10-17 17:06:05 +02001444 sv_state = 1; /* going up */
1445 else
1446 sv_state = 0; /* DOWN */
1447
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001448 if ((sv_state == 0) && (s->data_ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02001449 /* do not report servers which are DOWN */
1450 s->data_ctx.stats.sv = sv->next;
1451 continue;
1452 }
1453
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001454 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01001455 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
1456 "UP %d/%d &darr;", "UP",
1457 "NOLB %d/%d &darr;", "NOLB",
1458 "<i>no check</i>" };
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001459 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001460 /* name */
1461 "<tr align=\"center\" class=\"%s%d\"><td>%s</td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001462 /* queue : current, max, limit */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001463 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001464 /* sessions rate : current, max, limit */
1465 "<td align=right>%s</td><td align=right>%s</td><td align=right></td>"
1466 /* sessions : current, max, limit, total, lbtot */
1467 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001468 "<td align=right>%s</td><td align=right>%s</td>"
1469 "",
1470 (sv->state & SRV_BACKUP) ? "backup" : "active",
1471 sv_state, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001472 U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"),
1473 U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max),
1474 U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-"),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001475 U2H8(sv->counters.cum_sess), U2H9(sv->counters.cum_lbconn));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001476
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001477 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001478 /* bytes : in, out */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001479 "<td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001480 /* denied: req, resp */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001481 "<td align=right></td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001482 /* errors : request, connect, response */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001483 "<td align=right></td><td align=right>%s</td><td align=right>%s</td>\n"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001484 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001485 "<td align=right>%lld</td><td align=right>%lld</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001486 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001487 U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out),
1488 U2H2(sv->counters.failed_secu),
1489 U2H3(sv->counters.failed_conns), U2H4(sv->counters.failed_resp),
1490 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001491
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001492 /* status, lest check */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001493 chunk_printf(&msg, "<td nowrap>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001494
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001495 if (sv->state & SRV_CHECKED) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001496 chunk_printf(&msg, "%s ",
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001497 human_time(now.tv_sec - sv->last_change, 1));
1498
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001499 chunk_printf(&msg,
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001500 srv_hlt_st[sv_state],
1501 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
1502 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02001503
1504 chunk_printf(&msg, "</td><td title=\"%s",
1505 get_check_status_description(sv->check_status));
1506
1507 if (*sv->check_desc) {
1508 struct chunk src;
1509
1510 chunk_printf(&msg, ": ");
1511
1512 chunk_initlen(&src, sv->check_desc, 0, strlen(sv->check_desc));
1513 chunk_htmlencode(&msg, &src);
1514 }
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001515
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02001516 chunk_printf(&msg, "\" nowrap> %s%s",
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001517 tv_iszero(&sv->check_start)?"":"* ",
1518 get_check_status_info(sv->check_status));
1519
1520 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001521 chunk_printf(&msg, "/%d", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001522
1523 if (sv->check_status >= HCHK_STATUS_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001524 chunk_printf(&msg, " in %lums", sv->check_duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001525 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001526 chunk_printf(&msg, "</td><td>");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001527 }
Willy Tarreau91861262007-10-17 17:06:05 +02001528
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001529 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001530 /* weight */
1531 "</td><td>%d</td>"
1532 /* act, bck */
1533 "<td>%s</td><td>%s</td>"
1534 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01001535 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +02001536 (sv->state & SRV_BACKUP) ? "-" : "Y",
1537 (sv->state & SRV_BACKUP) ? "Y" : "-");
1538
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001539 /* check failures: unique, fatal, down time */
Willy Tarreau55bb8452007-10-17 18:44:57 +02001540 if (sv->state & SRV_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001541 chunk_printf(&msg,
Willy Tarreau3b88d442009-04-11 20:44:08 +02001542 "<td align=right>%lld</td><td align=right>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001543 "<td nowrap align=right>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001544 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001545 svs->counters.failed_checks, svs->counters.down_trans,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001546 human_time(srv_downtime(sv), 1));
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001547 else if (sv != svs)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001548 chunk_printf(&msg,
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001549 "<td nowrap colspan=3>via %s/%s</td>", svs->proxy->id, svs->id);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001550 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001551 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001552 "<td colspan=3></td>");
1553
1554 /* throttle */
1555 if ((sv->state & SRV_WARMINGUP) &&
1556 now.tv_sec < sv->last_change + sv->slowstart &&
1557 now.tv_sec >= sv->last_change) {
1558 unsigned int ratio;
1559 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001560 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001561 "<td>%d %%</td></tr>\n", ratio);
1562 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001563 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001564 "<td>-</td></tr>\n");
1565 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02001566 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +01001567 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
1568 "UP %d/%d,", "UP,",
1569 "NOLB %d/%d,", "NOLB,",
1570 "no check," };
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001571 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001572 /* pxid, name */
1573 "%s,%s,"
1574 /* queue : current, max */
1575 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001576 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001577 "%d,%d,%s,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001578 /* bytes : in, out */
1579 "%lld,%lld,"
1580 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001581 ",%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001582 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001583 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001584 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001585 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001586 "",
1587 px->id, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001588 sv->nbpend, sv->counters.nbpend_max,
1589 sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001590 sv->counters.bytes_in, sv->counters.bytes_out,
1591 sv->counters.failed_secu,
1592 sv->counters.failed_conns, sv->counters.failed_resp,
1593 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001594
Willy Tarreau55bb8452007-10-17 18:44:57 +02001595 /* status */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001596 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001597 srv_hlt_st[sv_state],
1598 (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health),
1599 (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise));
Willy Tarreau91861262007-10-17 17:06:05 +02001600
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001601 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001602 /* weight, active, backup */
1603 "%d,%d,%d,"
1604 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01001605 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001606 (sv->state & SRV_BACKUP) ? 0 : 1,
1607 (sv->state & SRV_BACKUP) ? 1 : 0);
1608
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001609 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +02001610 if (sv->state & SRV_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001611 chunk_printf(&msg,
Willy Tarreau3b88d442009-04-11 20:44:08 +02001612 "%lld,%lld,%d,%d,",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001613 sv->counters.failed_checks, sv->counters.down_trans,
Willy Tarreau1772ece2009-04-03 14:49:12 +02001614 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +02001615 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001616 chunk_printf(&msg,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001617 ",,,,");
1618
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001619 /* queue limit, pid, iid, sid, */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001620 chunk_printf(&msg,
Willy Tarreaudcd47712007-11-04 23:35:08 +01001621 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001622 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +01001623 LIM2A0(sv->maxqueue, ""),
1624 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001625
1626 /* throttle */
1627 if ((sv->state & SRV_WARMINGUP) &&
1628 now.tv_sec < sv->last_change + sv->slowstart &&
1629 now.tv_sec >= sv->last_change) {
1630 unsigned int ratio;
1631 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001632 chunk_printf(&msg, "%d", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001633 }
1634
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001635 /* sessions: lbtot */
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001636 chunk_printf(&msg, ",%lld,", sv->counters.cum_lbconn);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001637
1638 /* tracked */
1639 if (sv->tracked)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001640 chunk_printf(&msg, "%s/%s,",
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001641 sv->tracked->proxy->id, sv->tracked->id);
1642 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001643 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001644
Willy Tarreau7f062c42009-03-05 18:43:00 +01001645 /* type */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001646 chunk_printf(&msg, "%d,", STATS_TYPE_SV);
Willy Tarreau7f062c42009-03-05 18:43:00 +01001647
1648 /* rate */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001649 chunk_printf(&msg, "%u,,%u,",
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001650 read_freq_ctr(&sv->sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001651 sv->counters.sps_max);
Willy Tarreau7f062c42009-03-05 18:43:00 +01001652
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001653 if (sv->state & SRV_CHECKED) {
1654 /* check_status */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001655 chunk_printf(&msg, "%s,", get_check_status_info(sv->check_status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001656
1657 /* check_code */
1658 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001659 chunk_printf(&msg, "%u,", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001660 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001661 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001662
1663 /* check_duration */
1664 if (sv->check_status >= HCHK_STATUS_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001665 chunk_printf(&msg, "%lu,", sv->check_duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001666 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001667 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001668
1669 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001670 chunk_printf(&msg, ",,,");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001671 }
1672
Willy Tarreau7f062c42009-03-05 18:43:00 +01001673 /* finish with EOL */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001674 chunk_printf(&msg, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001675 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001676 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001677 return 0;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001678 } /* for sv */
Willy Tarreau91861262007-10-17 17:06:05 +02001679
1680 s->data_ctx.stats.px_st = DATA_ST_PX_BE;
1681 /* fall through */
1682
1683 case DATA_ST_PX_BE:
1684 /* print the backend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001685 if ((px->cap & PR_CAP_BE) &&
1686 (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_BE)))) {
1687 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001688 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001689 /* name */
1690 "<tr align=center class=\"backend\"><td>Backend</td>"
1691 /* queue : current, max */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001692 "<td align=right>%s</td><td align=right>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001693 /* sessions rate : current, max, limit */
1694 "<td align=right>%s</td><td align=right>%s</td><td align=right></td>"
1695 "",
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001696 U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->counters.nbpend_max),
1697 U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->counters.be_sps_max));
Willy Tarreaua3e49422009-05-10 19:19:41 +02001698
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001699 chunk_printf(&msg,
Willy Tarreaua3e49422009-05-10 19:19:41 +02001700 /* sessions : current, max, limit, total, lbtot */
1701 "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001702 "<td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001703 /* bytes : in, out */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001704 "<td align=right>%s</td><td align=right>%s</td>"
1705 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001706 U2H2(px->beconn), U2H3(px->counters.beconn_max), U2H4(px->fullconn),
1707 U2H6(px->counters.cum_beconn), U2H7(px->counters.cum_lbconn),
1708 U2H8(px->counters.bytes_in), U2H9(px->counters.bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001709
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001710 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001711 /* denied: req, resp */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001712 "<td align=right>%s</td><td align=right>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001713 /* errors : request, connect, response */
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001714 "<td align=right></td><td align=right>%s</td><td align=right>%s</td>\n"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001715 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001716 "<td align=right>%lld</td><td align=right>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001717 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +02001718 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001719 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +02001720 * active and backups. */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001721 "<td align=center nowrap>%s %s</td><td align=center>&nbsp;</td><td align=center>%d</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001722 "<td align=center>%d</td><td align=center>%d</td>"
1723 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001724 U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp),
1725 U2H2(px->counters.failed_conns), U2H3(px->counters.failed_resp),
1726 px->counters.retries, px->counters.redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001727 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +01001728 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
1729 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5542af62007-12-03 02:04:00 +01001730 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01001731 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001732
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001733 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001734 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001735 "<td align=center>&nbsp;</td><td align=\"right\">%d</td>"
1736 "<td align=\"right\" nowrap>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001737 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001738 "</tr>",
1739 px->down_trans,
1740 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001741 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001742 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001743 /* pxid, name */
1744 "%s,BACKEND,"
1745 /* queue : current, max */
1746 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001747 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001748 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001749 /* bytes : in, out */
1750 "%lld,%lld,"
1751 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001752 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001753 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001754 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001755 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001756 "%lld,%lld,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001757 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +02001758 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001759 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +02001760 * active and backups. */
1761 "%s,"
1762 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001763 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001764 ",%d,%d,%d,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001765 /* pid, iid, sid, throttle, lbtot, tracked, type */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001766 "%d,%d,0,,%lld,,%d,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001767 /* rate, rate_lim, rate_max, */
1768 "%u,,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001769 /* check_status, check_code, check_duration */
1770 ",,,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001771 "\n",
1772 px->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001773 px->nbpend /* or px->totpend ? */, px->counters.nbpend_max,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001774 px->beconn, px->counters.beconn_max, px->fullconn, px->counters.cum_beconn,
1775 px->counters.bytes_in, px->counters.bytes_out,
1776 px->counters.denied_req, px->counters.denied_resp,
1777 px->counters.failed_conns, px->counters.failed_resp,
1778 px->counters.retries, px->counters.redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +01001779 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5542af62007-12-03 02:04:00 +01001780 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01001781 px->srv_act, px->srv_bck,
Willy Tarreau1772ece2009-04-03 14:49:12 +02001782 px->down_trans, (int)(now.tv_sec - px->last_change),
Willy Tarreau20697042007-11-15 23:26:18 +01001783 px->srv?be_downtime(px):0,
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001784 relative_pid, px->uuid,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001785 px->counters.cum_lbconn, STATS_TYPE_BE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001786 read_freq_ctr(&px->be_sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001787 px->counters.be_sps_max);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001788 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001789 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001790 return 0;
1791 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001792
Willy Tarreau91861262007-10-17 17:06:05 +02001793 s->data_ctx.stats.px_st = DATA_ST_PX_END;
1794 /* fall through */
1795
1796 case DATA_ST_PX_END:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001797 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001798 chunk_printf(&msg, "</table><p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +02001799
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001800 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001801 return 0;
1802 }
Willy Tarreau91861262007-10-17 17:06:05 +02001803
1804 s->data_ctx.stats.px_st = DATA_ST_PX_FIN;
1805 /* fall through */
1806
1807 case DATA_ST_PX_FIN:
1808 return 1;
1809
1810 default:
1811 /* unknown state, we should put an abort() here ! */
1812 return 1;
1813 }
1814}
1815
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001816
1817/* This function is called to send output to the response buffer.
1818 * It dumps the sessions states onto the output buffer <rep>.
1819 * Expects to be called with client socket shut down on input.
1820 * s->data_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02001821 * It returns 0 as long as it does not complete, non-zero upon completion.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001822 */
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02001823int stats_dump_sess_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001824{
1825 struct chunk msg;
1826
1827 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) {
1828 /* If we're forced to shut down, we might have to remove our
1829 * reference to the last session being dumped.
1830 */
1831 if (s->data_state == DATA_ST_LIST) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01001832 if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001833 LIST_DEL(&s->data_ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01001834 LIST_INIT(&s->data_ctx.sess.bref.users);
1835 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001836 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02001837 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001838 }
1839
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001840 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001841
1842 switch (s->data_state) {
1843 case DATA_ST_INIT:
1844 /* the function had not been called yet, let's prepare the
1845 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01001846 * pointer to the first in the global list. When a target
1847 * session is being destroyed, it is responsible for updating
1848 * this pointer. We know we have reached the end when this
1849 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001850 */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001851 LIST_INIT(&s->data_ctx.sess.bref.users);
1852 s->data_ctx.sess.bref.ref = sessions.n;
1853 s->data_state = DATA_ST_LIST;
1854 /* fall through */
1855
1856 case DATA_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01001857 /* first, let's detach the back-ref from a possible previous session */
1858 if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) {
1859 LIST_DEL(&s->data_ctx.sess.bref.users);
1860 LIST_INIT(&s->data_ctx.sess.bref.users);
1861 }
1862
1863 /* and start from where we stopped */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001864 while (s->data_ctx.sess.bref.ref != &sessions) {
1865 char pn[INET6_ADDRSTRLEN + strlen(":65535")];
1866 struct session *curr_sess;
1867
1868 curr_sess = LIST_ELEM(s->data_ctx.sess.bref.ref, struct session *, list);
1869
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001870 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001871 "%p: proto=%s",
1872 curr_sess,
1873 curr_sess->listener->proto->name);
1874
1875 switch (curr_sess->listener->proto->sock_family) {
1876 case AF_INET:
1877 inet_ntop(AF_INET,
1878 (const void *)&((struct sockaddr_in *)&curr_sess->cli_addr)->sin_addr,
1879 pn, sizeof(pn));
1880
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001881 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001882 " src=%s:%d fe=%s be=%s srv=%s",
1883 pn,
1884 ntohs(((struct sockaddr_in *)&curr_sess->cli_addr)->sin_port),
1885 curr_sess->fe->id,
1886 curr_sess->be->id,
1887 curr_sess->srv ? curr_sess->srv->id : "<none>"
1888 );
1889 break;
1890 case AF_INET6:
1891 inet_ntop(AF_INET6,
1892 (const void *)&((struct sockaddr_in6 *)(&curr_sess->cli_addr))->sin6_addr,
1893 pn, sizeof(pn));
1894
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001895 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001896 " src=%s:%d fe=%s be=%s srv=%s",
1897 pn,
1898 ntohs(((struct sockaddr_in6 *)&curr_sess->cli_addr)->sin6_port),
1899 curr_sess->fe->id,
1900 curr_sess->be->id,
1901 curr_sess->srv ? curr_sess->srv->id : "<none>"
1902 );
1903
1904 break;
1905 case AF_UNIX:
1906 /* no more information to print right now */
1907 break;
1908 }
1909
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001910 chunk_printf(&msg,
Willy Tarreau65671ab2009-10-04 14:24:59 +02001911 " ts=%02x age=%s calls=%d",
1912 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01001913 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
1914 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001915
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001916 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001917 " rq[f=%06xh,l=%d,an=%02xh,rx=%s",
1918 curr_sess->req->flags,
1919 curr_sess->req->l,
1920 curr_sess->req->analysers,
1921 curr_sess->req->rex ?
1922 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
1923 TICKS_TO_MS(1000)) : "");
1924
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001925 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001926 ",wx=%s",
1927 curr_sess->req->wex ?
1928 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
1929 TICKS_TO_MS(1000)) : "");
1930
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001931 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001932 ",ax=%s]",
1933 curr_sess->req->analyse_exp ?
1934 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
1935 TICKS_TO_MS(1000)) : "");
1936
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001937 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001938 " rp[f=%06xh,l=%d,an=%02xh,rx=%s",
1939 curr_sess->rep->flags,
1940 curr_sess->rep->l,
1941 curr_sess->rep->analysers,
1942 curr_sess->rep->rex ?
1943 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
1944 TICKS_TO_MS(1000)) : "");
1945
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001946 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001947 ",wx=%s",
1948 curr_sess->rep->wex ?
1949 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
1950 TICKS_TO_MS(1000)) : "");
1951
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001952 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001953 ",ax=%s]",
1954 curr_sess->rep->analyse_exp ?
1955 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
1956 TICKS_TO_MS(1000)) : "");
1957
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001958 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001959 " s0=[%d,%1xh,fd=%d,ex=%s]",
1960 curr_sess->si[0].state,
1961 curr_sess->si[0].flags,
1962 curr_sess->si[0].fd,
1963 curr_sess->si[0].exp ?
1964 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
1965 TICKS_TO_MS(1000)) : "");
1966
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001967 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001968 " s1=[%d,%1xh,fd=%d,ex=%s]",
1969 curr_sess->si[1].state,
1970 curr_sess->si[1].flags,
1971 curr_sess->si[1].fd,
1972 curr_sess->si[1].exp ?
1973 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
1974 TICKS_TO_MS(1000)) : "");
1975
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001976 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001977 " exp=%s",
1978 curr_sess->task->expire ?
1979 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
1980 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01001981 if (task_in_rq(curr_sess->task))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001982 chunk_printf(&msg, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01001983
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001984 chunk_printf(&msg, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001985
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02001986 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01001987 /* let's try again later from this session. We add ourselves into
1988 * this session's users so that it can remove us upon termination.
1989 */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001990 LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02001991 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01001992 }
1993
1994 s->data_ctx.sess.bref.ref = curr_sess->list.n;
1995 }
1996 s->data_state = DATA_ST_FIN;
1997 /* fall through */
1998
1999 default:
2000 s->data_state = DATA_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002001 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002002 }
2003}
2004
Willy Tarreau74808cb2009-03-04 15:53:18 +01002005/* print a line of error buffer (limited to 70 bytes) to <out>. The format is :
2006 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
2007 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
2008 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
2009 * lines are respected within the limit of 70 output chars. Lines that are
2010 * continuation of a previous truncated line begin with "+" instead of " "
2011 * after the offset. The new pointer is returned.
2012 */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002013static int dump_error_line(struct chunk *out, struct error_snapshot *err,
2014 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01002015{
2016 int end;
2017 unsigned char c;
2018
2019 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002020 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01002021 return ptr;
2022
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002023 chunk_printf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01002024
Willy Tarreau61b34732009-10-03 23:49:35 +02002025 while (ptr < err->len && ptr < sizeof(err->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002026 c = err->buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01002027 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002028 if (out->len > end - 2)
2029 break;
2030 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01002031 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002032 if (out->len > end - 3)
2033 break;
2034 out->str[out->len++] = '\\';
2035 switch (c) {
2036 case '\t': c = 't'; break;
2037 case '\n': c = 'n'; break;
2038 case '\r': c = 'r'; break;
2039 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01002040 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002041 }
2042 out->str[out->len++] = c;
2043 } else {
2044 if (out->len > end - 5)
2045 break;
2046 out->str[out->len++] = '\\';
2047 out->str[out->len++] = 'x';
2048 out->str[out->len++] = hextab[(c >> 4) & 0xF];
2049 out->str[out->len++] = hextab[c & 0xF];
2050 }
2051 if (err->buf[ptr++] == '\n') {
2052 /* we had a line break, let's return now */
2053 out->str[out->len++] = '\n';
2054 *line = ptr;
2055 return ptr;
2056 }
2057 }
2058 /* we have an incomplete line, we return it as-is */
2059 out->str[out->len++] = '\n';
2060 return ptr;
2061}
2062
2063/* This function is called to send output to the response buffer.
2064 * It dumps the errors logged in proxies onto the output buffer <rep>.
2065 * Expects to be called with client socket shut down on input.
2066 * s->data_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau61b34732009-10-03 23:49:35 +02002067 * It returns 0 as long as it does not complete, non-zero upon completion.
Willy Tarreau74808cb2009-03-04 15:53:18 +01002068 */
Willy Tarreau61b34732009-10-03 23:49:35 +02002069int stats_dump_errors_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau74808cb2009-03-04 15:53:18 +01002070{
2071 extern const char *monthname[12];
2072 struct chunk msg;
2073
Willy Tarreau61b34732009-10-03 23:49:35 +02002074 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW)))
2075 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002076
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002077 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau74808cb2009-03-04 15:53:18 +01002078
2079 if (!s->data_ctx.errors.px) {
2080 /* the function had not been called yet, let's prepare the
2081 * buffer for a response.
2082 */
Willy Tarreau74808cb2009-03-04 15:53:18 +01002083 s->data_ctx.errors.px = proxy;
2084 s->data_ctx.errors.buf = 0;
2085 s->data_ctx.errors.bol = 0;
2086 s->data_ctx.errors.ptr = -1;
2087 }
2088
2089 /* we have two inner loops here, one for the proxy, the other one for
2090 * the buffer.
2091 */
2092 while (s->data_ctx.errors.px) {
2093 struct error_snapshot *es;
2094
2095 if (s->data_ctx.errors.buf == 0)
2096 es = &s->data_ctx.errors.px->invalid_req;
2097 else
2098 es = &s->data_ctx.errors.px->invalid_rep;
2099
2100 if (!es->when.tv_sec)
2101 goto next;
2102
2103 if (s->data_ctx.errors.iid >= 0 &&
2104 s->data_ctx.errors.px->uuid != s->data_ctx.errors.iid &&
2105 es->oe->uuid != s->data_ctx.errors.iid)
2106 goto next;
2107
2108 if (s->data_ctx.errors.ptr < 0) {
2109 /* just print headers now */
2110
2111 char pn[INET6_ADDRSTRLEN];
2112 struct tm tm;
2113
2114 get_localtime(es->when.tv_sec, &tm);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002115 chunk_printf(&msg, "\n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01002116 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02002117 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01002118
2119
2120 if (es->src.ss_family == AF_INET)
2121 inet_ntop(AF_INET,
2122 (const void *)&((struct sockaddr_in *)&es->src)->sin_addr,
2123 pn, sizeof(pn));
2124 else
2125 inet_ntop(AF_INET6,
2126 (const void *)&((struct sockaddr_in6 *)(&es->src))->sin6_addr,
2127 pn, sizeof(pn));
2128
2129 switch (s->data_ctx.errors.buf) {
2130 case 0:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002131 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01002132 " frontend %s (#%d): invalid request\n"
2133 " src %s, session #%d, backend %s (#%d), server %s (#%d)\n"
2134 " request length %d bytes, error at position %d:\n\n",
2135 s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid,
2136 pn, es->sid, es->oe->id, es->oe->uuid,
2137 es->srv ? es->srv->id : "<NONE>",
2138 es->srv ? es->srv->puid : -1,
2139 es->len, es->pos);
2140 break;
2141 case 1:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002142 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01002143 " backend %s (#%d) : invalid response\n"
2144 " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n"
2145 " response length %d bytes, error at position %d:\n\n",
2146 s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid,
2147 pn, es->sid, es->oe->id, es->oe->uuid,
2148 es->srv ? es->srv->id : "<NONE>",
2149 es->srv ? es->srv->puid : -1,
2150 es->len, es->pos);
2151 break;
2152 }
2153
Willy Tarreau61b34732009-10-03 23:49:35 +02002154 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002155 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02002156 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002157 }
2158 s->data_ctx.errors.ptr = 0;
2159 s->data_ctx.errors.sid = es->sid;
2160 }
2161
2162 if (s->data_ctx.errors.sid != es->sid) {
2163 /* the snapshot changed while we were dumping it */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002164 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01002165 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreau61b34732009-10-03 23:49:35 +02002166 if (buffer_feed_chunk(rep, &msg) >= 0)
2167 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002168 goto next;
2169 }
2170
2171 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau61b34732009-10-03 23:49:35 +02002172 while (s->data_ctx.errors.ptr < es->len && s->data_ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002173 int newptr;
2174 int newline;
2175
2176 newline = s->data_ctx.errors.bol;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002177 newptr = dump_error_line(&msg, es, &newline, s->data_ctx.errors.ptr);
Willy Tarreau74808cb2009-03-04 15:53:18 +01002178 if (newptr == s->data_ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02002179 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002180
Willy Tarreau61b34732009-10-03 23:49:35 +02002181 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002182 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02002183 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002184 }
2185 s->data_ctx.errors.ptr = newptr;
2186 s->data_ctx.errors.bol = newline;
2187 };
2188 next:
2189 s->data_ctx.errors.bol = 0;
2190 s->data_ctx.errors.ptr = -1;
2191 s->data_ctx.errors.buf++;
2192 if (s->data_ctx.errors.buf > 1) {
2193 s->data_ctx.errors.buf = 0;
2194 s->data_ctx.errors.px = s->data_ctx.errors.px->next;
2195 }
2196 }
2197
2198 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02002199 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002200}
2201
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002202
Willy Tarreau10522fd2008-07-09 20:12:41 +02002203static struct cfg_kw_list cfg_kws = {{ },{
2204 { CFG_GLOBAL, "stats", stats_parse_global },
2205 { 0, NULL, NULL },
2206}};
2207
2208__attribute__((constructor))
2209static void __dumpstats_module_init(void)
2210{
2211 cfg_register_keywords(&cfg_kws);
2212}
2213
Willy Tarreau91861262007-10-17 17:06:05 +02002214/*
2215 * Local variables:
2216 * c-indent-level: 8
2217 * c-basic-offset: 8
2218 * End:
2219 */